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` #19885

Closed
jonleighton opened this issue Jan 28, 2018 · 9 comments
Closed

Avoid `Window::GetComputedStyle` when checking for `display: none` #19885

jonleighton opened this issue Jan 28, 2018 · 9 comments

Comments

@jonleighton
Copy link
Contributor

@jonleighton jonleighton commented Jan 28, 2018

This can be done after #19881 is merged. See @emilio's comment:

I'm pretty sure we can use this to simplify and make stuff faster in canvasrenderingcontext2d.rs, and script_thread.rs, which right now call directly GetComputedStyle.

Those two files both contain calls to GetComputedStyle to check for display: none on an element. We can refactor them to use Node::style() instead.

@emilio
Copy link
Member

@emilio emilio commented Jan 28, 2018

(Or Element::has_css_layout_box, which is what they really want. They're both bogus, I think)

@emilio emilio added the E-easy label Jan 28, 2018
@highfive
Copy link

@highfive highfive commented Jan 28, 2018

Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

@emilio emilio removed the E-easy label Jan 28, 2018
@emilio
Copy link
Member

@emilio emilio commented Jan 28, 2018

Well, let me know if you want to take that before marking it as E-easy :).

@jonleighton
Copy link
Contributor Author

@jonleighton jonleighton commented Jan 28, 2018

I think leaving as E-easy is fine for now, could be a good first issue for someone :)

@emilio emilio added the E-easy label Jan 28, 2018
@highfive
Copy link

@highfive highfive commented Jan 28, 2018

Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

@emilio
Copy link
Member

@emilio emilio commented Jan 28, 2018

I think leaving as E-easy is fine for now, could be a good first issue for someone :)

Sounds great!

@alexfjw
Copy link
Contributor

@alexfjw alexfjw commented Jan 30, 2018

@highfive assign me

@highfive
Copy link

@highfive highfive commented Jan 30, 2018

Hey @alexfjw! Thanks for your interest in working on this issue. It's now assigned to you!

@highfive highfive added the C-assigned label Jan 30, 2018
@tigercosmos
Copy link
Collaborator

@tigercosmos tigercosmos commented Feb 4, 2018

@alexfjw I reply your letter here. (More clear to show code)

ComputedValue is trying to implement computed value in CSS. See https://developer.mozilla.org/zh-TW/docs/Web/CSS/computed_value
The detail reference is https://doc.servo.org/style/properties/struct.ComputedValues.html

GetComputedStyle's definition is

fn GetComputedStyle(&self,
element: &Element,
pseudo: Option<DOMString>) -> DomRoot<CSSStyleDeclaration> {
// Steps 1-4.
let pseudo = match pseudo.map(|mut s| { s.make_ascii_lowercase(); s }) {
Some(ref pseudo) if pseudo == ":before" || pseudo == "::before" =>
Some(PseudoElement::Before),
Some(ref pseudo) if pseudo == ":after" || pseudo == "::after" =>
Some(PseudoElement::After),
_ => None
};
// Step 5.
CSSStyleDeclaration::new(self,
CSSStyleOwner::Element(Dom::from_ref(element)),
pseudo,
CSSModificationAccess::Readonly)
}

P.S. When I encounter the new functions, I will search it for other examples like this

If you still not know how to do, I will suggest you to ping @jonleighton or @emilio. I thought they are nice to help you. Don't be shy to ask (I ask stupid questions all the time :P)

bors-servo added a commit that referenced this issue 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 added a commit that referenced this issue 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 added a commit that referenced this issue 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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.