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

CSSOM: Whole ton of things #14241

Merged
merged 13 commits into from Nov 23, 2016
Merged

CSSOM: Whole ton of things #14241

merged 13 commits into from Nov 23, 2016

Conversation

@Manishearth
Copy link
Member

Manishearth commented Nov 16, 2016

CSSOM is now starting to be useful!

Based on #14190. Only the last commit 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


This change is Reviewable

@highfive
Copy link

highfive commented Nov 16, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/selector_matching.rs, components/style/stylesheets.rs
  • @jgraham: tests/wpt/harness/test/metadata/testharness/firefox/test_pref_set.html.ini, tests/wpt/harness/test/metadata/testharness/firefox/subdir/test_pref_reset.html.ini, tests/wpt/harness/test/metadata/testharness/tags/testharness_2.html.ini, tests/wpt/harness/test/metadata/testharness/subdir/testharness_1.html.ini, tests/wpt/harness/test/metadata/testharness/tags/testharness_1.html.ini, tests/wpt/harness/test/metadata/testharness/tags/testharness_0.html.ini
  • @wafflespeanut: python/tidy/servo_tidy/tidy.py
  • @emilio: components/style/selector_matching.rs, ports/geckolib/glue.rs, components/style/stylesheets.rs
  • @fitzgen: components/script/dom/webidls/CSSStyleDeclaration.webidl, components/script/dom/webidls/CSSRule.webidl, components/script/dom/cssfontfacerule.rs, components/script/dom/mod.rs, components/script/dom/csskeyframesrule.rs, components/script/dom/webidls/StyleSheetList.webidl, components/script/dom/document.rs, components/script/dom/htmllinkelement.rs, components/script/dom/cssmediarule.rs, components/script/dom/cssgroupingrule.rs, components/script/dom/cssrulelist.rs, components/script/dom/webidls/CSSStyleSheet.webidl, components/script/dom/cssviewportrule.rs, components/script/dom/stylesheetlist.rs, components/script/dom/stylesheet.rs, components/script/dom/cssrule.rs, components/script/dom/webidls/CSS.webidl, components/script/dom/htmlstyleelement.rs, components/script/dom/webidls/CSSFontFaceRule.webidl, components/script/dom/webidls/CSSMediaRule.webidl, components/script/dom/webidls/CSSGroupingRule.webidl, components/script/dom/htmlmetaelement.rs, components/script/dom/node.rs, components/script/dom/cssstylerule.rs, components/script/dom/webidls/CSSStyleRule.webidl, components/script/dom/webidls/StyleSheet.webidl, components/script/dom/webidls/CSSViewportRule.webidl, components/script/dom/webidls/CSSKeyframesRule.webidl, components/script/dom/cssnamespacerule.rs, components/script/dom/webidls/CSSNamespaceRule.webidl, components/script/dom/cssstylesheet.rs, components/script/dom/webidls/CSSRuleList.webidl
  • @KiChjang: components/script/dom/webidls/CSSStyleDeclaration.webidl, components/script/dom/webidls/CSSRule.webidl, components/script/dom/cssfontfacerule.rs, components/script/dom/mod.rs, components/script/dom/csskeyframesrule.rs, components/script/dom/webidls/StyleSheetList.webidl, components/script/dom/document.rs, components/script/dom/htmllinkelement.rs, components/script/dom/cssmediarule.rs, components/script/dom/cssgroupingrule.rs, components/script/dom/cssrulelist.rs, components/script/dom/webidls/CSSStyleSheet.webidl, components/script/dom/cssviewportrule.rs, components/script/dom/stylesheetlist.rs, components/script/dom/stylesheet.rs, components/script/dom/cssrule.rs, components/script/dom/webidls/CSS.webidl, components/script/dom/htmlstyleelement.rs, components/script/dom/webidls/CSSFontFaceRule.webidl, components/script/dom/webidls/CSSMediaRule.webidl, components/script/dom/webidls/CSSGroupingRule.webidl, components/script/dom/htmlmetaelement.rs, components/script/dom/node.rs, components/script/dom/cssstylerule.rs, components/script/dom/webidls/CSSStyleRule.webidl, components/script/dom/webidls/StyleSheet.webidl, components/script/dom/webidls/CSSViewportRule.webidl, components/script/dom/webidls/CSSKeyframesRule.webidl, components/script/dom/cssnamespacerule.rs, components/script/dom/webidls/CSSNamespaceRule.webidl, components/script/dom/cssstylesheet.rs, components/script/dom/webidls/CSSRuleList.webidl

// Step 1, 2
// XXXManishearth get url from correct location
// XXXManishearth should we also store the namespace map?

This comment has been minimized.

@Manishearth

Manishearth Nov 16, 2016

Author Member

I'm considering just filing issues for these

return Err(Error::IndexSize);
}

// XXXManishearth Step 5 (throw HierarchyRequestError in invalid situations)

This comment has been minimized.

@Manishearth

Manishearth Nov 16, 2016

Author Member

spec is very vague here. will have to check against gecko (and file an issue)

@Manishearth Manishearth changed the title CSSOM mutation: Add insertRule() and deleteRule() on CSSStyleSheet CSSOM mutation: Add insertRule() and deleteRule() on CSSStyleSheet; LinkStyle impls on <style> and <link> Nov 16, 2016
@Manishearth Manishearth changed the title CSSOM mutation: Add insertRule() and deleteRule() on CSSStyleSheet; LinkStyle impls on <style> and <link> CSSOM: Add insertRule() and deleteRule() on CSSStyleSheet; LinkStyle impls on <style> and <link> Nov 16, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

Trying commit a5ccd59 with merge 3e29c46...

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
Copy link
Contributor

