Commit 416e5165 authored by Molnar Sandor's avatar Molnar Sandor
Browse files

Backed out 7 changesets (bug 1730442) for causing reftest failures in...

Backed out 7 changesets (bug 1730442) for causing reftest failures in editor/reftests/inline-table-editor-position-after-updating-table-size-from-input-event-listener.html. CLOSED TREE

Backed out changeset f6d7f162e57a (bug 1730442)
Backed out changeset e5d1671b3bbc (bug 1730442)
Backed out changeset e60a5cd69184 (bug 1730442)
Backed out changeset 943d4e4b0770 (bug 1730442)
Backed out changeset bd3324b635f4 (bug 1730442)
Backed out changeset ada0dda5bcde (bug 1730442)
Backed out changeset b67c4035c12f (bug 1730442)
parent b1015d9c
Loading
Loading
Loading
Loading
+0 −70
Original line number Diff line number Diff line
@@ -228,23 +228,6 @@ enum class EditAction {
  // <td> or <th>.
  eSetTableCellElementType,

  // Those edit actions are mapped to the methods in nsITableEditor which
  // access table layout information.
  eSelectTableCell,
  eSelectTableRow,
  eSelectTableColumn,
  eSelectTable,
  eSelectAllTableCells,
  eGetCellIndexes,
  eGetTableSize,
  eGetCellAt,
  eGetCellDataAt,
  eGetFirstRow,
  eGetSelectedOrParentTableElement,
  eGetSelectedCellsType,
  eGetFirstSelectedCellInTable,
  eGetSelectedCells,

  // eSetInlineStyleProperty indicates to set CSS another inline style property
  // which is not defined below.
  eSetInlineStyleProperty,
@@ -493,26 +476,6 @@ enum class EditSubAction : int32_t {
  eCreatePaddingBRElementForEmptyEditor,
};

// You can use this macro as:
//   case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING:
// clang-format off
#define NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING \
       mozilla::EditAction::eSelectTableCell:                     \
  case mozilla::EditAction::eSelectTableRow:                      \
  case mozilla::EditAction::eSelectTableColumn:                   \
  case mozilla::EditAction::eSelectTable:                         \
  case mozilla::EditAction::eSelectAllTableCells:                 \
  case mozilla::EditAction::eGetCellIndexes:                      \
  case mozilla::EditAction::eGetTableSize:                        \
  case mozilla::EditAction::eGetCellAt:                           \
  case mozilla::EditAction::eGetCellDataAt:                       \
  case mozilla::EditAction::eGetFirstRow:                         \
  case mozilla::EditAction::eGetSelectedOrParentTableElement:     \
  case mozilla::EditAction::eGetSelectedCellsType:                \
  case mozilla::EditAction::eGetFirstSelectedCellInTable:         \
  case mozilla::EditAction::eGetSelectedCells
// clang-format on

inline EditorInputType ToInputType(EditAction aEditAction) {
  switch (aEditAction) {
    case EditAction::eInsertText:
@@ -649,16 +612,6 @@ inline bool MayEditActionDeleteAroundCollapsedSelection(
  }
}

inline bool IsEditActionInOrderToEditSomething(const EditAction aEditAction) {
  switch (aEditAction) {
    case EditAction::eNotEditing:
    case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING:
      return false;
    default:
      return true;
  }
}

inline bool IsEditActionTableEditing(const EditAction aEditAction) {
  switch (aEditAction) {
    case EditAction::eInsertTableRowElement:
@@ -683,7 +636,6 @@ inline bool MayEditActionDeleteSelection(const EditAction aEditAction) {
    case EditAction::eNone:
    case EditAction::eNotEditing:
    case EditAction::eInitializing:
    case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING:
      return false;

    // EditActions modifying around selection.
@@ -827,28 +779,6 @@ inline bool MayEditActionDeleteSelection(const EditAction aEditAction) {
  return false;
}

inline bool MayEditActionRequireLayout(const EditAction aEditAction) {
  switch (aEditAction) {
    // Table editing require layout information for referring table cell data
    // such as row/column number and rowspan/colspan.
    case EditAction::eInsertTableRowElement:
    case EditAction::eRemoveTableRowElement:
    case EditAction::eInsertTableColumn:
    case EditAction::eRemoveTableColumn:
    case EditAction::eRemoveTableElement:
    case EditAction::eRemoveTableCellElement:
    case EditAction::eDeleteTableCellContents:
    case EditAction::eInsertTableCellElement:
    case EditAction::eJoinTableCellElements:
    case EditAction::eSplitTableCellElement:
    case EditAction::eSetTableCellElementType:
    case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING:
      return true;
    default:
      return false;
  }
}

}  // namespace mozilla

inline bool operator!(const mozilla::EditSubAction& aEditSubAction) {
+6 −25
Original line number Diff line number Diff line
@@ -6066,7 +6066,6 @@ EditorBase::AutoEditActionDataSetter::AutoEditActionDataSetter(
      mPrincipal(aPrincipal),
      mParentData(aEditorBase.mEditActionData),
      mData(VoidString()),
      mRawEditAction(aEditAction),
      mTopLevelEditSubAction(EditSubAction::eNone),
      mAborted(false),
      mHasTriedToDispatchBeforeInputEvent(false),
@@ -6083,10 +6082,10 @@ EditorBase::AutoEditActionDataSetter::AutoEditActionDataSetter(
    MOZ_ASSERT(!mSelection ||
               (mSelection->GetType() == SelectionType::eNormal));

    // If we're not editing something, we should inherit the parent's edit
    // action. This may occur if creator or its callee use public methods which
    // If we're eNotEditing, we should inherit the parent's edit action.
    // This may occur if creator or its callee use public methods which
    // just returns something.
    if (IsEditActionInOrderToEditSomething(aEditAction)) {
    if (aEditAction != EditAction::eNotEditing) {
      mEditAction = aEditAction;
    } else {
      mEditAction = mParentData->mEditAction;
@@ -6328,30 +6327,12 @@ bool EditorBase::AutoEditActionDataSetter::IsBeforeInputEventEnabled() const {
  return true;
}

nsresult EditorBase::AutoEditActionDataSetter::MaybeFlushPendingNotifications()
    const {
  MOZ_ASSERT(CanHandle());
  if (!MayEditActionRequireLayout(mRawEditAction)) {
    return NS_SUCCESS_DOM_NO_OPERATION;
  }
  OwningNonNull<EditorBase> editorBase = mEditorBase;
  RefPtr<PresShell> presShell = editorBase->GetPresShell();
  if (MOZ_UNLIKELY(NS_WARN_IF(!presShell))) {
    return NS_ERROR_NOT_AVAILABLE;
  }
  presShell->FlushPendingNotifications(FlushType::Layout);
  if (MOZ_UNLIKELY(NS_WARN_IF(editorBase->Destroyed()))) {
    return NS_ERROR_EDITOR_DESTROYED;
  }
  return NS_OK;
}

nsresult EditorBase::AutoEditActionDataSetter::MaybeDispatchBeforeInputEvent(
    nsIEditor::EDirection aDeleteDirectionAndAmount /* = nsIEditor::eNone */) {
    nsIEditor::EDirection aDeleteDirectionAndAmount /* nsIEditor::eNone */) {
  MOZ_ASSERT(!HasTriedToDispatchBeforeInputEvent(),
             "We've already handled beforeinput event");
  MOZ_ASSERT(CanHandle());
  MOZ_ASSERT_IF(IsBeforeInputEventEnabled(),
  MOZ_ASSERT(!IsBeforeInputEventEnabled() ||
             ShouldAlreadyHaveHandledBeforeInputEventDispatching());
  MOZ_ASSERT_IF(!MayEditActionDeleteAroundCollapsedSelection(mEditAction),
                aDeleteDirectionAndAmount == nsIEditor::eNone);
+1 −24
Original line number Diff line number Diff line
@@ -991,23 +991,11 @@ class EditorBase : public nsIEditor,
    }
    [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
    CanHandleAndMaybeDispatchBeforeInputEvent() {
      if (MOZ_UNLIKELY(NS_WARN_IF(!CanHandle()))) {
      if (NS_WARN_IF(!CanHandle())) {
        return NS_ERROR_NOT_INITIALIZED;
      }
      nsresult rv = MaybeFlushPendingNotifications();
      if (MOZ_UNLIKELY(NS_FAILED(rv))) {
        return rv;
      }
      return MaybeDispatchBeforeInputEvent();
    }
    [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
    CanHandleAndFlushPendingNotifications() {
      if (MOZ_UNLIKELY(NS_WARN_IF(!CanHandle()))) {
        return NS_ERROR_NOT_INITIALIZED;
      }
      MOZ_ASSERT(MayEditActionRequireLayout(mRawEditAction));
      return MaybeFlushPendingNotifications();
    }

    [[nodiscard]] bool IsDataAvailable() const {
      return mSelection && mEditorBase.IsInitialized();
@@ -1289,9 +1277,6 @@ class EditorBase : public nsIEditor,
   private:
    bool IsBeforeInputEventEnabled() const;

    [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
    MaybeFlushPendingNotifications() const;

    static bool NeedsBeforeInputEventHandling(EditAction aEditAction) {
      MOZ_ASSERT(aEditAction != EditAction::eNone);
      switch (aEditAction) {
@@ -1302,9 +1287,6 @@ class EditorBase : public nsIEditor,
        // If we're being initialized, we may need to create a padding <br>
        // element, but it shouldn't cause `beforeinput` event.
        case EditAction::eInitializing:
        // If we're just selecting or getting table cells, we shouldn't
        // dispatch `beforeinput` event.
        case NS_EDIT_ACTION_CASES_ACCESSING_TABLE_DATA_WITHOUT_EDITING:
        // If raw level transaction API is used, the API user needs to handle
        // both "beforeinput" event and "input" event if it's necessary.
        case EditAction::eUnknown:
@@ -1389,12 +1371,7 @@ class EditorBase : public nsIEditor,
    // for current edit sub action.
    EditSubActionData mEditSubActionData;

    // mEditAction and mRawEditActions stores edit action.  The difference of
    // them is, if and only if edit actions are nested and parent edit action
    // is one of trying to edit something, but nested one is not so, it's
    // overwritten by the parent edit action.
    EditAction mEditAction;
    EditAction mRawEditAction;

    // Different from its data, you can refer "current" AutoEditActionDataSetter
    // instance's mTopLevelEditSubAction member since it's copied from the
+0 −48
Original line number Diff line number Diff line
@@ -1384,54 +1384,6 @@ class HTMLEditUtils final {
    return nullptr;
  }

  /**
   * GetFirstTableCellElementChild() and GetLastTableCellElementChild()
   * return the first/last element child of <tr> element if it's a table
   * cell element.
   */
  static Element* GetFirstTableCellElementChild(
      const Element& aTableRowElement) {
    MOZ_ASSERT(aTableRowElement.IsHTMLElement(nsGkAtoms::tr));
    Element* firstElementChild = aTableRowElement.GetFirstElementChild();
    return firstElementChild && HTMLEditUtils::IsTableCell(firstElementChild)
               ? firstElementChild
               : nullptr;
  }
  static Element* GetLastTableCellElementChild(
      const Element& aTableRowElement) {
    MOZ_ASSERT(aTableRowElement.IsHTMLElement(nsGkAtoms::tr));
    Element* lastElementChild = aTableRowElement.GetLastElementChild();
    return lastElementChild && HTMLEditUtils::IsTableCell(lastElementChild)
               ? lastElementChild
               : nullptr;
  }

  /**
   * GetPreviousTableCellElementSibling() and GetNextTableCellElementSibling()
   * return a table cell element of previous/next element sibling of given
   * content node if and only if the element sibling is a table cell element.
   */
  static Element* GetPreviousTableCellElementSibling(
      const nsIContent& aChildOfTableRow) {
    MOZ_ASSERT(aChildOfTableRow.GetParentNode());
    MOZ_ASSERT(aChildOfTableRow.GetParentNode()->IsHTMLElement(nsGkAtoms::tr));
    Element* previousElementSibling =
        aChildOfTableRow.GetPreviousElementSibling();
    return previousElementSibling &&
                   HTMLEditUtils::IsTableCell(previousElementSibling)
               ? previousElementSibling
               : nullptr;
  }
  static Element* GetNextTableCellElementSibling(
      const nsIContent& aChildOfTableRow) {
    MOZ_ASSERT(aChildOfTableRow.GetParentNode());
    MOZ_ASSERT(aChildOfTableRow.GetParentNode()->IsHTMLElement(nsGkAtoms::tr));
    Element* nextElementSibling = aChildOfTableRow.GetNextElementSibling();
    return nextElementSibling && HTMLEditUtils::IsTableCell(nextElementSibling)
               ? nextElementSibling
               : nullptr;
  }

  /**
   * GetMostDistantAncestorInlineElement() returns the most distant ancestor
   * inline element between aContent and the aEditingHost.  Even if aEditingHost
+22 −20
Original line number Diff line number Diff line
@@ -1277,7 +1277,7 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
  }

  // Find enclosing table cell from selection (cell may be selected element)
  const RefPtr<Element> cellElement =
  Element* cellElement =
      GetInclusiveAncestorByTagNameAtSelection(*nsGkAtoms::td);
  if (!cellElement) {
    NS_WARNING(
@@ -1339,19 +1339,18 @@ 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);
  }
  rv = InsertTableRowsWithTransaction(*cellElement, 1,
                                      InsertPosition::eAfterSelectedCell);
  rv = InsertTableRowsWithTransaction(1, InsertPosition::eAfterSelectedCell);
  if (NS_WARN_IF(Destroyed())) {
    return EditActionHandled(NS_ERROR_EDITOR_DESTROYED);
  }
  if (NS_FAILED(rv)) {
    NS_WARNING(
        "HTMLEditor::InsertTableRowsWithTransaction(*cellElement, 1, "
        "HTMLEditor::InsertTableRowsWithTransaction(1, "
        "InsertPosition::eAfterSelectedCell) failed");
    return EditActionHandled(rv);
  }
@@ -2353,15 +2352,17 @@ nsresult HTMLEditor::GetHTMLBackgroundColorState(bool* aMixed,
  *aMixed = false;
  aOutColor.Truncate();

  Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError =
      GetSelectedOrParentTableElement();
  if (cellOrRowOrTableElementOrError.isErr()) {
    NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() returned error");
    return cellOrRowOrTableElementOrError.unwrapErr();
  ErrorResult error;
  RefPtr<Element> cellOrRowOrTableElement =
      GetSelectedOrParentTableElement(error);
  if (error.Failed()) {
    NS_WARNING(
        "HTMLEditor::GetSelectedOrParentTableElement() returned nullptr");
    return error.StealNSResult();
  }

  for (RefPtr<Element> element = cellOrRowOrTableElementOrError.unwrap();
       element; element = element->GetParentElement()) {
  for (RefPtr<Element> element = std::move(cellOrRowOrTableElement); element;
       element = element->GetParentElement()) {
    // We are in a cell or selected table
    element->GetAttr(kNameSpaceID_None, nsGkAtoms::bgcolor, aOutColor);

@@ -2719,7 +2720,7 @@ Element* HTMLEditor::GetInclusiveAncestorByTagNameAtSelection(
}

Element* HTMLEditor::GetInclusiveAncestorByTagNameInternal(
    const nsStaticAtom& aTagName, const nsIContent& aContent) const {
    const nsStaticAtom& aTagName, nsIContent& aContent) const {
  MOZ_ASSERT(&aTagName != nsGkAtoms::_empty);

  Element* currentElement = aContent.GetAsElementOrParentElement();
@@ -3296,18 +3297,19 @@ nsresult HTMLEditor::SetHTMLBackgroundColorWithTransaction(
  MOZ_ASSERT(IsEditActionDataAvailable());

  // Find a selected or enclosing table element to set background on
  ErrorResult error;
  bool isCellSelected = false;
  Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError =
      GetSelectedOrParentTableElement(&isCellSelected);
  if (cellOrRowOrTableElementOrError.isErr()) {
  RefPtr<Element> cellOrRowOrTableElement =
      GetSelectedOrParentTableElement(error, &isCellSelected);
  if (error.Failed()) {
    NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() failed");
    return cellOrRowOrTableElementOrError.unwrapErr();
    return error.StealNSResult();
  }

  bool setColor = !aColor.IsEmpty();
  RefPtr<Element> rootElementOfBackgroundColor =
      cellOrRowOrTableElementOrError.unwrap();
  if (rootElementOfBackgroundColor) {
  RefPtr<Element> rootElementOfBackgroundColor;
  if (cellOrRowOrTableElement) {
    rootElementOfBackgroundColor = std::move(cellOrRowOrTableElement);
    // Needs to set or remove background color of each selected cell elements.
    // Therefore, just the cell contains selection range, we don't need to
    // do this.  Note that users can select each cell, but with Selection API,
Loading