Bug 1275914 part.6 ContentEventHandler::OnQuerySelectedText() shouldn't refer anchor and focus of selection if there are 2 or more selection ranges r=smaug

Selection's focus and anchor node and offset are stored only for the last range.  However, ContentEventHandler needs its first range.  Therefore, ContentEventHandler shouldn't refer them if there are two or more selection ranges.

MozReview-Commit-ID: ACflFE3ZrOM

--HG--
extra : rebase_source : 9a2d1ef0e18a07881f77deff579830a4a0c97fc5
This commit is contained in:
Masayuki Nakano 2016-06-11 22:22:10 +09:00
Родитель 4e5c167f73
Коммит 99f2ffe496
1 изменённых файлов: 26 добавлений и 30 удалений

Просмотреть файл

@ -1233,37 +1233,33 @@ ContentEventHandler::OnQuerySelectedText(WidgetQueryContentEvent* aEvent)
nsCOMPtr<nsINode> anchorNode, focusNode;
int32_t anchorOffset, focusOffset;
if (mSelection->RangeCount()) {
anchorNode = mSelection->GetAnchorNode();
focusNode = mSelection->GetFocusNode();
if (NS_WARN_IF(!anchorNode) || NS_WARN_IF(!focusNode)) {
return NS_ERROR_FAILURE;
}
anchorOffset = static_cast<int32_t>(mSelection->AnchorOffset());
focusOffset = static_cast<int32_t>(mSelection->FocusOffset());
if (NS_WARN_IF(anchorOffset < 0) || NS_WARN_IF(focusOffset < 0)) {
return NS_ERROR_FAILURE;
}
int16_t compare = nsContentUtils::ComparePoints(anchorNode, anchorOffset,
focusNode, focusOffset);
aEvent->mReply.mReversed = compare > 0;
if (compare) {
RefPtr<nsRange> range;
if (mSelection->RangeCount() == 1) {
range = mFirstSelectedRange;
} else {
rv = nsRange::CreateRange(anchorNode, anchorOffset,
focusNode, focusOffset,
getter_AddRefs(range));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (NS_WARN_IF(!range)) {
return NS_ERROR_FAILURE;
}
// If there is only one selection range, the anchor/focus node and offset
// are the information of the range. Therefore, we have the direction
// information.
if (mSelection->RangeCount() == 1) {
anchorNode = mSelection->GetAnchorNode();
focusNode = mSelection->GetFocusNode();
if (NS_WARN_IF(!anchorNode) || NS_WARN_IF(!focusNode)) {
return NS_ERROR_FAILURE;
}
rv = GenerateFlatTextContent(range, aEvent->mReply.mString,
anchorOffset = static_cast<int32_t>(mSelection->AnchorOffset());
focusOffset = static_cast<int32_t>(mSelection->FocusOffset());
if (NS_WARN_IF(anchorOffset < 0) || NS_WARN_IF(focusOffset < 0)) {
return NS_ERROR_FAILURE;
}
int16_t compare = nsContentUtils::ComparePoints(anchorNode, anchorOffset,
focusNode, focusOffset);
aEvent->mReply.mReversed = compare > 0;
}
// However, if there are 2 or more selection ranges, we have no information
// of that.
else {
aEvent->mReply.mReversed = false;
}
if (!mFirstSelectedRange->Collapsed()) {
rv = GenerateFlatTextContent(mFirstSelectedRange, aEvent->mReply.mString,
lineBreakType);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;