Skip to content

Commit

Permalink
Bug 1623333: part 3) Assert EditorBase::SelectionRefPtr has type `e…
Browse files Browse the repository at this point in the history
…Normal`. r=masayuki

Simplifies reasoning about it.

Differential Revision: https://phabricator.services.mozilla.com/D67444
  • Loading branch information
mbrodesser committed Mar 19, 2020
1 parent 72c74af commit be1f4dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions editor/libeditor/EditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion editor/libeditor/EditorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit be1f4dc

Please sign in to comment.