Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #ifndef mozilla_a11y_FocusManager_h_
6 : #define mozilla_a11y_FocusManager_h_
7 :
8 : class nsINode;
9 : class nsIDocument;
10 : class nsISupports;
11 :
12 : namespace mozilla {
13 : namespace a11y {
14 :
15 : class AccEvent;
16 : class Accessible;
17 : class DocAccessible;
18 :
19 : /**
20 : * Manage the accessible focus. Used to fire and process accessible events.
21 : */
22 : class FocusManager
23 : {
24 : public:
25 : virtual ~FocusManager();
26 :
27 : /**
28 : * Return a focused accessible.
29 : */
30 : Accessible* FocusedAccessible() const;
31 :
32 : /**
33 : * Return true if given accessible is focused.
34 : */
35 : bool IsFocused(const Accessible* aAccessible) const;
36 :
37 : /**
38 : * Return true if the given accessible is an active item, i.e. an item that
39 : * is current within the active widget.
40 : */
41 0 : inline bool IsActiveItem(const Accessible* aAccessible)
42 0 : { return aAccessible == mActiveItem; }
43 :
44 : /**
45 : * Return true if given DOM node has DOM focus.
46 : */
47 0 : inline bool HasDOMFocus(const nsINode* aNode) const
48 0 : { return aNode == FocusedDOMNode(); }
49 :
50 : /**
51 : * Return true if focused accessible is within the given container.
52 : */
53 : bool IsFocusWithin(const Accessible* aContainer) const;
54 :
55 : /**
56 : * Return whether the given accessible is focused or contains the focus or
57 : * contained by focused accessible.
58 : */
59 : enum FocusDisposition {
60 : eNone,
61 : eFocused,
62 : eContainsFocus,
63 : eContainedByFocus
64 : };
65 : FocusDisposition IsInOrContainsFocus(const Accessible* aAccessible) const;
66 :
67 : //////////////////////////////////////////////////////////////////////////////
68 : // Focus notifications and processing (don't use until you know what you do).
69 :
70 : /**
71 : * Called when DOM focus event is fired.
72 : */
73 : void NotifyOfDOMFocus(nsISupports* aTarget);
74 :
75 : /**
76 : * Called when DOM blur event is fired.
77 : */
78 : void NotifyOfDOMBlur(nsISupports* aTarget);
79 :
80 : /**
81 : * Called when active item is changed. Note: must be called when accessible
82 : * tree is up to date.
83 : */
84 : void ActiveItemChanged(Accessible* aItem, bool aCheckIfActive = true);
85 :
86 : /**
87 : * Dispatch delayed focus event for the current focus accessible.
88 : */
89 : void ForceFocusEvent();
90 :
91 : /**
92 : * Dispatch delayed focus event for the given target.
93 : */
94 : void DispatchFocusEvent(DocAccessible* aDocument, Accessible* aTarget);
95 :
96 : /**
97 : * Process DOM focus notification.
98 : */
99 : void ProcessDOMFocus(nsINode* aTarget);
100 :
101 : /**
102 : * Process the delayed accessible event.
103 : * do.
104 : */
105 : void ProcessFocusEvent(AccEvent* aEvent);
106 :
107 : protected:
108 : FocusManager();
109 :
110 : private:
111 : FocusManager(const FocusManager&);
112 : FocusManager& operator =(const FocusManager&);
113 :
114 : /**
115 : * Return DOM node having DOM focus.
116 : */
117 : nsINode* FocusedDOMNode() const;
118 :
119 : /**
120 : * Return DOM document having DOM focus.
121 : */
122 : nsIDocument* FocusedDOMDocument() const;
123 :
124 : private:
125 : RefPtr<Accessible> mActiveItem;
126 : RefPtr<Accessible> mActiveARIAMenubar;
127 : };
128 :
129 : } // namespace a11y
130 : } // namespace mozilla
131 :
132 : #endif
|