Bug 1613378: part 4) Declare some methods in `nsFrameSelection` static. r=smaug
authorMirko Brodesser <mbrodesser@mozilla.com>
Fri, 07 Feb 2020 16:13:27 +0000
changeset 512989 b49700eb15966184ad55ba0d65653af80ac0ef32
parent 512985 4c08723ed20aec9a60d09247ba7ff0ed2beb62aa
child 512990 0ea74c8ad137d2cebe2db856397e3dde95ec7fc9
push id37108
push userapavel@mozilla.com
push dateMon, 10 Feb 2020 17:30:51 +0000
treeherdermozilla-central@0968327fb81d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1613378
milestone74.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 1613378: part 4) Declare some methods in `nsFrameSelection` static. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D62037
dom/base/Selection.cpp
dom/events/ContentEventHandler.cpp
layout/base/AccessibleCaretManager.cpp
layout/base/nsCaret.cpp
layout/generic/nsFrame.cpp
layout/generic/nsFrameSelection.cpp
layout/generic/nsFrameSelection.h
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -1266,17 +1266,17 @@ nsresult Selection::GetIndicesForInterva
 
 nsresult Selection::GetPrimaryFrameForAnchorNode(nsIFrame** aReturnFrame) {
   if (!aReturnFrame) return NS_ERROR_NULL_POINTER;
 
   int32_t frameOffset = 0;
   *aReturnFrame = 0;
   nsCOMPtr<nsIContent> content = do_QueryInterface(GetAnchorNode());
   if (content && mFrameSelection) {
-    *aReturnFrame = mFrameSelection->GetFrameForNodeOffset(
+    *aReturnFrame = nsFrameSelection::GetFrameForNodeOffset(
         content, AnchorOffset(), mFrameSelection->GetHint(), &frameOffset);
     if (*aReturnFrame) return NS_OK;
   }
   return NS_ERROR_FAILURE;
 }
 
 nsresult Selection::GetPrimaryFrameForFocusNode(nsIFrame** aReturnFrame,
                                                 int32_t* aOffsetUsed,
@@ -1339,18 +1339,18 @@ nsresult Selection::GetPrimaryOrCaretFra
   if (aVisual) {
     nsBidiLevel caretBidiLevel = mFrameSelection->GetCaretBidiLevel();
 
     return nsCaret::GetCaretFrameForNodeOffset(
         mFrameSelection, aContent, aOffset, hint, caretBidiLevel, aReturnFrame,
         /* aReturnUnadjustedFrame = */ nullptr, aOffsetUsed);
   }
 
-  *aReturnFrame = mFrameSelection->GetFrameForNodeOffset(aContent, aOffset,
-                                                         hint, aOffsetUsed);
+  *aReturnFrame = nsFrameSelection::GetFrameForNodeOffset(aContent, aOffset,
+                                                          hint, aOffsetUsed);
   if (!*aReturnFrame) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 void Selection::SelectFramesOf(nsIContent* aContent, bool aSelected) const {
@@ -2814,17 +2814,17 @@ nsIFrame* Selection::GetSelectionEndPoin
       return nullptr;
   }
 
   if (!node) return nullptr;
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(node);
   NS_ENSURE_TRUE(content.get(), nullptr);
   int32_t frameOffset = 0;
-  frame = mFrameSelection->GetFrameForNodeOffset(
+  frame = nsFrameSelection::GetFrameForNodeOffset(
       content, nodeOffset, mFrameSelection->GetHint(), &frameOffset);
   if (!frame) return nullptr;
 
   // Figure out what node type we have, then get the
   // appropriate rect for it's nodeOffset.
   bool isText = node->IsText();
 
   nsPoint pt(0, 0);
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -956,22 +956,21 @@ nsresult ContentEventHandler::ExpandToCl
   if (!aContent->IsText() || *aXPOffset == 0 ||
       *aXPOffset == aContent->TextLength()) {
     return NS_OK;
   }
 
   NS_ASSERTION(*aXPOffset <= aContent->TextLength(), "offset is out of range.");
 
   MOZ_DIAGNOSTIC_ASSERT(mDocument->GetPresShell());
-  RefPtr<nsFrameSelection> fs = mDocument->GetPresShell()->FrameSelection();
   int32_t offsetInFrame;
   CaretAssociationHint hint =
       aForward ? CARET_ASSOCIATE_BEFORE : CARET_ASSOCIATE_AFTER;
-  nsIFrame* frame = fs->GetFrameForNodeOffset(aContent, int32_t(*aXPOffset),
-                                              hint, &offsetInFrame);
+  nsIFrame* frame = nsFrameSelection::GetFrameForNodeOffset(
+      aContent, int32_t(*aXPOffset), hint, &offsetInFrame);
   if (frame) {
     int32_t startOffset, endOffset;
     nsresult rv = frame->GetOffsets(startOffset, endOffset);
     NS_ENSURE_SUCCESS(rv, rv);
     if (*aXPOffset == static_cast<uint32_t>(startOffset) ||
         *aXPOffset == static_cast<uint32_t>(endOffset)) {
       return NS_OK;
     }
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -621,17 +621,17 @@ nsresult AccessibleCaretManager::SelectW
   // can find a better frame for caret, we don't select a word.
   // See https://webcompat.com/issues/15953
   nsIFrame::ContentOffsets offsets =
       ptFrame->GetContentOffsetsFromPoint(ptInFrame, nsIFrame::SKIP_HIDDEN);
   if (offsets.content) {
     RefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
     if (frameSelection) {
       int32_t offset;
-      nsIFrame* theFrame = frameSelection->GetFrameForNodeOffset(
+      nsIFrame* theFrame = nsFrameSelection::GetFrameForNodeOffset(
           offsets.content, offsets.offset, offsets.associate, &offset);
       if (theFrame && theFrame != ptFrame) {
         SetSelectionDragState(true);
         frameSelection->HandleClick(offsets.content, offsets.StartOffset(),
                                     offsets.EndOffset(), false, false,
                                     offsets.associate);
         SetSelectionDragState(false);
         ClearMaintainedSelection();
@@ -1061,19 +1061,18 @@ nsIFrame* AccessibleCaretManager::GetFra
     range = selection->GetRangeAt(selection->RangeCount() - 1);
     startNode = range->GetEndContainer();
     endNode = range->GetStartContainer();
     nodeOffset = range->EndOffset();
     hint = CARET_ASSOCIATE_BEFORE;
   }
 
   nsCOMPtr<nsIContent> startContent = do_QueryInterface(startNode);
-  RefPtr<nsFrameSelection> fs = GetFrameSelection();
-  nsIFrame* startFrame =
-      fs->GetFrameForNodeOffset(startContent, nodeOffset, hint, aOutOffset);
+  nsIFrame* startFrame = nsFrameSelection::GetFrameForNodeOffset(
+      startContent, nodeOffset, hint, aOutOffset);
 
   if (!startFrame) {
     ErrorResult err;
     RefPtr<TreeWalker> walker = mPresShell->GetDocument()->CreateTreeWalker(
         *startNode, dom::NodeFilter_Binding::SHOW_ALL, nullptr, err);
 
     if (!walker) {
       return nullptr;
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -622,17 +622,17 @@ nsresult nsCaret::GetCaretFrameForNodeOf
 
   if (!aContentNode || !aContentNode->IsInComposedDoc() ||
       presShell->GetDocument() != aContentNode->GetComposedDoc())
     return NS_ERROR_FAILURE;
 
   nsIFrame* theFrame = nullptr;
   int32_t theFrameOffset = 0;
 
-  theFrame = aFrameSelection->GetFrameForNodeOffset(
+  theFrame = nsFrameSelection::GetFrameForNodeOffset(
       aContentNode, aOffset, aFrameHint, &theFrameOffset);
   if (!theFrame) return NS_ERROR_FAILURE;
 
   if (aReturnUnadjustedFrame) {
     *aReturnUnadjustedFrame = theFrame;
   }
 
   // if theFrame is after a text frame that's logically at the end of the line
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -4744,19 +4744,17 @@ nsresult nsFrame::SelectByTypeAtPoint(ns
   // No point in selecting if selection is turned off
   if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF)
     return NS_OK;
 
   ContentOffsets offsets = GetContentOffsetsFromPoint(aPoint, SKIP_HIDDEN);
   if (!offsets.content) return NS_ERROR_FAILURE;
 
   int32_t offset;
-  const nsFrameSelection* frameSelection =
-      PresContext()->GetPresShell()->ConstFrameSelection();
-  nsIFrame* theFrame = frameSelection->GetFrameForNodeOffset(
+  nsIFrame* theFrame = nsFrameSelection::GetFrameForNodeOffset(
       offsets.content, offsets.offset, offsets.associate, &offset);
   if (!theFrame) return NS_ERROR_FAILURE;
 
   nsFrame* frame = static_cast<nsFrame*>(theFrame);
   return frame->PeekBackwardAndForward(aBeginAmountType, aEndAmountType, offset,
                                        aBeginAmountType != eSelectWord,
                                        aSelectFlags);
 }
--- a/layout/generic/nsFrameSelection.cpp
+++ b/layout/generic/nsFrameSelection.cpp
@@ -834,19 +834,20 @@ nsresult nsFrameSelection::MoveCaret(nsD
   return result;
 }
 
 nsPrevNextBidiLevels nsFrameSelection::GetPrevNextBidiLevels(
     nsIContent* aNode, uint32_t aContentOffset, bool aJumpLines) const {
   return GetPrevNextBidiLevels(aNode, aContentOffset, mHint, aJumpLines);
 }
 
+// static
 nsPrevNextBidiLevels nsFrameSelection::GetPrevNextBidiLevels(
     nsIContent* aNode, uint32_t aContentOffset, CaretAssociateHint aHint,
-    bool aJumpLines) const {
+    bool aJumpLines) {
   // Get the level of the frames on each side
   nsIFrame* currentFrame;
   int32_t currentOffset;
   int32_t frameStart, frameEnd;
   nsDirection direction;
 
   nsPrevNextBidiLevels levels;
   levels.SetData(nullptr, nullptr, 0, 0);
@@ -1451,20 +1452,22 @@ nsresult nsFrameSelection::RepaintSelect
 #endif
   return mDomSelections[index]->Repaint(mPresShell->GetPresContext());
 }
 
 static bool IsDisplayContents(const nsIContent* aContent) {
   return aContent->IsElement() && aContent->AsElement()->IsDisplayContents();
 }
 
-nsIFrame* nsFrameSelection::GetFrameForNodeOffset(
-    nsIContent* aNode, int32_t aOffset, CaretAssociateHint aHint,
-    int32_t* aReturnOffset) const {
-  if (!aNode || !aReturnOffset || !mPresShell) return nullptr;
+// static
+nsIFrame* nsFrameSelection::GetFrameForNodeOffset(nsIContent* aNode,
+                                                  int32_t aOffset,
+                                                  CaretAssociateHint aHint,
+                                                  int32_t* aReturnOffset) {
+  if (!aNode || !aReturnOffset) return nullptr;
 
   if (aOffset < 0) return nullptr;
 
   if (!aNode->GetPrimaryFrame() && !IsDisplayContents(aNode)) {
     return nullptr;
   }
 
   nsIFrame* returnFrame = nullptr;
@@ -2590,17 +2593,18 @@ nsresult nsFrameSelection::SelectRowOrCo
       rowIndex += actualRowSpan;
   }
   while (cellElement);
 #endif
 
   return NS_OK;
 }
 
-nsIContent* nsFrameSelection::GetFirstCellNodeInRange(nsRange* aRange) const {
+// static
+nsIContent* nsFrameSelection::GetFirstCellNodeInRange(nsRange* aRange) {
   if (!aRange) return nullptr;
 
   nsIContent* childContent = aRange->GetChildAtStartOffset();
   if (!childContent) return nullptr;
   // Don't return node if not a cell
   if (!IsCell(childContent)) return nullptr;
 
   return childContent;
@@ -2646,29 +2650,31 @@ nsresult nsFrameSelection::GetCellIndexe
   aColIndex = 0;  // initialize out params
   aRowIndex = 0;
 
   nsITableCellLayout* cellLayoutObject = GetCellLayout(aCell);
   if (!cellLayoutObject) return NS_ERROR_FAILURE;
   return cellLayoutObject->GetCellIndexes(aRowIndex, aColIndex);
 }
 
+// static
 nsIContent* nsFrameSelection::IsInSameTable(nsIContent* aContent1,
-                                            nsIContent* aContent2) const {
+                                            nsIContent* aContent2) {
   if (!aContent1 || !aContent2) return nullptr;
 
   nsIContent* tableNode1 = GetParentTable(aContent1);
   nsIContent* tableNode2 = GetParentTable(aContent2);
 
   // Must be in the same table.  Note that we want to return false for
   // the test if both tables are null.
   return (tableNode1 == tableNode2) ? tableNode1 : nullptr;
 }
 
-nsIContent* nsFrameSelection::GetParentTable(nsIContent* aCell) const {
+// static
+nsIContent* nsFrameSelection::GetParentTable(nsIContent* aCell) {
   if (!aCell) {
     return nullptr;
   }
 
   for (nsIContent* parent = aCell->GetParent(); parent;
        parent = parent->GetParent()) {
     if (parent->IsHTMLElement(nsGkAtoms::table)) {
       return parent;
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -454,19 +454,19 @@ class nsFrameSelection final {
   /**
    * Given a node and its child offset, return the nsIFrame and the offset into
    * that frame.
    *
    * @param aNode input parameter for the node to look at
    * @param aOffset offset into above node.
    * @param aReturnOffset will contain offset into frame.
    */
-  nsIFrame* GetFrameForNodeOffset(nsIContent* aNode, int32_t aOffset,
-                                  CaretAssociateHint aHint,
-                                  int32_t* aReturnOffset) const;
+  static nsIFrame* GetFrameForNodeOffset(nsIContent* aNode, int32_t aOffset,
+                                         CaretAssociateHint aHint,
+                                         int32_t* aReturnOffset);
 
   /**
    * GetFrameToPageSelect() returns a frame which is ancestor limit of
    * per-page selection.  The frame may not be scrollable.  E.g.,
    * when selection ancestor limit is set to a frame of an editing host of
    * contenteditable element and it's not scrollable.
    */
   nsIFrame* GetFrameToPageSelect() const;
@@ -731,20 +731,20 @@ class nsFrameSelection final {
   nsresult TakeFocus(nsIContent* aNewFocus, uint32_t aContentOffset,
                      uint32_t aContentEndOffset, CaretAssociateHint aHint,
                      bool aContinueSelection, bool aMultipleSelection);
 
   void BidiLevelFromMove(mozilla::PresShell* aPresShell, nsIContent* aNode,
                          uint32_t aContentOffset, nsSelectionAmount aAmount,
                          CaretAssociateHint aHint);
   void BidiLevelFromClick(nsIContent* aNewFocus, uint32_t aContentOffset);
-  nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent* aNode,
-                                             uint32_t aContentOffset,
-                                             CaretAssociateHint aHint,
-                                             bool aJumpLines) const;
+  static nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent* aNode,
+                                                    uint32_t aContentOffset,
+                                                    CaretAssociateHint aHint,
+                                                    bool aJumpLines);
 
   bool AdjustForMaintainedSelection(nsIContent* aContent, int32_t aOffset);
 
   // post and pop reasons for notifications. we may stack these later
   void PostReason(int16_t aReason) { mSelectionChangeReason = aReason; }
   int16_t PopReason() {
     int16_t retval = mSelectionChangeReason;
     mSelectionChangeReason = nsISelectionListener::NO_REASON;
@@ -815,21 +815,22 @@ class nsFrameSelection final {
   // Get our first range, if its first selected node is a cell.  If this does
   // not return null, then the first node in the returned range is a cell
   // (according to GetFirstCellNodeInRange).
   nsRange* GetFirstCellRange();
   // Get our next range, if its first selected node is a cell.  If this does
   // not return null, then the first node in the returned range is a cell
   // (according to GetFirstCellNodeInRange).
   nsRange* GetNextCellRange();
-  nsIContent* GetFirstCellNodeInRange(nsRange* aRange) const;
+  static nsIContent* GetFirstCellNodeInRange(nsRange* aRange);
   // Returns non-null table if in same table, null otherwise
-  nsIContent* IsInSameTable(nsIContent* aContent1, nsIContent* aContent2) const;
+  static nsIContent* IsInSameTable(nsIContent* aContent1,
+                                   nsIContent* aContent2);
   // Might return null
-  nsIContent* GetParentTable(nsIContent* aCellNode) const;
+  static nsIContent* GetParentTable(nsIContent* aCellNode);
   nsresult CreateAndAddRange(nsINode* aContainer, int32_t aOffset);
 
   ////////////BEGIN nsFrameSelection members
 
   RefPtr<mozilla::dom::Selection>
       mDomSelections[sizeof(mozilla::kPresentSelectionTypes) /
                      sizeof(mozilla::SelectionType)];