1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 file,
5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_a11y_logs_h__
8 #define mozilla_a11y_logs_h__
9 
10 #include "nscore.h"
11 #include "nsStringFwd.h"
12 #include "mozilla/Attributes.h"
13 
14 class nsINode;
15 class nsIRequest;
16 class nsISupports;
17 class nsIWebProgress;
18 
19 namespace mozilla {
20 
21 namespace dom {
22 class Document;
23 class Selection;
24 }  // namespace dom
25 
26 namespace a11y {
27 
28 class AccEvent;
29 class LocalAccessible;
30 class DocAccessible;
31 class OuterDocAccessible;
32 
33 namespace logging {
34 
35 enum EModules {
36   eDocLoad = 1 << 0,
37   eDocCreate = 1 << 1,
38   eDocDestroy = 1 << 2,
39   eDocLifeCycle = eDocLoad | eDocCreate | eDocDestroy,
40 
41   eEvents = 1 << 3,
42   eEventTree = 1 << 4,
43   ePlatforms = 1 << 5,
44   eText = 1 << 6,
45   eTree = 1 << 7,
46   eTreeSize = 1 << 8,
47 
48   eDOMEvents = 1 << 9,
49   eFocus = 1 << 10,
50   eSelection = 1 << 11,
51   eNotifications = eDOMEvents | eSelection | eFocus,
52 
53   // extras
54   eStack = 1 << 12,
55   eVerbose = 1 << 13,
56   eCache = 1 << 14,
57 };
58 
59 /**
60  * Return true if any of the given modules is logged.
61  */
62 bool IsEnabled(uint32_t aModules);
63 
64 /**
65  * Return true if all of the given modules are logged.
66  */
67 bool IsEnabledAll(uint32_t aModules);
68 
69 /**
70  * Return true if the given module is logged.
71  */
72 bool IsEnabled(const nsAString& aModules);
73 
74 /**
75  * Log the document loading progress.
76  */
77 void DocLoad(const char* aMsg, nsIWebProgress* aWebProgress,
78              nsIRequest* aRequest, uint32_t aStateFlags);
79 void DocLoad(const char* aMsg, dom::Document* aDocumentNode);
80 void DocCompleteLoad(DocAccessible* aDocument, bool aIsLoadEventTarget);
81 
82 /**
83  * Log that document load event was fired.
84  */
85 void DocLoadEventFired(AccEvent* aEvent);
86 
87 /**
88  * Log that document laod event was handled.
89  */
90 void DocLoadEventHandled(AccEvent* aEvent);
91 
92 /**
93  * Log the document was created.
94  */
95 void DocCreate(const char* aMsg, dom::Document* aDocumentNode,
96                DocAccessible* aDocument = nullptr);
97 
98 /**
99  * Log the document was destroyed.
100  */
101 void DocDestroy(const char* aMsg, dom::Document* aDocumentNode,
102                 DocAccessible* aDocument = nullptr);
103 
104 /**
105  * Log the outer document was destroyed.
106  */
107 void OuterDocDestroy(OuterDocAccessible* OuterDoc);
108 
109 /**
110  * Log the focus notification target.
111  */
112 void FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
113                              LocalAccessible* aTarget);
114 void FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
115                              nsINode* aTargetNode);
116 void FocusNotificationTarget(const char* aMsg, const char* aTargetDescr,
117                              nsISupports* aTargetThing);
118 
119 /**
120  * Log a cause of active item descendant change (submessage).
121  */
122 void ActiveItemChangeCausedBy(const char* aMsg, LocalAccessible* aTarget);
123 
124 /**
125  * Log the active widget (submessage).
126  */
127 void ActiveWidget(LocalAccessible* aWidget);
128 
129 /**
130  * Log the focus event was dispatched (submessage).
131  */
132 void FocusDispatched(LocalAccessible* aTarget);
133 
134 /**
135  * Log the selection change.
136  */
137 void SelChange(dom::Selection* aSelection, DocAccessible* aDocument,
138                int16_t aReason);
139 
140 /**
141  * Log the given accessible elements info.
142  */
143 void TreeInfo(const char* aMsg, uint32_t aExtraFlags, ...);
144 void TreeInfo(const char* aMsg, uint32_t aExtraFlags, const char* aMsg1,
145               LocalAccessible* aAcc, const char* aMsg2, nsINode* aNode);
146 void TreeInfo(const char* aMsg, uint32_t aExtraFlags, LocalAccessible* aParent);
147 
148 /**
149  * Log the accessible/DOM tree.
150  */
151 typedef const char* (*GetTreePrefix)(void* aData, LocalAccessible*);
152 void Tree(const char* aTitle, const char* aMsgText, LocalAccessible* aRoot,
153           GetTreePrefix aPrefixFunc = nullptr,
154           void* aGetTreePrefixData = nullptr);
155 void DOMTree(const char* aTitle, const char* aMsgText, DocAccessible* aDoc);
156 
157 /**
158  * Log the tree size in bytes.
159  */
160 void TreeSize(const char* aTitle, const char* aMsgText, LocalAccessible* aRoot);
161 
162 /**
163  * Log the message ('title: text' format) on new line. Print the start and end
164  * boundaries of the message body designated by '{' and '}' (2 spaces indent for
165  * body).
166  */
167 void MsgBegin(const char* aTitle, const char* aMsgText, ...)
168     MOZ_FORMAT_PRINTF(2, 3);
169 void MsgEnd();
170 
171 /**
172  * Print start and end boundaries of the message body designated by '{' and '}'
173  * (2 spaces indent for body).
174  */
175 void SubMsgBegin();
176 void SubMsgEnd();
177 
178 /**
179  * Log the entry into message body (4 spaces indent).
180  */
181 void MsgEntry(const char* aEntryText, ...) MOZ_FORMAT_PRINTF(1, 2);
182 
183 /**
184  * Log the text, two spaces offset is used.
185  */
186 void Text(const char* aText);
187 
188 /**
189  * Log the accessible object address as message entry (4 spaces indent).
190  */
191 void Address(const char* aDescr, LocalAccessible* aAcc);
192 
193 /**
194  * Log the DOM node info as message entry.
195  */
196 void Node(const char* aDescr, nsINode* aNode);
197 
198 /**
199  * Log the document accessible info as message entry.
200  */
201 void Document(DocAccessible* aDocument);
202 
203 /**
204  * Log the accessible and its DOM node as a message entry.
205  */
206 void AccessibleInfo(const char* aDescr, LocalAccessible* aAccessible);
207 void AccessibleNNode(const char* aDescr, LocalAccessible* aAccessible);
208 void AccessibleNNode(const char* aDescr, nsINode* aNode);
209 
210 /**
211  * Log the DOM event.
212  */
213 void DOMEvent(const char* aDescr, nsINode* aOrigTarget,
214               const nsAString& aEventType);
215 
216 /**
217  * Log the call stack, two spaces offset is used.
218  */
219 void Stack();
220 
221 /**
222  * Enable logging of the specified modules, all other modules aren't logged.
223  */
224 void Enable(const nsCString& aModules);
225 
226 /**
227  * Enable logging of modules specified by A11YLOG environment variable,
228  * all other modules aren't logged.
229  */
230 void CheckEnv();
231 
232 }  // namespace logging
233 
234 }  // namespace a11y
235 }  // namespace mozilla
236 
237 #endif
238