Commit 1c4dcdbc authored by Mirko Brodesser's avatar Mirko Brodesser
Browse files

Bug 1623333: part 3) Assert `EditorBase::SelectionRefPtr` has type `eNormal`. r=masayuki

Simplifies reasoning about it.

Differential Revision: https://phabricator.services.mozilla.com/D67444

--HG--
extra : moz-landing-system : lando
parent d252ed11
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6096,6 +6096,9 @@ EditorBase::AutoEditActionDataSetter::AutoEditActionDataSetter(
  // If we're nested edit action, copies necessary data from the parent.
  if (mParentData) {
    mSelection = mParentData->mSelection;
    MOZ_ASSERT(!mSelection ||
               (mSelection->GetType() == SelectionType::eNormal));

    // If we're eNotEditing, we should inherit the parent's edit action.
    // This may occur if creator or its callee use public methods which
    // just returns something.
@@ -6115,6 +6118,9 @@ EditorBase::AutoEditActionDataSetter::AutoEditActionDataSetter(
    if (NS_WARN_IF(!mSelection)) {
      return;
    }

    MOZ_ASSERT(mSelection->GetType() == SelectionType::eNormal);

    mEditAction = aEditAction;
    mDirectionOfTopLevelEditSubAction = eNone;
    if (mEditorBase.mIsHTMLEditorClass) {
+12 −1
Original line number Diff line number Diff line
@@ -874,7 +874,13 @@ class EditorBase : public nsIEditor,

    bool IsCanceled() const { return mBeforeInputEventCanceled; }

    const RefPtr<Selection>& SelectionRefPtr() const { return mSelection; }
    const RefPtr<Selection>& SelectionRefPtr() const {
      MOZ_ASSERT(!mSelection ||
                 (mSelection->GetType() == SelectionType::eNormal));

      return mSelection;
    }

    nsIPrincipal* GetPrincipal() const { return mPrincipal; }
    EditAction GetEditAction() const { return mEditAction; }

@@ -1040,6 +1046,8 @@ class EditorBase : public nsIEditor,
    }

    void UpdateSelectionCache(Selection& aSelection) {
      MOZ_ASSERT(aSelection.GetType() == SelectionType::eNormal);

      AutoEditActionDataSetter* actionData = this;
      while (actionData) {
        if (actionData->mSelection) {
@@ -1217,6 +1225,9 @@ class EditorBase : public nsIEditor,
   */
  const RefPtr<Selection>& SelectionRefPtr() const {
    MOZ_ASSERT(mEditActionData);
    MOZ_ASSERT(mEditActionData->SelectionRefPtr()->GetType() ==
               SelectionType::eNormal);

    return mEditActionData->SelectionRefPtr();
  }