1 /* -*- Mode: C++; tab-width: 4; 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/. */
6 #ifndef mozilla_a11y_SelectionManager_h__
7 #define mozilla_a11y_SelectionManager_h__
9 #include "nsISelectionListener.h"
10 #include "mozilla/WeakPtr.h"
26 class HyperTextAccessible
;
29 * This special accessibility class is for the caret and selection management.
30 * There is only 1 visible caret per top level window. However, there may be
31 * several visible selections.
33 * The important selections are the one owned by each document, and the one in
34 * the currently focused control.
36 * On Windows this class is used to move an invisible system caret that
37 * shadows the Mozilla caret. Windows will also automatically map this to
38 * the MSAA caret accessible object (via OBJID_CARET) (as opposed to the root
39 * accessible tree for a window which is retrieved with OBJID_CLIENT).
41 * For ATK and IAccessible2, this class is used to fire caret move and
42 * selection change events.
47 class SelectionManager
: public nsISelectionListener
{
50 // implemented by derived nsAccessibilityService
52 // nsISelectionListener
53 NS_DECL_NSISELECTIONLISTENER
56 void Shutdown() { ClearControlSelectionListener(); }
59 * Listen to selection events on the focused control.
61 * Note: only one control's selection events are listened to at a time. This
62 * will remove the previous control's selection listener.
64 void SetControlSelectionListener(dom::Element
* aFocusedElm
);
67 * Stop listening to selection events on the control.
69 void ClearControlSelectionListener();
72 * Listen to selection events on the document.
74 void AddDocSelectionListener(PresShell
* aPresShell
);
77 * Stop listening to selection events for a given document
79 void RemoveDocSelectionListener(PresShell
* aPresShell
);
82 * Process delayed event, results in caret move and text selection change
85 void ProcessTextSelChangeEvent(AccEvent
* aEvent
);
88 * Gets the current caret offset/hypertext accessible pair. If there is no
89 * current pair, then returns -1 for the offset and a nullptr for the
92 inline HyperTextAccessible
* AccessibleWithCaret(int32_t* aCaret
) {
93 if (aCaret
) *aCaret
= mCaretOffset
;
99 * Update caret offset when it doesn't go through a caret move event.
101 inline void UpdateCaretOffset(HyperTextAccessible
* aItem
, int32_t aOffset
) {
102 mAccWithCaret
= aItem
;
103 mCaretOffset
= aOffset
;
106 inline void ResetCaretOffset() {
108 mAccWithCaret
= nullptr;
112 * Called by mozInlineSpellChecker when a spell check range is added/removed.
113 * nsISelectionListener isn't sufficient for spelling errors, since it only
114 * tells us that there was a change, not which range changed. We don't want
115 * to unnecessarily push a cache update for all Accessibles in the entire
118 void SpellCheckRangeChanged(const nsRange
& aRange
);
126 * Process DOM selection change. Fire selection and caret move events.
128 void ProcessSelectionChanged(SelData
* aSelData
);
131 // Currently focused control.
132 int32_t mCaretOffset
;
133 HyperTextAccessible
* mAccWithCaret
;
134 WeakPtr
<dom::Selection
> mCurrCtrlNormalSel
;
135 WeakPtr
<dom::Selection
> mCurrCtrlSpellSel
;
139 } // namespace mozilla