use of com.gargoylesoftware.htmlunit.javascript.host.ClientRect in project htmlunit by HtmlUnit.
the class Range method getClientRects.
/**
* Retrieves a collection of rectangles that describes the layout of the contents of an object
* or range within the client. Each rectangle describes a single line.
* @return a collection of rectangles that describes the layout of the contents
*/
@JsxFunction
public ClientRectList getClientRects() {
final Window w = getWindow();
final ClientRectList rectList = new ClientRectList();
rectList.setParentScope(w);
rectList.setPrototype(getPrototype(rectList.getClass()));
// simple impl for now
for (final DomNode node : toW3C().containedNodes()) {
final ScriptableObject scriptable = node.getScriptableObject();
if (scriptable instanceof HTMLElement) {
final ClientRect rect = new ClientRect(0, 0, 1, 1);
rect.setParentScope(w);
rect.setPrototype(getPrototype(rect.getClass()));
rectList.add(rect);
}
}
return rectList;
}
use of com.gargoylesoftware.htmlunit.javascript.host.ClientRect in project htmlunit by HtmlUnit.
the class HTMLElement method getBoundingClientRect.
/**
* {@inheritDoc}
*/
@Override
public ClientRect getBoundingClientRect() {
final ClientRect textRectangle = super.getBoundingClientRect();
int left = getPosX();
int top = getPosY();
// account for any scrolled ancestors
Object parentNode = getOffsetParentInternal(false);
while ((parentNode instanceof HTMLElement) && !(parentNode instanceof HTMLBodyElement)) {
final HTMLElement elem = (HTMLElement) parentNode;
left -= elem.getScrollLeft();
top -= elem.getScrollTop();
parentNode = elem.getParentNode();
}
textRectangle.setBottom(top + getOffsetHeight());
textRectangle.setLeft(left);
textRectangle.setRight(left + getOffsetWidth());
textRectangle.setTop(top);
return textRectangle;
}
use of com.gargoylesoftware.htmlunit.javascript.host.ClientRect in project htmlunit by HtmlUnit.
the class Range method getBoundingClientRect.
/**
* Returns an object that bounds the contents of the range.
* this a rectangle enclosing the union of the bounding rectangles for all the elements in the range.
* @return an object the bounds the contents of the range
*/
@JsxFunction
public ClientRect getBoundingClientRect() {
final ClientRect rect = new ClientRect();
rect.setParentScope(getWindow());
rect.setPrototype(getPrototype(rect.getClass()));
// simple impl for now
for (final DomNode node : toW3C().containedNodes()) {
final ScriptableObject scriptable = node.getScriptableObject();
if (scriptable instanceof HTMLElement) {
final ClientRect childRect = ((HTMLElement) scriptable).getBoundingClientRect();
rect.setTop(Math.min(rect.getTop(), childRect.getTop()));
rect.setLeft(Math.min(rect.getLeft(), childRect.getLeft()));
rect.setRight(Math.max(rect.getRight(), childRect.getRight()));
rect.setBottom(Math.max(rect.getBottom(), childRect.getBottom()));
}
}
return rect;
}
Aggregations