Bug 1494330 Part 2 - Change nsComboboxControlFrame::mDropdownFrame's type to nsListControlFrame*. r=layout-reviewers,boris
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 07 Jul 2021 03:11:06 +0000
changeset 584930 dd89d3803b2034b0a90c8280be72deea2594efe6
parent 584929 cdae5012ffbdd4609dd7f844afa8ddcbb54d6a37
child 584931 6ff478f9cce9079d913c4f966536b02f704d5f70
push id38589
push userimoraru@mozilla.com
push dateWed, 07 Jul 2021 09:52:09 +0000
treeherdermozilla-central@a2e6beb5031b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslayout-reviewers, boris
bugs1494330
milestone91.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494330 Part 2 - Change nsComboboxControlFrame::mDropdownFrame's type to nsListControlFrame*. r=layout-reviewers,boris This eliminates a lot of down casting from nsIFrame* to nsListControlFrame*. Make SetDropDown() accepts nsListControlFrame* because nsCSSFrameConstructor already passes the derived type in. We'll replace mListControlFrame with mDropdownFrame in the next part. Differential Revision: https://phabricator.services.mozilla.com/D119206
layout/forms/nsComboboxControlFrame.cpp
layout/forms/nsComboboxControlFrame.h
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -510,26 +510,24 @@ class nsAsyncRollup : public Runnable {
 class nsAsyncResize : public Runnable {
  public:
   explicit nsAsyncResize(nsComboboxControlFrame* aFrame)
       : mozilla::Runnable("nsAsyncResize"), mFrame(aFrame) {}
   MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD Run() override {
     if (mFrame.IsAlive()) {
       nsComboboxControlFrame* combo =
           static_cast<nsComboboxControlFrame*>(mFrame.GetFrame());
-      static_cast<nsListControlFrame*>(combo->mDropdownFrame)
-          ->SetSuppressScrollbarUpdate(true);
+      combo->mDropdownFrame->SetSuppressScrollbarUpdate(true);
       RefPtr<PresShell> presShell = mFrame->PresShell();
       presShell->FrameNeedsReflow(combo->mDropdownFrame, IntrinsicDirty::Resize,
                                   NS_FRAME_IS_DIRTY);
       presShell->FlushPendingNotifications(FlushType::Layout);
       if (mFrame.IsAlive()) {
         combo = static_cast<nsComboboxControlFrame*>(mFrame.GetFrame());
-        static_cast<nsListControlFrame*>(combo->mDropdownFrame)
-            ->SetSuppressScrollbarUpdate(false);
+        combo->mDropdownFrame->SetSuppressScrollbarUpdate(false);
         if (combo->mDelayedShowDropDown) {
           combo->ShowDropDown(true);
         }
       }
     }
     return NS_OK;
   }
   WeakFrame mFrame;
@@ -602,18 +600,17 @@ void nsComboboxControlFrame::GetAvailabl
   }
 
   nscoord after = logicalScreen.BEnd(aWM) - mLastDropDownAfterScreenBCoord;
   nscoord before = mLastDropDownBeforeScreenBCoord - minBCoord;
 
   // If the difference between the space before and after is less
   // than a row-block-size, then we favor the space after.
   if (before >= after) {
-    nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
-    nscoord rowBSize = lcf->GetBSizeOfARow();
+    nscoord rowBSize = mDropdownFrame->GetBSizeOfARow();
     if (before < after + rowBSize) {
       before -= rowBSize;
     }
   }
 
   *aAfter = after;
   *aBefore = before;
 }
@@ -636,26 +633,26 @@ nsComboboxControlFrame::AbsolutelyPositi
       view->GetViewManager()->SetViewVisibility(view, nsViewVisibility_kHide);
       NS_DispatchToCurrentThread(new nsAsyncRollup(this));
     }
     return eDropDownPositionSuppressed;
   }
 
   LogicalSize dropdownSize = mDropdownFrame->GetLogicalSize(wm);
   nscoord bSize = std::max(before, after);
