OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ | 5 #ifndef CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ |
6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ | 6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "content/public/renderer/render_view_observer.h" | 13 #include "content/public/renderer/render_view_observer.h" |
| 14 #include "content/renderer/accessibility/blink_ax_tree_source.h" |
14 #include "content/renderer/accessibility/renderer_accessibility.h" | 15 #include "content/renderer/accessibility/renderer_accessibility.h" |
15 #include "third_party/WebKit/public/web/WebAXEnums.h" | 16 #include "third_party/WebKit/public/web/WebAXEnums.h" |
16 #include "third_party/WebKit/public/web/WebAXObject.h" | 17 #include "third_party/WebKit/public/web/WebAXObject.h" |
17 #include "ui/accessibility/ax_node_data.h" | 18 #include "ui/accessibility/ax_node_data.h" |
| 19 #include "ui/accessibility/ax_tree_serializer.h" |
18 | 20 |
19 namespace blink { | 21 namespace blink { |
20 class WebDocument; | 22 class WebDocument; |
21 class WebNode; | 23 class WebNode; |
22 }; | 24 }; |
23 | 25 |
24 namespace content { | 26 namespace content { |
25 class RenderViewImpl; | 27 class RenderViewImpl; |
26 | 28 |
27 // This is the subclass of RendererAccessibility that implements | 29 // This is the subclass of RendererAccessibility that implements |
(...skipping 14 matching lines...) Expand all Loading... |
42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
43 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; | 45 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; |
44 virtual void DidFinishLoad(blink::WebFrame* frame) OVERRIDE; | 46 virtual void DidFinishLoad(blink::WebFrame* frame) OVERRIDE; |
45 | 47 |
46 // RendererAccessibility. | 48 // RendererAccessibility. |
47 virtual void HandleWebAccessibilityEvent( | 49 virtual void HandleWebAccessibilityEvent( |
48 const blink::WebAXObject& obj, blink::WebAXEvent event) OVERRIDE; | 50 const blink::WebAXObject& obj, blink::WebAXEvent event) OVERRIDE; |
49 | 51 |
50 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event); | 52 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event); |
51 | 53 |
52 // In order to keep track of what nodes the browser knows about, we keep a | |
53 // representation of the browser tree - just IDs and parent/child | |
54 // relationships. | |
55 struct CONTENT_EXPORT BrowserTreeNode { | |
56 BrowserTreeNode(); | |
57 virtual ~BrowserTreeNode(); | |
58 int32 id; | |
59 gfx::Rect location; | |
60 BrowserTreeNode* parent; | |
61 std::vector<BrowserTreeNode*> children; | |
62 }; | |
63 | |
64 virtual BrowserTreeNode* CreateBrowserTreeNode(); | |
65 | |
66 protected: | 54 protected: |
67 // Send queued events from the renderer to the browser. | 55 // Send queued events from the renderer to the browser. |
68 void SendPendingAccessibilityEvents(); | 56 void SendPendingAccessibilityEvents(); |
69 | 57 |
70 // Check the entire accessibility tree to see if any nodes have | 58 // Check the entire accessibility tree to see if any nodes have |
71 // changed location, by comparing their locations to the cached | 59 // changed location, by comparing their locations to the cached |
72 // versions. If any have moved, send an IPC with the new locations. | 60 // versions. If any have moved, send an IPC with the new locations. |
73 void SendLocationChanges(); | 61 void SendLocationChanges(); |
74 | 62 |
75 private: | 63 private: |
76 // Serialize the given accessibility object |obj| and append it to | |
77 // |dst|, and then recursively also serialize any *new* children of | |
78 // |obj|, based on what object ids we know the browser already has. | |
79 // The set of ids serialized is added to |ids_serialized|, and any | |
80 // ids previously in that set are not serialized again. | |
81 void SerializeChangedNodes(const blink::WebAXObject& obj, | |
82 std::vector<ui::AXNodeData>* dst, | |
83 std::set<int>* ids_serialized); | |
84 | |
85 // Clear the given node and recursively delete all of its descendants | |
86 // from the browser tree. (Does not delete |browser_node|). | |
87 void ClearBrowserTreeNode(BrowserTreeNode* browser_node); | |
88 | |
89 // Handlers for messages from the browser to the renderer. | 64 // Handlers for messages from the browser to the renderer. |
90 void OnDoDefaultAction(int acc_obj_id); | 65 void OnDoDefaultAction(int acc_obj_id); |
91 void OnEventsAck(); | 66 void OnEventsAck(); |
92 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y); | 67 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y); |
93 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus); | 68 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus); |
94 void OnScrollToPoint(int acc_obj_id, gfx::Point point); | 69 void OnScrollToPoint(int acc_obj_id, gfx::Point point); |
95 void OnSetFocus(int acc_obj_id); | 70 void OnSetFocus(int acc_obj_id); |
96 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); | 71 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); |
97 void OnFatalError(); | 72 void OnFatalError(); |
98 | 73 |
99 // Checks if a WebKit accessibility object is an editable text node. | 74 // Checks if a WebKit accessibility object is an editable text node. |
100 bool IsEditableText(const blink::WebAXObject& node); | 75 bool IsEditableText(const blink::WebAXObject& node); |
101 | 76 |
102 // Recursively explore the tree of WebKit accessibility objects rooted | 77 // Recursively explore the tree of WebKit accessibility objects rooted |
103 // at |src|, and for each editable text node encountered, add a | 78 // at |src|, and for each editable text node encountered, add a |
104 // corresponding WebAccessibility node as a child of |dst|. | 79 // corresponding WebAccessibility node as a child of |dst|. |
105 void RecursiveAddEditableTextNodesToTree( | 80 void RecursiveAddEditableTextNodesToTree( |
106 const blink::WebAXObject& src, | 81 const blink::WebAXObject& src, |
107 ui::AXNodeData* dst); | 82 ui::AXNodeData* dst); |
108 | 83 |
109 // Build a tree of serializable ui::AXNodeData nodes to send to the | |
110 // browser process, given a WebAXObject node from WebKit. | |
111 // Modifies |dst| in-place, it's assumed to be empty. | |
112 void BuildAccessibilityTree(const blink::WebAXObject& src, | |
113 bool include_children, | |
114 ui::AXNodeData* dst); | |
115 | |
116 // So we can queue up tasks to be executed later. | 84 // So we can queue up tasks to be executed later. |
117 base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_; | 85 base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_; |
118 | 86 |
119 // Events from WebKit are collected until they are ready to be | 87 // Events from WebKit are collected until they are ready to be |
120 // sent to the browser. | 88 // sent to the browser. |
121 std::vector<AccessibilityHostMsg_EventParams> pending_events_; | 89 std::vector<AccessibilityHostMsg_EventParams> pending_events_; |
122 | 90 |
123 // Our representation of the browser tree. | 91 // The adapter that exposes Blink's accessibility tree to AXTreeSerializer. |
124 BrowserTreeNode* browser_root_; | 92 BlinkAXTreeSource tree_source_; |
125 | 93 |
126 // A map from IDs to nodes in the browser tree. | 94 // The serializer that sends accessibility messages to the browser process. |
127 base::hash_map<int32, BrowserTreeNode*> browser_id_map_; | 95 ui::AXTreeSerializer<blink::WebAXObject> serializer_; |
| 96 |
| 97 // Current location of every object, so we can detect when it moves. |
| 98 base::hash_map<int, gfx::Rect> locations_; |
128 | 99 |
129 // The most recently observed scroll offset of the root document element. | 100 // The most recently observed scroll offset of the root document element. |
130 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460 | 101 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460 |
131 // is fixed. | 102 // is fixed. |
132 gfx::Size last_scroll_offset_; | 103 gfx::Size last_scroll_offset_; |
133 | 104 |
134 // Set if we are waiting for an accessibility event ack. | 105 // Set if we are waiting for an accessibility event ack. |
135 bool ack_pending_; | 106 bool ack_pending_; |
136 | 107 |
137 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete); | 108 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete); |
138 }; | 109 }; |
139 | 110 |
140 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ | 111 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ |
141 | 112 |
142 } // namespace content | 113 } // namespace content |
OLD | NEW |