Skip to content

Implement support for removing stylesheets from their document - #14930

Merged
bors-servo merged 4 commits into
servo:masterfrom
zaynetro:remove-stylesheets
Jan 24, 2017
Merged

bors-servo merged 4 commits into
servo:masterfrom
zaynetro:remove-stylesheets

Conversation

@zaynetro

@zaynetro zaynetro commented Jan 9, 2017 •

Copy link
Copy Markdown
Contributor

This pull request implements removing styles from the document when

  • <link> element with associated styles is removed
  • <style> element is removed

Additionally, it tests that when <style> element is changed. Styles are being reapplied correctly.


  • There are tests for these changes

This change is Reviewable

@highfive

highfive commented Jan 9, 2017

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmllinkelement.rs
  • @KiChjang: components/script/dom/htmllinkelement.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 9, 2017
@Manishearth

Copy link
Copy Markdown
Member

I don't see any handling for style elements?

@zaynetro

zaynetro commented Jan 9, 2017

Copy link
Copy Markdown
Contributor Author

I was also surprised by it. Either the test is wrong or styles are recalculated in some other way, I hope you can help.

@Manishearth

Copy link
Copy Markdown
Member

r? @SimonSapin

I don't know much about invalidation, I'm afraid.

@highfive highfive assigned SimonSapin and unassigned Manishearth Jan 9, 2017
@SimonSapin

Copy link
Copy Markdown
Member

For <style> elements, I suspect that the test’s script updates/removes them before any styling is done, so there is nothing yet to invalidate. Try to use getComputedStyle before the update/removal to observe the previous style and force styling, and make sure the tests fail. Then adding or changing some Rust code should fix the tests.


Reviewed 3 of 3 files at r1, 5 of 5 files at r2, 3 of 3 files at r3.
Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed.


tests/wpt/mozilla/tests/mozilla/remove_link_styles.css, line 3 at r2 (raw file):

