Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: content/renderer/accessibility/renderer_accessibility_complete.h

Issue 125763003: Refactor content/renderer/accessibility to use AXTreeSerializer (re-land). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leaks Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
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 virtual RendererAccessibilityType GetType() OVERRIDE; 51 virtual RendererAccessibilityType GetType() OVERRIDE;
50 52
51 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event); 53 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event);
52 54
53 // In order to keep track of what nodes the browser knows about, we keep a
54 // representation of the browser tree - just IDs and parent/child
55 // relationships.
56 struct CONTENT_EXPORT BrowserTreeNode {
57 BrowserTreeNode();
58 virtual ~BrowserTreeNode();
59 int32 id;
60 gfx::Rect location;
61 BrowserTreeNode* parent;
62 std::vector<BrowserTreeNode*> children;
63 };
64
65 virtual BrowserTreeNode* CreateBrowserTreeNode();
66
67 protected: 55 protected:
68 // Send queued events from the renderer to the browser. 56 // Send queued events from the renderer to the browser.
69 void SendPendingAccessibilityEvents(); 57 void SendPendingAccessibilityEvents();
70 58
71 // Check the entire accessibility tree to see if any nodes have 59 // Check the entire accessibility tree to see if any nodes have
72 // changed location, by comparing their locations to the cached 60 // changed location, by comparing their locations to the cached
73 // versions. If any have moved, send an IPC with the new locations. 61 // versions. If any have moved, send an IPC with the new locations.
74 void SendLocationChanges(); 62 void SendLocationChanges();
75 63
76 private: 64 private:
77 // Serialize the given accessibility object |obj| and append it to
78 // |dst|, and then recursively also serialize any *new* children of
79 // |obj|, based on what object ids we know the browser already has.
80 // The set of ids serialized is added to |ids_serialized|, and any
81 // ids previously in that set are not serialized again.
82 void SerializeChangedNodes(const blink::WebAXObject& obj,
83 std::vector<ui::AXNodeData>* dst,
84 std::set<int>* ids_serialized);
85
86 // Clear the given node and recursively delete all of its descendants
87 // from the browser tree. (Does not delete |browser_node|).
88 void ClearBrowserTreeNode(BrowserTreeNode* browser_node);
89
90 // Handlers for messages from the browser to the renderer. 65 // Handlers for messages from the browser to the renderer.
91 void OnDoDefaultAction(int acc_obj_id); 66 void OnDoDefaultAction(int acc_obj_id);
92 void OnEventsAck(); 67 void OnEventsAck();
93 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y); 68 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y);
94 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus); 69 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus);
95 void OnScrollToPoint(int acc_obj_id, gfx::Point point); 70 void OnScrollToPoint(int acc_obj_id, gfx::Point point);
96 void OnSetFocus(int acc_obj_id); 71 void OnSetFocus(int acc_obj_id);
97 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); 72 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset);
98 void OnFatalError(); 73 void OnFatalError();
99 74
100 // Checks if a Blink accessibility object is an editable text node. 75 // Checks if a Blink accessibility object is an editable text node.
101 bool IsEditableText(const blink::WebAXObject& node); 76 bool IsEditableText(const blink::WebAXObject& node);
102 77
103 // Recursively explore the tree of Blink accessibility objects rooted 78 // Recursively explore the tree of Blink accessibility objects rooted
104 // at |src|, and for each editable text node encountered, add a 79 // at |src|, and for each editable text node encountered, add a
105 // corresponding WebAccessibility node as a child of |dst|. 80 // corresponding WebAccessibility node as a child of |dst|.
106 void RecursiveAddEditableTextNodesToTree( 81 void RecursiveAddEditableTextNodesToTree(
107 const blink::WebAXObject& src, 82 const blink::WebAXObject& src,
108 ui::AXNodeData* dst); 83 ui::AXNodeData* dst);
109 84
110 // Build a tree of serializable ui::AXNodeData nodes to send to the
111 // browser process, given a WebAXObject node from Blink.
112 // Modifies |dst| in-place, it's assumed to be empty.
113 void BuildAccessibilityTree(const blink::WebAXObject& src,
114 bool include_children,
115 ui::AXNodeData* dst);
116
117 // So we can queue up tasks to be executed later. 85 // So we can queue up tasks to be executed later.
118 base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_; 86 base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_;
119 87
120 // Events from Blink are collected until they are ready to be 88 // Events from Blink are collected until they are ready to be
121 // sent to the browser. 89 // sent to the browser.
122 std::vector<AccessibilityHostMsg_EventParams> pending_events_; 90 std::vector<AccessibilityHostMsg_EventParams> pending_events_;
123 91
124 // Our representation of the browser tree. 92 // The adapter that exposes Blink's accessibility tree to AXTreeSerializer.
125 BrowserTreeNode* browser_root_; 93 BlinkAXTreeSource tree_source_;
126 94
127 // A map from IDs to nodes in the browser tree. 95 // The serializer that sends accessibility messages to the browser process.
128 base::hash_map<int32, BrowserTreeNode*> browser_id_map_; 96 ui::AXTreeSerializer<blink::WebAXObject> serializer_;
97
98 // Current location of every object, so we can detect when it moves.
99 base::hash_map<int, gfx::Rect> locations_;
129 100
130 // The most recently observed scroll offset of the root document element. 101 // The most recently observed scroll offset of the root document element.
131 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460 102 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460
132 // is fixed. 103 // is fixed.
133 gfx::Size last_scroll_offset_; 104 gfx::Size last_scroll_offset_;
134 105
135 // Set if we are waiting for an accessibility event ack. 106 // Set if we are waiting for an accessibility event ack.
136 bool ack_pending_; 107 bool ack_pending_;
137 108
138 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete); 109 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete);
139 }; 110 };
140 111
141 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ 112 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_
142 113
143 } // namespace content 114 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698