Search in sources :

Example 21 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class DomNamespaceNode method processImportNode.

/**
 * {@inheritDoc}
 */
@Override
public void processImportNode(final Document doc) {
    super.processImportNode(doc);
    // if we are importing from a namespace-aware source
    // we have to drop the XHtmlNamespace because we did this already
    // for the HTML document itself
    final SgmlPage page = (SgmlPage) doc.getDomNodeOrDie();
    if (page.isHtmlPage() && !(page instanceof XHtmlPage) && Html.XHTML_NAMESPACE.equals(namespaceURI_)) {
        namespaceURI_ = null;
    }
}
Also used : SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage)

Example 22 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class HtmlElement method detach.

/**
 * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
 *
 * Detach this node from all relationships with other nodes.
 * This is the first step of a move.
 */
@Override
protected void detach() {
    final SgmlPage page = getPage();
    if (!page.getWebClient().isJavaScriptEngineEnabled()) {
        super.detach();
        return;
    }
    final Object document = page.getScriptableObject();
    if (document instanceof HTMLDocument) {
        final HTMLDocument doc = (HTMLDocument) document;
        final Object activeElement = doc.getActiveElement();
        if (activeElement == getScriptableObject()) {
            doc.setActiveElement(null);
            if (hasFeature(HTMLELEMENT_REMOVE_ACTIVE_TRIGGERS_BLUR_EVENT)) {
                ((HtmlPage) page).setFocusedElement(null);
            } else {
                ((HtmlPage) page).setElementWithFocus(null);
            }
        } else {
            for (final DomNode child : getChildNodes()) {
                if (activeElement == child.getScriptableObject()) {
                    doc.setActiveElement(null);
                    if (hasFeature(HTMLELEMENT_REMOVE_ACTIVE_TRIGGERS_BLUR_EVENT)) {
                        ((HtmlPage) page).setFocusedElement(null);
                    } else {
                        ((HtmlPage) page).setElementWithFocus(null);
                    }
                    break;
                }
            }
        }
    }
    super.detach();
}
Also used : HTMLDocument(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage)

Example 23 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class HtmlDateInput method setAttributeNS.

/**
 * {@inheritDoc}
 */
@Override
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
    super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners, notifyMutationObservers);
    if ("value".equals(qualifiedName)) {
        final SgmlPage page = getPage();
        if (page != null && page.isHtmlPage()) {
            int pos = 0;
            if (!hasFeature(JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START)) {
                pos = attributeValue.length();
            }
            setSelectionStart(pos);
            setSelectionEnd(pos);
        }
    }
}
Also used : SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage)

Example 24 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class Image method jsConstructor.

/**
 * JavaScript constructor.
 */
@Override
@JsxConstructor
public void jsConstructor() {
    final SgmlPage page = (SgmlPage) getWindow().getWebWindow().getEnclosedPage();
    final DomElement fake = page.getWebClient().getPageCreator().getHtmlParser().getFactory(HtmlImage.TAG_NAME).createElement(page, HtmlImage.TAG_NAME, null);
    setDomNode(fake);
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) JsxConstructor(com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)

Example 25 with SgmlPage

use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.

the class HtmlInput method executeOnChangeHandlerIfAppropriate.

/**
 * Executes the onchange script code for this element if this is appropriate.
 * This means that the element must have an onchange script, script must be enabled
 * and the change in the element must not have been triggered by a script.
 *
 * @param htmlElement the element that contains the onchange attribute
 * @return the page that occupies this window after this method completes (may or
 *         may not be the same as the original page)
 */
static Page executeOnChangeHandlerIfAppropriate(final HtmlElement htmlElement) {
    final SgmlPage page = htmlElement.getPage();
    final WebClient webClient = page.getWebClient();
    if (!webClient.isJavaScriptEngineEnabled()) {
        return page;
    }
    final AbstractJavaScriptEngine<?> engine = webClient.getJavaScriptEngine();
    if (engine.isScriptRunning()) {
        return page;
    }
    final ScriptResult scriptResult = htmlElement.fireEvent(Event.TYPE_CHANGE);
    if (webClient.containsWebWindow(page.getEnclosingWindow())) {
        // may be itself or a newly loaded one
        return page.getEnclosingWindow().getEnclosedPage();
    }
    if (scriptResult != null) {
        // current window doesn't exist anymore
        return webClient.getCurrentWindow().getEnclosedPage();
    }
    return page;
}
Also used : ScriptResult(com.gargoylesoftware.htmlunit.ScriptResult) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) WebClient(com.gargoylesoftware.htmlunit.WebClient)

Aggregations

SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)38 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)10 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)7 DomDocumentFragment (com.gargoylesoftware.htmlunit.html.DomDocumentFragment)5 DomText (com.gargoylesoftware.htmlunit.html.DomText)5 Page (com.gargoylesoftware.htmlunit.Page)4 ScriptResult (com.gargoylesoftware.htmlunit.ScriptResult)4 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)3 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)3 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)3 Node (com.gargoylesoftware.htmlunit.javascript.host.dom.Node)3 HTMLDocument (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument)3 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)2 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)2 HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)2 JsxConstructor (com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor)2 DocumentFragment (com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentFragment)2 MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)2 PointerEvent (com.gargoylesoftware.htmlunit.javascript.host.event.PointerEvent)2