List of usage examples for com.google.gwt.user.client Window getScrollLeft
public static int getScrollLeft()
From source file:com.vaadin.client.ui.SuperTreeWidget.java
License:Apache License
private void handleBodyContextMenu(ContextMenuEvent event) { if (!readonly && !disabled) { if (bodyActionKeys != null) { int left = event.getNativeEvent().getClientX(); int top = event.getNativeEvent().getClientY(); top += Window.getScrollTop(); left += Window.getScrollLeft(); client.getContextMenu().showAt(this, left, top); }/*from w w w. j ava 2s. co m*/ event.stopPropagation(); event.preventDefault(); } }
From source file:com.vaadin.client.ui.VCustomScrollTable.java
License:Apache License
/** * Handles a context menu event on table body. * /*w ww . j a v a2s .c om*/ * @param left * left position of the context menu * @param top * top position of the context menu * @return true if a context menu was shown, otherwise false */ private boolean handleBodyContextMenu(int left, int top) { if (enabled && bodyActionKeys != null) { top += Window.getScrollTop(); left += Window.getScrollLeft(); client.getContextMenu().showAt(this, left, top); return true; } return false; }
From source file:com.vaadin.client.ui.VSlider.java
License:Apache License
private void setValueByEvent(Event event, boolean updateToServer) { double v = min; // Fallback to min final int coord = getEventPosition(event); final int handleSize, baseSize, baseOffset; if (isVertical()) { handleSize = handle.getOffsetHeight(); baseSize = base.getOffsetHeight(); baseOffset = base.getAbsoluteTop() - Window.getScrollTop() - handleSize / 2; } else {/*from www . j ava2s. c o m*/ handleSize = handle.getOffsetWidth(); baseSize = base.getOffsetWidth(); baseOffset = base.getAbsoluteLeft() - Window.getScrollLeft() + handleSize / 2; } if (isVertical()) { v = ((baseSize - (coord - baseOffset)) / (double) (baseSize - handleSize)) * (max - min) + min; } else { v = ((coord - baseOffset) / (double) (baseSize - handleSize)) * (max - min) + min; } if (v < min) { v = min; } else if (v > max) { v = max; } setValue(v, updateToServer); }
From source file:com.vaadin.client.VTooltip.java
License:Apache License
/** * Show a popup containing the currentTooltipInfo * //w w w . j a v a2 s. com */ 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
@Override public void center() { super.center(); // Some devices can be zoomed in, we should center to the visual // viewport for those devices BrowserInfo b = BrowserInfo.get();//from w ww . j a va 2s .com if (b.isAndroid() || b.isIOS()) { int left = (getVisualViewportWidth() - getOffsetWidth()) >> 1; int top = (getVisualViewportHeight() - getOffsetHeight()) >> 1; setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max(Window.getScrollTop() + top, 0)); } }
From source file:com.vaadin.terminal.gwt.client.ui.VCustomScrollTable.java
License:Apache License
protected void handleBodyContextMenu(ContextMenuEvent event) { if (enabled && bodyActionKeys != null) { int left = Util.getTouchOrMouseClientX(event.getNativeEvent()); int top = Util.getTouchOrMouseClientY(event.getNativeEvent()); top += Window.getScrollTop(); left += Window.getScrollLeft(); client.getContextMenu().showAt(this, left, top); // Only prevent browser context menu if there are action handlers // registered event.stopPropagation();/*from ww w .j a va 2 s . co m*/ event.preventDefault(); } }
From source file:com.vaadin.terminal.gwt.client.ui.VPopupCalendar.java
License:Open Source License
/** * Opens the calendar panel popup/* w w w . j a v a 2s.co 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!"); } }
From source file:com.vaadin.terminal.gwt.client.ui.VScrollTable.java
License:Open Source License
private void handleBodyContextMenu(ContextMenuEvent event) { if (enabled && bodyActionKeys != null) { int left = Util.getTouchOrMouseClientX(event.getNativeEvent()); int top = Util.getTouchOrMouseClientY(event.getNativeEvent()); top += Window.getScrollTop(); left += Window.getScrollLeft(); client.getContextMenu().showAt(this, left, top); // Only prevent browser context menu if there are action handlers // registered event.stopPropagation();/*w w w. ja v a 2s. c o m*/ event.preventDefault(); } }
From source file:com.vaadin.terminal.gwt.client.ui.VSlider.java
License:Open Source License
private void setValueByEvent(Event event, boolean updateToServer) { double v = min; // Fallback to min final int coord = getEventPosition(event); final int handleSize, baseSize, baseOffset; if (vertical) { handleSize = handle.getOffsetHeight(); baseSize = base.getOffsetHeight(); baseOffset = base.getAbsoluteTop() - Window.getScrollTop() - handleSize / 2; } else {//from w w w . ja va 2 s . c om handleSize = handle.getOffsetWidth(); baseSize = base.getOffsetWidth(); baseOffset = base.getAbsoluteLeft() - Window.getScrollLeft() + handleSize / 2; } if (vertical) { v = ((baseSize - (coord - baseOffset)) / (double) (baseSize - handleSize)) * (max - min) + min; } else { v = ((coord - baseOffset) / (double) (baseSize - handleSize)) * (max - min) + min; } if (v < min) { v = min; } else if (v > max) { v = max; } setValue(v, updateToServer); }
From source file:com.vaadin.terminal.gwt.client.VTooltip.java
License:Open Source License
/** * Show a popup containing the information in the "info" tooltip * //from ww w .ja va 2 s. co m * @param info */ private void show(TooltipInfo info) { boolean hasContent = false; if (info.getErrorUidl() != null) { em.setVisible(true); em.updateFromUIDL(info.getErrorUidl()); hasContent = true; } else { em.setVisible(false); } if (info.getTitle() != null && !"".equals(info.getTitle())) { DOM.setInnerHTML(description, info.getTitle()); DOM.setStyleAttribute(description, "display", ""); hasContent = true; } else { DOM.setInnerHTML(description, ""); DOM.setStyleAttribute(description, "display", "none"); } if (hasContent) { setPopupPositionAndShow(new PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { if (offsetWidth > MAX_WIDTH) { setWidth(MAX_WIDTH + "px"); // Check new height and width with reflowed content offsetWidth = getOffsetWidth(); offsetHeight = getOffsetHeight(); } int x = tooltipEventMouseX + 10 + Window.getScrollLeft(); int y = tooltipEventMouseY + 10 + Window.getScrollTop(); if (x + offsetWidth + MARGIN - Window.getScrollLeft() > Window.getClientWidth()) { x = Window.getClientWidth() - offsetWidth - MARGIN; } if (y + offsetHeight + MARGIN - Window.getScrollTop() > Window.getClientHeight()) { y = tooltipEventMouseY - 5 - offsetHeight; 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(); } } setPopupPosition(x, y); sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT); } }); } else { hide(); } }