Line data Source code
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/. */
5 :
6 : #ifndef mozilla_a11y_SelectionManager_h__
7 : #define mozilla_a11y_SelectionManager_h__
8 :
9 : #include "nsIFrame.h"
10 : #include "nsISelectionListener.h"
11 :
12 : class nsIPresShell;
13 :
14 : namespace mozilla {
15 :
16 : namespace dom {
17 : class Element;
18 : }
19 :
20 : namespace a11y {
21 :
22 : class AccEvent;
23 : class HyperTextAccessible;
24 :
25 : /**
26 : * This special accessibility class is for the caret and selection management.
27 : * There is only 1 visible caret per top level window. However, there may be
28 : * several visible selections.
29 : *
30 : * The important selections are the one owned by each document, and the one in
31 : * the currently focused control.
32 : *
33 : * On Windows this class is used to move an invisible system caret that
34 : * shadows the Mozilla caret. Windows will also automatically map this to
35 : * the MSAA caret accessible object (via OBJID_CARET) (as opposed to the root
36 : * accessible tree for a window which is retrieved with OBJID_CLIENT).
37 : *
38 : * For ATK and IAccessible2, this class is used to fire caret move and
39 : * selection change events.
40 : */
41 :
42 : struct SelData;
43 :
44 0 : class SelectionManager : public nsISelectionListener
45 : {
46 : public:
47 : // nsISupports
48 : // implemented by derived nsAccessibilityService
49 :
50 : // nsISelectionListener
51 : NS_DECL_NSISELECTIONLISTENER
52 :
53 : // SelectionManager
54 0 : void Shutdown() { ClearControlSelectionListener(); }
55 :
56 : /**
57 : * Listen to selection events on the focused control.
58 : *
59 : * Note: only one control's selection events are listened to at a time. This
60 : * will remove the previous control's selection listener.
61 : */
62 : void SetControlSelectionListener(dom::Element* aFocusedElm);
63 :
64 : /**
65 : * Stop listening to selection events on the control.
66 : */
67 : void ClearControlSelectionListener();
68 :
69 : /**
70 : * Listen to selection events on the document.
71 : */
72 : void AddDocSelectionListener(nsIPresShell* aPresShell);
73 :
74 : /**
75 : * Stop listening to selection events for a given document
76 : */
77 : void RemoveDocSelectionListener(nsIPresShell* aShell);
78 :
79 : /**
80 : * Process delayed event, results in caret move and text selection change
81 : * events.
82 : */
83 : void ProcessTextSelChangeEvent(AccEvent* aEvent);
84 :
85 : /**
86 : * Gets the current caret offset/hypertext accessible pair. If there is no
87 : * current pair, then returns -1 for the offset and a nullptr for the
88 : * accessible.
89 : */
90 0 : inline HyperTextAccessible* AccessibleWithCaret(int32_t* aCaret)
91 : {
92 0 : if (aCaret)
93 0 : *aCaret = mCaretOffset;
94 :
95 0 : return mAccWithCaret;
96 : }
97 :
98 : /**
99 : * Update caret offset when it doesn't go through a caret move event.
100 : */
101 0 : inline void UpdateCaretOffset(HyperTextAccessible* aItem, int32_t aOffset)
102 : {
103 0 : mAccWithCaret = aItem;
104 0 : mCaretOffset = aOffset;
105 0 : }
106 :
107 0 : inline void ResetCaretOffset()
108 : {
109 0 : mCaretOffset = -1;
110 0 : mAccWithCaret = nullptr;
111 0 : }
112 :
113 : protected:
114 :
115 : SelectionManager();
116 :
117 : /**
118 : * Process DOM selection change. Fire selection and caret move events.
119 : */
120 : void ProcessSelectionChanged(SelData* aSelData);
121 :
122 : private:
123 : // Currently focused control.
124 : WeakFrame mCurrCtrlFrame;
125 : int32_t mCaretOffset;
126 : HyperTextAccessible* mAccWithCaret;
127 : };
128 :
129 : } // namespace a11y
130 : } // namespace mozilla
131 :
132 : #endif
|