зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1649121: part 19) Add `HTMLWithContextInserter` and move content of `DoInsertHTMLWithContext` to it. r=masayuki
This is minimally invasive. In the following parts, methods will be moved to it and potentially other methods will be extracted. Differential Revision: https://phabricator.services.mozilla.com/D82384
This commit is contained in:
Родитель
1684d9040a
Коммит
b1c3499828
|
@ -4616,6 +4616,8 @@ class HTMLEditor final : public TextEditor,
|
||||||
EditorDOMPoint GetNewCaretPointAfterInsertingHTML(
|
EditorDOMPoint GetNewCaretPointAfterInsertingHTML(
|
||||||
const EditorDOMPoint& lastInsertedPoint) const;
|
const EditorDOMPoint& lastInsertedPoint) const;
|
||||||
|
|
||||||
|
class HTMLWithContextInserter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used to insert a string of HTML input optionally with some
|
* This function is used to insert a string of HTML input optionally with some
|
||||||
* context information into the editable field. The HTML input either comes
|
* context information into the editable field. The HTML input either comes
|
||||||
|
|
|
@ -200,6 +200,26 @@ nsresult HTMLEditor::InsertHTMLAsAction(const nsAString& aInString,
|
||||||
return EditorBase::ToGenericNSResult(rv);
|
return EditorBase::ToGenericNSResult(rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MOZ_STACK_CLASS HTMLEditor::HTMLWithContextInserter final {
|
||||||
|
public:
|
||||||
|
MOZ_CAN_RUN_SCRIPT explicit HTMLWithContextInserter(HTMLEditor& aHTMLEditor)
|
||||||
|
: mHTMLEditor(aHTMLEditor) {}
|
||||||
|
|
||||||
|
HTMLWithContextInserter() = delete;
|
||||||
|
HTMLWithContextInserter(const HTMLWithContextInserter&) = delete;
|
||||||
|
HTMLWithContextInserter(HTMLWithContextInserter&&) = delete;
|
||||||
|
|
||||||
|
MOZ_CAN_RUN_SCRIPT nsresult Run(const nsAString& aInputString,
|
||||||
|
const nsAString& aContextStr,
|
||||||
|
const nsAString& aInfoStr,
|
||||||
|
const EditorDOMPoint& aPointToInsert,
|
||||||
|
bool aDoDeleteSelection, bool aTrustedInput,
|
||||||
|
bool aClearStyle);
|
||||||
|
|
||||||
|
private:
|
||||||
|
HTMLEditor& mHTMLEditor;
|
||||||
|
};
|
||||||
|
|
||||||
EditorDOMPoint HTMLEditor::GetNewCaretPointAfterInsertingHTML(
|
EditorDOMPoint HTMLEditor::GetNewCaretPointAfterInsertingHTML(
|
||||||
const EditorDOMPoint& aLastInsertedPoint) const {
|
const EditorDOMPoint& aLastInsertedPoint) const {
|
||||||
EditorDOMPoint pointToPutCaret;
|
EditorDOMPoint pointToPutCaret;
|
||||||
|
@ -277,23 +297,36 @@ EditorDOMPoint HTMLEditor::GetNewCaretPointAfterInsertingHTML(
|
||||||
|
|
||||||
return pointToPutCaret;
|
return pointToPutCaret;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult HTMLEditor::DoInsertHTMLWithContext(
|
nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
const nsAString& aInputString, const nsAString& aContextStr,
|
const nsAString& aInputString, const nsAString& aContextStr,
|
||||||
const nsAString& aInfoStr, const nsAString& aFlavor, Document* aSourceDoc,
|
const nsAString& aInfoStr, const nsAString& aFlavor, Document* aSourceDoc,
|
||||||
const EditorDOMPoint& aPointToInsert, bool aDoDeleteSelection,
|
const EditorDOMPoint& aPointToInsert, bool aDoDeleteSelection,
|
||||||
bool aTrustedInput, bool aClearStyle) {
|
bool aTrustedInput, bool aClearStyle) {
|
||||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
HTMLWithContextInserter htmlWithContextInserter(*this);
|
||||||
|
|
||||||
if (NS_WARN_IF(!mInitSucceeded)) {
|
return htmlWithContextInserter.Run(aInputString, aContextStr, aInfoStr,
|
||||||
|
aPointToInsert, aDoDeleteSelection,
|
||||||
|
aTrustedInput, aClearStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult HTMLEditor::HTMLWithContextInserter::Run(
|
||||||
|
const nsAString& aInputString, const nsAString& aContextStr,
|
||||||
|
const nsAString& aInfoStr, const EditorDOMPoint& aPointToInsert,
|
||||||
|
bool aDoDeleteSelection, bool aTrustedInput, bool aClearStyle) {
|
||||||
|
MOZ_ASSERT(mHTMLEditor.IsEditActionDataAvailable());
|
||||||
|
|
||||||
|
if (NS_WARN_IF(!mHTMLEditor.mInitSucceeded)) {
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
return NS_ERROR_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// force IME commit; set up rules sniffing and batching
|
// force IME commit; set up rules sniffing and batching
|
||||||
CommitComposition();
|
mHTMLEditor.CommitComposition();
|
||||||
AutoPlaceholderBatch treatAsOneTransaction(*this);
|
AutoPlaceholderBatch treatAsOneTransaction(mHTMLEditor);
|
||||||
IgnoredErrorResult ignoredError;
|
IgnoredErrorResult ignoredError;
|
||||||
AutoEditSubActionNotifier startToHandleEditSubAction(
|
AutoEditSubActionNotifier startToHandleEditSubAction(
|
||||||
*this, EditSubAction::ePasteHTMLContent, nsIEditor::eNext, ignoredError);
|
MOZ_KnownLive(mHTMLEditor), EditSubAction::ePasteHTMLContent,
|
||||||
|
nsIEditor::eNext, ignoredError);
|
||||||
if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
|
if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {
|
||||||
return ignoredError.StealNSResult();
|
return ignoredError.StealNSResult();
|
||||||
}
|
}
|
||||||
|
@ -306,7 +339,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
nsCOMPtr<nsINode> fragmentAsNode, streamStartParent, streamEndParent;
|
nsCOMPtr<nsINode> fragmentAsNode, streamStartParent, streamEndParent;
|
||||||
int32_t streamStartOffset = 0, streamEndOffset = 0;
|
int32_t streamStartOffset = 0, streamEndOffset = 0;
|
||||||
|
|
||||||
nsresult rv = CreateDOMFragmentFromPaste(
|
nsresult rv = mHTMLEditor.CreateDOMFragmentFromPaste(
|
||||||
aInputString, aContextStr, aInfoStr, address_of(fragmentAsNode),
|
aInputString, aContextStr, aInfoStr, address_of(fragmentAsNode),
|
||||||
address_of(streamStartParent), address_of(streamEndParent),
|
address_of(streamStartParent), address_of(streamEndParent),
|
||||||
&streamStartOffset, &streamEndOffset, aTrustedInput);
|
&streamStartOffset, &streamEndOffset, aTrustedInput);
|
||||||
|
@ -322,7 +355,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// scenarios where we are dropping in an editor (and may want to delete
|
// scenarios where we are dropping in an editor (and may want to delete
|
||||||
// the selection before collapsing the selection in the new destination)
|
// the selection before collapsing the selection in the new destination)
|
||||||
if (aPointToInsert.IsSet()) {
|
if (aPointToInsert.IsSet()) {
|
||||||
rv = PrepareToInsertContent(aPointToInsert, aDoDeleteSelection);
|
rv = MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.PrepareToInsertContent(aPointToInsert, aDoDeleteSelection);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("HTMLEditor::PrepareToInsertContent() failed");
|
NS_WARNING("HTMLEditor::PrepareToInsertContent() failed");
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -357,7 +391,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// XXX What will this do? We've already called DeleteSelectionAsSubAtion()
|
// XXX What will this do? We've already called DeleteSelectionAsSubAtion()
|
||||||
// above if insertion point is specified.
|
// above if insertion point is specified.
|
||||||
if (aDoDeleteSelection) {
|
if (aDoDeleteSelection) {
|
||||||
nsresult rv = DeleteSelectionAsSubAction(eNone, eStrip);
|
nsresult rv =
|
||||||
|
MOZ_KnownLive(mHTMLEditor).DeleteSelectionAsSubAction(eNone, eStrip);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING(
|
NS_WARNING(
|
||||||
"EditorBase::DeleteSelectionAsSubAction(eNone, eStrip) failed");
|
"EditorBase::DeleteSelectionAsSubAction(eNone, eStrip) failed");
|
||||||
|
@ -370,7 +405,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// Are there any table elements in the list?
|
// Are there any table elements in the list?
|
||||||
// check for table cell selection mode
|
// check for table cell selection mode
|
||||||
bool cellSelectionMode = false;
|
bool cellSelectionMode = false;
|
||||||
RefPtr<Element> cellElement = GetFirstSelectedTableCellElement(ignoredError);
|
RefPtr<Element> cellElement =
|
||||||
|
mHTMLEditor.GetFirstSelectedTableCellElement(ignoredError);
|
||||||
if (cellElement) {
|
if (cellElement) {
|
||||||
cellSelectionMode = true;
|
cellSelectionMode = true;
|
||||||
}
|
}
|
||||||
|
@ -387,7 +423,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cellSelectionMode) {
|
if (!cellSelectionMode) {
|
||||||
rv = DeleteSelectionAndPrepareToCreateNode();
|
rv = MOZ_KnownLive(mHTMLEditor).DeleteSelectionAndPrepareToCreateNode();
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("HTMLEditor::DeleteSelectionAndPrepareToCreateNode() failed");
|
NS_WARNING("HTMLEditor::DeleteSelectionAndPrepareToCreateNode() failed");
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -395,8 +431,11 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
|
|
||||||
if (aClearStyle) {
|
if (aClearStyle) {
|
||||||
// pasting does not inherit local inline styles
|
// pasting does not inherit local inline styles
|
||||||
EditResult result = ClearStyleAt(
|
EditResult result =
|
||||||
EditorDOMPoint(SelectionRefPtr()->AnchorRef()), nullptr, nullptr);
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.ClearStyleAt(
|
||||||
|
EditorDOMPoint(mHTMLEditor.SelectionRefPtr()->AnchorRef()),
|
||||||
|
nullptr, nullptr);
|
||||||
if (result.Failed()) {
|
if (result.Failed()) {
|
||||||
NS_WARNING("HTMLEditor::ClearStyleAt() failed");
|
NS_WARNING("HTMLEditor::ClearStyleAt() failed");
|
||||||
return result.Rv();
|
return result.Rv();
|
||||||
|
@ -409,8 +448,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// Save current selection since DeleteTableCellWithTransaction() perturbs
|
// Save current selection since DeleteTableCellWithTransaction() perturbs
|
||||||
// it.
|
// it.
|
||||||
{
|
{
|
||||||
AutoSelectionRestorer restoreSelectionLater(*this);
|
AutoSelectionRestorer restoreSelectionLater(mHTMLEditor);
|
||||||
rv = DeleteTableCellWithTransaction(1);
|
rv = MOZ_KnownLive(mHTMLEditor).DeleteTableCellWithTransaction(1);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("HTMLEditor::DeleteTableCellWithTransaction(1) failed");
|
NS_WARNING("HTMLEditor::DeleteTableCellWithTransaction(1) failed");
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -418,26 +457,26 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
}
|
}
|
||||||
// collapse selection to beginning of deleted table content
|
// collapse selection to beginning of deleted table content
|
||||||
IgnoredErrorResult ignoredError;
|
IgnoredErrorResult ignoredError;
|
||||||
SelectionRefPtr()->CollapseToStart(ignoredError);
|
mHTMLEditor.SelectionRefPtr()->CollapseToStart(ignoredError);
|
||||||
NS_WARNING_ASSERTION(!ignoredError.Failed(),
|
NS_WARNING_ASSERTION(!ignoredError.Failed(),
|
||||||
"Selection::Collapse() failed, but ignored");
|
"Selection::Collapse() failed, but ignored");
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX Why don't we test this first?
|
// XXX Why don't we test this first?
|
||||||
if (IsReadonly()) {
|
if (mHTMLEditor.IsReadonly()) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
EditActionResult result = mHTMLEditor.CanHandleHTMLEditSubAction();
|
||||||
if (result.Failed() || result.Canceled()) {
|
if (result.Failed() || result.Canceled()) {
|
||||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||||
return result.Rv();
|
return result.Rv();
|
||||||
}
|
}
|
||||||
|
|
||||||
UndefineCaretBidiLevel();
|
mHTMLEditor.UndefineCaretBidiLevel();
|
||||||
|
|
||||||
rv = EnsureNoPaddingBRElementForEmptyEditor();
|
rv = MOZ_KnownLive(mHTMLEditor).EnsureNoPaddingBRElementForEmptyEditor();
|
||||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
|
@ -445,8 +484,9 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
"EditorBase::EnsureNoPaddingBRElementForEmptyEditor() "
|
"EditorBase::EnsureNoPaddingBRElementForEmptyEditor() "
|
||||||
"failed, but ignored");
|
"failed, but ignored");
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && SelectionRefPtr()->IsCollapsed()) {
|
if (NS_SUCCEEDED(rv) && mHTMLEditor.SelectionRefPtr()->IsCollapsed()) {
|
||||||
nsresult rv = EnsureCaretNotAfterPaddingBRElement();
|
nsresult rv =
|
||||||
|
MOZ_KnownLive(mHTMLEditor).EnsureCaretNotAfterPaddingBRElement();
|
||||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +494,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
"HTMLEditor::EnsureCaretNotAfterPaddingBRElement() "
|
"HTMLEditor::EnsureCaretNotAfterPaddingBRElement() "
|
||||||
"failed, but ignored");
|
"failed, but ignored");
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
nsresult rv = PrepareInlineStylesForCaret();
|
nsresult rv = MOZ_KnownLive(mHTMLEditor).PrepareInlineStylesForCaret();
|
||||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
|
@ -465,9 +505,9 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust position based on the first node we are going to insert.
|
// Adjust position based on the first node we are going to insert.
|
||||||
EditorDOMPoint pointToInsert =
|
EditorDOMPoint pointToInsert = mHTMLEditor.GetBetterInsertionPointFor(
|
||||||
GetBetterInsertionPointFor(arrayOfTopMostChildContents[0],
|
arrayOfTopMostChildContents[0],
|
||||||
EditorBase::GetStartPoint(*SelectionRefPtr()));
|
EditorBase::GetStartPoint(*mHTMLEditor.SelectionRefPtr()));
|
||||||
if (!pointToInsert.IsSet()) {
|
if (!pointToInsert.IsSet()) {
|
||||||
NS_WARNING("HTMLEditor::GetBetterInsertionPointFor() failed");
|
NS_WARNING("HTMLEditor::GetBetterInsertionPointFor() failed");
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
@ -476,14 +516,16 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// Remove invisible `<br>` element at the point because if there is a `<br>`
|
// Remove invisible `<br>` element at the point because if there is a `<br>`
|
||||||
// element at end of what we paste, it will make the existing invisible
|
// element at end of what we paste, it will make the existing invisible
|
||||||
// `<br>` element visible.
|
// `<br>` element visible.
|
||||||
WSRunScanner wsRunScannerAtInsertionPoint(this, pointToInsert);
|
WSRunScanner wsRunScannerAtInsertionPoint(&mHTMLEditor, pointToInsert);
|
||||||
if (wsRunScannerAtInsertionPoint.GetEndReasonContent() &&
|
if (wsRunScannerAtInsertionPoint.GetEndReasonContent() &&
|
||||||
wsRunScannerAtInsertionPoint.GetEndReasonContent()->IsHTMLElement(
|
wsRunScannerAtInsertionPoint.GetEndReasonContent()->IsHTMLElement(
|
||||||
nsGkAtoms::br) &&
|
nsGkAtoms::br) &&
|
||||||
!IsVisibleBRElement(wsRunScannerAtInsertionPoint.GetEndReasonContent())) {
|
!mHTMLEditor.IsVisibleBRElement(
|
||||||
|
wsRunScannerAtInsertionPoint.GetEndReasonContent())) {
|
||||||
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
|
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
|
||||||
nsresult rv = DeleteNodeWithTransaction(
|
nsresult rv = MOZ_KnownLive(mHTMLEditor)
|
||||||
MOZ_KnownLive(*wsRunScannerAtInsertionPoint.GetEndReasonContent()));
|
.DeleteNodeWithTransaction(MOZ_KnownLive(
|
||||||
|
*wsRunScannerAtInsertionPoint.GetEndReasonContent()));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed");
|
NS_WARNING("HTMLEditor::DeleteNodeWithTransaction() failed");
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -491,12 +533,14 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool insertionPointWasInLink =
|
const bool insertionPointWasInLink =
|
||||||
!!GetLinkElement(pointToInsert.GetContainer());
|
!!HTMLEditor::GetLinkElement(pointToInsert.GetContainer());
|
||||||
|
|
||||||
if (pointToInsert.IsInTextNode()) {
|
if (pointToInsert.IsInTextNode()) {
|
||||||
SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
|
SplitNodeResult splitNodeResult =
|
||||||
MOZ_KnownLive(*pointToInsert.GetContainerAsContent()), pointToInsert,
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
SplitAtEdges::eAllowToCreateEmptyContainer);
|
.SplitNodeDeepWithTransaction(
|
||||||
|
MOZ_KnownLive(*pointToInsert.GetContainerAsContent()),
|
||||||
|
pointToInsert, SplitAtEdges::eAllowToCreateEmptyContainer);
|
||||||
if (splitNodeResult.Failed()) {
|
if (splitNodeResult.Failed()) {
|
||||||
NS_WARNING("HTMLEditor::SplitNodeDeepWithTransaction() failed");
|
NS_WARNING("HTMLEditor::SplitNodeDeepWithTransaction() failed");
|
||||||
return splitNodeResult.Rv();
|
return splitNodeResult.Rv();
|
||||||
|
@ -559,7 +603,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
for (nsCOMPtr<nsIContent> firstChild = content->GetFirstChild();
|
for (nsCOMPtr<nsIContent> firstChild = content->GetFirstChild();
|
||||||
firstChild; firstChild = content->GetFirstChild()) {
|
firstChild; firstChild = content->GetFirstChild()) {
|
||||||
EditorDOMPoint insertedPoint =
|
EditorDOMPoint insertedPoint =
|
||||||
InsertNodeIntoProperAncestorWithTransaction(
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.InsertNodeIntoProperAncestorWithTransaction(
|
||||||
*firstChild, pointToInsert,
|
*firstChild, pointToInsert,
|
||||||
SplitAtEdges::eDoNotCreateEmptyContainer);
|
SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||||
if (!insertedPoint.IsSet()) {
|
if (!insertedPoint.IsSet()) {
|
||||||
|
@ -596,14 +641,16 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// is not proper child of the parent element, or current node
|
// is not proper child of the parent element, or current node
|
||||||
// is a list element.
|
// is a list element.
|
||||||
if (HTMLEditUtils::IsListItem(pointToInsert.GetContainer()) &&
|
if (HTMLEditUtils::IsListItem(pointToInsert.GetContainer()) &&
|
||||||
IsEmptyNode(*pointToInsert.GetContainer(), true)) {
|
mHTMLEditor.IsEmptyNode(*pointToInsert.GetContainer(), true)) {
|
||||||
NS_WARNING_ASSERTION(pointToInsert.GetContainerParent(),
|
NS_WARNING_ASSERTION(pointToInsert.GetContainerParent(),
|
||||||
"Insertion point is out of the DOM tree");
|
"Insertion point is out of the DOM tree");
|
||||||
if (pointToInsert.GetContainerParent()) {
|
if (pointToInsert.GetContainerParent()) {
|
||||||
pointToInsert.Set(pointToInsert.GetContainer());
|
pointToInsert.Set(pointToInsert.GetContainer());
|
||||||
MOZ_ASSERT(pointToInsert.IsSet());
|
MOZ_ASSERT(pointToInsert.IsSet());
|
||||||
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
|
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
|
||||||
DebugOnly<nsresult> rvIgnored = DeleteNodeWithTransaction(
|
DebugOnly<nsresult> rvIgnored =
|
||||||
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.DeleteNodeWithTransaction(
|
||||||
MOZ_KnownLive(*pointToInsert.GetChild()));
|
MOZ_KnownLive(*pointToInsert.GetChild()));
|
||||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
|
||||||
"HTMLEditor::DeleteNodeWithTransaction() "
|
"HTMLEditor::DeleteNodeWithTransaction() "
|
||||||
|
@ -611,7 +658,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EditorDOMPoint insertedPoint =
|
EditorDOMPoint insertedPoint =
|
||||||
InsertNodeIntoProperAncestorWithTransaction(
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.InsertNodeIntoProperAncestorWithTransaction(
|
||||||
*firstChild, pointToInsert,
|
*firstChild, pointToInsert,
|
||||||
SplitAtEdges::eDoNotCreateEmptyContainer);
|
SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||||
if (!insertedPoint.IsSet()) {
|
if (!insertedPoint.IsSet()) {
|
||||||
|
@ -649,7 +697,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
for (nsCOMPtr<nsIContent> firstChild = content->GetFirstChild();
|
for (nsCOMPtr<nsIContent> firstChild = content->GetFirstChild();
|
||||||
firstChild; firstChild = content->GetFirstChild()) {
|
firstChild; firstChild = content->GetFirstChild()) {
|
||||||
EditorDOMPoint insertedPoint =
|
EditorDOMPoint insertedPoint =
|
||||||
InsertNodeIntoProperAncestorWithTransaction(
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.InsertNodeIntoProperAncestorWithTransaction(
|
||||||
*firstChild, pointToInsert,
|
*firstChild, pointToInsert,
|
||||||
SplitAtEdges::eDoNotCreateEmptyContainer);
|
SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||||
if (!insertedPoint.IsSet()) {
|
if (!insertedPoint.IsSet()) {
|
||||||
|
@ -675,7 +724,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// MOZ_KnownLive because 'arrayOfTopMostChildContents' is guaranteed to
|
// MOZ_KnownLive because 'arrayOfTopMostChildContents' is guaranteed to
|
||||||
// keep it alive.
|
// keep it alive.
|
||||||
EditorDOMPoint insertedPoint =
|
EditorDOMPoint insertedPoint =
|
||||||
InsertNodeIntoProperAncestorWithTransaction(
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.InsertNodeIntoProperAncestorWithTransaction(
|
||||||
MOZ_KnownLive(content), pointToInsert,
|
MOZ_KnownLive(content), pointToInsert,
|
||||||
SplitAtEdges::eDoNotCreateEmptyContainer);
|
SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||||
NS_WARNING_ASSERTION(
|
NS_WARNING_ASSERTION(
|
||||||
|
@ -703,7 +753,8 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
}
|
}
|
||||||
OwningNonNull<nsIContent> oldParentContent(
|
OwningNonNull<nsIContent> oldParentContent(
|
||||||
*childContent->GetParent());
|
*childContent->GetParent());
|
||||||
insertedPoint = InsertNodeIntoProperAncestorWithTransaction(
|
insertedPoint = MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.InsertNodeIntoProperAncestorWithTransaction(
|
||||||
oldParentContent, pointToInsert,
|
oldParentContent, pointToInsert,
|
||||||
SplitAtEdges::eDoNotCreateEmptyContainer);
|
SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||||
NS_WARNING_ASSERTION(
|
NS_WARNING_ASSERTION(
|
||||||
|
@ -740,9 +791,9 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditorDOMPoint pointToPutCaret =
|
const EditorDOMPoint pointToPutCaret =
|
||||||
GetNewCaretPointAfterInsertingHTML(lastInsertedPoint);
|
mHTMLEditor.GetNewCaretPointAfterInsertingHTML(lastInsertedPoint);
|
||||||
// Now collapse the selection to the end of what we just inserted.
|
// Now collapse the selection to the end of what we just inserted.
|
||||||
rv = CollapseSelectionTo(pointToPutCaret);
|
rv = MOZ_KnownLive(mHTMLEditor).CollapseSelectionTo(pointToPutCaret);
|
||||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
|
@ -763,15 +814,19 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||||
// above just placed selection inside that. So we need to split it instead.
|
// above just placed selection inside that. So we need to split it instead.
|
||||||
// XXX Sounds like that it's not really expensive comparing with the reason
|
// XXX Sounds like that it's not really expensive comparing with the reason
|
||||||
// to use SplitNodeDeepWithTransaction() here.
|
// to use SplitNodeDeepWithTransaction() here.
|
||||||
SplitNodeResult splitLinkResult = SplitNodeDeepWithTransaction(
|
SplitNodeResult splitLinkResult =
|
||||||
*linkElement, pointToPutCaret, SplitAtEdges::eDoNotCreateEmptyContainer);
|
MOZ_KnownLive(mHTMLEditor)
|
||||||
|
.SplitNodeDeepWithTransaction(
|
||||||
|
*linkElement, pointToPutCaret,
|
||||||
|
SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||||
NS_WARNING_ASSERTION(
|
NS_WARNING_ASSERTION(
|
||||||
splitLinkResult.Succeeded(),
|
splitLinkResult.Succeeded(),
|
||||||
"HTMLEditor::SplitNodeDeepWithTransaction() failed, but ignored");
|
"HTMLEditor::SplitNodeDeepWithTransaction() failed, but ignored");
|
||||||
if (splitLinkResult.GetPreviousNode()) {
|
if (splitLinkResult.GetPreviousNode()) {
|
||||||
EditorRawDOMPoint afterLeftLink(splitLinkResult.GetPreviousNode());
|
EditorRawDOMPoint afterLeftLink(splitLinkResult.GetPreviousNode());
|
||||||
if (afterLeftLink.AdvanceOffset()) {
|
if (afterLeftLink.AdvanceOffset()) {
|
||||||
nsresult rv = CollapseSelectionTo(afterLeftLink);
|
nsresult rv =
|
||||||
|
MOZ_KnownLive(mHTMLEditor).CollapseSelectionTo(afterLeftLink);
|
||||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||||
return NS_ERROR_EDITOR_DESTROYED;
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче