Attachment #8822391: part 6. Stop using initial_values when doing inheritance in Gecko glue code for bug #1298588

View | Details | Raw Unified | Return to bug 1298588
Collapse All | Expand All

(-)a/layout/style/ServoBindingList.h (+1 lines)
Line     Link Here 
 Lines 142-157   SERVO_BINDING_FUNC(Servo_CSSSupports, bo Link Here 
142
                   const nsACString* name, const nsACString* value)
142
                   const nsACString* name, const nsACString* value)
143
143
144
// Computed style data
144
// Computed style data
145
SERVO_BINDING_FUNC(Servo_ComputedValues_GetForAnonymousBox,
145
SERVO_BINDING_FUNC(Servo_ComputedValues_GetForAnonymousBox,
146
                   ServoComputedValuesStrong,
146
                   ServoComputedValuesStrong,
147
                   ServoComputedValuesBorrowedOrNull parent_style_or_null,
147
                   ServoComputedValuesBorrowedOrNull parent_style_or_null,
148
                   nsIAtom* pseudoTag, RawServoStyleSetBorrowed set)
148
                   nsIAtom* pseudoTag, RawServoStyleSetBorrowed set)
149
SERVO_BINDING_FUNC(Servo_ComputedValues_Inherit, ServoComputedValuesStrong,
149
SERVO_BINDING_FUNC(Servo_ComputedValues_Inherit, ServoComputedValuesStrong,
150
                   RawServoStyleSetBorrowed set,
150
                   ServoComputedValuesBorrowedOrNull parent_style)
151
                   ServoComputedValuesBorrowedOrNull parent_style)
151
152
152
// Initialize Servo components. Should be called exactly once at startup.
153
// Initialize Servo components. Should be called exactly once at startup.
153
SERVO_BINDING_FUNC(Servo_Initialize, void)
154
SERVO_BINDING_FUNC(Servo_Initialize, void)
154
// Shut down Servo components. Should be called exactly once at shutdown.
155
// Shut down Servo components. Should be called exactly once at shutdown.
155
SERVO_BINDING_FUNC(Servo_Shutdown, void)
156
SERVO_BINDING_FUNC(Servo_Shutdown, void)
156
157
157
// Gets the snapshot for the element. This will return null if the element
158
// Gets the snapshot for the element. This will return null if the element
(-)a/layout/style/ServoStyleSet.cpp (-2 / +2 lines)
Line     Link Here 
 Lines 170-200   ServoStyleSet::ResolveStyleForText(nsICo Link Here 
170
170
171
  // Gecko expects text node style contexts to be like elements that match no
171
  // Gecko expects text node style contexts to be like elements that match no
172
  // rules: inherit the inherit structs, reset the reset structs. This is cheap
172
  // rules: inherit the inherit structs, reset the reset structs. This is cheap
173
  // enough to do on the main thread, which means that the parallel style system
173
  // enough to do on the main thread, which means that the parallel style system
174
  // can avoid worrying about text nodes.
174
  // can avoid worrying about text nodes.
175
  const ServoComputedValues* parentComputedValues =
175
  const ServoComputedValues* parentComputedValues =
176
    aParentContext->StyleSource().AsServoComputedValues();
176
    aParentContext->StyleSource().AsServoComputedValues();
177
  RefPtr<ServoComputedValues> computedValues =
177
  RefPtr<ServoComputedValues> computedValues =
178
    Servo_ComputedValues_Inherit(parentComputedValues).Consume();
178
    Servo_ComputedValues_Inherit(mRawSet.get(), parentComputedValues).Consume();
179
179
180
  return GetContext(computedValues.forget(), aParentContext,
180
  return GetContext(computedValues.forget(), aParentContext,
181
                    nsCSSAnonBoxes::mozText, CSSPseudoElementType::AnonBox);
181
                    nsCSSAnonBoxes::mozText, CSSPseudoElementType::AnonBox);
182
}
182
}
183
183
184
already_AddRefed<nsStyleContext>
184
already_AddRefed<nsStyleContext>
185
ServoStyleSet::ResolveStyleForOtherNonElement(nsStyleContext* aParentContext)
185
ServoStyleSet::ResolveStyleForOtherNonElement(nsStyleContext* aParentContext)
186
{
186
{
187
  // The parent context can be null if the non-element share a style context
187
  // The parent context can be null if the non-element share a style context
188
  // with the root of an anonymous subtree.
188
  // with the root of an anonymous subtree.
189
  const ServoComputedValues* parent =
189
  const ServoComputedValues* parent =
190
    aParentContext ? aParentContext->StyleSource().AsServoComputedValues() : nullptr;
190
    aParentContext ? aParentContext->StyleSource().AsServoComputedValues() : nullptr;
191
  RefPtr<ServoComputedValues> computedValues =
191
  RefPtr<ServoComputedValues> computedValues =
192
    Servo_ComputedValues_Inherit(parent).Consume();
192
    Servo_ComputedValues_Inherit(mRawSet.get(), parent).Consume();
193
  MOZ_ASSERT(computedValues);
193
  MOZ_ASSERT(computedValues);
194
194
195
  return GetContext(computedValues.forget(), aParentContext,
195
  return GetContext(computedValues.forget(), aParentContext,
196
                    nsCSSAnonBoxes::mozOtherNonElement,
196
                    nsCSSAnonBoxes::mozOtherNonElement,
197
                    CSSPseudoElementType::AnonBox);
197
                    CSSPseudoElementType::AnonBox);
198
}
198
}
199
199
200
already_AddRefed<nsStyleContext>
200
already_AddRefed<nsStyleContext>
(-)a/servo/components/style/gecko_bindings/bindings.rs (-1 / +2 lines)
Line     Link Here 
 Lines 1315-1331   extern "C" { Link Here 
1315
    pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
1315
    pub fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
1316
                                                       ServoComputedValuesBorrowedOrNull,
1316
                                                       ServoComputedValuesBorrowedOrNull,
1317
                                                   pseudoTag: *mut nsIAtom,
1317
                                                   pseudoTag: *mut nsIAtom,
1318
                                                   set:
1318
                                                   set:
1319
                                                       RawServoStyleSetBorrowed)
