mirror of
https://github.com/servo/servo.git
synced 2025-06-21 23:59:00 +01:00
stylo: Cleanup the Gecko bits.
MozReview-Commit-ID: dbVDy1u4vp
This commit is contained in:
parent
655c842d2e
commit
07e1c6e75a
8 changed files with 148 additions and 111 deletions
|
@ -16,7 +16,7 @@ use gecko_bindings::structs::nsIDocument;
|
||||||
use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
|
use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
|
||||||
use invalidation::media_queries::{MediaListKey, ToMediaListKey};
|
use invalidation::media_queries::{MediaListKey, ToMediaListKey};
|
||||||
use media_queries::{Device, MediaList};
|
use media_queries::{Device, MediaList};
|
||||||
use properties::ComputedValuesInner;
|
use properties::ComputedValues;
|
||||||
use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
|
use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
|
||||||
use stylearc::Arc;
|
use stylearc::Arc;
|
||||||
use stylesheet_set::StylesheetSet;
|
use stylesheet_set::StylesheetSet;
|
||||||
|
@ -188,8 +188,8 @@ impl PerDocumentStyleDataImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the default computed values for this document.
|
/// Get the default computed values for this document.
|
||||||
pub fn default_computed_values(&self) -> &ComputedValuesInner {
|
pub fn default_computed_values(&self) -> &Arc<ComputedValues> {
|
||||||
self.stylist.device().default_computed_values()
|
self.stylist.device().default_computed_values_arc()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear the stylist. This will be a no-op if the stylist is
|
/// Clear the stylist. This will be a no-op if the stylist is
|
||||||
|
|
|
@ -17,9 +17,10 @@ use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType
|
||||||
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned};
|
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned};
|
||||||
use media_queries::MediaType;
|
use media_queries::MediaType;
|
||||||
use parser::ParserContext;
|
use parser::ParserContext;
|
||||||
use properties::{ComputedValuesInner, StyleBuilder};
|
use properties::{ComputedValues, StyleBuilder};
|
||||||
use properties::longhands::font_size;
|
use properties::longhands::font_size;
|
||||||
use selectors::parser::SelectorParseError;
|
use selectors::parser::SelectorParseError;
|
||||||
|
use servo_arc::Arc;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering};
|
||||||
use str::starts_with_ignore_ascii_case;
|
use str::starts_with_ignore_ascii_case;
|
||||||
|
@ -36,7 +37,7 @@ pub struct Device {
|
||||||
/// stylist, and thus the `Device`, so having a raw pres context pointer
|
/// stylist, and thus the `Device`, so having a raw pres context pointer
|
||||||
/// here is fine.
|
/// here is fine.
|
||||||
pres_context: RawGeckoPresContextOwned,
|
pres_context: RawGeckoPresContextOwned,
|
||||||
default_values: ComputedValuesInner,
|
default_values: Arc<ComputedValues>,
|
||||||
viewport_override: Option<ViewportConstraints>,
|
viewport_override: Option<ViewportConstraints>,
|
||||||
/// The font size of the root element
|
/// The font size of the root element
|
||||||
/// This is set when computing the style of the root
|
/// This is set when computing the style of the root
|
||||||
|
@ -61,7 +62,7 @@ impl Device {
|
||||||
assert!(!pres_context.is_null());
|
assert!(!pres_context.is_null());
|
||||||
Device {
|
Device {
|
||||||
pres_context: pres_context,
|
pres_context: pres_context,
|
||||||
default_values: ComputedValuesInner::default_values(unsafe { &*pres_context }),
|
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
|
||||||
viewport_override: None,
|
viewport_override: None,
|
||||||
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
|
||||||
used_root_font_size: AtomicBool::new(false),
|
used_root_font_size: AtomicBool::new(false),
|
||||||
|
@ -77,7 +78,12 @@ impl Device {
|
||||||
|
|
||||||
/// Returns the default computed values as a reference, in order to match
|
/// Returns the default computed values as a reference, in order to match
|
||||||
/// Servo.
|
/// Servo.
|
||||||
pub fn default_computed_values(&self) -> &ComputedValuesInner {
|
pub fn default_computed_values(&self) -> &ComputedValues {
|
||||||
|
&self.default_values
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the default computed values as an `Arc`.
|
||||||
|
pub fn default_computed_values_arc(&self) -> &Arc<ComputedValues> {
|
||||||
&self.default_values
|
&self.default_values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +107,7 @@ impl Device {
|
||||||
pub fn reset_computed_values(&mut self) {
|
pub fn reset_computed_values(&mut self) {
|
||||||
// NB: A following stylesheet flush will populate this if appropriate.
|
// NB: A following stylesheet flush will populate this if appropriate.
|
||||||
self.viewport_override = None;
|
self.viewport_override = None;
|
||||||
self.default_values = ComputedValuesInner::default_values(self.pres_context());
|
self.default_values = ComputedValues::default_values(self.pres_context());
|
||||||
self.used_root_font_size.store(false, Ordering::Relaxed);
|
self.used_root_font_size.store(false, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,8 +626,7 @@ impl Expression {
|
||||||
is_root_element: false,
|
is_root_element: false,
|
||||||
device: device,
|
device: device,
|
||||||
inherited_style: default_values,
|
inherited_style: default_values,
|
||||||
layout_parent_style: default_values,
|
style: StyleBuilder::for_derived_style(device, default_values, None),
|
||||||
style: StyleBuilder::for_derived_style(default_values),
|
|
||||||
font_metrics_provider: &provider,
|
font_metrics_provider: &provider,
|
||||||
cached_system_font: None,
|
cached_system_font: None,
|
||||||
in_media_query: true,
|
in_media_query: true,
|
||||||
|
|
|
@ -107,7 +107,6 @@ impl PseudoElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Construct a `CSSPseudoElementType` from a pseudo-element
|
/// Construct a `CSSPseudoElementType` from a pseudo-element
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn pseudo_type(&self) -> CSSPseudoElementType {
|
pub fn pseudo_type(&self) -> CSSPseudoElementType {
|
||||||
|
@ -133,6 +132,21 @@ impl PseudoElement {
|
||||||
(self.atom().as_ptr(), self.pseudo_type())
|
(self.atom().as_ptr(), self.pseudo_type())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Construct a pseudo-element from an `Atom`.
|
||||||
|
#[inline]
|
||||||
|
pub fn from_atom(atom: &Atom) -> Option<Self> {
|
||||||
|
% for pseudo in PSEUDOS:
|
||||||
|
% if pseudo.is_tree_pseudo_element():
|
||||||
|
// We cannot generate ${pseudo_element_variant(pseudo)} from just an atom.
|
||||||
|
% else:
|
||||||
|
if atom == &atom!("${pseudo.value}") {
|
||||||
|
return Some(${pseudo_element_variant(pseudo)});
|
||||||
|
}
|
||||||
|
% endif
|
||||||
|
% endfor
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// 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> {
|
||||||
|
|
|
@ -57,6 +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 selector_parser::PseudoElement;
|
||||||
use std::mem::{forget, uninitialized, 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};
|
||||||
|
@ -105,11 +106,37 @@ impl ComputedValues {
|
||||||
${style_struct.ident},
|
${style_struct.ident},
|
||||||
% endfor
|
% endfor
|
||||||
).to_outer(
|
).to_outer(
|
||||||
device,
|
device.pres_context(),
|
||||||
parent,
|
parent,
|
||||||
pseudo.map(|p| p.pseudo_info())
|
pseudo.map(|p| p.pseudo_info())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
|
||||||
|
ComputedValuesInner::new(
|
||||||
|
/* custom_properties = */ None,
|
||||||
|
/* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
|
||||||
|
FontComputationData::default_font_size_keyword(),
|
||||||
|
ComputedValueFlags::empty(),
|
||||||
|
/* rules = */ None,
|
||||||
|
/* visited_style = */ None,
|
||||||
|
% for style_struct in data.style_structs:
|
||||||
|
style_structs::${style_struct.name}::default(pres_context),
|
||||||
|
% endfor
|
||||||
|
).to_outer(pres_context, None, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pseudo(&self) -> Option<PseudoElement> {
|
||||||
|
use string_cache::Atom;
|
||||||
|
|
||||||
|
let atom = (self.0)._base.mPseudoTag.raw::<structs::nsIAtom>();
|
||||||
|
if atom.is_null() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let atom = Atom::from(atom);
|
||||||
|
PseudoElement::from_atom(&atom)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for ComputedValues {
|
impl Drop for ComputedValues {
|
||||||
|
@ -145,8 +172,8 @@ impl Clone for ComputedValuesInner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PseudoInfo = (*mut structs::nsIAtom, structs::CSSPseudoElementType);
|
type PseudoInfo = (*mut structs::nsIAtom, structs::CSSPseudoElementType);
|
||||||
pub type ParentStyleContextInfo<'a> = Option< &'a ComputedValues>;
|
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>>,
|
||||||
|
@ -172,37 +199,28 @@ impl ComputedValuesInner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Self {
|
fn to_outer(
|
||||||
ComputedValuesInner {
|
self,
|
||||||
custom_properties: None,
|
pres_context: RawGeckoPresContextBorrowed,
|
||||||
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
|
parent: ParentStyleContextInfo,
|
||||||
font_computation_data: FontComputationData::default_values(),
|
info: Option<PseudoInfo>
|
||||||
rules: None,
|
) -> Arc<ComputedValues> {
|
||||||
visited_style: None,
|
|
||||||
flags: ComputedValueFlags::empty(),
|
|
||||||
% for style_struct in data.style_structs:
|
|
||||||
${style_struct.gecko_name}: Arc::into_raw_offset(
|
|
||||||
style_structs::${style_struct.name}::default(pres_context)
|
|
||||||
),
|
|
||||||
% endfor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_outer(self, device: &Device, parent: ParentStyleContextInfo,
|
|
||||||
info: Option<PseudoInfo>) -> Arc<ComputedValues> {
|
|
||||||
let (tag, ty) = if let Some(info) = info {
|
let (tag, ty) = if let Some(info) = info {
|
||||||
info
|
info
|
||||||
} else {
|
} else {
|
||||||
(ptr::null_mut(), structs::CSSPseudoElementType::NotPseudo)
|
(ptr::null_mut(), structs::CSSPseudoElementType::NotPseudo)
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe { self.to_outer_helper(device.pres_context(), parent, ty, tag) }
|
unsafe { self.to_outer_helper(pres_context, parent, ty, tag) }
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn to_outer_helper(self, pres_context: bindings::RawGeckoPresContextBorrowed,
|
unsafe fn to_outer_helper(
|
||||||
parent: ParentStyleContextInfo,
|
self,
|
||||||
pseudo_ty: structs::CSSPseudoElementType,
|
pres_context: bindings::RawGeckoPresContextBorrowed,
|
||||||
pseudo_tag: *mut structs::nsIAtom) -> Arc<ComputedValues> {
|
parent: ParentStyleContextInfo,
|
||||||
|
pseudo_ty: structs::CSSPseudoElementType,
|
||||||
|
pseudo_tag: *mut structs::nsIAtom
|
||||||
|
) -> Arc<ComputedValues> {
|
||||||
let arc = unsafe {
|
let arc = unsafe {
|
||||||
let arc: Arc<ComputedValues> = Arc::new(uninitialized());
|
let arc: Arc<ComputedValues> = Arc::new(uninitialized());
|
||||||
bindings::Gecko_ServoStyleContext_Init(&arc.0 as *const _ as *mut _, parent, pres_context,
|
bindings::Gecko_ServoStyleContext_Init(&arc.0 as *const _ as *mut _, parent, pres_context,
|
||||||
|
|
|
@ -121,10 +121,8 @@ impl FontComputationData {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assigns default values for variables in struct FontComputationData
|
/// Assigns default values for variables in struct FontComputationData
|
||||||
pub fn default_values() -> Self {
|
pub fn default_font_size_keyword() -> Option<(longhands::font_size::KeywordSize, f32)> {
|
||||||
FontComputationData{
|
Some((Default::default(), 1.))
|
||||||
font_size_keyword: Some((Default::default(), 1.))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1873,7 +1871,7 @@ pub mod style_structs {
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use gecko_properties::{ComputedValues, ComputedValuesInner, ParentStyleContextInfo, PseudoInfo};
|
pub use gecko_properties::{ComputedValues, ComputedValuesInner};
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[cfg_attr(feature = "servo", derive(Clone, Debug))]
|
#[cfg_attr(feature = "servo", derive(Clone, Debug))]
|
||||||
|
@ -1921,6 +1919,7 @@ pub struct ComputedValues {
|
||||||
inner: ComputedValuesInner,
|
inner: ComputedValuesInner,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
impl ComputedValues {
|
impl ComputedValues {
|
||||||
/// Create a new refcounted `ComputedValues`
|
/// Create a new refcounted `ComputedValues`
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
@ -2521,8 +2520,12 @@ impl<'a> StyleBuilder<'a> {
|
||||||
|
|
||||||
/// Creates a StyleBuilder holding only references to the structs of `s`, in
|
/// Creates a StyleBuilder holding only references to the structs of `s`, in
|
||||||
/// order to create a derived style.
|
/// order to create a derived style.
|
||||||
pub fn for_derived_style(device: &'a Device, s: &'a ComputedValues) -> Self {
|
pub fn for_derived_style(
|
||||||
Self::for_inheritance(device, s, s, s.pseudo())
|
device: &'a Device,
|
||||||
|
s: &'a ComputedValues,
|
||||||
|
pseudo: Option<<&'a PseudoElement>,
|
||||||
|
) -> Self {
|
||||||
|
Self::for_inheritance(device, s, s, pseudo)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inherits style from the parent element, accounting for the default
|
/// Inherits style from the parent element, accounting for the default
|
||||||
|
|
|
@ -231,7 +231,7 @@ impl Range<specified::Length> {
|
||||||
is_root_element: false,
|
is_root_element: false,
|
||||||
device: device,
|
device: device,
|
||||||
inherited_style: default_values,
|
inherited_style: default_values,
|
||||||
style: StyleBuilder::for_derived_style(device, default_values),
|
style: StyleBuilder::for_derived_style(device, default_values, None),
|
||||||
// Servo doesn't support font metrics
|
// Servo doesn't support font metrics
|
||||||
// A real provider will be needed here once we do; since
|
// A real provider will be needed here once we do; since
|
||||||
// ch units can exist in media queries.
|
// ch units can exist in media queries.
|
||||||
|
|
|
@ -706,7 +706,7 @@ impl MaybeNew for ViewportConstraints {
|
||||||
is_root_element: false,
|
is_root_element: false,
|
||||||
device: device,
|
device: device,
|
||||||
inherited_style: default_values,
|
inherited_style: default_values,
|
||||||
style: StyleBuilder::for_derived_style(device, default_values),
|
style: StyleBuilder::for_derived_style(device, default_values, None),
|
||||||
font_metrics_provider: &provider,
|
font_metrics_provider: &provider,
|
||||||
cached_system_font: None,
|
cached_system_font: None,
|
||||||
in_media_query: false,
|
in_media_query: false,
|
||||||
|
|
|
@ -60,7 +60,6 @@ use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed;
|
||||||
use style::gecko_bindings::bindings::RawServoAnimationValueMapBorrowedMut;
|
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::ServoStyleContextBorrowedOrNull;
|
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;
|
||||||
|
@ -91,9 +90,8 @@ use style::invalidation::element::restyle_hints::{self, RestyleHint};
|
||||||
use style::media_queries::{MediaList, parse_media_query_list};
|
use style::media_queries::{MediaList, parse_media_query_list};
|
||||||
use style::parallel;
|
use style::parallel;
|
||||||
use style::parser::ParserContext;
|
use style::parser::ParserContext;
|
||||||
use style::properties::{ComputedValues, ComputedValuesInner, Importance};
|
use style::properties::{ComputedValues, Importance};
|
||||||
use style::properties::{IS_FIELDSET_CONTENT, LonghandIdSet};
|
use style::properties::{IS_FIELDSET_CONTENT, LonghandIdSet};
|
||||||
use style::properties::{ParentStyleContextInfo, PseudoInfo};
|
|
||||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyId};
|
||||||
use style::properties::{SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, SourcePropertyDeclaration, StyleBuilder};
|
use style::properties::{SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, SourcePropertyDeclaration, StyleBuilder};
|
||||||
use style::properties::animated_properties::{Animatable, AnimatableLonghand, AnimationValue};
|
use style::properties::animated_properties::{Animatable, AnimatableLonghand, AnimationValue};
|
||||||
|
@ -1504,7 +1502,6 @@ pub extern "C" fn Servo_DocumentRule_GetConditionText(rule: RawServoDocumentRule
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoStyleContextBorrowedOrNull,
|
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)
|
||||||
-> ServoStyleContextStrong {
|
-> ServoStyleContextStrong {
|
||||||
|
@ -1521,20 +1518,19 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
|
||||||
cascade_flags.insert(IS_FIELDSET_CONTENT);
|
cascade_flags.insert(IS_FIELDSET_CONTENT);
|
||||||
}
|
}
|
||||||
let metrics = get_metrics_provider_for_product();
|
let metrics = get_metrics_provider_for_product();
|
||||||
data.stylist.precomputed_values_for_pseudo(&guards, &pseudo, parent_style_or_null.map(|x| &**x),
|
data.stylist.precomputed_values_for_pseudo(
|
||||||
cascade_flags, &metrics,
|
&guards,
|
||||||
(pseudo_tag, pseudo_type),
|
&pseudo,
|
||||||
parent_style_or_null)
|
parent_style_or_null.map(|x| &*x),
|
||||||
.into_strong()
|
cascade_flags, &metrics
|
||||||
|
).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: ServoStyleContextBorrowedOrNull,
|
||||||
parent_style_context: ServoStyleContextBorrowedOrNull,
|
|
||||||
raw_data: RawServoStyleSetBorrowed)
|
raw_data: RawServoStyleSetBorrowed)
|
||||||
-> ServoStyleContextStrong
|
-> ServoStyleContextStrong
|
||||||
{
|
{
|
||||||
|
@ -1551,9 +1547,7 @@ 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()
|
doc_data.default_computed_values().clone().into_strong()
|
||||||
.clone().to_outer(doc_data.stylist.device(), parent_style_context,
|
|
||||||
Some((pseudo_tag, pseudo_type))).into_strong()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1571,8 +1565,6 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
|
||||||
inherited_style,
|
inherited_style,
|
||||||
&*doc_data,
|
&*doc_data,
|
||||||
is_probe,
|
is_probe,
|
||||||
(pseudo_tag, pseudo_type),
|
|
||||||
parent_style_context
|
|
||||||
);
|
);
|
||||||
|
|
||||||
match style {
|
match style {
|
||||||
|
@ -1624,11 +1616,9 @@ fn get_pseudo_style(
|
||||||
pseudo: &PseudoElement,
|
pseudo: &PseudoElement,
|
||||||
rule_inclusion: RuleInclusion,
|
rule_inclusion: RuleInclusion,
|
||||||
styles: &ElementStyles,
|
styles: &ElementStyles,
|
||||||
inherited_styles: Option<&ComputedValuesInner>,
|
inherited_styles: Option<&ComputedValues>,
|
||||||
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 => {
|
||||||
|
@ -1648,17 +1638,17 @@ fn get_pseudo_style(
|
||||||
doc_data.stylist
|
doc_data.stylist
|
||||||
.compute_pseudo_element_style_with_inputs(
|
.compute_pseudo_element_style_with_inputs(
|
||||||
&inputs,
|
&inputs,
|
||||||
|
pseudo,
|
||||||
&guards,
|
&guards,
|
||||||
inherited_styles,
|
inherited_styles,
|
||||||
&metrics,
|
&metrics
|
||||||
pseudo_info.clone(),
|
)
|
||||||
parent_style_context)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
debug_assert!(inherited_styles.is_none() ||
|
debug_assert!(inherited_styles.is_none() ||
|
||||||
ptr::eq(&*inherited_styles.unwrap(),
|
ptr::eq(inherited_styles.unwrap(),
|
||||||
&***styles.primary()));
|
&**styles.primary()));
|
||||||
styles.pseudos.get(&pseudo).cloned()
|
styles.pseudos.get(&pseudo).cloned()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1666,8 +1656,8 @@ fn get_pseudo_style(
|
||||||
PseudoElementCascadeType::Precomputed => unreachable!("No anonymous boxes"),
|
PseudoElementCascadeType::Precomputed => unreachable!("No anonymous boxes"),
|
||||||
PseudoElementCascadeType::Lazy => {
|
PseudoElementCascadeType::Lazy => {
|
||||||
debug_assert!(inherited_styles.is_none() ||
|
debug_assert!(inherited_styles.is_none() ||
|
||||||
ptr::eq(&*inherited_styles.unwrap(),
|
ptr::eq(inherited_styles.unwrap(),
|
||||||
&***styles.primary()));
|
&**styles.primary()));
|
||||||
let base = if pseudo.inherits_from_default_values() {
|
let base = if pseudo.inherits_from_default_values() {
|
||||||
doc_data.default_computed_values()
|
doc_data.default_computed_values()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1684,8 +1674,7 @@ fn get_pseudo_style(
|
||||||
base,
|
base,
|
||||||
is_probe,
|
is_probe,
|
||||||
&metrics,
|
&metrics,
|
||||||
pseudo_info.clone(),
|
)
|
||||||
parent_style_context)
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1695,17 +1684,17 @@ fn get_pseudo_style(
|
||||||
|
|
||||||
Some(style.unwrap_or_else(|| {
|
Some(style.unwrap_or_else(|| {
|
||||||
StyleBuilder::for_inheritance(
|
StyleBuilder::for_inheritance(
|
||||||
|
doc_data.stylist.device(),
|
||||||
styles.primary(),
|
styles.primary(),
|
||||||
doc_data.default_computed_values(),
|
doc_data.default_computed_values(),
|
||||||
).build().to_outer(doc_data.stylist.device(), parent_style_context,
|
Some(pseudo),
|
||||||
Some(pseudo_info))
|
).build()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ComputedValues_Inherit(
|
pub extern "C" fn Servo_ComputedValues_Inherit(
|
||||||
raw_data: RawServoStyleSetBorrowed,
|
raw_data: RawServoStyleSetBorrowed,
|
||||||
pseudo_type: CSSPseudoElementType,
|
|
||||||
pseudo_tag: *mut nsIAtom,
|
pseudo_tag: *mut nsIAtom,
|
||||||
parent_style_context: ServoStyleContextBorrowedOrNull,
|
parent_style_context: ServoStyleContextBorrowedOrNull,
|
||||||
target: structs::InheritTarget
|
target: structs::InheritTarget
|
||||||
|
@ -1713,10 +1702,17 @@ pub extern "C" fn Servo_ComputedValues_Inherit(
|
||||||
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||||
|
|
||||||
let for_text = target == structs::InheritTarget::Text;
|
let for_text = target == structs::InheritTarget::Text;
|
||||||
|
let atom = Atom::from(pseudo_tag);
|
||||||
|
let pseudo = PseudoElement::from_anon_box_atom(&atom)
|
||||||
|
.expect("Not an anon-box? Gah!");
|
||||||
let style = if let Some(reference) = parent_style_context {
|
let style = if let Some(reference) = parent_style_context {
|
||||||
let mut style =
|
let mut style = StyleBuilder::for_inheritance(
|
||||||
StyleBuilder::for_inheritance(reference,
|
data.stylist.device(),
|
||||||
&data.default_computed_values());
|
reference,
|
||||||
|
data.default_computed_values(),
|
||||||
|
Some(&pseudo)
|
||||||
|
);
|
||||||
|
|
||||||
if for_text {
|
if for_text {
|
||||||
StyleAdjuster::new(&mut style)
|
StyleAdjuster::new(&mut style)
|
||||||
.adjust_for_text();
|
.adjust_for_text();
|
||||||
|
@ -1725,16 +1721,14 @@ pub extern "C" fn Servo_ComputedValues_Inherit(
|
||||||
style.build()
|
style.build()
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(!for_text);
|
debug_assert!(!for_text);
|
||||||
data.default_computed_values().clone()
|
StyleBuilder::for_derived_style(
|
||||||
|
data.stylist.device(),
|
||||||
|
data.default_computed_values(),
|
||||||
|
Some(&pseudo),
|
||||||
|
).build()
|
||||||
};
|
};
|
||||||
|
|
||||||
let pseudo_info = if pseudo_tag.is_null() {
|
style.into_strong()
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some((pseudo_tag, pseudo_type))
|
|
||||||
};
|
|
||||||
|
|
||||||
style.to_outer(data.stylist.device(), parent_style_context, pseudo_info).into_strong()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -2814,8 +2808,6 @@ 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)
|
||||||
|
@ -2840,8 +2832,6 @@ 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")
|
||||||
}
|
}
|
||||||
|
@ -2895,8 +2885,9 @@ 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 ComputedValuesInner,
|
style: &'a ComputedValues,
|
||||||
parent_style: &'a Option<&ComputedValuesInner>)
|
parent_style: Option<&'a ComputedValues>,
|
||||||
|
pseudo: Option<&'a PseudoElement>)
|
||||||
-> 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.unwrap_or(default_values);
|
let inherited_style = parent_style.unwrap_or(default_values);
|
||||||
|
@ -2905,8 +2896,7 @@ fn create_context<'a>(per_doc_data: &'a PerDocumentStyleDataImpl,
|
||||||
is_root_element: false,
|
is_root_element: false,
|
||||||
device: per_doc_data.stylist.device(),
|
device: per_doc_data.stylist.device(),
|
||||||
inherited_style: inherited_style,
|
inherited_style: inherited_style,
|
||||||
layout_parent_style: inherited_style,
|
style: StyleBuilder::for_derived_style(per_doc_data.stylist.device(), style, pseudo),
|
||||||
style: StyleBuilder::for_derived_style(&style),
|
|
||||||
font_metrics_provider: font_metrics_provider,
|
font_metrics_provider: font_metrics_provider,
|
||||||
cached_system_font: None,
|
cached_system_font: None,
|
||||||
in_media_query: false,
|
in_media_query: false,
|
||||||
|
@ -2917,7 +2907,7 @@ fn create_context<'a>(per_doc_data: &'a PerDocumentStyleDataImpl,
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeListBorrowed,
|
pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeListBorrowed,
|
||||||
element: RawGeckoElementBorrowed,
|
element: RawGeckoElementBorrowed,
|
||||||
style: ServoComputedValuesBorrowed,
|
style: ServoStyleContextBorrowed,
|
||||||
raw_data: RawServoStyleSetBorrowed,
|
raw_data: RawServoStyleSetBorrowed,
|
||||||
computed_keyframes: RawGeckoComputedKeyframeValuesListBorrowedMut)
|
computed_keyframes: RawGeckoComputedKeyframeValuesListBorrowedMut)
|
||||||
{
|
{
|
||||||
|
@ -2926,13 +2916,15 @@ 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()).map(|x| &***x);
|
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 pseudo = style.pseudo();
|
||||||
|
let mut context = create_context(&data, &metrics, style, parent_style, pseudo.as_ref());
|
||||||
|
|
||||||
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();
|
||||||
|
@ -3001,18 +2993,20 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_GetAnimationValues(declarations: RawServoDeclarationBlockBorrowed,
|
pub extern "C" fn Servo_GetAnimationValues(declarations: RawServoDeclarationBlockBorrowed,
|
||||||
element: RawGeckoElementBorrowed,
|
element: RawGeckoElementBorrowed,
|
||||||
style: ServoComputedValuesBorrowed,
|
style: ServoStyleContextBorrowed,
|
||||||
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 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()).map(|x| &***x);
|
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 pseudo = style.pseudo();
|
||||||
|
let mut context = create_context(&data, &metrics, style, parent_style, pseudo.as_ref());
|
||||||
|
|
||||||
let default_values = data.default_computed_values();
|
let default_values = data.default_computed_values();
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
|
@ -3029,18 +3023,20 @@ pub extern "C" fn Servo_GetAnimationValues(declarations: RawServoDeclarationBloc
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_AnimationValue_Compute(element: RawGeckoElementBorrowed,
|
pub extern "C" fn Servo_AnimationValue_Compute(element: RawGeckoElementBorrowed,
|
||||||
declarations: RawServoDeclarationBlockBorrowed,
|
declarations: RawServoDeclarationBlockBorrowed,
|
||||||
style: ServoComputedValuesBorrowed,
|
style: ServoStyleContextBorrowed,
|
||||||
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 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()).map(|x| &***x);
|
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 pseudo = style.pseudo();
|
||||||
|
let mut context = create_context(&data, &metrics, style, parent_style, pseudo.as_ref());
|
||||||
|
|
||||||
let default_values = data.default_computed_values();
|
let default_values = data.default_computed_values();
|
||||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||||
|
@ -3291,16 +3287,17 @@ pub extern "C" fn Servo_StyleSet_ResolveForDeclarations(
|
||||||
let guards = StylesheetGuards::same(&guard);
|
let guards = StylesheetGuards::same(&guard);
|
||||||
|
|
||||||
let parent_style = match parent_style_context {
|
let parent_style = match parent_style_context {
|
||||||
Some(parent) => &**parent,
|
Some(parent) => &*parent,
|
||||||
None => doc_data.default_computed_values(),
|
None => doc_data.default_computed_values(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
let declarations = Locked::<PropertyDeclarationBlock>::as_arc(&declarations);
|
||||||
|
|
||||||
doc_data.stylist.compute_for_declarations(&guards,
|
doc_data.stylist.compute_for_declarations(
|
||||||
parent_style,
|
&guards,
|
||||||
declarations.clone_arc(),
|
parent_style,
|
||||||
parent_style_context).into_strong()
|
declarations.clone_arc(),
|
||||||
|
).into_strong()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue