Bug 1200194 - Expose nsCaret::GetFrameAndOffset for reuse. r=roc
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 09 Sep 2015 16:47:20 +0800
changeset 294341 8d7e8ebd0de628c8a393e36c392eb3b1ab227bdf
parent 294340 6b470e90aef5b8b6c250673a10184bf0ee3dcf68
child 294342 bc60f34e6b6e3e84de94b09ee5b79927c53e9966
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1200194
milestone43.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 1200194 - Expose nsCaret::GetFrameAndOffset for reuse. r=roc This function can be reused by AccessibleCaret.
layout/base/AccessibleCaretManager.cpp
layout/base/nsCaret.cpp
layout/base/nsCaret.h
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -120,34 +120,20 @@ AccessibleCaretManager::UpdateCaretsForC
   AC_LOG("%s, selection: %p", __FUNCTION__, GetSelection());
 
   nsRefPtr<nsCaret> caret = mPresShell->GetCaret();
   if (!caret || !caret->IsVisible()) {
     HideCarets();
     return;
   }
 
-  nsRefPtr<nsFrameSelection> fs = GetFrameSelection();
-  Selection* selection = GetSelection();
-  if (!fs || !selection) {
-    HideCarets();
-    return;
-  }
+  int32_t offset = 0;
+  nsIFrame* frame = nsCaret::GetFrameAndOffset(GetSelection(), nullptr, 0, &offset);
 
-  nsINode* focusNode = selection->GetFocusNode();
-  nsIContent* focusContent = focusNode->AsContent();
-  uint32_t focusOffset = selection->FocusOffset();
-
-  nsIFrame* frame = nullptr;
-  int32_t offset = 0;
-  nsresult rv = nsCaret::GetCaretFrameForNodeOffset(
-    fs, focusContent, focusOffset, fs->GetHint(), fs->GetCaretBidiLevel(),
-    &frame, &offset);
-
-  if (NS_FAILED(rv) || !frame) {
+  if (!frame) {
     HideCarets();
     return;
   }
 
   Element* editingHost = frame->GetContent()->GetEditingHost();
   if (!editingHost) {
     HideCarets();
     return;
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -405,20 +405,20 @@ nsCaret::GetGeometryForFrame(nsIFrame* a
   }
 
   if (aBidiIndicatorSize) {
     *aBidiIndicatorSize = caretMetrics.mBidiIndicatorSize;
   }
   return rect;
 }
 
-static nsIFrame*
-GetFrameAndOffset(Selection* aSelection,
-                  nsINode* aOverrideNode, int32_t aOverrideOffset,
-                  int32_t* aFrameOffset)
+nsIFrame*
+nsCaret::GetFrameAndOffset(Selection* aSelection,
+                           nsINode* aOverrideNode, int32_t aOverrideOffset,
+                           int32_t* aFrameOffset)
 {
   nsINode* focusNode;
   int32_t focusOffset;
 
   if (aOverrideNode) {
     focusNode = aOverrideNode;
     focusOffset = aOverrideOffset;
   } else if (aSelection) {
--- a/layout/base/nsCaret.h
+++ b/layout/base/nsCaret.h
@@ -163,16 +163,26 @@ class nsCaret final : public nsISelectio
                                                CaretAssociationHint aFrameHint,
                                                uint8_t aBidiLevel,
                                                nsIFrame** aReturnFrame,
                                                int32_t* aReturnOffset);
     static nsRect GetGeometryForFrame(nsIFrame* aFrame,
                                       int32_t   aFrameOffset,
                                       nscoord*  aBidiIndicatorSize);
 
+    // Get the frame and frame offset based on the focus node and focus offset
+    // of aSelection. If aOverrideNode and aOverride are provided, use them
+    // instead.
+    // @param aFrameOffset return the frame offset if non-null.
+    // @return the frame of the focus node.
+    static nsIFrame* GetFrameAndOffset(mozilla::dom::Selection* aSelection,
+                                       nsINode* aOverrideNode,
+                                       int32_t aOverrideOffset,
+                                       int32_t* aFrameOffset);
+
     size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 protected:
     static void   CaretBlinkCallback(nsITimer *aTimer, void *aClosure);
 
     bool          IsBidiUI();
     void          CheckSelectionLanguageChange();