@@ -542,20 +542,20 @@ static uint32_t CountNewlinesInXPLength(const Text& aTextNode,
542
542
return newlines;
543
543
}
544
544
545
- static uint32_t CountNewlinesInNativeLength (Text* aText ,
545
+ static uint32_t CountNewlinesInNativeLength (const Text& aTextNode ,
546
546
uint32_t aNativeLength) {
547
- const nsTextFragment* text = &aText-> TextFragment ();
547
+ const nsTextFragment& textFragment = aTextNode. TextFragment ();
548
548
// For automated tests, we should abort on debug build.
549
- MOZ_ASSERT (
550
- (aNativeLength == UINT32_MAX || aNativeLength <= text-> GetLength () * 2 ),
551
- " aNativeLength is unexpected value" );
552
- const uint32_t xpLength = text-> GetLength ();
549
+ MOZ_ASSERT ((aNativeLength == UINT32_MAX ||
550
+ aNativeLength <= textFragment. GetLength () * 2 ),
551
+ " aNativeLength is unexpected value" );
552
+ const uint32_t xpLength = textFragment. GetLength ();
553
553
uint32_t newlines = 0 ;
554
554
for (uint32_t i = 0 , nativeOffset = 0 ;
555
555
i < xpLength && nativeOffset < aNativeLength; ++i, ++nativeOffset) {
556
556
// For automated tests, we should abort on debug build.
557
- MOZ_ASSERT (i < text-> GetLength () , " i is out-of-bounds" );
558
- if (text-> CharAt (i) == ' \n ' ) {
557
+ MOZ_ASSERT (i < xpLength , " i is out-of-bounds" );
558
+ if (textFragment. CharAt (i) == ' \n ' ) {
559
559
++newlines;
560
560
++nativeOffset;
561
561
}
@@ -615,14 +615,13 @@ uint32_t ContentEventHandler::GetTextLength(const Text& aTextNode,
615
615
return length + textLengthDifference;
616
616
}
617
617
618
- static uint32_t ConvertToXPOffset (nsIContent* aContent ,
618
+ static uint32_t ConvertToXPOffset (const Text& aTextNode ,
619
619
uint32_t aNativeOffset) {
620
620
#if defined(XP_WIN)
621
621
// On Windows, the length of a native newline ("\r\n") is twice the length of
622
622
// the XP newline ("\n"), so XP offset is equal to the length of the native
623
623
// offset minus the number of newlines encountered in the string.
624
- return aNativeOffset -
625
- CountNewlinesInNativeLength (aContent->AsText (), aNativeOffset);
624
+ return aNativeOffset - CountNewlinesInNativeLength (aTextNode, aNativeOffset);
626
625
#else
627
626
// On other platforms, the native and XP newlines are the same.
628
627
return aNativeOffset;
@@ -1057,16 +1056,16 @@ nsresult ContentEventHandler::SetRawRangeFromFlatTextOffset(
1057
1056
if (!startSet && aOffset <= offset + textLength) {
1058
1057
nsINode* startNode = nullptr ;
1059
1058
int32_t startNodeOffset = -1 ;
1060
- if (content-> IsText ( )) {
1059
+ if (Text* textNode = Text::FromNode (content )) {
1061
1060
// Rule #1.1: [textNode or text[Node or textNode[
1062
1061
uint32_t xpOffset = aOffset - offset;
1063
1062
if (aLineBreakType == LINE_BREAK_TYPE_NATIVE) {
1064
- xpOffset = ConvertToXPOffset (content , xpOffset);
1063
+ xpOffset = ConvertToXPOffset (*textNode , xpOffset);
1065
1064
}
1066
1065
1067
1066
if (aExpandToClusterBoundaries) {
1068
1067
uint32_t oldXPOffset = xpOffset;
1069
- rv = ExpandToClusterBoundary (content , false , &xpOffset);
1068
+ nsresult rv = ExpandToClusterBoundary (textNode , false , &xpOffset);
1070
1069
if (NS_WARN_IF(NS_FAILED(rv))) {
1071
1070
return rv;
1072
1071
}
@@ -1075,7 +1074,7 @@ nsresult ContentEventHandler::SetRawRangeFromFlatTextOffset(
1075
1074
*aNewOffset -= (oldXPOffset - xpOffset);
1076
1075
}
1077
1076
}
1078
- startNode = content ;
1077
+ startNode = textNode ;
1079
1078
startNodeOffset = static_cast <int32_t >(xpOffset);
1080
1079
} else if (aOffset < offset + textLength) {
1081
1080
// Rule #1.2 [<element>
@@ -1128,14 +1127,14 @@ nsresult ContentEventHandler::SetRawRangeFromFlatTextOffset(
1128
1127
// range.
1129
1128
if (endOffset <= offset + textLength) {
1130
1129
MOZ_ASSERT (startSet, " The start of the range should've been set already" );
1131
- if (content-> IsText ( )) {
1130
+ if (Text* textNode = Text::FromNode (content )) {
1132
1131
// Rule #2.1: ]textNode or text]Node or textNode]
1133
1132
uint32_t xpOffset = endOffset - offset;
1134
1133
if (aLineBreakType == LINE_BREAK_TYPE_NATIVE) {
1135
- uint32_t xpOffsetCurrent = ConvertToXPOffset (content , xpOffset);
1134
+ uint32_t xpOffsetCurrent = ConvertToXPOffset (*textNode , xpOffset);
1136
1135
if (xpOffset && GetBRLength (aLineBreakType) > 1 ) {
1137
1136
MOZ_ASSERT (GetBRLength (aLineBreakType) == 2 );
1138
- uint32_t xpOffsetPre = ConvertToXPOffset (content , xpOffset - 1 );
1137
+ uint32_t xpOffsetPre = ConvertToXPOffset (*textNode , xpOffset - 1 );
1139
1138
// If previous character's XP offset is same as current character's,
1140
1139
// it means that the end offset is between \r and \n. So, the
1141
1140
// range end should be after the \n.
@@ -1147,13 +1146,13 @@ nsresult ContentEventHandler::SetRawRangeFromFlatTextOffset(
1147
1146
}
1148
1147
}
1149
1148
if (aExpandToClusterBoundaries) {
1150
- rv = ExpandToClusterBoundary (content , true , &xpOffset);
1149
+ nsresult rv = ExpandToClusterBoundary (textNode , true , &xpOffset);
1151
1150
if (NS_WARN_IF(NS_FAILED(rv))) {
1152
1151
return rv;
1153
1152
}
1154
1153
}
1155
1154
NS_ASSERTION (xpOffset <= INT32_MAX, " The end node offset is too large" );
1156
- rv = aRawRange->SetEnd (content , xpOffset);
1155
+ nsresult rv = aRawRange->SetEnd (textNode , xpOffset);
1157
1156
if (NS_WARN_IF(NS_FAILED(rv))) {
1158
1157
return rv;
1159
1158
}
0 commit comments