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

Immutable CSSOM #14190

Merged
merged 6 commits into from Nov 16, 2016
Merged

Immutable CSSOM #14190

merged 6 commits into from Nov 16, 2016

Conversation

@Manishearth
Copy link
Member

Manishearth commented Nov 12, 2016

This PR is intended to add basic support for all CSSOM interfaces, with the ability to index document.styleSheets and css rule lists, and serializing individual css rules. Handling individual interface methods for CSSRule subclasses can probably be done with easy/medium bugs.

Mutation safety isn't dealt with here; if the css rule list is mutated the CSSOM will be in an inconsistent state. I intend to deal with this via zero sized tokens, see https://groups.google.com/forum/#!topic/mozilla.dev.servo/AnxJoVmtMXQ . I'll handle that when I start making the CSSOM mutable. (Getting the immutable bit landed first opens this up for easy bugs)

This doesn't really change style aside from adding an extra arc in the CSS rule list as discussed in the linked thread. So far this same design can be used by stylo as well when the time comes.

f? @SimonSapin @emilio

cc @upsuper

part of #11420
Todo:

  • Stubs for rest of the CSSRule subclasses
  • ToCSS impls for CSSRules. May make into easy bugs and stub out in this PR #14195
  • Cache CSSStyleSheet on the relevant node

This change is Reviewable

@highfive
Copy link

highfive commented Nov 12, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/selector_matching.rs, components/style/stylesheets.rs
  • @KiChjang: components/script/dom/cssrule.rs, components/script/dom/document.rs, components/script/dom/webidls/MediaQueryList.idl, components/script/dom/mod.rs, components/script/dom/cssstylerule.rs, components/script/dom/webidls/CSSStyleRule.webidl, components/script/dom/cssrulelist.rs, components/script/dom/htmlmetaelement.rs, components/script/dom/webidls/CSSStyleSheet.webidl, components/script/dom/webidls/CSSRule.webidl, components/script/dom/stylesheetlist.rs, components/script/dom/cssstylesheet.rs, components/script/dom/stylesheet.rs, components/script/dom/webidls/CSSRuleList.webidl
  • @fitzgen: components/script/dom/cssrule.rs, components/script/dom/document.rs, components/script/dom/webidls/MediaQueryList.idl, components/script/dom/mod.rs, components/script/dom/cssstylerule.rs, components/script/dom/webidls/CSSStyleRule.webidl, components/script/dom/cssrulelist.rs, components/script/dom/htmlmetaelement.rs, components/script/dom/webidls/CSSStyleSheet.webidl, components/script/dom/webidls/CSSRule.webidl, components/script/dom/stylesheetlist.rs, components/script/dom/cssstylesheet.rs, components/script/dom/stylesheet.rs, components/script/dom/webidls/CSSRuleList.webidl
  • @emilio: components/style/selector_matching.rs, components/style/stylesheets.rs
@highfive
Copy link

highfive commented Nov 12, 2016

warning Warning warning

  • These commits modify style and script code, but no tests are modified. Please consider adding a test!
