Bug 1867925 - Mark some storage-access-api tests as intermittent after wpt-sync....
[gecko.git] / accessible / base / SelectionManager.h
blob1dba086036b206bc39bec89433e06b578ca6d270
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"
12 class nsRange;
14 namespace mozilla {
16 class PresShell;
18 namespace dom {
19 class Element;
20 class Selection;
21 } // namespace dom
23 namespace a11y {
25 class AccEvent;
26 class HyperTextAccessible;
28 /**
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.
45 struct SelData;
47 class SelectionManager : public nsISelectionListener {
48 public:
49 // nsISupports
50 // implemented by derived nsAccessibilityService
52 // nsISelectionListener
53 NS_DECL_NSISELECTIONLISTENER
55 // SelectionManager
56 void Shutdown() { ClearControlSelectionListener(); }
58 /**
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);
66 /**
67 * Stop listening to selection events on the control.
69 void ClearControlSelectionListener();
71 /**
72 * Listen to selection events on the document.
74 void AddDocSelectionListener(PresShell* aPresShell);
76 /**
77 * Stop listening to selection events for a given document
79 void RemoveDocSelectionListener(PresShell* aPresShell);
81 /**
82 * Process delayed event, results in caret move and text selection change
83 * events.
85 void ProcessTextSelChangeEvent(AccEvent* aEvent);
87 /**
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
90 * accessible.
92 inline HyperTextAccessible* AccessibleWithCaret(int32_t* aCaret) {
93 if (aCaret) *aCaret = mCaretOffset;
95 return mAccWithCaret;
98 /**
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() {
107 mCaretOffset = -1;
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
116 * selection.
118 void SpellCheckRangeChanged(const nsRange& aRange);
120 ~SelectionManager();
122 protected:
123 SelectionManager();
126 * Process DOM selection change. Fire selection and caret move events.
128 void ProcessSelectionChanged(SelData* aSelData);
130 private:
131 // Currently focused control.
132 int32_t mCaretOffset;
133 HyperTextAccessible* mAccWithCaret;
134 WeakPtr<dom::Selection> mCurrCtrlNormalSel;
135 WeakPtr<dom::Selection> mCurrCtrlSpellSel;
138 } // namespace a11y
139 } // namespace mozilla
141 #endif