use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class Range method getCommonAncestorContainer.
/**
* Returns the deepest common ancestor container of the Range's two boundary points.
* @return the deepest common ancestor container of the Range's two boundary points
*/
@JsxGetter
public Object getCommonAncestorContainer() {
final HashSet<Node> startAncestors = new HashSet<>();
Node ancestor = startContainer_;
while (ancestor != null) {
startAncestors.add(ancestor);
ancestor = ancestor.getParent();
}
ancestor = endContainer_;
while (ancestor != null) {
if (startAncestors.contains(ancestor)) {
return ancestor;
}
ancestor = ancestor.getParent();
}
return Undefined.instance;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter 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();
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class File method getLastModifiedDate.
/**
* Returns the {@code lastModifiedDate} property.
* @return the {@code lastModifiedDate} property
*/
@JsxGetter({ CHROME, EDGE, IE })
public String getLastModifiedDate() {
final Date date = new Date(getLastModified());
final BrowserVersion browser = getBrowserVersion();
final Locale locale = browser.getBrowserLocale();
final TimeZone timezone = browser.getSystemTimezone();
final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT, timezone, locale);
return format.format(date);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter 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();
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class HTMLElement method getOffsetTop.
/**
* Returns this element's {@code offsetTop}, which is the calculated top position of this
* element relative to the {@code offsetParent}.
*
* @return this element's {@code offsetTop}
* @see <a href="http://msdn2.microsoft.com/en-us/library/ms534303.aspx">MSDN Documentation</a>
* @see <a href="http://www.quirksmode.org/js/elementdimensions.html">Element Dimensions</a>
* @see <a href="http://dump.testsuite.org/2006/dom/style/offset/spec">Reverse Engineering by Anne van Kesteren</a>
*/
@JsxGetter
public int getOffsetTop() {
if (this instanceof HTMLBodyElement) {
return 0;
}
int top = 0;
// Add the offset for this node.
DomNode node = getDomNodeOrDie();
HTMLElement element = node.getScriptableObject();
ComputedCSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
top += style.getTop(true, false, false);
// If this node is absolutely positioned, we're done.
final String position = style.getPositionWithInheritance();
if ("absolute".equals(position)) {
return top;
}
final HTMLElement offsetParent = getOffsetParent();
// Add the offset for the ancestor nodes.
node = node.getParentNode();
while (node != null && node.getScriptableObject() != offsetParent) {
if (node.getScriptableObject() instanceof HTMLElement) {
element = node.getScriptableObject();
style = element.getWindow().getComputedStyle(element, null);
top += style.getTop(false, true, true);
}
node = node.getParentNode();
}
if (offsetParent != null) {
final HTMLElement thiz = getDomNodeOrDie().getScriptableObject();
style = thiz.getWindow().getComputedStyle(thiz, null);
final boolean thisElementHasTopMargin = style.getMarginTopValue() != 0;
style = offsetParent.getWindow().getComputedStyle(offsetParent, null);
if (!thisElementHasTopMargin) {
top += style.getMarginTopValue();
}
top += style.getPaddingTopValue();
}
return top;
}
Aggregations