Attachment #8822397: part 10. Pass through useful default styles to apply_declarations() 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 84-99   SERVO_BINDING_FUNC(Servo_StyleRule_GetSe Link Here 
84
SERVO_BINDING_FUNC(Servo_ParseProperty,
84
SERVO_BINDING_FUNC(Servo_ParseProperty,
85
                   RawServoDeclarationBlockStrong,
85
                   RawServoDeclarationBlockStrong,
86
                   const nsACString* property, const nsACString* value,
86
                   const nsACString* property, const nsACString* value,
87
                   const nsACString* base_url, ThreadSafeURIHolder* base,
87
                   const nsACString* base_url, ThreadSafeURIHolder* base,
88
                   ThreadSafeURIHolder* referrer,
88
                   ThreadSafeURIHolder* referrer,
89
                   ThreadSafePrincipalHolder* principal)
89
                   ThreadSafePrincipalHolder* principal)
90
SERVO_BINDING_FUNC(Servo_RestyleWithAddedDeclaration,
90
SERVO_BINDING_FUNC(Servo_RestyleWithAddedDeclaration,
91
                   ServoComputedValuesStrong,
91
                   ServoComputedValuesStrong,
92
                   RawServoStyleSetBorrowed set,
92
                   RawServoDeclarationBlockBorrowed declarations,
93
                   RawServoDeclarationBlockBorrowed declarations,
93
                   ServoComputedValuesBorrowed previous_style)
94
                   ServoComputedValuesBorrowed previous_style)
94
95
95
// Style attribute
96
// Style attribute
96
SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, RawServoDeclarationBlockStrong,
97
SERVO_BINDING_FUNC(Servo_ParseStyleAttribute, RawServoDeclarationBlockStrong,
97
                   const nsACString* data)
98
                   const nsACString* data)
98
SERVO_BINDING_FUNC(Servo_DeclarationBlock_CreateEmpty,
99
SERVO_BINDING_FUNC(Servo_DeclarationBlock_CreateEmpty,
99
                   RawServoDeclarationBlockStrong)
100
                   RawServoDeclarationBlockStrong)
(-)a/layout/style/ServoStyleSet.cpp (+9 lines)
Line     Link Here 
 Lines 526-533   ServoStyleSet::AssertTreeIsClean() Link Here 
526
}
526
}
527
#endif
527
#endif
528
528
529
void
529
void
530
ServoStyleSet::RecomputeDefaultComputedStyles()
530
ServoStyleSet::RecomputeDefaultComputedStyles()
531
{
531
{
532
  Servo_StyleSet_RecomputeDefaultStyles(mRawSet.get(), mPresContext);
532
  Servo_StyleSet_RecomputeDefaultStyles(mRawSet.get(), mPresContext);
533
}
533
}
534
535
ServoComputedValuesStrong
536
ServoStyleSet::RestyleWithAddedDeclaration(RawServoDeclarationBlock* aDeclarations,
537
                                           const ServoComputedValues* aPreviousStyle)
538
{
539
  return Servo_RestyleWithAddedDeclaration(mRawSet.get(), aDeclarations,
540
                                           aPreviousStyle);
541
}
542
(-)a/layout/style/ServoStyleSet.h (+6 lines)
Line     Link Here 
 Lines 156-171   public: Link Here 
156
#endif
156
#endif
157
157
158
  /**
158
  /**
159
   * Recompute our default computed styles.  This will eagerly create a new set
159
   * Recompute our default computed styles.  This will eagerly create a new set
160
   * of default computed style structs.
160
   * of default computed style structs.
161
   */
161
   */
162
  void RecomputeDefaultComputedStyles();
162
  void RecomputeDefaultComputedStyles();
163
163
164
  /**
165
   * Restyle with added declaration, for use in animations.
166
   */
167
  ServoComputedValuesStrong RestyleWithAddedDeclaration(
168
    RawServoDeclarationBlock* aDeclarations,
169
    const ServoComputedValues* aPreviousStyle);
164
private:
170
private:
165
  already_AddRefed<nsStyleContext> GetContext(already_AddRefed<ServoComputedValues>,
171
  already_AddRefed<nsStyleContext> GetContext(already_AddRefed<ServoComputedValues>,
166
                                              nsStyleContext* aParentContext,
172
                                              nsStyleContext* aParentContext,
167
                                              nsIAtom* aPseudoTag,
173
                                              nsIAtom* aPseudoTag,
168
                                              CSSPseudoElementType aPseudoType);
174
                                              CSSPseudoElementType aPseudoType);
