Bug 1364871: Factor out some code from UpdateStyleOfChildAnonBox into UpdateStyleOfOwnedChildFrame. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 19 May 2017 23:56:02 +0200
changeset 581947 936832cb3366336ba8f1d6facec31fb9c03951b4
parent 581886 1a556bb5975676bd13ca2e01ef11b705a5ba1fc4
child 581948 218b85725b795a50c667c1334e78fbad5f9ef05a
push id59918
push userbmo:emilio+bugs@crisal.io
push dateSat, 20 May 2017 08:21:51 +0000
reviewersheycam
bugs1364871
milestone55.0a1
Bug 1364871: Factor out some code from UpdateStyleOfChildAnonBox into UpdateStyleOfOwnedChildFrame. r?heycam MozReview-Commit-ID: 24U6PmmqCeP
layout/generic/nsFrame.cpp
layout/generic/nsIFrame.h
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -10233,45 +10233,58 @@ nsFrame::UpdateStyleOfChildAnonBox(nsIFr
   MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(pseudo), "Child is not an anon box?");
   MOZ_ASSERT(!nsCSSAnonBoxes::IsNonInheritingAnonBox(pseudo),
              "Why did the caller bother calling us?");
 
   // Anon boxes inherit from their parent; that's us.
   RefPtr<nsStyleContext> newContext =
     aStyleSet.ResolveInheritingAnonymousBoxStyle(pseudo, StyleContext());
 
+  nsChangeHint childHint =
+    UpdateStyleOfOwnedChildFrame(aChildFrame, newContext, aChangeList);
+
+  // Now that we've updated the style on aChildFrame, check whether it itself
+  // has anon boxes to deal with.
+  aChildFrame->UpdateStyleOfOwnedAnonBoxes(aStyleSet, aChangeList, childHint);
+}
+
+nsChangeHint
+nsIFrame::UpdateStyleOfOwnedChildFrame(nsIFrame* aChildFrame,
+                                       nsStyleContext* aNewStyleContext,
+                                       nsStyleChangeList& aChangeList)
+{
   // Figure out whether we have an actual change.  It's important that we do
   // this, for several reasons:
   //
   // 1) Even if all the child's changes are due to properties it inherits from
   //    us, it's possible that no one ever asked us for those style structs and
   //    hence changes to them aren't reflected in aHintForThisFrame at all.
-  // 2) Extensions can add/remove stylesheets that change the styles of
-  //    anonymous boxed directly.
+  //
+  // 2) Content can change stylesheets that change the styles of pseudos, and
+  //    extensions can add/remove stylesheets that change the styles of
+  //    anonymous boxes directly.
   uint32_t equalStructs, samePointerStructs; // Not used, actually.
   nsChangeHint childHint = aChildFrame->StyleContext()->CalcStyleDifference(
-    newContext,
+    aNewStyleContext,
     &equalStructs,
     &samePointerStructs);
   if (childHint) {
     if (childHint & nsChangeHint_ReconstructFrame) {
       // If we generate a reconstruct here, remove any non-reconstruct hints we
       // may have already generated for this content.
       aChangeList.PopChangesForContent(aChildFrame->GetContent());
     }
     aChangeList.AppendChange(aChildFrame, aChildFrame->GetContent(), childHint);
   }
 
   for (nsIFrame* kid = aChildFrame; kid; kid = kid->GetNextContinuation()) {
-    kid->SetStyleContext(newContext);
-  }
-
-  // Now that we've updated the style on aChildFrame, check whether it itself
-  // has anon boxes to deal with.
-  aChildFrame->UpdateStyleOfOwnedAnonBoxes(aStyleSet, aChangeList, childHint);
+    kid->SetStyleContext(aNewStyleContext);
+  }
+
+  return childHint;
 }
 
 /* static */ void
 nsIFrame::AddInPopupStateBitToDescendants(nsIFrame* aFrame)
 {
   if (!aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP) &&
       aFrame->TrackingVisibility()) {
     // Assume all frames in popups are visible.
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -3257,16 +3257,28 @@ public:
   void UpdateStyleOfOwnedAnonBoxes(mozilla::ServoStyleSet& aStyleSet,
                                    nsStyleChangeList& aChangeList,
                                    nsChangeHint aHintForThisFrame) {
     if (GetStateBits() & NS_FRAME_OWNS_ANON_BOXES) {
       DoUpdateStyleOfOwnedAnonBoxes(aStyleSet, aChangeList, aHintForThisFrame);
     }
   }
 
+  // A helper both for UpdateStyleOfChildAnonBox, and to update frame-backed
+  // pseudo-elements in ServoRestyleManager.
+  //
+  // This gets a style context that will be the new style context for
+  // `aChildFrame`, and takes care of updating it, calling CalcStyleDifference,
+  // and adding to the change list as appropriate.
+  //
+  // Returns the generated change hint for the frame.
+  nsChangeHint UpdateStyleOfOwnedChildFrame(nsIFrame* aChildFrame,
+                                            nsStyleContext* aNewStyleContext,
+                                            nsStyleChangeList& aChangeList);
+
   /**
    * Hook subclasses can override to actually implement updating of style of
    * owned anon boxes.
    */
   virtual void DoUpdateStyleOfOwnedAnonBoxes(mozilla::ServoStyleSet& aStyleSet,
                                              nsStyleChangeList& aChangeList,
                                              nsChangeHint aHintForThisFrame);