Bug 1217939 - part 2 - move nsContentUtils::GetSelectionBoundingRect to nsLayoutUtils; r=smaug
authorNathan Froyd <froydnj@mozilla.com>
Fri, 23 Oct 2015 13:39:00 -0400
changeset 304686 d9f5c51cfa0029b60ebfc7cf2aaf766010072ca4
parent 304685 37d64688bf9d1e2aca7d0660333752ab0a977e1e
child 304687 bf77e2eef0a0d12f2b0c5dc8d771d436291b5de8
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1217939
milestone44.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 1217939 - part 2 - move nsContentUtils::GetSelectionBoundingRect to nsLayoutUtils; r=smaug All callers of this function are in layout/base/ and it uses a lot of things from nsLayoutUtils, so nsLayoutUtils seems like a better fit for it.
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
layout/base/AccessibleCaretManager.cpp
layout/base/SelectionCarets.cpp
layout/base/TouchCaret.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7017,48 +7017,16 @@ nsContentUtils::GetSelectionInTextContro
     }
   }
 
   // Make sure aOutStartOffset <= aOutEndOffset.
   aOutStartOffset = std::min(anchorOffset, focusOffset);
   aOutEndOffset = std::max(anchorOffset, focusOffset);
 }
 
-/* static */
-nsRect
-nsContentUtils::GetSelectionBoundingRect(Selection* aSel)
-{
-  nsRect res;
-  // Bounding client rect may be empty after calling GetBoundingClientRect
-  // when range is collapsed. So we get caret's rect when range is
-  // collapsed.
-  if (aSel->IsCollapsed()) {
-    nsIFrame* frame = nsCaret::GetGeometry(aSel, &res);
-    if (frame) {
-      nsIFrame* relativeTo =
-        nsLayoutUtils::GetContainingBlockForClientRect(frame);
-      res = nsLayoutUtils::TransformFrameRectToAncestor(frame, res, relativeTo);
-    }
-  } else {
-    int32_t rangeCount = aSel->RangeCount();
-    nsLayoutUtils::RectAccumulator accumulator;
-    for (int32_t idx = 0; idx < rangeCount; ++idx) {
-      nsRange* range = aSel->GetRangeAt(idx);
-      nsRange::CollectClientRects(&accumulator, range,
-                                  range->GetStartParent(), range->StartOffset(),
-                                  range->GetEndParent(), range->EndOffset(),
-                                  true, false);
-    }
-    res = accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect :
-      accumulator.mResultRect;
-  }
-
-  return res;
-}
-
 
 nsIEditor*
 nsContentUtils::GetHTMLEditor(nsPresContext* aPresContext)
 {
   nsCOMPtr<nsIDocShell> docShell(aPresContext->GetDocShell());
   bool isEditable;
   if (!docShell ||
       NS_FAILED(docShell->GetEditable(&isEditable)) || !isEditable)
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2308,24 +2308,16 @@ public:
    * @param aOutEndOffset   Output end offset
    */
   static void GetSelectionInTextControl(mozilla::dom::Selection* aSelection,
                                         Element* aRoot,
                                         int32_t& aOutStartOffset,
                                         int32_t& aOutEndOffset);
 
   /**
-   * Takes a selection, and return selection's bounding rect which is relative
-   * to root frame.
-   *
-   * @param aSel      Selection to check
-   */
-  static nsRect GetSelectionBoundingRect(mozilla::dom::Selection* aSel);
-
-  /**
    * Takes a frame for anonymous content within a text control (<input> or
    * <textarea>), and returns an offset in the text content, adjusted for a
    * trailing <br> frame.
    *
    * @param aOffsetFrame      Frame for the text content in which the offset
    *                          lies
    * @param aOffset           Offset as calculated by GetContentOffsetsFromPoint
    * @param aOutOffset        Output adjusted offset
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -1053,17 +1053,17 @@ AccessibleCaretManager::DispatchCaretSta
     commonAncestorNode = range->GetCommonAncestor();
   }
 
   if (!commonAncestorNode) {
     commonAncestorNode = sel->GetFrameSelection()->GetAncestorLimiter();
   }
 
   RefPtr<DOMRect> domRect = new DOMRect(ToSupports(doc));
-  nsRect rect = nsContentUtils::GetSelectionBoundingRect(sel);
+  nsRect rect = nsLayoutUtils::GetSelectionBoundingRect(sel);
 
   nsIFrame* commonAncestorFrame = nullptr;
   nsIFrame* rootFrame = mPresShell->GetRootFrame();
 
   if (commonAncestorNode && commonAncestorNode->IsContent()) {
     commonAncestorFrame = commonAncestorNode->AsContent()->GetPrimaryFrame();
   }
 
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -506,17 +506,17 @@ SelectionCarets::UpdateSelectionCarets()
     SetVisibility(false);
     return;
   }
 
   // If the selection is not visible, we should dispatch a event.
   nsIFrame* commonAncestorFrame =
     nsLayoutUtils::FindNearestCommonAncestorFrame(startFrame, endFrame);
 
-  nsRect selectionRectInRootFrame = nsContentUtils::GetSelectionBoundingRect(selection);
+  nsRect selectionRectInRootFrame = nsLayoutUtils::GetSelectionBoundingRect(selection);
   nsRect selectionRectInCommonAncestorFrame = selectionRectInRootFrame;
   nsLayoutUtils::TransformRect(rootFrame, commonAncestorFrame,
                                selectionRectInCommonAncestorFrame);
 
   mSelectionVisibleInScrollFrames =
     nsLayoutUtils::IsRectVisibleInScrollFrames(commonAncestorFrame,
                                                selectionRectInCommonAncestorFrame);
   SELECTIONCARETS_LOG("Selection visibility %s",
@@ -1087,17 +1087,17 @@ SelectionCarets::DispatchSelectionStateC
   MOZ_ASSERT(doc);
 
   SelectionStateChangedEventInit init;
   init.mBubbles = true;
 
   if (aSelection) {
     // XXX: Do we need to flush layout?
     mPresShell->FlushPendingNotifications(Flush_Layout);
-    nsRect rect = nsContentUtils::GetSelectionBoundingRect(aSelection);
+    nsRect rect = nsLayoutUtils::GetSelectionBoundingRect(aSelection);
     RefPtr<DOMRect>domRect = new DOMRect(ToSupports(doc));
 
     domRect->SetLayoutRect(rect);
     init.mBoundingClientRect = domRect;
     init.mVisible = mSelectionVisibleInScrollFrames;
 
     aSelection->Stringify(init.mSelectedText);
   }
--- a/layout/base/TouchCaret.cpp
+++ b/layout/base/TouchCaret.cpp
@@ -1134,17 +1134,17 @@ TouchCaret::DispatchTapEvent()
 
   MOZ_ASSERT(doc);
 
   dom::SelectionStateChangedEventInit init;
   init.mBubbles = true;
 
   // XXX: Do we need to flush layout?
   presShell->FlushPendingNotifications(Flush_Layout);
-  nsRect rect = nsContentUtils::GetSelectionBoundingRect(sel);
+  nsRect rect = nsLayoutUtils::GetSelectionBoundingRect(sel);
   RefPtr<dom::DOMRect>domRect = new dom::DOMRect(ToSupports(doc));
 
   domRect->SetLayoutRect(rect);
   init.mBoundingClientRect = domRect;
   init.mVisible = false;
 
   sel->Stringify(init.mSelectedText);
 
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -20,16 +20,17 @@
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsFrameList.h"
 #include "nsGkAtoms.h"
 #include "nsHtml5Atoms.h"
 #include "nsIAtom.h"
+#include "nsCaret.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsCSSColorUtils.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsPlaceholderFrame.h"
 #include "nsIScrollableFrame.h"
 #include "nsIDOMEvent.h"
@@ -8623,8 +8624,39 @@ nsLayoutUtils::AppendFrameTextContent(ns
     textFrame->GetContent()->
       GetText()->AppendTo(aResult, offset, length);
   } else {
     for (nsIFrame* child : aFrame->PrincipalChildList()) {
       AppendFrameTextContent(child, aResult);
     }
   }
 }
+
+/* static */
+nsRect
+nsLayoutUtils::GetSelectionBoundingRect(Selection* aSel)
+{
+  nsRect res;
+  // Bounding client rect may be empty after calling GetBoundingClientRect
+  // when range is collapsed. So we get caret's rect when range is
+  // collapsed.
+  if (aSel->IsCollapsed()) {
+    nsIFrame* frame = nsCaret::GetGeometry(aSel, &res);
+    if (frame) {
+      nsIFrame* relativeTo = GetContainingBlockForClientRect(frame);
+      res = TransformFrameRectToAncestor(frame, res, relativeTo);
+    }
+  } else {
+    int32_t rangeCount = aSel->RangeCount();
+    RectAccumulator accumulator;
+    for (int32_t idx = 0; idx < rangeCount; ++idx) {
+      nsRange* range = aSel->GetRangeAt(idx);
+      nsRange::CollectClientRects(&accumulator, range,
+                                  range->GetStartParent(), range->StartOffset(),
+                                  range->GetEndParent(), range->EndOffset(),
+                                  true, false);
+    }
+    res = accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect :
+      accumulator.mResultRect;
+  }
+
+  return res;
+}
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -67,16 +67,17 @@ struct IntrinsicSize;
 struct ContainerLayerParameters;
 class WritingMode;
 namespace dom {
 class DOMRectList;
 class Element;
 class HTMLImageElement;
 class HTMLCanvasElement;
 class HTMLVideoElement;
+class Selection;
 } // namespace dom
 namespace gfx {
 struct RectCornerRadii;
 } // namespace gfx
 namespace layers {
 class Layer;
 } // namespace layers
 } // namespace mozilla
@@ -2750,16 +2751,23 @@ public:
    */
   static void GetFrameTextContent(nsIFrame* aFrame, nsAString& aResult);
 
   /**
    * Same as GetFrameTextContent but appends the result rather than sets it.
    */
   static void AppendFrameTextContent(nsIFrame* aFrame, nsAString& aResult);
 
+  /**
+   * Takes a selection, and returns selection's bounding rect which is relative
+   * to its root frame.
+   *
+   * @param aSel      Selection to check
+   */
+  static nsRect GetSelectionBoundingRect(mozilla::dom::Selection* aSel);
 private:
   static uint32_t sFontSizeInflationEmPerLine;
   static uint32_t sFontSizeInflationMinTwips;
   static uint32_t sFontSizeInflationLineThreshold;
   static int32_t  sFontSizeInflationMappingIntercept;
   static uint32_t sFontSizeInflationMaxRatio;
   static bool sFontSizeInflationForceEnabled;
   static bool sFontSizeInflationDisabledInMasterProcess;