Bug 987718 - Part 2: Expose GetHintForPosition to nsFrameSelection; r=roc
authorMorris Tseng <mtseng@mozilla.com>
Wed, 04 Jun 2014 22:53:00 +0200
changeset 206050 83bdc6425e06708a45c86af1544c4df3d9ec5953
parent 206049 9928bd00f32c7655f390d0299302b4b8cfdbb962
child 206051 82610924de41b38ab09d4d557102dc2764b8653f
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs987718
milestone32.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 987718 - Part 2: Expose GetHintForPosition to nsFrameSelection; r=roc
layout/base/nsCaret.cpp
layout/generic/nsFrameSelection.h
layout/generic/nsSelection.cpp
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -406,49 +406,34 @@ void nsCaret::EraseCaret()
   }
 }
 
 void nsCaret::SetVisibilityDuringSelection(bool aVisibility) 
 {
   mShowDuringSelection = aVisibility;
 }
 
-static
-nsFrameSelection::HINT GetHintForPosition(nsIDOMNode* aNode, int32_t aOffset)
-{
-  nsFrameSelection::HINT hint = nsFrameSelection::HINTLEFT;
-  nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
-  if (!node || aOffset < 1) {
-    return hint;
-  }
-  const nsTextFragment* text = node->GetText();
-  if (text && text->CharAt(aOffset - 1) == '\n') {
-    // Attach the caret to the next line if needed
-    hint = nsFrameSelection::HINTRIGHT;
-  }
-  return hint;
-}
-
 nsresult nsCaret::DrawAtPosition(nsIDOMNode* aNode, int32_t aOffset)
 {
   NS_ENSURE_ARG(aNode);
 
   uint8_t bidiLevel;
   nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
   if (!frameSelection)
     return NS_ERROR_FAILURE;
   bidiLevel = frameSelection->GetCaretBidiLevel();
 
   // DrawAtPosition is used by consumers who want us to stay drawn where they
   // tell us. Setting mBlinkRate to 0 tells us to not set a timer to erase
   // ourselves, our consumer will take care of that.
   mBlinkRate = 0;
 
+  nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
   nsresult rv = DrawAtPositionWithHint(aNode, aOffset,
-                                       GetHintForPosition(aNode, aOffset),
+                                       nsFrameSelection::GetHintForPosition(node, aOffset),
                                        bidiLevel, true)
     ?  NS_OK : NS_ERROR_FAILURE;
   ToggleDrawnStatus();
   return rv;
 }
 
 nsIFrame * nsCaret::GetCaretFrame(int32_t *aOffset)
 {
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -586,16 +586,18 @@ public:
   void EndBatchChanges();
   /*unsafe*/
   nsresult DeleteFromDocument();
 
   nsIPresShell *GetShell()const  { return mShell; }
 
   void DisconnectFromPresShell();
   nsresult ClearNormalSelection();
+
+  static HINT GetHintForPosition(nsIContent* aContent, int32_t aOffset);
 private:
   nsresult TakeFocus(nsIContent *aNewFocus,
                      uint32_t aContentOffset,
                      uint32_t aContentEndOffset,
                      HINT aHint,
                      bool aContinueSelection,
                      bool aMultipleSelection);
 
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -679,16 +679,30 @@ GetCellParent(nsINode *aDomNode)
       nsIAtom* tag = GetTag(current);
       if (tag == nsGkAtoms::td || tag == nsGkAtoms::th)
         return current;
       current = current->GetParent();
     }
     return nullptr;
 }
 
+nsFrameSelection::HINT
+nsFrameSelection::GetHintForPosition(nsIContent* aContent, int32_t aOffset)
+{
+  HINT hint = HINTLEFT;
+  if (!aContent || aOffset < 1) {
+    return hint;
+  }
+  const nsTextFragment* text = aContent->GetText();
+  if (text && text->CharAt(aOffset - 1) == '\n') {
+    // Attach the caret to the next line if needed
+    hint = HINTRIGHT;
+  }
+  return hint;
+}
 
 void
 nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter)
 {
   mShell = aShell;
   mMouseDownState = false;
   mDesiredXSet = false;
   mLimiter = aLimiter;