mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move all PropertyDeclarationBlock from RwLock<_> to Locked<_>
This commit is contained in:
parent
aeffca2a59
commit
1bacd0eb15
28 changed files with 321 additions and 208 deletions
|
@ -562,7 +562,7 @@ unsafe impl JSTraceable for StyleLocked<ViewportRule> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<PropertyDeclarationBlock> {
|
||||
unsafe impl JSTraceable for StyleLocked<PropertyDeclarationBlock> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ use dom::window::Window;
|
|||
use dom_struct::dom_struct;
|
||||
use std::sync::Arc;
|
||||
use style::keyframes::Keyframe;
|
||||
use style::shared_lock::Locked;
|
||||
use style_traits::ToCss;
|
||||
use style::shared_lock::{Locked, ToCssWithGuard};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSKeyframeRule {
|
||||
|
@ -70,6 +69,6 @@ impl SpecificCSSRule for CSSKeyframeRule {
|
|||
|
||||
fn get_css(&self) -> DOMString {
|
||||
let guard = self.cssrule.shared_lock().read();
|
||||
self.keyframerule.read_with(&guard).to_css_string().into()
|
||||
self.keyframerule.read_with(&guard).to_css_string(&guard).into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,9 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
|||
use dom::bindings::str::DOMString;
|
||||
use dom::cssrule::CSSRule;
|
||||
use dom::element::Element;
|
||||
use dom::node::{Node, window_from_node};
|
||||
use dom::node::{Node, window_from_node, document_from_node};
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use servo_url::ServoUrl;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::sync::Arc;
|
||||
|
@ -23,6 +22,7 @@ use style::parser::ParserContextExtraData;
|
|||
use style::properties::{Importance, PropertyDeclarationBlock, PropertyId, LonghandId, ShorthandId};
|
||||
use style::properties::{parse_one_declaration, parse_style_attribute};
|
||||
use style::selector_parser::PseudoElement;
|
||||
use style::shared_lock::Locked;
|
||||
use style_traits::ToCss;
|
||||
|
||||
// http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
|
||||
|
@ -40,7 +40,7 @@ pub enum CSSStyleOwner {
|
|||
Element(JS<Element>),
|
||||
CSSRule(JS<CSSRule>,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
Arc<RwLock<PropertyDeclarationBlock>>),
|
||||
Arc<Locked<PropertyDeclarationBlock>>),
|
||||
}
|
||||
|
||||
impl CSSStyleOwner {
|
||||
|
@ -55,10 +55,13 @@ impl CSSStyleOwner {
|
|||
let mut changed = true;
|
||||
match *self {
|
||||
CSSStyleOwner::Element(ref el) => {
|
||||
let document = document_from_node(&**el);
|
||||
let shared_lock = document.style_shared_lock();
|
||||
let mut attr = el.style_attribute().borrow_mut().take();
|
||||
let result = if attr.is_some() {
|
||||
let lock = attr.as_ref().unwrap();
|
||||
let mut pdb = lock.write();
|
||||
let mut guard = shared_lock.write();
|
||||
let mut pdb = lock.write_with(&mut guard);
|
||||
let result = f(&mut pdb, &mut changed);
|
||||
result
|
||||
} else {
|
||||
|
@ -69,7 +72,7 @@ impl CSSStyleOwner {
|
|||
// exact conditions under it changes.
|
||||
changed = !pdb.declarations().is_empty();
|
||||
if changed {
|
||||
attr = Some(Arc::new(RwLock::new(pdb)));
|
||||
attr = Some(Arc::new(shared_lock.wrap(pdb)));
|
||||
}
|
||||
|
||||
result
|
||||
|
@ -83,7 +86,8 @@ impl CSSStyleOwner {
|
|||
//
|
||||
// [1]: https://github.com/whatwg/html/issues/2306
|
||||
if let Some(pdb) = attr {
|
||||
let serialization = pdb.read().to_css_string();
|
||||
let guard = shared_lock.read();
|
||||
let serialization = pdb.read_with(&guard).to_css_string();
|
||||
el.set_attribute(&local_name!("style"),
|
||||
AttrValue::Declaration(serialization,
|
||||
pdb));
|
||||
|
@ -96,7 +100,10 @@ impl CSSStyleOwner {
|
|||
result
|
||||
}
|
||||
CSSStyleOwner::CSSRule(ref rule, ref pdb) => {
|
||||
let result = f(&mut *pdb.write(), &mut changed);
|
||||
let result = {
|
||||
let mut guard = rule.shared_lock().write();
|
||||
f(&mut *pdb.write_with(&mut guard), &mut changed)
|
||||
};
|
||||
if changed {
|
||||
rule.global().as_window().Document().invalidate_stylesheets();
|
||||
}
|
||||
|
@ -111,15 +118,20 @@ impl CSSStyleOwner {
|
|||
match *self {
|
||||
CSSStyleOwner::Element(ref el) => {
|
||||
match *el.style_attribute().borrow() {
|
||||
Some(ref pdb) => f(&pdb.read()),
|
||||
Some(ref pdb) => {
|
||||
let document = document_from_node(&**el);
|
||||
let guard = document.style_shared_lock().read();
|
||||
f(pdb.read_with(&guard))
|
||||
}
|
||||
None => {
|
||||
let pdb = PropertyDeclarationBlock::new();
|
||||
f(&pdb)
|
||||
}
|
||||
}
|
||||
}
|
||||
CSSStyleOwner::CSSRule(_, ref pdb) => {
|
||||
f(&pdb.read())
|
||||
CSSStyleOwner::CSSRule(ref rule, ref pdb) => {
|
||||
let guard = rule.shared_lock().read();
|
||||
f(pdb.read_with(&guard))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,6 @@ use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode};
|
|||
use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
|
||||
use js::jsapi::{HandleValue, JSAutoCompartment};
|
||||
use net_traits::request::CorsSettings;
|
||||
use parking_lot::RwLock;
|
||||
use ref_filter_map::ref_filter_map;
|
||||
use script_layout_interface::message::ReflowQueryType;
|
||||
use script_thread::Runnable;
|
||||
|
@ -108,6 +107,7 @@ use style::properties::longhands::{self, background_image, border_spacing, font_
|
|||
use style::restyle_hints::RESTYLE_SELF;
|
||||
use style::rule_tree::CascadeLevel;
|
||||
use style::selector_parser::{NonTSPseudoClass, RestyleDamage, SelectorImpl, SelectorParser};
|
||||
use style::shared_lock::{SharedRwLock, Locked};
|
||||
use style::sink::Push;
|
||||
use style::stylist::ApplicableDeclarationBlock;
|
||||
use style::thread_state;
|
||||
|
@ -129,7 +129,7 @@ pub struct Element {
|
|||
attrs: DOMRefCell<Vec<JS<Attr>>>,
|
||||
id_attribute: DOMRefCell<Option<Atom>>,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
style_attribute: DOMRefCell<Option<Arc<RwLock<PropertyDeclarationBlock>>>>,
|
||||
style_attribute: DOMRefCell<Option<Arc<Locked<PropertyDeclarationBlock>>>>,
|
||||
attr_list: MutNullableJS<NamedNodeMap>,
|
||||
class_list: MutNullableJS<DOMTokenList>,
|
||||
state: Cell<ElementState>,
|
||||
|
@ -352,7 +352,7 @@ pub trait LayoutElementHelpers {
|
|||
#[allow(unsafe_code)]
|
||||
unsafe fn html_element_in_html_document_for_layout(&self) -> bool;
|
||||
fn id_attribute(&self) -> *const Option<Atom>;
|
||||
fn style_attribute(&self) -> *const Option<Arc<RwLock<PropertyDeclarationBlock>>>;
|
||||
fn style_attribute(&self) -> *const Option<Arc<Locked<PropertyDeclarationBlock>>>;
|
||||
fn local_name(&self) -> &LocalName;
|
||||
fn namespace(&self) -> &Namespace;
|
||||
fn get_lang_for_layout(&self) -> String;
|
||||
|
@ -384,14 +384,18 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
where V: Push<ApplicableDeclarationBlock>
|
||||
{
|
||||
#[inline]
|
||||
fn from_declaration(declaration: PropertyDeclaration) -> ApplicableDeclarationBlock {
|
||||
fn from_declaration(shared_lock: &SharedRwLock, declaration: PropertyDeclaration)
|
||||
-> ApplicableDeclarationBlock {
|
||||
ApplicableDeclarationBlock::from_declarations(
|
||||
Arc::new(RwLock::new(PropertyDeclarationBlock::with_one(
|
||||
Arc::new(shared_lock.wrap(PropertyDeclarationBlock::with_one(
|
||||
declaration, Importance::Normal
|
||||
))),
|
||||
CascadeLevel::PresHints)
|
||||
}
|
||||
|
||||
let document = self.upcast::<Node>().owner_doc_for_layout();
|
||||
let shared_lock = document.style_shared_lock();
|
||||
|
||||
let bgcolor = if let Some(this) = self.downcast::<HTMLBodyElement>() {
|
||||
this.get_background_color()
|
||||
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||
|
@ -408,6 +412,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
|
||||
if let Some(color) = bgcolor {
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BackgroundColor(
|
||||
CSSColor { parsed: Color::RGBA(color), authored: None })));
|
||||
}
|
||||
|
@ -420,6 +425,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
|
||||
if let Some(url) = background {
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BackgroundImage(
|
||||
background_image::SpecifiedValue(vec![
|
||||
background_image::single_value::SpecifiedValue(Some(
|
||||
|
@ -442,6 +448,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
|
||||
if let Some(color) = color {
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Color(
|
||||
longhands::color::SpecifiedValue(CSSColor {
|
||||
parsed: Color::RGBA(color),
|
||||
|
@ -459,6 +466,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
|
||||
if let Some(font_family) = font_family {
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::FontFamily(
|
||||
font_family::computed_value::T(vec![
|
||||
font_family::computed_value::FontFamily::from_atom(
|
||||
|
@ -469,6 +477,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
|
||||
if let Some(font_size) = font_size {
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::FontSize(font_size::SpecifiedValue(font_size.into()))))
|
||||
}
|
||||
|
||||
|
@ -481,6 +490,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
if let Some(cellspacing) = cellspacing {
|
||||
let width_value = specified::Length::from_px(cellspacing as f32);
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BorderSpacing(
|
||||
Box::new(border_spacing::SpecifiedValue {
|
||||
horizontal: width_value.clone(),
|
||||
|
@ -514,6 +524,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
if let Some(size) = size {
|
||||
let value = specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Width(
|
||||
specified::LengthOrPercentageOrAuto::Length(value))));
|
||||
}
|
||||
|
@ -539,12 +550,14 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
let width_value =
|
||||
specified::LengthOrPercentageOrAuto::Percentage(specified::Percentage(percentage));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Width(width_value)));
|
||||
}
|
||||
LengthOrPercentageOrAuto::Length(length) => {
|
||||
let width_value = specified::LengthOrPercentageOrAuto::Length(
|
||||
specified::NoCalcLength::Absolute(length));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Width(width_value)));
|
||||
}
|
||||
}
|
||||
|
@ -564,12 +577,14 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
let height_value =
|
||||
specified::LengthOrPercentageOrAuto::Percentage(specified::Percentage(percentage));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Height(height_value)));
|
||||
}
|
||||
LengthOrPercentageOrAuto::Length(length) => {
|
||||
let height_value = specified::LengthOrPercentageOrAuto::Length(
|
||||
specified::NoCalcLength::Absolute(length));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Height(height_value)));
|
||||
}
|
||||
}
|
||||
|
@ -592,6 +607,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
// https://html.spec.whatwg.org/multipage/#textarea-effective-width
|
||||
let value = specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value))));
|
||||
}
|
||||
|
||||
|
@ -610,6 +626,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
// https://html.spec.whatwg.org/multipage/#textarea-effective-height
|
||||
let value = specified::NoCalcLength::FontRelative(specified::FontRelativeLength::Em(rows as CSSFloat));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::Length(value))));
|
||||
}
|
||||
|
||||
|
@ -623,12 +640,16 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
if let Some(border) = border {
|
||||
let width_value = specified::BorderWidth::from_length(specified::Length::from_px(border as f32));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BorderTopWidth(Box::new(width_value.clone()))));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BorderLeftWidth(Box::new(width_value.clone()))));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BorderBottomWidth(Box::new(width_value.clone()))));
|
||||
hints.push(from_declaration(
|
||||
shared_lock,
|
||||
PropertyDeclaration::BorderRightWidth(Box::new(width_value))));
|
||||
}
|
||||
}
|
||||
|
@ -672,7 +693,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn style_attribute(&self) -> *const Option<Arc<RwLock<PropertyDeclarationBlock>>> {
|
||||
fn style_attribute(&self) -> *const Option<Arc<Locked<PropertyDeclarationBlock>>> {
|
||||
unsafe {
|
||||
(*self.unsafe_get()).style_attribute.borrow_for_layout()
|
||||
}
|
||||
|
@ -835,7 +856,7 @@ impl Element {
|
|||
ns!()
|
||||
}
|
||||
|
||||
pub fn style_attribute(&self) -> &DOMRefCell<Option<Arc<RwLock<PropertyDeclarationBlock>>>> {
|
||||
pub fn style_attribute(&self) -> &DOMRefCell<Option<Arc<Locked<PropertyDeclarationBlock>>>> {
|
||||
&self.style_attribute
|
||||
}
|
||||
|
||||
|
@ -2170,7 +2191,7 @@ impl VirtualMethods for Element {
|
|||
block
|
||||
} else {
|
||||
let win = window_from_node(self);
|
||||
Arc::new(RwLock::new(parse_style_attribute(
|
||||
Arc::new(doc.style_shared_lock().wrap(parse_style_attribute(
|
||||
&attr.value(),
|
||||
&doc.base_url(),
|
||||
win.css_error_reporter(),
|
||||
|
|
|
@ -44,7 +44,6 @@ use dom::text::Text;
|
|||
use gfx_traits::ByteIndex;
|
||||
use html5ever_atoms::{LocalName, Namespace};
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use parking_lot::RwLock;
|
||||
use range::Range;
|
||||
use script_layout_interface::{HTMLCanvasData, LayoutNodeType, SVGSVGData, TrustedNodeAddress};
|
||||
use script_layout_interface::{OpaqueStyleAndLayoutData, PartialPersistentLayoutData};
|
||||
|
@ -69,7 +68,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::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocked};
|
||||
use style::sink::Push;
|
||||
use style::str::is_whitespace;
|
||||
use style::stylist::ApplicableDeclarationBlock;
|
||||
|
@ -377,7 +376,7 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
|||
ServoLayoutNode::from_layout_js(self.element.upcast())
|
||||
}
|
||||
|
||||
fn style_attribute(&self) -> Option<&Arc<RwLock<PropertyDeclarationBlock>>> {
|
||||
fn style_attribute(&self) -> Option<&Arc<StyleLocked<PropertyDeclarationBlock>>> {
|
||||
unsafe {
|
||||
(*self.element.style_attribute()).as_ref()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue