stylo: Switch Gecko over to ServoStyleContext

This commit is contained in:
Manish Goregaokar 2017-07-17 11:42:00 -07:00 committed by Manish Goregaokar
parent 74519cc1a7
commit 89930e7565
19 changed files with 4479 additions and 2353 deletions

View file

@ -1119,7 +1119,7 @@ impl BaseFlow {
/// ///
/// These flags are initially set during flow construction. They only need to be updated here /// These flags are initially set during flow construction. They only need to be updated here
/// if they are based on properties that can change without triggering `RECONSTRUCT_FLOW`. /// if they are based on properties that can change without triggering `RECONSTRUCT_FLOW`.
pub fn update_flags_if_needed(&mut self, style: &ServoComputedValues) { pub fn update_flags_if_needed(&mut self, style: &ComputedValues) {
// For absolutely-positioned flows, changes to top/bottom/left/right can cause these flags // For absolutely-positioned flows, changes to top/bottom/left/right can cause these flags
// to get out of date: // to get out of date:
if self.restyle_damage.contains(REFLOW_OUT_OF_FLOW) { if self.restyle_damage.contains(REFLOW_OUT_OF_FLOW) {

View file

@ -78,7 +78,7 @@ use style::selector_parser::{AttrValue as SelectorAttrValue, NonTSPseudoClass, P
use style::selector_parser::{PseudoElement, SelectorImpl, extended_filtering}; use style::selector_parser::{PseudoElement, SelectorImpl, extended_filtering};
use style::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocked}; use style::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocked};
use style::str::is_whitespace; use style::str::is_whitespace;
use style::stylearc::Arc; use style::stylearc::{Arc, ArcBorrow};
pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) { pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) {
let ptr: *mut StyleData = data.ptr.get(); let ptr: *mut StyleData = data.ptr.get();
@ -412,9 +412,9 @@ impl<'le> TElement for ServoLayoutElement<'le> {
ServoLayoutNode::from_layout_js(self.element.upcast()) ServoLayoutNode::from_layout_js(self.element.upcast())
} }
fn style_attribute(&self) -> Option<&Arc<StyleLocked<PropertyDeclarationBlock>>> { fn style_attribute(&self) -> Option<ArcBorrow<StyleLocked<PropertyDeclarationBlock>>> {
unsafe { unsafe {
(*self.element.style_attribute()).as_ref() (*self.element.style_attribute()).as_ref().map(|x| x.borrow_arc())
} }
} }

View file

@ -90,13 +90,15 @@ impl CSSRuleList {
let index = idx as usize; let index = idx as usize;
let parent_stylesheet = self.parent_stylesheet.style_stylesheet(); let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
let new_rule = let new_rule = css_rules.with_raw_offset_arc(|arc| {
css_rules.insert_rule(&parent_stylesheet.shared_lock, arc.insert_rule(&parent_stylesheet.shared_lock,
rule, rule,
&parent_stylesheet.contents, &parent_stylesheet.contents,
index, index,
nested, nested,
None)?; None)
})?;
let parent_stylesheet = &*self.parent_stylesheet; let parent_stylesheet = &*self.parent_stylesheet;
let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule); let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule);

View file

@ -416,7 +416,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
&style_pseudo, &style_pseudo,
Some(data.styles.primary()), Some(data.styles.primary()),
CascadeFlags::empty(), CascadeFlags::empty(),
&ServoMetricsProvider) &ServoMetricsProvider, (), ())
.clone() .clone()
} }
PseudoElementCascadeType::Lazy => { PseudoElementCascadeType::Lazy => {
@ -428,7 +428,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
RuleInclusion::All, RuleInclusion::All,
data.styles.primary(), data.styles.primary(),
/* is_probe = */ false, /* is_probe = */ false,
&ServoMetricsProvider) &ServoMetricsProvider, (), ())
.unwrap() .unwrap()
.clone() .clone()
} }

View file

@ -10,14 +10,15 @@
use gecko_bindings::bindings::{RawServoImportRule, RawServoSupportsRule}; use gecko_bindings::bindings::{RawServoImportRule, RawServoSupportsRule};
use gecko_bindings::bindings::{RawServoKeyframe, RawServoKeyframesRule}; use gecko_bindings::bindings::{RawServoKeyframe, RawServoKeyframesRule};
use gecko_bindings::bindings::RawServoMediaRule;
use gecko_bindings::bindings::{RawServoNamespaceRule, RawServoPageRule}; use gecko_bindings::bindings::{RawServoNamespaceRule, RawServoPageRule};
use gecko_bindings::bindings::{RawServoRuleNode, RawServoRuleNodeStrong, RawServoDocumentRule, RawServoMediaRule}; use gecko_bindings::bindings::{RawServoRuleNode, RawServoRuleNodeStrong, RawServoDocumentRule};
use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules}; use gecko_bindings::bindings::ServoCssRules;
use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock, RawServoStyleRule, RawServoMediaList}; use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock, RawServoStyleRule, RawServoMediaList};
use gecko_bindings::structs::RawServoStyleSheetContents; use gecko_bindings::structs::{RawServoStyleSheetContents, ServoComputedValues, ServoStyleContext};
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI}; use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI};
use media_queries::MediaList; use media_queries::MediaList;
use properties::{ComputedValues, PropertyDeclarationBlock}; use properties::{ComputedValues, ComputedValuesInner, PropertyDeclarationBlock};
use properties::animated_properties::AnimationValue; use properties::animated_properties::AnimationValue;
use rule_tree::StrongRuleNode; use rule_tree::StrongRuleNode;
use shared_lock::Locked; use shared_lock::Locked;
@ -51,9 +52,12 @@ impl_arc_ffi!(Locked<CssRules> => ServoCssRules
impl_arc_ffi!(StylesheetContents => RawServoStyleSheetContents impl_arc_ffi!(StylesheetContents => RawServoStyleSheetContents
[Servo_StyleSheetContents_AddRef, Servo_StyleSheetContents_Release]); [Servo_StyleSheetContents_AddRef, Servo_StyleSheetContents_Release]);
impl_arc_ffi!(ComputedValues => ServoComputedValues impl_arc_ffi!(ComputedValuesInner => ServoComputedValues
[Servo_ComputedValues_AddRef, Servo_ComputedValues_Release]); [Servo_ComputedValues_AddRef, Servo_ComputedValues_Release]);
impl_arc_ffi!(ComputedValues => ServoStyleContext
[Servo_StyleContext_AddRef, Servo_StyleContext_Release]);
impl_arc_ffi!(Locked<PropertyDeclarationBlock> => RawServoDeclarationBlock impl_arc_ffi!(Locked<PropertyDeclarationBlock> => RawServoDeclarationBlock
[Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]); [Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]);

View file

@ -5,6 +5,8 @@ use gecko_bindings::structs::nsStyleTransformMatrix;
use gecko_bindings::structs::nsTArray; use gecko_bindings::structs::nsTArray;
type nsACString_internal = nsACString; type nsACString_internal = nsACString;
type nsAString_internal = nsAString; type nsAString_internal = nsAString;
pub type ServoStyleContextBorrowed<'a> = &'a ServoStyleContext;
pub type ServoStyleContextBorrowedOrNull<'a> = Option<&'a ::properties::ComputedValues>;
use gecko_bindings::structs::mozilla::css::GridTemplateAreasValue; use gecko_bindings::structs::mozilla::css::GridTemplateAreasValue;
use gecko_bindings::structs::mozilla::css::ErrorReporter; use gecko_bindings::structs::mozilla::css::ErrorReporter;
use gecko_bindings::structs::mozilla::css::ImageValue; use gecko_bindings::structs::mozilla::css::ImageValue;
@ -215,6 +217,9 @@ use gecko_bindings::structs::nsresult;
use gecko_bindings::structs::Loader; use gecko_bindings::structs::Loader;
use gecko_bindings::structs::LoaderReusableStyleSheets; use gecko_bindings::structs::LoaderReusableStyleSheets;
use gecko_bindings::structs::ServoStyleSheet; use gecko_bindings::structs::ServoStyleSheet;
use gecko_bindings::structs::ServoComputedValues;
use gecko_bindings::structs::ServoStyleContext;
use gecko_bindings::structs::ServoStyleContextStrong;
use gecko_bindings::structs::EffectCompositor_CascadeLevel; use gecko_bindings::structs::EffectCompositor_CascadeLevel;
use gecko_bindings::structs::UpdateAnimationsTasks; use gecko_bindings::structs::UpdateAnimationsTasks;
use gecko_bindings::structs::ParsingMode; use gecko_bindings::structs::ParsingMode;
@ -317,8 +322,6 @@ pub type RawServoStyleSheetContentsBorrowedOrNull<'a> = Option<&'a RawServoStyle
pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>; pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong<ServoComputedValues>;
pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues; pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues;
pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>; pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>;
enum ServoComputedValuesVoid { }
pub struct ServoComputedValues(ServoComputedValuesVoid);
pub type RawServoDeclarationBlockStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoDeclarationBlock>; pub type RawServoDeclarationBlockStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoDeclarationBlock>;
pub type RawServoDeclarationBlockBorrowed<'a> = &'a RawServoDeclarationBlock; pub type RawServoDeclarationBlockBorrowed<'a> = &'a RawServoDeclarationBlock;
pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclarationBlock>; pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclarationBlock>;
@ -528,6 +531,19 @@ extern "C" {
pub fn Gecko_DestroyAnonymousContentList(anon_content: pub fn Gecko_DestroyAnonymousContentList(anon_content:
*mut nsTArray<*mut nsIContent>); *mut nsTArray<*mut nsIContent>);
} }
extern "C" {
pub fn Gecko_ServoStyleContext_Init(context: *mut ServoStyleContext,
parent_context:
ServoStyleContextBorrowedOrNull,
pres_context:
RawGeckoPresContextBorrowed,
values: ServoComputedValuesStrong,
pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom);
}
extern "C" {
pub fn Gecko_ServoStyleContext_Destroy(context: *mut ServoStyleContext);
}
extern "C" { extern "C" {
pub fn Gecko_ConstructStyleChildrenIterator(aElement: pub fn Gecko_ConstructStyleChildrenIterator(aElement:
RawGeckoElementBorrowed, RawGeckoElementBorrowed,
@ -755,9 +771,9 @@ extern "C" {
extern "C" { extern "C" {
pub fn Gecko_UpdateAnimations(aElementOrPseudo: RawGeckoElementBorrowed, pub fn Gecko_UpdateAnimations(aElementOrPseudo: RawGeckoElementBorrowed,
aOldComputedValues: aOldComputedValues:
ServoComputedValuesBorrowedOrNull, ServoStyleContextBorrowedOrNull,
aComputedValues: aComputedValues:
ServoComputedValuesBorrowedOrNull, ServoStyleContextBorrowedOrNull,
aTasks: UpdateAnimationsTasks); aTasks: UpdateAnimationsTasks);
} }
extern "C" { extern "C" {
@ -1957,10 +1973,10 @@ extern "C" {
pub fn Servo_StyleSet_ResolveForDeclarations(set: pub fn Servo_StyleSet_ResolveForDeclarations(set:
RawServoStyleSetBorrowed, RawServoStyleSetBorrowed,
parent_style: parent_style:
ServoComputedValuesBorrowedOrNull, ServoStyleContextBorrowedOrNull,
declarations: declarations:
RawServoDeclarationBlockBorrowed) RawServoDeclarationBlockBorrowed)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_StyleSet_MightHaveAttributeDependency(set: pub fn Servo_StyleSet_MightHaveAttributeDependency(set:
@ -2661,23 +2677,27 @@ extern "C" {
} }
extern "C" { extern "C" {
pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
ServoComputedValuesBorrowedOrNull, ServoStyleContextBorrowedOrNull,
pseudo_type:
CSSPseudoElementType,
pseudo_tag: *mut nsIAtom, pseudo_tag: *mut nsIAtom,
set: set:
RawServoStyleSetBorrowed) RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_ComputedValues_Inherit(set: RawServoStyleSetBorrowed, pub fn Servo_ComputedValues_Inherit(set: RawServoStyleSetBorrowed,
pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom,
parent_style: parent_style:
ServoComputedValuesBorrowedOrNull, ServoStyleContextBorrowedOrNull,
target: InheritTarget) target: InheritTarget)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_ComputedValues_GetVisitedStyle(values: pub fn Servo_ComputedValues_GetVisitedStyle(values:
ServoComputedValuesBorrowed) ServoComputedValuesBorrowed)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_ComputedValues_GetStyleBits(values: pub fn Servo_ComputedValues_GetStyleBits(values:
@ -2697,6 +2717,16 @@ extern "C" {
rules: rules:
RawGeckoServoStyleRuleListBorrowedMut); RawGeckoServoStyleRuleListBorrowedMut);
} }
extern "C" {
pub fn Servo_StyleContext_NewContext(values: ServoComputedValuesBorrowed,
parent:
ServoStyleContextBorrowedOrNull,
pres_context:
RawGeckoPresContextBorrowed,
pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom)
-> ServoStyleContextStrong;
}
extern "C" { extern "C" {
pub fn Servo_Initialize(dummy_url_data: *mut RawGeckoURLExtraData); pub fn Servo_Initialize(dummy_url_data: *mut RawGeckoURLExtraData);
} }
@ -2716,20 +2746,22 @@ extern "C" {
extern "C" { extern "C" {
pub fn Servo_ResolveStyle(element: RawGeckoElementBorrowed, pub fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
set: RawServoStyleSetBorrowed) set: RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed, pub fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
pseudo_type: CSSPseudoElementType, pseudo_type: CSSPseudoElementType,
is_probe: bool, pseudo_tag: *mut nsIAtom, is_probe: bool,
inherited_style: inherited_style:
ServoComputedValuesBorrowedOrNull, ServoComputedValuesBorrowedOrNull,
parent_style_context:
ServoStyleContextBorrowedOrNull,
set: RawServoStyleSetBorrowed) set: RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed, pub fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed,
primary_style: ServoComputedValuesBorrowed); primary_style: ServoStyleContextBorrowed);
} }
extern "C" { extern "C" {
pub fn Servo_HasAuthorSpecifiedRules(element: RawGeckoElementBorrowed, pub fn Servo_HasAuthorSpecifiedRules(element: RawGeckoElementBorrowed,
@ -2739,11 +2771,14 @@ extern "C" {
extern "C" { extern "C" {
pub fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed, pub fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
pseudo_type: CSSPseudoElementType, pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom,
parent_style_context:
ServoStyleContextBorrowedOrNull,
rule_inclusion: StyleRuleInclusion, rule_inclusion: StyleRuleInclusion,
snapshots: snapshots:
*const ServoElementSnapshotTable, *const ServoElementSnapshotTable,
set: RawServoStyleSetBorrowed) set: RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_TraverseSubtree(root: RawGeckoElementBorrowed, pub fn Servo_TraverseSubtree(root: RawGeckoElementBorrowed,
@ -2765,12 +2800,12 @@ extern "C" {
element: element:
RawGeckoElementBorrowed, RawGeckoElementBorrowed,
existing_style: existing_style:
ServoComputedValuesBorrowed, ServoStyleContextBorrowed,
snapshots: snapshots:
*const ServoElementSnapshotTable, *const ServoElementSnapshotTable,
pseudo_type: pseudo_type:
CSSPseudoElementType) CSSPseudoElementType)
-> ServoComputedValuesStrong; -> ServoStyleContextStrong;
} }
extern "C" { extern "C" {
pub fn Servo_SerializeFontValueForCanvas(declarations: pub fn Servo_SerializeFontValueForCanvas(declarations:

View file

@ -689,6 +689,45 @@ impl PseudoElement {
} }
} }
/// Construct a `CSSPseudoElementType` from a pseudo-element
#[inline]
pub fn pseudo_type(&self) -> CSSPseudoElementType {
match *self {
PseudoElement::After => CSSPseudoElementType::after,
PseudoElement::Before => CSSPseudoElementType::before,
PseudoElement::Backdrop => CSSPseudoElementType::backdrop,
PseudoElement::Cue => CSSPseudoElementType::cue,
PseudoElement::FirstLetter => CSSPseudoElementType::firstLetter,
PseudoElement::FirstLine => CSSPseudoElementType::firstLine,
PseudoElement::MozSelection => CSSPseudoElementType::mozSelection,
PseudoElement::MozFocusInner => CSSPseudoElementType::mozFocusInner,
PseudoElement::MozFocusOuter => CSSPseudoElementType::mozFocusOuter,
PseudoElement::MozListBullet => CSSPseudoElementType::mozListBullet,
PseudoElement::MozListNumber => CSSPseudoElementType::mozListNumber,
PseudoElement::MozMathAnonymous => CSSPseudoElementType::mozMathAnonymous,
PseudoElement::MozNumberWrapper => CSSPseudoElementType::mozNumberWrapper,
PseudoElement::MozNumberText => CSSPseudoElementType::mozNumberText,
PseudoElement::MozNumberSpinBox => CSSPseudoElementType::mozNumberSpinBox,
PseudoElement::MozNumberSpinUp => CSSPseudoElementType::mozNumberSpinUp,
PseudoElement::MozNumberSpinDown => CSSPseudoElementType::mozNumberSpinDown,
PseudoElement::MozProgressBar => CSSPseudoElementType::mozProgressBar,
PseudoElement::MozRangeTrack => CSSPseudoElementType::mozRangeTrack,
PseudoElement::MozRangeProgress => CSSPseudoElementType::mozRangeProgress,
PseudoElement::MozRangeThumb => CSSPseudoElementType::mozRangeThumb,
PseudoElement::MozMeterBar => CSSPseudoElementType::mozMeterBar,
PseudoElement::MozPlaceholder => CSSPseudoElementType::mozPlaceholder,
PseudoElement::Placeholder => CSSPseudoElementType::placeholder,
PseudoElement::MozColorSwatch => CSSPseudoElementType::mozColorSwatch,
_ => CSSPseudoElementType::NotPseudo
}
}
/// Get a PseudoInfo for a pseudo
pub fn pseudo_info(&self) -> (*mut structs::nsIAtom, CSSPseudoElementType) {
(self.atom().as_ptr(), self.pseudo_type())
}
/// Construct a pseudo-element from an anonymous box `Atom`. /// Construct a pseudo-element from an anonymous box `Atom`.
#[inline] #[inline]
pub fn from_anon_box_atom(atom: &Atom) -> Option<Self> { pub fn from_anon_box_atom(atom: &Atom) -> Option<Self> {

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -107,6 +107,25 @@ impl PseudoElement {
} }
} }
/// Construct a `CSSPseudoElementType` from a pseudo-element
#[inline]
pub fn pseudo_type(&self) -> CSSPseudoElementType {
match *self {
% for pseudo in PSEUDOS:
% if not pseudo.is_anon_box():
PseudoElement::${pseudo.capitalized()} => CSSPseudoElementType::${pseudo.original_ident},
% endif
% endfor
_ => CSSPseudoElementType::NotPseudo
}
}
/// Get a PseudoInfo for a pseudo
pub fn pseudo_info(&self) -> (*mut structs::nsIAtom, CSSPseudoElementType) {
(self.atom().as_ptr(), self.pseudo_type())
}
/// Construct a pseudo-element from an anonymous box `Atom`. /// Construct a pseudo-element from an anonymous box `Atom`.
#[inline] #[inline]
pub fn from_anon_box_atom(atom: &Atom) -> Option<Self> { pub fn from_anon_box_atom(atom: &Atom) -> Option<Self> {

View file

@ -7,7 +7,6 @@
use gecko_bindings::bindings; use gecko_bindings::bindings;
use gecko_bindings::structs; use gecko_bindings::structs;
use gecko_bindings::structs::{nsChangeHint, nsStyleContext}; use gecko_bindings::structs::{nsChangeHint, nsStyleContext};
use gecko_bindings::sugar::ownership::FFIArcHelpers;
use matching::{StyleChange, StyleDifference}; use matching::{StyleChange, StyleDifference};
use properties::ComputedValues; use properties::ComputedValues;
use std::ops::{BitAnd, BitOr, BitOrAssign, Not}; use std::ops::{BitAnd, BitOr, BitOrAssign, Not};
@ -56,7 +55,7 @@ impl GeckoRestyleDamage {
let mut any_style_changed: bool = false; let mut any_style_changed: bool = false;
let hint = unsafe { let hint = unsafe {
bindings::Gecko_CalcStyleDifference(context, bindings::Gecko_CalcStyleDifference(context,
new_style.as_borrowed(), &new_style,
&mut any_style_changed) &mut any_style_changed)
}; };
let change = if any_style_changed { StyleChange::Changed } else { StyleChange::Unchanged }; let change = if any_style_changed { StyleChange::Changed } else { StyleChange::Unchanged };

View file

@ -64,7 +64,7 @@ use gecko_bindings::structs::EffectCompositor_CascadeLevel as CascadeLevel;
use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE; use gecko_bindings::structs::NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE;
use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS; use gecko_bindings::structs::NODE_IS_NATIVE_ANONYMOUS;
use gecko_bindings::structs::nsIDocument_DocumentTheme as DocumentTheme; use gecko_bindings::structs::nsIDocument_DocumentTheme as DocumentTheme;
use gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasSimpleFFI}; use gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
use logical_geometry::WritingMode; use logical_geometry::WritingMode;
use media_queries::Device; use media_queries::Device;
use properties::{ComputedValues, parse_style_attribute}; use properties::{ComputedValues, parse_style_attribute};
@ -1101,10 +1101,9 @@ impl<'le> TElement for GeckoElement<'le> {
let computed_data = self.borrow_data(); let computed_data = self.borrow_data();
let computed_values = let computed_values =
computed_data.as_ref().map(|d| d.styles.primary()); computed_data.as_ref().map(|d| d.styles.primary());
let computed_values_opt =
computed_values.map(|v| v.as_borrowed());
let before_change_values = let before_change_values =
before_change_style.as_ref().map(|v| v.as_borrowed()); before_change_style.as_ref().map(|x| &**x);
let computed_values_opt = computed_values.as_ref().map(|x| &***x);
unsafe { unsafe {
Gecko_UpdateAnimations(self.0, Gecko_UpdateAnimations(self.0,
before_change_values, before_change_values,

View file

@ -46,7 +46,6 @@ use gecko_bindings::structs;
use gecko_bindings::structs::nsCSSPropertyID; use gecko_bindings::structs::nsCSSPropertyID;
use gecko_bindings::structs::nsStyleVariables; use gecko_bindings::structs::nsStyleVariables;
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
use gecko_bindings::sugar::ownership::HasArcFFI;
use gecko::values::convert_nscolor_to_rgba; use gecko::values::convert_nscolor_to_rgba;
use gecko::values::convert_rgba_to_nscolor; use gecko::values::convert_rgba_to_nscolor;
use gecko::values::GeckoStyleCoordConvertible; use gecko::values::GeckoStyleCoordConvertible;
@ -58,7 +57,7 @@ use properties::computed_value_flags::ComputedValueFlags;
use properties::{longhands, FontComputationData, Importance, LonghandId}; use properties::{longhands, FontComputationData, Importance, LonghandId};
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId}; use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
use rule_tree::StrongRuleNode; use rule_tree::StrongRuleNode;
use std::mem::{forget, transmute, zeroed}; use std::mem::{forget, uninitialized, transmute, zeroed};
use std::{cmp, ops, ptr}; use std::{cmp, ops, ptr};
use stylearc::{Arc, RawOffsetArc}; use stylearc::{Arc, RawOffsetArc};
use values::{Auto, CustomIdent, Either, KeyframesName}; use values::{Auto, CustomIdent, Either, KeyframesName};
@ -74,11 +73,27 @@ pub mod style_structs {
} }
pub use ::gecko_bindings::structs::mozilla::ServoComputedValues2 as ComputedValuesInner; pub type ComputedValuesInner = ::gecko_bindings::structs::ServoComputedValues;
#[derive(Clone, Debug)] #[derive(Debug)]
pub struct ComputedValues { #[repr(C)]
pub inner: ComputedValuesInner pub struct ComputedValues(::gecko_bindings::structs::mozilla::ServoStyleContext);
impl Drop for ComputedValues {
fn drop(&mut self) {
unsafe {
bindings::Gecko_ServoStyleContext_Destroy(&mut self.0);
}
}
}
unsafe impl Sync for ComputedValues {}
unsafe impl Send for ComputedValues {}
impl Clone for ComputedValues {
fn clone(&self) -> Self {
unreachable!()
}
} }
impl Clone for ComputedValuesInner { impl Clone for ComputedValuesInner {
@ -97,6 +112,9 @@ impl Clone for ComputedValuesInner {
} }
} }
pub type PseudoInfo = (*mut structs::nsIAtom, structs::CSSPseudoElementType);
pub type ParentStyleContextInfo<'a> = Option< &'a ComputedValues>;
impl ComputedValuesInner { impl ComputedValuesInner {
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>, pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
writing_mode: WritingMode, writing_mode: WritingMode,
@ -134,21 +152,42 @@ impl ComputedValuesInner {
% endfor % endfor
} }
} }
pub fn to_outer(self) -> Arc<ComputedValues> { pub fn to_outer(self, device: &Device, parent: ParentStyleContextInfo,
Arc::new(ComputedValues {inner: self}) info: Option<PseudoInfo>) -> Arc<ComputedValues> {
let (tag, ty) = if let Some(info) = info {
info
} else {
(ptr::null_mut(), structs::CSSPseudoElementType::NotPseudo)
};
unsafe { Self::to_outer_from_arc(Arc::new(self), device.pres_context(), parent, ty, tag) }
}
pub unsafe fn to_outer_from_arc(s: Arc<Self>, pres_context: bindings::RawGeckoPresContextBorrowed,
parent: ParentStyleContextInfo,
pseudo_ty: structs::CSSPseudoElementType,
pseudo_tag: *mut structs::nsIAtom) -> Arc<ComputedValues> {
use gecko_bindings::sugar::ownership::FFIArcHelpers;
let arc = unsafe {
let arc: Arc<ComputedValues> = Arc::new(uninitialized());
bindings::Gecko_ServoStyleContext_Init(&arc.0 as *const _ as *mut _, parent, pres_context,
s.into_strong(), pseudo_ty, pseudo_tag);
arc
};
arc
} }
} }
impl ops::Deref for ComputedValues { impl ops::Deref for ComputedValues {
type Target = ComputedValuesInner; type Target = ComputedValuesInner;
fn deref(&self) -> &ComputedValuesInner { fn deref(&self) -> &ComputedValuesInner {
&self.inner unsafe { &*self.0.mSource.mRawPtr }
} }
} }
impl ops::DerefMut for ComputedValues { impl ops::DerefMut for ComputedValues {
fn deref_mut(&mut self) -> &mut ComputedValuesInner { fn deref_mut(&mut self) -> &mut ComputedValuesInner {
&mut self.inner unsafe { &mut *self.0.mSource.mRawPtr }
} }
} }
@ -197,12 +236,12 @@ impl ComputedValuesInner {
} }
/// Gets a reference to the visited style, if any. /// Gets a reference to the visited style, if any.
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> { pub fn get_visited_style(&self) -> Option< & ComputedValues> {
self.visited_style.as_ref().map(|x| &***x) self.visited_style.as_ref().map(|x| &**x)
} }
/// Gets a reference to the visited style. Panic if no visited style exists. /// Gets a reference to the visited style. Panic if no visited style exists.
pub fn visited_style(&self) -> &ComputedValuesInner { pub fn visited_style(&self) -> &ComputedValues {
self.get_visited_style().unwrap() self.get_visited_style().unwrap()
} }
@ -4801,7 +4840,7 @@ clip-path
#[allow(non_snake_case, unused_variables)] #[allow(non_snake_case, unused_variables)]
pub unsafe extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: pub unsafe extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values:
ServoComputedValuesBorrowedOrNull) -> *const ${style_struct.gecko_ffi_name} { ServoComputedValuesBorrowedOrNull) -> *const ${style_struct.gecko_ffi_name} {
ComputedValues::arc_from_borrowed(&computed_values).unwrap().get_${style_struct.name_lower}().get_gecko() computed_values.unwrap().get_${style_struct.name_lower}().get_gecko()
as *const ${style_struct.gecko_ffi_name} as *const ${style_struct.gecko_ffi_name}
} }
</%def> </%def>

View file

@ -1871,9 +1871,14 @@ pub mod style_structs {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use gecko_properties::ComputedValues; pub use gecko_properties::{ComputedValues, ComputedValuesInner, ParentStyleContextInfo, PseudoInfo};
#[cfg(feature = "gecko")]
pub use gecko_properties::ComputedValuesInner; #[cfg(feature = "servo")]
/// Servo doesn't have style contexts so this is extraneous info
pub type PseudoInfo = ();
#[cfg(feature = "servo")]
/// Servo doesn't have style contexts so this is extraneous info
pub type ParentStyleContextInfo = ();
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
@ -1970,7 +1975,8 @@ impl ops::DerefMut for ComputedValues {
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
impl ComputedValuesInner { impl ComputedValuesInner {
/// Convert to an Arc<ComputedValues> /// Convert to an Arc<ComputedValues>
pub fn to_outer(self) -> Arc<ComputedValues> { pub fn to_outer(self, _: &Device, _: ParentStyleContextInfo,
_: Option<PseudoInfo>) -> Arc<ComputedValues> {
Arc::new(ComputedValues {inner: self}) Arc::new(ComputedValues {inner: self})
} }
@ -2011,13 +2017,13 @@ impl ComputedValuesInner {
} }
/// Gets a reference to the visited style, if any. /// Gets a reference to the visited style, if any.
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> { pub fn get_visited_style(&self) -> Option< & ComputedValues> {
self.visited_style.as_ref().map(|x| &***x) self.visited_style.as_ref().map(|x| &**x)
} }
/// Gets a reference to the visited style. Panic if no visited style exists. /// Gets a reference to the visited style. Panic if no visited style exists.
pub fn visited_style(&self) -> &ComputedValuesInner { pub fn visited_style(&self) -> &ComputedValues {
self.get_visited_style().as_ref().map(|x| &**x).unwrap() self.get_visited_style().unwrap()
} }
/// Clone the visited style. Used for inheriting parent styles in /// Clone the visited style. Used for inheriting parent styles in

View file

@ -166,6 +166,9 @@ impl PseudoElement {
pub fn canonical(&self) -> PseudoElement { pub fn canonical(&self) -> PseudoElement {
self.clone() self.clone()
} }
/// Stub, only Gecko needs this
pub fn pseudo_info(&self) -> () { () }
} }
/// The type used for storing pseudo-class string arguments. /// The type used for storing pseudo-class string arguments.

View file

@ -47,7 +47,7 @@ pub struct PrimaryStyle {
fn with_default_parent_styles<E, F, R>(element: E, f: F) -> R fn with_default_parent_styles<E, F, R>(element: E, f: F) -> R
where where
E: TElement, E: TElement,
F: FnOnce(Option<&ComputedValuesInner>, Option<&ComputedValuesInner>) -> R, F: FnOnce(Option<&ComputedValues>, Option<&ComputedValuesInner>) -> R,
{ {
let parent_el = element.inheritance_parent(); let parent_el = element.inheritance_parent();
let parent_data = parent_el.as_ref().and_then(|e| e.borrow_data()); let parent_data = parent_el.as_ref().and_then(|e| e.borrow_data());
@ -72,7 +72,7 @@ where
layout_parent_style = Some(layout_parent_data.styles.primary()); layout_parent_style = Some(layout_parent_data.styles.primary());
} }
f(parent_style.map(|s| &***s), layout_parent_style.map(|s| &***s)) f(parent_style.map(|x| &**x), layout_parent_style.map(|s| &***s))
} }
impl<'a, 'ctx, 'le, E> StyleResolverForElement<'a, 'ctx, 'le, E> impl<'a, 'ctx, 'le, E> StyleResolverForElement<'a, 'ctx, 'le, E>
@ -98,7 +98,7 @@ where
/// Resolve just the style of a given element. /// Resolve just the style of a given element.
pub fn resolve_primary_style( pub fn resolve_primary_style(
&mut self, &mut self,
parent_style: Option<&ComputedValuesInner>, parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValuesInner>, layout_parent_style: Option<&ComputedValuesInner>,
) -> PrimaryStyle { ) -> PrimaryStyle {
let primary_results = let primary_results =
@ -119,6 +119,7 @@ where
relevant_link_found || relevant_link_found ||
parent_style.and_then(|s| s.get_visited_style()).is_some(); parent_style.and_then(|s| s.get_visited_style()).is_some();
let pseudo = self.element.implemented_pseudo_element();
if should_compute_visited_style { if should_compute_visited_style {
visited_style = Some(self.cascade_style( visited_style = Some(self.cascade_style(
visited_rules.as_ref().or(Some(&primary_results.rule_node)), visited_rules.as_ref().or(Some(&primary_results.rule_node)),
@ -126,17 +127,16 @@ where
parent_style, parent_style,
layout_parent_style, layout_parent_style,
CascadeVisitedMode::Visited, CascadeVisitedMode::Visited,
/* pseudo = */ None, /* pseudo = */ pseudo.as_ref(),
)); ));
} }
let style = self.cascade_style( let style = self.cascade_style(
Some(&primary_results.rule_node), Some(&primary_results.rule_node),
visited_style, visited_style,
parent_style, parent_style,
layout_parent_style, layout_parent_style,
CascadeVisitedMode::Unvisited, CascadeVisitedMode::Unvisited,
/* pseudo = */ None, /* pseudo = */ pseudo.as_ref(),
); );
PrimaryStyle { style, } PrimaryStyle { style, }
@ -146,7 +146,7 @@ where
/// Resolve the style of a given element, and all its eager pseudo-elements. /// Resolve the style of a given element, and all its eager pseudo-elements.
pub fn resolve_style( pub fn resolve_style(
&mut self, &mut self,
parent_style: Option<&ComputedValuesInner>, parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValuesInner>, layout_parent_style: Option<&ComputedValuesInner>,
) -> ElementStyles { ) -> ElementStyles {
use properties::longhands::display::computed_value::T as display; use properties::longhands::display::computed_value::T as display;
@ -215,7 +215,7 @@ where
fn cascade_style_and_visited( fn cascade_style_and_visited(
&mut self, &mut self,
inputs: CascadeInputs, inputs: CascadeInputs,
parent_style: Option<&ComputedValuesInner>, parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValuesInner>, layout_parent_style: Option<&ComputedValuesInner>,
pseudo: Option<&PseudoElement>, pseudo: Option<&PseudoElement>,
) -> Arc<ComputedValues> { ) -> Arc<ComputedValues> {
@ -462,7 +462,7 @@ where
&mut self, &mut self,
rules: Option<&StrongRuleNode>, rules: Option<&StrongRuleNode>,
style_if_visited: Option<Arc<ComputedValues>>, style_if_visited: Option<Arc<ComputedValues>>,
mut parent_style: Option<&ComputedValuesInner>, mut parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValuesInner>, layout_parent_style: Option<&ComputedValuesInner>,
cascade_visited: CascadeVisitedMode, cascade_visited: CascadeVisitedMode,
pseudo: Option<&PseudoElement>, pseudo: Option<&PseudoElement>,
@ -485,12 +485,17 @@ where
cascade_flags.insert(IS_ROOT_ELEMENT); cascade_flags.insert(IS_ROOT_ELEMENT);
} }
#[cfg(feature = "gecko")]
let parent_style_context = parent_style;
#[cfg(feature = "servo")]
let parent_style_context = ();
let values = let values =
cascade( cascade(
self.context.shared.stylist.device(), self.context.shared.stylist.device(),
rules.unwrap_or(self.context.shared.stylist.rule_tree().root()), rules.unwrap_or(self.context.shared.stylist.rule_tree().root()),
&self.context.shared.guards, &self.context.shared.guards,
parent_style, parent_style.map(|x| &**x),
layout_parent_style, layout_parent_style,
style_if_visited, style_if_visited,
Some(&mut cascade_info), Some(&mut cascade_info),
@ -500,6 +505,18 @@ where
); );
cascade_info.finish(&self.element.as_node()); cascade_info.finish(&self.element.as_node());
values.to_outer()
// In case of NAC like ::placeholder we style it via
// cascade_primary without a PseudoElement, but
// the element itself is a pseudo, so try to use that
// when `pseudo` is unset
let pseudo_info = if let Some(pseudo) = pseudo {
Some(pseudo.pseudo_info())
} else {
self.element.implemented_pseudo_element().map(|x| x.pseudo_info())
};
values.to_outer(self.context.shared.stylist.device(),
parent_style_context,
pseudo_info)
} }
} }

View file

@ -17,7 +17,7 @@ use invalidation::element::invalidation_map::InvalidationMap;
use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey}; use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
use media_queries::Device; use media_queries::Device;
use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner}; use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner};
use properties::{AnimationRules, PropertyDeclarationBlock}; use properties::{AnimationRules, PropertyDeclarationBlock, PseudoInfo, ParentStyleContextInfo};
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use properties::INHERIT_ALL; use properties::INHERIT_ALL;
use rule_tree::{CascadeLevel, RuleTree, StyleSource}; use rule_tree::{CascadeLevel, RuleTree, StyleSource};
@ -601,7 +601,9 @@ impl Stylist {
pseudo: &PseudoElement, pseudo: &PseudoElement,
parent: Option<&ComputedValuesInner>, parent: Option<&ComputedValuesInner>,
cascade_flags: CascadeFlags, cascade_flags: CascadeFlags,
font_metrics: &FontMetricsProvider) font_metrics: &FontMetricsProvider,
pseudo_info: PseudoInfo,
parent_style_context: ParentStyleContextInfo)
-> Arc<ComputedValues> { -> Arc<ComputedValues> {
debug_assert!(pseudo.is_precomputed()); debug_assert!(pseudo.is_precomputed());
@ -638,7 +640,8 @@ impl Stylist {
None, None,
font_metrics, font_metrics,
cascade_flags, cascade_flags,
self.quirks_mode).to_outer() self.quirks_mode).to_outer(self.device(), parent_style_context,
Some(pseudo_info))
} }
/// Returns the style for an anonymous box of the given type. /// Returns the style for an anonymous box of the given type.
@ -675,7 +678,7 @@ impl Stylist {
cascade_flags.insert(INHERIT_ALL); cascade_flags.insert(INHERIT_ALL);
} }
self.precomputed_values_for_pseudo(guards, &pseudo, Some(parent_style), cascade_flags, self.precomputed_values_for_pseudo(guards, &pseudo, Some(parent_style), cascade_flags,
&ServoMetricsProvider) &ServoMetricsProvider, (), ())
} }
/// Computes a pseudo-element style lazily during layout. /// Computes a pseudo-element style lazily during layout.
@ -692,7 +695,9 @@ impl Stylist {
rule_inclusion: RuleInclusion, rule_inclusion: RuleInclusion,
parent_style: &ComputedValuesInner, parent_style: &ComputedValuesInner,
is_probe: bool, is_probe: bool,
font_metrics: &FontMetricsProvider) font_metrics: &FontMetricsProvider,
pseudo_info: PseudoInfo,
parent_style_context: ParentStyleContextInfo)
-> Option<Arc<ComputedValues>> -> Option<Arc<ComputedValues>>
where E: TElement, where E: TElement,
{ {
@ -701,7 +706,9 @@ impl Stylist {
self.compute_pseudo_element_style_with_inputs(&cascade_inputs, self.compute_pseudo_element_style_with_inputs(&cascade_inputs,
guards, guards,
parent_style, parent_style,
font_metrics) font_metrics,
pseudo_info,
parent_style_context)
} }
/// Computes a pseudo-element style lazily using the given CascadeInputs. /// Computes a pseudo-element style lazily using the given CascadeInputs.
@ -712,7 +719,9 @@ impl Stylist {
inputs: &CascadeInputs, inputs: &CascadeInputs,
guards: &StylesheetGuards, guards: &StylesheetGuards,
parent_style: &ComputedValuesInner, parent_style: &ComputedValuesInner,
font_metrics: &FontMetricsProvider) font_metrics: &FontMetricsProvider,
pseudo_info: PseudoInfo,
parent_style_context: ParentStyleContextInfo)
-> Option<Arc<ComputedValues>> -> Option<Arc<ComputedValues>>
{ {
// We may have only visited rules in cases when we are actually // We may have only visited rules in cases when we are actually
@ -734,7 +743,7 @@ impl Stylist {
// We want to use the visited bits (if any) from our parent style as // We want to use the visited bits (if any) from our parent style as
// our parent. // our parent.
let inherited_style = let inherited_style =
parent_style.get_visited_style().unwrap_or(parent_style); parent_style.get_visited_style().map(|x| &**x).unwrap_or(parent_style);
// FIXME(emilio): The lack of layout_parent_style here could be // FIXME(emilio): The lack of layout_parent_style here could be
// worrying, but we're probably dropping the display fixup for // worrying, but we're probably dropping the display fixup for
@ -751,7 +760,8 @@ impl Stylist {
None, None,
font_metrics, font_metrics,
CascadeFlags::empty(), CascadeFlags::empty(),
self.quirks_mode).to_outer(); self.quirks_mode).to_outer(self.device(), parent_style_context,
Some(pseudo_info.clone()));
Some(computed) Some(computed)
} else { } else {
@ -775,7 +785,9 @@ impl Stylist {
None, None,
font_metrics, font_metrics,
CascadeFlags::empty(), CascadeFlags::empty(),
self.quirks_mode).to_outer()) self.quirks_mode).to_outer(self.device(),
parent_style_context,
Some(pseudo_info)))
} }
/// Computes the cascade inputs for a lazily-cascaded pseudo-element. /// Computes the cascade inputs for a lazily-cascaded pseudo-element.
@ -1313,7 +1325,8 @@ impl Stylist {
pub fn compute_for_declarations(&self, pub fn compute_for_declarations(&self,
guards: &StylesheetGuards, guards: &StylesheetGuards,
parent_style: &ComputedValuesInner, parent_style: &ComputedValuesInner,
declarations: Arc<Locked<PropertyDeclarationBlock>>) declarations: Arc<Locked<PropertyDeclarationBlock>>,
parent_style_context: ParentStyleContextInfo)
-> Arc<ComputedValues> { -> Arc<ComputedValues> {
use font_metrics::get_metrics_provider_for_product; use font_metrics::get_metrics_provider_for_product;
@ -1337,7 +1350,7 @@ impl Stylist {
None, None,
&metrics, &metrics,
CascadeFlags::empty(), CascadeFlags::empty(),
self.quirks_mode).to_outer() self.quirks_mode).to_outer(self.device(), parent_style_context, None)
} }
/// Accessor for a shared reference to the device. /// Accessor for a shared reference to the device.

