Skip to content

Commit

Permalink
Auto merge of #19222 - upsuper:serialize-group-rule, r=emilio
Browse files Browse the repository at this point in the history
Serialize media rule and supports rule like Gecko

This should fix [bug 1417207](https://bugzilla.mozilla.org/show_bug.cgi?id=1417207).

<!-- 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/19222)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Nov 15, 2017
2 parents 2efbf22 + ae3989e commit b2c19b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
7 changes: 1 addition & 6 deletions components/style/stylesheets/media_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ impl ToCssWithGuard for MediaRule {
where W: fmt::Write {
dest.write_str("@media ")?;
self.media_queries.read_with(guard).to_css(dest)?;
dest.write_str(" {")?;
for rule in self.rules.read_with(guard).0.iter() {
dest.write_str(" ")?;
rule.to_css(guard, dest)?;
}
dest.write_str(" }")
self.rules.read_with(guard).to_css_block(guard, dest)
}
}

Expand Down
19 changes: 18 additions & 1 deletion components/style/stylesheets/rule_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#[cfg(feature = "gecko")]
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOfOps};
use servo_arc::{Arc, RawOffsetArc};
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard};
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked};
use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt;
use stylesheets::{CssRule, RulesMutateError};
use stylesheets::loader::StylesheetLoader;
use stylesheets::rule_parser::State;
Expand Down Expand Up @@ -88,6 +90,21 @@ impl CssRules {
self.0.remove(index);
Ok(())
}

/// Serializes this CSSRules to CSS text as a block of rules.
///
/// This should be speced into CSSOM spec at some point. See
/// <https://github.com/w3c/csswg-drafts/issues/1985>
pub fn to_css_block<W>(&self, guard: &SharedRwLockReadGuard, dest: &mut W)
-> fmt::Result where W: fmt::Write
{
dest.write_str(" {")?;
for rule in self.0.iter() {
dest.write_str("\n ")?;
rule.to_css(guard, dest)?;
}
dest.write_str("\n}")
}
}

/// A trait to implement helpers for `Arc<Locked<CssRules>>`.
Expand Down
7 changes: 1 addition & 6 deletions components/style/stylesheets/supports_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ impl ToCssWithGuard for SupportsRule {
where W: fmt::Write {
dest.write_str("@supports ")?;
self.condition.to_css(dest)?;
dest.write_str(" {")?;
for rule in self.rules.read_with(guard).0.iter() {
dest.write_str(" ")?;
rule.to_css(guard, dest)?;
}
dest.write_str(" }")
self.rules.read_with(guard).to_css_block(guard, dest)
}
}

Expand Down

0 comments on commit b2c19b1

Please sign in to comment.