Java Code Examples for com.gargoylesoftware.htmlunit.html.BaseFrameElement#isDisplayed()

The following examples show how to use com.gargoylesoftware.htmlunit.html.BaseFrameElement#isDisplayed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebClient.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void webWindowContentChanged(final WebWindowEvent event) {
    final WebWindow window = event.getWebWindow();
    boolean use = false;
    if (window instanceof DialogWindow) {
        use = true;
    }
    else if (window instanceof TopLevelWindow) {
        use = event.getOldPage() == null;
    }
    else if (window instanceof FrameWindow) {
        final FrameWindow fw = (FrameWindow) window;
        final String enclosingPageState = fw.getEnclosingPage().getDocumentElement().getReadyState();
        final URL frameUrl = fw.getEnclosedPage().getUrl();
        if (!DomNode.READY_STATE_COMPLETE.equals(enclosingPageState) || frameUrl == URL_ABOUT_BLANK) {
            return;
        }

        // now looks at the visibility of the frame window
        final BaseFrameElement frameElement = fw.getFrameElement();
        if (webClient_.isJavaScriptEnabled() && frameElement.isDisplayed()) {
            final Object element = frameElement.getScriptableObject();
            final HTMLElement htmlElement = (HTMLElement) element;
            final ComputedCSSStyleDeclaration style =
                    htmlElement.getWindow().getComputedStyle(htmlElement, null);
            use = style.getCalculatedWidth(false, false) != 0
                    && style.getCalculatedHeight(false, false) != 0;
        }
    }
    if (use) {
        webClient_.setCurrentWindow(window);
    }
}
 
Example 2
Source File: WebClient.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void webWindowContentChanged(final WebWindowEvent event) {
    final WebWindow window = event.getWebWindow();
    boolean use = false;
    if (window instanceof DialogWindow) {
        use = true;
    }
    else if (window instanceof TopLevelWindow) {
        use = event.getOldPage() == null;
    }
    else if (window instanceof FrameWindow) {
        final FrameWindow fw = (FrameWindow) window;
        final String enclosingPageState = fw.getEnclosingPage().getDocumentElement().getReadyState();
        final URL frameUrl = fw.getEnclosedPage().getUrl();
        if (!DomNode.READY_STATE_COMPLETE.equals(enclosingPageState) || frameUrl == URL_ABOUT_BLANK) {
            return;
        }

        // now looks at the visibility of the frame window
        final BaseFrameElement frameElement = fw.getFrameElement();
        if (frameElement.isDisplayed()) {
            final Object element = frameElement.getScriptableObject();
            final HTMLElement htmlElement = (HTMLElement) element;
            final ComputedCSSStyleDeclaration style =
                    htmlElement.getWindow().getComputedStyle(htmlElement, null);
            use = style.getCalculatedWidth(false, false) != 0
                    && style.getCalculatedHeight(false, false) != 0;
        }
    }
    if (use) {
        webClient_.setCurrentWindow(window);
    }
}