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"
14 #include "nsDirection.h"
26 class SelectionChangeEventDispatcher final
{
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
)
35 void OnSelectionChange(dom::Document
* aDocument
, dom::Selection
* aSelection
,
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
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
;
56 explicit RawRangeData(const nsRange
* aRange
);
57 bool Equals(const nsRange
* aRange
);
61 nsTArray
<RawRangeData
> mOldRanges
;
62 nsDirection mOldDirection
;
64 ~SelectionChangeEventDispatcher() = default;
67 } // namespace mozilla
69 #endif // mozilla_SelectionChangeEventDispatcher_h