@@ -941,24 +941,22 @@ nsresult ContentEventHandler::GenerateFlatFontRanges(
941
941
return NS_OK;
942
942
}
943
943
944
- nsresult ContentEventHandler::ExpandToClusterBoundary (nsIContent* aContent,
945
- bool aForward,
946
- uint32_t * aXPOffset) {
944
+ nsresult ContentEventHandler::ExpandToClusterBoundary (
945
+ Text& aTextNode, bool aForward, uint32_t * aXPOffset) const {
947
946
// XXX This method assumes that the frame boundaries must be cluster
948
947
// boundaries. It's false, but no problem now, maybe.
949
- if (!aContent->IsText () || *aXPOffset == 0 ||
950
- *aXPOffset == aContent->TextLength ()) {
948
+ if (*aXPOffset == 0 || *aXPOffset == aTextNode.TextLength ()) {
951
949
return NS_OK;
952
950
}
953
951
954
- NS_ASSERTION (*aXPOffset <= aContent-> TextLength (), "offset is out of range.");
952
+ NS_ASSERTION (*aXPOffset <= aTextNode. TextLength(), "offset is out of range.");
955
953
956
954
MOZ_DIAGNOSTIC_ASSERT (mDocument ->GetPresShell ());
957
955
int32_t offsetInFrame;
958
956
CaretAssociationHint hint =
959
957
aForward ? CARET_ASSOCIATE_BEFORE : CARET_ASSOCIATE_AFTER;
960
958
nsIFrame* frame = nsFrameSelection::GetFrameForNodeOffset (
961
- aContent , int32_t (*aXPOffset), hint, &offsetInFrame);
959
+ &aTextNode , int32_t (*aXPOffset), hint, &offsetInFrame);
962
960
if (frame) {
963
961
auto [startOffset, endOffset] = frame->GetOffsets ();
964
962
if (*aXPOffset == static_cast <uint32_t >(startOffset) ||
@@ -986,9 +984,8 @@ nsresult ContentEventHandler::ExpandToClusterBoundary(nsIContent* aContent,
986
984
}
987
985
988
986
// If the frame isn't available, we only can check surrogate pair...
989
- const nsTextFragment* text = &aContent->AsText ()->TextFragment ();
990
- NS_ENSURE_TRUE (text, NS_ERROR_FAILURE);
991
- if (text->IsLowSurrogateFollowingHighSurrogateAt (*aXPOffset)) {
987
+ if (aTextNode.TextFragment ().IsLowSurrogateFollowingHighSurrogateAt (
988
+ *aXPOffset)) {
992
989
*aXPOffset += aForward ? 1 : -1 ;
993
990
}
994
991
return NS_OK;
@@ -1061,7 +1058,7 @@ nsresult ContentEventHandler::SetRawRangeFromFlatTextOffset(
1061
1058
1062
1059
if (aExpandToClusterBoundaries) {
1063
1060
uint32_t oldXPOffset = xpOffset;
1064
- nsresult rv = ExpandToClusterBoundary (textNode, false , &xpOffset);
1061
+ nsresult rv = ExpandToClusterBoundary (* textNode, false , &xpOffset);
1065
1062
if (NS_WARN_IF(NS_FAILED(rv))) {
1066
1063
return rv;
1067
1064
}
@@ -1142,7 +1139,7 @@ nsresult ContentEventHandler::SetRawRangeFromFlatTextOffset(
1142
1139
}
1143
1140
}
1144
1141
if (aExpandToClusterBoundaries) {
1145
- nsresult rv = ExpandToClusterBoundary (textNode, true , &xpOffset);
1142
+ nsresult rv = ExpandToClusterBoundary (* textNode, true , &xpOffset);
1146
1143
if (NS_WARN_IF(NS_FAILED(rv))) {
1147
1144
return rv;
1148
1145
}
0 commit comments