mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 04:38:02 +00:00
Bug 1791501 - Use EditActionResult
as ok type of mozilla::Result
r=m_kato
Any callers do not refer "ignored", "handled" and "cancel" state without checking whether the method returns error or not. Therefore, error state can be (and should be) managed by `mozilla::Result`'s error state. Perhaps, it should store a caret position later because deletion handlers of `HTMLEditor` use it, but update `Selection` immediately. Differential Revision: https://phabricator.services.mozilla.com/D158080
This commit is contained in:
parent
ebd19dfa4a
commit
bd1059c951
@ -1422,13 +1422,14 @@ nsresult EditorBase::ComputeValueInternal(const nsAString& aFormatType,
|
||||
// we need some complicated handling. In such case, we need to use the
|
||||
// expensive path.
|
||||
// XXX Anything else what we cannot return the text node data simply?
|
||||
EditActionResult result =
|
||||
Result<EditActionResult, nsresult> result =
|
||||
AsTextEditor()->ComputeValueFromTextNodeAndBRElement(aOutputString);
|
||||
if (result.Failed() || result.Canceled() || result.Handled()) {
|
||||
NS_WARNING_ASSERTION(
|
||||
result.Succeeded(),
|
||||
"TextEditor::ComputeValueFromTextNodeAndBRElement() failed");
|
||||
return result.Rv();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("TextEditor::ComputeValueFromTextNodeAndBRElement() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (!result.inspect().Ignored()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4209,12 +4210,16 @@ nsresult EditorBase::DeleteSelectionAsSubAction(
|
||||
!ignoredError.Failed(),
|
||||
"TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
|
||||
|
||||
EditActionResult result =
|
||||
HandleDeleteSelection(aDirectionAndAmount, aStripWrappers);
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"TextEditor::HandleDeleteSelection() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result =
|
||||
HandleDeleteSelection(aDirectionAndAmount, aStripWrappers);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("TextEditor::HandleDeleteSelection() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX This is odd. We just tries to remove empty text node here but we
|
||||
@ -6009,11 +6014,13 @@ nsresult EditorBase::InsertTextAsSubAction(
|
||||
!ignoredError.Failed(),
|
||||
"TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
|
||||
|
||||
EditActionResult result =
|
||||
Result<EditActionResult, nsresult> result =
|
||||
HandleInsertText(editSubAction, aStringToInsert, aSelectionHandling);
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"EditorBase::HandleInsertText() failed");
|
||||
return result.Rv();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("EditorBase::HandleInsertText() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP EditorBase::InsertLineBreak() { return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
|
@ -2053,7 +2053,7 @@ class EditorBase : public nsIEditor,
|
||||
* TextEditor instance. Otherwise,
|
||||
* nsIEditor::eStrip is also valid.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual Result<EditActionResult, nsresult>
|
||||
HandleDeleteSelection(nsIEditor::EDirection aDirectionAndAmount,
|
||||
nsIEditor::EStripWrappers aStripWrappers) = 0;
|
||||
|
||||
@ -2074,9 +2074,10 @@ class EditorBase : public nsIEditor,
|
||||
* @param aSelectionHandling Specify whether selected content should be
|
||||
* deleted or ignored.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual EditActionResult HandleInsertText(
|
||||
EditSubAction aEditSubAction, const nsAString& aInsertionString,
|
||||
SelectionHandling aSelectionHandling) = 0;
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT virtual Result<EditActionResult, nsresult>
|
||||
HandleInsertText(EditSubAction aEditSubAction,
|
||||
const nsAString& aInsertionString,
|
||||
SelectionHandling aSelectionHandling) = 0;
|
||||
|
||||
/**
|
||||
* InsertWithQuotationsAsSubAction() inserts aQuotedText with appending ">"
|
||||
|
@ -37,32 +37,8 @@ using namespace dom;
|
||||
*****************************************************************************/
|
||||
|
||||
EditActionResult& EditActionResult::operator|=(
|
||||
const Result<MoveNodeResult, nsresult>& aMoveNodeResult) {
|
||||
mHandled |= aMoveNodeResult.isOk() && aMoveNodeResult.inspect().Handled();
|
||||
|
||||
// If one of the result is NS_ERROR_EDITOR_DESTROYED, use it since it's
|
||||
// the most important error code for editor.
|
||||
if (EditorDestroyed() ||
|
||||
(aMoveNodeResult.isErr() &&
|
||||
aMoveNodeResult.inspectErr() == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
mRv = NS_ERROR_EDITOR_DESTROYED;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// If one of the results is error, return error.
|
||||
if (Failed() || aMoveNodeResult.isErr()) {
|
||||
// If both failed and the error codes are same, just return.
|
||||
if (Failed() && aMoveNodeResult.isErr() &&
|
||||
mRv == aMoveNodeResult.inspectErr()) {
|
||||
return *this;
|
||||
}
|
||||
// If the error codes is different or one of them succeeded, use the general
|
||||
// error code.
|
||||
mRv = NS_ERROR_FAILURE;
|
||||
return *this;
|
||||
}
|
||||
// Otherwise, use general success code.
|
||||
mRv = NS_OK;
|
||||
const MoveNodeResult& aMoveNodeResult) {
|
||||
mHandled |= aMoveNodeResult.Handled();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -32,105 +32,51 @@ namespace mozilla {
|
||||
enum class StyleWhiteSpace : uint8_t;
|
||||
|
||||
/***************************************************************************
|
||||
* EditActionResult is useful to return multiple results of an editor
|
||||
* action handler without out params.
|
||||
* Note that when you return an anonymous instance from a method, you should
|
||||
* use EditActionIgnored(), EditActionHandled() or EditActionCanceled() for
|
||||
* easier to read. In other words, EditActionResult should be used when
|
||||
* declaring return type of a method, being an argument or defined as a local
|
||||
* variable.
|
||||
* EditActionResult is useful to return the handling state of edit sub actions
|
||||
* without out params.
|
||||
*/
|
||||
class MOZ_STACK_CLASS EditActionResult final {
|
||||
public:
|
||||
bool Succeeded() const { return NS_SUCCEEDED(mRv); }
|
||||
bool Failed() const { return NS_FAILED(mRv); }
|
||||
nsresult Rv() const { return mRv; }
|
||||
bool Canceled() const { return mCanceled; }
|
||||
bool Handled() const { return mHandled; }
|
||||
bool Ignored() const { return !mCanceled && !mHandled; }
|
||||
bool EditorDestroyed() const { return mRv == NS_ERROR_EDITOR_DESTROYED; }
|
||||
|
||||
EditActionResult SetResult(nsresult aRv) {
|
||||
mRv = aRv;
|
||||
return *this;
|
||||
}
|
||||
EditActionResult MarkAsCanceled() {
|
||||
mCanceled = true;
|
||||
return *this;
|
||||
}
|
||||
EditActionResult MarkAsHandled() {
|
||||
mHandled = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit EditActionResult(nsresult aRv)
|
||||
: mRv(aRv), mCanceled(false), mHandled(false) {}
|
||||
void MarkAsCanceled() { mCanceled = true; }
|
||||
void MarkAsHandled() { mHandled = true; }
|
||||
|
||||
EditActionResult& operator|=(const EditActionResult& aOther) {
|
||||
mCanceled |= aOther.mCanceled;
|
||||
mHandled |= aOther.mHandled;
|
||||
// When both result are same, keep the result.
|
||||
if (mRv == aOther.mRv) {
|
||||
return *this;
|
||||
}
|
||||
// If one of the result is NS_ERROR_EDITOR_DESTROYED, use it since it's
|
||||
// the most important error code for editor.
|
||||
if (EditorDestroyed() || aOther.EditorDestroyed()) {
|
||||
mRv = NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
// If one of the results is error, use NS_ERROR_FAILURE.
|
||||
else if (Failed() || aOther.Failed()) {
|
||||
mRv = NS_ERROR_FAILURE;
|
||||
} else {
|
||||
// Otherwise, use generic success code, NS_OK.
|
||||
mRv = NS_OK;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
EditActionResult& operator|=(
|
||||
const Result<MoveNodeResult, nsresult>& aMoveNodeResult);
|
||||
EditActionResult& operator|=(const MoveNodeResult& aMoveNodeResult);
|
||||
|
||||
static EditActionResult IgnoredResult() {
|
||||
return EditActionResult(false, false);
|
||||
}
|
||||
static EditActionResult HandledResult() {
|
||||
return EditActionResult(false, true);
|
||||
}
|
||||
static EditActionResult CanceledResult() {
|
||||
return EditActionResult(true, true);
|
||||
}
|
||||
|
||||
EditActionResult(const EditActionResult&) = delete;
|
||||
EditActionResult& operator=(const EditActionResult&) = delete;
|
||||
EditActionResult(EditActionResult&&) = default;
|
||||
EditActionResult& operator=(EditActionResult&&) = default;
|
||||
|
||||
private:
|
||||
nsresult mRv;
|
||||
bool mCanceled;
|
||||
bool mHandled;
|
||||
bool mCanceled = false;
|
||||
bool mHandled = false;
|
||||
|
||||
EditActionResult(nsresult aRv, bool aCanceled, bool aHandled)
|
||||
: mRv(aRv), mCanceled(aCanceled), mHandled(aHandled) {}
|
||||
EditActionResult(bool aCanceled, bool aHandled)
|
||||
: mCanceled(aCanceled), mHandled(aHandled) {}
|
||||
|
||||
EditActionResult()
|
||||
: mRv(NS_ERROR_NOT_INITIALIZED), mCanceled(false), mHandled(false) {}
|
||||
|
||||
friend EditActionResult EditActionIgnored(nsresult aRv);
|
||||
friend EditActionResult EditActionHandled(nsresult aRv);
|
||||
friend EditActionResult EditActionCanceled(nsresult aRv);
|
||||
EditActionResult() : mCanceled(false), mHandled(false) {}
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
* When an edit action handler (or its helper) does nothing,
|
||||
* EditActionIgnored should be returned.
|
||||
*/
|
||||
inline EditActionResult EditActionIgnored(nsresult aRv = NS_OK) {
|
||||
return EditActionResult(aRv, false, false);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* When an edit action handler (or its helper) handled and not canceled,
|
||||
* EditActionHandled should be returned.
|
||||
*/
|
||||
inline EditActionResult EditActionHandled(nsresult aRv = NS_OK) {
|
||||
return EditActionResult(aRv, false, true);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* When an edit action handler (or its helper) handled and canceled,
|
||||
* EditActionHandled should be returned.
|
||||
*/
|
||||
inline EditActionResult EditActionCanceled(nsresult aRv = NS_OK) {
|
||||
return EditActionResult(aRv, true, true);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* CreateNodeResultBase is a simple class for CreateSomething() methods
|
||||
* which want to return new node.
|
||||
|
@ -61,16 +61,20 @@ nsresult HTMLEditor::SetSelectionToAbsoluteOrStaticAsAction(
|
||||
}
|
||||
|
||||
if (aEnabled) {
|
||||
EditActionResult result = SetSelectionToAbsoluteAsSubAction(*editingHost);
|
||||
NS_WARNING_ASSERTION(
|
||||
result.Succeeded(),
|
||||
"HTMLEditor::SetSelectionToAbsoluteAsSubAction() failed");
|
||||
return result.Rv();
|
||||
Result<EditActionResult, nsresult> result =
|
||||
SetSelectionToAbsoluteAsSubAction(*editingHost);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::SetSelectionToAbsoluteAsSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
EditActionResult result = SetSelectionToStaticAsSubAction();
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::SetSelectionToStaticAsSubAction() failed");
|
||||
return result.Rv();
|
||||
Result<EditActionResult, nsresult> result = SetSelectionToStaticAsSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::SetSelectionToStaticAsSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<Element>
|
||||
@ -183,10 +187,12 @@ nsresult HTMLEditor::AddZIndexAsAction(int32_t aChange,
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
EditActionResult result = AddZIndexAsSubAction(aChange);
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::AddZIndexAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result = AddZIndexAsSubAction(aChange);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::AddZIndexAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int32_t HTMLEditor::GetZIndex(Element& aElement) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,7 @@
|
||||
#include "EditorBase.h"
|
||||
#include "EditorDOMPoint.h"
|
||||
#include "EditorUtils.h"
|
||||
#include "ErrorList.h"
|
||||
#include "HTMLEditorEventListener.h"
|
||||
#include "HTMLEditUtils.h"
|
||||
#include "InsertNodeTransaction.h"
|
||||
@ -1206,12 +1207,13 @@ nsresult HTMLEditor::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) {
|
||||
|
||||
// If selection is in a table element, we need special handling.
|
||||
if (HTMLEditUtils::IsAnyTableElement(editableBlockElement)) {
|
||||
EditActionResult result = HandleTabKeyPressInTable(aKeyboardEvent);
|
||||
if (result.Failed()) {
|
||||
Result<EditActionResult, nsresult> result =
|
||||
HandleTabKeyPressInTable(aKeyboardEvent);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::HandleTabKeyPressInTable() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
if (!result.Handled()) {
|
||||
if (!result.inspect().Handled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult rv = ScrollSelectionFocusIntoView();
|
||||
@ -1319,11 +1321,13 @@ NS_IMETHODIMP HTMLEditor::InsertLineBreak() {
|
||||
return NS_SUCCESS_DOM_NO_OPERATION;
|
||||
}
|
||||
|
||||
EditActionResult result = InsertParagraphSeparatorAsSubAction(*editingHost);
|
||||
NS_WARNING_ASSERTION(
|
||||
result.Succeeded(),
|
||||
"HTMLEditor::InsertParagraphSeparatorAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result =
|
||||
InsertParagraphSeparatorAsSubAction(*editingHost);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::InsertParagraphSeparatorAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::InsertLineBreakAsAction(nsIPrincipal* aPrincipal) {
|
||||
@ -1364,21 +1368,23 @@ nsresult HTMLEditor::InsertParagraphSeparatorAsAction(
|
||||
return NS_SUCCESS_DOM_NO_OPERATION;
|
||||
}
|
||||
|
||||
EditActionResult result = InsertParagraphSeparatorAsSubAction(*editingHost);
|
||||
NS_WARNING_ASSERTION(
|
||||
result.Succeeded(),
|
||||
"HTMLEditor::InsertParagraphSeparatorAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result =
|
||||
InsertParagraphSeparatorAsSubAction(*editingHost);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::InsertParagraphSeparatorAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
Result<EditActionResult, nsresult> HTMLEditor::HandleTabKeyPressInTable(
|
||||
WidgetKeyboardEvent* aKeyboardEvent) {
|
||||
MOZ_ASSERT(aKeyboardEvent);
|
||||
|
||||
AutoEditActionDataSetter dummyEditActionData(*this, EditAction::eNotEditing);
|
||||
if (NS_WARN_IF(!dummyEditActionData.CanHandle())) {
|
||||
// Do nothing if we didn't find a table cell.
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
|
||||
// Find enclosing table cell from selection (cell may be selected element)
|
||||
@ -1389,7 +1395,7 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
"HTMLEditor::GetInclusiveAncestorByTagNameAtSelection(*nsGkAtoms::td) "
|
||||
"returned nullptr");
|
||||
// Do nothing if we didn't find a table cell.
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
|
||||
// find enclosing table
|
||||
@ -1397,7 +1403,7 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
HTMLEditUtils::GetClosestAncestorTableElement(*cellElement);
|
||||
if (!table) {
|
||||
NS_WARNING("HTMLEditor::GetClosestAncestorTableElement() failed");
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
|
||||
// advance to next cell
|
||||
@ -1406,13 +1412,13 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
nsresult rv = postOrderIter.Init(table);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("PostContentIterator::Init() failed");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
// position postOrderIter at block
|
||||
rv = postOrderIter.PositionAt(cellElement);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("PostContentIterator::PositionAt() failed");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
do {
|
||||
@ -1428,13 +1434,15 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
table) {
|
||||
aKeyboardEvent->PreventDefault();
|
||||
CollapseSelectionToDeepestNonTableFirstChild(node);
|
||||
return EditActionHandled(
|
||||
NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED : NS_OK);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
} while (!postOrderIter.IsDone());
|
||||
|
||||
if (aKeyboardEvent->IsShift()) {
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
|
||||
// If we haven't handled it yet, then we must have run off the end of the
|
||||
@ -1444,21 +1452,21 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
AutoEditActionDataSetter editActionData(*this,
|
||||
EditAction::eInsertTableRowElement);
|
||||
rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent();
|
||||
if (MOZ_UNLIKELY(NS_FAILED(rv))) {
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED,
|
||||
"CanHandleAndMaybeDispatchBeforeInputEvent(), failed");
|
||||
return EditActionHandled(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
rv = InsertTableRowsWithTransaction(*cellElement, 1,
|
||||
InsertPosition::eAfterSelectedCell);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return EditActionHandled(NS_ERROR_EDITOR_DESTROYED);
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::InsertTableRowsWithTransaction(*cellElement, 1, "
|
||||
"InsertPosition::eAfterSelectedCell) failed");
|
||||
return EditActionHandled(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
aKeyboardEvent->PreventDefault();
|
||||
// Put selection in right place. Use table code to get selection and index
|
||||
@ -1469,11 +1477,11 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
nullptr, &row, nullptr);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("HTMLEditor::GetCellContext() failed");
|
||||
return EditActionHandled(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
if (!tblElement) {
|
||||
NS_WARNING("HTMLEditor::GetCellContext() didn't return table element");
|
||||
return EditActionHandled(NS_ERROR_FAILURE);
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
// ...so that we can ask for first cell in that row...
|
||||
cell = GetTableCellElementAt(*tblElement, row, 0);
|
||||
@ -1482,18 +1490,15 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
|
||||
// empty new cell, so this works fine)
|
||||
if (cell) {
|
||||
nsresult rv = CollapseSelectionToStartOf(*cell);
|
||||
if (MOZ_UNLIKELY(NS_FAILED(rv))) {
|
||||
NS_WARNING(
|
||||
"EditorBase::CollapseSelectionToStartOf() caused destroying the "
|
||||
"editor");
|
||||
return EditActionHandled(NS_ERROR_EDITOR_DESTROYED);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::CollapseSelectionToStartOf() failed");
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rv),
|
||||
"EditorBase::CollapseSelectionToStartOf() failed, but ignored");
|
||||
}
|
||||
return EditActionHandled(NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED
|
||||
: NS_OK);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
void HTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(nsINode* aNode) {
|
||||
@ -1891,11 +1896,15 @@ nsresult HTMLEditor::InsertElementAtSelectionAsAction(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
UndefineCaretBidiLevel();
|
||||
@ -2234,12 +2243,16 @@ nsresult HTMLEditor::SetParagraphFormatAsAction(
|
||||
RefPtr<nsAtom> tagName = NS_Atomize(lowerCaseTagName);
|
||||
MOZ_ASSERT(tagName);
|
||||
if (tagName == nsGkAtoms::dd || tagName == nsGkAtoms::dt) {
|
||||
EditActionResult result = MakeOrChangeListAndListItemAsSubAction(
|
||||
*tagName, u""_ns, SelectAllOfCurrentList::No);
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::MakeOrChangeListAndListItemAsSubAction("
|
||||
"SelectAllOfCurrentList::No) failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result =
|
||||
MakeOrChangeListAndListItemAsSubAction(*tagName, u""_ns,
|
||||
SelectAllOfCurrentList::No);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::MakeOrChangeListAndListItemAsSubAction("
|
||||
"SelectAllOfCurrentList::No) failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = FormatBlockContainerAsSubAction(*tagName);
|
||||
@ -2608,12 +2621,14 @@ nsresult HTMLEditor::MakeOrChangeListAsAction(
|
||||
return EditorBase::ToGenericNSResult(rv);
|
||||
}
|
||||
|
||||
EditActionResult result = MakeOrChangeListAndListItemAsSubAction(
|
||||
aListTagName, aBulletType, aSelectAllOfCurrentList);
|
||||
NS_WARNING_ASSERTION(
|
||||
result.Succeeded(),
|
||||
"HTMLEditor::MakeOrChangeListAndListItemAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result =
|
||||
MakeOrChangeListAndListItemAsSubAction(aListTagName, aBulletType,
|
||||
aSelectAllOfCurrentList);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::MakeOrChangeListAndListItemAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP HTMLEditor::RemoveList(const nsAString& aListType) {
|
||||
@ -2683,11 +2698,15 @@ nsresult HTMLEditor::FormatBlockContainerAsSubAction(nsAtom& aTagName) {
|
||||
!ignoredError.Failed(),
|
||||
"HTMLEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSelectionRangeContainerNotContent()) {
|
||||
@ -2810,10 +2829,12 @@ nsresult HTMLEditor::IndentAsAction(nsIPrincipal* aPrincipal) {
|
||||
return NS_SUCCESS_DOM_NO_OPERATION;
|
||||
}
|
||||
|
||||
EditActionResult result = IndentAsSubAction(*editingHost);
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::IndentAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result = IndentAsSubAction(*editingHost);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::IndentAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::OutdentAsAction(nsIPrincipal* aPrincipal) {
|
||||
@ -2835,10 +2856,12 @@ nsresult HTMLEditor::OutdentAsAction(nsIPrincipal* aPrincipal) {
|
||||
return NS_SUCCESS_DOM_NO_OPERATION;
|
||||
}
|
||||
|
||||
EditActionResult result = OutdentAsSubAction(*editingHost);
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::OutdentAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result = OutdentAsSubAction(*editingHost);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::OutdentAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// TODO: IMPLEMENT ALIGNMENT!
|
||||
@ -2859,10 +2882,13 @@ nsresult HTMLEditor::AlignAsAction(const nsAString& aAlignType,
|
||||
return NS_SUCCESS_DOM_NO_OPERATION;
|
||||
}
|
||||
|
||||
EditActionResult result = AlignAsSubAction(aAlignType, *editingHost);
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::AlignAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
Result<EditActionResult, nsresult> result =
|
||||
AlignAsSubAction(aAlignType, *editingHost);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::AlignAsSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Element* HTMLEditor::GetInclusiveAncestorByTagName(const nsStaticAtom& aTagName,
|
||||
@ -5750,11 +5776,15 @@ nsresult HTMLEditor::SetBlockBackgroundColorWithCSSAsSubAction(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
IgnoredErrorResult ignoredError;
|
||||
|
@ -1034,7 +1034,7 @@ class HTMLEditor final : public EditorBase,
|
||||
* XXX I think that `IsSelectionEditable()` is better name, but it's already
|
||||
* in `EditorBase`...
|
||||
*/
|
||||
EditActionResult CanHandleHTMLEditSubAction() const;
|
||||
Result<EditActionResult, nsresult> CanHandleHTMLEditSubAction() const;
|
||||
|
||||
/**
|
||||
* EnsureCaretNotAfterInvisibleBRElement() makes sure that caret is NOT after
|
||||
@ -1077,9 +1077,10 @@ class HTMLEditor final : public EditorBase,
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult PrepareInlineStylesForCaret();
|
||||
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult HandleInsertText(
|
||||
EditSubAction aEditSubAction, const nsAString& aInsertionString,
|
||||
SelectionHandling aSelectionHandling) final;
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleInsertText(EditSubAction aEditSubAction,
|
||||
const nsAString& aInsertionString,
|
||||
SelectionHandling aSelectionHandling) final;
|
||||
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertDroppedDataTransferAsAction(
|
||||
AutoEditActionDataSetter& aEditActionData,
|
||||
@ -1590,7 +1591,7 @@ class HTMLEditor final : public EditorBase,
|
||||
*
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
InsertParagraphSeparatorAsSubAction(const Element& aEditingHost);
|
||||
|
||||
/**
|
||||
@ -1643,7 +1644,7 @@ class HTMLEditor final : public EditorBase,
|
||||
* ancestor list element at selection.
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
ConvertContentAroundRangesToList(
|
||||
AutoRangeArray& aRanges, nsAtom& aListElementTagName,
|
||||
nsAtom& aListItemElementTagName, const nsAString& aBulletType,
|
||||
@ -1667,7 +1668,7 @@ class HTMLEditor final : public EditorBase,
|
||||
* @param aSelectAllOfCurrentList Yes if this should treat all of
|
||||
* ancestor list element at selection.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
MakeOrChangeListAndListItemAsSubAction(
|
||||
nsAtom& aListElementOrListItemElementTagName,
|
||||
const nsAString& aBulletType,
|
||||
@ -2263,7 +2264,7 @@ class HTMLEditor final : public EditorBase,
|
||||
* @param aDirectionAndAmount Direction of the deletion.
|
||||
* @param aStripWrappers Must be eStrip or eNoStrip.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleDeleteSelection(nsIEditor::EDirection aDirectionAndAmount,
|
||||
nsIEditor::EStripWrappers aStripWrappers) final;
|
||||
|
||||
@ -2371,7 +2372,7 @@ class HTMLEditor final : public EditorBase,
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
// TODO: Make this take AutoRangeArray instead of retrieving `Selection`
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleIndentAtSelection(const Element& aEditingHost);
|
||||
|
||||
/**
|
||||
@ -2428,7 +2429,7 @@ class HTMLEditor final : public EditorBase,
|
||||
*
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleOutdentAtSelection(const Element& aEditingHost);
|
||||
|
||||
/**
|
||||
@ -2589,7 +2590,7 @@ class HTMLEditor final : public EditorBase,
|
||||
* should be aligned to.
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
AlignAsSubAction(const nsAString& aAlignType, const Element& aEditingHost);
|
||||
|
||||
/**
|
||||
@ -2673,14 +2674,14 @@ class HTMLEditor final : public EditorBase,
|
||||
*
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
SetSelectionToAbsoluteAsSubAction(const Element& aEditingHost);
|
||||
|
||||
/**
|
||||
* SetSelectionToStaticAsSubAction() sets the `position` property of a
|
||||
* selection parent's block whose `position` is `absolute` to `static`.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
SetSelectionToStaticAsSubAction();
|
||||
|
||||
/**
|
||||
@ -2689,7 +2690,7 @@ class HTMLEditor final : public EditorBase,
|
||||
*
|
||||
* @param aChange Amount to change `z-index`.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
AddZIndexAsSubAction(int32_t aChange);
|
||||
|
||||
/**
|
||||
@ -3306,7 +3307,7 @@ class HTMLEditor final : public EditorBase,
|
||||
*
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
IndentAsSubAction(const Element& aEditingHost);
|
||||
|
||||
/**
|
||||
@ -3314,7 +3315,7 @@ class HTMLEditor final : public EditorBase,
|
||||
*
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
OutdentAsSubAction(const Element& aEditingHost);
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT nsresult LoadHTML(const nsAString& aInputString);
|
||||
@ -3479,7 +3480,7 @@ class HTMLEditor final : public EditorBase,
|
||||
* HandleTabKeyPressInTable() handles "Tab" key press in table if selection
|
||||
* is in a `<table>` element.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleTabKeyPressInTable(WidgetKeyboardEvent* aKeyboardEvent);
|
||||
|
||||
/**
|
||||
|
@ -681,11 +681,16 @@ nsresult HTMLEditor::HTMLWithContextInserter::Run(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = mHTMLEditor.CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result =
|
||||
mHTMLEditor.CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
mHTMLEditor.UndefineCaretBidiLevel();
|
||||
@ -2594,12 +2599,16 @@ nsresult HTMLEditor::PasteAsQuotationAsAction(int32_t aClipboardType,
|
||||
// If it's not in plain text edit mode, paste text into new
|
||||
// <blockquote type="cite"> element after removing selection.
|
||||
|
||||
// XXX Why don't we test these first?
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.Rv());
|
||||
{
|
||||
// XXX Why don't we test these first?
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return EditorBase::ToGenericNSResult(result.unwrapErr());
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
UndefineCaretBidiLevel();
|
||||
@ -2762,11 +2771,15 @@ nsresult HTMLEditor::InsertWithQuotationsAsSubAction(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
UndefineCaretBidiLevel();
|
||||
@ -3008,11 +3021,15 @@ nsresult HTMLEditor::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
UndefineCaretBidiLevel();
|
||||
@ -3285,11 +3302,15 @@ nsresult HTMLEditor::InsertAsCitedQuotationInternal(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
UndefineCaretBidiLevel();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -214,11 +214,15 @@ nsresult HTMLEditor::SetInlinePropertiesAsSubAction(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
AutoPlaceholderBatch treatAsOneTransaction(
|
||||
@ -2207,11 +2211,15 @@ nsresult HTMLEditor::RemoveInlinePropertiesAsSubAction(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult result = CanHandleHTMLEditSubAction();
|
||||
if (result.Failed() || result.Canceled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.Rv();
|
||||
{
|
||||
Result<EditActionResult, nsresult> result = CanHandleHTMLEditSubAction();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("HTMLEditor::CanHandleHTMLEditSubAction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (result.inspect().Canceled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
AutoPlaceholderBatch treatAsOneTransaction(
|
||||
|
@ -47,7 +47,7 @@ using namespace dom;
|
||||
|
||||
#define CANCEL_OPERATION_AND_RETURN_EDIT_ACTION_RESULT_IF_READONLY \
|
||||
if (IsReadonly()) { \
|
||||
return EditActionCanceled(NS_OK); \
|
||||
return EditActionResult::CanceledResult(); \
|
||||
}
|
||||
|
||||
void TextEditor::OnStartToHandleTopLevelEditSubAction(
|
||||
@ -161,14 +161,18 @@ nsresult TextEditor::InsertLineBreakAsSubAction() {
|
||||
!ignoredError.Failed(),
|
||||
"TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored");
|
||||
|
||||
EditActionResult result = InsertLineFeedCharacterAtSelection();
|
||||
NS_WARNING_ASSERTION(
|
||||
result.Succeeded(),
|
||||
"TextEditor::InsertLineFeedCharacterAtSelection() failed, but ignored");
|
||||
return result.Rv();
|
||||
Result<EditActionResult, nsresult> result =
|
||||
InsertLineFeedCharacterAtSelection();
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING(
|
||||
"TextEditor::InsertLineFeedCharacterAtSelection() failed, but ignored");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EditActionResult TextEditor::InsertLineFeedCharacterAtSelection() {
|
||||
Result<EditActionResult, nsresult>
|
||||
TextEditor::InsertLineFeedCharacterAtSelection() {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
MOZ_ASSERT(!IsSingleLineEditor());
|
||||
|
||||
@ -178,16 +182,16 @@ EditActionResult TextEditor::InsertLineFeedCharacterAtSelection() {
|
||||
|
||||
if (mMaxTextLength >= 0) {
|
||||
nsAutoString insertionString(u"\n"_ns);
|
||||
EditActionResult result =
|
||||
Result<EditActionResult, nsresult> result =
|
||||
MaybeTruncateInsertionStringForMaxLength(insertionString);
|
||||
if (result.Failed()) {
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING(
|
||||
"TextEditor::MaybeTruncateInsertionStringForMaxLength() failed");
|
||||
return result;
|
||||
}
|
||||
if (result.Handled()) {
|
||||
if (result.inspect().Handled()) {
|
||||
// Don't return as handled since we stopped inserting the line break.
|
||||
return EditActionCanceled();
|
||||
return EditActionResult::CanceledResult();
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,20 +202,20 @@ EditActionResult TextEditor::InsertLineFeedCharacterAtSelection() {
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
"EditorBase::DeleteSelectionAsSubAction(eNone, eNoStrip) failed");
|
||||
return EditActionIgnored(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
}
|
||||
|
||||
const auto pointToInsert = GetFirstSelectionStartPoint<EditorDOMPoint>();
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(!pointToInsert.IsSet()))) {
|
||||
return EditActionResult(NS_ERROR_FAILURE);
|
||||
if (NS_WARN_IF(!pointToInsert.IsSet())) {
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
MOZ_ASSERT(pointToInsert.IsSetAndValid());
|
||||
MOZ_ASSERT(!pointToInsert.IsContainerHTMLElement(nsGkAtoms::br));
|
||||
|
||||
RefPtr<Document> document = GetDocument();
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(!document))) {
|
||||
return EditActionResult(NS_ERROR_NOT_INITIALIZED);
|
||||
if (NS_WARN_IF(!document)) {
|
||||
return Err(NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
// Don't change my selection in sub-transactions.
|
||||
@ -222,13 +226,13 @@ EditActionResult TextEditor::InsertLineFeedCharacterAtSelection() {
|
||||
InsertTextWithTransaction(*document, u"\n"_ns, pointToInsert);
|
||||
if (MOZ_UNLIKELY(insertTextResult.isErr())) {
|
||||
NS_WARNING("TextEditor::InsertTextWithTransaction(\"\\n\") failed");
|
||||
return EditActionResult(insertTextResult.unwrapErr());
|
||||
return insertTextResult.propagateErr();
|
||||
}
|
||||
if (MOZ_UNLIKELY(!insertTextResult.inspect().IsSet())) {
|
||||
NS_WARNING(
|
||||
"EditorBase::InsertTextWithTransaction(\"\\n\") didn't return position "
|
||||
"of inserted linefeed");
|
||||
return EditActionHandled(NS_ERROR_FAILURE);
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
// set the selection to the correct location
|
||||
@ -236,9 +240,9 @@ EditActionResult TextEditor::InsertLineFeedCharacterAtSelection() {
|
||||
"After inserting text into a text node, insertTextResult should "
|
||||
"return a point in a text node");
|
||||
nsresult rv = CollapseSelectionTo(insertTextResult.inspect());
|
||||
if (MOZ_UNLIKELY(NS_FAILED(rv))) {
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
|
||||
return EditActionHandled(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
// XXX I don't think we still need this. This must have been required when
|
||||
@ -257,7 +261,7 @@ EditActionResult TextEditor::InsertLineFeedCharacterAtSelection() {
|
||||
"StartOfNextLine) failed, but ignored");
|
||||
}
|
||||
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
nsresult TextEditor::EnsureCaretNotAtEndOfTextNode() {
|
||||
@ -359,7 +363,7 @@ void TextEditor::HandleNewLinesInStringForSingleLineEditor(
|
||||
}
|
||||
}
|
||||
|
||||
EditActionResult TextEditor::HandleInsertText(
|
||||
Result<EditActionResult, nsresult> TextEditor::HandleInsertText(
|
||||
EditSubAction aEditSubAction, const nsAString& aInsertionString,
|
||||
SelectionHandling aSelectionHandling) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
@ -377,23 +381,25 @@ EditActionResult TextEditor::HandleInsertText(
|
||||
// because IME transaction depend on them
|
||||
// There is more work to do to make the
|
||||
// world safe for IME.
|
||||
return EditActionCanceled();
|
||||
return EditActionResult::CanceledResult();
|
||||
}
|
||||
|
||||
nsAutoString insertionString(aInsertionString);
|
||||
if (mMaxTextLength >= 0) {
|
||||
EditActionResult result =
|
||||
Result<EditActionResult, nsresult> result =
|
||||
MaybeTruncateInsertionStringForMaxLength(insertionString);
|
||||
if (result.Failed()) {
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING(
|
||||
"TextEditor::MaybeTruncateInsertionStringForMaxLength() failed");
|
||||
return result.MarkAsHandled();
|
||||
EditActionResult unwrappedResult = result.unwrap();
|
||||
unwrappedResult.MarkAsHandled();
|
||||
return unwrappedResult;
|
||||
}
|
||||
// If we're exceeding the maxlength when composing IME, we need to clean up
|
||||
// the composing text, so we shouldn't return early.
|
||||
if (result.Handled() && insertionString.IsEmpty() &&
|
||||
if (result.inspect().Handled() && insertionString.IsEmpty() &&
|
||||
aEditSubAction != EditSubAction::eInsertTextComingFromIME) {
|
||||
return EditActionCanceled();
|
||||
return EditActionResult::CanceledResult();
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,7 +422,7 @@ EditActionResult TextEditor::HandleInsertText(
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
"EditorBase::DeleteSelectionAsSubAction(eNone, eNoStrip) failed");
|
||||
return EditActionHandled(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
}
|
||||
|
||||
@ -450,14 +456,14 @@ EditActionResult TextEditor::HandleInsertText(
|
||||
}
|
||||
|
||||
const auto atStartOfSelection = GetFirstSelectionStartPoint<EditorDOMPoint>();
|
||||
if (MOZ_UNLIKELY(NS_WARN_IF(!atStartOfSelection.IsSetAndValid()))) {
|
||||
return EditActionHandled(NS_ERROR_FAILURE);
|
||||
if (NS_WARN_IF(!atStartOfSelection.IsSetAndValid())) {
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
MOZ_ASSERT(!atStartOfSelection.IsContainerHTMLElement(nsGkAtoms::br));
|
||||
|
||||
RefPtr<Document> document = GetDocument();
|
||||
if (NS_WARN_IF(!document)) {
|
||||
return EditActionHandled(NS_ERROR_NOT_INITIALIZED);
|
||||
return Err(NS_ERROR_NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
if (aEditSubAction == EditSubAction::eInsertTextComingFromIME) {
|
||||
@ -474,7 +480,7 @@ EditActionResult TextEditor::HandleInsertText(
|
||||
compositionStartPoint);
|
||||
if (MOZ_UNLIKELY(insertTextResult.isErr())) {
|
||||
NS_WARNING("EditorBase::InsertTextWithTransaction() failed");
|
||||
return EditActionResult(insertTextResult.unwrapErr());
|
||||
return insertTextResult.propagateErr();
|
||||
}
|
||||
} else {
|
||||
MOZ_ASSERT(aEditSubAction == EditSubAction::eInsertText);
|
||||
@ -487,7 +493,7 @@ EditActionResult TextEditor::HandleInsertText(
|
||||
atStartOfSelection);
|
||||
if (MOZ_UNLIKELY(insertTextResult.isErr())) {
|
||||
NS_WARNING("EditorBase::InsertTextWithTransaction() failed");
|
||||
return EditActionResult(insertTextResult.unwrapErr());
|
||||
return insertTextResult.propagateErr();
|
||||
}
|
||||
|
||||
if (insertTextResult.inspect().IsSet()) {
|
||||
@ -503,10 +509,8 @@ EditActionResult TextEditor::HandleInsertText(
|
||||
"After inserting text into a text node, insertTextResult "
|
||||
"should return a point in a text node");
|
||||
nsresult rv = CollapseSelectionTo(pointToPutCaret);
|
||||
if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
NS_WARNING(
|
||||
"EditorBase::CollapseSelectionTo() caused destroying the editor");
|
||||
return EditActionHandled(NS_ERROR_EDITOR_DESTROYED);
|
||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rv),
|
||||
@ -518,15 +522,17 @@ EditActionResult TextEditor::HandleInsertText(
|
||||
if (IsPasswordEditor() && IsMaskingPassword() && CanEchoPasswordNow()) {
|
||||
nsresult rv = SetUnmaskRangeAndNotify(start, insertionString.Length(),
|
||||
LookAndFeel::GetPasswordMaskDelay());
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"TextEditor::SetUnmaskRangeAndNotify() failed");
|
||||
return EditActionHandled(rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("TextEditor::SetUnmaskRangeAndNotify() failed");
|
||||
return Err(rv);
|
||||
}
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
EditActionResult TextEditor::SetTextWithoutTransaction(
|
||||
Result<EditActionResult, nsresult> TextEditor::SetTextWithoutTransaction(
|
||||
const nsAString& aValue) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
MOZ_ASSERT(!IsIMEComposing());
|
||||
@ -559,7 +565,7 @@ EditActionResult TextEditor::SetTextWithoutTransaction(
|
||||
if (!textNode->GetNextSibling() ||
|
||||
!EditorUtils::IsPaddingBRElementForEmptyLastLine(
|
||||
*textNode->GetNextSibling())) {
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
}
|
||||
|
||||
@ -573,13 +579,13 @@ EditActionResult TextEditor::SetTextWithoutTransaction(
|
||||
nsresult rv = SetTextNodeWithoutTransaction(sanitizedValue, *textNode);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::SetTextNodeWithoutTransaction() failed");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
EditActionResult TextEditor::HandleDeleteSelection(
|
||||
Result<EditActionResult, nsresult> TextEditor::HandleDeleteSelection(
|
||||
nsIEditor::EDirection aDirectionAndAmount,
|
||||
nsIEditor::EStripWrappers aStripWrappers) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
@ -590,22 +596,22 @@ EditActionResult TextEditor::HandleDeleteSelection(
|
||||
CANCEL_OPERATION_AND_RETURN_EDIT_ACTION_RESULT_IF_READONLY
|
||||
|
||||
if (IsEmpty()) {
|
||||
return EditActionCanceled();
|
||||
return EditActionResult::CanceledResult();
|
||||
}
|
||||
EditActionResult result =
|
||||
Result<EditActionResult, nsresult> result =
|
||||
HandleDeleteSelectionInternal(aDirectionAndAmount, nsIEditor::eNoStrip);
|
||||
// HandleDeleteSelectionInternal() creates SelectionBatcher. Therefore,
|
||||
// quitting from it might cause having destroyed the editor.
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return result.SetResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
NS_WARNING_ASSERTION(
|
||||
result.Succeeded(),
|
||||
result.isOk(),
|
||||
"TextEditor::HandleDeleteSelectionInternal(eNoStrip) failed");
|
||||
return result;
|
||||
}
|
||||
|
||||
EditActionResult TextEditor::HandleDeleteSelectionInternal(
|
||||
Result<EditActionResult, nsresult> TextEditor::HandleDeleteSelectionInternal(
|
||||
nsIEditor::EDirection aDirectionAndAmount,
|
||||
nsIEditor::EStripWrappers aStripWrappers) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
@ -627,28 +633,30 @@ EditActionResult TextEditor::HandleDeleteSelectionInternal(
|
||||
const auto selectionStartPoint =
|
||||
GetFirstSelectionStartPoint<EditorRawDOMPoint>();
|
||||
if (NS_WARN_IF(!selectionStartPoint.IsSet())) {
|
||||
return EditActionResult(NS_ERROR_FAILURE);
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
if (!SelectionRef().IsCollapsed()) {
|
||||
nsresult rv = DeleteSelectionWithTransaction(aDirectionAndAmount,
|
||||
nsIEditor::eNoStrip);
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rv),
|
||||
"EditorBase::DeleteSelectionWithTransaction(eNoStrip) failed");
|
||||
return EditActionHandled(rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING(
|
||||
"EditorBase::DeleteSelectionWithTransaction(eNoStrip) failed");
|
||||
return Err(rv);
|
||||
}
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
// Test for distance between caret and text that will be deleted
|
||||
AutoCaretBidiLevelManager bidiLevelManager(*this, aDirectionAndAmount,
|
||||
selectionStartPoint);
|
||||
if (bidiLevelManager.Failed()) {
|
||||
if (MOZ_UNLIKELY(bidiLevelManager.Failed())) {
|
||||
NS_WARNING("EditorBase::AutoCaretBidiLevelManager() failed");
|
||||
return EditActionResult(NS_ERROR_FAILURE);
|
||||
return Err(NS_ERROR_FAILURE);
|
||||
}
|
||||
bidiLevelManager.MaybeUpdateCaretBidiLevel(*this);
|
||||
if (bidiLevelManager.Canceled()) {
|
||||
return EditActionCanceled();
|
||||
return EditActionResult::CanceledResult();
|
||||
}
|
||||
}
|
||||
|
||||
@ -657,7 +665,7 @@ EditActionResult TextEditor::HandleDeleteSelectionInternal(
|
||||
rangesToDelete.ExtendAnchorFocusRangeFor(*this, aDirectionAndAmount);
|
||||
if (result.isErr()) {
|
||||
NS_WARNING("AutoRangeArray::ExtendAnchorFocusRangeFor() failed");
|
||||
return EditActionResult(result.unwrapErr());
|
||||
return result.propagateErr();
|
||||
}
|
||||
if (const Text* theTextNode = GetTextNode()) {
|
||||
rangesToDelete.EnsureRangesInTextNode(*theTextNode);
|
||||
@ -665,22 +673,23 @@ EditActionResult TextEditor::HandleDeleteSelectionInternal(
|
||||
|
||||
nsresult rv = DeleteRangesWithTransaction(
|
||||
result.unwrap(), nsIEditor::eNoStrip, rangesToDelete);
|
||||
NS_WARNING_ASSERTION(
|
||||
NS_SUCCEEDED(rv),
|
||||
"EditorBase::DeleteRangesWithTransaction(eNoStrip) failed");
|
||||
return EditActionHandled(rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::DeleteRangesWithTransaction(eNoStrip) failed");
|
||||
return Err(rv);
|
||||
}
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
EditActionResult TextEditor::ComputeValueFromTextNodeAndBRElement(
|
||||
nsAString& aValue) const {
|
||||
Result<EditActionResult, nsresult>
|
||||
TextEditor::ComputeValueFromTextNodeAndBRElement(nsAString& aValue) const {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
MOZ_ASSERT(!IsHTMLEditor());
|
||||
|
||||
Element* anonymousDivElement = GetRoot();
|
||||
if (!anonymousDivElement) {
|
||||
if (MOZ_UNLIKELY(!anonymousDivElement)) {
|
||||
// Don't warn this case, this is possible, e.g., 997805.html
|
||||
aValue.Truncate();
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
Text* textNode = Text::FromNodeOrNull(anonymousDivElement->GetFirstChild());
|
||||
@ -688,7 +697,7 @@ EditActionResult TextEditor::ComputeValueFromTextNodeAndBRElement(
|
||||
|
||||
if (!textNode->Length()) {
|
||||
aValue.Truncate();
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
nsIContent* firstChildExceptText = textNode->GetNextSibling();
|
||||
@ -701,21 +710,22 @@ EditActionResult TextEditor::ComputeValueFromTextNodeAndBRElement(
|
||||
!EditorUtils::IsPaddingBRElementForEmptyLastLine(
|
||||
*firstChildExceptText) &&
|
||||
!firstChildExceptText->IsXULElement(nsGkAtoms::scrollbar))) {
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
|
||||
// Otherwise, the text data is the value.
|
||||
textNode->GetData(aValue);
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
EditActionResult TextEditor::MaybeTruncateInsertionStringForMaxLength(
|
||||
Result<EditActionResult, nsresult>
|
||||
TextEditor::MaybeTruncateInsertionStringForMaxLength(
|
||||
nsAString& aInsertionString) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
MOZ_ASSERT(mMaxTextLength >= 0);
|
||||
|
||||
if (IsIMEComposing()) {
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
|
||||
// Ignore user pastes
|
||||
@ -730,7 +740,7 @@ EditActionResult TextEditor::MaybeTruncateInsertionStringForMaxLength(
|
||||
// By now we are certain that this is a user paste, before we ignore it,
|
||||
// lets check if the user explictly enabled truncating user pastes.
|
||||
if (!StaticPrefs::editor_truncate_user_pastes()) {
|
||||
return EditActionIgnored();
|
||||
return EditActionResult::IgnoredResult();
|
||||
}
|
||||
}
|
||||
[[fallthrough]];
|
||||
@ -742,7 +752,7 @@ EditActionResult TextEditor::MaybeTruncateInsertionStringForMaxLength(
|
||||
nsresult rv = GetTextLength(¤tLength);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("TextEditor::GetTextLength() failed");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
uint32_t selectionStart, selectionEnd;
|
||||
@ -761,12 +771,12 @@ EditActionResult TextEditor::MaybeTruncateInsertionStringForMaxLength(
|
||||
currentLength - kSelectionLength - kOldCompositionStringLength;
|
||||
if (kNewLength >= AssertedCast<uint32_t>(mMaxTextLength)) {
|
||||
aInsertionString.Truncate(); // Too long, we cannot accept new character.
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
if (aInsertionString.Length() + kNewLength <=
|
||||
AssertedCast<uint32_t>(mMaxTextLength)) {
|
||||
return EditActionIgnored(); // Enough short string.
|
||||
return EditActionResult::IgnoredResult(); // Enough short string.
|
||||
}
|
||||
|
||||
int32_t newInsertionStringLength = mMaxTextLength - kNewLength;
|
||||
@ -782,7 +792,7 @@ EditActionResult TextEditor::MaybeTruncateInsertionStringForMaxLength(
|
||||
// XXX What should we do if we're removing IVS but its preceding
|
||||
// character won't be removed?
|
||||
aInsertionString.Truncate(newInsertionStringLength);
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
bool TextEditor::CanEchoPasswordNow() const {
|
||||
|
@ -420,11 +420,14 @@ nsresult TextEditor::SetTextAsSubAction(const nsAString& aString) {
|
||||
|
||||
if (!IsIMEComposing() && !IsUndoRedoEnabled() &&
|
||||
GetEditAction() != EditAction::eReplaceText && mMaxTextLength < 0) {
|
||||
EditActionResult result = SetTextWithoutTransaction(aString);
|
||||
if (result.Failed() || result.Canceled() || result.Handled()) {
|
||||
NS_WARNING_ASSERTION(result.Succeeded(),
|
||||
"TextEditor::SetTextWithoutTransaction() failed");
|
||||
return result.Rv();
|
||||
Result<EditActionResult, nsresult> result =
|
||||
SetTextWithoutTransaction(aString);
|
||||
if (MOZ_UNLIKELY(result.isErr())) {
|
||||
NS_WARNING("TextEditor::SetTextWithoutTransaction() failed");
|
||||
return result.unwrapErr();
|
||||
}
|
||||
if (!result.inspect().Ignored()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,14 +414,14 @@ class TextEditor final : public EditorBase,
|
||||
* @return If aInsertionString is truncated, it returns "as
|
||||
* handled", else "as ignored."
|
||||
*/
|
||||
EditActionResult MaybeTruncateInsertionStringForMaxLength(
|
||||
Result<EditActionResult, nsresult> MaybeTruncateInsertionStringForMaxLength(
|
||||
nsAString& aInsertionString);
|
||||
|
||||
/**
|
||||
* InsertLineFeedCharacterAtSelection() inserts a linefeed character at
|
||||
* selection.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
InsertLineFeedCharacterAtSelection();
|
||||
|
||||
/**
|
||||
@ -446,9 +446,10 @@ class TextEditor final : public EditorBase,
|
||||
*/
|
||||
void HandleNewLinesInStringForSingleLineEditor(nsString& aString) const;
|
||||
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult HandleInsertText(
|
||||
EditSubAction aEditSubAction, const nsAString& aInsertionString,
|
||||
SelectionHandling aSelectionHandling) final;
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleInsertText(EditSubAction aEditSubAction,
|
||||
const nsAString& aInsertionString,
|
||||
SelectionHandling aSelectionHandling) final;
|
||||
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult InsertDroppedDataTransferAsAction(
|
||||
AutoEditActionDataSetter& aEditActionData,
|
||||
@ -463,7 +464,7 @@ class TextEditor final : public EditorBase,
|
||||
* needs to check if the editor is still available even if this returns
|
||||
* NS_OK.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleDeleteSelectionInternal(nsIEditor::EDirection aDirectionAndAmount,
|
||||
nsIEditor::EStripWrappers aStripWrappers);
|
||||
|
||||
@ -473,7 +474,7 @@ class TextEditor final : public EditorBase,
|
||||
* @param aDirectionAndAmount Direction of the deletion.
|
||||
* @param aStripWrappers Must be nsIEditor::eNoStrip.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
HandleDeleteSelection(nsIEditor::EDirection aDirectionAndAmount,
|
||||
nsIEditor::EStripWrappers aStripWrappers) final;
|
||||
|
||||
@ -484,7 +485,7 @@ class TextEditor final : public EditorBase,
|
||||
* the result is marked as "handled". Otherwise, the caller needs to
|
||||
* compute it with another way.
|
||||
*/
|
||||
EditActionResult ComputeValueFromTextNodeAndBRElement(
|
||||
Result<EditActionResult, nsresult> ComputeValueFromTextNodeAndBRElement(
|
||||
nsAString& aValue) const;
|
||||
|
||||
/**
|
||||
@ -492,7 +493,7 @@ class TextEditor final : public EditorBase,
|
||||
* and `<textarea>.value` to aValue without transaction. This must be
|
||||
* called only when it's not `HTMLEditor` and undo/redo is disabled.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
|
||||
SetTextWithoutTransaction(const nsAString& aValue);
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ WhiteSpaceVisibilityKeeper::PrepareToSplitBlockElement(
|
||||
}
|
||||
|
||||
// static
|
||||
EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
Result<EditActionResult, nsresult> WhiteSpaceVisibilityKeeper::
|
||||
MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement(
|
||||
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
|
||||
Element& aRightBlockElement, const EditorDOMPoint& aAtRightBlockChild,
|
||||
@ -181,41 +181,44 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_WARNING(
|
||||
"WhiteSpaceVisibilityKeeper::DeleteInvisibleASCIIWhiteSpaces() "
|
||||
"failed at left block");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
// Check whether aLeftBlockElement is a descendant of aRightBlockElement.
|
||||
if (aHTMLEditor.MayHaveMutationEventListeners()) {
|
||||
EditorDOMPoint leftBlockContainingPointInRightBlockElement;
|
||||
if (aHTMLEditor.MayHaveMutationEventListeners() &&
|
||||
!EditorUtils::IsDescendantOf(
|
||||
MOZ_UNLIKELY(!EditorUtils::IsDescendantOf(
|
||||
aLeftBlockElement, aRightBlockElement,
|
||||
&leftBlockContainingPointInRightBlockElement)) {
|
||||
&leftBlockContainingPointInRightBlockElement))) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at end of left block element caused "
|
||||
"moving the left block element outside the right block element");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
|
||||
if (leftBlockContainingPointInRightBlockElement != aAtRightBlockChild) {
|
||||
if (MOZ_UNLIKELY(leftBlockContainingPointInRightBlockElement !=
|
||||
aAtRightBlockChild)) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at end of left block element caused "
|
||||
"changing the left block element in the right block element");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
|
||||
if (!EditorUtils::IsEditableContent(aRightBlockElement, EditorType::HTML)) {
|
||||
if (MOZ_UNLIKELY(!EditorUtils::IsEditableContent(aRightBlockElement,
|
||||
EditorType::HTML))) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at end of left block element caused "
|
||||
"making the right block element non-editable");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
|
||||
if (!EditorUtils::IsEditableContent(aLeftBlockElement, EditorType::HTML)) {
|
||||
if (MOZ_UNLIKELY(!EditorUtils::IsEditableContent(aLeftBlockElement,
|
||||
EditorType::HTML))) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at end of left block element caused "
|
||||
"making the left block element non-editable");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,7 +234,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_WARNING(
|
||||
"WhiteSpaceVisibilityKeeper::DeleteInvisibleASCIIWhiteSpaces() "
|
||||
"failed at right block child");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
// XXX AutoTrackDOMPoint instance, tracker, hasn't been destroyed here.
|
||||
@ -243,7 +246,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
rightBlockElement = *afterRightBlockChild.ContainerAs<Element>();
|
||||
} else if (NS_WARN_IF(
|
||||
!afterRightBlockChild.GetContainerParentAs<Element>())) {
|
||||
return EditActionResult(NS_ERROR_UNEXPECTED);
|
||||
return Err(NS_ERROR_UNEXPECTED);
|
||||
} else {
|
||||
rightBlockElement = *afterRightBlockChild.GetContainerParentAs<Element>();
|
||||
}
|
||||
@ -257,7 +260,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_ASSERTION(
|
||||
aPrecedingInvisibleBRElement == invisibleBRElementAtEndOfLeftBlockElement,
|
||||
"The preceding invisible BR element computation was different");
|
||||
EditActionResult ret(NS_OK);
|
||||
auto ret = EditActionResult::IgnoredResult();
|
||||
// NOTE: Keep syncing with CanMergeLeftAndRightBlockElements() of
|
||||
// AutoInclusiveAncestorBlockElementsJoiner.
|
||||
if (NS_WARN_IF(aListElementTagName.isSome())) {
|
||||
@ -293,11 +296,11 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
EditorDOMPoint(rightBlockElement, afterRightBlockChild.Offset()),
|
||||
EditorDOMPoint(&aLeftBlockElement, 0u), aEditingHost,
|
||||
HTMLEditor::MoveToEndOfContainer::Yes);
|
||||
if (moveNodeResult.isErr()) {
|
||||
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
|
||||
NS_WARNING(
|
||||
"HTMLEditor::MoveOneHardLineContentsWithTransaction("
|
||||
"MoveToEndOfContainer::Yes) failed");
|
||||
return EditActionResult(moveNodeResult.unwrapErr());
|
||||
return moveNodeResult.propagateErr();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -314,7 +317,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
// We don't need to update selection here because of dontChangeMySelection
|
||||
// above.
|
||||
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
|
||||
ret |= moveNodeResult;
|
||||
ret |= moveNodeResult.unwrap();
|
||||
// Now, all children of rightBlockElement were moved to leftBlockElement.
|
||||
// So, afterRightBlockChild is now invalid.
|
||||
afterRightBlockChild.Clear();
|
||||
@ -329,13 +332,13 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
*invisibleBRElementAtEndOfLeftBlockElement);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed, but ignored");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
// static
|
||||
EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
Result<EditActionResult, nsresult> WhiteSpaceVisibilityKeeper::
|
||||
MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement(
|
||||
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
|
||||
Element& aRightBlockElement, const EditorDOMPoint& aAtLeftBlockChild,
|
||||
@ -365,43 +368,46 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_WARNING(
|
||||
"WhiteSpaceVisibilityKeeper::DeleteInvisibleASCIIWhiteSpaces() failed "
|
||||
"at right block");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
|
||||
// Check whether aRightBlockElement is a descendant of aLeftBlockElement.
|
||||
if (aHTMLEditor.MayHaveMutationEventListeners()) {
|
||||
EditorDOMPoint rightBlockContainingPointInLeftBlockElement;
|
||||
if (aHTMLEditor.MayHaveMutationEventListeners() &&
|
||||
!EditorUtils::IsDescendantOf(
|
||||
MOZ_UNLIKELY(!EditorUtils::IsDescendantOf(
|
||||
aRightBlockElement, aLeftBlockElement,
|
||||
&rightBlockContainingPointInLeftBlockElement)) {
|
||||
&rightBlockContainingPointInLeftBlockElement))) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at start of right block element "
|
||||
"caused moving the right block element outside the left block "
|
||||
"element");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
|
||||
if (rightBlockContainingPointInLeftBlockElement != aAtLeftBlockChild) {
|
||||
if (MOZ_UNLIKELY(rightBlockContainingPointInLeftBlockElement !=
|
||||
aAtLeftBlockChild)) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at start of right block element "
|
||||
"caused changing the right block element position in the left block "
|
||||
"element");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
|
||||
if (!EditorUtils::IsEditableContent(aLeftBlockElement, EditorType::HTML)) {
|
||||
if (MOZ_UNLIKELY(!EditorUtils::IsEditableContent(aLeftBlockElement,
|
||||
EditorType::HTML))) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at start of right block element "
|
||||
"caused making the left block element non-editable");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
|
||||
if (!EditorUtils::IsEditableContent(aRightBlockElement, EditorType::HTML)) {
|
||||
if (MOZ_UNLIKELY(!EditorUtils::IsEditableContent(aRightBlockElement,
|
||||
EditorType::HTML))) {
|
||||
NS_WARNING(
|
||||
"Deleting invisible whitespace at start of right block element "
|
||||
"caused making the right block element non-editable");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,14 +425,14 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_WARNING(
|
||||
"WhiteSpaceVisibilityKeeper::DeleteInvisibleASCIIWhiteSpaces() "
|
||||
"failed at left block child");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
}
|
||||
if (!atLeftBlockChild.IsSetAndValid()) {
|
||||
if (MOZ_UNLIKELY(!atLeftBlockChild.IsSetAndValid())) {
|
||||
NS_WARNING(
|
||||
"WhiteSpaceVisibilityKeeper::DeleteInvisibleASCIIWhiteSpaces() caused "
|
||||
"unexpected DOM tree");
|
||||
return EditActionResult(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
|
||||
}
|
||||
// XXX atLeftBlockChild.GetContainerAs<Element>() should always return
|
||||
// an element pointer so that probably here should not use
|
||||
@ -435,7 +441,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
atLeftBlockChild.GetContainerOrContainerParentElement()) {
|
||||
leftBlockElement = *nearestAncestor;
|
||||
} else {
|
||||
return EditActionResult(NS_ERROR_UNEXPECTED);
|
||||
return Err(NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
// Do br adjustment.
|
||||
@ -445,7 +451,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_ASSERTION(
|
||||
aPrecedingInvisibleBRElement == invisibleBRElementBeforeLeftBlockElement,
|
||||
"The preceding invisible BR element computation was different");
|
||||
EditActionResult ret(NS_OK);
|
||||
auto ret = EditActionResult::IgnoredResult();
|
||||
// NOTE: Keep syncing with CanMergeLeftAndRightBlockElements() of
|
||||
// AutoInclusiveAncestorBlockElementsJoiner.
|
||||
if (aListElementTagName.isSome()) {
|
||||
@ -466,16 +472,11 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
if (MOZ_UNLIKELY(moveNodeResult.isErr())) {
|
||||
if (NS_WARN_IF(moveNodeResult.inspectErr() ==
|
||||
NS_ERROR_EDITOR_DESTROYED)) {
|
||||
return EditActionResult(moveNodeResult.unwrapErr());
|
||||
return Err(moveNodeResult.unwrapErr());
|
||||
}
|
||||
NS_WARNING(
|
||||
"HTMLEditor::MoveChildrenWithTransaction() failed, but ignored");
|
||||
} else {
|
||||
// We don't need to update selection here because of dontChangeMySelection
|
||||
// above.
|
||||
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
|
||||
ret |= moveNodeResult;
|
||||
|
||||
#ifdef DEBUG
|
||||
MOZ_ASSERT(!rightBlockHasContent.isErr());
|
||||
if (rightBlockHasContent.inspect()) {
|
||||
@ -486,6 +487,10 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
"Failed to consider whether moving or not children");
|
||||
}
|
||||
#endif // #ifdef DEBUG
|
||||
// We don't need to update selection here because of dontChangeMySelection
|
||||
// above.
|
||||
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
|
||||
ret |= moveNodeResult.unwrap();
|
||||
}
|
||||
// atLeftBlockChild was moved to rightListElement. So, it's invalid now.
|
||||
atLeftBlockChild.Clear();
|
||||
@ -532,14 +537,14 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
HTMLEditor::SplitAtEdges::eDoNotCreateEmptyContainer);
|
||||
if (splitResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::SplitAncestorStyledInlineElementsAt() failed");
|
||||
return EditActionResult(splitResult.unwrapErr());
|
||||
return Err(splitResult.unwrapErr());
|
||||
}
|
||||
nsresult rv = splitResult.SuggestCaretPointTo(
|
||||
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
|
||||
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("SplitNodeResult::SuggestCaretPointTo() failed");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
if (!splitResult.DidSplit()) {
|
||||
// If nothing was split, we should move the first line content to after
|
||||
@ -562,16 +567,16 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
if (nsIContent* nextContentAtSplitPoint =
|
||||
splitResult.GetNextContent()) {
|
||||
pointToMoveFirstLineContent.Set(nextContentAtSplitPoint);
|
||||
if (!pointToMoveFirstLineContent.IsSet()) {
|
||||
if (MOZ_UNLIKELY(!pointToMoveFirstLineContent.IsSet())) {
|
||||
NS_WARNING("Next node of split point was orphaned");
|
||||
return EditActionResult(NS_ERROR_NULL_POINTER);
|
||||
return Err(NS_ERROR_NULL_POINTER);
|
||||
}
|
||||
} else {
|
||||
pointToMoveFirstLineContent =
|
||||
splitResult.AtSplitPoint<EditorDOMPoint>();
|
||||
if (!pointToMoveFirstLineContent.IsSet()) {
|
||||
if (MOZ_UNLIKELY(!pointToMoveFirstLineContent.IsSet())) {
|
||||
NS_WARNING("Split node was orphaned");
|
||||
return EditActionResult(NS_ERROR_NULL_POINTER);
|
||||
return Err(NS_ERROR_NULL_POINTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -584,7 +589,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
pointToMoveFirstLineContent, aEditingHost);
|
||||
if (moveNodeResult.isErr()) {
|
||||
NS_WARNING("HTMLEditor::MoveOneHardLineContentsWithTransaction() failed");
|
||||
return EditActionResult(moveNodeResult.unwrapErr());
|
||||
return moveNodeResult.propagateErr();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -601,7 +606,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
// We don't need to update selection here because of dontChangeMySelection
|
||||
// above.
|
||||
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
|
||||
ret |= moveNodeResult;
|
||||
ret |= moveNodeResult.unwrap();
|
||||
}
|
||||
|
||||
if (!invisibleBRElementBeforeLeftBlockElement ||
|
||||
@ -613,13 +618,13 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
*invisibleBRElementBeforeLeftBlockElement);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed, but ignored");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
// static
|
||||
EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
Result<EditActionResult, nsresult> WhiteSpaceVisibilityKeeper::
|
||||
MergeFirstLineOfRightBlockElementIntoLeftBlockElement(
|
||||
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
|
||||
Element& aRightBlockElement, const Maybe<nsAtom*>& aListElementTagName,
|
||||
@ -647,7 +652,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_WARNING(
|
||||
"WhiteSpaceVisibilityKeeper::"
|
||||
"MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange() failed");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
// Do br adjustment.
|
||||
RefPtr<HTMLBRElement> invisibleBRElementAtEndOfLeftBlockElement =
|
||||
@ -657,7 +662,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_ASSERTION(
|
||||
aPrecedingInvisibleBRElement == invisibleBRElementAtEndOfLeftBlockElement,
|
||||
"The preceding invisible BR element computation was different");
|
||||
EditActionResult ret(NS_OK);
|
||||
auto ret = EditActionResult::IgnoredResult();
|
||||
if (aListElementTagName.isSome() ||
|
||||
// TODO: We should stop merging entire blocks even if they have same
|
||||
// white-space style because Chrome behave so. However, it's risky to
|
||||
@ -672,7 +677,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
nsresult rv = aHTMLEditor.JoinNearestEditableNodesWithTransaction(
|
||||
aLeftBlockElement, aRightBlockElement, &atFirstChildOfRightNode);
|
||||
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
|
||||
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"HTMLEditor::JoinNearestEditableNodesWithTransaction()"
|
||||
@ -685,7 +690,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
if (MOZ_UNLIKELY(convertListTypeResult.isErr())) {
|
||||
if (NS_WARN_IF(convertListTypeResult.inspectErr() ==
|
||||
NS_ERROR_EDITOR_DESTROYED)) {
|
||||
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
|
||||
return Err(NS_ERROR_EDITOR_DESTROYED);
|
||||
}
|
||||
NS_WARNING("HTMLEditor::ChangeListElementType() failed, but ignored");
|
||||
}
|
||||
@ -711,7 +716,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
NS_WARNING(
|
||||
"HTMLEditor::MoveOneHardLineContentsWithTransaction("
|
||||
"MoveToEndOfContainer::Yes) failed");
|
||||
return EditActionResult(moveNodeResult.unwrapErr());
|
||||
return moveNodeResult.propagateErr();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -728,12 +733,13 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
// We don't need to update selection here because of dontChangeMySelection
|
||||
// above.
|
||||
moveNodeResult.inspect().IgnoreCaretPointSuggestion();
|
||||
ret |= moveNodeResult;
|
||||
ret |= moveNodeResult.unwrap();
|
||||
}
|
||||
|
||||
if (!invisibleBRElementAtEndOfLeftBlockElement ||
|
||||
!invisibleBRElementAtEndOfLeftBlockElement->IsInComposedDoc()) {
|
||||
return ret.MarkAsHandled();
|
||||
ret.MarkAsHandled();
|
||||
return ret;
|
||||
}
|
||||
|
||||
rv = aHTMLEditor.DeleteNodeWithTransaction(
|
||||
@ -743,9 +749,9 @@ EditActionResult WhiteSpaceVisibilityKeeper::
|
||||
// is respected?
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
|
||||
return EditActionResult(rv);
|
||||
return Err(rv);
|
||||
}
|
||||
return EditActionHandled();
|
||||
return EditActionResult::HandledResult();
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -1400,7 +1400,7 @@ class WhiteSpaceVisibilityKeeper final {
|
||||
* list element.
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<EditActionResult, nsresult>
|
||||
MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement(
|
||||
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
|
||||
Element& aRightBlockElement, const EditorDOMPoint& aAtRightBlockChild,
|
||||
@ -1429,7 +1429,7 @@ class WhiteSpaceVisibilityKeeper final {
|
||||
* list element.
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<EditActionResult, nsresult>
|
||||
MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement(
|
||||
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
|
||||
Element& aRightBlockElement, const EditorDOMPoint& aAtLeftBlockChild,
|
||||
@ -1453,7 +1453,7 @@ class WhiteSpaceVisibilityKeeper final {
|
||||
* element and its type needs to be changed.
|
||||
* @param aEditingHost The editing host.
|
||||
*/
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult
|
||||
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<EditActionResult, nsresult>
|
||||
MergeFirstLineOfRightBlockElementIntoLeftBlockElement(
|
||||
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
|
||||
Element& aRightBlockElement, const Maybe<nsAtom*>& aListElementTagName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user