Commit 909288b9 authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1658472 - part 5: Split `AutoInclusiveAncestorBlockElementsJoiner::Run()`...

Bug 1658472 - part 5: Split `AutoInclusiveAncestorBlockElementsJoiner::Run()` to computation part and touching the DOM tree part r=m_kato

Depends on D86884

Differential Revision: https://phabricator.services.mozilla.com/D86885
parent 5d035943
Loading
Loading
Loading
Loading
+46 −12
Original line number Diff line number Diff line
@@ -3218,12 +3218,19 @@ EditActionResult HTMLEditor::AutoBlockElementsJoiner::
    AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret);
    AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
                                                    *mRightContent);
    result |= joiner.Prepare();
    if (result.Failed()) {
      NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
      return result;
    }
    if (!result.Canceled() && !result.Handled()) {
      result |= joiner.Run(aHTMLEditor);
      if (result.Failed()) {
        NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
        return result;
      }
    }
  }

  // If AutoInclusiveAncestorBlockElementsJoiner didn't handle it and it's not
  // canceled, user may want to modify the start leaf node or the last leaf
@@ -3291,16 +3298,23 @@ EditActionResult HTMLEditor::AutoBlockElementsJoiner::
    AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret);
    AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
                                                    *mRightContent);
    result |= joiner.Prepare();
    if (result.Failed()) {
      NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
      return result;
    }
    if (!result.Canceled() && !result.Handled()) {
      result |= joiner.Run(aHTMLEditor);
    // This should claim that trying to join the block means that
    // this handles the action because the caller shouldn't do anything
    // anymore in this case.
    result.MarkAsHandled();
      if (result.Failed()) {
        NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
        return result;
      }
    }
    // This should claim that trying to join the block means that
    // this handles the action because the caller shouldn't do anything
    // anymore in this case.
    result.MarkAsHandled();
  }
  nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
  if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
    return result.SetResult(NS_ERROR_EDITOR_DESTROYED);
@@ -3701,11 +3715,20 @@ HTMLEditor::AutoBlockElementsJoiner::HandleDeleteNonCollapsedRanges(
    if (joinInclusiveAncestorBlockElements) {
      AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
                                                      *mRightContent);
      EditActionResult preparationResult = joiner.Prepare();
      result |= preparationResult;
      if (result.Failed()) {
        NS_WARNING(
            "AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
        return result;
      }
      if (!preparationResult.Canceled() && !preparationResult.Handled()) {
        result |= joiner.Run(aHTMLEditor);
        if (result.Failed()) {
          NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
          return result;
        }
      }

      // If we're joining blocks: if deleting forward the selection should
      // be collapsed to the end of the selection, if deleting backward the
@@ -4600,9 +4623,7 @@ HTMLEditor::AutoBlockElementsJoiner::JoinNodesDeepWithTransaction(
}

EditActionResult HTMLEditor::AutoBlockElementsJoiner::
    AutoInclusiveAncestorBlockElementsJoiner::Run(HTMLEditor& aHTMLEditor) {
  MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());

    AutoInclusiveAncestorBlockElementsJoiner::Prepare() {
  mLeftBlockElement = HTMLEditUtils::GetInclusiveAncestorBlockElement(
      mInclusiveDescendantOfLeftBlockElement);
  mRightBlockElement = HTMLEditUtils::GetInclusiveAncestorBlockElement(
@@ -4677,6 +4698,19 @@ EditActionResult HTMLEditor::AutoBlockElementsJoiner::
    }
  }

  return EditActionIgnored();
}

EditActionResult HTMLEditor::AutoBlockElementsJoiner::
    AutoInclusiveAncestorBlockElementsJoiner::Run(HTMLEditor& aHTMLEditor) {
  MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
  MOZ_ASSERT(mLeftBlockElement);
  MOZ_ASSERT(mRightBlockElement);

  if (mLeftBlockElement == mRightBlockElement) {
    return EditActionIgnored();
  }

  // If the left block element is in the right block element, move the hard
  // line including the right block element to end of the left block.
  // However, if we are merging list elements, we don't join them.
+15 −15
Original line number Diff line number Diff line
@@ -2948,21 +2948,21 @@ class HTMLEditor final : public TextEditor,
                aInclusiveDescendantOfRightBlockElement) {}

      /**
       * Tries to join two block elements.  The right element is always joined
       * to the left element.  If the elements are the same type and not nested
       * within each other, JoinEditableNodesWithTransaction() is called
       * (example, joining two list items together into one).  If the elements
       * are not the same type, or one is a descendant of the other, we instead
       * destroy the right block placing its children into leftblock.
       *
       * @return          Sets canceled to true if the operation should do
       *                  nothing anymore even if this doesn't join the blocks.
       *                  Sets handled to true if this actually handles the
       *                  request.  Note that this may set it to true even if
       *                  this does not join the block.  E.g., if the blocks
       *                  shouldn't be joined or it's impossible to join them
       *                  but it's not unexpected case, this return true with
       *                  this.
       * Prepare for joining inclusive ancestor block elements.  When this
       * returns error or "canceled" or "handled" state, don't call Run().
       */
      EditActionResult Prepare();

      /**
       * Join inclusive ancestor block elements which are found by preceding
       * Preare() call.
       * The right element is always joined to the left element.
       * If the elements are the same type and not nested within each other,
       * JoinEditableNodesWithTransaction() is called (example, joining two
       * list items together into one).
       * If the elements are not the same type, or one is a descendant of the
       * other, we instead destroy the right block placing its children into
       * left block.
       */
      [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
      Run(HTMLEditor& aHTMLEditor);