Commit c602e0e0 authored by Mirko Brodesser's avatar Mirko Brodesser
Browse files

Bug 1623333: part 4) Assert Selection's type is `eNormal` in relevant methods...

Bug 1623333: part 4) Assert Selection's type is `eNormal` in relevant methods accessing `mFrameSelection`. r=smaug

Helps to determine which methods of `nsFrameSelection` are intended to
be called only for the `eNormal` Selection.

Driven by the idea that state of `nsFrameSelection` relevant only for
the `eNormal` Selection should later move to a `NormalSelection` class.

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

--HG--
extra : moz-landing-system : lando
parent 812500d8
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -326,15 +326,20 @@ void Selection::ToStringWithFormat(const nsAString& aFormatType,
}

void Selection::SetInterlinePosition(bool aHintRight, ErrorResult& aRv) {
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  if (!mFrameSelection) {
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);  // Can't do selection
    return;
  }

  mFrameSelection->SetHint(aHintRight ? CARET_ASSOCIATE_AFTER
                                      : CARET_ASSOCIATE_BEFORE);
}

bool Selection::GetInterlinePosition(ErrorResult& aRv) {
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  if (!mFrameSelection) {
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);  // Can't do selection
    return false;
@@ -361,6 +366,8 @@ bool Selection::IsEditorSelection() const {

Nullable<int16_t> Selection::GetCaretBidiLevel(
    mozilla::ErrorResult& aRv) const {
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  if (!mFrameSelection) {
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
    return Nullable<int16_t>();
@@ -373,6 +380,8 @@ Nullable<int16_t> Selection::GetCaretBidiLevel(

void Selection::SetCaretBidiLevel(const Nullable<int16_t>& aCaretBidiLevel,
                                  mozilla::ErrorResult& aRv) {
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  if (!mFrameSelection) {
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
    return;
@@ -1237,6 +1246,8 @@ nsresult Selection::GetIndicesForInterval(
}

nsresult Selection::GetPrimaryFrameForAnchorNode(nsIFrame** aReturnFrame) {
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  if (!aReturnFrame) return NS_ERROR_NULL_POINTER;

  int32_t frameOffset = 0;
@@ -1661,6 +1672,8 @@ nsresult Selection::GetCachedFrameOffset(nsIFrame* aFrame, int32_t inOffset,
}

nsIContent* Selection::GetAncestorLimiter() const {
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  if (mFrameSelection) {
    return mFrameSelection->GetAncestorLimiter();
  }
@@ -1668,6 +1681,8 @@ nsIContent* Selection::GetAncestorLimiter() const {
}

void Selection::SetAncestorLimiter(nsIContent* aLimiter) {
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  if (mFrameSelection) {
    RefPtr<nsFrameSelection> frameSelection = mFrameSelection;
    frameSelection->SetAncestorLimiter(aLimiter);
@@ -1696,6 +1711,7 @@ nsresult Selection::StartAutoScrollTimer(nsIFrame* aFrame,
                                         const nsPoint& aPoint,
                                         uint32_t aDelay) {
  MOZ_ASSERT(aFrame, "Need a frame");
  MOZ_ASSERT(mSelectionType == SelectionType::eNormal);

  nsresult result;
  if (!mFrameSelection) {
+2 −0
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ class MOZ_RAII AutoSetTemporaryAncestorLimiter final {
      nsINode& aStartPointNode MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
    MOZ_GUARD_OBJECT_NOTIFIER_INIT;

    MOZ_ASSERT(aSelection.GetType() == SelectionType::eNormal);

    if (aSelection.GetAncestorLimiter()) {
      return;
    }
+3 −0
Original line number Diff line number Diff line
@@ -212,6 +212,9 @@ struct MOZ_RAII AutoPrepareFocusRange {
                            MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
    MOZ_GUARD_OBJECT_NOTIFIER_INIT;

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

    if (aSelection->mRanges.Length() <= 1) {
      return;
    }