mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Move StylesheetSetRef to script
This commit is contained in:
parent
9d52feffbb
commit
d0b2e826ef
6 changed files with 75 additions and 65 deletions
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
70
components/script/stylesheet_set.rs
Normal file
70
components/script/stylesheet_set.rs
Normal file
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue