mirror of
https://github.com/servo/servo.git
synced 2025-06-13 10:54:29 +00:00
Auto merge of #9824 - danlrobertson:element1, r=asajeffrey
Add the scrollWidth and scrollHeight extensions to the element interface Add the `scrollWidth` and `scrollHeight` extensions to the element interface. My goal was to create a method that encompassed getting `scrollWidth`, `scrollHeight`, `scrollTop`, and `scrollLeft`. I also noted that `clientHeight` and `clientWidth` to not handle the root element and the body element correctly. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9824) <!-- Reviewable:end -->
This commit is contained in:
commit
7ff7932a8c
10 changed files with 234 additions and 39 deletions
|
@ -1421,6 +1421,16 @@ impl ElementMethods for Element {
|
|||
rect.size.height.to_f64_px())
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth
|
||||
fn ScrollWidth(&self) -> i32 {
|
||||
self.upcast::<Node>().get_scroll_area().size.width
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollheight
|
||||
fn ScrollHeight(&self) -> i32 {
|
||||
self.upcast::<Node>().get_scroll_area().size.height
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-clienttop
|
||||
fn ClientTop(&self) -> i32 {
|
||||
self.upcast::<Node>().get_client_rect().origin.y
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -77,6 +77,9 @@ partial interface Element {
|
|||
DOMRectList getClientRects();
|
||||
DOMRect getBoundingClientRect();
|
||||
|
||||
readonly attribute long scrollWidth;
|
||||
readonly attribute long scrollHeight;
|
||||
|
||||
readonly attribute long clientTop;
|
||||
readonly attribute long clientLeft;
|
||||
readonly attribute long clientWidth;
|
||||
|
|
|
@ -1110,6 +1110,13 @@ impl Window {
|
|||
self.layout_rpc.hit_test().node_address
|
||||
}
|
||||
|
||||
pub fn scroll_area_query(&self, node: TrustedNodeAddress) -> Rect<i32> {
|
||||
self.reflow(ReflowGoal::ForScriptQuery,
|
||||
ReflowQueryType::NodeScrollGeometryQuery(node),
|
||||
ReflowReason::Query);
|
||||
self.layout_rpc.node_scroll_area().client_rect
|
||||
}
|
||||
|
||||
pub fn resolved_style_query(&self,
|
||||
element: TrustedNodeAddress,
|
||||
pseudo: Option<PseudoElement>,
|
||||
|
@ -1463,6 +1470,7 @@ fn debug_reflow_events(id: PipelineId, goal: &ReflowGoal, query_type: &ReflowQue
|
|||
ReflowQueryType::ContentBoxesQuery(_n) => "\tContentBoxesQuery",
|
||||
ReflowQueryType::HitTestQuery(_n, _o) => "\tHitTestQuery",
|
||||
ReflowQueryType::NodeGeometryQuery(_n) => "\tNodeGeometryQuery",
|
||||
ReflowQueryType::NodeScrollGeometryQuery(_n) => "\tNodeScrollGeometryQuery",
|
||||
ReflowQueryType::ResolvedStyleQuery(_, _, _) => "\tResolvedStyleQuery",
|
||||
ReflowQueryType::OffsetParentQuery(_n) => "\tOffsetParentQuery",
|
||||
ReflowQueryType::MarginStyleQuery(_n) => "\tMarginStyleQuery",
|
||||
|
|
|
@ -104,6 +104,8 @@ pub trait LayoutRPC {
|
|||
fn content_boxes(&self) -> ContentBoxesResponse;
|
||||
/// Requests the geometry of this node. Used by APIs such as `clientTop`.
|
||||
fn node_geometry(&self) -> NodeGeometryResponse;
|
||||
/// Requests the scroll geometry of this node. Used by APIs such as `scrollTop`.
|
||||
fn node_scroll_area(&self) -> NodeGeometryResponse;
|
||||
/// Requests the node containing the point of interest
|
||||
fn hit_test(&self) -> HitTestResponse;
|
||||
/// Query layout for the resolved value of a given CSS property
|
||||
|
@ -165,6 +167,7 @@ pub enum ReflowQueryType {
|
|||
ContentBoxesQuery(TrustedNodeAddress),
|
||||
HitTestQuery(Point2D<f32>, bool),
|
||||
NodeGeometryQuery(TrustedNodeAddress),
|
||||
NodeScrollGeometryQuery(TrustedNodeAddress),
|
||||
ResolvedStyleQuery(TrustedNodeAddress, Option<PseudoElement>, Atom),
|
||||
OffsetParentQuery(TrustedNodeAddress),
|
||||
MarginStyleQuery(TrustedNodeAddress),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue