diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 097cf74a2ac..dfbbbb1ae64 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -129,7 +129,6 @@ use style::context::RegisteredSpeculativePainters; use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode}; use style::error_reporting::{NullReporter, RustLogReporter}; use style::invalidation::element::restyle_hints::RestyleHint; -use style::invalidation::media_queries::{MediaListKey, ToMediaListKey}; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaList, MediaType}; use style::properties::PropertyId; @@ -137,7 +136,7 @@ use style::selector_parser::SnapshotMap; use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW}; use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards}; use style::stylesheet_set::StylesheetSet; -use style::stylesheets::{Origin, Stylesheet, StylesheetContents, StylesheetInDocument, UserAgentStylesheets}; +use style::stylesheets::{Origin, Stylesheet, DocumentStyleSheet, StylesheetInDocument, UserAgentStylesheets}; use style::stylist::Stylist; use style::thread_state; use style::timer::Timer; @@ -147,35 +146,6 @@ use style_traits::CSSPixel; use style_traits::DevicePixel; use style_traits::SpeculativePainter; -#[derive(Clone)] -struct DocumentStyleSheet(ServoArc); - -impl PartialEq for DocumentStyleSheet { - fn eq(&self, other: &Self) -> bool { - ServoArc::ptr_eq(&self.0, &other.0) - } -} - -impl ToMediaListKey for DocumentStyleSheet { - fn to_media_list_key(&self) -> MediaListKey { - self.0.to_media_list_key() - } -} - -impl StylesheetInDocument for DocumentStyleSheet { - fn contents(&self, guard: &SharedRwLockReadGuard) -> &StylesheetContents { - self.0.contents(guard) - } - - fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> { - self.0.media(guard) - } - - fn enabled(&self) -> bool { - self.0.enabled() - } -} - /// Information needed by the layout thread. pub struct LayoutThread { /// The ID of the pipeline that we belong to. diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs index e418878363d..ff3ed8c333f 100644 --- a/components/style/stylesheets/mod.rs +++ b/components/style/stylesheets/mod.rs @@ -49,7 +49,8 @@ pub use self::page_rule::PageRule; pub use self::rule_parser::{State, TopLevelRuleParser}; pub use self::rule_list::{CssRules, CssRulesHelpers}; pub use self::rules_iterator::{AllRules, EffectiveRules, NestedRuleIterationCondition, RulesIterator}; -pub use self::stylesheet::{Namespaces, Stylesheet, StylesheetContents, StylesheetInDocument, UserAgentStylesheets}; +pub use self::stylesheet::{Namespaces, Stylesheet, DocumentStyleSheet}; +pub use self::stylesheet::{StylesheetContents, StylesheetInDocument, UserAgentStylesheets}; pub use self::style_rule::StyleRule; pub use self::supports_rule::SupportsRule; pub use self::viewport_rule::ViewportRule; diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index 15d6d5ceec8..d5e953a9525 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -7,6 +7,7 @@ use context::QuirksMode; use cssparser::{Parser, RuleListParser, ParserInput}; use error_reporting::{ParseErrorReporter, ContextualParseError}; use fnv::FnvHashMap; +use invalidation::media_queries::{MediaListKey, ToMediaListKey}; use media_queries::{MediaList, Device}; use parking_lot::RwLock; use parser::ParserContext; @@ -275,6 +276,37 @@ impl StylesheetInDocument for Stylesheet { } } +/// A simple wrapper over an `Arc`, with pointer comparison, and +/// suitable for its use in a `StylesheetSet`. +#[derive(Clone)] +pub struct DocumentStyleSheet(pub Arc); + +impl PartialEq for DocumentStyleSheet { + fn eq(&self, other: &Self) -> bool { + Arc::ptr_eq(&self.0, &other.0) + } +} + +impl ToMediaListKey for DocumentStyleSheet { + fn to_media_list_key(&self) -> MediaListKey { + self.0.to_media_list_key() + } +} + +impl StylesheetInDocument for DocumentStyleSheet { + fn contents(&self, guard: &SharedRwLockReadGuard) -> &StylesheetContents { + self.0.contents(guard) + } + + fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> { + self.0.media(guard) + } + + fn enabled(&self) -> bool { + self.0.enabled() + } +} + impl Stylesheet { /// Updates an empty stylesheet from a given string of text. pub fn update_from_str(existing: &Stylesheet,