mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Serialize media rule and supports rule like Gecko.
This commit is contained in:
parent
d7b4471c80
commit
ae3989ebf0
3 changed files with 20 additions and 13 deletions
|
@ -46,12 +46,7 @@ impl ToCssWithGuard for MediaRule {
|
||||||
where W: fmt::Write {
|
where W: fmt::Write {
|
||||||
dest.write_str("@media ")?;
|
dest.write_str("@media ")?;
|
||||||
self.media_queries.read_with(guard).to_css(dest)?;
|
self.media_queries.read_with(guard).to_css(dest)?;
|
||||||
dest.write_str(" {")?;
|
self.rules.read_with(guard).to_css_block(guard, dest)
|
||||||
for rule in self.rules.read_with(guard).0.iter() {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
rule.to_css(guard, dest)?;
|
|
||||||
}
|
|
||||||
dest.write_str(" }")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocShallowSizeOf, MallocSizeOfOps};
|
||||||
use servo_arc::{Arc, RawOffsetArc};
|
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::{CssRule, RulesMutateError};
|
||||||
use stylesheets::loader::StylesheetLoader;
|
use stylesheets::loader::StylesheetLoader;
|
||||||
use stylesheets::rule_parser::State;
|
use stylesheets::rule_parser::State;
|
||||||
|
@ -88,6 +90,21 @@ impl CssRules {
|
||||||
self.0.remove(index);
|
self.0.remove(index);
|
||||||
Ok(())
|
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>>`.
|
/// A trait to implement helpers for `Arc<Locked<CssRules>>`.
|
||||||
|
|
|
@ -47,12 +47,7 @@ impl ToCssWithGuard for SupportsRule {
|
||||||
where W: fmt::Write {
|
where W: fmt::Write {
|
||||||
dest.write_str("@supports ")?;
|
dest.write_str("@supports ")?;
|
||||||
self.condition.to_css(dest)?;
|
self.condition.to_css(dest)?;
|
||||||
dest.write_str(" {")?;
|
self.rules.read_with(guard).to_css_block(guard, dest)
|
||||||
for rule in self.rules.read_with(guard).0.iter() {
|
|
||||||
dest.write_str(" ")?;
|
|
||||||
rule.to_css(guard, dest)?;
|
|
||||||
}
|
|
||||||
dest.write_str(" }")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue