Bug 1480055 - part 1: Remove nsIEditor::shouldTxnSetSelection() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 01 Aug 2018 20:16:30 +0900
changeset 825746 ae7788ac79a79d5f8f65e4b0327e19e915ebd59b
parent 825745 338d8b83f029333b6e4a8a335da0469be554593f
child 825747 2c1cbb7b73c7af4892fbb3b8967a648a8b6d02d3
push id118159
push usermasayuki@d-toybox.com
push dateThu, 02 Aug 2018 07:24:41 +0000
reviewersm_kato
bugs1480055
milestone63.0a1
Bug 1480055 - part 1: Remove nsIEditor::shouldTxnSetSelection() r?m_kato nsIEditor::ShouldTxnSetSelection() is used only by DeleteRangeTransaction (even if including comm-central and BlueGriffon) and there is a non-virtual method EditorBase::GetShouldTxnSetSelection(). So, we can remove this. MozReview-Commit-ID: JWSCw9k6lI0
editor/libeditor/DeleteRangeTransaction.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/nsIEditor.idl
--- a/editor/libeditor/DeleteRangeTransaction.cpp
+++ b/editor/libeditor/DeleteRangeTransaction.cpp
@@ -86,19 +86,17 @@ DeleteRangeTransaction::DoTransaction()
 
   // if we've successfully built this aggregate transaction, then do it.
   nsresult rv = EditAggregateTransaction::DoTransaction();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // only set selection to deletion point if editor gives permission
-  bool bAdjustSelection;
-  mEditorBase->ShouldTxnSetSelection(&bAdjustSelection);
-  if (bAdjustSelection) {
+  if (mEditorBase->GetShouldTxnSetSelection()) {
     RefPtr<Selection> selection = mEditorBase->GetSelection();
     if (NS_WARN_IF(!selection)) {
       return NS_ERROR_NULL_POINTER;
     }
     rv = selection->Collapse(startRef.AsRaw());
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -978,24 +978,16 @@ EditorBase::EndPlaceholderTransaction()
     } else {
       NotifyEditorObservers(eNotifyEditorObserversOfCancel);
     }
   }
   mPlaceholderBatch--;
 }
 
 NS_IMETHODIMP
-EditorBase::ShouldTxnSetSelection(bool* aResult)
-{
-  NS_ENSURE_TRUE(aResult, NS_ERROR_NULL_POINTER);
-  *aResult = mShouldTxnSetSelection;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 EditorBase::SetShouldTxnSetSelection(bool aShould)
 {
   mShouldTxnSetSelection = aShould;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::GetDocumentIsEmpty(bool* aDocumentIsEmpty)
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -55,16 +55,17 @@ class AutoSelectionRestorer;
 class AutoTopLevelEditSubActionNotifier;
 class AutoTransactionsConserveSelection;
 class AutoUpdateViewBatch;
 class ChangeAttributeTransaction;
 class CompositionTransaction;
 class CreateElementTransaction;
 class CSSEditUtils;
 class DeleteNodeTransaction;
+class DeleteRangeTransaction;
 class DeleteTextTransaction;
 class EditAggregateTransaction;
 class EditorEventListener;
 class EditTransactionBase;
 class ErrorResult;
 class HTMLEditor;
 class HTMLEditUtils;
 class IMEContentObserver;
@@ -1966,16 +1967,17 @@ protected:
   friend class AutoSelectionRestorer;
   friend class AutoTopLevelEditSubActionNotifier;
   friend class AutoTransactionsConserveSelection;
   friend class AutoUpdateViewBatch;
   friend class CompositionTransaction;
   friend class CreateElementTransaction;
   friend class CSSEditUtils;
   friend class DeleteNodeTransaction;
+  friend class DeleteRangeTransaction;
   friend class DeleteTextTransaction;
   friend class HTMLEditRules;
   friend class HTMLEditUtils;
   friend class InsertNodeTransaction;
   friend class InsertTextTransaction;
   friend class JoinNodeTransaction;
   friend class SplitNodeTransaction;
   friend class TextEditRules;
--- a/editor/nsIEditor.idl
+++ b/editor/nsIEditor.idl
@@ -211,26 +211,33 @@ interface nsIEditor  : nsISupports
   /** endTransaction is a signal to the editor that the caller is
     * finished updating the content model.<br>
     * beginUpdate must be called before endTransaction is called.<br>
     * Calls to beginTransaction can be nested, as long as endTransaction
     * is called once per beginTransaction.
     */
   void endTransaction();
 
-  boolean shouldTxnSetSelection();
-
-  /** Set the flag that prevents insertElementTxn from changing the selection
-    * @param   should  Set false to suppress changing the selection;
-    *                  i.e., before using InsertElement() to insert
-    *                  under <head> element
-    * WARNING: You must be very careful to reset back to PR_TRUE after
-    *          setting PR_FALSE, else selection/caret is trashed
-    *          for further editing.
-    */
+  /**
+   * While setting the flag with this method to false, CreateElementTransaction,
+   * DeleteRangeTransaction, DeleteTextTransaction, InsertNodeTransaction,
+   * InsertTextTransaction and SplitNodeTransaction won't change Selection
+   * after modifying the DOM tree.
+   * Note that calling this with false does not guarantee that Selection won't
+   * be changed because other transaction may ignore this flag, editor itself
+   * may change selection, and current selection may become invalid after
+   * changing the DOM tree, etc.
+   * After calling this method with true, the caller should guarantee that
+   * Selection should be positioned where user expects.
+   *
+   * @param should    false if you don't want above transactions to modify
+   *                  Selection automatically after modifying the DOM tree.
+   *                  Note that calling this with false does not guarantee
+   *                  that Selection is never changed.
+   */
   void setShouldTxnSetSelection(in boolean should);
 
   /* ------------ Inline Spell Checking methods -------------- */
 
   /** Returns the inline spell checker associated with this object. The spell
     * checker is lazily created, so this function may create the object for
     * you during this call.
     * @param  autoCreate  If true, this will create a spell checker object