1319
                                                       RawServoStyleSetBorrowed)
1320
     -> ServoComputedValuesStrong;
1320
     -> ServoComputedValuesStrong;
1321
}
1321
}
1322
extern "C" {
1322
extern "C" {
1323
    pub fn Servo_ComputedValues_Inherit(parent_style:
1323
    pub fn Servo_ComputedValues_Inherit(set: RawServoStyleSetBorrowed,
1324
                                        parent_style:
1324
                                            ServoComputedValuesBorrowedOrNull)
1325
                                            ServoComputedValuesBorrowedOrNull)
1325
     -> ServoComputedValuesStrong;
1326
     -> ServoComputedValuesStrong;
1326
}
1327
}
1327
extern "C" {
1328
extern "C" {
1328
    pub fn Servo_Initialize();
1329
    pub fn Servo_Initialize();
1329
}
1330
}
1330
extern "C" {
1331
extern "C" {
1331
    pub fn Servo_Shutdown();
1332
    pub fn Servo_Shutdown();
(-)a/servo/components/style/properties/gecko.mako.rs (-9 / +2 lines)
Line     Link Here 
 Lines 75-101   pub struct ComputedValues { Link Here 
75
75
76
    custom_properties: Option<Arc<ComputedValuesMap>>,
76
    custom_properties: Option<Arc<ComputedValuesMap>>,
77
    shareable: bool,
77
    shareable: bool,
78
    pub writing_mode: WritingMode,
78
    pub writing_mode: WritingMode,
79
    pub root_font_size: Au,
79
    pub root_font_size: Au,
80
}
80
}
81
81
82
impl ComputedValues {
82
impl ComputedValues {
83
    pub fn inherit_from(parent: &Arc<Self>) -> Arc<Self> {
83
    pub fn inherit_from(parent: &Arc<Self>, default: &Arc<Self>) -> Arc<Self> {
84
        Arc::new(ComputedValues {
84
        Arc::new(ComputedValues {
85
            custom_properties: parent.custom_properties.clone(),
85
            custom_properties: parent.custom_properties.clone(),
86
            shareable: parent.shareable,
86
            shareable: parent.shareable,
87
            writing_mode: parent.writing_mode,
87
            writing_mode: parent.writing_mode,
88
            root_font_size: parent.root_font_size,
88
            root_font_size: parent.root_font_size,
89
            % for style_struct in data.style_structs:
89
            % for style_struct in data.style_structs:
90
            % if style_struct.inherited:
90
            % if style_struct.inherited:
91
            ${style_struct.ident}: parent.${style_struct.ident}.clone(),
91
            ${style_struct.ident}: parent.${style_struct.ident}.clone(),
92
            % else:
92
            % else:
93
            ${style_struct.ident}: Self::initial_values().${style_struct.ident}.clone(),
93
            ${style_struct.ident}: default.${style_struct.ident}.clone(),
94
            % endif
94
            % endif
95
            % endfor
95
            % endfor
96
        })
96
        })
97
    }
97
    }
98
98
99
    pub fn new(custom_properties: Option<Arc<ComputedValuesMap>>,
99
    pub fn new(custom_properties: Option<Arc<ComputedValuesMap>>,
100
           shareable: bool,
100
           shareable: bool,
101
           writing_mode: WritingMode,
101
           writing_mode: WritingMode,
 Lines 110-132   impl ComputedValues { Link Here 
110
            writing_mode: writing_mode,
110
            writing_mode: writing_mode,
111
            root_font_size: root_font_size,
111
            root_font_size: root_font_size,
112
            % for style_struct in data.style_structs:
112
            % for style_struct in data.style_structs:
113
            ${style_struct.ident}: ${style_struct.ident},
113
            ${style_struct.ident}: ${style_struct.ident},
114
            % endfor
114
            % endfor
115
        }
115
        }
116
    }
116
    }
117
117
118
    pub fn style_for_child_text_node(parent: &Arc<Self>) -> Arc<Self> {
119
        // Gecko expects text nodes to be styled as if they were elements that
120
        // matched no rules (that is, inherited style structs are inherited and
121
        // non-inherited style structs are set to their initial values).
122
        ComputedValues::inherit_from(parent)
123
    }
124
125
    pub fn initial_values() -> &'static Self {
118
    pub fn initial_values() -> &'static Self {
126
        unsafe {
119
        unsafe {
127
            debug_assert!(!raw_initial_values().is_null());
120
            debug_assert!(!raw_initial_values().is_null());
128
            &*raw_initial_values()
121
            &*raw_initial_values()
129
        }
122
        }
130
    }
123
    }
