/src/mozilla-central/dom/base/SelectionChangeEventDispatcher.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef mozilla_SelectionChangeEventDispatcher_h |
8 | | #define mozilla_SelectionChangeEventDispatcher_h |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "nsCycleCollectionParticipant.h" |
12 | | #include "nsTArray.h" |
13 | | #include "nsCOMPtr.h" |
14 | | |
15 | | class nsIDocument; |
16 | | class nsINode; |
17 | | class nsRange; |
18 | | |
19 | | namespace mozilla { |
20 | | |
21 | | namespace dom { |
22 | | class Selection; |
23 | | } |
24 | | |
25 | | class SelectionChangeEventDispatcher final |
26 | | { |
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) |
33 | | |
34 | | MOZ_CAN_RUN_SCRIPT |
35 | | void OnSelectionChange(nsIDocument* aDocument, |
36 | | dom::Selection* aSelection, |
37 | | int16_t aReason); |
38 | | |
39 | | // This field is used to keep track of the ranges which were present in the |
40 | | // selection when the selectionchange event was previously fired. This allows |
41 | | // for the selectionchange event to only be fired when a selection is actually |
42 | | // changed. |
43 | | struct RawRangeData |
44 | | { |
45 | | // These properties are not void*s to avoid the potential situation where the |
46 | | // nsINode is freed, and a new nsINode is allocated with the same address, which |
47 | | // could potentially break the comparison logic. In reality, this is extremely |
48 | | // unlikely to occur (potentially impossible), but these nsCOMPtrs are safer. |
49 | | // They are never dereferenced. |
50 | | nsCOMPtr<nsINode> mStartContainer; |
51 | | nsCOMPtr<nsINode> mEndContainer; |
52 | | |
53 | | // XXX These are int32_ts on nsRange, but uint32_ts in the return value |
54 | | // of GetStart_, so I use uint32_ts here. See bug 1194256. |
55 | | uint32_t mStartOffset; |
56 | | uint32_t mEndOffset; |
57 | | |
58 | | explicit RawRangeData(const nsRange* aRange); |
59 | | bool Equals(const nsRange* aRange); |
60 | | }; |
61 | | |
62 | | private: |
63 | | nsTArray<RawRangeData> mOldRanges; |
64 | | |
65 | 0 | ~SelectionChangeEventDispatcher() {} |
66 | | }; |
67 | | |
68 | | } // namespace mozilla |
69 | | |
70 | | #endif // mozilla_SelectionChangeEventDispatcher_h |