List of usage examples for com.google.gwt.user.client Window getClientHeight
public static int getClientHeight()
From source file:com.vaadin.client.ui.VUI.java
License:Apache License
/** * Called when the window or parent div might have been resized. * //from www. jav a2 s . c om * This immediately checks the sizes of the window and the parent div (if * monitoring it) and triggers layout recalculation if they have changed. */ protected void performSizeCheck() { windowSizeMaybeChanged(Window.getClientWidth(), Window.getClientHeight()); }
From source file:com.vaadin.client.ui.VWindow.java
License:Apache License
/** * TODO check if we need to support this with touch based devices. * // w w w.j a va 2s . co m * Checks if the cursor was inside the browser content area when the event * happened. * * @param event * The event to be checked * @return true, if the cursor is inside the browser content area * * false, otherwise */ private boolean cursorInsideBrowserContentArea(Event event) { if (event.getClientX() < 0 || event.getClientY() < 0) { // Outside to the left or above return false; } if (event.getClientX() > Window.getClientWidth() || event.getClientY() > Window.getClientHeight()) { // Outside to the right or below return false; } return true; }
From source file:com.vaadin.client.ui.window.WindowConnector.java
License:Apache License
@Override public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); VWindow window = getWidget();/* ww w .j a v a2 s . c o m*/ WindowState state = getState(); if (state.modal != window.vaadinModality) { window.setVaadinModality(!window.vaadinModality); } boolean resizeable = state.resizable && state.windowMode == WindowMode.NORMAL; window.setResizable(resizeable); window.resizeLazy = state.resizeLazy; window.setDraggable(state.draggable && state.windowMode == WindowMode.NORMAL); window.updateMaximizeRestoreClassName(state.resizable, state.windowMode); // Caption must be set before required header size is measured. If // the caption attribute is missing the caption should be cleared. String iconURL = null; if (getIconUri() != null) { iconURL = getIconUri(); } window.setAssistivePrefix(state.assistivePrefix); window.setAssistivePostfix(state.assistivePostfix); window.setCaption(state.caption, iconURL, getState().captionAsHtml); window.setWaiAriaRole(getState().role); window.setAssistiveDescription(state.contentDescription); window.setTabStopEnabled(getState().assistiveTabStop); window.setTabStopTopAssistiveText(getState().assistiveTabStopTopText); window.setTabStopBottomAssistiveText(getState().assistiveTabStopBottomText); clickEventHandler.handleEventHandlerRegistration(); window.immediate = state.immediate; window.setClosable(!isReadOnly()); // initialize position from state updateWindowPosition(); // setting scrollposition must happen after children is rendered window.contentPanel.setScrollPosition(state.scrollTop); window.contentPanel.setHorizontalScrollPosition(state.scrollLeft); // Center this window on screen if requested // This had to be here because we might not know the content size before // everything is painted into the window // centered is this is unset on move/resize window.centered = state.centered; // Ensure centering before setting visible (#16486) if (window.centered && getState().windowMode != WindowMode.MAXIMIZED) { Scheduler.get().scheduleFinally(new ScheduledCommand() { @Override public void execute() { getWidget().center(); } }); } window.setVisible(true); // ensure window is not larger than browser window if (window.getOffsetWidth() > Window.getClientWidth()) { window.setWidth(Window.getClientWidth() + "px"); } if (window.getOffsetHeight() > Window.getClientHeight()) { window.setHeight(Window.getClientHeight() + "px"); } }
From source file:com.vaadin.client.VDebugConsole.java
License:Apache License
@Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); switch (DOM.eventGetType(event)) { case Event.ONMOUSEDOWN: if (DOM.eventGetShiftKey(event)) { resizing = true;//from ww w . j a va 2 s . co m DOM.setCapture(getElement()); startX = DOM.eventGetScreenX(event); startY = DOM.eventGetScreenY(event); initialW = VDebugConsole.this.getOffsetWidth(); initialH = VDebugConsole.this.getOffsetHeight(); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); DOM.addEventPreview(dragpreview); } else if (DOM.eventGetTarget(event) == caption) { moving = true; startX = DOM.eventGetScreenX(event); startY = DOM.eventGetScreenY(event); origTop = getAbsoluteTop(); origLeft = getAbsoluteLeft(); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); DOM.addEventPreview(dragpreview); } break; case Event.ONMOUSEMOVE: if (resizing) { int deltaX = startX - DOM.eventGetScreenX(event); int detalY = startY - DOM.eventGetScreenY(event); int w = initialW - deltaX; if (w < 30) { w = 30; } int h = initialH - detalY; if (h < 40) { h = 40; } VDebugConsole.this.setPixelSize(w, h); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); } else if (moving) { int deltaX = startX - DOM.eventGetScreenX(event); int detalY = startY - DOM.eventGetScreenY(event); int left = origLeft - deltaX; if (left < 0) { left = 0; } int top = origTop - detalY; if (top < 0) { top = 0; } VDebugConsole.this.setPopupPosition(left, top); DOM.eventCancelBubble(event, true); DOM.eventPreventDefault(event); } break; case Event.ONLOSECAPTURE: case Event.ONMOUSEUP: if (resizing) { DOM.releaseCapture(getElement()); resizing = false; } else if (moving) { DOM.releaseCapture(getElement()); moving = false; } DOM.removeEventPreview(dragpreview); break; case Event.ONDBLCLICK: if (DOM.eventGetTarget(event) == caption) { if (collapsed) { panel.setVisible(true); setToDefaultSizeAndPos(); } else { panel.setVisible(false); setPixelSize(120, 20); setPopupPosition(Window.getClientWidth() - 125, Window.getClientHeight() - 25); } collapsed = !collapsed; } break; default: break; } }
From source file:com.vaadin.client.VDebugConsole.java
License:Apache License
private void setToDefaultSizeAndPos() { String cookie = Cookies.getCookie(POS_COOKIE_NAME); int width, height, top, left; boolean autoScrollValue = false; if (cookie != null) { String[] split = cookie.split(","); left = Integer.parseInt(split[0]); top = Integer.parseInt(split[1]); width = Integer.parseInt(split[2]); height = Integer.parseInt(split[3]); autoScrollValue = Boolean.valueOf(split[4]); } else {/*from w ww .j a v a 2 s . c o m*/ int windowHeight = Window.getClientHeight(); int windowWidth = Window.getClientWidth(); width = DEFAULT_WIDTH; height = DEFAULT_HEIGHT; if (height > windowHeight / 2) { height = windowHeight / 2; } if (width > windowWidth / 2) { width = windowWidth / 2; } top = windowHeight - (height + 10); left = windowWidth - (width + 10); } setPixelSize(width, height); setPopupPosition(left, top); autoScroll.setValue(autoScrollValue); }
From source file:com.vaadin.client.VTooltip.java
License:Apache License
/** * Show a popup containing the currentTooltipInfo * /*from ww w . ja va 2 s.c om*/ */ private void showTooltip() { if (currentTooltipInfo.hasMessage()) { // Issue #8454: With IE7 the tooltips size is calculated based on // the last tooltip's position, causing problems if the last one was // in the right or bottom edge. For this reason the tooltip is moved // first to 0,0 position so that the calculation goes correctly. setPopupPosition(0, 0); setPopupPositionAndShow(new PositionCallback() { @Override public void setPosition(int offsetWidth, int offsetHeight) { if (offsetWidth > getMaxWidth()) { setWidth(getMaxWidth() + "px"); // Check new height and width with reflowed content offsetWidth = getOffsetWidth(); offsetHeight = getOffsetHeight(); } int x = 0; int y = 0; if (BrowserInfo.get().isTouchDevice()) { setMaxWidth(Window.getClientWidth()); offsetWidth = getOffsetWidth(); offsetHeight = getOffsetHeight(); x = getFinalTouchX(offsetWidth); y = getFinalTouchY(offsetHeight); } else { x = getFinalX(offsetWidth); y = getFinalY(offsetHeight); } setPopupPosition(x, y); sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT); } /** * Return the final X-coordinate of the tooltip based on cursor * position, size of the tooltip, size of the page and necessary * margins. * * @param offsetWidth * @return The final X-coordinate */ private int getFinalX(int offsetWidth) { int x = 0; int widthNeeded = 10 + MARGIN + offsetWidth; int roomLeft = tooltipEventMouseX; int roomRight = Window.getClientWidth() - roomLeft; if (roomRight > widthNeeded) { x = tooltipEventMouseX + 10 + Window.getScrollLeft(); } else { x = tooltipEventMouseX + Window.getScrollLeft() - 10 - offsetWidth; } if (x + offsetWidth + MARGIN - Window.getScrollLeft() > Window.getClientWidth()) { x = Window.getClientWidth() - offsetWidth - MARGIN + Window.getScrollLeft(); } if (tooltipEventMouseX != EVENT_XY_POSITION_OUTSIDE) { // Do not allow x to be zero, for otherwise the tooltip // does not close when the mouse is moved (see // isTooltipOpen()). #15129 int minX = Window.getScrollLeft() + MARGIN; x = Math.max(x, minX); } return x; } /** * Return the final X-coordinate of the tooltip based on cursor * position, size of the tooltip, size of the page and necessary * margins. * * @param offsetWidth * @return The final X-coordinate */ private int getFinalTouchX(int offsetWidth) { int x = 0; int widthNeeded = 10 + offsetWidth; int roomLeft = currentElement != null ? currentElement.getAbsoluteLeft() : EVENT_XY_POSITION_OUTSIDE; int viewPortWidth = Window.getClientWidth(); int roomRight = viewPortWidth - roomLeft; if (roomRight > widthNeeded) { x = roomLeft; } else { x = roomLeft - offsetWidth; } if (x + offsetWidth - Window.getScrollLeft() > viewPortWidth) { x = viewPortWidth - offsetWidth + Window.getScrollLeft(); } if (roomLeft != EVENT_XY_POSITION_OUTSIDE) { // Do not allow x to be zero, for otherwise the tooltip // does not close when the mouse is moved (see // isTooltipOpen()). #15129 int minX = Window.getScrollLeft(); x = Math.max(x, minX); } return x; } /** * Return the final Y-coordinate of the tooltip based on cursor * position, size of the tooltip, size of the page and necessary * margins. * * @param offsetHeight * @return The final y-coordinate * */ private int getFinalY(int offsetHeight) { int y = 0; int heightNeeded = 10 + offsetHeight; int roomAbove = tooltipEventMouseY; int roomBelow = Window.getClientHeight() - roomAbove; if (roomBelow > heightNeeded) { y = tooltipEventMouseY + 10 + Window.getScrollTop(); } else { y = tooltipEventMouseY + Window.getScrollTop() - 10 - offsetHeight; } if (y + offsetHeight + MARGIN - Window.getScrollTop() > Window.getClientHeight()) { y = tooltipEventMouseY - 5 - offsetHeight + Window.getScrollTop(); if (y - Window.getScrollTop() < 0) { // tooltip does not fit on top of the mouse either, // put it at the top of the screen y = Window.getScrollTop(); } } if (tooltipEventMouseY != EVENT_XY_POSITION_OUTSIDE) { // Do not allow y to be zero, for otherwise the tooltip // does not close when the mouse is moved (see // isTooltipOpen()). #15129 int minY = Window.getScrollTop() + MARGIN; y = Math.max(y, minY); } return y; } /** * Return the final Y-coordinate of the tooltip based on cursor * position, size of the tooltip, size of the page and necessary * margins. * * @param offsetHeight * @return The final y-coordinate * */ private int getFinalTouchY(int offsetHeight) { int y = 0; int heightNeeded = 10 + offsetHeight; int roomAbove = currentElement != null ? currentElement.getAbsoluteTop() + currentElement.getOffsetHeight() : EVENT_XY_POSITION_OUTSIDE; int roomBelow = Window.getClientHeight() - roomAbove; if (roomBelow > heightNeeded) { y = roomAbove; } else { y = roomAbove - offsetHeight - (currentElement != null ? currentElement.getOffsetHeight() : 0); } if (y + offsetHeight - Window.getScrollTop() > Window.getClientHeight()) { y = roomAbove - 5 - offsetHeight + Window.getScrollTop(); if (y - Window.getScrollTop() < 0) { // tooltip does not fit on top of the mouse either, // put it at the top of the screen y = Window.getScrollTop(); } } if (roomAbove != EVENT_XY_POSITION_OUTSIDE) { // Do not allow y to be zero, for otherwise the tooltip // does not close when the mouse is moved (see // isTooltipOpen()). #15129 int minY = Window.getScrollTop(); y = Math.max(y, minY); } return y; } }); } else { hide(); } }
From source file:com.vaadin.client.widgets.Overlay.java
License:Apache License
/** * Gets the visual viewport height, which is useful for e.g iOS where the * view can be zoomed in while keeping the layout viewport intact. * /*w ww . jav a 2 s.com*/ * Falls back to layout viewport; for those browsers/devices the difference * is that the scrollbar with is included (if there is a scrollbar). * * @since 7.0.7 * @return */ private int getVisualViewportHeight() { int h = (int) getSubpixelInnerHeight(); if (h < 0) { return Window.getClientHeight(); } else { return h; } }
From source file:com.vaadin.terminal.gwt.client.ApplicationConnection.java
License:Open Source License
/** * Converts relative sizes into pixel sizes. * /*from w w w .jav a2s.c o m*/ * @param child * @return true if the child has a relative size */ private boolean handleComponentRelativeSize(ComponentDetail cd) { if (cd == null) { return false; } boolean debugSizes = false; FloatSize relativeSize = cd.getRelativeSize(); if (relativeSize == null) { return false; } Widget widget = (Widget) cd.getComponent(); boolean horizontalScrollBar = false; boolean verticalScrollBar = false; Container parent = Util.getLayout(widget); RenderSpace renderSpace; // Parent-less components (like sub-windows) are relative to browser // window. if (parent == null) { renderSpace = new RenderSpace(Window.getClientWidth(), Window.getClientHeight()); } else { renderSpace = parent.getAllocatedSpace(widget); } if (relativeSize.getHeight() >= 0) { if (renderSpace != null) { if (renderSpace.getScrollbarSize() > 0) { if (relativeSize.getWidth() > 100) { horizontalScrollBar = true; } else if (relativeSize.getWidth() < 0 && renderSpace.getWidth() > 0) { int offsetWidth = widget.getOffsetWidth(); int width = renderSpace.getWidth(); if (offsetWidth > width) { horizontalScrollBar = true; } } } int height = renderSpace.getHeight(); if (horizontalScrollBar) { height -= renderSpace.getScrollbarSize(); } if (validatingLayouts && height <= 0) { zeroHeightComponents.add(cd.getComponent()); } height = (int) (height * relativeSize.getHeight() / 100.0); if (height < 0) { height = 0; } if (debugSizes) { VConsole.log("Widget " + Util.getSimpleName(widget) + "/" + getPid(widget.getElement()) + " relative height " + relativeSize.getHeight() + "% of " + renderSpace.getHeight() + "px (reported by " + Util.getSimpleName(parent) + "/" + (parent == null ? "?" : parent.hashCode()) + ") : " + height + "px"); } widget.setHeight(height + "px"); } else { widget.setHeight(relativeSize.getHeight() + "%"); VConsole.error(Util.getLayout(widget).getClass().getName() + " did not produce allocatedSpace for " + widget.getClass().getName()); } } if (relativeSize.getWidth() >= 0) { if (renderSpace != null) { int width = renderSpace.getWidth(); if (renderSpace.getScrollbarSize() > 0) { if (relativeSize.getHeight() > 100) { verticalScrollBar = true; } else if (relativeSize.getHeight() < 0 && renderSpace.getHeight() > 0 && widget.getOffsetHeight() > renderSpace.getHeight()) { verticalScrollBar = true; } } if (verticalScrollBar) { width -= renderSpace.getScrollbarSize(); } if (validatingLayouts && width <= 0) { zeroWidthComponents.add(cd.getComponent()); } width = (int) (width * relativeSize.getWidth() / 100.0); if (width < 0) { width = 0; } if (debugSizes) { VConsole.log("Widget " + Util.getSimpleName(widget) + "/" + getPid(widget.getElement()) + " relative width " + relativeSize.getWidth() + "% of " + renderSpace.getWidth() + "px (reported by " + Util.getSimpleName(parent) + "/" + (parent == null ? "?" : getPid(parent)) + ") : " + width + "px"); } widget.setWidth(width + "px"); } else { widget.setWidth(relativeSize.getWidth() + "%"); VConsole.error(Util.getLayout(widget).getClass().getName() + " did not produce allocatedSpace for " + widget.getClass().getName()); } } return true; }
From source file:com.vaadin.terminal.gwt.client.ui.VContextMenu.java
License:Open Source License
/** * Shows context menu at given location IF it contain at least one item. * /*from ww w . ja v a 2 s .c om*/ * @param left * @param top */ public void showAt(int left, int top) { final Action[] actions = actionOwner.getActions(); if (actions == null || actions.length == 0) { // Only show if there really are actions return; } this.left = left; this.top = top; menu.clearItems(); for (int i = 0; i < actions.length; i++) { final Action a = actions[i]; menu.addItem(new MenuItem(a.getHTML(), true, a)); } // Attach onload listeners to all images Util.sinkOnloadForImages(menu.getElement()); setPopupPositionAndShow(new PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { // mac FF gets bad width due GWT popups overflow hacks, // re-determine width offsetWidth = menu.getOffsetWidth(); int left = VContextMenu.this.left; int top = VContextMenu.this.top; if (offsetWidth + left > Window.getClientWidth()) { left = left - offsetWidth; if (left < 0) { left = 0; } } if (offsetHeight + top > Window.getClientHeight()) { top = top - offsetHeight; if (top < 0) { top = 0; } } setPopupPosition(left, top); /* * Move keyboard focus to menu, deferring the focus setting so * the focus is certainly moved to the menu in all browser after * the positioning has been done. */ Scheduler.get().scheduleDeferred(new Command() { public void execute() { // Focus the menu. menu.setFocus(true); // Unselect previously selected items menu.selectItem(null); } }); } }); }
From source file:com.vaadin.terminal.gwt.client.ui.VPopupCalendar.java
License:Open Source License
/** * Opens the calendar panel popup//ww w. j av a2s . c o m */ public void openCalendarPanel() { if (!open && !readonly) { open = true; if (getCurrentDate() != null) { calendar.setDate((Date) getCurrentDate().clone()); } else { calendar.setDate(new Date()); } // clear previous values popup.setWidth(""); popup.setHeight(""); popup.setPopupPositionAndShow(new PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { final int w = offsetWidth; final int h = offsetHeight; final int browserWindowWidth = Window.getClientWidth() + Window.getScrollLeft(); final int browserWindowHeight = Window.getClientHeight() + Window.getScrollTop(); int t = calendarToggle.getAbsoluteTop(); int l = calendarToggle.getAbsoluteLeft(); // Add a little extra space to the right to avoid // problems with IE7 scrollbars and to make it look // nicer. int extraSpace = 30; boolean overflowRight = false; if (l + +w + extraSpace > browserWindowWidth) { overflowRight = true; // Part of the popup is outside the browser window // (to the right) l = browserWindowWidth - w - extraSpace; } if (t + h + calendarToggle.getOffsetHeight() + 30 > browserWindowHeight) { // Part of the popup is outside the browser window // (below) t = browserWindowHeight - h - calendarToggle.getOffsetHeight() - 30; if (!overflowRight) { // Show to the right of the popup button unless we // are in the lower right corner of the screen l += calendarToggle.getOffsetWidth(); } } // fix size popup.setWidth(w + "px"); popup.setHeight(h + "px"); popup.setPopupPosition(l, t + calendarToggle.getOffsetHeight() + 2); /* * We have to wait a while before focusing since the popup * needs to be opened before we can focus */ Timer focusTimer = new Timer() { @Override public void run() { setFocus(true); } }; focusTimer.schedule(100); } }); } else { VConsole.error("Cannot reopen popup, it is already open!"); } }