Search in sources :

Example 6 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class TextRange method getHtmlText.

/**
 * Retrieves the HTML fragment contained within the range.
 * @return the HTML fragment contained within the range
 */
@JsxGetter
public String getHtmlText() {
    final org.w3c.dom.Node node = range_.getCommonAncestorContainer();
    if (null == node) {
        return "";
    }
    final HTMLElement element = (HTMLElement) getScriptableFor(node);
    // TODO: not quite right, but good enough for now
    return element.getOuterHTML();
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 7 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class MouseEvent method getScreenY.

/**
 * The vertical coordinate at which the event occurred relative to the origin of the screen
 * coordinate system. The value of this attribute is initialized lazily, in order to optimize
 * performance (it requires CSS parsing).
 *
 * @return the vertical coordinate
 */
@JsxGetter
public int getScreenY() {
    if (screenY_ == null) {
        final HTMLElement target = (HTMLElement) getTarget();
        screenY_ = Integer.valueOf(target.getPosY() + 10);
    }
    return screenY_.intValue();
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 8 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class HtmlTableRowTest method cellScriptObjectIsReturnedByScript.

/**
 * Ensure that the JavaScript object returned by the script fragment is the
 * same one the DOM node thinks it's wrapped by.
 */
@Test
public void cellScriptObjectIsReturnedByScript() {
    final String cmd = "document.getElementById('cell')";
    final HTMLElement jselement = (HTMLElement) page_.executeJavaScript(cmd).getJavaScriptResult();
    assertSame(jselement, cell_.getScriptableObject());
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) Test(org.junit.Test)

Example 9 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class HtmlTableRowTest method scriptCanGetOriginalCell.

// these next few test our assumptions about how scripts affect the DOM
/**
 * Ensure that the JavaScript object returned by the script fragment really
 * refers to the same DOM node we think it should.
 */
@Test
public void scriptCanGetOriginalCell() {
    final String cmd = "document.getElementById('cell')";
    final Object object = page_.executeJavaScript(cmd).getJavaScriptResult();
    final HtmlElement cellElement = ((HTMLElement) object).getDomNodeOrDie();
    assertSame(cell_, cellElement);
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) Test(org.junit.Test)

Example 10 with HTMLElement

use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method scrollByLines.

/**
 * Scrolls the window content down by the specified number of lines.
 * @param lines the number of lines to scroll down
 */
@JsxFunction({ FF, FF_ESR })
public void scrollByLines(final int lines) {
    final HTMLElement body = document_.getBody();
    if (body != null) {
        body.setScrollTop(body.getScrollTop() + (19 * lines));
        final Event event = new Event(body, Event.TYPE_SCROLL);
        body.fireEvent(event);
    }
}
Also used : HTMLElement(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement) MouseEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent) HtmlAttributeChangeEvent(com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent) Event(com.gargoylesoftware.htmlunit.javascript.host.event.Event) MessageEvent(com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)35 AttributedString (java.text.AttributedString)10 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)7 Test (org.junit.Test)7 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)6 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)6 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 MouseEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MouseEvent)5 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)5 BaseFrameElement (com.gargoylesoftware.htmlunit.html.BaseFrameElement)4 HtmlAttributeChangeEvent (com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent)4 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)4 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)4 MessageEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent)4 HTMLUnknownElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLUnknownElement)4 StyleElement (com.gargoylesoftware.htmlunit.css.StyleElement)3 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)3 HTMLBodyElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement)3 HTMLCanvasElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement)3