diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/element.rs | 12 | ||||
-rw-r--r-- | components/script/dom/node.rs | 54 | ||||
-rw-r--r-- | components/script/dom/window.rs | 38 |
3 files changed, 51 insertions, 53 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 31ea2701c82..f204b95f3b4 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -584,6 +584,13 @@ impl Element { node.parent_directionality() }) } + + pub(crate) fn is_root(&self) -> bool { + match self.node.GetParentNode() { + None => false, + Some(node) => node.is::<Document>(), + } + } } #[inline] @@ -3194,10 +3201,7 @@ impl<'a> SelectorsElement for DomRoot<Element> { } fn is_root(&self) -> bool { - match self.node.GetParentNode() { - None => false, - Some(node) => node.is::<Document>(), - } + Element::is_root(self) } fn is_empty(&self) -> bool { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 4758c28717d..d360ee3694f 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -16,7 +16,7 @@ use app_units::Au; use bitflags::bitflags; use devtools_traits::NodeInfo; use dom_struct::dom_struct; -use euclid::default::{Point2D, Rect, Size2D, Vector2D}; +use euclid::default::{Rect, Size2D, Vector2D}; use html5ever::{namespace_url, ns, Namespace, Prefix, QualName}; use js::jsapi::JSObject; use js::rust::HandleObject; @@ -808,38 +808,42 @@ impl Node { // https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth // https://drafts.csswg.org/cssom-view/#dom-element-scrollheight pub fn scroll_area(&self) -> Rect<i32> { - // Step 1 + // "1. Let document be the element’s node document."" let document = self.owner_doc(); - // Step 3 - let window = document.window(); - let html_element = document.GetDocumentElement(); + // "2. If document is not the active document, return zero and terminate these steps."" + if !document.is_active() { + return Rect::zero(); + } + + // "3. Let viewport width/height be the width of the viewport excluding the width/height of the + // scroll bar, if any, or zero if there is no viewport." + let window = document.window(); + let viewport = Size2D::new(window.InnerWidth(), window.InnerHeight()); + let in_quirks_mode = document.quirks_mode() == QuirksMode::Quirks; + let is_root = self.downcast::<Element>().map_or(false, |e| e.is_root()); let is_body_element = self .downcast::<HTMLBodyElement>() .map_or(false, |e| e.is_the_html_body_element()); - let scroll_area = window.scroll_area_query(self); - - match ( - document != window.Document(), - is_body_element, - document.quirks_mode(), - html_element.as_deref() == 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( - cmp::max(window.InnerWidth(), scroll_area.size.width), - cmp::max(window.InnerHeight(), scroll_area.size.height), - ), - ), - // Step 9 - _ => scroll_area, + // "4. If the element is the root element and document is not in quirks mode + // return max(viewport scrolling area width/height, viewport width/height)." + // "5. If the element is the body element, document is in quirks mode and the + // element is not potentially scrollable, return max(viewport scrolling area + // width, viewport width)." + if (is_root && !in_quirks_mode) || (is_body_element && in_quirks_mode) { + let viewport_scrolling_area = window.scrolling_area_query(None); + return Rect::new( + viewport_scrolling_area.origin, + viewport_scrolling_area.size.max(viewport), + ); } + + // "6. If the element does not have any associated box return zero and terminate + // these steps." + // "7. Return the width of the element’s scrolling area." + window.scrolling_area_query(Some(self)) } pub fn scroll_offset(&self) -> Vector2D<f32> { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index ce7306e8e1b..a0af8e2537d 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1721,26 +1721,13 @@ impl Window { // Step 7 & 8 // TODO: Consider `block-end` and `inline-end` overflow direction. - let body = self.Document().GetBody(); - let (x, y) = match body { - Some(e) => { - // This doesn't properly take into account the overflow set on <body> - // and the root element, which might affect how much the root can - // scroll. That requires properly handling propagating those values - // according to the rules defined in in the specification at: - // https://w3c.github.io/csswg-drafts/css-overflow/#overflow-propagation - let scroll_area = e.upcast::<Node>().bounding_content_box_or_zero(); - ( - xfinite - .min(scroll_area.width().to_f64_px() - viewport.width as f64) - .max(0.0f64), - yfinite - .min(scroll_area.height().to_f64_px() - viewport.height as f64) - .max(0.0f64), - ) - }, - None => (xfinite.max(0.0f64), yfinite.max(0.0f64)), - }; + let scrolling_area = self.scrolling_area_query(None); + let x = xfinite + .min(scrolling_area.width() as f64 - viewport.width as f64) + .max(0.0f64); + let y = yfinite + .min(scrolling_area.height() as f64 - viewport.height as f64) + .max(0.0f64); // Step 10 //TODO handling ongoing smooth scrolling @@ -2113,11 +2100,14 @@ impl Window { self.layout_rpc.node_geometry().client_rect } - pub fn scroll_area_query(&self, node: &Node) -> UntypedRect<i32> { - if !self.layout_reflow(QueryMsg::NodeScrollGeometryQuery(node.to_opaque())) { + /// Find the scroll area of the given node, if it is not None. If the node + /// is None, find the scroll area of the viewport. + pub fn scrolling_area_query(&self, node: Option<&Node>) -> UntypedRect<i32> { + let opaque = node.map(|node| node.to_opaque()); + if !self.layout_reflow(QueryMsg::ScrollingAreaQuery(opaque)) { return Rect::zero(); } - self.layout_rpc.node_scroll_area().client_rect + self.layout_rpc.scrolling_area().client_rect } pub fn scroll_offset_query(&self, node: &Node) -> Vector2D<f32, LayoutPixel> { @@ -2748,7 +2738,7 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow &QueryMsg::ContentBoxesQuery(_n) => "\tContentBoxesQuery", &QueryMsg::NodesFromPointQuery(..) => "\tNodesFromPointQuery", &QueryMsg::ClientRectQuery(_n) => "\tClientRectQuery", - &QueryMsg::NodeScrollGeometryQuery(_n) => "\tNodeScrollGeometryQuery", + &QueryMsg::ScrollingAreaQuery(_n) => "\tNodeScrollGeometryQuery", &QueryMsg::NodeScrollIdQuery(_n) => "\tNodeScrollIdQuery", &QueryMsg::ResolvedStyleQuery(_, _, _) => "\tResolvedStyleQuery", &QueryMsg::ResolvedFontStyleQuery(..) => "\nResolvedFontStyleQuery", |