script/
stylesheet_set.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use style::media_queries::Device;
6use style::shared_lock::SharedRwLockReadGuard;
7use style::stylesheet_set::{AuthorStylesheetSet, DocumentStylesheetSet};
8use style::stylesheets::StylesheetInDocument;
9
10/// Functionality common to DocumentStylesheetSet and AuthorStylesheetSet.
11pub(crate) enum StylesheetSetRef<'a, S>
12where
13    S: StylesheetInDocument + PartialEq + 'static,
14{
15    /// Author stylesheet set.
16    Author(&'a mut AuthorStylesheetSet<S>),
17    /// Document stylesheet set.
18    Document(&'a mut DocumentStylesheetSet<S>),
19}
20
21impl<S> StylesheetSetRef<'_, S>
22where
23    S: StylesheetInDocument + PartialEq + 'static,
24{
25    /// Appends a new stylesheet to the current set.
26    ///
27    /// No device implies not computing invalidations.
28    pub(crate) fn append_stylesheet(
29        &mut self,
30        device: Option<&Device>,
31        sheet: S,
32        guard: &SharedRwLockReadGuard,
33    ) {
34        match self {
35            StylesheetSetRef::Author(set) => set.append_stylesheet(device, sheet, guard),
36            StylesheetSetRef::Document(set) => set.append_stylesheet(device, sheet, guard),
37        }
38    }
39
40    /// Insert a given stylesheet before another stylesheet in the document.
41    pub(crate) fn insert_stylesheet_before(
42        &mut self,
43        device: Option<&Device>,
44        sheet: S,
45        before_sheet: S,
46        guard: &SharedRwLockReadGuard,
47    ) {
48        match self {
49            StylesheetSetRef::Author(set) => {
50                set.insert_stylesheet_before(device, sheet, before_sheet, guard)
51            },
52            StylesheetSetRef::Document(set) => {
53                set.insert_stylesheet_before(device, sheet, before_sheet, guard)
54            },
55        }
56    }
57
58    /// Remove a given stylesheet from the set.
59    pub(crate) fn remove_stylesheet(
60        &mut self,
61        device: Option<&Device>,
62        sheet: S,
63        guard: &SharedRwLockReadGuard,
64    ) {
65        match self {
66            StylesheetSetRef::Author(set) => set.remove_stylesheet(device, sheet, guard),
67            StylesheetSetRef::Document(set) => set.remove_stylesheet(device, sheet, guard),
68        }
69    }
70}