bors-servo commented Nov 16, 2016

The build was interrupted to prioritize another pull request.

@bors-servo
Copy link
Contributor

bors-servo commented Nov 16, 2016

Trying commit a5ccd59 with merge 7fbc165...

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
Copy link
Contributor

bors-servo commented Nov 16, 2016

💔 Test failed - linux-rel-css

@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2016

@SimonSapin
Copy link
Member

SimonSapin commented Nov 16, 2016

Looks good modulo inline comments. (Opening this before #14190 is merged makes review slightly harder…)


Review status: 0 of 75 files reviewed at latest revision, 7 unresolved discussions.


components/script/dom/cssrulelist.rs, line 79 at r6 (raw file):

Previously, Manishearth (Manish Goregaokar) wrote…

spec is very vague here. will have to check against gecko (and file an issue)

The rules are:

Tracking this is what the split between TopLevelRuleParser and NestedRuleParser as well as the TopLevelRuleParser.state field are for. As mentioned in another comment, some things probably need to be moved around for this.


components/script/dom/cssrulelist.rs, line 82 at r6 (raw file):

            // Step 6
            if let StyleCssRule::Namespace(..) = new_rule {

Something implicit in CSSOM is that namespace prefixes in selectors in a stylesheet are based on all @namespace rules in the stylesheet, even inserted by CSSOM. So this code will need to update the NamespaceMap that is currently only maintained during stylesheet parsing but will need to be kept in the Stylesheet struct.

(This is why this InvalidStateError exception exists: so that selectors don’t need to be re-parsed.)


components/script/dom/cssrulelist.rs, line 115 at r6 (raw file):

        let mut dom_rules = self.dom_rules.borrow_mut();
        self.rules.0.write().remove(index);
        dom_rules[index].get().map(|r| r.disown());

Nit: Vec::remove returns the removed element, disown can be called on that.


components/style/stylesheets.rs, line 136 at r6 (raw file):

    }

    pub fn from_str(css: &str, origin: Origin,

Nit: I’d prefer to call this parse.


components/style/stylesheets.rs, line 139 at r6 (raw file):

                    base_url: Url, extra_data: ParserContextExtraData) -> Result<Self, ()> {
        let error_reporter = Box::new(MemoryHoleReporter);
        let rule_parser = TopLevelRuleParser {

TopLevelRuleParser is what you want for CSSStyleSheet.insertRule, but for CSSGroupingRule.insertRule it’s NestedRuleParser. Probably these two Rust types should be merged, with a boolean field or something to tell both cases apart. This boolean would be an additional parameter to this method.

If you’d rather not do this now I can do it in a follow-up PR.


components/style/stylesheets.rs, line 145 at r6 (raw file):

        };
        let mut input = Parser::new(css);
        let mut iter = RuleListParser::new_for_stylesheet(&mut input, rule_parser);

This should use cssparser::parse_one_rule instead.


Comments from Reviewable

@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2016

Review status: 0 of 75 files reviewed at latest revision, 7 unresolved discussions.


components/script/dom/cssrulelist.rs, line 115 at r6 (raw file):

Previously, SimonSapin (Simon Sapin) wrote…

Nit: Vec::remove returns the removed element, disown can be called on that.

I'm wary of GC happening within that step.

components/style/stylesheets.rs, line 139 at r6 (raw file):

Previously, SimonSapin (Simon Sapin) wrote…

TopLevelRuleParser is what you want for CSSStyleSheet.insertRule, but for CSSGroupingRule.insertRule it’s NestedRuleParser. Probably these two Rust types should be merged, with a boolean field or something to tell both cases apart. This boolean would be an additional parameter to this method.

If you’d rather not do this now I can do it in a follow-up PR.

I didn't merge them, instead I just changed CssRule::parse to accept a nested parameter

Comments from Reviewable

@Manishearth Manishearth force-pushed the Manishearth:mut-cssom branch from 8b26e8d to 7090797 Nov 16, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Nov 16, 2016

Made it handle state (and other review fixups)

@Manishearth
Copy link
Member Author

Manishearth commented 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
Copy link
Contributor

bors-servo commented Nov 16, 2016

Trying commit 7090797 with merge 852e589...

@Manishearth
Copy link
Member Author

Manishearth commented Nov 17, 2016

Added support for keyframe-backed CSSRuleLists, and CSSKeyframeRule. No insertion/deletion from CSSKeyframesRules yet (but it's easy to implement).

@Manishearth Manishearth force-pushed the Manishearth:mut-cssom branch from adb7a3a to 95cbf1a Nov 23, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Nov 23, 2016

@bors-servo r=SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Nov 23, 2016

📌 Commit 95cbf1a has been approved by SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Nov 23, 2016

Testing commit 95cbf1a with merge 9967566...

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
Copy link
Contributor

bors-servo commented Nov 23, 2016

@bors-servo bors-servo mentioned this pull request Nov 23, 2016
2 of 5 tasks complete
@bors-servo bors-servo merged commit 95cbf1a into servo:master Nov 23, 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:mut-cssom branch Nov 23, 2016
@bors-servo bors-servo mentioned this pull request Nov 23, 2016
0 of 5 tasks complete
@upsuper
Copy link
Member

upsuper commented Nov 23, 2016

You didn't successfully cc'ed me...

The algorithm of insertRule and deleteRule really should be implemented inside style component so that they can be reused for stylo...

@Manishearth
Copy link
Member Author

Manishearth commented Nov 23, 2016

I tried to make it as reusable as possible. Because of the parallel dom tree the algorithm involves DOM code as well and is hard to separate. The parsing/insertion validity algorithms are in stylesheets.rs though.

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

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