Bug 1574852 - part 13: Move `HTMLEditRules::CanContainParagraph()` to `HTMLEditor` r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 22 Aug 2019 08:29:38 +0000
changeset 553294 236e278e33a4871a38bcb4167ed868a952a31221
parent 553293 8ab6419caa6a8d474c5055c66e3530864db39816
child 553295 bc05d6bf98ef882a289ff4d6d8b66c87eb8a8ce6
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1574852
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1574852 - part 13: Move `HTMLEditRules::CanContainParagraph()` to `HTMLEditor` r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D42784
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
editor/libeditor/HTMLEditor.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -1621,20 +1621,20 @@ nsresult HTMLEditor::WillInsertText(Edit
     return rv;
   }
 
   rv = TopLevelEditSubActionDataRef().mChangedRange->CollapseTo(pointToInsert);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to collapse mChangedRange");
   return rv;
 }
 
-bool HTMLEditRules::CanContainParagraph(Element& aElement) const {
-  MOZ_ASSERT(IsEditorDataAvailable());
-
-  if (HTMLEditorRef().CanContainTag(aElement, *nsGkAtoms::p)) {
+bool HTMLEditor::CanContainParagraph(Element& aElement) const {
+  MOZ_ASSERT(IsEditActionDataAvailable());
+
+  if (CanContainTag(aElement, *nsGkAtoms::p)) {
     return true;
   }
 
   // Even if the element cannot have a <p> element as a child, it can contain
   // <p> element as a descendant if it's one of the following elements.
   if (aElement.IsAnyOfHTMLElements(nsGkAtoms::ol, nsGkAtoms::ul, nsGkAtoms::dl,
                                    nsGkAtoms::table, nsGkAtoms::thead,
                                    nsGkAtoms::tbody, nsGkAtoms::tfoot,
@@ -1726,32 +1726,32 @@ EditActionResult HTMLEditRules::WillInse
   if (!blockParent) {
     // XXX Chromium checks if the CSS box of the editing host is block.
     insertBRElement = true;
   }
   // If only the editing host is block, and the default paragraph separator
   // is <br> or the editing host cannot contain a <p> element, we should
   // insert a <br> element.
   else if (host == blockParent) {
-    insertBRElement =
-        separator == ParagraphSeparator::br || !CanContainParagraph(*host);
+    insertBRElement = separator == ParagraphSeparator::br ||
+                      !HTMLEditorRef().CanContainParagraph(*host);
   }
   // If the nearest block parent is a single-line container declared in
   // the execCommand spec and not the editing host, we should separate the
   // block even if the default paragraph separator is <br> element.
   else if (HTMLEditUtils::IsSingleLineContainer(*blockParent)) {
     insertBRElement = false;
   }
   // Otherwise, unless there is no block ancestor which can contain <p>
   // element, we shouldn't insert a <br> element here.
   else {
     insertBRElement = true;
     for (Element* blockAncestor = blockParent; blockAncestor && insertBRElement;
          blockAncestor = HTMLEditor::GetBlockNodeParent(blockAncestor, host)) {
-      insertBRElement = !CanContainParagraph(*blockAncestor);
+      insertBRElement = !HTMLEditorRef().CanContainParagraph(*blockAncestor);
     }
   }
 
   // If we cannot insert a <p>/<div> element at the selection, we should insert
   // a <br> element instead.
   if (insertBRElement) {
     nsresult rv = InsertBRElement(atStartOfSelection);
     if (NS_WARN_IF(NS_FAILED(rv))) {
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -172,22 +172,16 @@ class HTMLEditRules : public TextEditRul
   /**
    * InsertBRIfNeeded() determines if a br is needed for current selection to
    * not be spastic.  If so, it inserts one.  Callers responsibility to only
    * call with collapsed selection.
    */
   MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertBRIfNeeded();
 
   /**
-   * CanContainParagraph() returns true if aElement can have a <p> element as
-   * its child or its descendant.
-   */
-  bool CanContainParagraph(Element& aElement) const;
-
-  /**
    * Insert normal <br> element into aNode when aNode is a block and it has
    * no children.
    */
   MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult InsertBRIfNeeded(nsINode& aNode) {
     return InsertBRIfNeededInternal(aNode, false);
   }
 
   /**
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1182,16 +1182,22 @@ class HTMLEditor final : public TextEdit
    * Selection starts from inside a mail-cite element.  Of course, if it's
    * necessary, this inserts <br> node to new left nodes or existing right
    * nodes.
    * XXX This modifies Selection, but should return SplitNodeResult() instead.
    */
   MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
   SplitMailCiteElements(const EditorDOMPoint& aPointToSplit);
 
+  /**
+   * CanContainParagraph() returns true if aElement can have a <p> element as
+   * its child or its descendant.
+   */
+  bool CanContainParagraph(Element& aElement) const;
+
  protected:  // Called by helper classes.
   virtual void OnStartToHandleTopLevelEditSubAction(
       EditSubAction aEditSubAction, nsIEditor::EDirection aDirection) override;
   MOZ_CAN_RUN_SCRIPT
   virtual void OnEndHandlingTopLevelEditSubAction() override;
 
  protected:  // Shouldn't be used by friend classes
   virtual ~HTMLEditor();