Bug 1572375 - part 8: Wrap `EditorBase::mPaddingBRElementForEmptyEditor` with an inline method r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 13 Aug 2019 00:57:38 +0000
changeset 487569 3a07d2f4b955d2e8847d4b8c73ae7a657b5195d9
parent 487568 571000b4df5b49b8cbee56e0298233633f4ab932
child 487570 58dd47c5aa51acc3095c623148df986354dfbf72
push id92340
push usermasayuki@d-toybox.com
push dateTue, 13 Aug 2019 02:32:12 +0000
treeherderautoland@3a07d2f4b955 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1572375
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 1572375 - part 8: Wrap `EditorBase::mPaddingBRElementForEmptyEditor` with an inline method r=m_kato `TextEditRules` and `HTMLEditRules` still refer `EditorBase::mPaddingBRElementForEmptyEditor` directly but this is really ugly. Therefore, this patch creates `EditorBase::HasPaddingBRElementForEmptyEditor()` for wrapping its access. Differential Revision: https://phabricator.services.mozilla.com/D41162
editor/libeditor/EditorBase.h
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/TextEditRules.cpp
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1463,16 +1463,25 @@ class EditorBase : public nsIEditor,
    *                    aLeftNode.
    * @return            The point of the first child of the last right node.
    */
   MOZ_CAN_RUN_SCRIPT
   EditorDOMPoint JoinNodesDeepWithTransaction(nsIContent& aLeftNode,
                                               nsIContent& aRightNode);
 
   /**
+   * HasPaddingBRElementForEmptyEditor() returns true if there is a padding
+   * <br> element for empty editor.  When this returns true, it means that
+   * we're empty.
+   */
+  bool HasPaddingBRElementForEmptyEditor() const {
+    return !!mPaddingBRElementForEmptyEditor;
+  }
+
+  /**
    * EnsureNoPaddingBRElementForEmptyEditor() removes padding <br> element
    * for empty editor if there is.
    */
   MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
   EnsureNoPaddingBRElementForEmptyEditor();
 
   /**
    * MaybeCreatePaddingBRElementForEmptyEditor() creates padding <br> element
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -818,17 +818,19 @@ nsresult HTMLEditRules::DidDoAction(Edit
       MOZ_ASSERT_UNREACHABLE("This path should've been dead code");
       return NS_ERROR_UNEXPECTED;
     default:
       return TextEditRules::DidDoAction(aInfo, aResult);
   }
 }
 
 bool HTMLEditRules::DocumentIsEmpty() const {
-  return !!HTMLEditorRef().mPaddingBRElementForEmptyEditor;
+  // XXX This is wrong.  Even if there is no padding <br> element for empty
+  //     editor, the editor may be empty.
+  return HTMLEditorRef().HasPaddingBRElementForEmptyEditor();
 }
 
 nsresult HTMLEditRules::GetListState(bool* aMixed, bool* aOL, bool* aUL,
                                      bool* aDL) {
   NS_ENSURE_TRUE(aMixed && aOL && aUL && aDL, NS_ERROR_NULL_POINTER);
   *aMixed = false;
   *aOL = false;
   *aUL = false;
@@ -2287,17 +2289,17 @@ nsresult HTMLEditRules::WillDeleteSelect
   *aHandled = false;
 
   // Remember that we did a selection deletion.  Used by
   // CreateStyleForInsertText()
   mDidDeleteSelection = true;
 
   // If there is only padding <br> element for empty editor, cancel the
   // operation.
-  if (HTMLEditorRef().mPaddingBRElementForEmptyEditor) {
+  if (HTMLEditorRef().HasPaddingBRElementForEmptyEditor()) {
     *aCancel = true;
     return NS_OK;
   }
 
   // First check for table selection mode.  If so, hand off to table editor.
   ErrorResult error;
   RefPtr<Element> cellElement =
       HTMLEditorRef().GetFirstSelectedTableCellElement(error);
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1001,17 +1001,17 @@ nsresult TextEditRules::WillDeleteSelect
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
 
   // initialize out param
   *aCancel = false;
   *aHandled = false;
 
   // if there is only padding <br> element for empty editor, cancel the
   // operation.
-  if (TextEditorRef().mPaddingBRElementForEmptyEditor) {
+  if (TextEditorRef().HasPaddingBRElementForEmptyEditor()) {
     *aCancel = true;
     return NS_OK;
   }
   nsresult rv =
       DeleteSelectionWithTransaction(aCollapsedAction, aCancel, aHandled);
   // DeleteSelectionWithTransaction() creates SelectionBatcher.  Therefore,
   // quitting from it might cause having destroyed the editor.
   if (NS_WARN_IF(!CanHandleEditAction())) {
@@ -1131,17 +1131,17 @@ nsresult TextEditRules::WillOutputText(c
   *aHandled = false;
 
   if (!aOutputFormat->LowerCaseEqualsLiteral("text/plain")) {
     return NS_OK;
   }
 
   // If there is a padding <br> element, there's no content.  So output empty
   // string.
-  if (TextEditorRef().mPaddingBRElementForEmptyEditor) {
+  if (TextEditorRef().HasPaddingBRElementForEmptyEditor()) {
     aOutString->Truncate();
     *aHandled = true;
     return NS_OK;
   }
 
   // If it's necessary to check selection range or the editor wraps hard,
   // we need some complicated handling.  In such case, we need to use the
   // expensive path.