Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / base / SelectionChangeEventDispatcher.h
bloba734b4490d6398c474f7e7ba28a54038ea0c08dd
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_SelectionChangeEventDispatcher_h
8 #define mozilla_SelectionChangeEventDispatcher_h
10 #include "mozilla/Attributes.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsTArray.h"
13 #include "nsCOMPtr.h"
14 #include "nsDirection.h"
16 class nsINode;
17 class nsRange;
19 namespace mozilla {
21 namespace dom {
22 class Document;
23 class Selection;
24 } // namespace dom
26 class SelectionChangeEventDispatcher final {
27 public:
28 // SelectionChangeEventDispatcher has to participate in cycle collection
29 // because it holds strong references to nsINodes in its mOldRanges array.
30 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(
31 SelectionChangeEventDispatcher)
32 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(SelectionChangeEventDispatcher)
34 MOZ_CAN_RUN_SCRIPT
35 void OnSelectionChange(dom::Document* aDocument, dom::Selection* aSelection,
36 int16_t aReason);
38 // This field is used to keep track of the ranges which were present in the
39 // selection when the selectionchange event was previously fired. This allows
40 // for the selectionchange event to only be fired when a selection is actually
41 // changed.
42 struct RawRangeData {
43 // These properties are not void*s to avoid the potential situation where
44 // the nsINode is freed, and a new nsINode is allocated with the same
45 // address, which could potentially break the comparison logic. In reality,
46 // this is extremely unlikely to occur (potentially impossible), but these
47 // nsCOMPtrs are safer. They are never dereferenced.
48 nsCOMPtr<nsINode> mStartContainer;
49 nsCOMPtr<nsINode> mEndContainer;
51 // XXX These are int32_ts on nsRange, but uint32_ts in the return value
52 // of GetStart_, so I use uint32_ts here. See bug 1194256.
53 uint32_t mStartOffset;
54 uint32_t mEndOffset;
56 explicit RawRangeData(const nsRange* aRange);
57 bool Equals(const nsRange* aRange);
60 private:
61 nsTArray<RawRangeData> mOldRanges;
62 nsDirection mOldDirection;
64 ~SelectionChangeEventDispatcher() = default;
67 } // namespace mozilla
69 #endif // mozilla_SelectionChangeEventDispatcher_h