mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add scrollWidth/Height to element interface
Add the scrollWidth and scrollHeight extensions to the element interface.
This commit is contained in:
parent
5fbed88248
commit
16d2778ece
10 changed files with 234 additions and 39 deletions
|
@ -18,6 +18,7 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
|
|||
use dom::bindings::codegen::Bindings::NodeBinding::{NodeConstants, NodeMethods};
|
||||
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
||||
use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||
use dom::bindings::conversions::{self, DerivedFrom};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
|
@ -37,6 +38,7 @@ use dom::documentfragment::DocumentFragment;
|
|||
use dom::documenttype::DocumentType;
|
||||
use dom::element::{Element, ElementCreator};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlbodyelement::HTMLBodyElement;
|
||||
use dom::htmlcollection::HTMLCollection;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::nodelist::NodeList;
|
||||
|
@ -45,8 +47,11 @@ use dom::range::WeakRangeVec;
|
|||
use dom::text::Text;
|
||||
use dom::virtualmethods::{VirtualMethods, vtable_for};
|
||||
use dom::window::Window;
|
||||
use euclid::point::Point2D;
|
||||
use euclid::rect::Rect;
|
||||
use euclid::size::Size2D;
|
||||
use heapsize::{HeapSizeOf, heap_size_of};
|
||||
use html5ever::tree_builder::QuirksMode;
|
||||
use js::jsapi::{JSContext, JSObject, JSRuntime};
|
||||
use layout_interface::{LayoutChan, Msg};
|
||||
use libc::{self, c_void, uintptr_t};
|
||||
|
@ -577,6 +582,42 @@ impl Node {
|
|||
window_from_node(self).client_rect_query(self.to_trusted_node_address())
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollheight
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrolltop
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollleft
|
||||
pub fn get_scroll_area(&self) -> Rect<i32> {
|
||||
// Step 1
|
||||
let document = self.owner_doc();
|
||||
// Step 3
|
||||
let window = document.window();
|
||||
|
||||
let html_element = document.GetDocumentElement();
|
||||
|
||||
let is_body_element = html_element.r().and_then(|root| {
|
||||
let node = root.upcast::<Node>();
|
||||
node.children().find(|child| { child.is::<HTMLBodyElement>() }).map(|node| {
|
||||
*node.r() == *self
|
||||
})
|
||||
}).unwrap_or(false);
|
||||
|
||||
let scroll_area = window.scroll_area_query(self.to_trusted_node_address());
|
||||
|
||||
match (document != window.Document(), is_body_element, document.quirks_mode(),
|
||||
html_element.r() == self.downcast::<Element>()) {
|
||||
// Step 2 && Step 5
|
||||
(true, _, _, _) | (_, false, QuirksMode::Quirks, true) => Rect::zero(),
|
||||
// Step 6 && Step 7
|
||||
(false, false, _, true) | (false, true, QuirksMode::Quirks, _) => {
|
||||
Rect::new(Point2D::new(window.ScrollX(), window.ScrollY()),
|
||||
Size2D::new(max(window.InnerWidth(), scroll_area.size.width),
|
||||
max(window.InnerHeight(), scroll_area.size.height)))
|
||||
},
|
||||
// Step 9
|
||||
_ => scroll_area
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-childnode-before
|
||||
pub fn before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||
// Step 1.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue