Bug 653131. nsBoxFrame::CreateViewForFrame is only used for menu popups, so simplify it and move it there. r=roc
authorTimothy Nikkel <tnikkel@gmail.com>
Fri, 29 Apr 2011 15:51:05 +0200
changeset 68753 582d7662fd7b471138cdfd3bf4af001cccf5babe
parent 68752 00f6e702f095f89747b671f7991204826069638f
child 68754 fa8be020bfb45130448b0c914301a4c278e2e68a
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs653131
milestone6.0a1
Bug 653131. nsBoxFrame::CreateViewForFrame is only used for menu popups, so simplify it and move it there. r=roc
layout/xul/base/src/nsBoxFrame.cpp
layout/xul/base/src/nsBoxFrame.h
layout/xul/base/src/nsMenuPopupFrame.cpp
layout/xul/base/src/nsMenuPopupFrame.h
--- a/layout/xul/base/src/nsBoxFrame.cpp
+++ b/layout/xul/base/src/nsBoxFrame.cpp
@@ -1837,73 +1837,16 @@ nsBoxFrame::GetFrameSizeWithMargin(nsIBo
   aBox->GetMargin(margin);
   rect.Inflate(margin);
   aSize.width = rect.width;
   aSize.height = rect.height;
   return NS_OK;
 }
 #endif
 
-/**
- * Boxed don't support fixed positionioning of their children.
- * KEEP THIS IN SYNC WITH nsContainerFrame::CreateViewForFrame
- * as much as possible. Until we get rid of views finally...
- */
-nsresult
-nsBoxFrame::CreateViewForFrame(nsPresContext*  aPresContext,
-                               nsIFrame*        aFrame,
-                               nsStyleContext*  aStyleContext,
-                               PRBool           aForce,
-                               PRBool           aIsPopup)
-{
-  NS_ASSERTION(aForce, "We only get called to force view creation now");
-  // If we don't yet have a view, see if we need a view
-  if (!aFrame->HasView()) {
-    nsViewVisibility visibility = nsViewVisibility_kShow;
-    PRInt32 zIndex = 0;
-    PRBool  autoZIndex = PR_FALSE;
-
-    if (aForce) {
-      nsIView* parentView;
-      nsIViewManager* viewManager = aPresContext->GetPresShell()->GetViewManager();
-      NS_ASSERTION(nsnull != viewManager, "null view manager");
-
-      // Create a view
-      if (aIsPopup) {
-        parentView = viewManager->GetRootView();
-        visibility = nsViewVisibility_kHide;
-        zIndex = PR_INT32_MAX;
-      }
-      else {
-        parentView = aFrame->GetParent()->GetClosestView();
-      }
-
-      NS_ASSERTION(parentView, "no parent view");
-
-      // Create a view
-      nsIView *view = viewManager->CreateView(aFrame->GetRect(), parentView, visibility);
-      if (view) {
-        viewManager->SetViewZIndex(view, autoZIndex, zIndex);
-        // XXX put view last in document order until we can do better
-        viewManager->InsertChild(parentView, view, nsnull, PR_TRUE);
-      }
-
-      // Remember our view
-      aFrame->SetView(view);
-
-      NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
-        ("nsBoxFrame::CreateViewForFrame: frame=%p view=%p",
-         aFrame));
-      if (!view)
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
-  }
-  return NS_OK;
-}
-
 // If you make changes to this function, check its counterparts
 // in nsTextBoxFrame and nsXULLabelFrame
 nsresult
 nsBoxFrame::RegUnregAccessKey(PRBool aDoReg)
 {
   // if we have no content, we can't do anything
   if (!mContent)
     return NS_ERROR_FAILURE;
--- a/layout/xul/base/src/nsBoxFrame.h
+++ b/layout/xul/base/src/nsBoxFrame.h
@@ -175,24 +175,16 @@ public:
                        nsDidReflowStatus         aStatus);
 
   virtual PRBool HonorPrintBackgroundSettings();
 
   virtual ~nsBoxFrame();
   
   nsBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, PRBool aIsRoot = PR_FALSE, nsIBoxLayout* aLayoutManager = nsnull);
 
-  // if aIsPopup is true, then the view is for a popup. In this case,
-  // the view is added a child of the root view, and is initially hidden
-  static nsresult CreateViewForFrame(nsPresContext* aPresContext,
-                                     nsIFrame* aChild,
-                                     nsStyleContext* aStyleContext,
-                                     PRBool aForce,
-                                     PRBool aIsPopup = PR_FALSE);
-
   // virtual so nsStackFrame, nsButtonBoxFrame, nsSliderFrame and nsMenuFrame
   // can override it
   NS_IMETHOD BuildDisplayListForChildren(nsDisplayListBuilder*   aBuilder,
                                          const nsRect&           aDirtyRect,
                                          const nsDisplayListSet& aLists);
 
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
--- a/layout/xul/base/src/nsMenuPopupFrame.cpp
+++ b/layout/xul/base/src/nsMenuPopupFrame.cpp
@@ -146,17 +146,17 @@ nsMenuPopupFrame::Init(nsIContent*      
 
   // lookup if we're allowed to overlap the OS bar (menubar/taskbar) from the
   // look&feel object
   PRBool tempBool;
   presContext->LookAndFeel()->
     GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, tempBool);
   mMenuCanOverlapOSBar = tempBool;
 
-  rv = CreateViewForFrame(presContext, this, GetStyleContext(), PR_TRUE, PR_TRUE);
+  rv = CreatePopupViewForFrame();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // XXX Hack. The popup's view should float above all other views,
   // so we use the nsIView::SetFloating() to tell the view manager
   // about that constraint.
   nsIView* ourView = GetView();
   nsIViewManager* viewManager = ourView->GetViewManager();
   viewManager->SetViewFloating(ourView, PR_TRUE);
@@ -1867,8 +1867,54 @@ nsMenuPopupFrame::SetAutoPosition(PRBool
   mShouldAutoPosition = aShouldAutoPosition;
 }
 
 void
 nsMenuPopupFrame::SetConsumeRollupEvent(PRUint32 aConsumeMode)
 {
   mConsumeRollupEvent = aConsumeMode;
 }
+
+/**
+ * KEEP THIS IN SYNC WITH nsContainerFrame::CreateViewForFrame
+ * as much as possible. Until we get rid of views finally...
+ */
+nsresult
+nsMenuPopupFrame::CreatePopupViewForFrame()
+{
+  if (HasView()) {
+    return NS_OK;
+  }
+
+  nsViewVisibility visibility = nsViewVisibility_kShow;
+  PRInt32 zIndex = 0;
+  PRBool  autoZIndex = PR_FALSE;
+
+  nsIView* parentView;
+  nsIViewManager* viewManager = PresContext()->GetPresShell()->GetViewManager();
+  NS_ASSERTION(nsnull != viewManager, "null view manager");
+
+  // Create a view
+  parentView = viewManager->GetRootView();
+  visibility = nsViewVisibility_kHide;
+  zIndex = PR_INT32_MAX;
+
+  NS_ASSERTION(parentView, "no parent view");
+
+  // Create a view
+  nsIView *view = viewManager->CreateView(GetRect(), parentView, visibility);
+  if (view) {
+    viewManager->SetViewZIndex(view, autoZIndex, zIndex);
+    // XXX put view last in document order until we can do better
+    viewManager->InsertChild(parentView, view, nsnull, PR_TRUE);
+  }
+
+  // Remember our view
+  SetView(view);
+
+  NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
+    ("nsMenuPopupFrame::CreatePopupViewForFrame: frame=%p view=%p", this, view));
+
+  if (!view)
+    return NS_ERROR_OUT_OF_MEMORY;
+
+  return NS_OK;
+}
--- a/layout/xul/base/src/nsMenuPopupFrame.h
+++ b/layout/xul/base/src/nsMenuPopupFrame.h
@@ -395,16 +395,20 @@ protected:
    * Return whether the popup direction should be RTL.
    */
   bool IsDirectionRTL() const {
     return mAnchorContent && mAnchorContent->GetPrimaryFrame()
       ? mAnchorContent->GetPrimaryFrame()->GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL
       : GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
   }
 
+  // Create a popup view for this frame. The view is added a child of the root
+  // view, and is initially hidden.
+  nsresult CreatePopupViewForFrame();
+
   nsString     mIncrementalString;  // for incremental typing navigation
 
   // the content that the popup is anchored to, if any, which may be in a
   // different document than the popup.
   nsCOMPtr<nsIContent> mAnchorContent;
 
   // the content that triggered the popup, typically the node where the mouse
   // was clicked. It will be cleared when the popup is hidden.