-  nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
   if (bSize < dropdownSize.BSize(wm)) {
-    if (lcf->GetNumDisplayRows() > 1) {
+    if (mDropdownFrame->GetNumDisplayRows() > 1) {
       // The drop-down doesn't fit and currently shows more than 1 row -
       // schedule a resize to show fewer rows.
       NS_DispatchToCurrentThread(new nsAsyncResize(this));
       return eDropDownPositionPendingResize;
     }
-  } else if (bSize > (dropdownSize.BSize(wm) + lcf->GetBSizeOfARow() * 1.5) &&
-             lcf->GetDropdownCanGrow()) {
+  } else if (bSize > (dropdownSize.BSize(wm) +
+                      mDropdownFrame->GetBSizeOfARow() * 1.5) &&
+             mDropdownFrame->GetDropdownCanGrow()) {
     // The drop-down fits but there is room for at least 1.5 more rows -
     // schedule a resize to show more rows if it has more rows to show.
     // (1.5 rows for good measure to avoid any rounding issues that would
     // lead to a loop of reflow requests)
     NS_DispatchToCurrentThread(new nsAsyncResize(this));
     return eDropDownPositionPendingResize;
   }
 
@@ -917,17 +914,17 @@ void nsComboboxControlFrame::ShowDropDow
       // Delay until we get focus, see SetFocus().
       mDelayedShowDropDown = true;
     }
   } else if (mDroppedDown && !aDoDropDown) {
     ShowList(aDoDropDown);  // might destroy us
   }
 }
 
