Skip to content
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

Merged
merged 1 commit into from Feb 27, 2018
Merged

Avoid Window::GetComputedStyle when checking for display: none #20012

merged 1 commit into from Feb 27, 2018

Conversation

alexfjw
Copy link
Contributor

@alexfjw alexfjw commented Feb 10, 2018

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.


  • These changes do not require tests because it's a refactoring task

This change is Reviewable

@highfive
Copy link

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.

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/script_thread.rs, components/script/dom/canvasrenderingcontext2d.rs, components/script/dom/element.rs
  • @fitzgen: components/script/script_thread.rs, components/script/dom/canvasrenderingcontext2d.rs, components/script/dom/element.rs
  • @KiChjang: components/script/script_thread.rs, components/script/dom/canvasrenderingcontext2d.rs, components/script/dom/element.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Feb 10, 2018
@highfive
Copy link

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!


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)
}
Copy link
Member

@CYBAI CYBAI Feb 10, 2018

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))
}

Copy link
Contributor Author

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.

@alexfjw alexfjw changed the title Avoid Window::GetComputedStyle when checking for display: none [WIP] Avoid Window::GetComputedStyle when checking for display: none Feb 10, 2018
@alexfjw alexfjw changed the title [WIP] Avoid Window::GetComputedStyle when checking for display: none Avoid Window::GetComputedStyle when checking for display: none Feb 10, 2018
@jdm
Copy link
Member

jdm commented Feb 10, 2018

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit 32fae57 with merge ff97245...

bors-servo pushed a commit that referenced this pull request Feb 10, 2018
…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 -->
@bors-servo
Copy link
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Feb 10, 2018
@alexfjw alexfjw changed the title Avoid Window::GetComputedStyle when checking for display: none [WIP] Avoid Window::GetComputedStyle when checking for display: none Feb 10, 2018
@alexfjw
Copy link
Contributor Author

alexfjw commented Feb 10, 2018

Apologies, looks like I should have ran through all the css tests. I'll get the code fixed.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Feb 11, 2018
Copy link
Member

@emilio emilio left a 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),
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@alexfjw alexfjw changed the title [WIP] Avoid Window::GetComputedStyle when checking for display: none Avoid Window::GetComputedStyle when checking for display: none Feb 12, 2018
} 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),
Copy link
Member

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!

Copy link
Contributor Author

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.

@emilio
Copy link
Member

emilio commented Feb 12, 2018

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit c448e09 has been approved by emilio

@highfive highfive assigned emilio and unassigned metajack Feb 12, 2018
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Feb 12, 2018
@bors-servo
Copy link
Contributor

⌛ Testing commit c448e09 with merge aa59ad9...

bors-servo pushed a commit that referenced this pull request Feb 12, 2018
…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 -->
@bors-servo
Copy link
Contributor

💔 Test failed - windows-msvc-dev

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Feb 12, 2018
@emilio
Copy link
Member

emilio commented Feb 12, 2018

@bors-servo retry

@jdm
Copy link
Member

jdm commented Feb 12, 2018

@bors-servo r-

  ▶ TIMEOUT [expected OK] /_mozilla/mozilla/transitionend_safety.html
  │ 
  │ VMware, Inc.
  │ softpipe
  └ 3.3 (Core Profile) Mesa 17.3.0-devel

  ▶ Unexpected subtest result in /_mozilla/mozilla/transitionend_safety.html:
  │ TIMEOUT [expected PASS] Nodes cannot be GCed while a CSS transition is in effect.
  └   → Test timed out

These tests still fail consistently.

@alexfjw
Copy link
Contributor Author

alexfjw commented Feb 13, 2018

@emilio
I'm sorry but I'm not really sure why the test fails. Hope you could help me out.
It looks to me like checking Window.GetComputedStyle(element).Display() == 'none' is the same as checking !element.has_css_layout_box(). However, they return different values in the failing test, the former being false and latter true.

The wiki's article on layout styling mentions Window.getComputedStyle() method sometimes returns used values and sometimes computed values, but I'm not sure if that point is relevant here.

//Edit, missed out a !

@emilio
Copy link
Member

emilio commented Feb 13, 2018

I think that test is wrong, and I suspect it'll fail on other browsers. has_css_layout_box is definitely not the same as GetComputedStyle().Display() == "none". For example, if the node is outside of the document, the element would not have a layout box, regardless of the computed value of the Display property. Similarly if the element is under a display: none parent, it'll have no layout box, even though its display will not be none.

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 step_func_done to a timeout? The test looks invalid to me.

@jdm
Copy link
Member

jdm commented Feb 14, 2018

A timeout seems like the best choice to me, rather than losing test coverage of a safety issue.

@emilio
Copy link
Member

emilio commented Feb 24, 2018

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!

@alexfjw
Copy link
Contributor Author

alexfjw commented Feb 25, 2018

Apologies, was a little busy the past week. Yep, I'll try to finish it up soon

@emilio
Copy link
Member

emilio commented Feb 25, 2018

No problem, thank you very much!

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Feb 26, 2018
@alexfjw
Copy link
Contributor Author

alexfjw commented Feb 26, 2018

@emilio, would something like this be fine? Or did you mean updating the test expectation to accept a timeout?

Copy link
Member

@emilio emilio left a 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!

@emilio
Copy link
Member

emilio commented Feb 26, 2018

Looks like you need to update the manifest:

diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json
index 892d423d8..2cd4e0050 100644
--- a/tests/wpt/mozilla/meta/MANIFEST.json
+++ b/tests/wpt/mozilla/meta/MANIFEST.json
@@ -70817,7 +70817,7 @@
    "testharness"
   ],
   "mozilla/transitionend_safety.html": [
-   "778e43b049aa421bad7f86eb03d0955576a84ce0",
+   "16d238e94b2cc2843c9aee4210db43d496bb3114",
    "testharness"
   ],
   "mozilla/union.html": [

@emilio
Copy link
Member

emilio commented Feb 27, 2018

@bors-servo r+

Thanks!

@bors-servo
Copy link
Contributor

📌 Commit 8d09398 has been approved by emilio

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Feb 27, 2018
@bors-servo
Copy link
Contributor

⌛ Testing commit 8d09398 with merge ac162e8...

bors-servo pushed a commit that referenced this pull request Feb 27, 2018
…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 -->
@bors-servo
Copy link
Contributor

☀️ 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
Approved by: emilio
Pushing ac162e8 to master...

@bors-servo bors-servo merged commit 8d09398 into servo:master Feb 27, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid Window::GetComputedStyle when checking for display: none
7 participants