Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: Fuse ServoStyleContext and ServoComputedValues #17767

Merged
merged 16 commits into from Jul 18, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

stylo: Switch Gecko over to ServoStyleContext

  • Loading branch information
Manishearth committed Jul 18, 2017
commit 89930e75654f2942e39e1f1f93f1525e40488fb0
@@ -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> {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.