Auto merge of #29711 - switchpiggy:sp3, r=mrobinson

Implemented special cases for Element.clientWidth() and clientHeight()

<!-- Please describe your changes on the following line: -->
Implemented the special cases for Element.clientWidth() and Element.clientHeight() as outlined in issue #29704.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because tests already exist.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

[Specification text](https://w3c.github.io/csswg-drafts/cssom-view/#dom-element-clientwidth):
> If the element is the [root element](https://w3c.github.io/csswg-drafts/css-display-4/#root-element) and the element’s [node document](https://dom.spec.whatwg.org/#concept-node-document) is not in [quirks mode](https://dom.spec.whatwg.org/#concept-document-quirks), or if the element is [the body element](https://html.spec.whatwg.org/multipage/dom.html#the-body-element-2) and the element’s node document is in quirks mode, return the [viewport](https://www.w3.org/TR/CSS21/visuren.html#x1) width excluding the size of a rendered scroll bar (if any).
This commit is contained in:
bors-servo 2023-05-08 13:56:51 +02:00 committed by GitHub
commit 419c03182f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 21 deletions

View file

@ -87,6 +87,7 @@ use crate::task::TaskOnce;
use devtools_traits::AttrInfo;
use dom_struct::dom_struct;
use euclid::default::Rect;
use euclid::default::Size2D;
use html5ever::serialize;
use html5ever::serialize::SerializeOpts;
use html5ever::serialize::TraversalScope;
@ -3292,7 +3293,25 @@ impl Element {
{
return rect;
}
let rect = self.upcast::<Node>().client_rect();
let mut rect = self.upcast::<Node>().client_rect();
let in_quirks_mode = self.node.owner_doc().quirks_mode() == QuirksMode::Quirks;
if (in_quirks_mode &&
self.node.owner_doc().GetBody().as_deref() == self.downcast::<HTMLElement>()) ||
(!in_quirks_mode && *self.root_element() == *self)
{
let viewport_dimensions = self
.node
.owner_doc()
.window()
.window_size()
.initial_viewport
.round()
.to_i32();
rect.size = Size2D::<i32>::new(viewport_dimensions.width, viewport_dimensions.height);
}
self.ensure_rare_data().client_rect = Some(window_from_node(self).cache_layout_value(rect));
rect
}

View file

@ -1,4 +0,0 @@
[client-props-root.html]
[client* properties on the root element]
expected: FAIL

View file

@ -2,9 +2,6 @@
[scrollingElement in non-quirks mode]
expected: FAIL
[clientWidth/clientHeight on the HTML body element in quirks mode]
expected: FAIL
[scrollLeft/scrollRight of the content in quirks mode]
expected: FAIL
@ -14,9 +11,6 @@
[scrollingElement in quirks mode]
expected: FAIL
[clientWidth/clientHeight on the root element in non-quirks mode]
expected: FAIL
[scrollWidth/scrollHeight on the root element in quirks mode]
expected: FAIL

View file

@ -1,4 +0,0 @@
[client-props-root.html]
[client* properties on the root element]
expected: FAIL

View file

@ -8,9 +8,6 @@
[scrollWidth/scrollHeight on the HTML body element in quirks mode]
expected: FAIL
[clientWidth/clientHeight on the HTML body element in quirks mode]
expected: FAIL
[scrollLeft/scrollRight of the content in quirks mode]
expected: FAIL
@ -20,9 +17,6 @@
[scrollWidth/scrollHeight on the root element in non-quirks mode]
expected: FAIL
[clientWidth/clientHeight on the root element in non-quirks mode]
expected: FAIL
[scroll() on the HTML body element in non-quirks mode]
expected: FAIL