@@ -112,7 +120,7 @@ pub struct KeyframesRule {
#[derive(Debug)]
pub struct MediaRule {
pub media_queries: Arc<RwLock<MediaList>>,
pub rules: Vec<CSSRule>,
pub rules: CSSRules,

This comment has been minimized.

Copy link
@upsuper

upsuper Nov 13, 2016

Member

I think this would likely make it meaningless to wrap MediaRule in RwLock anymore. Probably we can do fine-grained lock everywhere...

This comment has been minimized.

Copy link
@Manishearth

Manishearth Nov 13, 2016

Author Member

Yeah a lot of the rwlocks will move around when I work on the mutable stuff.

This comment has been minimized.

Copy link
@SimonSapin

SimonSapin Nov 14, 2016

Member

@upsuper I don’t understand what you mean here.

This comment has been minimized.

Copy link
@upsuper

upsuper Nov 14, 2016

Member

@SimonSapin Wrapping content of rules into Arc means we need to further wrap it into RwLock as well, otherwise it would not be as mutable as we expect. And wrapping both fields of MediaRule into Arc<RwLock> means there is likely no more need of mutating the struct itself, so it doesn't make sense anymore to have it wrapped in RwLock.

This comment has been minimized.

Copy link
@SimonSapin

SimonSapin Nov 14, 2016

Member

I see, thanks. I think this is ok for now, and I expect that once we have CSSOM functional in Servo and Stylo we’ll likely to a pass at simplifying/optimizing things.

@Manishearth Manishearth force-pushed the Manishearth:cssom branch 4 times, most recently from 5be9528 to d4ef7a0 Nov 13, 2016
@Manishearth Manishearth changed the title [WIP] Immutable CSSOM Immutable CSSOM Nov 14, 2016
@Manishearth Manishearth force-pushed the Manishearth:cssom branch from d4ef7a0 to 339259d Nov 14, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Nov 14, 2016

Ready for review.

r? @SimonSapin

I have not implemented ToCss, so the .cssText() getter will spew out Debug output for everything but style rules. Going to open bugs for these.

CORS isn't handled either; so you can read the contents of a cross-origin stylesheet. This doesn't seem like a big deal (for now) to me, but I can implement this if necessary.

In the current implementation, the CSSOM is lazy at every step. [SameObject] is satisfied, including for the semantics of the indexers, however CSSOM objects don't get created until you ask for them (but once you ask for them asking for the same one will get you the same object). I'm not sure if we need to do this; if just document.styleSheets[i] was lazy most of the problems of lugging around the full CSSOM for every page that doesn't need it would be solved, but being fully lazy is nice. Let me know if I should change that.

@highfive highfive assigned SimonSapin and unassigned metajack Nov 14, 2016
@Manishearth Manishearth force-pushed the Manishearth:cssom branch from 339259d to caac2bc Nov 14, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Nov 14, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Nov 14, 2016

Trying commit caac2bc with merge c8193d2...

bors-servo added a commit that referenced this pull request Nov 14, 2016
Immutable CSSOM

This PR is intended to add basic support for all CSSOM interfaces, with the ability to index `document.styleSheets` and css rule lists, and serializing individual css rules. Handling individual interface methods for CSSRule subclasses can probably be done with easy/medium bugs.

Mutation safety isn't dealt with here; if the css rule list is mutated the CSSOM will be in an inconsistent state. I intend to deal with this via zero sized tokens, see https://groups.google.com/forum/#!topic/mozilla.dev.servo/AnxJoVmtMXQ .  I'll handle that when I start making the CSSOM mutable. (Getting the immutable bit landed first opens this up for easy bugs)

This doesn't really change style aside from adding an extra arc in the CSS rule list as discussed in the linked thread. So far this same design can be used by stylo as well when the time comes.

f? @SimonSapin @emilio

cc @upsuper

Todo:

 - [x] Stubs for rest of the CSSRule subclasses
 - [ ] <s>ToCSS impls for CSSRules.</s> May make into easy bugs and stub out in this PR
 - [x] Cache CSSStyleSheet on the relevant node

<!-- 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/14190)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 14, 2016

💔 Test failed - linux-dev

@Manishearth Manishearth force-pushed the Manishearth:cssom branch from caac2bc to d6e95ee Nov 14, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Nov 14, 2016

@upsuper
Copy link
Member

upsuper commented Nov 14, 2016

I suspect some of the changes here may conflict with my patches in bug 1307357, so if this pr gets merged first, I hope there could be a merge from servo/servo to incubator/stylo soonish, so that I can update my patches accordingly.

@Manishearth
Copy link
Member Author

Manishearth commented Nov 14, 2016

There are only two conflicting bits -- the first patch (which you can just import), and the ToCss impl (we can keep whichever lands first). I'll try to get a sync in once this lands.

@upsuper
Copy link
Member

upsuper commented Nov 14, 2016

I think you also want to separate the serialization algorithm of selectors from the ToCss of StyleRule like what I did in my patch, because that is needed in CSSOM.

@Manishearth
Copy link
Member Author

Manishearth commented Nov 14, 2016

Ah, okay. In that case I'll just use your serialization code 😄

@Manishearth Manishearth force-pushed the Manishearth:cssom branch from d6e95ee to 2f80643 Nov 14, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Nov 14, 2016

Updated tocss code. Made minor adjustments for better code and to match the spec.

@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

Previous build results for arm32, arm64, linux-dev, linux-rel-css, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-dev are reusable. Rebuilding only linux-rel-wpt...

@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

💔 Test failed - linux-rel-wpt

@highfive
Copy link

highfive commented Nov 16, 2016

  ▶ FAIL [expected PASS] /_mozilla/css/inline_block_opacity_change.html
  └   → /_mozilla/css/inline_block_opacity_change.html aed6845267bba6c52d3aa69c4889449b454d8117
/_mozilla/css/inline_block_opacity_change_ref.html febec1b4730afab195f280694dad47200b09ea3c
Testing aed6845267bba6c52d3aa69c4889449b454d8117 == febec1b4730afab195f280694dad47200b09ea3c
@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2016

@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2016

@bors-servo r=SimonSapin

(intermittent disabling r+d in irc)

@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

📌 Commit 7fcad8a has been approved by SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

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

  • There's another pull request that is currently being tested, blocking this pull request: #14039
@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

📌 Commit 7fcad8a has been approved by SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

Testing commit 7fcad8a with merge afc60be...

bors-servo added a commit that referenced this pull request Nov 16, 2016
Immutable CSSOM

This PR is intended to add basic support for all CSSOM interfaces, with the ability to index `document.styleSheets` and css rule lists, and serializing individual css rules. Handling individual interface methods for CSSRule subclasses can probably be done with easy/medium bugs.

Mutation safety isn't dealt with here; if the css rule list is mutated the CSSOM will be in an inconsistent state. I intend to deal with this via zero sized tokens, see https://groups.google.com/forum/#!topic/mozilla.dev.servo/AnxJoVmtMXQ .  I'll handle that when I start making the CSSOM mutable. (Getting the immutable bit landed first opens this up for easy bugs)

This doesn't really change style aside from adding an extra arc in the CSS rule list as discussed in the linked thread. So far this same design can be used by stylo as well when the time comes.

f? @SimonSapin @emilio

cc @upsuper

part of #11420
Todo:

 - [x] Stubs for rest of the CSSRule subclasses
 - [x] <s>ToCSS impls for CSSRules.</s> May make into easy bugs and stub out in this PR #14195
 - [x] Cache CSSStyleSheet on the relevant node

<!-- 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/14190)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

