Skip to content

Commit

Permalink
Move StylesheetSetRef to script
Browse files Browse the repository at this point in the history
  • Loading branch information
ferjm committed Apr 26, 2019
1 parent 9d52fef commit d0b2e82
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 65 deletions.
3 changes: 2 additions & 1 deletion components/script/dom/document.rs
Expand Up @@ -101,6 +101,7 @@ use crate::dom::windowproxy::WindowProxy;
use crate::fetch::FetchCanceller;
use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use crate::script_thread::{MainThreadScriptMsg, ScriptThread};
use crate::stylesheet_set::StylesheetSetRef;
use crate::task::TaskBox;
use crate::task_source::{TaskSource, TaskSourceName};
use crate::timers::OneshotTimerCallback;
Expand Down Expand Up @@ -154,7 +155,7 @@ use style::media_queries::{Device, MediaType};
use style::selector_parser::{RestyleDamage, Snapshot};
use style::shared_lock::SharedRwLock as StyleSharedRwLock;
use style::str::{split_html_space_chars, str_join};
use style::stylesheet_set::{DocumentStylesheetSet, StylesheetSetRef};
use style::stylesheet_set::DocumentStylesheetSet;
use style::stylesheets::{Origin, OriginSet, Stylesheet};
use url::percent_encoding::percent_decode;
use url::Host;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/documentorshadowroot.rs
Expand Up @@ -12,6 +12,7 @@ use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlmetaelement::HTMLMetaElement;
use crate::dom::node::{self, Node, VecPreOrderInsertionHelper};
use crate::dom::window::Window;
use crate::stylesheet_set::StylesheetSetRef;
use euclid::Point2D;
use js::jsapi::JS_GetRuntime;
use script_layout_interface::message::{NodesFromPointQueryType, QueryMsg};
Expand All @@ -24,7 +25,6 @@ use style::context::QuirksMode;
use style::invalidation::media_queries::{MediaListKey, ToMediaListKey};
use style::media_queries::MediaList;
use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuard};
use style::stylesheet_set::StylesheetSetRef;
use style::stylesheets::{CssRule, Origin, Stylesheet};

#[derive(Clone, JSTraceable, MallocSizeOf)]
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/shadowroot.rs
Expand Up @@ -17,6 +17,7 @@ use crate::dom::element::Element;
use crate::dom::node::{Node, NodeDamage, NodeFlags, ShadowIncluding};
use crate::dom::stylesheetlist::{StyleSheetList, StyleSheetListOwner};
use crate::dom::window::Window;
use crate::stylesheet_set::StylesheetSetRef;
use dom_struct::dom_struct;
use selectors::context::QuirksMode;
use servo_arc::Arc;
Expand All @@ -25,7 +26,6 @@ use style::author_styles::AuthorStyles;
use style::dom::TElement;
use style::media_queries::Device;
use style::shared_lock::SharedRwLockReadGuard;
use style::stylesheet_set::StylesheetSetRef;
use style::stylesheets::Stylesheet;

// https://dom.spec.whatwg.org/#interface-shadowroot
Expand Down
1 change: 1 addition & 0 deletions components/script/lib.rs
Expand Up @@ -69,6 +69,7 @@ pub mod script_thread;
mod serviceworker_manager;
mod serviceworkerjob;
mod stylesheet_loader;
mod stylesheet_set;
mod task_manager;
mod task_queue;
mod task_source;
Expand Down
70 changes: 70 additions & 0 deletions components/script/stylesheet_set.rs
@@ -0,0 +1,70 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use style::media_queries::Device;
use style::shared_lock::SharedRwLockReadGuard;
use style::stylesheet_set::{AuthorStylesheetSet, DocumentStylesheetSet};
use style::stylesheets::StylesheetInDocument;

