Java Code Examples for com.gargoylesoftware.htmlunit.javascript.host.Window#getDocument()

The following examples show how to use com.gargoylesoftware.htmlunit.javascript.host.Window#getDocument() . 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: HTMLDocument.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the current document instance, using <tt>thisObj</tt> as a hint.
 * @param thisObj a hint as to the current document (may be the prototype when function is used without "this")
 * @return the current document instance
 */
private static HTMLDocument getDocument(final Scriptable thisObj) {
    // if function is used "detached", then thisObj is the top scope (ie Window), not the real object
    // cf unit test DocumentTest#testDocumentWrite_AssignedToVar
    // may be the prototype too
    // cf DocumentTest#testDocumentWrite_AssignedToVar2
    if (thisObj instanceof HTMLDocument && thisObj.getPrototype() instanceof HTMLDocument) {
        return (HTMLDocument) thisObj;
    }
    if (thisObj instanceof DocumentProxy && thisObj.getPrototype() instanceof HTMLDocument) {
        return (HTMLDocument) ((DocumentProxy) thisObj).getDelegee();
    }

    final Window window = getWindow(thisObj);
    if (window.getBrowserVersion().hasFeature(HTMLDOCUMENT_FUNCTION_DETACHED)) {
        return (HTMLDocument) window.getDocument();
    }
    throw Context.reportRuntimeError("Function can't be used detached from document");
}
 
Example 2
Source File: HTMLDocument.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the current document instance, using <tt>thisObj</tt> as a hint.
 * @param thisObj a hint as to the current document (may be the prototype when function is used without "this")
 * @return the current document instance
 */
private static HTMLDocument getDocument(final Scriptable thisObj) {
    // if function is used "detached", then thisObj is the top scope (ie Window), not the real object
    // cf unit test DocumentTest#testDocumentWrite_AssignedToVar
    // may be the prototype too
    // cf DocumentTest#testDocumentWrite_AssignedToVar2
    if (thisObj instanceof HTMLDocument && thisObj.getPrototype() instanceof HTMLDocument) {
        return (HTMLDocument) thisObj;
    }
    if (thisObj instanceof DocumentProxy && thisObj.getPrototype() instanceof HTMLDocument) {
        return (HTMLDocument) ((DocumentProxy) thisObj).getDelegee();
    }

    final Window window = getWindow(thisObj);
    if (window.getBrowserVersion().hasFeature(HTMLDOCUMENT_FUNCTION_DETACHED)) {
        return (HTMLDocument) window.getDocument();
    }
    throw Context.reportRuntimeError("Function can't be used detached from document");
}
 
Example 3
Source File: HTMLElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the object as active without setting focus to the object.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a>
 */
@JsxFunction(IE)
public void setActive() {
    final Window window = getWindow();
    final HTMLDocument document = (HTMLDocument) window.getDocument();
    document.setActiveElement(this);
    if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) {
        final HtmlElement element = getDomNodeOrDie();
        ((HtmlPage) element.getPage()).setFocusedElement(element);
    }
}
 
Example 4
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the object as active without setting focus to the object.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a>
 */
@JsxFunction(IE)
public void setActive() {
    final Window window = getWindow();
    final HTMLDocument document = (HTMLDocument) window.getDocument();
    document.setActiveElement(this);
    if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) {
        final HtmlElement element = getDomNodeOrDie();
        ((HtmlPage) element.getPage()).setFocusedElement(element);
    }
}
 
Example 5
Source File: DocumentProxy.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Document getDelegee() {
    final Window w = webWindow_.getScriptableObject();
    return w.getDocument();
}
 
Example 6
Source File: DocumentProxy.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Document getDelegee() {
    final Window w = (Window) webWindow_.getScriptableObject();
    return w.getDocument();
}