Auto merge of #19222 - upsuper:serialize-group-rule, r=emilio

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 -->
This commit is contained in:
bors-servo 2017-11-15 05:40:24 -06:00 committed by GitHub
commit b2c19b1544
3 changed files with 20 additions and 13 deletions

View file

@ -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)
}
}

View file

@ -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;
@ -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>>`.

View file

@ -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)
}
}