Bug 1734771 - part 3: Make `AppendString()` and `AppendSubString()` take `const Text&` instead of `Text*` r=m_kato

Depends on D128139

Differential Revision: https://phabricator.services.mozilla.com/D128140
This commit is contained in:
Masayuki Nakano 2021-10-12 15:02:38 +00:00
Родитель 383080bb17
Коммит fc532efa09
6 изменённых файлов: 26 добавлений и 26 удалений

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

@ -7120,7 +7120,7 @@ EditorBase* nsContentUtils::GetActiveEditor(nsPIDOMWindowOuter* aWindow) {
// static
TextEditor* nsContentUtils::GetTextEditorFromAnonymousNodeWithoutCreation(
nsIContent* aAnonymousContent) {
const nsIContent* aAnonymousContent) {
if (!aAnonymousContent) {
return nullptr;
}

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

@ -2704,7 +2704,7 @@ class nsContentUtils {
* `aAnonymousContent` hasn't been created yet.
*/
static mozilla::TextEditor* GetTextEditorFromAnonymousNodeWithoutCreation(
nsIContent* aAnonymousContent);
const nsIContent* aAnonymousContent);
/**
* Returns whether a node has an editable ancestor.

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

@ -508,20 +508,20 @@ static void ConvertToNativeNewlines(nsString& aString) {
#endif
}
static void AppendString(nsString& aString, Text* aText) {
uint32_t oldXPLength = aString.Length();
aText->TextFragment().AppendTo(aString);
if (aText->HasFlag(NS_MAYBE_MASKED)) {
EditorUtils::MaskString(aString, aText, oldXPLength, 0);
static void AppendString(nsString& aString, const Text& aTextNode) {
const uint32_t oldXPLength = aString.Length();
aTextNode.TextFragment().AppendTo(aString);
if (aTextNode.HasFlag(NS_MAYBE_MASKED)) {
EditorUtils::MaskString(aString, aTextNode, oldXPLength, 0);
}
}
static void AppendSubString(nsString& aString, Text* aText, uint32_t aXPOffset,
uint32_t aXPLength) {
static void AppendSubString(nsString& aString, const Text& aTextNode,
uint32_t aXPOffset, uint32_t aXPLength) {
const uint32_t oldXPLength = aString.Length();
aText->TextFragment().AppendTo(aString, aXPOffset, aXPLength);
if (aText->HasFlag(NS_MAYBE_MASKED)) {
EditorUtils::MaskString(aString, aText, oldXPLength, aXPOffset);
aTextNode.TextFragment().AppendTo(aString, aXPOffset, aXPLength);
if (aTextNode.HasFlag(NS_MAYBE_MASKED)) {
EditorUtils::MaskString(aString, aTextNode, oldXPLength, aXPOffset);
}
}
@ -724,7 +724,7 @@ nsresult ContentEventHandler::GenerateFlatTextContent(
}
if (startNode == endNode && startNode->IsText()) {
AppendSubString(aString, startNode->AsText(), aRawRange.StartOffset(),
AppendSubString(aString, *startNode->AsText(), aRawRange.StartOffset(),
aRawRange.EndOffset() - aRawRange.StartOffset());
ConvertToNativeNewlines(aString);
return NS_OK;
@ -745,14 +745,14 @@ nsresult ContentEventHandler::GenerateFlatTextContent(
continue;
}
if (node->IsText()) {
if (node == startNode) {
AppendSubString(aString, node->AsText(), aRawRange.StartOffset(),
node->AsText()->TextLength() - aRawRange.StartOffset());
} else if (node == endNode) {
AppendSubString(aString, node->AsText(), 0, aRawRange.EndOffset());
if (const Text* textNode = Text::FromNode(node)) {
if (textNode == startNode) {
AppendSubString(aString, *textNode, aRawRange.StartOffset(),
textNode->TextLength() - aRawRange.StartOffset());
} else if (textNode == endNode) {
AppendSubString(aString, *textNode, 0, aRawRange.EndOffset());
} else {
AppendString(aString, node->AsText());
AppendString(aString, *textNode);
}
} else if (ShouldBreakLineBefore(node->AsContent(), mRootContent)) {
aString.Append(char16_t('\n'));
@ -1911,7 +1911,7 @@ nsresult ContentEventHandler::OnQueryTextRectArray(
}
// Assign the characters whose rects are computed by the call of
// nsTextFrame::GetCharacterRectsInRange().
AppendSubString(chars, firstContent->AsText(), firstFrame.mOffsetInNode,
AppendSubString(chars, *firstContent->AsText(), firstFrame.mOffsetInNode,
charRects.Length());
if (NS_WARN_IF(chars.Length() != charRects.Length())) {
return NS_ERROR_UNEXPECTED;

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

@ -436,7 +436,7 @@ nsPlainTextSerializer::AppendText(nsIContent* aText, int32_t aStartOffset,
// Mask the text if the text node is in a password field.
if (content->HasFlag(NS_MAYBE_MASKED)) {
EditorUtils::MaskString(textstr, content->AsText(), 0, aStartOffset);
EditorUtils::MaskString(textstr, *content->AsText(), 0, aStartOffset);
}
// We have to split the string across newlines

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

@ -482,15 +482,15 @@ bool EditorUtils::IsDescendantOf(const nsINode& aNode, const nsINode& aParent,
}
// static
void EditorUtils::MaskString(nsString& aString, Text* aText,
void EditorUtils::MaskString(nsString& aString, const Text& aTextNode,
uint32_t aStartOffsetInString,
uint32_t aStartOffsetInText) {
MOZ_ASSERT(aText->HasFlag(NS_MAYBE_MASKED));
MOZ_ASSERT(aTextNode.HasFlag(NS_MAYBE_MASKED));
MOZ_ASSERT(aStartOffsetInString == 0 || aStartOffsetInText == 0);
uint32_t unmaskStart = UINT32_MAX, unmaskLength = 0;
TextEditor* textEditor =
nsContentUtils::GetTextEditorFromAnonymousNodeWithoutCreation(aText);
nsContentUtils::GetTextEditorFromAnonymousNodeWithoutCreation(&aTextNode);
if (textEditor && textEditor->UnmaskedLength() > 0) {
unmaskStart = textEditor->UnmaskedStart();
unmaskLength = textEditor->UnmaskedLength();

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

@ -1186,7 +1186,7 @@ class EditorUtils final {
* been copied (apppended) to `aString`. `aStartOffsetInString` is where
* the password was appended into `aString`.
*/
static void MaskString(nsString& aString, dom::Text* aText,
static void MaskString(nsString& aString, const dom::Text& aTextNode,
uint32_t aStartOffsetInString,
uint32_t aStartOffsetInText);