зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1713334 - Part 2: Initialize TextEditor always with a text node r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D117022
This commit is contained in:
Родитель
b327288d9d
Коммит
760acf8789
|
@ -339,9 +339,32 @@ nsresult EditorBase::Init(Document& aDocument, Element* aRoot,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult EditorBase::EnsureEmptyTextFirstChild() {
|
||||
MOZ_ASSERT(IsTextEditor());
|
||||
RefPtr<Element> root = GetRoot();
|
||||
nsIContent* firstChild = root->GetFirstChild();
|
||||
|
||||
if (!firstChild || !firstChild->IsText()) {
|
||||
RefPtr<nsTextNode> newTextNode = CreateTextNode(u""_ns);
|
||||
if (!newTextNode) {
|
||||
NS_WARNING("EditorBase::CreateTextNode() failed");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
IgnoredErrorResult ignoredError;
|
||||
root->InsertChildBefore(newTextNode, nullptr, true, ignoredError);
|
||||
MOZ_ASSERT(!ignoredError.Failed());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult EditorBase::InitEditorContentAndSelection() {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
if (IsTextEditor()) {
|
||||
MOZ_TRY(EnsureEmptyTextFirstChild());
|
||||
}
|
||||
|
||||
nsresult rv = MaybeCreatePaddingBRElementForEmptyEditor();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
|
|
|
@ -2240,6 +2240,8 @@ class EditorBase : public nsIEditor,
|
|||
return mIsHTMLEditorClass ? EditorType::HTML : EditorType::Text;
|
||||
}
|
||||
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult EnsureEmptyTextFirstChild();
|
||||
|
||||
/**
|
||||
* InitEditorContentAndSelection() may insert a padding `<br>` element for
|
||||
* if it's required in the anonymous `<div>` element or `<body>` element and
|
||||
|
|
|
@ -77,10 +77,9 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
|
|||
using EditorBase::CanPaste;
|
||||
|
||||
// Overrides of EditorBase
|
||||
MOZ_CAN_RUN_SCRIPT virtual nsresult Init(Document& aDoc, Element* aRoot,
|
||||
nsISelectionController* aSelCon,
|
||||
uint32_t aFlags,
|
||||
const nsAString& aValue) override;
|
||||
MOZ_CAN_RUN_SCRIPT virtual nsresult Init(
|
||||
Document& aDoc, Element* aRoot, nsISelectionController* aSelCon,
|
||||
uint32_t aFlags, const nsAString& aInitialValue) override;
|
||||
|
||||
bool IsEmpty() const override;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче