mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Implement offsetParent/Top/Left/Width/Height.
This commit is contained in:
parent
1809748dc1
commit
9e5687e3e7
21 changed files with 325 additions and 24 deletions
|
@ -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-*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue