mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
stylo: Switch Gecko over to ServoStyleContext
This commit is contained in:
parent
74519cc1a7
commit
89930e7565
19 changed files with 4479 additions and 2353 deletions
|
@ -1119,7 +1119,7 @@ impl BaseFlow {
|
|||
///
|
||||
/// 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`.
|
||||
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
|
||||
// to get out of date:
|
||||
if self.restyle_damage.contains(REFLOW_OUT_OF_FLOW) {
|
||||
|
|
|
@ -78,7 +78,7 @@ use style::selector_parser::{AttrValue as SelectorAttrValue, NonTSPseudoClass, P
|
|||
use style::selector_parser::{PseudoElement, SelectorImpl, extended_filtering};
|
||||
use style::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocked};
|
||||
use style::str::is_whitespace;
|
||||
use style::stylearc::Arc;
|
||||
use style::stylearc::{Arc, ArcBorrow};
|
||||
|
||||
pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) {
|
||||
let ptr: *mut StyleData = data.ptr.get();
|
||||
|
@ -412,9 +412,9 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
|||
ServoLayoutNode::from_layout_js(self.element.upcast())
|
||||
}
|
||||
|
||||
fn style_attribute(&self) -> Option<&Arc<StyleLocked<PropertyDeclarationBlock>>> {
|
||||
fn style_attribute(&self) -> Option<ArcBorrow<StyleLocked<PropertyDeclarationBlock>>> {
|
||||
unsafe {
|
||||
(*self.element.style_attribute()).as_ref()
|
||||
(*self.element.style_attribute()).as_ref().map(|x| x.borrow_arc())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,13 +90,15 @@ impl CSSRuleList {
|
|||
let index = idx as usize;
|
||||
|
||||
let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
|
||||
let new_rule =
|
||||
css_rules.insert_rule(&parent_stylesheet.shared_lock,
|
||||
rule,
|
||||
&parent_stylesheet.contents,
|
||||
index,
|
||||
nested,
|
||||
None)?;
|
||||
let new_rule = css_rules.with_raw_offset_arc(|arc| {
|
||||
arc.insert_rule(&parent_stylesheet.shared_lock,
|
||||
rule,
|
||||
&parent_stylesheet.contents,
|
||||
index,
|
||||
nested,
|
||||
None)
|
||||
})?;
|
||||
|
||||
|
||||
let parent_stylesheet = &*self.parent_stylesheet;
|
||||
let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule);
|
||||
|
|
|
@ -416,7 +416,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
|
|||
&style_pseudo,
|
||||
Some(data.styles.primary()),
|
||||
CascadeFlags::empty(),
|
||||
&ServoMetricsProvider)
|
||||
&ServoMetricsProvider, (), ())
|
||||
.clone()
|
||||
}
|
||||
PseudoElementCascadeType::Lazy => {
|
||||
|
@ -428,7 +428,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
|
|||
RuleInclusion::All,
|
||||
data.styles.primary(),
|
||||
/* is_probe = */ false,
|
||||
&ServoMetricsProvider)
|
||||
&ServoMetricsProvider, (), ())
|
||||
.unwrap()
|
||||
.clone()
|
||||
}
|
||||
|
|
|
@ -10,14 +10,15 @@
|
|||
|
||||
use gecko_bindings::bindings::{RawServoImportRule, RawServoSupportsRule};
|
||||
use gecko_bindings::bindings::{RawServoKeyframe, RawServoKeyframesRule};
|
||||
use gecko_bindings::bindings::RawServoMediaRule;
|
||||
use gecko_bindings::bindings::{RawServoNamespaceRule, RawServoPageRule};
|
||||
use gecko_bindings::bindings::{RawServoRuleNode, RawServoRuleNodeStrong, RawServoDocumentRule, RawServoMediaRule};
|
||||
use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules};
|
||||
use gecko_bindings::bindings::{RawServoRuleNode, RawServoRuleNodeStrong, RawServoDocumentRule};
|
||||
use gecko_bindings::bindings::ServoCssRules;
|
||||
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 media_queries::MediaList;
|
||||
use properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use properties::{ComputedValues, ComputedValuesInner, PropertyDeclarationBlock};
|
||||
use properties::animated_properties::AnimationValue;
|
||||
use rule_tree::StrongRuleNode;
|
||||
use shared_lock::Locked;
|
||||
|
@ -51,9 +52,12 @@ impl_arc_ffi!(Locked<CssRules> => ServoCssRules
|
|||
impl_arc_ffi!(StylesheetContents => RawServoStyleSheetContents
|
||||
[Servo_StyleSheetContents_AddRef, Servo_StyleSheetContents_Release]);
|
||||
|
||||
impl_arc_ffi!(ComputedValues => ServoComputedValues
|
||||
impl_arc_ffi!(ComputedValuesInner => ServoComputedValues
|
||||
[Servo_ComputedValues_AddRef, Servo_ComputedValues_Release]);
|
||||
|
||||
impl_arc_ffi!(ComputedValues => ServoStyleContext
|
||||
[Servo_StyleContext_AddRef, Servo_StyleContext_Release]);
|
||||
|
||||
impl_arc_ffi!(Locked<PropertyDeclarationBlock> => RawServoDeclarationBlock
|
||||
[Servo_DeclarationBlock_AddRef, Servo_DeclarationBlock_Release]);
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ use gecko_bindings::structs::nsStyleTransformMatrix;
|
|||
use gecko_bindings::structs::nsTArray;
|
||||
type nsACString_internal = nsACString;
|
||||
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::ErrorReporter;
|
||||
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::LoaderReusableStyleSheets;
|
||||
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::UpdateAnimationsTasks;
|
||||
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 ServoComputedValuesBorrowed<'a> = &'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 RawServoDeclarationBlockBorrowed<'a> = &'a RawServoDeclarationBlock;
|
||||
pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclarationBlock>;
|
||||
|
@ -528,6 +531,19 @@ extern "C" {
|
|||
pub fn Gecko_DestroyAnonymousContentList(anon_content:
|
||||
*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" {
|
||||
pub fn Gecko_ConstructStyleChildrenIterator(aElement:
|
||||
RawGeckoElementBorrowed,
|
||||
|
@ -755,9 +771,9 @@ extern "C" {
|
|||
extern "C" {
|
||||
pub fn Gecko_UpdateAnimations(aElementOrPseudo: RawGeckoElementBorrowed,
|
||||
aOldComputedValues:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
ServoStyleContextBorrowedOrNull,
|
||||
aComputedValues:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
ServoStyleContextBorrowedOrNull,
|
||||
aTasks: UpdateAnimationsTasks);
|
||||
}
|
||||
extern "C" {
|
||||
|
@ -1957,10 +1973,10 @@ extern "C" {
|
|||
pub fn Servo_StyleSet_ResolveForDeclarations(set:
|
||||
RawServoStyleSetBorrowed,
|
||||
parent_style:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
ServoStyleContextBorrowedOrNull,
|
||||
declarations:
|
||||
RawServoDeclarationBlockBorrowed)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_StyleSet_MightHaveAttributeDependency(set:
|
||||
|
@ -2661,23 +2677,27 @@ extern "C" {
|
|||
}
|
||||
extern "C" {
|
||||
pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
ServoStyleContextBorrowedOrNull,
|
||||
pseudo_type:
|
||||
CSSPseudoElementType,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
set:
|
||||
RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_ComputedValues_Inherit(set: RawServoStyleSetBorrowed,
|
||||
pseudo_type: CSSPseudoElementType,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
parent_style:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
ServoStyleContextBorrowedOrNull,
|
||||
target: InheritTarget)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_ComputedValues_GetVisitedStyle(values:
|
||||
ServoComputedValuesBorrowed)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_ComputedValues_GetStyleBits(values:
|
||||
|
@ -2697,6 +2717,16 @@ extern "C" {
|
|||
rules:
|
||||
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" {
|
||||
pub fn Servo_Initialize(dummy_url_data: *mut RawGeckoURLExtraData);
|
||||
}
|
||||
|
@ -2716,20 +2746,22 @@ extern "C" {
|
|||
extern "C" {
|
||||
pub fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
|
||||
set: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
|
||||
pseudo_type: CSSPseudoElementType,
|
||||
is_probe: bool,
|
||||
pseudo_tag: *mut nsIAtom, is_probe: bool,
|
||||
inherited_style:
|
||||
ServoComputedValuesBorrowedOrNull,
|
||||
parent_style_context:
|
||||
ServoStyleContextBorrowedOrNull,
|
||||
set: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed,
|
||||
primary_style: ServoComputedValuesBorrowed);
|
||||
primary_style: ServoStyleContextBorrowed);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_HasAuthorSpecifiedRules(element: RawGeckoElementBorrowed,
|
||||
|
@ -2739,11 +2771,14 @@ extern "C" {
|
|||
extern "C" {
|
||||
pub fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
|
||||
pseudo_type: CSSPseudoElementType,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
parent_style_context:
|
||||
ServoStyleContextBorrowedOrNull,
|
||||
rule_inclusion: StyleRuleInclusion,
|
||||
snapshots:
|
||||
*const ServoElementSnapshotTable,
|
||||
set: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_TraverseSubtree(root: RawGeckoElementBorrowed,
|
||||
|
@ -2765,12 +2800,12 @@ extern "C" {
|
|||
element:
|
||||
RawGeckoElementBorrowed,
|
||||
existing_style:
|
||||
ServoComputedValuesBorrowed,
|
||||
ServoStyleContextBorrowed,
|
||||
snapshots:
|
||||
*const ServoElementSnapshotTable,
|
||||
pseudo_type:
|
||||
CSSPseudoElementType)
|
||||
-> ServoComputedValuesStrong;
|
||||
-> ServoStyleContextStrong;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Servo_SerializeFontValueForCanvas(declarations:
|
||||
|
|
|
@ -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`.
|
||||
#[inline]
|
||||
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
|
@ -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`.
|
||||
#[inline]
|
||||
pub fn from_anon_box_atom(atom: &Atom) -> Option<Self> {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs;
|
||||
use gecko_bindings::structs::{nsChangeHint, nsStyleContext};
|
||||
use gecko_bindings::sugar::ownership::FFIArcHelpers;
|
||||
use matching::{StyleChange, StyleDifference};
|
||||
use properties::ComputedValues;
|
||||
use std::ops::{BitAnd, BitOr, BitOrAssign, Not};
|
||||
|
@ -56,7 +55,7 @@ impl GeckoRestyleDamage {
|
|||
let mut any_style_changed: bool = false;
|
||||
let hint = unsafe {
|
||||
bindings::Gecko_CalcStyleDifference(context,
|
||||
new_style.as_borrowed(),
|
||||
&new_style,
|
||||
&mut any_style_changed)
|
||||
};
|
||||
let change = if any_style_changed { StyleChange::Changed } else { StyleChange::Unchanged };
|
||||
|
|
|
@ -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_NATIVE_ANONYMOUS;
|
||||
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 media_queries::Device;
|
||||
use properties::{ComputedValues, parse_style_attribute};
|
||||
|
@ -1101,10 +1101,9 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
let computed_data = self.borrow_data();
|
||||
let computed_values =
|
||||
computed_data.as_ref().map(|d| d.styles.primary());
|
||||
let computed_values_opt =
|
||||
computed_values.map(|v| v.as_borrowed());
|
||||
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 {
|
||||
Gecko_UpdateAnimations(self.0,
|
||||
before_change_values,
|
||||
|
|
|
@ -46,7 +46,6 @@ use gecko_bindings::structs;
|
|||
use gecko_bindings::structs::nsCSSPropertyID;
|
||||
use gecko_bindings::structs::nsStyleVariables;
|
||||
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_rgba_to_nscolor;
|
||||
use gecko::values::GeckoStyleCoordConvertible;
|
||||
|
@ -58,7 +57,7 @@ use properties::computed_value_flags::ComputedValueFlags;
|
|||
use properties::{longhands, FontComputationData, Importance, LonghandId};
|
||||
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
|
||||
use rule_tree::StrongRuleNode;
|
||||
use std::mem::{forget, transmute, zeroed};
|
||||
use std::mem::{forget, uninitialized, transmute, zeroed};
|
||||
use std::{cmp, ops, ptr};
|
||||
use stylearc::{Arc, RawOffsetArc};
|
||||
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)]
|
||||
pub struct ComputedValues {
|
||||
pub inner: ComputedValuesInner
|
||||
#[derive(Debug)]
|
||||
#[repr(C)]
|
||||
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 {
|
||||
|
@ -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 {
|
||||
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
|
||||
writing_mode: WritingMode,
|
||||
|
@ -134,21 +152,42 @@ impl ComputedValuesInner {
|
|||
% endfor
|
||||
}
|
||||
}
|
||||
pub fn to_outer(self) -> Arc<ComputedValues> {
|
||||
Arc::new(ComputedValues {inner: self})
|
||||
pub fn to_outer(self, device: &Device, parent: ParentStyleContextInfo,
|
||||
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 {
|
||||
type Target = ComputedValuesInner;
|
||||
fn deref(&self) -> &ComputedValuesInner {
|
||||
&self.inner
|
||||
unsafe { &*self.0.mSource.mRawPtr }
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::DerefMut for ComputedValues {
|
||||
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.
|
||||
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> {
|
||||
self.visited_style.as_ref().map(|x| &***x)
|
||||
pub fn get_visited_style(&self) -> Option< & ComputedValues> {
|
||||
self.visited_style.as_ref().map(|x| &**x)
|
||||
}
|
||||
|
||||
/// 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()
|
||||
}
|
||||
|
||||
|
@ -4801,7 +4840,7 @@ clip-path
|
|||
#[allow(non_snake_case, unused_variables)]
|
||||
pub unsafe extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values:
|
||||
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}
|
||||
}
|
||||
</%def>
|
||||
|
|
|
@ -1871,9 +1871,14 @@ pub mod style_structs {
|
|||
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use gecko_properties::ComputedValues;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use gecko_properties::ComputedValuesInner;
|
||||
pub use gecko_properties::{ComputedValues, ComputedValuesInner, ParentStyleContextInfo, PseudoInfo};
|
||||
|
||||
#[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")]
|
||||
|
@ -1970,7 +1975,8 @@ impl ops::DerefMut for ComputedValues {
|
|||
#[cfg(feature = "servo")]
|
||||
impl ComputedValuesInner {
|
||||
/// 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})
|
||||
}
|
||||
|
||||
|
@ -2011,13 +2017,13 @@ impl ComputedValuesInner {
|
|||
}
|
||||
|
||||
/// Gets a reference to the visited style, if any.
|
||||
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> {
|
||||
self.visited_style.as_ref().map(|x| &***x)
|
||||
pub fn get_visited_style(&self) -> Option< & ComputedValues> {
|
||||
self.visited_style.as_ref().map(|x| &**x)
|
||||
}
|
||||
|
||||
/// Gets a reference to the visited style. Panic if no visited style exists.
|
||||
pub fn visited_style(&self) -> &ComputedValuesInner {
|
||||
self.get_visited_style().as_ref().map(|x| &**x).unwrap()
|
||||
pub fn visited_style(&self) -> &ComputedValues {
|
||||
self.get_visited_style().unwrap()
|
||||
}
|
||||
|
||||
/// Clone the visited style. Used for inheriting parent styles in
|
||||
|
|
|
@ -166,6 +166,9 @@ impl PseudoElement {
|
|||
pub fn canonical(&self) -> PseudoElement {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
/// Stub, only Gecko needs this
|
||||
pub fn pseudo_info(&self) -> () { () }
|
||||
}
|
||||
|
||||
/// The type used for storing pseudo-class string arguments.
|
||||
|
|
|
@ -47,7 +47,7 @@ pub struct PrimaryStyle {
|
|||
fn with_default_parent_styles<E, F, R>(element: E, f: F) -> R
|
||||
where
|
||||
E: TElement,
|
||||
F: FnOnce(Option<&ComputedValuesInner>, Option<&ComputedValuesInner>) -> R,
|
||||
F: FnOnce(Option<&ComputedValues>, Option<&ComputedValuesInner>) -> R,
|
||||
{
|
||||
let parent_el = element.inheritance_parent();
|
||||
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());
|
||||
}
|
||||
|
||||
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>
|
||||
|
@ -98,7 +98,7 @@ where
|
|||
/// Resolve just the style of a given element.
|
||||
pub fn resolve_primary_style(
|
||||
&mut self,
|
||||
parent_style: Option<&ComputedValuesInner>,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValuesInner>,
|
||||
) -> PrimaryStyle {
|
||||
let primary_results =
|
||||
|
@ -119,6 +119,7 @@ where
|
|||
relevant_link_found ||
|
||||
parent_style.and_then(|s| s.get_visited_style()).is_some();
|
||||
|
||||
let pseudo = self.element.implemented_pseudo_element();
|
||||
if should_compute_visited_style {
|
||||
visited_style = Some(self.cascade_style(
|
||||
visited_rules.as_ref().or(Some(&primary_results.rule_node)),
|
||||
|
@ -126,17 +127,16 @@ where
|
|||
parent_style,
|
||||
layout_parent_style,
|
||||
CascadeVisitedMode::Visited,
|
||||
/* pseudo = */ None,
|
||||
/* pseudo = */ pseudo.as_ref(),
|
||||
));
|
||||
}
|
||||
|
||||
let style = self.cascade_style(
|
||||
Some(&primary_results.rule_node),
|
||||
visited_style,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
CascadeVisitedMode::Unvisited,
|
||||
/* pseudo = */ None,
|
||||
/* pseudo = */ pseudo.as_ref(),
|
||||
);
|
||||
|
||||
PrimaryStyle { style, }
|
||||
|
@ -146,7 +146,7 @@ where
|
|||
/// Resolve the style of a given element, and all its eager pseudo-elements.
|
||||
pub fn resolve_style(
|
||||
&mut self,
|
||||
parent_style: Option<&ComputedValuesInner>,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValuesInner>,
|
||||
) -> ElementStyles {
|
||||
use properties::longhands::display::computed_value::T as display;
|
||||
|
@ -215,7 +215,7 @@ where
|
|||
fn cascade_style_and_visited(
|
||||
&mut self,
|
||||
inputs: CascadeInputs,
|
||||
parent_style: Option<&ComputedValuesInner>,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValuesInner>,
|
||||
pseudo: Option<&PseudoElement>,
|
||||
) -> Arc<ComputedValues> {
|
||||
|
@ -462,7 +462,7 @@ where
|
|||
&mut self,
|
||||
rules: Option<&StrongRuleNode>,
|
||||
style_if_visited: Option<Arc<ComputedValues>>,
|
||||
mut parent_style: Option<&ComputedValuesInner>,
|
||||
mut parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValuesInner>,
|
||||
cascade_visited: CascadeVisitedMode,
|
||||
pseudo: Option<&PseudoElement>,
|
||||
|
@ -485,12 +485,17 @@ where
|
|||
cascade_flags.insert(IS_ROOT_ELEMENT);
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
let parent_style_context = parent_style;
|
||||
#[cfg(feature = "servo")]
|
||||
let parent_style_context = ();
|
||||
|
||||
let values =
|
||||
cascade(
|
||||
self.context.shared.stylist.device(),
|
||||
rules.unwrap_or(self.context.shared.stylist.rule_tree().root()),
|
||||
&self.context.shared.guards,
|
||||
parent_style,
|
||||
parent_style.map(|x| &**x),
|
||||
layout_parent_style,
|
||||
style_if_visited,
|
||||
Some(&mut cascade_info),
|
||||
|
@ -500,6 +505,18 @@ where
|
|||
);
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use invalidation::element::invalidation_map::InvalidationMap;
|
|||
use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
|
||||
use media_queries::Device;
|
||||
use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner};
|
||||
use properties::{AnimationRules, PropertyDeclarationBlock};
|
||||
use properties::{AnimationRules, PropertyDeclarationBlock, PseudoInfo, ParentStyleContextInfo};
|
||||
#[cfg(feature = "servo")]
|
||||
use properties::INHERIT_ALL;
|
||||
use rule_tree::{CascadeLevel, RuleTree, StyleSource};
|
||||
|
@ -601,7 +601,9 @@ impl Stylist {
|
|||
pseudo: &PseudoElement,
|
||||
parent: Option<&ComputedValuesInner>,
|
||||
cascade_flags: CascadeFlags,
|
||||
font_metrics: &FontMetricsProvider)
|
||||
font_metrics: &FontMetricsProvider,
|
||||
pseudo_info: PseudoInfo,
|
||||
parent_style_context: ParentStyleContextInfo)
|
||||
-> Arc<ComputedValues> {
|
||||
debug_assert!(pseudo.is_precomputed());
|
||||
|
||||
|
@ -638,7 +640,8 @@ impl Stylist {
|
|||
None,
|
||||
font_metrics,
|
||||
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.
|
||||
|
@ -675,7 +678,7 @@ impl Stylist {
|
|||
cascade_flags.insert(INHERIT_ALL);
|
||||
}
|
||||
self.precomputed_values_for_pseudo(guards, &pseudo, Some(parent_style), cascade_flags,
|
||||
&ServoMetricsProvider)
|
||||
&ServoMetricsProvider, (), ())
|
||||
}
|
||||
|
||||
/// Computes a pseudo-element style lazily during layout.
|
||||
|
@ -692,7 +695,9 @@ impl Stylist {
|
|||
rule_inclusion: RuleInclusion,
|
||||
parent_style: &ComputedValuesInner,
|
||||
is_probe: bool,
|
||||
font_metrics: &FontMetricsProvider)
|
||||
font_metrics: &FontMetricsProvider,
|
||||
pseudo_info: PseudoInfo,
|
||||
parent_style_context: ParentStyleContextInfo)
|
||||
-> Option<Arc<ComputedValues>>
|
||||
where E: TElement,
|
||||
{
|
||||
|
@ -701,7 +706,9 @@ impl Stylist {
|
|||
self.compute_pseudo_element_style_with_inputs(&cascade_inputs,
|
||||
guards,
|
||||
parent_style,
|
||||
font_metrics)
|
||||
font_metrics,
|
||||
pseudo_info,
|
||||
parent_style_context)
|
||||
}
|
||||
|
||||
/// Computes a pseudo-element style lazily using the given CascadeInputs.
|
||||
|
@ -712,7 +719,9 @@ impl Stylist {
|
|||
inputs: &CascadeInputs,
|
||||
guards: &StylesheetGuards,
|
||||
parent_style: &ComputedValuesInner,
|
||||
font_metrics: &FontMetricsProvider)
|
||||
font_metrics: &FontMetricsProvider,
|
||||
pseudo_info: PseudoInfo,
|
||||
parent_style_context: ParentStyleContextInfo)
|
||||
-> Option<Arc<ComputedValues>>
|
||||
{
|
||||
// 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
|
||||
// our parent.
|
||||
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
|
||||
// worrying, but we're probably dropping the display fixup for
|
||||
|
@ -751,7 +760,8 @@ impl Stylist {
|
|||
None,
|
||||
font_metrics,
|
||||
CascadeFlags::empty(),
|
||||
self.quirks_mode).to_outer();
|
||||
self.quirks_mode).to_outer(self.device(), parent_style_context,
|
||||
Some(pseudo_info.clone()));
|
||||
|
||||
Some(computed)
|
||||
} else {
|
||||
|
@ -775,7 +785,9 @@ impl Stylist {
|
|||
None,
|
||||
font_metrics,
|
||||
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.
|
||||
|
@ -1313,7 +1325,8 @@ impl Stylist {
|
|||
pub fn compute_for_declarations(&self,
|
||||
guards: &StylesheetGuards,
|
||||
parent_style: &ComputedValuesInner,
|
||||
declarations: Arc<Locked<PropertyDeclarationBlock>>)
|
||||
declarations: Arc<Locked<PropertyDeclarationBlock>>,
|
||||
parent_style_context: ParentStyleContextInfo)
|
||||
-> Arc<ComputedValues> {
|
||||
use font_metrics::get_metrics_provider_for_product;
|
||||
|
||||
|
@ -1337,7 +1350,7 @@ impl Stylist {
|
|||
None,
|
||||
&metrics,
|
||||
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.
|
||||
|
|
|
@ -484,7 +484,7 @@ where
|
|||
let primary_style =
|
||||
StyleResolverForElement::new(*ancestor, context, rule_inclusion)
|
||||
.resolve_primary_style(
|
||||
style.as_ref().map(|s| &***s),
|
||||
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);
|
||||
StyleResolverForElement::new(element, context, rule_inclusion)
|
||||
.resolve_style(
|
||||
style.as_ref().map(|s| &***s),
|
||||
style.as_ref().map(|s| &**s),
|
||||
layout_parent_style.as_ref().map(|s| &***s)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ use style::gecko_bindings::bindings::{RawServoNamespaceRule, RawServoNamespaceRu
|
|||
use style::gecko_bindings::bindings::{RawServoPageRule, RawServoPageRuleBorrowed};
|
||||
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
|
||||
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::{ServoCssRulesBorrowed, ServoCssRulesStrong};
|
||||
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::RawServoStyleRuleBorrowed;
|
||||
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::nsTimingFunctionBorrowed;
|
||||
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
|
||||
use style::gecko_bindings::structs;
|
||||
use style::gecko_bindings::structs::{CSSPseudoElementType, CompositeOperation, Loader};
|
||||
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleSheet};
|
||||
use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom, nsCSSPropertyID};
|
||||
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong};
|
||||
use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsIAtom, nsCSSPropertyID};
|
||||
use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule};
|
||||
use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair};
|
||||
use style::gecko_bindings::structs::IterationCompositeOperation;
|
||||
|
@ -92,7 +93,7 @@ use style::parallel;
|
|||
use style::parser::ParserContext;
|
||||
use style::properties::{ComputedValues, ComputedValuesInner, Importance, SourcePropertyDeclaration};
|
||||
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::parse_one_declaration_into;
|
||||
use style::rule_tree::StyleSource;
|
||||
|
@ -655,10 +656,10 @@ pub extern "C" fn Servo_AnimationValue_Uncompute(value: RawServoAnimationValueBo
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(raw_data: RawServoStyleSetBorrowed,
|
||||
element: RawGeckoElementBorrowed,
|
||||
computed_values: ServoComputedValuesBorrowed,
|
||||
computed_values: ServoStyleContextBorrowed,
|
||||
snapshots: *const ServoElementSnapshotTable,
|
||||
pseudo_type: CSSPseudoElementType)
|
||||
-> ServoComputedValuesStrong
|
||||
-> ServoStyleContextStrong
|
||||
{
|
||||
use style::style_resolver::StyleResolverForElement;
|
||||
|
||||
|
@ -731,7 +732,6 @@ pub extern "C" fn Servo_ComputedValues_ExtractAnimationValue(computed_values: Se
|
|||
None => { return Strong::null(); }
|
||||
};
|
||||
|
||||
let computed_values = ComputedValues::as_arc(&computed_values);
|
||||
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]
|
||||
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,
|
||||
raw_data: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong {
|
||||
-> ServoStyleContextStrong {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
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)
|
||||
.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 metrics = get_metrics_provider_for_product();
|
||||
data.stylist.precomputed_values_for_pseudo(&guards, &pseudo, maybe_parent,
|
||||
cascade_flags, &metrics)
|
||||
data.stylist.precomputed_values_for_pseudo(&guards, &pseudo, parent_style_or_null.map(|x| &**x),
|
||||
cascade_flags, &metrics,
|
||||
(pseudo_tag, pseudo_type),
|
||||
parent_style_or_null)
|
||||
.into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
|
||||
pseudo_type: CSSPseudoElementType,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
is_probe: bool,
|
||||
inherited_style: ServoComputedValuesBorrowedOrNull,
|
||||
parent_style_context: ServoStyleContextBorrowedOrNull,
|
||||
raw_data: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong
|
||||
-> ServoStyleContextStrong
|
||||
{
|
||||
let element = GeckoElement(element);
|
||||
let data = unsafe { element.ensure_data() };
|
||||
|
@ -1544,7 +1546,9 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
|
|||
return if is_probe {
|
||||
Strong::null()
|
||||
} 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,
|
||||
RuleInclusion::All,
|
||||
&data.styles,
|
||||
ComputedValues::arc_from_borrowed(&inherited_style).map(|x| &***x),
|
||||
inherited_style,
|
||||
&*doc_data,
|
||||
is_probe
|
||||
is_probe,
|
||||
(pseudo_tag, pseudo_type),
|
||||
parent_style_context
|
||||
);
|
||||
|
||||
match style {
|
||||
|
@ -1575,7 +1581,7 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_SetExplicitStyle(element: RawGeckoElementBorrowed,
|
||||
style: ServoComputedValuesBorrowed)
|
||||
style: ServoStyleContextBorrowed)
|
||||
{
|
||||
let element = GeckoElement(element);
|
||||
let style = ComputedValues::as_arc(&style);
|
||||
|
@ -1616,6 +1622,8 @@ fn get_pseudo_style(
|
|||
inherited_styles: Option<&ComputedValuesInner>,
|
||||
doc_data: &PerDocumentStyleDataImpl,
|
||||
is_probe: bool,
|
||||
pseudo_info: PseudoInfo,
|
||||
parent_style_context: ParentStyleContextInfo,
|
||||
) -> Option<Arc<ComputedValues>> {
|
||||
let style = match pseudo.cascade_type() {
|
||||
PseudoElementCascadeType::Eager => {
|
||||
|
@ -1637,7 +1645,9 @@ fn get_pseudo_style(
|
|||
&inputs,
|
||||
&guards,
|
||||
inherited_styles,
|
||||
&metrics)
|
||||
&metrics,
|
||||
pseudo_info.clone(),
|
||||
parent_style_context)
|
||||
})
|
||||
},
|
||||
_ => {
|
||||
|
@ -1668,7 +1678,9 @@ fn get_pseudo_style(
|
|||
rule_inclusion,
|
||||
base,
|
||||
is_probe,
|
||||
&metrics)
|
||||
&metrics,
|
||||
pseudo_info.clone(),
|
||||
parent_style_context)
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1680,21 +1692,23 @@ fn get_pseudo_style(
|
|||
StyleBuilder::for_inheritance(
|
||||
styles.primary(),
|
||||
doc_data.default_computed_values(),
|
||||
).build().to_outer()
|
||||
).build().to_outer(doc_data.stylist.device(), parent_style_context,
|
||||
Some(pseudo_info))
|
||||
}))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ComputedValues_Inherit(
|
||||
raw_data: RawServoStyleSetBorrowed,
|
||||
parent_style: ServoComputedValuesBorrowedOrNull,
|
||||
pseudo_type: CSSPseudoElementType,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
parent_style_context: ServoStyleContextBorrowedOrNull,
|
||||
target: structs::InheritTarget
|
||||
) -> ServoComputedValuesStrong {
|
||||
) -> ServoStyleContextStrong {
|
||||
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 style = if let Some(reference) = maybe_arc.as_ref() {
|
||||
let style = if let Some(reference) = parent_style_context {
|
||||
let mut style =
|
||||
StyleBuilder::for_inheritance(reference,
|
||||
&data.default_computed_values());
|
||||
|
@ -1709,22 +1723,42 @@ pub extern "C" fn Servo_ComputedValues_Inherit(
|
|||
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]
|
||||
pub extern "C" fn Servo_ComputedValues_GetVisitedStyle(values: ServoComputedValuesBorrowed)
|
||||
-> ServoComputedValuesStrong {
|
||||
match ComputedValues::as_arc(&values).clone_visited_style() {
|
||||
-> ServoStyleContextStrong {
|
||||
match ComputedValuesInner::as_arc(&values).clone_visited_style() {
|
||||
Some(v) => v.into_strong(),
|
||||
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]
|
||||
pub extern "C" fn Servo_ComputedValues_GetStyleBits(values: ServoComputedValuesBorrowed) -> u64 {
|
||||
use style::properties::computed_value_flags::*;
|
||||
let flags = ComputedValues::as_arc(&values).flags;
|
||||
let flags = values.flags;
|
||||
let mut result = 0;
|
||||
if flags.contains(HAS_TEXT_DECORATION_LINES) {
|
||||
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]
|
||||
pub extern "C" fn Servo_ComputedValues_SpecifiesAnimationsOrTransitions(values: ServoComputedValuesBorrowed)
|
||||
-> bool {
|
||||
let values = ComputedValues::as_arc(&values);
|
||||
let b = values.get_box();
|
||||
b.specifies_animations() || b.specifies_transitions()
|
||||
}
|
||||
|
@ -1748,15 +1781,12 @@ pub extern "C" fn Servo_ComputedValues_EqualCustomProperties(
|
|||
first: ServoComputedValuesBorrowed,
|
||||
second: ServoComputedValuesBorrowed
|
||||
) -> bool {
|
||||
let first = ComputedValues::as_arc(&first);
|
||||
let second = ComputedValues::as_arc(&second);
|
||||
first.get_custom_properties() == second.get_custom_properties()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ComputedValues_GetStyleRuleList(values: ServoComputedValuesBorrowed,
|
||||
rules: RawGeckoServoStyleRuleListBorrowedMut) {
|
||||
let values = ComputedValues::as_arc(&values);
|
||||
if let Some(ref rule_node) = values.rules {
|
||||
let mut result = vec![];
|
||||
for node in rule_node.self_and_ancestors() {
|
||||
|
@ -2775,7 +2805,7 @@ pub extern "C" fn Servo_TakeChangeHint(element: RawGeckoElementBorrowed,
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
|
||||
_raw_data: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong
|
||||
-> ServoStyleContextStrong
|
||||
{
|
||||
let element = GeckoElement(element);
|
||||
debug!("Servo_ResolveStyle: {:?}", element);
|
||||
|
@ -2792,10 +2822,12 @@ pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
|
||||
pseudo_type: CSSPseudoElementType,
|
||||
pseudo_tag: *mut nsIAtom,
|
||||
parent_style_context: ServoStyleContextBorrowedOrNull,
|
||||
rule_inclusion: StyleRuleInclusion,
|
||||
snapshots: *const ServoElementSnapshotTable,
|
||||
raw_data: RawServoStyleSetBorrowed)
|
||||
-> ServoComputedValuesStrong
|
||||
-> ServoStyleContextStrong
|
||||
{
|
||||
debug_assert!(!snapshots.is_null());
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
|
@ -2816,6 +2848,8 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
|
|||
/* inherited_styles = */ None,
|
||||
&*data,
|
||||
/* is_probe = */ false,
|
||||
(pseudo_tag, pseudo_type),
|
||||
parent_style_context
|
||||
).expect("We're not probing, so we should always get a style \
|
||||
back")
|
||||
}
|
||||
|
@ -2869,11 +2903,11 @@ fn simulate_compute_values_failure(_: &PropertyValuePair) -> bool {
|
|||
|
||||
fn create_context<'a>(per_doc_data: &'a PerDocumentStyleDataImpl,
|
||||
font_metrics_provider: &'a FontMetricsProvider,
|
||||
style: &'a ComputedValues,
|
||||
parent_style: &'a Option<&Arc<ComputedValues>>)
|
||||
style: &'a ComputedValuesInner,
|
||||
parent_style: &'a Option<&ComputedValuesInner>)
|
||||
-> Context<'a> {
|
||||
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 {
|
||||
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 metrics = get_metrics_provider_for_product();
|
||||
let style = ComputedValues::as_arc(&style);
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let parent_element = element.inheritance_parent();
|
||||
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);
|
||||
|
||||
|
@ -2980,13 +3013,12 @@ pub extern "C" fn Servo_GetAnimationValues(declarations: RawServoDeclarationBloc
|
|||
raw_data: RawServoStyleSetBorrowed,
|
||||
animation_values: RawGeckoServoAnimationValueListBorrowedMut) {
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let style = ComputedValues::as_arc(&style);
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let parent_element = element.inheritance_parent();
|
||||
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);
|
||||
|
||||
|
@ -3009,13 +3041,12 @@ pub extern "C" fn Servo_AnimationValue_Compute(element: RawGeckoElementBorrowed,
|
|||
raw_data: RawServoStyleSetBorrowed)
|
||||
-> RawServoAnimationValueStrong {
|
||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let style = ComputedValues::as_arc(&style);
|
||||
let metrics = get_metrics_provider_for_product();
|
||||
|
||||
let element = GeckoElement(element);
|
||||
let parent_element = element.inheritance_parent();
|
||||
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);
|
||||
|
||||
|
@ -3259,16 +3290,16 @@ pub extern "C" fn Servo_StyleSet_GetCounterStyleRule(raw_data: RawServoStyleSetB
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(
|
||||
raw_data: RawServoStyleSetBorrowed,
|
||||
parent_style_or_null: ServoComputedValuesBorrowedOrNull,
|
||||
declarations: RawServoDeclarationBlockBorrowed
|
||||
) -> ServoComputedValuesStrong {
|
||||
parent_style_context: ServoStyleContextBorrowedOrNull,
|
||||
declarations: RawServoDeclarationBlockBorrowed,
|
||||
) -> ServoStyleContextStrong {
|
||||
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let guards = StylesheetGuards::same(&guard);
|
||||
|
||||
let parent_style = match ComputedValues::arc_from_borrowed(&parent_style_or_null) {
|
||||
Some(parent) => &parent.inner,
|
||||
let parent_style = match parent_style_context {
|
||||
Some(parent) => &**parent,
|
||||
None => doc_data.default_computed_values(),
|
||||
};
|
||||
|
||||
|
@ -3276,7 +3307,8 @@ pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(
|
|||
|
||||
doc_data.stylist.compute_for_declarations(&guards,
|
||||
parent_style,
|
||||
declarations.clone_arc()).into_strong()
|
||||
declarations.clone_arc(),
|
||||
parent_style_context).into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -3336,7 +3368,8 @@ pub extern "C" fn Servo_StyleSet_HasStateDependency(
|
|||
pub extern "C" fn Servo_GetCustomPropertyValue(computed_values: ServoComputedValuesBorrowed,
|
||||
name: *const nsAString,
|
||||
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,
|
||||
None => return false,
|
||||
};
|
||||
|
@ -3353,7 +3386,7 @@ pub extern "C" fn Servo_GetCustomPropertyValue(computed_values: ServoComputedVal
|
|||
|
||||
#[no_mangle]
|
||||
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,
|
||||
None => 0,
|
||||
}
|
||||
|
@ -3363,7 +3396,7 @@ pub extern "C" fn Servo_GetCustomPropertiesCount(computed_values: ServoComputedV
|
|||
pub extern "C" fn Servo_GetCustomPropertyNameAt(computed_values: ServoComputedValuesBorrowed,
|
||||
index: u32,
|
||||
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,
|
||||
None => return false,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue