Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef mozilla_SelectionChangeListener_h_
7 : #define mozilla_SelectionChangeListener_h_
8 :
9 : #include "nsISelectionListener.h"
10 : #include "nsISelectionPrivate.h"
11 : #include "mozilla/Attributes.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 32 : class SelectionChangeListener final : public nsISelectionListener
17 : {
18 : public:
19 : // SelectionChangeListener has to participate in cycle collection because
20 : // it holds strong references to nsINodes in its mOldRanges array.
21 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
22 238 : NS_DECL_CYCLE_COLLECTION_CLASS(SelectionChangeListener)
23 : NS_DECL_NSISELECTIONLISTENER
24 :
25 : // This field is used to keep track of the ranges which were present in the
26 : // selection when the selectionchange event was previously fired. This allows
27 : // for the selectionchange event to only be fired when a selection is actually
28 : // changed.
29 41 : struct RawRangeData
30 : {
31 : // These properties are not void*s to avoid the potential situation where the
32 : // nsINode is freed, and a new nsINode is allocated with the same address, which
33 : // could potentially break the comparison logic. In reality, this is extremely
34 : // unlikely to occur (potentially impossible), but these nsCOMPtrs are safer.
35 : // They are never dereferenced.
36 : nsCOMPtr<nsINode> mStartContainer;
37 : nsCOMPtr<nsINode> mEndContainer;
38 :
39 : // XXX These are int32_ts on nsRange, but uint32_ts in the return value
40 : // of GetStart_, so I use uint32_ts here. See bug 1194256.
41 : uint32_t mStartOffset;
42 : uint32_t mEndOffset;
43 :
44 : explicit RawRangeData(const nsRange* aRange);
45 : bool Equals(const nsRange* aRange);
46 : };
47 :
48 : private:
49 : nsTArray<RawRangeData> mOldRanges;
50 :
51 0 : ~SelectionChangeListener() {}
52 : };
53 :
54 : } // namespace dom
55 : } // namespace mozilla
56 :
57 : #endif // mozilla_SelectionChangeListener_h_
|