New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid Window::GetComputedStyle
when checking for display: none
#20012
Avoid Window::GetComputedStyle
when checking for display: none
#20012
Conversation
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @metajack (or someone else) soon. |
Heads up! This PR modifies the following files:
|
|
||
if element_not_rendered { | ||
Ok(RGBA::new(0, 0, 0, 255)) | ||
} else { | ||
self.parse_color(&style.GetPropertyValue(DOMString::from("color"))) | ||
Ok(style.unwrap().get_color().color) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering will it be better to use pattern matching for style
here?
Ex.
let style = canvas.upcast::<Element>().style();
match (style) {
Some(s) if canvas.upcast::<Node>().is_in_doc() => Ok(s.get_color().color),
_ => Ok(RGBA::new(0, 0, 0, 255))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was pondering on that as well but couldn't think of a good way to write it. Thanks for the suggestion, I'll try it out.
Window::GetComputedStyle
when checking for display: none
Window::GetComputedStyle
when checking for display: none
Window::GetComputedStyle
when checking for display: none
Window::GetComputedStyle
when checking for display: none
@bors-servo try |
…cking_for_display-none, r=<try> Avoid `Window::GetComputedStyle` when checking for `display: none` <!-- Please describe your changes on the following line: --> Refactored Window::GetComputedStyle to use Element::Style. Not sure which tests are relevant, but I've ran the dom, fetch & 2dcontext wpt tests. They don't seem to give errors. --- <!-- 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 - [x] These changes fix #19885. <!-- Either: --> - [x] These changes do not require tests because it's a refactoring task <!-- 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. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20012) <!-- Reviewable:end -->
💔 Test failed - linux-rel-wpt |
Window::GetComputedStyle
when checking for display: none
Window::GetComputedStyle
when checking for display: none
Apologies, looks like I should have ran through all the css tests. I'll get the code fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great with that tiny bit fixed, thanks!
} else { | ||
self.parse_color(&style.GetPropertyValue(DOMString::from("color"))) | ||
match style { | ||
Some(ref s) if canvas.upcast::<Node>().is_in_doc() => Ok(s.get_color().color), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to check whether s.get_box().display
is not Display::None
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you should be able to assert that is_in_doc()
if the style is Some(..)
. But checking it explicitly doesn't hurt I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks emilio! I realised about s.get_box().display
from the error I made previously. Was wondering about is_in_doc()
as well but wasn't too sure & decided to spend some time reading up.
Window::GetComputedStyle
when checking for display: none
Window::GetComputedStyle
when checking for display: none
} else { | ||
self.parse_color(&style.GetPropertyValue(DOMString::from("color"))) | ||
match canvas_element.style() { | ||
Some(ref s) if canvas_element.has_css_layout_box() => Ok(s.get_color().color), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The has_css_layout_box
check whole new style query, which is somewhat unfortunate, but can be fixed in a followup I guess.
Thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man, didn't realize that style queries were expensive. Thanks for the help as well! I've learnt quite a bit from this PR.
@bors-servo r+ |
📌 Commit c448e09 has been approved by |
…cking_for_display-none, r=emilio Avoid `Window::GetComputedStyle` when checking for `display: none` <!-- Please describe your changes on the following line: --> Refactored Window::GetComputedStyle to use Element::Style. Not sure which tests are relevant, but I've ran the dom, fetch & 2dcontext wpt tests. They don't seem to give errors. --- <!-- 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 - [x] These changes fix #19885. <!-- Either: --> - [x] These changes do not require tests because it's a refactoring task <!-- 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. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20012) <!-- Reviewable:end -->
💔 Test failed - windows-msvc-dev |
@bors-servo retry |
@bors-servo r-
These tests still fail consistently. |
@emilio The wiki's article on layout styling mentions //Edit, missed out a ! |
I think that test is wrong, and I suspect it'll fail on other browsers. Not firing transitionend for an element outside of the document seems what other browsers do and what the spec mandates, too. @jdm would you be fine with removing that test-case, or maybe moving the |
A timeout seems like the best choice to me, rather than losing test coverage of a safety issue. |
Hi @alexfjw are you planning to finish this up? It should be a matter of marking the test as an expected timeout. Let me know if you have any question on how to do that, happy to help! |
Apologies, was a little busy the past week. Yep, I'll try to finish it up soon |
No problem, thank you very much! |
@emilio, would something like this be fine? Or did you mean updating the test expectation to accept a timeout? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to just let the harness expect a timeout, but this wfm too. Thanks!
Looks like you need to update the manifest:
|
@bors-servo r+ Thanks! |
📌 Commit 8d09398 has been approved by |
…cking_for_display-none, r=emilio Avoid `Window::GetComputedStyle` when checking for `display: none` <!-- Please describe your changes on the following line: --> Refactored Window::GetComputedStyle to use Element::Style. Not sure which tests are relevant, but I've ran the dom, fetch & 2dcontext wpt tests. They don't seem to give errors. --- <!-- 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 - [x] These changes fix #19885. <!-- Either: --> - [x] These changes do not require tests because it's a refactoring task <!-- 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. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20012) <!-- Reviewable:end -->
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
Refactored Window::GetComputedStyle to use Element::Style.
Not sure which tests are relevant, but I've ran the dom, fetch & 2dcontext wpt tests. They don't seem to give errors.
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsWindow::GetComputedStyle
when checking fordisplay: none
#19885.This change is