169
175
170
  already_AddRefed<nsStyleContext> GetContext(nsIContent* aContent,
176
  already_AddRefed<nsStyleContext> GetContext(nsIContent* aContent,
171
                                              nsStyleContext* aParentContext,
177
                                              nsStyleContext* aParentContext,
(-)a/layout/style/StyleAnimationValue.cpp (-1 / +2 lines)
Line     Link Here 
 Lines 3668-3684   StyleAnimationValue::ComputeValues( Link Here 
3668
3668
3669
  const ServoComputedValues* previousStyle =
3669
  const ServoComputedValues* previousStyle =
3670
    aStyleContext->StyleSource().AsServoComputedValues();
3670
    aStyleContext->StyleSource().AsServoComputedValues();
3671
3671
3672
  // FIXME: Servo bindings don't yet represent const-ness so we just
3672
  // FIXME: Servo bindings don't yet represent const-ness so we just
3673
  // cast it away for now.
3673
  // cast it away for now.
3674
  auto declarations = const_cast<RawServoDeclarationBlock*>(&aDeclarations);
3674
  auto declarations = const_cast<RawServoDeclarationBlock*>(&aDeclarations);
3675
  RefPtr<ServoComputedValues> computedValues =
3675
  RefPtr<ServoComputedValues> computedValues =
3676
    Servo_RestyleWithAddedDeclaration(declarations, previousStyle).Consume();
3676
    aStyleContext->PresContext()->StyleSet()->AsServo()->
3677
      RestyleWithAddedDeclaration(declarations, previousStyle).Consume();
3677
  if (!computedValues) {
3678
  if (!computedValues) {
3678
    return false;
3679
    return false;
3679
  }
3680
  }
3680
3681
3681
  RefPtr<nsStyleContext> tmpStyleContext =
3682
  RefPtr<nsStyleContext> tmpStyleContext =
3682
    NS_NewStyleContext(aStyleContext, aStyleContext->PresContext(),
3683
    NS_NewStyleContext(aStyleContext, aStyleContext->PresContext(),
3683
                       aStyleContext->GetPseudo(),
3684
                       aStyleContext->GetPseudo(),
3684
                       aStyleContext->GetPseudoType(),
3685
                       aStyleContext->GetPseudoType(),
(-)a/servo/components/style/animation.rs (+1 lines)
Line     Link Here 
 Lines 414-429   fn compute_style_for_animation_step(cont Link Here 
414
                guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl)
414
                guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl)
415
            };
415
            };
416
416
417
            let computed =
417
            let computed =
418
                properties::apply_declarations(context.viewport_size,
418
                properties::apply_declarations(context.viewport_size,
419
                                               /* is_root = */ false,
419
                                               /* is_root = */ false,
420
                                               iter,
420
                                               iter,
421
                                               previous_style,
421
                                               previous_style,
422
                                               &context.default_computed_values,
422
                                               /* cascade_info = */ None,
423
                                               /* cascade_info = */ None,
423
                                               context.error_reporter.clone(),
424
                                               context.error_reporter.clone(),
424
                                               /* Metrics provider */ None,
425
                                               /* Metrics provider */ None,
425
                                               CascadeFlags::empty());
426
                                               CascadeFlags::empty());
426
            computed
427
            computed
427
        }
428
        }
428
    }
429
    }
429
}
430
}
(-)a/servo/components/style/gecko_bindings/bindings.rs (-1 / +2 lines)
Line     Link Here 
 Lines 1202-1218   extern "C" { Link Here 
1202
                               value: *const nsACString_internal,
1202
                               value: *const nsACString_internal,
1203
                               base_url: *const nsACString_internal,
1203
                               base_url: *const nsACString_internal,
1204
                               base: *mut ThreadSafeURIHolder,
1204
                               base: *mut ThreadSafeURIHolder,
1205
                               referrer: *mut ThreadSafeURIHolder,
1205
                               referrer: *mut ThreadSafeURIHolder,
1206
                               principal: *mut ThreadSafePrincipalHolder)
1206
                               principal: *mut ThreadSafePrincipalHolder)
1207
     -> RawServoDeclarationBlockStrong;
1207
     -> RawServoDeclarationBlockStrong;
1208
}
1208
}
1209
extern "C" {
1209
extern "C" {
1210
    pub fn Servo_RestyleWithAddedDeclaration(declarations:
1210
    pub fn Servo_RestyleWithAddedDeclaration(set: RawServoStyleSetBorrowed,
1211
                                             declarations:
1211
                                                 RawServoDeclarationBlockBorrowed,
1212
                                                 RawServoDeclarationBlockBorrowed,
1212
                                             previous_style:
1213
                                             previous_style:
1213
                                                 ServoComputedValuesBorrowed)
1214
                                                 ServoComputedValuesBorrowed)
1214
     -> ServoComputedValuesStrong;
1215
     -> ServoComputedValuesStrong;
1215
}
1216
}
1216
extern "C" {
1217
extern "C" {
1217
    pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
1218
    pub fn Servo_ParseStyleAttribute(data: *const nsACString_internal)
1218
     -> RawServoDeclarationBlockStrong;
1219
     -> RawServoDeclarationBlockStrong;
(-)a/servo/components/style/properties/properties.mako.rs (-3 / +3 lines)
Line     Link Here 
 Lines 1555-1582   pub fn cascade(viewport_size: Size2D<Au> Link Here 
1555
                }
1555
                }
1556
            })
1556
            })
1557
        })
1557
        })
1558
    };
1558
    };
1559
    apply_declarations(viewport_size,
1559
    apply_declarations(viewport_size,
1560
                       is_root_element,
1560
                       is_root_element,
1561
                       iter_declarations,
1561
                       iter_declarations,
1562
                       inherited_style,
1562
                       inherited_style,
1563
                       default_style,
1563
                       cascade_info,
1564
                       cascade_info,
1564
                       error_reporter,
1565
                       error_reporter,
1565
                       None,
1566
                       None,
1566
                       flags)
1567
                       flags)
1567
}
1568
}
1568
1569
1569
/// NOTE: This function expects the declaration with more priority to appear
1570
/// NOTE: This function expects the declaration with more priority to appear
1570
/// first.
1571
/// first.
1571
pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>,
1572
pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>,
1572
                                    is_root_element: bool,
1573
                                    is_root_element: bool,
1573
                                    iter_declarations: F,
1574
                                    iter_declarations: F,
1574
                                    inherited_style: &ComputedValues,
1575
                                    inherited_style: &ComputedValues,
1576
                                    default_style: &Arc<ComputedValues>,
1575
                                    mut cascade_info: Option<<&mut CascadeInfo>,
1577
                                    mut cascade_info: Option<<&mut CascadeInfo>,
1576
                                    mut error_reporter: StdBox<ParseErrorReporter + Send>,
1578
                                    mut error_reporter: StdBox<ParseErrorReporter + Send>,
1577
                                    font_metrics_provider: Option<<&FontMetricsProvider>,
1579
                                    font_metrics_provider: Option<<&FontMetricsProvider>,
1578
                                    flags: CascadeFlags)
1580
                                    flags: CascadeFlags)
1579
                                    -> ComputedValues
1581
                                    -> ComputedValues
1580
    where F: Fn() -> I, I: Iterator<Item = &'a PropertyDeclaration>
1582
    where F: Fn() -> I, I: Iterator<Item = &'a PropertyDeclaration>
1581
{
1583
{
1582
    let inherited_custom_properties = inherited_style.custom_properties();
1584
    let inherited_custom_properties = inherited_style.custom_properties();
 Lines 1592-1619   pub fn apply_declarations<'a, F, I>(view Link Here 
1592
            _ => {}
1594
            _ => {}
1593
        }
1595
        }
1594
    }
1596
    }
1595
1597
1596
    let custom_properties =
1598
    let custom_properties =
1597
        ::custom_properties::finish_cascade(
1599
        ::custom_properties::finish_cascade(
1598
            custom_properties, &inherited_custom_properties);
1600
            custom_properties, &inherited_custom_properties);
1599
1601
1600
    let initial_values = ComputedValues::initial_values();
1601
1602
    let starting_style = if !flags.contains(INHERIT_ALL) {
1602
    let starting_style = if !flags.contains(INHERIT_ALL) {
1603
        ComputedValues::new(custom_properties,
1603
        ComputedValues::new(custom_properties,
1604
                            flags.contains(SHAREABLE),
1604
                            flags.contains(SHAREABLE),
1605
                            WritingMode::empty(),
1605
                            WritingMode::empty(),
1606
                            inherited_style.root_font_size(),
1606
                            inherited_style.root_font_size(),
1607
                            % for style_struct in data.active_style_structs():
1607
                            % for style_struct in data.active_style_structs():
1608
                                % if style_struct.inherited:
1608
                                % if style_struct.inherited:
1609
                                    inherited_style.clone_${style_struct.name_lower}(),
1609
                                    inherited_style.clone_${style_struct.name_lower}(),
1610
                                % else:
1610
                                % else:
1611
                                    initial_values.clone_${style_struct.name_lower}(),
1611
                                    default_style.clone_${style_struct.name_lower}(),
1612
                                % endif
1612
                                % endif
1613
                            % endfor
1613
                            % endfor
1614
                            )
1614
                            )
1615
    } else {
1615
    } else {
1616
        ComputedValues::new(custom_properties,
1616
        ComputedValues::new(custom_properties,
1617
                            flags.contains(SHAREABLE),
1617
                            flags.contains(SHAREABLE),
1618
                            WritingMode::empty(),
1618
                            WritingMode::empty(),
1619
                            inherited_style.root_font_size(),
1619
                            inherited_style.root_font_size(),
(-)a/servo/ports/geckolib/glue.rs (-1 / +5 lines)
Line     Link Here 
 Lines 161-194   pub extern "C" fn Servo_TraverseSubtree( Link Here 
161
                                        behavior: structs::TraversalRootBehavior) -> () {
161
                                        behavior: structs::TraversalRootBehavior) -> () {
162
    let element = GeckoElement(root);
162
    let element = GeckoElement(root);
163
    debug!("Servo_TraverseSubtree: {:?}", element);
163
    debug!("Servo_TraverseSubtree: {:?}", element);
164
    traverse_subtree(element, raw_data,
164
    traverse_subtree(element, raw_data,
165
                     behavior == structs::TraversalRootBehavior::UnstyledChildrenOnly);
165
                     behavior == structs::TraversalRootBehavior::UnstyledChildrenOnly);
166
}
166
}
167
167
168
#[no_mangle]
168
#[no_mangle]
169
pub extern "C" fn Servo_RestyleWithAddedDeclaration(declarations: RawServoDeclarationBlockBorrowed,
169
pub extern "C" fn Servo_RestyleWithAddedDeclaration(raw_data: RawServoStyleSetBorrowed,
170
                                                    declarations: RawServoDeclarationBlockBorrowed,
170
                                                    previous_style: ServoComputedValuesBorrowed)
171
                                                    previous_style: ServoComputedValuesBorrowed)
171
  -> ServoComputedValuesStrong
172
  -> ServoComputedValuesStrong
172
{
173
{
173
    let previous_style = ComputedValues::as_arc(&previous_style);
174
    let previous_style = ComputedValues::as_arc(&previous_style);
174
    let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
175
    let declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations);
175
176
176
    let guard = declarations.read();
177
    let guard = declarations.read();
177
178
178
    let declarations = || {
179
    let declarations = || {
179
        guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl)
180
        guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl)
180
    };
181
    };
181
182
183
    let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
184
182
    // FIXME (bug 1303229): Use the actual viewport size here
185
    // FIXME (bug 1303229): Use the actual viewport size here
183
    let computed = apply_declarations(Size2D::new(Au(0), Au(0)),
186
    let computed = apply_declarations(Size2D::new(Au(0), Au(0)),
184
                                      /* is_root_element = */ false,
187
                                      /* is_root_element = */ false,
185
                                      declarations,
188
                                      declarations,
186
                                      previous_style,
189
                                      previous_style,
190
                                      &data.default_computed_values,
187
                                      None,
191
                                      None,
188
                                      Box::new(StdoutErrorReporter),
192
                                      Box::new(StdoutErrorReporter),
189
                                      None,
193
                                      None,
190
                                      CascadeFlags::empty());
194
                                      CascadeFlags::empty());
191
    Arc::new(computed).into_strong()
195
    Arc::new(computed).into_strong()
192
}
196
}
193
197
194
#[no_mangle]
198
#[no_mangle]

Return to bug 1298588