Sets the "current" window for this client. This is the window that will be used when getPage(...) is called without specifying a window. @param window the new "current" window for this client
(final WebWindow window)
| 986 | * @param window the new "current" window for this client |
| 987 | */ |
| 988 | public void setCurrentWindow(final WebWindow window) { |
| 989 | WebAssert.notNull("window", window); |
| 990 | if (currentWindow_ == window) { |
| 991 | return; |
| 992 | } |
| 993 | // onBlur event is triggered for focused element of old current window |
| 994 | if (currentWindow_ != null && !currentWindow_.isClosed()) { |
| 995 | final Page enclosedPage = currentWindow_.getEnclosedPage(); |
| 996 | if (enclosedPage != null && enclosedPage.isHtmlPage()) { |
| 997 | final DomElement focusedElement = ((HtmlPage) enclosedPage).getFocusedElement(); |
| 998 | if (focusedElement != null) { |
| 999 | focusedElement.fireEvent(Event.TYPE_BLUR); |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | currentWindow_ = window; |
| 1004 | |
| 1005 | // when marking an iframe window as current we have no need to move the focus |
| 1006 | final boolean isIFrame = currentWindow_ instanceof FrameWindow fw |
| 1007 | && fw.getFrameElement() instanceof HtmlInlineFrame; |
| 1008 | if (!isIFrame) { |
| 1009 | //1. activeElement becomes focused element for new current window |
| 1010 | //2. onFocus event is triggered for focusedElement of new current window |
| 1011 | final Page enclosedPage = currentWindow_.getEnclosedPage(); |
| 1012 | if (enclosedPage != null && enclosedPage.isHtmlPage()) { |
| 1013 | final HtmlPage enclosedHtmlPage = (HtmlPage) enclosedPage; |
| 1014 | final HtmlElement activeElement = enclosedHtmlPage.getActiveElement(); |
| 1015 | if (activeElement != null) { |
| 1016 | enclosedHtmlPage.setFocusedElement(activeElement, true); |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Adds a listener for {@link WebWindowEvent}s. All events from all windows associated with this |