/// Functionality common to DocumentStylesheetSet and AuthorStylesheetSet.
pub enum StylesheetSetRef<'a, S>
where
S: StylesheetInDocument + PartialEq + 'static,
{
/// Author stylesheet set.
Author(&'a mut AuthorStylesheetSet<S>),
/// Document stylesheet set.
Document(&'a mut DocumentStylesheetSet<S>),
}

impl<'a, S> StylesheetSetRef<'a, S>
where
S: StylesheetInDocument + PartialEq + 'static,
{
/// Appends a new stylesheet to the current set.
///
/// No device implies not computing invalidations.
pub fn append_stylesheet(
&mut self,
device: Option<&Device>,
sheet: S,
guard: &SharedRwLockReadGuard,
) {
match self {
StylesheetSetRef::Author(set) => set.append_stylesheet(device, sheet, guard),
StylesheetSetRef::Document(set) => set.append_stylesheet(device, sheet, guard),
}
}

/// Insert a given stylesheet before another stylesheet in the document.
pub fn insert_stylesheet_before(
&mut self,
device: Option<&Device>,
sheet: S,
before_sheet: S,
guard: &SharedRwLockReadGuard,
) {
match self {
StylesheetSetRef::Author(set) => {
set.insert_stylesheet_before(device, sheet, before_sheet, guard)
},
StylesheetSetRef::Document(set) => {
set.insert_stylesheet_before(device, sheet, before_sheet, guard)
},
}
}

/// Remove a given stylesheet from the set.
pub fn remove_stylesheet(
&mut self,
device: Option<&Device>,
sheet: S,
guard: &SharedRwLockReadGuard,
) {
match self {
StylesheetSetRef::Author(set) => set.remove_stylesheet(device, sheet, guard),
StylesheetSetRef::Document(set) => set.remove_stylesheet(device, sheet, guard),
}
}
}
62 changes: 0 additions & 62 deletions components/style/stylesheet_set.rs
Expand Up @@ -373,68 +373,6 @@ where
invalidations: StylesheetInvalidationSet,
}

/// Functionality common to DocumentStylesheetSet and AuthorStylesheetSet.
pub enum StylesheetSetRef<'a, S>
where
S: StylesheetInDocument + PartialEq + 'static,
{
/// Author stylesheet set.
Author(&'a mut AuthorStylesheetSet<S>),
/// Document stylesheet set.
Document(&'a mut DocumentStylesheetSet<S>),
}

impl<'a, S> StylesheetSetRef<'a, S>
where
S: StylesheetInDocument + PartialEq + 'static,
{
/// Appends a new stylesheet to the current set.
///
/// No device implies not computing invalidations.
pub fn append_stylesheet(
&mut self,
device: Option<&Device>,
sheet: S,
guard: &SharedRwLockReadGuard,
) {
match self {
StylesheetSetRef::Author(set) => set.append_stylesheet(device, sheet, guard),
StylesheetSetRef::Document(set) => set.append_stylesheet(device, sheet, guard),
}
}

/// Insert a given stylesheet before another stylesheet in the document.
pub fn insert_stylesheet_before(
&mut self,
device: Option<&Device>,
sheet: S,
before_sheet: S,
guard: &SharedRwLockReadGuard,
) {
match self {
StylesheetSetRef::Author(set) => {
set.insert_stylesheet_before(device, sheet, before_sheet, guard)
},
StylesheetSetRef::Document(set) => {
set.insert_stylesheet_before(device, sheet, before_sheet, guard)
},
}
}

/// Remove a given stylesheet from the set.
pub fn remove_stylesheet(
&mut self,
device: Option<&Device>,
sheet: S,
guard: &SharedRwLockReadGuard,
) {
match self {
StylesheetSetRef::Author(set) => set.remove_stylesheet(device, sheet, guard),
StylesheetSetRef::Document(set) => set.remove_stylesheet(device, sheet, guard),
}
}
}

/// This macro defines methods common to DocumentStylesheetSet and
/// AuthorStylesheetSet.
///
Expand Down

0 comments on commit d0b2e82

Please sign in to comment.