@Override public boolean onEventPreview(Event event) { if (dragging) { onDragEvent(event); return false; } else if (resizing) { onResizeEvent(event); return false; } // TODO This is probably completely unnecessary as the modality curtain // prevents events from reaching other windows and any security check // must be done on the server side and not here. // The code here is also run many times as each VWindow has an event // preview but we cannot check only the current VWindow here (e.g. // if(isTopMost) {...}) because PopupPanel will cause all events that // are not cancelled here and target this window to be consume():d // meaning the event won't be sent to the rest of the preview handlers. if (getTopmostWindow().vaadinModality) { // Topmost window is modal. Cancel the event if it targets something // outside that window (except debug console...) if (DOM.getCaptureElement() != null) { // Allow events when capture is set return true; } final Element target = event.getEventTarget().cast(); if (!DOM.isOrHasChild(getTopmostWindow().getElement(), target)) { // not within the modal window, but let's see if it's in the // debug window Widget w = Util.findWidget(target, null); while (w != null) { if (w instanceof VDebugWindow) { return true; // allow debug-window clicks } else if (ConnectorMap.get(client).isConnector(w)) { return false; } w = w.getParent(); } return false; } } return true; }
/** * Called when the window or parent div might have been resized. * * <p>This immediately checks the sizes of the window and the parent div (if monitoring it) and * triggers layout recalculation if they have changed. * * @param newWindowWidth The new width of the window * @param newWindowHeight The new height of the window * @deprecated use {@link #performSizeCheck()} */ @Deprecated protected void windowSizeMaybeChanged(int newWindowWidth, int newWindowHeight) { if (connection == null) { // Connection is null if the timer fires before the first UIDL // update return; } boolean changed = false; ComponentConnector connector = ConnectorMap.get(connection).getConnector(this); if (windowWidth != newWindowWidth) { windowWidth = newWindowWidth; changed = true; connector.getLayoutManager().reportOuterWidth(connector, newWindowWidth); VConsole.log("New window width: " + windowWidth); } if (windowHeight != newWindowHeight) { windowHeight = newWindowHeight; changed = true; connector.getLayoutManager().reportOuterHeight(connector, newWindowHeight); VConsole.log("New window height: " + windowHeight); } Element parentElement = getElement().getParentElement(); if (isMonitoringParentSize() && parentElement != null) { // check also for parent size changes int newParentWidth = parentElement.getClientWidth(); int newParentHeight = parentElement.getClientHeight(); if (parentWidth != newParentWidth) { parentWidth = newParentWidth; changed = true; VConsole.log("New parent width: " + parentWidth); } if (parentHeight != newParentHeight) { parentHeight = newParentHeight; changed = true; VConsole.log("New parent height: " + parentHeight); } } if (changed) { /* * If the window size has changed, layout the VView again and send * new size to the server if the size changed. (Just checking VView * size would cause us to ignore cases when a relatively sized VView * should shrink as the content's size is fixed and would thus not * automatically shrink.) */ VConsole.log("Running layout functions due to window or parent resize"); // update size to avoid (most) redundant re-layout passes // there can still be an extra layout recalculation if webkit // overflow fix updates the size in a deferred block if (isMonitoringParentSize() && parentElement != null) { parentWidth = parentElement.getClientWidth(); parentHeight = parentElement.getClientHeight(); } sendClientResized(); LayoutManager layoutManager = connector.getLayoutManager(); if (layoutManager.isLayoutRunning()) { layoutManager.layoutLater(); } else { layoutManager.layoutNow(); } } }
public void updateContentsSize() { LayoutManager layoutManager = getLayoutManager(); layoutManager.setNeedsMeasure(ConnectorMap.get(client).getConnector(this)); layoutManager.layoutNow(); }
@Override public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { ConnectorMap paintableMap = ConnectorMap.get(getConnection()); getWidget().rendering = true; getWidget().id = getConnectorId(); boolean firstPaint = getWidget().connection == null; getWidget().connection = client; getWidget().immediate = getState().immediate; getWidget().resizeLazy = uidl.hasAttribute(UIConstants.RESIZE_LAZY); String newTheme = uidl.getStringAttribute("theme"); if (getWidget().theme != null && !newTheme.equals(getWidget().theme)) { // Complete page refresh is needed due css can affect layout // calculations etc getWidget().reloadHostPage(); } else { getWidget().theme = newTheme; } // this also implicitly removes old styles String styles = ""; styles += getWidget().getStylePrimaryName() + " "; if (ComponentStateUtil.hasStyles(getState())) { for (String style : getState().styles) { styles += style + " "; } } if (!client.getConfiguration().isStandalone()) { styles += getWidget().getStylePrimaryName() + "-embedded"; } getWidget().setStyleName(styles.trim()); getWidget().makeScrollable(); clickEventHandler.handleEventHandlerRegistration(); // Process children int childIndex = 0; // Open URL:s boolean isClosed = false; // was this window closed? while (childIndex < uidl.getChildCount() && "open".equals(uidl.getChildUIDL(childIndex).getTag())) { final UIDL open = uidl.getChildUIDL(childIndex); final String url = client.translateVaadinUri(open.getStringAttribute("src")); final String target = open.getStringAttribute("name"); if (target == null) { // source will be opened to this browser window, but we may have // to finish rendering this window in case this is a download // (and window stays open). Scheduler.get() .scheduleDeferred( new Command() { @Override public void execute() { VUI.goTo(url); } }); } else if ("_self".equals(target)) { // This window is closing (for sure). Only other opens are // relevant in this change. See #3558, #2144 isClosed = true; VUI.goTo(url); } else { String options; boolean alwaysAsPopup = true; if (open.hasAttribute("popup")) { alwaysAsPopup = open.getBooleanAttribute("popup"); } if (alwaysAsPopup) { if (open.hasAttribute("border")) { if (open.getStringAttribute("border").equals("minimal")) { options = "menubar=yes,location=no,status=no"; } else { options = "menubar=no,location=no,status=no"; } } else { options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes"; } if (open.hasAttribute("width")) { int w = open.getIntAttribute("width"); options += ",width=" + w; } if (open.hasAttribute("height")) { int h = open.getIntAttribute("height"); options += ",height=" + h; } Window.open(url, target, options); } else { open(url, target); } } childIndex++; } if (isClosed) { // don't render the content, something else will be opened to this // browser view getWidget().rendering = false; return; } // Handle other UIDL children UIDL childUidl; while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) { String tag = childUidl.getTag().intern(); if (tag == "actions") { if (getWidget().actionHandler == null) { getWidget().actionHandler = new ShortcutActionHandler(getWidget().id, client); } getWidget().actionHandler.updateActionMap(childUidl); } else if (tag == "notifications") { for (final Iterator<?> it = childUidl.getChildIterator(); it.hasNext(); ) { final UIDL notification = (UIDL) it.next(); VNotification.showNotification(client, notification); } } } if (uidl.hasAttribute("focused")) { // set focused component when render phase is finished Scheduler.get() .scheduleDeferred( new Command() { @Override public void execute() { ComponentConnector paintable = (ComponentConnector) uidl.getPaintableAttribute("focused", getConnection()); final Widget toBeFocused = paintable.getWidget(); /* * Two types of Widgets can be focused, either implementing * GWT HasFocus of a thinner Vaadin specific Focusable * interface. */ if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; toBeFocusedWidget.setFocus(true); } else if (toBeFocused instanceof Focusable) { ((Focusable) toBeFocused).focus(); } else { VConsole.log("Could not focus component"); } } }); } // Add window listeners on first paint, to prevent premature // variablechanges if (firstPaint) { Window.addWindowClosingHandler(getWidget()); Window.addResizeHandler(getWidget()); } if (uidl.hasAttribute("scrollTo")) { final ComponentConnector connector = (ComponentConnector) uidl.getPaintableAttribute("scrollTo", getConnection()); scrollIntoView(connector); } if (uidl.hasAttribute(UIConstants.LOCATION_VARIABLE)) { String location = uidl.getStringAttribute(UIConstants.LOCATION_VARIABLE); int fragmentIndex = location.indexOf('#'); if (fragmentIndex >= 0) { getWidget().currentFragment = location.substring(fragmentIndex + 1); } if (!getWidget().currentFragment.equals(History.getToken())) { History.newItem(getWidget().currentFragment, true); } } if (firstPaint) { // Queue the initial window size to be sent with the following // request. getWidget().sendClientResized(); } getWidget().rendering = false; }