Bug 987718 - Part 2: Expose GetHintForPosition to nsFrameSelection; r=roc

This commit is contained in:
Morris Tseng 2014-06-04 22:53:00 +02:00
parent 3aa22d4895
commit 4dfb8172cb
3 changed files with 18 additions and 17 deletions

View File

@ -411,22 +411,6 @@ void nsCaret::SetVisibilityDuringSelection(bool aVisibility)
mShowDuringSelection = 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) nsresult nsCaret::DrawAtPosition(nsIDOMNode* aNode, int32_t aOffset)
{ {
NS_ENSURE_ARG(aNode); NS_ENSURE_ARG(aNode);
@ -442,8 +426,9 @@ nsresult nsCaret::DrawAtPosition(nsIDOMNode* aNode, int32_t aOffset)
// ourselves, our consumer will take care of that. // ourselves, our consumer will take care of that.
mBlinkRate = 0; mBlinkRate = 0;
nsCOMPtr<nsIContent> node = do_QueryInterface(aNode);
nsresult rv = DrawAtPositionWithHint(aNode, aOffset, nsresult rv = DrawAtPositionWithHint(aNode, aOffset,
GetHintForPosition(aNode, aOffset), nsFrameSelection::GetHintForPosition(node, aOffset),
bidiLevel, true) bidiLevel, true)
? NS_OK : NS_ERROR_FAILURE; ? NS_OK : NS_ERROR_FAILURE;
ToggleDrawnStatus(); ToggleDrawnStatus();

View File

@ -591,6 +591,8 @@ public:
void DisconnectFromPresShell(); void DisconnectFromPresShell();
nsresult ClearNormalSelection(); nsresult ClearNormalSelection();
static HINT GetHintForPosition(nsIContent* aContent, int32_t aOffset);
private: private:
nsresult TakeFocus(nsIContent *aNewFocus, nsresult TakeFocus(nsIContent *aNewFocus,
uint32_t aContentOffset, uint32_t aContentOffset,

View File

@ -684,6 +684,20 @@ GetCellParent(nsINode *aDomNode)
return nullptr; 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 void
nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter) nsFrameSelection::Init(nsIPresShell *aShell, nsIContent *aLimiter)