@bors-servo bors-servo merged commit 7fcad8a into servo:master Nov 16, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@Manishearth Manishearth deleted the Manishearth:cssom branch Nov 16, 2016
bors-servo added a commit that referenced this pull request Nov 16, 2016
CSSOM: Add insertRule() and deleteRule() on CSSStyleSheet; LinkStyle impls on <style> and <link>

CSSOM is now starting to be useful!

Based on #14190. Only the <s>last commit</s> last two commits need review.

cc @Xidorn . This doesn't change the style API, but adds useful methods.

part of #11420

r? @SimonSapin

<!-- 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/14241)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Nov 17, 2016
CSSOM: Add insertRule() and deleteRule() on CSSStyleSheet; LinkStyle impls on <style> and <link>

CSSOM is now starting to be useful!

Based on #14190. Only the <s>last commit</s> last two commits need review.

cc @Xidorn . This doesn't change the style API, but adds useful methods.

part of #11420

r? @SimonSapin

<!-- 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/14241)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Nov 18, 2016
Implement ToCss serialization for CSSRules

<!-- Please describe your changes on the following line: -->
Implementation of ToCss serialization for CSSRules. It requires #14190 to merge first to uncomment `CssRule::Style` branch in CssRule's ToCss implementation.

r? @Manishearth

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

- [X] These changes do not require tests because it's serialization changes and I'm not sure there is a test for that.

<!-- 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/14238)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Nov 18, 2016
Implement ToCss serialization for CSSRules

<!-- Please describe your changes on the following line: -->
Implementation of ToCss serialization for CSSRules. It requires #14190 to merge first to uncomment `CssRule::Style` branch in CssRule's ToCss implementation.

r? @Manishearth

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

- [X] These changes do not require tests because it's serialization changes and I'm not sure there is a test for that.

<!-- 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/14238)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Nov 18, 2016
CSSOM: Whole ton of things

CSSOM is now starting to be useful!

Based on #14190. Only the <s>last commit</s> last two commits need review.

cc @Xidorn . This doesn't change the style API, but adds useful methods.

part of #11420

This adds:
 - `insertRule()` and `deleteRule()` on `CSSStyleSheet`, `CSSGroupingRule`
 - `.style` getters on link and style elements
 - Keyframes-backed `CSSRules` and `CSSKeyframesRule.cssRules`
 - `CSSGroupingRule.cssRules`
 - `prefix` and `namespaceURI` attributes of `CSSNamespaceRule`
 - Fixups regarding parent stylesheets

r? @SimonSapin

<!-- 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/14241)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Nov 23, 2016
CSSOM: Whole ton of things

CSSOM is now starting to be useful!

Based on #14190. Only the <s>last commit</s> last two commits need review.

cc @Xidorn . This doesn't change the style API, but adds useful methods.

part of #11420

This adds:
 - `insertRule()` and `deleteRule()` on `CSSStyleSheet`, `CSSGroupingRule`
 - `.style` getters on link and style elements
 - Keyframes-backed `CSSRules` and `CSSKeyframesRule.cssRules`
 - `CSSGroupingRule.cssRules`
 - `prefix` and `namespaceURI` attributes of `CSSNamespaceRule`
 - Fixups regarding parent stylesheets

r? @SimonSapin

<!-- 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/14241)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Nov 23, 2016
CSSOM: Whole ton of things

CSSOM is now starting to be useful!

Based on #14190. Only the <s>last commit</s> last two commits need review.

cc @Xidorn . This doesn't change the style API, but adds useful methods.

part of #11420

This adds:
 - `insertRule()` and `deleteRule()` on `CSSStyleSheet`, `CSSGroupingRule`
 - `.style` getters on link and style elements
 - Keyframes-backed `CSSRules` and `CSSKeyframesRule.cssRules`
 - `CSSGroupingRule.cssRules`
 - `prefix` and `namespaceURI` attributes of `CSSNamespaceRule`
 - Fixups regarding parent stylesheets

r? @SimonSapin

<!-- 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/14241)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

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