From 65da2cda4282682026f1c61b0da1eb21db58b700 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Sat, 12 Sep 2015 19:08:10 +1000 Subject: [PATCH] Bug 1202512 - Part 1: Add Element flags to record whether an eRestyle_SomeDescendants restyle is pending for it. r=bzbarsky --- dom/base/Element.h | 25 +++++++++++++++++-------- layout/base/RestyleManager.cpp | 3 ++- layout/base/RestyleTracker.cpp | 3 ++- layout/base/RestyleTracker.h | 26 ++++++++++++++++++++------ 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/dom/base/Element.h b/dom/base/Element.h index 69768f7eb59..7a9624d5801 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -89,18 +89,27 @@ enum { // change will attempt to restyle descendants). ELEMENT_IS_POTENTIAL_ANIMATION_ONLY_RESTYLE_ROOT = ELEMENT_FLAG_BIT(3), - // All of those bits together, for convenience. - ELEMENT_ALL_RESTYLE_FLAGS = ELEMENT_HAS_PENDING_RESTYLE | - ELEMENT_IS_POTENTIAL_RESTYLE_ROOT | - ELEMENT_HAS_PENDING_ANIMATION_ONLY_RESTYLE | - ELEMENT_IS_POTENTIAL_ANIMATION_ONLY_RESTYLE_ROOT, + // Set if this element has a pending restyle with an eRestyle_SomeDescendants + // restyle hint. + ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR = ELEMENT_FLAG_BIT(4), // Just the HAS_PENDING bits, for convenience - ELEMENT_PENDING_RESTYLE_FLAGS = ELEMENT_HAS_PENDING_RESTYLE | - ELEMENT_HAS_PENDING_ANIMATION_ONLY_RESTYLE, + ELEMENT_PENDING_RESTYLE_FLAGS = + ELEMENT_HAS_PENDING_RESTYLE | + ELEMENT_HAS_PENDING_ANIMATION_ONLY_RESTYLE, + + // Just the IS_POTENTIAL bits, for convenience + ELEMENT_POTENTIAL_RESTYLE_ROOT_FLAGS = + ELEMENT_IS_POTENTIAL_RESTYLE_ROOT | + ELEMENT_IS_POTENTIAL_ANIMATION_ONLY_RESTYLE_ROOT, + + // All of the restyle bits together, for convenience. + ELEMENT_ALL_RESTYLE_FLAGS = ELEMENT_PENDING_RESTYLE_FLAGS | + ELEMENT_POTENTIAL_RESTYLE_ROOT_FLAGS | + ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR, // Remaining bits are for subclasses - ELEMENT_TYPE_SPECIFIC_BITS_OFFSET = NODE_TYPE_SPECIFIC_BITS_OFFSET + 4 + ELEMENT_TYPE_SPECIFIC_BITS_OFFSET = NODE_TYPE_SPECIFIC_BITS_OFFSET + 5 }; #undef ELEMENT_FLAG_BIT diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 50af56133e1..c94540ed1cd 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -91,7 +91,8 @@ RestyleManager::RestyleManager(nsPresContext* aPresContext) , mAnimationGeneration(0) , mReframingStyleContexts(nullptr) , mPendingRestyles(ELEMENT_HAS_PENDING_RESTYLE | - ELEMENT_IS_POTENTIAL_RESTYLE_ROOT) + ELEMENT_IS_POTENTIAL_RESTYLE_ROOT | + ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR) #ifdef DEBUG , mIsProcessingRestyles(false) #endif diff --git a/layout/base/RestyleTracker.cpp b/layout/base/RestyleTracker.cpp index e668eedfb68..397b48f8e9c 100644 --- a/layout/base/RestyleTracker.cpp +++ b/layout/base/RestyleTracker.cpp @@ -138,7 +138,8 @@ CollectRestyles(nsISupports* aElement, // Unset the restyle bits now, so if they get readded later as we // process we won't clobber that adding of the bit. element->UnsetFlags(collector->tracker->RestyleBit() | - collector->tracker->RootBit()); + collector->tracker->RootBit() | + collector->tracker->ConditionalDescendantsBit()); RestyleEnumerateData** restyleArrayPtr = collector->restyleArrayPtr; RestyleEnumerateData* currentRestyle = *restyleArrayPtr; diff --git a/layout/base/RestyleTracker.h b/layout/base/RestyleTracker.h index fa8805d9a01..bb7bcd2bdce 100644 --- a/layout/base/RestyleTracker.h +++ b/layout/base/RestyleTracker.h @@ -240,10 +240,10 @@ public: NS_PRECONDITION((mRestyleBits & ELEMENT_PENDING_RESTYLE_FLAGS) != ELEMENT_PENDING_RESTYLE_FLAGS, "Shouldn't have both restyle flags set"); - NS_PRECONDITION((mRestyleBits & ~ELEMENT_PENDING_RESTYLE_FLAGS) != 0, + NS_PRECONDITION((mRestyleBits & ELEMENT_POTENTIAL_RESTYLE_ROOT_FLAGS) != 0, "Must have root flag"); - NS_PRECONDITION((mRestyleBits & ~ELEMENT_PENDING_RESTYLE_FLAGS) != - (ELEMENT_ALL_RESTYLE_FLAGS & ~ELEMENT_PENDING_RESTYLE_FLAGS), + NS_PRECONDITION((mRestyleBits & ELEMENT_POTENTIAL_RESTYLE_ROOT_FLAGS) != + ELEMENT_POTENTIAL_RESTYLE_ROOT_FLAGS, "Shouldn't have both root flags"); } @@ -284,7 +284,13 @@ public: // Return our ELEMENT_IS_POTENTIAL_(ANIMATION_)RESTYLE_ROOT bit Element::FlagsType RootBit() const { - return mRestyleBits & ~ELEMENT_PENDING_RESTYLE_FLAGS; + return mRestyleBits & ELEMENT_POTENTIAL_RESTYLE_ROOT_FLAGS; + } + + // Return our ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR bit if present, + // or 0 if it is not. + Element::FlagsType ConditionalDescendantsBit() const { + return mRestyleBits & ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR; } struct Hints { @@ -390,8 +396,9 @@ private: typedef nsClassHashtable PendingRestyleTable; typedef nsAutoTArray< nsRefPtr, 32> RestyleRootArray; // Our restyle bits. These will be a subset of ELEMENT_ALL_RESTYLE_FLAGS, and - // will include one flag from ELEMENT_PENDING_RESTYLE_FLAGS and one flag - // that's not in ELEMENT_PENDING_RESTYLE_FLAGS. + // will include one flag from ELEMENT_PENDING_RESTYLE_FLAGS, one flag + // from ELEMENT_POTENTIAL_RESTYLE_ROOT_FLAGS, and might also include + // ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR. Element::FlagsType mRestyleBits; RestyleManager* mRestyleManager; // Owns us // A hashtable that maps elements to pointers to RestyleData structs. The @@ -439,6 +446,13 @@ RestyleTracker::AddPendingRestyleToTable(Element* aElement, existingData = nullptr; } + if (aRestyleHint & eRestyle_SomeDescendants) { + NS_ASSERTION(ConditionalDescendantsBit(), + "why are we getting eRestyle_SomeDescendants in an " + "animation-only restyle?"); + aElement->SetFlags(ConditionalDescendantsBit()); + } + if (!existingData) { RestyleData* rd = new RestyleData(aRestyleHint, aMinChangeHint, aRestyleHintData);