131
124
132
    pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
125
    pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
(-)a/servo/ports/geckolib/glue.rs (-3 / +6 lines)
Line     Link Here 
 Lines 515-537   fn get_pseudo_style(element: GeckoElemen Link Here 
515
            let base = &styles.primary.values;
515
            let base = &styles.primary.values;
516
            d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base)
516
            d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base)
517
                     .map(|s| s.values.clone())
517
                     .map(|s| s.values.clone())
518
        },
518
        },
519
    }
519
    }
520
}
520
}
521
521
522
#[no_mangle]
522
#[no_mangle]
523
pub extern "C" fn Servo_ComputedValues_Inherit(parent_style: ServoComputedValuesBorrowedOrNull)
523
pub extern "C" fn Servo_ComputedValues_Inherit(
524
  raw_data: RawServoStyleSetBorrowed,
525
  parent_style: ServoComputedValuesBorrowedOrNull)
524
     -> ServoComputedValuesStrong {
526
     -> ServoComputedValuesStrong {
527
    let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
525
    let maybe_arc = ComputedValues::arc_from_borrowed(&parent_style);
528
    let maybe_arc = ComputedValues::arc_from_borrowed(&parent_style);
526
    let style = if let Some(reference) = maybe_arc.as_ref() {
529
    let style = if let Some(reference) = maybe_arc.as_ref() {
527
        ComputedValues::inherit_from(reference)
530
        ComputedValues::inherit_from(reference, &data.default_computed_values)
528
    } else {
531
    } else {
529
        Arc::new(ComputedValues::initial_values().clone())
532
        data.default_computed_values.clone()
530
    };
533
    };
531
    style.into_strong()
534
    style.into_strong()
532
}
535
}
533
536
534
#[no_mangle]
537
#[no_mangle]
535
pub extern "C" fn Servo_ComputedValues_AddRef(ptr: ServoComputedValuesBorrowed) -> () {
538
pub extern "C" fn Servo_ComputedValues_AddRef(ptr: ServoComputedValuesBorrowed) -> () {
536
    unsafe { ComputedValues::addref(ptr) };
539
    unsafe { ComputedValues::addref(ptr) };
537
}
540
}

Return to bug 1298588