|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_RENDERER_RENDERER_ACCESSIBILITY_H_ | |
6 #define CONTENT_RENDERER_RENDERER_ACCESSIBILITY_H_ | |
7 #pragma once | |
8 | |
9 #include <vector> | |
10 | |
11 #include "base/hash_tables.h" | |
12 #include "base/task.h" | |
13 #include "content/renderer/render_view_observer.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityNotif ication.h" | |
15 | |
16 namespace WebKit { | |
17 class WebAccessibilityObject; | |
18 class WebDocument; | |
19 class WebNode; | |
20 }; | |
21 | |
22 namespace webkit_glue { | |
23 struct WebAccessibility; | |
24 }; | |
25 | |
26 // RendererAccessibility belongs to the RenderView. It's responsible for | |
27 // sending a serialized representation of WebKit's accessibility tree from | |
28 // the renderer to the browser and sending updates whenever it changes, and | |
29 // handling requests from the browser to perform accessibility actions on | |
30 // nodes in the tree (e.g., change focus, or click on a button). | |
31 class RendererAccessibility : public RenderViewObserver { | |
32 public: | |
33 RendererAccessibility(RenderView* render_view); | |
34 virtual ~RendererAccessibility(); | |
35 | |
36 // RenderView::Observer implementation. | |
37 virtual bool OnMessageReceived(const IPC::Message& message); | |
38 virtual void FocusedNodeChanged(const WebKit::WebNode& node); | |
39 virtual void DidFinishLoad(WebKit::WebFrame* frame); | |
40 | |
41 // Called when an accessibility notification occurs in WebKit. | |
42 virtual void PostAccessibilityNotification( | |
43 const WebKit::WebAccessibilityObject& obj, | |
44 WebKit::WebAccessibilityNotification notification); | |
45 | |
46 private: | |
47 // One accessibility notification from WebKit. These are queued up and | |
48 // used to send tree updates and notification messages from the | |
49 // renderer to the browser. | |
50 struct Notification { | |
51 public: | |
52 // The id of the accessibility object. | |
53 int32 id; | |
54 | |
55 // The accessibility notification type. | |
56 WebKit::WebAccessibilityNotification type; | |
57 }; | |
58 | |
59 // In order to keep track of what nodes the browser knows about, we keep a | |
60 // representation of the browser tree - just IDs and parent/child | |
61 // relationships. | |
62 struct BrowserTreeNode { | |
63 BrowserTreeNode() {} | |
64 ~BrowserTreeNode() {} | |
65 int32 id; | |
66 std::vector<BrowserTreeNode*> children; | |
67 }; | |
68 | |
69 // Send queued notifications from the renderer to the browser. | |
70 void SendPendingAccessibilityNotifications(); | |
71 | |
72 // Update our representation of what nodes the browser has, given a | |
73 // tree of nodes. | |
74 void UpdateBrowserTree(const webkit_glue::WebAccessibility& renderer_node); | |
75 | |
76 // Clear the given node and all of its descendants from the browser tree. | |
David Tseng
2011/09/27 21:26:13
It looks like this method clears the children but
dmazzoni
2011/09/28 05:28:50
You're right. I renamed it ClearBrowserTreeNode an
| |
77 void ClearBrowserTree(BrowserTreeNode* browser_node); | |
78 | |
79 // Handlers for messages from the browser to the renderer. | |
80 void OnAccessibilityDoDefaultAction(int acc_obj_id); | |
81 void OnAccessibilityNotificationsAck(); | |
82 void OnEnableAccessibility(); | |
83 void OnSetAccessibilityFocus(int acc_obj_id); | |
84 | |
85 // Whether or not this notification typically needs to send | |
86 // updates to its children, too. | |
87 bool ShouldIncludeChildren(const Notification& notification); | |
88 | |
89 // Returns the main top-level document for this page, or NULL if there's | |
90 // no view or frame. | |
91 WebKit::WebDocument GetMainDocument(); | |
92 | |
93 // So we can queue up tasks to be executed later. | |
94 ScopedRunnableMethodFactory<RendererAccessibility> method_factory_; | |
95 | |
96 // Notifications from WebKit are collected until they are ready to be | |
97 // sent to the browser. | |
98 std::vector<Notification> pending_notifications_; | |
99 | |
100 // Our representation of the browser tree. | |
101 BrowserTreeNode* browser_root_; | |
102 | |
103 // A map from IDs to nodes in the browser tree. | |
104 base::hash_map<int32, BrowserTreeNode*> browser_id_map_; | |
105 | |
106 // Set if we are waiting for a accessibility notification ack. | |
David Tseng
2011/09/27 21:26:13
a -> an
dmazzoni
2011/09/28 05:28:50
Done.
| |
107 bool ack_pending_; | |
108 | |
109 // True if verbose logging of accessibility events is on. | |
110 bool logging_; | |
111 | |
112 // True if we've sent a load complete notification for this page already. | |
113 bool sent_load_complete_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(RendererAccessibility); | |
116 }; | |
117 | |
118 #endif // CONTENT_RENDERER_RENDERER_ACCESSIBILITY_H_ | |
OLD | NEW |