Bug 1348665 part 1 - Move a few nsView related methods from nsContainerFrame to nsIFrame/nsFrame (idempotent patch). r=dholbert draft
authorMats Palmgren <mats@mozilla.com>
Mon, 20 Mar 2017 22:06:07 +0100
changeset 501714 d0228816ca706e48b8426593b5455bc9582d03a2
parent 501713 fd44b9b13bf906d189d26310896738a1471a6e19
child 501715 ade9e7ab0a54dd00c42b1e18c29a8c739a8925e4
child 501758 61d3e2268df4db2e81193aeab81c679afeb189ce
push id50091
push usermpalmgren@mozilla.com
push dateMon, 20 Mar 2017 21:17:55 +0000
reviewersdholbert
bugs1348665
milestone55.0a1
Bug 1348665 part 1 - Move a few nsView related methods from nsContainerFrame to nsIFrame/nsFrame (idempotent patch). r=dholbert Views are used for PluginFrame which inherits nsFrame, not nsContainerFrame, so it's more appropriate that these methods should live in nsIFrame/nsFrame. MozReview-Commit-ID: 8zxTDneOE4k
layout/base/nsCSSFrameConstructor.cpp
layout/generic/nsContainerFrame.cpp
layout/generic/nsContainerFrame.h
layout/generic/nsFrame.cpp
layout/generic/nsFrame.h
layout/generic/nsIFrame.h
layout/generic/nsSubDocumentFrame.cpp
layout/xul/nsMenuPopupFrame.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -3237,17 +3237,17 @@ nsCSSFrameConstructor::InitializeSelectF
   scrollFrame->Init(aContent, geometricParent, nullptr);
 
   if (!aBuildCombobox) {
     aState.AddChild(scrollFrame, aFrameItems, aContent,
                     aStyleContext, aParentFrame);
   }
 
   if (aBuildCombobox) {
-    nsContainerFrame::CreateViewForFrame(scrollFrame, true);
+    nsFrame::CreateViewForFrame(scrollFrame, true);
   }
 
   BuildScrollFrame(aState, aContent, aStyleContext, scrolledFrame,
                    geometricParent, scrollFrame);
 
   if (aState.mFrameState) {
     // Restore frame state for the scroll frame
     RestoreFrameStateFor(scrollFrame, aState.mFrameState);
@@ -3926,17 +3926,17 @@ nsCSSFrameConstructor::ConstructFrameFro
         display->IsScrollableOverflow()) {
       nsContainerFrame* scrollframe = nullptr;
       BuildScrollFrame(aState, content, styleContext, newFrame,
                        geometricParent, scrollframe);
       frameToAddToList = scrollframe;
     } else {
       InitAndRestoreFrame(aState, content, geometricParent, newFrame);
       // See whether we need to create a view
-      nsContainerFrame::CreateViewForFrame(newFrame, false);
+      nsFrame::CreateViewForFrame(newFrame, false);
       frameToAddToList = newFrame;
     }
 
     // Use frameToAddToList as the primary frame.  In the non-scrollframe case
     // they're equal, but in the scrollframe case newFrame is the scrolled
     // frame, while frameToAddToList is the scrollframe (and should be the
     // primary frame).
     primaryFrame = frameToAddToList;
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -372,102 +372,16 @@ nsContainerFrame::PeekOffsetCharacter(bo
   NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
   // Don't allow the caret to stay in an empty (leaf) container frame.
   return CONTINUE_EMPTY;
 }
 
 /////////////////////////////////////////////////////////////////////////////
 // Helper member functions
 
