Bug 1062735 - Part 1: Remove GetHintForPosition. r=roc
authorMorris Tseng <mtseng@mozilla.com>
Sun, 28 Sep 2014 23:48:00 +0200
changeset 210994 12499d6135bf09ad39b1bf4593c852c712e2c794
parent 210993 f5fa8ea86d3b7645835b35b4fe6ff35860eea18c
child 210995 fe11070e6932f219bf7be979b195bdccbce7f956
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc
bugs1062735
milestone36.0a1
Bug 1062735 - Part 1: Remove GetHintForPosition. r=roc
layout/base/SelectionCarets.cpp
layout/generic/nsFrameSelection.h
layout/generic/nsSelection.cpp
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -318,17 +318,17 @@ FindFirstNodeWithFrame(nsIDocument* aDoc
     do_QueryInterface(aBackward ? aRange->GetEndParent() : aRange->GetStartParent());
   nsCOMPtr<nsINode> endNode =
     do_QueryInterface(aBackward ? aRange->GetStartParent() : aRange->GetEndParent());
   int32_t offset = aBackward ? aRange->EndOffset() : aRange->StartOffset();
 
   nsCOMPtr<nsIContent> startContent = do_QueryInterface(startNode);
   nsCOMPtr<nsIContent> endContent = do_QueryInterface(endNode);
   CaretAssociationHint hintStart =
-    nsFrameSelection::GetHintForPosition(startContent, offset);
+    aBackward ? CARET_ASSOCIATE_BEFORE : CARET_ASSOCIATE_AFTER;
   nsIFrame* startFrame = aFrameSelection->GetFrameForNodeOffset(startContent,
                                                                 offset,
                                                                 hintStart,
                                                                 &aOutOffset);
 
   if (startFrame) {
     return startFrame;
   }
@@ -713,17 +713,17 @@ SelectionCarets::GetCaretYCenterPosition
     nodeOffset = range->StartOffset();
   } else {
     node = do_QueryInterface(range->GetEndParent());
     nodeOffset = range->EndOffset();
   }
 
   int32_t offset;
   CaretAssociationHint hint =
-    nsFrameSelection::GetHintForPosition(node, nodeOffset);
+    mDragMode == START_FRAME ? CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE;
   nsIFrame* theFrame =
     fs->GetFrameForNodeOffset(node, nodeOffset, hint, &offset);
 
   if (!theFrame) {
     return 0;
   }
   nsRect frameRect = theFrame->GetRectRelativeToSelf();
   nsLayoutUtils::TransformRect(theFrame, canvasFrame, frameRect);
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -579,18 +579,16 @@ public:
   /*unsafe*/
   nsresult DeleteFromDocument();
 
   nsIPresShell *GetShell()const  { return mShell; }
 
   void DisconnectFromPresShell();
   nsresult ClearNormalSelection();
 
-  static CaretAssociateHint GetHintForPosition(nsIContent* aContent, int32_t aOffset);
-
 private:
   ~nsFrameSelection();
 
   nsresult TakeFocus(nsIContent *aNewFocus,
                      uint32_t aContentOffset,
                      uint32_t aContentEndOffset,
                      CaretAssociateHint aHint,
                      bool aContinueSelection,
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -709,31 +709,16 @@ GetCellParent(nsINode *aDomNode)
       nsIAtom* tag = GetTag(current);
       if (tag == nsGkAtoms::td || tag == nsGkAtoms::th)
         return current;
       current = current->GetParent();
     }
     return nullptr;
 }
 
-CaretAssociationHint
-nsFrameSelection::GetHintForPosition(nsIContent* aContent, int32_t aOffset)
-{
-  CaretAssociateHint hint = CARET_ASSOCIATE_BEFORE;
-  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 = CARET_ASSOCIATE_AFTER;
-  }
-  return hint;
-}
-
 void
 nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter)
 {
   mShell = aShell;
   mDragState = false;
   mDesiredXSet = false;
   mLimiter = aLimiter;
   mCaretMovementStyle =