body {
    background-color: orange;
    color: yellow;

Unless you need multiple different colors, please stick to red for incorrect and green for correct, so that someone debugging the test visually doesn’t need to look at the reference to see what color is expected.


tests/wpt/mozilla/tests/mozilla/remove_link_styles.html, line 5 at r2 (raw file):

<title>Removing link tag should remove associated styles</title>
<link rel="match" href="remove_link_styles_ref.html">
<link rel="stylesheet" type="text/css" href="remove_link_styles.css">

Since <link rel=stylesheet> happens before <style> and the two stylesheets have rule with identical specificity, the latter will "win" the cascade even before the stylesheet is removed. Either reverse their order, use a more specific selector, or use !important.


tests/wpt/mozilla/tests/mozilla/remove_link_styles.html, line 9 at r2 (raw file):

    <style>
        body {
            color: pink;

The color property is used, there is no text that would use it. Please add some text, preferably something descriptive that says what a successful result should look like.


tests/wpt/mozilla/tests/mozilla/remove_style_styles.html, line 8 at r3 (raw file):

    <style>
        body {
            background-color: purple;

Nit: use red for incorrect test results.


tests/wpt/mozilla/tests/mozilla/remove_style_styles_ref.html, line 4 at r3 (raw file):

<meta charset="utf-8">
<body>
</body>

Avoid completely empty/white test or reference files, since we can’t tell them apart from a potential bug where a screenshot is taken before anything is rendered. Please include at least some text, and while you’re at it make it descriptive.


tests/wpt/mozilla/tests/mozilla/reparse_style_elements.html, line 14 at r1 (raw file):

    <script>
        var s = document.querySelector('body > style');
        s.textContent = 'body { color: green; }';

Nit: this test works as-is, but since this is using the color property please add some text content so that color applies to something. Something descriptive like "This test should be green and the background should not be red."


Comments from Reviewable

@zaynetro

Copy link
Copy Markdown
Contributor Author

@SimonSapin good call with using getComputedStyle to force styling. I managed to make the test to fail. Now I will start working on removing styles when style element is removed.

@SimonSapin SimonSapin added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 13, 2017
@zaynetro

Copy link
Copy Markdown
Contributor Author

I was busy during the previous week. I will continue looking into this closer to the end of the current week.

@zaynetro

Copy link
Copy Markdown
Contributor Author

I think I need some help with figuring out how to remove stylesheet added by <style> element.

Some of my findings (doesn't mean they are relevant to the problem):

  1. When children of htmlstyleelement.rs have changed we parse_own_css and then send newly parsed stylesheet with:
win.layout_chan().send(Msg::AddStylesheet(sheet.clone())).unwrap();

I will get back to this later (A)

  1. After sending stylesheet to window layout channel we invalidate stylesheets with doc.invalidate_stylesheets();. Implementation of Document::invalidate_stylesheets() tells me nothing about what is actually happening behind this function call. Where can I look to better understand what is actually going on there?

Returning back to (A). When we receive new stylesheet in layout thread we handle_add_stylesheet. So we load fonts(??) in add_font_face_rules. This is a bit confusing to me as I don't see the place where the stylesheet is being applied to the document.

The problem: I want to remove previously added stylesheet when <style> element is removed from the DOM. For this reason I'd like to have an understanding of the actions described before. Please, let me know if I am looking at the right direction.

    fn unbind_from_tree(&self, context: &UnbindContext) {
        if let Some(ref s) = self.super_type() {
            s.unbind_from_tree(context);
        }

        // Some magic code that will remove stylesheet from the document
    }

@jdm

jdm commented Jan 20, 2017 •

Copy link
Copy Markdown
Member

@zaynetro One piece you're missing is the implementation of Window::force_reflow, which is called when the script thread needs to tell the layout thread to reflow the document. This calls document.get_and_reset_stylesheets_changed_since_reflow(), which is a boolean passed to the layout thread along with all of the known stylesheets in the document - in layout_thread/lib.rs, the stylesheets_changed boolean is passed to Stylist::update in order to determine the stylesheets that are applied to the document.

@jdm

jdm commented Jan 20, 2017 •

Copy link
Copy Markdown
Member

As far as removing the stylesheet from unbind_from_tree, the important bit of Document::invalidate_stylesheets() is that it sets the stylesheets field to None. Next time layout happens, this us to find all of the stylesheets that currently exist in the tree (see Document::ensure_stylesheets()) and pass them to layout, which should have the effect you're looking for.

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jan 20, 2017
@zaynetro

zaynetro commented Jan 20, 2017 •

Copy link
Copy Markdown
Contributor Author

Thanks for the explanations!

I've just written a huge post that Document::invalidate_stylesheets doesn't work in this case, but before submitting it I decided to double check everything. The reason it was failing the test was a silly typo. In the test I have a JS function call window.getComputedStyle(document.body); but originally the function was window.getComputedStyles( . :(

Sorry, it took me a while to find out the root cause. Hopefully, everything should be fine now.

@jdm

jdm commented Jan 20, 2017

Copy link
Copy Markdown
Member

@bors-servo: try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 2135d3d with merge d0ae98b...

bors-servo pushed a commit that referenced this pull request Jan 20, 2017
Implement support for removing stylesheets from their document

<!-- Please describe your changes on the following line: -->
This pull request implements removing styles from the document when

* `<link>` element with associated styles is removed
* `<style>` element is removed

Additionally, it tests that when `<style>` element is changed. Styles are being reapplied correctly.

---
<!-- 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 #14886 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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/14930)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jan 20, 2017
@jdm

jdm commented Jan 20, 2017

Copy link
Copy Markdown
Member
  ▶ Unexpected subtest result in /subresource-integrity/subresource-integrity.sub.html:
  └ PASS [expected FAIL] Style: Same-origin with incorrect hash.

  ▶ Unexpected subtest result in /subresource-integrity/subresource-integrity.sub.html:
  └ PASS [expected FAIL] Style: Same-origin with sha256 match, sha512 mismatch

  ▶ Unexpected subtest result in /subresource-integrity/subresource-integrity.sub.html:
  └ PASS [expected FAIL] Style: <crossorigin='anonymous'> with incorrect hash, ACAO: *

  ▶ Unexpected subtest result in /subresource-integrity/subresource-integrity.sub.html:
  └ PASS [expected FAIL] Style: <crossorigin='use-credentials'> with incorrect hash CORS-eligible

  ▶ Unexpected subtest result in /subresource-integrity/subresource-integrity.sub.html:
  └ PASS [expected FAIL] Style: <crossorigin='anonymous'> with CORS-ineligible resource

  ▶ Unexpected subtest result in /subresource-integrity/subresource-integrity.sub.html:
  └ PASS [expected FAIL] Style: Cross-origin, not CORS request, with correct hash

  ▶ Unexpected subtest result in /subresource-integrity/subresource-integrity.sub.html:
  └ PASS [expected FAIL] Style: Cross-origin, not CORS request, with hash mismatch

Very nice.

@emilio

emilio commented Jan 22, 2017

Copy link
Copy Markdown
Member

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit d4ddafd with merge fa1178c...

bors-servo pushed a commit that referenced this pull request Jan 22, 2017
Implement support for removing stylesheets from their document

<!-- Please describe your changes on the following line: -->
This pull request implements removing styles from the document when

* `<link>` element with associated styles is removed
* `<style>` element is removed

Additionally, it tests that when `<style>` element is changed. Styles are being reapplied correctly.

---
<!-- 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 #14886 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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/14930)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

@emilio

emilio commented Jan 22, 2017 •

Copy link
Copy Markdown
Member

@bors-servo r+

Thanks a lot for these changes @zaynetro! :)

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit d4ddafd 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 Jan 22, 2017
@highfive highfive assigned emilio and unassigned SimonSapin Jan 22, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

💡 This pull request was already approved, no need to approve it again.

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit d4ddafd has been approved by emilio

@Ms2ger

Ms2ger commented Jan 24, 2017

Copy link
Copy Markdown
Contributor

@bors-servo try- retry

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit d4ddafd with merge dbdcfa6...

bors-servo pushed a commit that referenced this pull request Jan 24, 2017
Implement support for removing stylesheets from their document

<!-- Please describe your changes on the following line: -->
This pull request implements removing styles from the document when

* `<link>` element with associated styles is removed
* `<style>` element is removed

Additionally, it tests that when `<style>` element is changed. Styles are being reapplied correctly.

---
<!-- 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 #14886 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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/14930)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
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 Jan 24, 2017
@Ms2ger

Ms2ger commented Jan 24, 2017

Copy link
Copy Markdown
Contributor

@bors-servo retry servo/saltfs#585

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit d4ddafd with merge f3c102d...

bors-servo pushed a commit that referenced this pull request Jan 24, 2017
Implement support for removing stylesheets from their document

<!-- Please describe your changes on the following line: -->
This pull request implements removing styles from the document when

* `<link>` element with associated styles is removed
* `<style>` element is removed

Additionally, it tests that when `<style>` element is changed. Styles are being reapplied correctly.

---
<!-- 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 #14886 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes

<!-- 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/14930)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jan 24, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

@bors-servo
bors-servo merged commit d4ddafd into servo:master Jan 24, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 24, 2017
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.

Implement support for removing stylesheets from their document.

9 participants