Quelle SelectionChangeEventDispatcher.cpp
Sprache: C
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * Implementation of mozilla::SelectionChangeEventDispatcher
*/
void SelectionChangeEventDispatcher::OnSelectionChange(Document* aDoc,
Selection* aSel,
int16_t aReason) { // Check if the ranges have actually changed // Don't bother checking this if we are hiding changes. if (mOldRanges.Length() == aSel->RangeCount() &&
!aSel->IsBlockingSelectionChangeEvents()) { bool changed = mOldDirection != aSel->GetDirection(); if (!changed) { for (const uint32_t i : IntegerRange(mOldRanges.Length())) { if (!mOldRanges[i].Equals(aSel->GetRangeAt(i))) {
changed = true; break;
}
}
}
if (!changed) { return;
}
}
// The ranges have actually changed, update the mOldRanges array
mOldRanges.ClearAndRetainStorage(); for (const uint32_t i : IntegerRange(aSel->RangeCount())) {
mOldRanges.AppendElement(RawRangeData(aSel->GetRangeAt(i)));
}
mOldDirection = aSel->GetDirection();
// If we are hiding changes, then don't do anything else. We do this after we // update mOldRanges so that changes after the changes stop being hidden don't // incorrectly trigger a change, even though they didn't change anything if (aSel->IsBlockingSelectionChangeEvents()) { return;
}
// Be aware, don't call GetTextControlFromSelectionLimiter once you might // run script because selection limit may have already been changed by it.
nsCOMPtr<nsIContent> textControl; if ((maybeHasFormSelectEventListeners &&
(aReason & nsISelectionListener::JS_REASON)) ||
maybeHasSelectionChangeEventListeners) { if (const nsFrameSelection* fs = aSel->GetFrameSelection()) { if (nsCOMPtr<nsIContent> root = fs->GetLimiter()) {
textControl = root->GetClosestNativeAnonymousSubtreeRootParentOrHost();
MOZ_ASSERT_IF(textControl,
textControl->IsTextControlElement() &&
!textControl->IsInNativeAnonymousSubtree());
}
}
};
// Selection changes with non-JS reason only cares about whether the new // selection is collapsed or not. See TextInputListener::OnSelectionChange. if (textControl && maybeHasFormSelectEventListeners &&
(aReason & nsISelectionListener::JS_REASON)) {
RefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(textControl, eFormSelect, CanBubble::eYes);
asyncDispatcher->PostDOMEvent();
}
if (!maybeHasSelectionChangeEventListeners) { return;
}
// The spec currently doesn't say that we should dispatch this event on text // controls, so for now we only support doing that under a pref, disabled by // default. // See https://github.com/w3c/selection-api/issues/53. if (textControl &&
!StaticPrefs::dom_select_events_textcontrols_selectionchange_enabled()) { return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.