View file

@ -484,7 +484,7 @@ where
let primary_style = let primary_style =
StyleResolverForElement::new(*ancestor, context, rule_inclusion) StyleResolverForElement::new(*ancestor, context, rule_inclusion)
.resolve_primary_style( .resolve_primary_style(
style.as_ref().map(|s| &***s), style.as_ref().map(|s| &**s),
layout_parent_style.as_ref().map(|s| &***s) layout_parent_style.as_ref().map(|s| &***s)
); );
@ -501,7 +501,7 @@ where
context.thread_local.bloom_filter.assert_complete(element); context.thread_local.bloom_filter.assert_complete(element);
StyleResolverForElement::new(element, context, rule_inclusion) StyleResolverForElement::new(element, context, rule_inclusion)
.resolve_style( .resolve_style(
style.as_ref().map(|s| &***s), style.as_ref().map(|s| &**s),
layout_parent_style.as_ref().map(|s| &***s) layout_parent_style.as_ref().map(|s| &***s)
) )
} }

View file

@ -39,7 +39,7 @@ use style::gecko_bindings::bindings::{RawServoNamespaceRule, RawServoNamespaceRu
use style::gecko_bindings::bindings::{RawServoPageRule, RawServoPageRuleBorrowed}; use style::gecko_bindings::bindings::{RawServoPageRule, RawServoPageRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned}; use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
use style::gecko_bindings::bindings::{RawServoStyleSheetContentsBorrowed, ServoComputedValuesBorrowed}; use style::gecko_bindings::bindings::{RawServoStyleSheetContentsBorrowed, ServoComputedValuesBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSheetContentsStrong, ServoComputedValuesStrong}; use style::gecko_bindings::bindings::{RawServoStyleSheetContentsStrong, ServoStyleContextBorrowed};
use style::gecko_bindings::bindings::{RawServoSupportsRule, RawServoSupportsRuleBorrowed}; use style::gecko_bindings::bindings::{RawServoSupportsRule, RawServoSupportsRuleBorrowed};
use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong}; use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong};
use style::gecko_bindings::bindings::{nsACString, nsAString, nsCSSPropertyIDSetBorrowedMut}; use style::gecko_bindings::bindings::{nsACString, nsAString, nsCSSPropertyIDSetBorrowedMut};
@ -61,13 +61,14 @@ use style::gecko_bindings::bindings::RawServoAnimationValueMapBorrowedMut;
use style::gecko_bindings::bindings::RawServoAnimationValueStrong; use style::gecko_bindings::bindings::RawServoAnimationValueStrong;
use style::gecko_bindings::bindings::RawServoStyleRuleBorrowed; use style::gecko_bindings::bindings::RawServoStyleRuleBorrowed;
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use style::gecko_bindings::bindings::ServoStyleContextBorrowedOrNull;
use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t; use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowed; use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut; use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
use style::gecko_bindings::structs; use style::gecko_bindings::structs;
use style::gecko_bindings::structs::{CSSPseudoElementType, CompositeOperation, Loader}; use style::gecko_bindings::structs::{CSSPseudoElementType, CompositeOperation, Loader};
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleSheet}; use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong};
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom, nsCSSPropertyID}; use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsIAtom, nsCSSPropertyID};
use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule}; use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule};
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair}; use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair};
use style::gecko_bindings::structs::IterationCompositeOperation; use style::gecko_bindings::structs::IterationCompositeOperation;
@ -92,7 +93,7 @@ use style::parallel;
use style::parser::ParserContext; use style::parser::ParserContext;
use style::properties::{ComputedValues, ComputedValuesInner, Importance, SourcePropertyDeclaration}; use style::properties::{ComputedValues, ComputedValuesInner, Importance, SourcePropertyDeclaration};
use style::properties::{LonghandIdSet, PropertyDeclaration, PropertyDeclarationBlock, PropertyId, StyleBuilder}; use style::properties::{LonghandIdSet, PropertyDeclaration, PropertyDeclarationBlock, PropertyId, StyleBuilder};
use style::properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; use style::properties::{SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, PseudoInfo, ParentStyleContextInfo};
use style::properties::animated_properties::{Animatable, AnimatableLonghand, AnimationValue}; use style::properties::animated_properties::{Animatable, AnimatableLonghand, AnimationValue};
use style::properties::parse_one_declaration_into; use style::properties::parse_one_declaration_into;
use style::rule_tree::StyleSource; use style::rule_tree::StyleSource;
@ -655,10 +656,10 @@ pub extern "C" fn Servo_AnimationValue_Uncompute(value: RawServoAnimationValueBo
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(raw_data: RawServoStyleSetBorrowed, pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(raw_data: RawServoStyleSetBorrowed,
element: RawGeckoElementBorrowed, element: RawGeckoElementBorrowed,
computed_values: ServoComputedValuesBorrowed, computed_values: ServoStyleContextBorrowed,
snapshots: *const ServoElementSnapshotTable, snapshots: *const ServoElementSnapshotTable,
pseudo_type: CSSPseudoElementType) pseudo_type: CSSPseudoElementType)
-> ServoComputedValuesStrong -> ServoStyleContextStrong
{ {
use style::style_resolver::StyleResolverForElement; use style::style_resolver::StyleResolverForElement;
@ -731,7 +732,6 @@ pub extern "C" fn Servo_ComputedValues_ExtractAnimationValue(computed_values: Se
None => { return Strong::null(); } None => { return Strong::null(); }
}; };
let computed_values = ComputedValues::as_arc(&computed_values);
Arc::new(AnimationValue::from_computed_values(&property, computed_values)).into_strong() Arc::new(AnimationValue::from_computed_values(&property, computed_values)).into_strong()
} }
@ -1501,10 +1501,11 @@ pub extern "C" fn Servo_DocumentRule_GetConditionText(rule: RawServoDocumentRule
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowedOrNull, pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoStyleContextBorrowedOrNull,
pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom, pseudo_tag: *mut nsIAtom,
raw_data: RawServoStyleSetBorrowed) raw_data: RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong { -> ServoStyleContextStrong {
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read(); let guard = global_style_data.shared_lock.read();
let guards = StylesheetGuards::same(&guard); let guards = StylesheetGuards::same(&guard);
@ -1513,23 +1514,24 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
let pseudo = PseudoElement::from_anon_box_atom(&atom) let pseudo = PseudoElement::from_anon_box_atom(&atom)
.expect("Not an anon box pseudo?"); .expect("Not an anon box pseudo?");
let maybe_parent = ComputedValues::arc_from_borrowed(&parent_style_or_null)
.map(|p| &p.inner);
let cascade_flags = SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; let cascade_flags = SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
let metrics = get_metrics_provider_for_product(); let metrics = get_metrics_provider_for_product();
data.stylist.precomputed_values_for_pseudo(&guards, &pseudo, maybe_parent, data.stylist.precomputed_values_for_pseudo(&guards, &pseudo, parent_style_or_null.map(|x| &**x),
cascade_flags, &metrics) cascade_flags, &metrics,
(pseudo_tag, pseudo_type),
parent_style_or_null)
.into_strong() .into_strong()
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed, pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
pseudo_type: CSSPseudoElementType, pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom,
is_probe: bool, is_probe: bool,
inherited_style: ServoComputedValuesBorrowedOrNull, inherited_style: ServoComputedValuesBorrowedOrNull,
parent_style_context: ServoStyleContextBorrowedOrNull,
raw_data: RawServoStyleSetBorrowed) raw_data: RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong -> ServoStyleContextStrong
{ {
let element = GeckoElement(element); let element = GeckoElement(element);
let data = unsafe { element.ensure_data() }; let data = unsafe { element.ensure_data() };
@ -1544,7 +1546,9 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
return if is_probe { return if is_probe {
Strong::null() Strong::null()
} else { } else {
doc_data.default_computed_values().clone().to_outer().into_strong() doc_data.default_computed_values()
.clone().to_outer(doc_data.stylist.device(), parent_style_context,
Some((pseudo_tag, pseudo_type))).into_strong()
}; };
} }
@ -1559,9 +1563,11 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
&pseudo, &pseudo,
RuleInclusion::All, RuleInclusion::All,
&data.styles, &data.styles,
ComputedValues::arc_from_borrowed(&inherited_style).map(|x| &***x), inherited_style,
&*doc_data, &*doc_data,
is_probe is_probe,
(pseudo_tag, pseudo_type),
parent_style_context
); );
match style { match style {
@ -1575,7 +1581,7 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed, pub extern "C" fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed,
style: ServoComputedValuesBorrowed) style: ServoStyleContextBorrowed)
{ {
let element = GeckoElement(element); let element = GeckoElement(element);
let style = ComputedValues::as_arc(&style); let style = ComputedValues::as_arc(&style);
@ -1616,6 +1622,8 @@ fn get_pseudo_style(
inherited_styles: Option<&ComputedValuesInner>, inherited_styles: Option<&ComputedValuesInner>,
doc_data: &PerDocumentStyleDataImpl, doc_data: &PerDocumentStyleDataImpl,
is_probe: bool, is_probe: bool,
pseudo_info: PseudoInfo,
parent_style_context: ParentStyleContextInfo,
) -> Option<Arc<ComputedValues>> { ) -> Option<Arc<ComputedValues>> {
let style = match pseudo.cascade_type() { let style = match pseudo.cascade_type() {
PseudoElementCascadeType::Eager => { PseudoElementCascadeType::Eager => {
@ -1637,7 +1645,9 @@ fn get_pseudo_style(
&inputs, &inputs,
&guards, &guards,
inherited_styles, inherited_styles,
&metrics) &metrics,
pseudo_info.clone(),
parent_style_context)
}) })
}, },
_ => { _ => {
@ -1668,7 +1678,9 @@ fn get_pseudo_style(
rule_inclusion, rule_inclusion,
base, base,
is_probe, is_probe,
&metrics) &metrics,
pseudo_info.clone(),
parent_style_context)
}, },
}; };
@ -1680,21 +1692,23 @@ fn get_pseudo_style(
StyleBuilder::for_inheritance( StyleBuilder::for_inheritance(
styles.primary(), styles.primary(),
doc_data.default_computed_values(), doc_data.default_computed_values(),
).build().to_outer() ).build().to_outer(doc_data.stylist.device(), parent_style_context,
Some(pseudo_info))
})) }))
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ComputedValues_Inherit( pub extern "C" fn Servo_ComputedValues_Inherit(
raw_data: RawServoStyleSetBorrowed, raw_data: RawServoStyleSetBorrowed,
parent_style: ServoComputedValuesBorrowedOrNull, pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom,
parent_style_context: ServoStyleContextBorrowedOrNull,
target: structs::InheritTarget target: structs::InheritTarget
) -> ServoComputedValuesStrong { ) -> ServoStyleContextStrong {
let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
let maybe_arc = ComputedValues::arc_from_borrowed(&parent_style);
let for_text = target == structs::InheritTarget::Text; let for_text = target == structs::InheritTarget::Text;
let style = if let Some(reference) = maybe_arc.as_ref() { let style = if let Some(reference) = parent_style_context {
let mut style = let mut style =
StyleBuilder::for_inheritance(reference, StyleBuilder::for_inheritance(reference,
&data.default_computed_values()); &data.default_computed_values());
@ -1709,22 +1723,42 @@ pub extern "C" fn Servo_ComputedValues_Inherit(
data.default_computed_values().clone() data.default_computed_values().clone()
}; };
style.to_outer().into_strong() let pseudo_info = if pseudo_tag.is_null() {
None
} else {
Some((pseudo_tag, pseudo_type))
};
style.to_outer(data.stylist.device(), parent_style_context, pseudo_info).into_strong()
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetVisitedStyle(values: ServoComputedValuesBorrowed) pub extern "C" fn Servo_ComputedValues_GetVisitedStyle(values: ServoComputedValuesBorrowed)
-> ServoComputedValuesStrong { -> ServoStyleContextStrong {
match ComputedValues::as_arc(&values).clone_visited_style() { match ComputedValuesInner::as_arc(&values).clone_visited_style() {
Some(v) => v.into_strong(), Some(v) => v.into_strong(),
None => Strong::null(), None => Strong::null(),
} }
} }
#[no_mangle]
pub extern "C" fn Servo_StyleContext_NewContext(values: ServoComputedValuesBorrowed,
parent: ServoStyleContextBorrowedOrNull,
pres_context: bindings::RawGeckoPresContextBorrowed,
pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom)
-> ServoStyleContextStrong {
let arc = ComputedValuesInner::as_arc(&values);
unsafe {
ComputedValuesInner::to_outer_from_arc(arc.clone_arc(), pres_context, parent,
pseudo_type, pseudo_tag).into_strong()
}
}
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetStyleBits(values: ServoComputedValuesBorrowed) -> u64 { pub extern "C" fn Servo_ComputedValues_GetStyleBits(values: ServoComputedValuesBorrowed) -> u64 {
use style::properties::computed_value_flags::*; use style::properties::computed_value_flags::*;
let flags = ComputedValues::as_arc(&values).flags; let flags = values.flags;
let mut result = 0; let mut result = 0;
if flags.contains(HAS_TEXT_DECORATION_LINES) { if flags.contains(HAS_TEXT_DECORATION_LINES) {
result |= structs::NS_STYLE_HAS_TEXT_DECORATION_LINES as u64; result |= structs::NS_STYLE_HAS_TEXT_DECORATION_LINES as u64;
@ -1738,7 +1772,6 @@ pub extern "C" fn Servo_ComputedValues_GetStyleBits(values: ServoComputedValuesB
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ComputedValues_SpecifiesAnimationsOrTransitions(values: ServoComputedValuesBorrowed) pub extern "C" fn Servo_ComputedValues_SpecifiesAnimationsOrTransitions(values: ServoComputedValuesBorrowed)
-> bool { -> bool {
let values = ComputedValues::as_arc(&values);
let b = values.get_box(); let b = values.get_box();
b.specifies_animations() || b.specifies_transitions() b.specifies_animations() || b.specifies_transitions()
} }
@ -1748,15 +1781,12 @@ pub extern "C" fn Servo_ComputedValues_EqualCustomProperties(
first: ServoComputedValuesBorrowed, first: ServoComputedValuesBorrowed,
second: ServoComputedValuesBorrowed second: ServoComputedValuesBorrowed
) -> bool { ) -> bool {
let first = ComputedValues::as_arc(&first);
let second = ComputedValues::as_arc(&second);
first.get_custom_properties() == second.get_custom_properties() first.get_custom_properties() == second.get_custom_properties()
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetStyleRuleList(values: ServoComputedValuesBorrowed, pub extern "C" fn Servo_ComputedValues_GetStyleRuleList(values: ServoComputedValuesBorrowed,
rules: RawGeckoServoStyleRuleListBorrowedMut) { rules: RawGeckoServoStyleRuleListBorrowedMut) {
let values = ComputedValues::as_arc(&values);
if let Some(ref rule_node) = values.rules { if let Some(ref rule_node) = values.rules {
let mut result = vec![]; let mut result = vec![];
for node in rule_node.self_and_ancestors() { for node in rule_node.self_and_ancestors() {
@ -2775,7 +2805,7 @@ pub extern "C" fn Servo_TakeChangeHint(element: RawGeckoElementBorrowed,
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed, pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
_raw_data: RawServoStyleSetBorrowed) _raw_data: RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong -> ServoStyleContextStrong
{ {
let element = GeckoElement(element); let element = GeckoElement(element);
debug!("Servo_ResolveStyle: {:?}", element); debug!("Servo_ResolveStyle: {:?}", element);
@ -2792,10 +2822,12 @@ pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed, pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
pseudo_type: CSSPseudoElementType, pseudo_type: CSSPseudoElementType,
pseudo_tag: *mut nsIAtom,
parent_style_context: ServoStyleContextBorrowedOrNull,
rule_inclusion: StyleRuleInclusion, rule_inclusion: StyleRuleInclusion,
snapshots: *const ServoElementSnapshotTable, snapshots: *const ServoElementSnapshotTable,
raw_data: RawServoStyleSetBorrowed) raw_data: RawServoStyleSetBorrowed)
-> ServoComputedValuesStrong -> ServoStyleContextStrong
{ {
debug_assert!(!snapshots.is_null()); debug_assert!(!snapshots.is_null());
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
@ -2816,6 +2848,8 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
/* inherited_styles = */ None, /* inherited_styles = */ None,
&*data, &*data,
/* is_probe = */ false, /* is_probe = */ false,
(pseudo_tag, pseudo_type),
parent_style_context
).expect("We're not probing, so we should always get a style \ ).expect("We're not probing, so we should always get a style \
back") back")
} }
@ -2869,11 +2903,11 @@ fn simulate_compute_values_failure(_: &PropertyValuePair) -> bool {
fn create_context<'a>(per_doc_data: &'a PerDocumentStyleDataImpl, fn create_context<'a>(per_doc_data: &'a PerDocumentStyleDataImpl,
font_metrics_provider: &'a FontMetricsProvider, font_metrics_provider: &'a FontMetricsProvider,
style: &'a ComputedValues, style: &'a ComputedValuesInner,
parent_style: &'a Option<&Arc<ComputedValues>>) parent_style: &'a Option<&ComputedValuesInner>)
-> Context<'a> { -> Context<'a> {
let default_values = per_doc_data.default_computed_values(); let default_values = per_doc_data.default_computed_values();
let inherited_style = parent_style.map(|x| &x.inner).unwrap_or(default_values); let inherited_style = parent_style.unwrap_or(default_values);
Context { Context {
is_root_element: false, is_root_element: false,
@ -2900,12 +2934,11 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
let metrics = get_metrics_provider_for_product(); let metrics = get_metrics_provider_for_product();
let style = ComputedValues::as_arc(&style);
let element = GeckoElement(element); let element = GeckoElement(element);
let parent_element = element.inheritance_parent(); let parent_element = element.inheritance_parent();
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data()); let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
let parent_style = parent_data.as_ref().map(|d| d.styles.primary()); let parent_style = parent_data.as_ref().map(|d| d.styles.primary()).map(|x| &***x);
let mut context = create_context(&data, &metrics, style, &parent_style); let mut context = create_context(&data, &metrics, style, &parent_style);
@ -2980,13 +3013,12 @@ pub extern "C" fn Servo_GetAnimationValues(declarations: RawServoDeclarationBloc
raw_data: RawServoStyleSetBorrowed, raw_data: RawServoStyleSetBorrowed,
animation_values: RawGeckoServoAnimationValueListBorrowedMut) { animation_values: RawGeckoServoAnimationValueListBorrowedMut) {
let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
let style = ComputedValues::as_arc(&style);
let metrics = get_metrics_provider_for_product(); let metrics = get_metrics_provider_for_product();
let element = GeckoElement(element); let element = GeckoElement(element);
let parent_element = element.inheritance_parent(); let parent_element = element.inheritance_parent();
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data()); let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
let parent_style = parent_data.as_ref().map(|d| d.styles.primary()); let parent_style = parent_data.as_ref().map(|d| d.styles.primary()).map(|x| &***x);
let mut context = create_context(&data, &metrics, style, &parent_style); let mut context = create_context(&data, &metrics, style, &parent_style);
@ -3009,13 +3041,12 @@ pub extern "C" fn Servo_AnimationValue_Compute(element: RawGeckoElementBorrowed,
raw_data: RawServoStyleSetBorrowed) raw_data: RawServoStyleSetBorrowed)
-> RawServoAnimationValueStrong { -> RawServoAnimationValueStrong {
let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
let style = ComputedValues::as_arc(&style);
let metrics = get_metrics_provider_for_product(); let metrics = get_metrics_provider_for_product();
let element = GeckoElement(element); let element = GeckoElement(element);
let parent_element = element.inheritance_parent(); let parent_element = element.inheritance_parent();
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data()); let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
let parent_style = parent_data.as_ref().map(|d| d.styles.primary()); let parent_style = parent_data.as_ref().map(|d| d.styles.primary()).map(|x| &***x);
let mut context = create_context(&data, &metrics, style, &parent_style); let mut context = create_context(&data, &metrics, style, &parent_style);
@ -3259,16 +3290,16 @@ pub extern "C" fn Servo_StyleSet_GetCounterStyleRule(raw_data: RawServoStyleSetB
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_StyleSet_ResolveForDeclarations( pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(
raw_data: RawServoStyleSetBorrowed, raw_data: RawServoStyleSetBorrowed,
parent_style_or_null: ServoComputedValuesBorrowedOrNull, parent_style_context: ServoStyleContextBorrowedOrNull,
declarations: RawServoDeclarationBlockBorrowed declarations: RawServoDeclarationBlockBorrowed,
) -> ServoComputedValuesStrong { ) -> ServoStyleContextStrong {
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read(); let guard = global_style_data.shared_lock.read();
let guards = StylesheetGuards::same(&guard); let guards = StylesheetGuards::same(&guard);
let parent_style = match ComputedValues::arc_from_borrowed(&parent_style_or_null) { let parent_style = match parent_style_context {
Some(parent) => &parent.inner, Some(parent) => &**parent,
None => doc_data.default_computed_values(), None => doc_data.default_computed_values(),
}; };
@ -3276,7 +3307,8 @@ pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(
doc_data.stylist.compute_for_declarations(&guards, doc_data.stylist.compute_for_declarations(&guards,
parent_style, parent_style,
declarations.clone_arc()).into_strong() declarations.clone_arc(),
parent_style_context).into_strong()
} }
#[no_mangle] #[no_mangle]
@ -3336,7 +3368,8 @@ pub extern "C" fn Servo_StyleSet_HasStateDependency(
pub extern "C" fn Servo_GetCustomPropertyValue(computed_values: ServoComputedValuesBorrowed, pub extern "C" fn Servo_GetCustomPropertyValue(computed_values: ServoComputedValuesBorrowed,
name: *const nsAString, name: *const nsAString,
value: *mut nsAString) -> bool { value: *mut nsAString) -> bool {
let custom_properties = match ComputedValues::as_arc(&computed_values).custom_properties() {
let custom_properties = match computed_values.custom_properties() {
Some(p) => p, Some(p) => p,
None => return false, None => return false,
}; };
@ -3353,7 +3386,7 @@ pub extern "C" fn Servo_GetCustomPropertyValue(computed_values: ServoComputedVal
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_GetCustomPropertiesCount(computed_values: ServoComputedValuesBorrowed) -> u32 { pub extern "C" fn Servo_GetCustomPropertiesCount(computed_values: ServoComputedValuesBorrowed) -> u32 {
match ComputedValues::as_arc(&computed_values).custom_properties() { match ComputedValuesInner::as_arc(&computed_values).custom_properties() {
Some(p) => p.len() as u32, Some(p) => p.len() as u32,
None => 0, None => 0,
} }
@ -3363,7 +3396,7 @@ pub extern "C" fn Servo_GetCustomPropertiesCount(computed_values: ServoComputedV
pub extern "C" fn Servo_GetCustomPropertyNameAt(computed_values: ServoComputedValuesBorrowed, pub extern "C" fn Servo_GetCustomPropertyNameAt(computed_values: ServoComputedValuesBorrowed,
index: u32, index: u32,
name: *mut nsAString) -> bool { name: *mut nsAString) -> bool {
let custom_properties = match ComputedValues::as_arc(&computed_values).custom_properties() { let custom_properties = match ComputedValuesInner::as_arc(&computed_values).custom_properties() {
Some(p) => p, Some(p) => p,
None => return false, None => return false,
}; };