Bug 1286464 part.4 ContentEventHandler::SetRangeFromFlatTextOffset() should set end of the range to after a line break when the range is end between a set of native line breakers r=smaug

Currently, ContentEventHandler::SetRangeFromFlatTextOffset() sets end point to before a line breaker when the end of queried range is between a set of native line breakers (i.e., "\r]\n" on Windows). This causes unexpected empty range (e.g., "[]\n") when it queries a text rect at [\r]\n.

Therefore, it should select an XP line breaker in such case (i.e., the range should be "[\n]" when it queries "[\r]\n" or "\r[\n]").

Note that we don't need to do anything at setting selection start because it's always aligned to before the line breaker.

MozReview-Commit-ID: 6ht8QNAhibY

--HG--
extra : rebase_source : b7933554c2a5bf51b8faabe3a96d006971510e0a
This commit is contained in:
Masayuki Nakano 2016-07-28 17:23:47 +09:00
parent 92692b4cb4
commit d8cc4e966b

View File

@ -1071,7 +1071,19 @@ ContentEventHandler::SetRangeFromFlatTextOffset(nsRange* aRange,
// Rule #2.1: ]textNode or text]Node or textNode]
uint32_t xpOffset = endOffset - offset;
if (aLineBreakType == LINE_BREAK_TYPE_NATIVE) {
xpOffset = ConvertToXPOffset(content, xpOffset);
uint32_t xpOffsetCurrent = ConvertToXPOffset(content, xpOffset);
if (xpOffset && GetBRLength(aLineBreakType) > 1) {
MOZ_ASSERT(GetBRLength(aLineBreakType) == 2);
uint32_t xpOffsetPre = ConvertToXPOffset(content, xpOffset - 1);
// If previous character's XP offset is same as current character's,
// it means that the end offset is between \r and \n. So, the
// range end should be after the \n.
if (xpOffsetPre == xpOffsetCurrent) {
xpOffset = xpOffsetCurrent + 1;
} else {
xpOffset = xpOffsetCurrent;
}
}
}
if (aExpandToClusterBoundaries) {
rv = ExpandToClusterBoundary(content, true, &xpOffset);