use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLTableCellElement method getOffsetWidth.
/**
* {@inheritDoc}
*/
@Override
public int getOffsetWidth() {
float w = super.getOffsetWidth();
final MouseEvent event = MouseEvent.getCurrentMouseEvent();
if (isAncestorOfEventTarget(event)) {
return (int) w;
}
if (isDisplayNone()) {
return 0;
}
final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
if ("collapse".equals(style.getStyleAttribute(StyleAttributes.Definition.BORDER_COLLAPSE))) {
final HtmlTableRow row = getRow();
if (row != null) {
final HtmlElement thiz = getDomNodeOrDie();
final List<HtmlTableCell> cells = row.getCells();
final boolean ie = getBrowserVersion().hasFeature(JS_TABLE_CELL_OFFSET_INCLUDES_BORDER);
final boolean leftmost = cells.indexOf(thiz) == 0;
final boolean rightmost = cells.indexOf(thiz) == cells.size() - 1;
w -= (ie && leftmost ? 0 : 0.5) * style.getBorderLeftValue();
w -= (ie && rightmost ? 0 : 0.5) * style.getBorderRightValue();
}
}
return (int) w;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLElement method getOffsetLeft.
/**
* Returns this element's <tt>offsetLeft</tt>, which is the calculated left position of this
* element relative to the <tt>offsetParent</tt>.
*
* @return this element's <tt>offsetLeft</tt>
* @see <a href="http://msdn2.microsoft.com/en-us/library/ms534200.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 getOffsetLeft() {
if (this instanceof HTMLBodyElement) {
return 0;
}
int left = 0;
// Add the offset for this node.
DomNode node = getDomNodeOrDie();
HTMLElement element = node.getScriptableObject();
ComputedCSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
left += style.getLeft(true, false, false);
// If this node is absolutely positioned, we're done.
final String position = style.getPositionWithInheritance();
if ("absolute".equals(position)) {
return left;
}
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);
left += style.getLeft(true, true, true);
}
node = node.getParentNode();
}
if (offsetParent != null) {
style = offsetParent.getWindow().getComputedStyle(offsetParent, null);
left += style.getMarginLeftValue();
left += style.getPaddingLeftValue();
}
return left;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLElement method getPosX.
/**
* Returns this element's X position.
* @return this element's X position
*/
public int getPosX() {
int cumulativeOffset = 0;
HTMLElement element = this;
while (element != null) {
cumulativeOffset += element.getOffsetLeft();
if (element != this) {
final ComputedCSSStyleDeclaration style = element.getWindow().getComputedStyle(element, null);
cumulativeOffset += style.getBorderLeftValue();
}
element = element.getOffsetParent();
}
return cumulativeOffset;
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLElement method getOffsetHeight.
/**
* Returns this element's <tt>offsetHeight</tt>, which is the element height plus the element's padding
* plus the element's border. This method returns a dummy value compatible with mouse event coordinates
* during mouse events.
* @return this element's <tt>offsetHeight</tt>
* @see <a href="http://msdn2.microsoft.com/en-us/library/ms534199.aspx">MSDN Documentation</a>
* @see <a href="http://www.quirksmode.org/js/elementdimensions.html">Element Dimensions</a>
*/
@JsxGetter
public int getOffsetHeight() {
if (isDisplayNone() || !getDomNodeOrDie().isAttachedToPage()) {
return 0;
}
final MouseEvent event = MouseEvent.getCurrentMouseEvent();
if (isAncestorOfEventTarget(event)) {
// compute appropriate offset height to pretend mouse event was produced within this element
return event.getClientY() - getPosY() + 50;
}
final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
return style.getCalculatedHeight(true, true);
}
use of com.gargoylesoftware.htmlunit.javascript.host.css.ComputedCSSStyleDeclaration in project htmlunit by HtmlUnit.
the class HTMLElement method getOffsetWidth.
/**
* Returns this element's <tt>offsetWidth</tt>, which is the element width plus the element's padding
* plus the element's border. This method returns a dummy value compatible with mouse event coordinates
* during mouse events.
* @return this element's <tt>offsetWidth</tt>
* @see <a href="http://msdn2.microsoft.com/en-us/library/ms534304.aspx">MSDN Documentation</a>
* @see <a href="http://www.quirksmode.org/js/elementdimensions.html">Element Dimensions</a>
*/
@JsxGetter
public int getOffsetWidth() {
if (isDisplayNone() || !getDomNodeOrDie().isAttachedToPage()) {
return 0;
}
final MouseEvent event = MouseEvent.getCurrentMouseEvent();
if (isAncestorOfEventTarget(event)) {
// compute appropriate offset width to pretend mouse event was produced within this element
return event.getClientX() - getPosX() + 50;
}
final ComputedCSSStyleDeclaration style = getWindow().getComputedStyle(this, null);
return style.getCalculatedWidth(true, true);
}
Aggregations