Bug 1364799 - Add PostRestyleEventForCSSRuleChanges to distinguish PostRestyleEvent. r?birtles
The difference is that PostRestyleEventForCSSRuleChanges sets
mRestyleForCSSRuleChanges true. In a subsequent patch,
we propagate a new TraversalRestyleBehavior flag to servo side
if mRestyleForCSSRuleChanges is true.
MozReview-Commit-ID: IKsBbm09uT9
--- a/layout/base/GeckoRestyleManager.h
+++ b/layout/base/GeckoRestyleManager.h
@@ -268,16 +268,22 @@ public:
* descendants.
* @param aRestyleHintData: Additional data to go with aRestyleHint.
*/
void PostRestyleEvent(Element* aElement,
nsRestyleHint aRestyleHint,
nsChangeHint aMinChangeHint,
const RestyleHintData* aRestyleHintData = nullptr);
+ void PostRestyleEventForCSSRuleChanges(Element* aElement,
+ nsRestyleHint aRestyleHint,
+ nsChangeHint aMinChangeHint) {
+ PostRestyleEvent(aElement, aRestyleHint, aMinChangeHint);
+ }
+
public:
/**
* Asynchronously clear style data from the root frame downwards and ensure
* it will all be rebuilt. This is safe to call anytime; it will schedule
* a restyle and take effect next time style changes are flushed.
* This method is used to recompute the style data when some change happens
* outside of any style rules, like a color preference change or a change
* in a system font size, or to fix things up when an optimization in the
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -4579,22 +4579,24 @@ nsIPresShell::RestyleForCSSRuleChanges()
}
RestyleManager* restyleManager = mPresContext->RestyleManager();
if (scopeRoots.IsEmpty()) {
// If scopeRoots is empty, we know that mStylesHaveChanged was true at
// the beginning of this function, and that we need to restyle the whole
// document.
- restyleManager->PostRestyleEvent(root, eRestyle_Subtree,
- nsChangeHint(0));
+ restyleManager->PostRestyleEventForCSSRuleChanges(root,
+ eRestyle_Subtree,
+ nsChangeHint(0));
} else {
for (Element* scopeRoot : scopeRoots) {
- restyleManager->PostRestyleEvent(scopeRoot, eRestyle_Subtree,
- nsChangeHint(0));
+ restyleManager->PostRestyleEventForCSSRuleChanges(scopeRoot,
+ eRestyle_Subtree,
+ nsChangeHint(0));
}
}
}
void
PresShell::RecordStyleSheetChange(StyleSheet* aStyleSheet)
{
// too bad we can't check that the update is UPDATE_STYLE
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -156,16 +156,19 @@ public:
// the container is null, no work is needed.
void RestyleForAppend(nsIContent* aContainer, nsIContent* aFirstNewContent);
MOZ_DECL_STYLO_METHODS(GeckoRestyleManager, ServoRestyleManager)
inline void PostRestyleEvent(dom::Element* aElement,
nsRestyleHint aRestyleHint,
nsChangeHint aMinChangeHint);
+ inline void PostRestyleEventForCSSRuleChanges(dom::Element* aElement,
+ nsRestyleHint aRestyleHint,
+ nsChangeHint aMinChangeHint);
inline void RebuildAllStyleData(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint);
inline void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint);
inline void ProcessPendingRestyles();
inline void ContentStateChanged(nsIContent* aContent,
EventStates aStateMask);
inline void AttributeWillChange(dom::Element* aElement,
--- a/layout/base/RestyleManagerInlines.h
+++ b/layout/base/RestyleManagerInlines.h
@@ -20,16 +20,25 @@ void
RestyleManager::PostRestyleEvent(dom::Element* aElement,
nsRestyleHint aRestyleHint,
nsChangeHint aMinChangeHint)
{
MOZ_STYLO_FORWARD(PostRestyleEvent, (aElement, aRestyleHint, aMinChangeHint));
}
void
+RestyleManager::PostRestyleEventForCSSRuleChanges(dom::Element* aElement,
+ nsRestyleHint aRestyleHint,
+ nsChangeHint aMinChangeHint)
+{
+ MOZ_STYLO_FORWARD(PostRestyleEventForCSSRuleChanges,
+ (aElement, aRestyleHint, aMinChangeHint));
+}
+
+void
RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint)
{
MOZ_STYLO_FORWARD(RebuildAllStyleData, (aExtraHint, aRestyleHint));
}
void
RestyleManager::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -61,16 +61,27 @@ ServoRestyleManager::PostRestyleEvent(El
if (aRestyleHint & ~eRestyle_AllHintsWithAnimations) {
mHaveNonAnimationRestyles = true;
}
Servo_NoteExplicitHints(aElement, aRestyleHint, aMinChangeHint);
}
+void
+ServoRestyleManager::PostRestyleEventForCSSRuleChanges(
+ Element* aElement,
+ nsRestyleHint aRestyleHint,
+ nsChangeHint aMinChangeHint)
+{
+ mRestyleForCSSRuleChanges = true;
+
+ PostRestyleEvent(aElement, aRestyleHint, aMinChangeHint);
+}
+
/* static */ void
ServoRestyleManager::PostRestyleEventForAnimations(Element* aElement,
nsRestyleHint aRestyleHint)
{
Servo_NoteExplicitHints(aElement, aRestyleHint, nsChangeHint(0));
}
void
@@ -590,16 +601,17 @@ ServoRestyleManager::DoProcessPendingRes
FlushOverflowChangedTracker();
if (!animationOnly) {
ClearSnapshots();
styleSet->AssertTreeIsClean();
mHaveNonAnimationRestyles = false;
}
+ mRestyleForCSSRuleChanges = false;
mInStyleRefresh = false;
// Note: We are in the scope of |animationsWithDestroyedFrame|, so
// |mAnimationsWithDestroyedFrame| is still valid.
MOZ_ASSERT(mAnimationsWithDestroyedFrame);
mAnimationsWithDestroyedFrame->StopAnimationsForElementsWithoutFrames();
}
--- a/layout/base/ServoRestyleManager.h
+++ b/layout/base/ServoRestyleManager.h
@@ -39,16 +39,19 @@ public:
typedef RestyleManager base_type;
explicit ServoRestyleManager(nsPresContext* aPresContext);
void PostRestyleEvent(dom::Element* aElement,
nsRestyleHint aRestyleHint,
nsChangeHint aMinChangeHint);
void PostRestyleEventForLazyConstruction();
+ void PostRestyleEventForCSSRuleChanges(dom::Element* aElement,
+ nsRestyleHint aRestyleHint,
+ nsChangeHint aMinChangeHint);
void RebuildAllStyleData(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint);
void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint);
void ProcessPendingRestyles();
void UpdateOnlyAnimationStyles();
@@ -157,16 +160,24 @@ private:
// We use this flag to track if the current restyle contains any non-animation
// update, which triggers a normal restyle, and so there might be any new
// transition created later. Therefore, if this flag is true, we need to
// increase mAnimationGeneration before creating new transitions, so their
// creation sequence will be correct.
bool mHaveNonAnimationRestyles = false;
+ // Set to true when posting restyle events triggered by CSS rule changes.
+ // This flag is cleared once ProcessPendingRestyles has completed.
+ // When we process a traversal all descendants elements of the document
+ // triggered by CSS rule changes, we will need to update all elements with
+ // CSS animations. We propagate TraversalRestyleBehavior::ForCSSRuleChanges
+ // to traversal function if this flag is set.
+ bool mRestyleForCSSRuleChanges = false;
+
// A hashtable with the elements that have changed state or attributes, in
// order to calculate restyle hints during the traversal.
SnapshotTable mSnapshots;
};
} // namespace mozilla
#endif // mozilla_ServoRestyleManager_h