Bug 1463985 - part 27: Replace EditSubAction::ignore with EditSubAction::eReplaceHeadWithHTMLSource and EditSubAction::eCreateBogusNode r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 29 May 2018 00:06:24 +0900
changeset 801997 96b34737232680f04534b5d14f4f0d29c547a04d
parent 801996 bbaaf63dab1e8d73154a1b96a5833c2e7461a841
push id111796
push usermasayuki@d-toybox.com
push dateThu, 31 May 2018 06:40:56 +0000
reviewersm_kato
bugs1463985
milestone62.0a1
Bug 1463985 - part 27: Replace EditSubAction::ignore with EditSubAction::eReplaceHeadWithHTMLSource and EditSubAction::eCreateBogusNode r?m_kato EditSubAction::ignore is declared for making HTMLEditRules::AfterEditInner() ignores post-processing of handling edit action. Currently, this is used only by TextEditRules::CreateBogusNodeIfNeeded() and HTMLEditor::ReplaceHeadContentsWithHTML(). So, we should make them use specific EditSubAction values which explain what they do and make HTMLEditRules::AfterEditInner() ignore both of them. MozReview-Commit-ID: JSHcgPfTrOE
editor/libeditor/EditAction.h
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/TextEditRules.cpp
--- a/editor/libeditor/EditAction.h
+++ b/editor/libeditor/EditAction.h
@@ -9,21 +9,19 @@
 namespace mozilla {
 
 // This is int32_t instead of int16_t because nsIInlineSpellChecker.idl's
 // spellCheckAfterEditorChange is defined to take it as a long.
 // TODO: Make each name eFoo and investigate whether the numeric values
 //       still have some meaning.
 enum class EditSubAction : int32_t
 {
-  ignore = -1,
-
   // eNone indicates not edit sub-action is being handled.  This is useful
   // of initial value of member variables.
-  eNone = 0,
+  eNone,
 
   // eUndo and eRedo indicate entire actions of undo/redo operation.
   eUndo,
   eRedo,
 
   // eInsertNode indicates to insert a new node into the DOM tree.
   eInsertNode,
 
@@ -104,25 +102,32 @@ enum class EditSubAction : int32_t
 
   // ePasteHTMLContent indicates to paste HTML content in clipboard.
   ePasteHTMLContent,
 
   // eInsertHTMLSource indicates to create a document fragment from given HTML
   // source and insert into the DOM tree.  So, this is similar to innerHTML.
   eInsertHTMLSource,
 
-  // eSetPositionToAbsolute and eSetPositionToStatic indicate to set position
+  // eReplaceHeadWithHTMLSource indicates to create a document fragment from
+  // given HTML source and replace content of <head> with it.
+  eReplaceHeadWithHTMLSource,
+
+  // eSetPositionToAbsolute and eSetPositionToStatic indicates to set position
   // property to absolute or static.
   eSetPositionToAbsolute,
   eSetPositionToStatic,
 
   // eDecreaseZIndex and eIncreaseZIndex indicate to decrease and increase
   // z-index value.
   eDecreaseZIndex,
   eIncreaseZIndex,
+
+  // eCreateBogusNode indicates to create a bogus <br> node.
+  eCreateBogusNode,
 };
 
 } // namespace mozilla
 
 inline bool operator!(const mozilla::EditSubAction& aEditSubAction)
 {
   return aEditSubAction == mozilla::EditSubAction::eNone;
 }
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -463,17 +463,18 @@ HTMLEditRules::AfterEditInner(EditSubAct
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   nsresult rv = ConfirmSelectionInBody();
   if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
     return NS_ERROR_EDITOR_DESTROYED;
   }
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to normalize Selection");
-  if (aEditSubAction == EditSubAction::ignore) {
+  if (aEditSubAction == EditSubAction::eReplaceHeadWithHTMLSource ||
+      aEditSubAction == EditSubAction::eCreateBogusNode) {
     return NS_OK;
   }
 
   nsCOMPtr<nsINode> rangeStartContainer, rangeEndContainer;
   uint32_t rangeStartOffset = 0, rangeEndOffset = 0;
   // do we have a real range to act on?
   bool bDamagedRange = false;
   if (mDocChangeRange) {
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1221,19 +1221,20 @@ HTMLEditor::CollapseSelectionToDeepestNo
  * This is mostly like InsertHTMLWithCharsetAndContext, but we can't use that
  * because it is selection-based and the rules code won't let us edit under the
  * <head> node
  */
 NS_IMETHODIMP
 HTMLEditor::ReplaceHeadContentsWithHTML(const nsAString& aSourceToInsert)
 {
   // don't do any post processing, rules get confused
-  AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
-                                      *this, EditSubAction::ignore,
-                                      nsIEditor::eNone);
+  AutoTopLevelEditSubActionNotifier
+    maybeTopLevelEditSubAction(*this,
+                               EditSubAction::eReplaceHeadWithHTMLSource,
+                               nsIEditor::eNone);
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   CommitComposition();
 
   // Do not use AutoTopLevelEditSubActionNotifier -- rules code won't let us
   // insert in <head>.  Use the head node as a parent and delete/insert
   // directly.
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1496,17 +1496,18 @@ TextEditRules::CreateBogusNodeIfNeeded()
 
   if (mBogusNode) {
     // Let's not create more than one, ok?
     return NS_OK;
   }
 
   // tell rules system to not do any post-processing
   AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
-                                      TextEditorRef(), EditSubAction::ignore,
+                                      TextEditorRef(),
+                                      EditSubAction::eCreateBogusNode,
                                       nsIEditor::eNone);
 
   RefPtr<Element> rootElement = TextEditorRef().GetRoot();
   if (!rootElement) {
     // We don't even have a body yet, don't insert any bogus nodes at
     // this point.
     return NS_OK;
   }