-static void
-ReparentFrameViewTo(nsIFrame*       aFrame,
-                    nsViewManager* aViewManager,
-                    nsView*        aNewParentView,
-                    nsView*        aOldParentView)
-{
-  if (aFrame->HasView()) {
-#ifdef MOZ_XUL
-    if (aFrame->GetType() == nsGkAtoms::menuPopupFrame) {
-      // This view must be parented by the root view, don't reparent it.
-      return;
-    }
-#endif
-    nsView* view = aFrame->GetView();
-    // Verify that the current parent view is what we think it is
-    //nsView*  parentView;
-    //NS_ASSERTION(parentView == aOldParentView, "unexpected parent view");
-
-    aViewManager->RemoveChild(view);
-    
-    // The view will remember the Z-order and other attributes that have been set on it.
-    nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(aNewParentView, aFrame);
-    aViewManager->InsertChild(aNewParentView, view, insertBefore, insertBefore != nullptr);
-  } else if (aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW) {
-    nsIFrame::ChildListIterator lists(aFrame);
-    for (; !lists.IsDone(); lists.Next()) {
-      // Iterate the child frames, and check each child frame to see if it has
-      // a view
-      nsFrameList::Enumerator childFrames(lists.CurrentList());
-      for (; !childFrames.AtEnd(); childFrames.Next()) {
-        ReparentFrameViewTo(childFrames.get(), aViewManager,
-                            aNewParentView, aOldParentView);
-      }
-    }
-  }
-}
-
-void
-nsContainerFrame::CreateViewForFrame(nsIFrame* aFrame,
-                                     bool aForce)
-{
-  if (aFrame->HasView()) {
-    return;
-  }
-
-  // If we don't yet have a view, see if we need a view
-  if (!aForce && !aFrame->NeedsView()) {
-    // don't need a view
-    return;
-  }
-
-  nsView* parentView = aFrame->GetParent()->GetClosestView();
-  NS_ASSERTION(parentView, "no parent with view");
-
-  nsViewManager* viewManager = parentView->GetViewManager();
-  NS_ASSERTION(viewManager, "null view manager");
-
-  // Create a view
-  nsView* view = viewManager->CreateView(aFrame->GetRect(), parentView);
-
-  SyncFrameViewProperties(aFrame->PresContext(), aFrame, nullptr, view);
-
-  nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, aFrame);
-  // we insert this view 'above' the insertBefore view, unless insertBefore is null,
-  // in which case we want to call with aAbove == false to insert at the beginning
-  // in document order
-  viewManager->InsertChild(parentView, view, insertBefore, insertBefore != nullptr);
-
-  // REVIEW: Don't create a widget for fixed-pos elements anymore.
-  // ComputeRepaintRegionForCopy will calculate the right area to repaint
-  // when we scroll.
-  // Reparent views on any child frames (or their descendants) to this
-  // view. We can just call ReparentFrameViewTo on this frame because
-  // we know this frame has no view, so it will crawl the children. Also,
-  // we know that any descendants with views must have 'parentView' as their
-  // parent view.
-  ReparentFrameViewTo(aFrame, viewManager, view, parentView);
-
-  // Remember our view
-  aFrame->SetView(view);
-
-  NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
-               ("nsContainerFrame::CreateViewForFrame: frame=%p view=%p",
-                aFrame, view));
-}
-
 /**
  * Position the view associated with |aKidFrame|, if there is one. A
  * container frame should call this method after positioning a frame,
  * but before |Reflow|.
  */
 void
 nsContainerFrame::PositionFrameView(nsIFrame* aKidFrame)
 {
@@ -764,64 +678,16 @@ nsContainerFrame::SyncFrameViewAfterRefl
 
   if (0 == (aFlags & NS_FRAME_NO_SIZE_VIEW)) {
     nsViewManager* vm = aView->GetViewManager();
 
     vm->ResizeView(aView, aVisualOverflowArea, true);
   }
 }
 
-void
-nsContainerFrame::SyncFrameViewProperties(nsPresContext*  aPresContext,
-                                          nsIFrame*        aFrame,
-                                          nsStyleContext*  aStyleContext,
-                                          nsView*         aView,
-                                          uint32_t         aFlags)
-{
-  NS_ASSERTION(!aStyleContext || aFrame->StyleContext() == aStyleContext,
-               "Wrong style context for frame?");
-
-  if (!aView) {
-    return;
-  }
-
-  nsViewManager* vm = aView->GetViewManager();
-
-  if (nullptr == aStyleContext) {
-    aStyleContext = aFrame->StyleContext();
-  }
-
-  // Make sure visibility is correct. This only affects nsSubdocumentFrame.
-  if (0 == (aFlags & NS_FRAME_NO_VISIBILITY) &&
-      !aFrame->SupportsVisibilityHidden()) {
-    // See if the view should be hidden or visible
-    vm->SetViewVisibility(aView,
-        aStyleContext->StyleVisibility()->IsVisible()
-            ? nsViewVisibility_kShow : nsViewVisibility_kHide);
-  }
-
-  int32_t zIndex = 0;
-  bool    autoZIndex = false;
-
-  if (aFrame->IsAbsPosContainingBlock()) {
-    // Make sure z-index is correct
-    const nsStylePosition* position = aStyleContext->StylePosition();
-
-    if (position->mZIndex.GetUnit() == eStyleUnit_Integer) {
-      zIndex = position->mZIndex.GetIntValue();
-    } else if (position->mZIndex.GetUnit() == eStyleUnit_Auto) {
-      autoZIndex = true;
-    }
-  } else {
-    autoZIndex = true;
-  }
-
-  vm->SetViewZIndex(aView, autoZIndex, zIndex);
-}
-
 static nscoord GetCoord(const nsStyleCoord& aCoord, nscoord aIfNotCoord)
 {
   if (aCoord.ConvertsToLength()) {
     return nsRuleNode::ComputeCoordPercentCalc(aCoord, 0);
   }
   return aIfNotCoord;
 }
 
--- a/layout/generic/nsContainerFrame.h
+++ b/layout/generic/nsContainerFrame.h
@@ -150,23 +150,16 @@ public:
    * Delete aNextInFlow and its next-in-flows.
    * @param aDeletingEmptyFrames if set, then the reflow for aNextInFlow's
    * content was complete before aNextInFlow, so aNextInFlow and its
    * next-in-flows no longer map any real content.
    */
   virtual void DeleteNextInFlowChild(nsIFrame* aNextInFlow,
                                      bool      aDeletingEmptyFrames);
 
-  /**
-   * Helper method to wrap views around frames. Used by containers
-   * under special circumstances (can be used by leaf frames as well)
-   */
-  static void CreateViewForFrame(nsIFrame* aFrame,
-                                 bool aForce);
-
   // Positions the frame's view based on the frame's origin
   static void PositionFrameView(nsIFrame* aKidFrame);
 
   static nsresult ReparentFrameView(nsIFrame* aChildFrame,
                                     nsIFrame* aOldParentFrame,
                                     nsIFrame* aNewParentFrame);
 
   static nsresult ReparentFrameViewList(const nsFrameList& aChildFrameList,
@@ -193,28 +186,16 @@ public:
     SET_ASYNC = 0x01,
   };
   static void SyncWindowProperties(nsPresContext*       aPresContext,
                                    nsIFrame*            aFrame,
                                    nsView*              aView,
                                    nsRenderingContext*  aRC,
                                    uint32_t             aFlags);
 
-  // Sets the view's attributes from the frame style.
-  // - visibility
-  // - clip
-  // Call this when one of these styles changes or when the view has just
-  // been created.
-  // @param aStyleContext can be null, in which case the frame's style context is used
-  static void SyncFrameViewProperties(nsPresContext*  aPresContext,
-                                      nsIFrame*        aFrame,
-                                      nsStyleContext*  aStyleContext,
-                                      nsView*         aView,
-                                      uint32_t         aFlags = 0);
-
   /**
    * Converts the minimum and maximum sizes given in inner window app units to
    * outer window device pixel sizes and assigns these constraints to the widget.
    *
    * @param aPresContext pres context
    * @param aWidget widget for this frame
    * @param minimum size of the window in app units
    * @param maxmimum size of the window in app units
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -981,16 +981,150 @@ nsFrame::DidSetStyleContext(nsStyleConte
   // context before reflow starts.  See bug 115921.
   if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
     PresContext()->SetBidiEnabled();
   }
 
   RemoveStateBits(NS_FRAME_SIMPLE_EVENT_REGIONS);
 }
 
+void
+nsIFrame::ReparentFrameViewTo(nsIFrame* aFrame,
+                              nsViewManager* aViewManager,
+                              nsView*        aNewParentView,
+                              nsView*        aOldParentView)
+{
+  if (aFrame->HasView()) {
+#ifdef MOZ_XUL
+    if (aFrame->GetType() == nsGkAtoms::menuPopupFrame) {
+      // This view must be parented by the root view, don't reparent it.
+      return;
+    }
+#endif
+    nsView* view = aFrame->GetView();
+    // Verify that the current parent view is what we think it is
+    //nsView*  parentView;
+    //NS_ASSERTION(parentView == aOldParentView, "unexpected parent view");
+
+    aViewManager->RemoveChild(view);
+    
+    // The view will remember the Z-order and other attributes that have been set on it.
+    nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(aNewParentView, aFrame);
+    aViewManager->InsertChild(aNewParentView, view, insertBefore, insertBefore != nullptr);
+  } else if (aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW) {
+    nsIFrame::ChildListIterator lists(aFrame);
+    for (; !lists.IsDone(); lists.Next()) {
+      // Iterate the child frames, and check each child frame to see if it has
+      // a view
+      nsFrameList::Enumerator childFrames(lists.CurrentList());
+      for (; !childFrames.AtEnd(); childFrames.Next()) {
+        ReparentFrameViewTo(childFrames.get(), aViewManager,
+                            aNewParentView, aOldParentView);
+      }
+    }
+  }
+}
+
+void
+nsIFrame::SyncFrameViewProperties(nsPresContext*  aPresContext,
+                                 nsIFrame*        aFrame,
+                                 nsStyleContext*  aStyleContext,
+                                 nsView*          aView,
+                                 uint32_t         aFlags)
+{
+  NS_ASSERTION(!aStyleContext || aFrame->StyleContext() == aStyleContext,
+               "Wrong style context for frame?");
+
+  if (!aView) {
+    return;
+  }
+
+  nsViewManager* vm = aView->GetViewManager();
+
+  if (nullptr == aStyleContext) {
+    aStyleContext = aFrame->StyleContext();
+  }
+
+  // Make sure visibility is correct. This only affects nsSubdocumentFrame.
+  if (0 == (aFlags & NS_FRAME_NO_VISIBILITY) &&
+      !aFrame->SupportsVisibilityHidden()) {
+    // See if the view should be hidden or visible
+    vm->SetViewVisibility(aView,
+        aStyleContext->StyleVisibility()->IsVisible()
+            ? nsViewVisibility_kShow : nsViewVisibility_kHide);
+  }
+
+  int32_t zIndex = 0;
+  bool    autoZIndex = false;
+
+  if (aFrame->IsAbsPosContainingBlock()) {
+    // Make sure z-index is correct
+    const nsStylePosition* position = aStyleContext->StylePosition();
+
+    if (position->mZIndex.GetUnit() == eStyleUnit_Integer) {
+      zIndex = position->mZIndex.GetIntValue();
+    } else if (position->mZIndex.GetUnit() == eStyleUnit_Auto) {
+      autoZIndex = true;
+    }
+  } else {
+    autoZIndex = true;
+  }
+
+  vm->SetViewZIndex(aView, autoZIndex, zIndex);
+}
+
+void
+nsFrame::CreateViewForFrame(nsIFrame* aFrame,
+                            bool aForce)
+{
+  if (aFrame->HasView()) {
+    return;
+  }
+
+  // If we don't yet have a view, see if we need a view
+  if (!aForce && !aFrame->NeedsView()) {
+    // don't need a view
+    return;
+  }
+
+  nsView* parentView = aFrame->GetParent()->GetClosestView();
+  NS_ASSERTION(parentView, "no parent with view");
+
+  nsViewManager* viewManager = parentView->GetViewManager();
+  NS_ASSERTION(viewManager, "null view manager");
+
+  // Create a view
+  nsView* view = viewManager->CreateView(aFrame->GetRect(), parentView);
+
+  SyncFrameViewProperties(aFrame->PresContext(), aFrame, nullptr, view);
+
+  nsView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, aFrame);
+  // we insert this view 'above' the insertBefore view, unless insertBefore is null,
+  // in which case we want to call with aAbove == false to insert at the beginning
+  // in document order
+  viewManager->InsertChild(parentView, view, insertBefore, insertBefore != nullptr);
+
+  // REVIEW: Don't create a widget for fixed-pos elements anymore.
+  // ComputeRepaintRegionForCopy will calculate the right area to repaint
+  // when we scroll.
+  // Reparent views on any child frames (or their descendants) to this
+  // view. We can just call ReparentFrameViewTo on this frame because
+  // we know this frame has no view, so it will crawl the children. Also,
+  // we know that any descendants with views must have 'parentView' as their
+  // parent view.
+  ReparentFrameViewTo(aFrame, viewManager, view, parentView);
+
+  // Remember our view
+  aFrame->SetView(view);
+
+  NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
+               ("nsContainerFrame::CreateViewForFrame: frame=%p view=%p",
+                aFrame, view));
+}
+
 // MSVC fails with link error "one or more multiply defined symbols found",
 // gcc fails with "hidden symbol `nsIFrame::kPrincipalList' isn't defined"
 // etc if they are not defined.
 #ifndef _MSC_VER
 // static nsIFrame constants; initialized in the header file.
 const nsIFrame::ChildListID nsIFrame::kPrincipalList;
 const nsIFrame::ChildListID nsIFrame::kAbsoluteList;
 const nsIFrame::ChildListID nsIFrame::kBulletList;
--- a/layout/generic/nsFrame.h
+++ b/layout/generic/nsFrame.h
@@ -590,16 +590,23 @@ protected:
       nsDisplayList* aList, uint16_t aContentType = nsISelectionDisplay::DISPLAY_FRAMES);
 
   int16_t DisplaySelection(nsPresContext* aPresContext, bool isOkToTurnOn = false);
   
   // Style post processing hook
   void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
 
 public:
+  /**
+   * Helper method to wrap views around frames. Used by containers
+   * under special circumstances (can be used by leaf frames as well)
+   */
+  static void CreateViewForFrame(nsIFrame* aFrame,
+                                 bool aForce);
+
   //given a frame five me the first/last leaf available
   //XXX Robert O'Callahan wants to move these elsewhere
   static void GetLastLeaf(nsPresContext* aPresContext, nsIFrame **aFrame);
   static void GetFirstLeaf(nsPresContext* aPresContext, nsIFrame **aFrame);
 
   // Return the line number of the aFrame, and (optionally) the containing block
   // frame.
   // If aScrollLock is true, don't break outside scrollframes when looking for a
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -2461,16 +2461,28 @@ public:
    */
   nsView* GetClosestView(nsPoint* aOffset = nullptr) const;
 
   /**
    * Find the closest ancestor (excluding |this| !) that has a view
    */
   nsIFrame* GetAncestorWithView() const;
 
