aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlelement.rs
diff options
context:
space:
mode:
authorGlenn Watson <gw@intuitionlibrary.com>2015-07-27 15:20:27 +1000
committerGlenn Watson <gw@intuitionlibrary.com>2015-08-03 11:55:38 +1000
commit9e5687e3e72f2c79bf17bcfb33ea33f0659377ac (patch)
tree747b19a3de028cebc1dca77f6edd1a38fba1cf33 /components/script/dom/htmlelement.rs
parent1809748dc12ec63e3179b66109c91983f744c235 (diff)
downloadservo-9e5687e3e72f2c79bf17bcfb33ea33f0659377ac.tar.gz
servo-9e5687e3e72f2c79bf17bcfb33ea33f0659377ac.zip
Implement offsetParent/Top/Left/Width/Height.
Diffstat (limited to 'components/script/dom/htmlelement.rs')
-rw-r--r--components/script/dom/htmlelement.rs59
1 files changed, 58 insertions, 1 deletions
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index 513a9d39775..376bec890cc 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -12,7 +12,7 @@ use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementM
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFrameSetElementDerived};
use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLInputElementCast, NodeCast};
-use dom::bindings::codegen::InheritTypes::{HTMLElementDerived, HTMLBodyElementDerived};
+use dom::bindings::codegen::InheritTypes::{HTMLElementDerived, HTMLBodyElementDerived, HTMLHtmlElementDerived};
use dom::bindings::js::{JS, MutNullableHeap, Root};
use dom::bindings::error::ErrorResult;
use dom::bindings::error::Error::Syntax;
@@ -216,6 +216,63 @@ impl<'a> HTMLElementMethods for &'a HTMLElement {
// If `request_focus` is not called, focus will be set to None.
document.r().commit_focus_transaction(FocusType::Element);
}
+
+ // https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
+ fn GetOffsetParent(self) -> Option<Root<Element>> {
+ if self.is_htmlbodyelement() || self.is_htmlhtmlelement() {
+ return None;
+ }
+
+ let node = NodeCast::from_ref(self);
+ let window = window_from_node(self);
+ let (element, _) = window.offset_parent_query(node.to_trusted_node_address());
+
+ element
+ }
+
+ // https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
+ fn OffsetTop(self) -> i32 {
+ if self.is_htmlbodyelement() {
+ return 0;
+ }
+
+ let node = NodeCast::from_ref(self);
+ let window = window_from_node(self);
+ let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
+
+ rect.origin.y.to_nearest_px()
+ }
+
+ // https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
+ fn OffsetLeft(self) -> i32 {
+ if self.is_htmlbodyelement() {
+ return 0;
+ }
+
+ let node = NodeCast::from_ref(self);
+ let window = window_from_node(self);
+ let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
+
+ rect.origin.x.to_nearest_px()
+ }
+
+ // https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
+ fn OffsetWidth(self) -> i32 {
+ let node = NodeCast::from_ref(self);
+ let window = window_from_node(self);
+ let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
+
+ rect.size.width.to_nearest_px()
+ }
+
+ // https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
+ fn OffsetHeight(self) -> i32 {
+ let node = NodeCast::from_ref(self);
+ let window = window_from_node(self);
+ let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
+
+ rect.size.height.to_nearest_px()
+ }
}
// https://html.spec.whatwg.org/#attr-data-*