From 4dfb8172cb826c5202a7dfaf0e66843896a7786a Mon Sep 17 00:00:00 2001 From: Morris Tseng Date: Wed, 4 Jun 2014 22:53:00 +0200 Subject: [PATCH] Bug 987718 - Part 2: Expose GetHintForPosition to nsFrameSelection; r=roc --- layout/base/nsCaret.cpp | 19 ++----------------- layout/generic/nsFrameSelection.h | 2 ++ layout/generic/nsSelection.cpp | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 47b68ad0484..59d484c44e5 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -411,22 +411,6 @@ void nsCaret::SetVisibilityDuringSelection(bool aVisibility) mShowDuringSelection = aVisibility; } -static -nsFrameSelection::HINT GetHintForPosition(nsIDOMNode* aNode, int32_t aOffset) -{ - nsFrameSelection::HINT hint = nsFrameSelection::HINTLEFT; - nsCOMPtr 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); @@ -442,8 +426,9 @@ nsresult nsCaret::DrawAtPosition(nsIDOMNode* aNode, int32_t aOffset) // ourselves, our consumer will take care of that. mBlinkRate = 0; + nsCOMPtr node = do_QueryInterface(aNode); nsresult rv = DrawAtPositionWithHint(aNode, aOffset, - GetHintForPosition(aNode, aOffset), + nsFrameSelection::GetHintForPosition(node, aOffset), bidiLevel, true) ? NS_OK : NS_ERROR_FAILURE; ToggleDrawnStatus(); diff --git a/layout/generic/nsFrameSelection.h b/layout/generic/nsFrameSelection.h index a751dd0139d..4bb19a915e0 100644 --- a/layout/generic/nsFrameSelection.h +++ b/layout/generic/nsFrameSelection.h @@ -591,6 +591,8 @@ public: void DisconnectFromPresShell(); nsresult ClearNormalSelection(); + + static HINT GetHintForPosition(nsIContent* aContent, int32_t aOffset); private: nsresult TakeFocus(nsIContent *aNewFocus, uint32_t aContentOffset, diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 33d06e14f0b..60a83f2e5f2 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -684,6 +684,20 @@ GetCellParent(nsINode *aDomNode) 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)