+  // Sets the view's attributes from the frame style.
+  // - visibility
+  // - clip
+  // Call this when one of these styles changes or when the view has just
+  // been created.
+  // @param aStyleContext can be null, in which case the frame's style context is used
+  static void SyncFrameViewProperties(nsPresContext*  aPresContext,
+                                      nsIFrame*        aFrame,
+                                      nsStyleContext*  aStyleContext,
+                                      nsView*         aView,
+                                      uint32_t         aFlags = 0);
+
   /**
    * Get the offset between the coordinate systems of |this| and aOther.
    * Adding the return value to a point in the coordinate system of |this|
    * will transform the point to the coordinate system of aOther.
    *
    * aOther must be non-null.
    *
    * This function is fastest when aOther is an ancestor of |this|.
@@ -3611,16 +3623,21 @@ public:
    */
   nscoord ComputeISizeValue(nsRenderingContext* aRenderingContext,
                             nscoord             aContainingBlockISize,
                             nscoord             aContentEdgeToBoxSizing,
                             nscoord             aBoxSizingToMarginEdge,
                             const nsStyleCoord& aCoord,
                             ComputeSizeFlags    aFlags = eDefault);
 protected:
+  static void ReparentFrameViewTo(nsIFrame* aFrame,
+                                  nsViewManager* aViewManager,
+                                  nsView*        aNewParentView,
+                                  nsView*        aOldParentView);
+
   // Members
   nsRect           mRect;
   nsIContent*      mContent;
   nsStyleContext*  mStyleContext;
 private:
   nsContainerFrame* mParent;
   nsIFrame*        mNextSibling;  // doubly-linked list of frames
   nsIFrame*        mPrevSibling;  // Do not touch outside SetNextSibling!
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -125,17 +125,17 @@ nsSubDocumentFrame::Init(nsIContent*    
   // OuterFrame but we wait for the normal view creation path in
   // nsCSSFrameConstructor, then we will lose because the inner view's
   // parent will already have been set to some outer view (e.g., the
   // canvas) when it really needs to have this frame's view as its
   // parent. So, create this frame's view right away, whether we
   // really need it or not, and the inner view will get it as the
   // parent.
   if (!HasView()) {
-    nsContainerFrame::CreateViewForFrame(this, true);
+    nsFrame::CreateViewForFrame(this, true);
   }
   EnsureInnerView();
 
   // Set the primary frame now so that nsDocumentViewer::FindContainerView
   // called from within EndSwapDocShellsForViews below can find it if needed.
   aContent->SetPrimaryFrame(this);
 
   // If we have a detached subdoc's root view on our frame loader, re-insert
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -2431,17 +2431,17 @@ nsMenuPopupFrame::GetAlignmentPosition()
   if (mVFlip) {
     position = POPUPPOSITION_VFLIP(position);
   }
 
   return position;
 }
 
 /**
- * KEEP THIS IN SYNC WITH nsContainerFrame::CreateViewForFrame
+ * KEEP THIS IN SYNC WITH nsFrame::CreateView
  * as much as possible. Until we get rid of views finally...
  */
 void
 nsMenuPopupFrame::CreatePopupView()
 {
   if (HasView()) {
     return;
   }