mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Replace RwLock<MediaList> with shared_lock::Locked<MediaList>
This commit is contained in:
parent
8feb9e8047
commit
c5a7294e05
18 changed files with 117 additions and 42 deletions
|
@ -99,6 +99,7 @@ use style::keyframes::Keyframe;
|
|||
use style::media_queries::MediaList;
|
||||
use style::properties::PropertyDeclarationBlock;
|
||||
use style::selector_parser::{PseudoElement, Snapshot};
|
||||
use style::shared_lock::SharedRwLock as StyleSharedRwLock;
|
||||
use style::stylesheets::{CssRules, KeyframesRule, MediaRule, NamespaceRule, StyleRule, ImportRule};
|
||||
use style::stylesheets::SupportsRule;
|
||||
use style::values::specified::Length;
|
||||
|
@ -360,6 +361,7 @@ unsafe_no_jsmanaged_fields!(HttpsState);
|
|||
unsafe_no_jsmanaged_fields!(Request);
|
||||
unsafe_no_jsmanaged_fields!(RequestInit);
|
||||
unsafe_no_jsmanaged_fields!(SharedRt);
|
||||
unsafe_no_jsmanaged_fields!(StyleSharedRwLock);
|
||||
unsafe_no_jsmanaged_fields!(TouchpadPressurePhase);
|
||||
unsafe_no_jsmanaged_fields!(USVString);
|
||||
unsafe_no_jsmanaged_fields!(ReferrerPolicy);
|
||||
|
|
|
@ -134,6 +134,7 @@ use style::attr::AttrValue;
|
|||
use style::context::{QuirksMode, ReflowGoal};
|
||||
use style::restyle_hints::{RestyleHint, RESTYLE_STYLE_ATTRIBUTE};
|
||||
use style::selector_parser::{RestyleDamage, Snapshot};
|
||||
use style::shared_lock::SharedRwLock as StyleSharedRwLock;
|
||||
use style::str::{HTML_SPACE_CHARACTERS, split_html_space_chars, str_join};
|
||||
use style::stylesheets::Stylesheet;
|
||||
use task_source::TaskSource;
|
||||
|
@ -220,6 +221,9 @@ pub struct Document {
|
|||
scripts: MutNullableJS<HTMLCollection>,
|
||||
anchors: MutNullableJS<HTMLCollection>,
|
||||
applets: MutNullableJS<HTMLCollection>,
|
||||
/// Lock use for style attributes and author-origin stylesheet objects in this document.
|
||||
/// Can be acquired once for accessing many objects.
|
||||
style_shared_lock: StyleSharedRwLock,
|
||||
/// List of stylesheets associated with nodes in this document. |None| if the list needs to be refreshed.
|
||||
stylesheets: DOMRefCell<Option<Vec<StylesheetInDocument>>>,
|
||||
/// Whether the list of stylesheets has changed since the last reflow was triggered.
|
||||
|
@ -1964,6 +1968,7 @@ pub trait LayoutDocumentHelpers {
|
|||
unsafe fn needs_paint_from_layout(&self);
|
||||
unsafe fn will_paint(&self);
|
||||
unsafe fn quirks_mode(&self) -> QuirksMode;
|
||||
unsafe fn style_shared_lock(&self) -> &StyleSharedRwLock;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -2000,6 +2005,11 @@ impl LayoutDocumentHelpers for LayoutJS<Document> {
|
|||
unsafe fn quirks_mode(&self) -> QuirksMode {
|
||||
(*self.unsafe_get()).quirks_mode()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn style_shared_lock(&self) -> &StyleSharedRwLock {
|
||||
(*self.unsafe_get()).style_shared_lock()
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#is-a-registrable-domain-suffix-of-or-is-equal-to
|
||||
|
@ -2121,6 +2131,7 @@ impl Document {
|
|||
scripts: Default::default(),
|
||||
anchors: Default::default(),
|
||||
applets: Default::default(),
|
||||
style_shared_lock: StyleSharedRwLock::new(),
|
||||
stylesheets: DOMRefCell::new(None),
|
||||
stylesheets_changed_since_reflow: Cell::new(false),
|
||||
stylesheet_list: MutNullableJS::new(None),
|
||||
|
@ -2250,6 +2261,11 @@ impl Document {
|
|||
};
|
||||
}
|
||||
|
||||
/// Return a reference to the per-document shared lock used in stylesheets.
|
||||
pub fn style_shared_lock(&self) -> &StyleSharedRwLock {
|
||||
&self.style_shared_lock
|
||||
}
|
||||
|
||||
/// Returns the list of stylesheets associated with nodes in the document.
|
||||
pub fn stylesheets(&self) -> Vec<Arc<Stylesheet>> {
|
||||
self.ensure_stylesheets();
|
||||
|
|
|
@ -99,12 +99,15 @@ impl HTMLMetaElement {
|
|||
let content = content.value();
|
||||
if !content.is_empty() {
|
||||
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
||||
let document = self.upcast::<Node>().owner_doc();
|
||||
let shared_lock = document.style_shared_lock();
|
||||
*self.stylesheet.borrow_mut() = Some(Arc::new(Stylesheet {
|
||||
rules: CssRules::new(vec![CssRule::Viewport(Arc::new(RwLock::new(translated_rule)))]),
|
||||
origin: Origin::Author,
|
||||
shared_lock: shared_lock.clone(),
|
||||
base_url: window_from_node(self).get_url(),
|
||||
namespaces: Default::default(),
|
||||
media: Default::default(),
|
||||
media: Arc::new(shared_lock.wrap(Default::default())),
|
||||
// Viewport constraints are always recomputed on resize; they don't need to
|
||||
// force all styles to be recomputed.
|
||||
dirty_on_viewport_size_change: AtomicBool::new(false),
|
||||
|
|
|
@ -84,9 +84,10 @@ impl HTMLStyleElement {
|
|||
|
||||
let data = node.GetTextContent().expect("Element.textContent must be a string");
|
||||
let mq = parse_media_query_list(&mut CssParser::new(&mq_str));
|
||||
let shared_lock = node.owner_doc().style_shared_lock().clone();
|
||||
let loader = StylesheetLoader::for_element(self.upcast());
|
||||
let sheet = Stylesheet::from_str(&data, url, Origin::Author, mq,
|
||||
Some(&loader),
|
||||
shared_lock, Some(&loader),
|
||||
win.css_error_reporter(),
|
||||
ParserContextExtraData::default());
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ use style::dom::UnsafeNode;
|
|||
use style::element_state::*;
|
||||
use style::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use style::selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl};
|
||||
use style::shared_lock::SharedRwLock as StyleSharedRwLock;
|
||||
use style::sink::Push;
|
||||
use style::str::is_whitespace;
|
||||
use style::stylist::ApplicableDeclarationBlock;
|
||||
|
@ -330,6 +331,10 @@ impl<'ld> ServoLayoutDocument<'ld> {
|
|||
unsafe { self.document.quirks_mode() }
|
||||
}
|
||||
|
||||
pub fn style_shared_lock(&self) -> &StyleSharedRwLock {
|
||||
unsafe { self.document.style_shared_lock() }
|
||||
}
|
||||
|
||||
pub fn from_layout_js(doc: LayoutJS<Document>) -> ServoLayoutDocument<'ld> {
|
||||
ServoLayoutDocument {
|
||||
document: doc,
|
||||
|
|
|
@ -152,12 +152,14 @@ impl FetchResponseListener for StylesheetContext {
|
|||
let is_stylesheet_load_applicable =
|
||||
self.request_generation_id.map_or(true, |gen| gen == link.get_request_generation_id());
|
||||
if is_stylesheet_load_applicable {
|
||||
let shared_lock = document.style_shared_lock().clone();
|
||||
let sheet =
|
||||
Arc::new(Stylesheet::from_bytes(&data, final_url,
|
||||
protocol_encoding_label,
|
||||
Some(environment_encoding),
|
||||
Origin::Author,
|
||||
media.take().unwrap(),
|
||||
shared_lock,
|
||||
Some(&loader),
|
||||
win.css_error_reporter(),
|
||||
ParserContextExtraData::default()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue