Bug 1357461: Cache effective media query results.
And implement a function that returns whether they changed, to be shared with
Servo.
MozReview-Commit-ID: 8gnAdJaEfZC
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -2065,28 +2065,18 @@ nsPresContext::MediaFeatureValuesChanged
void
nsPresContext::MediaFeatureValuesChanged(nsRestyleHint aRestyleHint,
nsChangeHint aChangeHint)
{
mPendingMediaFeatureValuesChanged = false;
// MediumFeaturesChanged updates the applied rules, so it always gets called.
- if (mShell) {
- // XXXheycam ServoStyleSets don't support responding to medium
- // changes yet.
- if (mShell->StyleSet()->IsGecko()) {
- if (mShell->StyleSet()->AsGecko()->MediumFeaturesChanged()) {
- aRestyleHint |= eRestyle_Subtree;
- }
- } else {
- NS_WARNING("stylo: ServoStyleSets don't support responding to medium "
- "changes yet. See bug 1290228.");
- aRestyleHint |= eRestyle_Subtree;
- }
+ if (mShell && mShell->StyleSet()->MediumFeaturesChanged()) {
+ aRestyleHint |= eRestyle_Subtree;
}
if (mUsesViewportUnits && mPendingViewportChange) {
// Rebuild all style data without rerunning selector matching.
//
// TODO(emilio, bug 1328652): We don't set mUsesViewportUnits in stylo yet.
// This is wallpapered given we assume medium feature changes
// unconditionally, but we need to fix this.
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -49,16 +49,18 @@ SERVO_BINDING_FUNC(Servo_StyleSheet_Clon
RawServoStyleSheetBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSheet_SizeOfIncludingThis, size_t,
mozilla::MallocSizeOf malloc_size_of, RawServoStyleSheetBorrowed sheet)
SERVO_BINDING_FUNC(Servo_StyleSet_Init, RawServoStyleSetOwned, RawGeckoPresContextOwned pres_context)
SERVO_BINDING_FUNC(Servo_StyleSet_Clear, void,
RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_StyleSet_RebuildData, void,
RawServoStyleSetBorrowed set)
+SERVO_BINDING_FUNC(Servo_StyleSet_MediumFeaturesChanged, bool,
+ RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_StyleSet_Drop, void, RawServoStyleSetOwned set)
SERVO_BINDING_FUNC(Servo_StyleSet_AppendStyleSheet, void,
RawServoStyleSetBorrowed set,
RawServoStyleSheetBorrowed sheet,
uint64_t unique_id)
SERVO_BINDING_FUNC(Servo_StyleSet_PrependStyleSheet, void,
RawServoStyleSetBorrowed set,
RawServoStyleSheetBorrowed sheet,
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -128,16 +128,22 @@ ServoStyleSet::Shutdown()
void
ServoStyleSet::InvalidateStyleForCSSRuleChanges()
{
MOZ_ASSERT(StylistNeedsUpdate());
mPresContext->RestyleManager()->AsServo()->PostRestyleEventForCSSRuleChanges();
}
+bool
+ServoStyleSet::MediumFeaturesChanged() const
+{
+ return Servo_StyleSet_MediumFeaturesChanged(mRawSet.get());
+}
+
size_t
ServoStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:
// - mRawSet
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -132,16 +132,18 @@ public:
ForceAllStyleDirty();
}
bool StyleSheetsHaveChanged() const
{
return StylistNeedsUpdate();
}
+ bool MediumFeaturesChanged() const;
+
void InvalidateStyleForCSSRuleChanges();
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
const RawServoStyleSet& RawSet() const { return *mRawSet; }
bool GetAuthorStyleDisabled() const;
nsresult SetAuthorStyleDisabled(bool aStyleDisabled);
--- a/layout/style/StyleSetHandle.h
+++ b/layout/style/StyleSetHandle.h
@@ -153,16 +153,17 @@ public:
inline int32_t SheetCount(SheetType aType) const;
inline StyleSheet* StyleSheetAt(SheetType aType, int32_t aIndex) const;
inline nsresult RemoveDocStyleSheet(StyleSheet* aSheet);
inline nsresult AddDocStyleSheet(StyleSheet* aSheet, nsIDocument* aDocument);
inline void RecordStyleSheetChange(StyleSheet* aSheet, StyleSheet::ChangeType);
inline void RecordShadowStyleChange(mozilla::dom::ShadowRoot* aShadowRoot);
inline bool StyleSheetsHaveChanged() const;
inline void InvalidateStyleForCSSRuleChanges();
+ inline bool MediumFeaturesChanged();
inline already_AddRefed<nsStyleContext>
ProbePseudoElementStyle(dom::Element* aParentElement,
mozilla::CSSPseudoElementType aType,
nsStyleContext* aParentContext);
inline already_AddRefed<nsStyleContext>
ProbePseudoElementStyle(dom::Element* aParentElement,
mozilla::CSSPseudoElementType aType,
nsStyleContext* aParentContext,
--- a/layout/style/StyleSetHandleInlines.h
+++ b/layout/style/StyleSetHandleInlines.h
@@ -234,17 +234,21 @@ StyleSetHandle::Ptr::RecordShadowStyleCh
FORWARD(RecordShadowStyleChange, (aShadowRoot));
}
bool
StyleSetHandle::Ptr::StyleSheetsHaveChanged() const
{
FORWARD(StyleSheetsHaveChanged, ());
}
-
+bool
+StyleSetHandle::Ptr::MediumFeaturesChanged()
+{
+ FORWARD(MediumFeaturesChanged, ());
+}
void
StyleSetHandle::Ptr::InvalidateStyleForCSSRuleChanges()
{
FORWARD(InvalidateStyleForCSSRuleChanges, ());
}
// check whether there is ::before/::after style for an element
already_AddRefed<nsStyleContext>