Bug 1460509 - part 28: Make HTMLEditRules::AdjustWhitespace() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 14 May 2018 22:42:08 +0900
changeset 798746 b8fbae3ccecd66392b37df3b750a56c789f2f5bf
parent 798745 6995f85de581a856cccf1d73df1b6eba2602a7b7
child 798747 1ee689274b0e610f38723bbc86798f5fa86100c2
push id110840
push usermasayuki@d-toybox.com
push dateWed, 23 May 2018 13:41:58 +0000
reviewersm_kato
bugs1460509
milestone62.0a1
Bug 1460509 - part 28: Make HTMLEditRules::AdjustWhitespace() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r?m_kato MozReview-Commit-ID: 6dFP6BYDXMg
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -8632,16 +8632,19 @@ HTMLEditRules::AdjustWhitespace()
                       EditorBase::GetStartPoint(&SelectionRef()));
   if (NS_WARN_IF(!selectionStartPoint.IsSet())) {
     return NS_ERROR_FAILURE;
   }
 
   // Ask whitespace object to tweak nbsp's
   nsresult rv =
     WSRunObject(&HTMLEditorRef(), selectionStartPoint).AdjustWhitespace();
+  if (NS_WARN_IF(!CanHandleEditAction())) {
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::PinSelectionToNewBlock()
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -589,17 +589,22 @@ protected:
    * @param aListElement        A <ul>, <ol> or <dl> element.
    */
   MOZ_MUST_USE nsresult RemoveListStructure(Element& aListElement);
 
   nsresult CacheInlineStyles(nsINode* aNode);
   nsresult ReapplyCachedStyles();
   void ClearCachedStyles();
   void AdjustSpecialBreaks();
-  nsresult AdjustWhitespace();
+
+  /**
+   * AdjustWhitespace() may replace whitespaces with NBSP or something.
+   * See WSRunObject::AdjustWhitespace() for the detail.
+   */
+  MOZ_MUST_USE nsresult AdjustWhitespace();
 
   /**
    * PinSelectionToNewBlock() may collapse Selection around mNewNode if it's
    * necessary,
    */
   MOZ_MUST_USE nsresult PinSelectionToNewBlock();
 
   void CheckInterlinePosition();