-void nsComboboxControlFrame::SetDropDown(nsIFrame* aDropDownFrame) {
+void nsComboboxControlFrame::SetDropDown(nsListControlFrame* aDropDownFrame) {
   mDropdownFrame = aDropDownFrame;
   mListControlFrame = do_QueryFrame(mDropdownFrame);
   if (!sFocused && nsContentUtils::IsFocusedContent(GetContent())) {
     sFocused = this;
     nsListControlFrame::ComboboxFocusSet();
   }
 }
 
@@ -1037,30 +1034,26 @@ int32_t nsComboboxControlFrame::GetIndex
   return mDisplayedIndex;
 }
 
 //----------------------------------------------------------------------
 // nsISelectControlFrame
 //----------------------------------------------------------------------
 NS_IMETHODIMP
 nsComboboxControlFrame::DoneAddingChildren(bool aIsDone) {
-  nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
-  if (!listFrame) return NS_ERROR_FAILURE;
-
-  return listFrame->DoneAddingChildren(aIsDone);
+  return mDropdownFrame->DoneAddingChildren(aIsDone);
 }
 
 NS_IMETHODIMP
 nsComboboxControlFrame::AddOption(int32_t aIndex) {
   if (aIndex <= mDisplayedIndex) {
     ++mDisplayedIndex;
   }
 
-  nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
-  return lcf->AddOption(aIndex);
+  return mDropdownFrame->AddOption(aIndex);
 }
 
 NS_IMETHODIMP
 nsComboboxControlFrame::RemoveOption(int32_t aIndex) {
   AutoWeakFrame weakThis(this);
   if (mListControlFrame->GetNumberOfOptions() > 0) {
     if (aIndex < mDisplayedIndex) {
       --mDisplayedIndex;
@@ -1071,32 +1064,27 @@ nsComboboxControlFrame::RemoveOption(int
   } else {
     // If we removed the last option, we need to blank things out
     mDisplayedIndex = -1;
     RedisplayText();
   }
 
   if (!weakThis.IsAlive()) return NS_OK;
 
-  nsListControlFrame* lcf = static_cast<nsListControlFrame*>(mDropdownFrame);
-  return lcf->RemoveOption(aIndex);
+  return mDropdownFrame->RemoveOption(aIndex);
 }
 
 NS_IMETHODIMP_(void)
 nsComboboxControlFrame::OnSetSelectedIndex(int32_t aOldIndex,
                                            int32_t aNewIndex) {
   nsAutoScriptBlocker scriptBlocker;
   mDisplayedIndex = aNewIndex;
   RedisplayText();
-  NS_ASSERTION(mDropdownFrame, "No dropdown frame!");
-
-  nsISelectControlFrame* listFrame = do_QueryFrame(mDropdownFrame);
-  NS_ASSERTION(listFrame, "No list frame!");
-
-  return listFrame->OnSetSelectedIndex(aOldIndex, aNewIndex);
+  MOZ_ASSERT(mDropdownFrame, "No dropdown frame!");
+  return mDropdownFrame->OnSetSelectedIndex(aOldIndex, aNewIndex);
 }
 
 // End nsISelectControlFrame
 //----------------------------------------------------------------------
 
 nsresult nsComboboxControlFrame::HandleEvent(nsPresContext* aPresContext,
                                              WidgetGUIEvent* aEvent,
                                              nsEventStatus* aEventStatus) {
@@ -1127,22 +1115,17 @@ nsresult nsComboboxControlFrame::HandleE
   if (IsContentDisabled()) {
     return nsBlockFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
   }
   return NS_OK;
 }
 
 nsresult nsComboboxControlFrame::SetFormProperty(nsAtom* aName,
                                                  const nsAString& aValue) {
-  nsIFormControlFrame* fcFrame = do_QueryFrame(mDropdownFrame);
-  if (!fcFrame) {
-    return NS_NOINTERFACE;
-  }
-
-  return fcFrame->SetFormProperty(aName, aValue);
+  return mDropdownFrame->SetFormProperty(aName, aValue);
 }
 
 nsContainerFrame* nsComboboxControlFrame::GetContentInsertionFrame() {
   return mInRedisplayText ? mDisplayFrame
                           : mDropdownFrame->GetContentInsertionFrame();
 }
 
 void nsComboboxControlFrame::AppendDirectlyOwnedAnonBoxes(
@@ -1359,17 +1342,17 @@ nsIFrame* nsComboboxControlFrame::Create
   mDisplayContent->SetPrimaryFrame(textFrame);
 
   nsFrameList textList(textFrame, textFrame);
   mDisplayFrame->SetInitialChildList(kPrincipalList, textList);
   return mDisplayFrame;
 }
 
 nsIScrollableFrame* nsComboboxControlFrame::GetScrollTargetFrame() const {
-  return do_QueryFrame(mDropdownFrame);
+  return mDropdownFrame;
 }
 
 void nsComboboxControlFrame::DestroyFrom(nsIFrame* aDestructRoot,
                                          PostDestroyData& aPostDestroyData) {
   if (sFocused == this) {
     sFocused = nullptr;
   }
 
--- a/layout/forms/nsComboboxControlFrame.h
+++ b/layout/forms/nsComboboxControlFrame.h
@@ -132,17 +132,17 @@ class nsComboboxControlFrame final : pub
    * @note This method might destroy |this|.
    */
   MOZ_CAN_RUN_SCRIPT_BOUNDARY
   virtual void SetFocus(bool aOn, bool aRepaint) override;
 
   bool IsDroppedDown() { return mDroppedDown; }
   MOZ_CAN_RUN_SCRIPT void ShowDropDown(bool aDoDropDown);
   nsIFrame* GetDropDown();
-  void SetDropDown(nsIFrame* aDropDownFrame);
+  void SetDropDown(nsListControlFrame* aDropDownFrame);
   MOZ_CAN_RUN_SCRIPT void RollupFromList();
 
   /**
    * Return the available space before and after this frame for
    * placing the drop-down list, and the current 2D translation.
    * Note that either or both can be less than or equal to zero,
    * if both are then the drop-down should be closed.
    */
@@ -279,17 +279,17 @@ class nsComboboxControlFrame final : pub
 
  protected:
   nsFrameList mPopupFrames;            // additional named child list
   RefPtr<nsTextNode> mDisplayContent;  // Anonymous content used to display the
                                        // current selection
   RefPtr<Element> mButtonContent;      // Anonymous content for the button
   nsContainerFrame* mDisplayFrame;     // frame to display selection
   nsIFrame* mButtonFrame;              // button frame
-  nsIFrame* mDropdownFrame;            // dropdown list frame
+  nsListControlFrame* mDropdownFrame;  // dropdown list frame
   nsListControlFrame* mListControlFrame;  // ListControl for the dropdown frame
 
   // The inline size of our display area.  Used by that frame's reflow
   // to size to the full inline size except the drop-marker.
   nscoord mDisplayISize;
   // The maximum inline size of our display area, which is the
   // nsComoboxControlFrame's border-box.
   //