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_H_ | 5 #ifndef CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_ |
6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_ | 6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_ |
7 | 7 |
8 #include <vector> | |
9 | |
10 #include "base/containers/hash_tables.h" | |
11 #include "base/memory/weak_ptr.h" | |
8 #include "content/common/accessibility_messages.h" | 12 #include "content/common/accessibility_messages.h" |
9 #include "content/public/renderer/render_frame_observer.h" | 13 #include "content/public/renderer/render_frame_observer.h" |
14 #include "content/renderer/accessibility/blink_ax_tree_source.h" | |
10 #include "third_party/WebKit/public/web/WebAXObject.h" | 15 #include "third_party/WebKit/public/web/WebAXObject.h" |
16 #include "ui/accessibility/ax_tree_serializer.h" | |
11 | 17 |
12 namespace blink { | 18 namespace blink { |
13 class WebDocument; | 19 class WebDocument; |
20 class WebNode; | |
14 }; | 21 }; |
15 | 22 |
16 namespace content { | 23 namespace content { |
17 class RenderFrameImpl; | 24 class RenderFrameImpl; |
18 | 25 |
19 enum RendererAccessibilityType { | 26 // The browser process implements native accessibility APIs, allowing |
20 // Turns on Blink accessibility and provides a full accessibility | |
21 // implementation for when assistive technology is running. | |
22 RendererAccessibilityTypeComplete | |
23 }; | |
24 | |
25 // The browser process implement native accessibility APIs, allowing | |
26 // assistive technology (e.g., screen readers, magnifiers) to access and | 27 // assistive technology (e.g., screen readers, magnifiers) to access and |
27 // control the web contents with high-level APIs. These APIs are also used | 28 // control the web contents with high-level APIs. These APIs are also used |
28 // by automation tools, and Windows 8 uses them to determine when the | 29 // by automation tools, and Windows 8 uses them to determine when the |
29 // on-screen keyboard should be shown. | 30 // on-screen keyboard should be shown. |
30 // | 31 // |
31 // An instance of this class (or rather, a subclass) belongs to RenderFrameImpl. | 32 // An instance of this class belongs to RenderFrameImpl. Accessibility is |
32 // Accessibility is initialized based on the AccessibilityMode of | 33 // initialized based on the AccessibilityMode of RenderFrameImpl; it lazily |
33 // RenderFrameImpl; it lazily starts as Off or EditableTextOnly depending on | 34 // starts as Off or EditableTextOnly depending on the operating system, and |
34 // the operating system, and switches to Complete if assistive technology is | 35 // switches to Complete if assistive technology is detected or a flag is set. |
35 // detected or a flag is set. | |
36 // | 36 // |
37 // A tree of accessible objects is built here and sent to the browser process; | 37 // A tree of accessible objects is built here and sent to the browser process; |
38 // the browser process maintains this as a tree of platform-native | 38 // the browser process maintains this as a tree of platform-native |
39 // accessible objects that can be used to respond to accessibility requests | 39 // accessible objects that can be used to respond to accessibility requests |
40 // from other processes. | 40 // from other processes. |
41 // | 41 // |
42 // This base class just contains common code and will not do anything by itself. | 42 // This class implements complete accessibility support for assistive |
dmazzoni
2014/10/30 15:15:49
Thank you for carefully merging the comments too,
| |
43 // The subclass is: | 43 // technology. It turns on Blink's accessibility code and sends a serialized |
44 // | 44 // representation of that tree whenever it changes. It also handles requests |
45 // RendererAccessibilityComplete - turns on Blink accessibility and | 45 // from the browser to perform accessibility actions on nodes in the tree |
46 // provides a full accessibility implementation for when | 46 // (e.g., change focus, or click on a button). |
47 // assistive technology is running. | |
48 // | |
49 class CONTENT_EXPORT RendererAccessibility : public RenderFrameObserver { | 47 class CONTENT_EXPORT RendererAccessibility : public RenderFrameObserver { |
50 public: | 48 public: |
51 explicit RendererAccessibility(RenderFrameImpl* render_frame); | 49 explicit RendererAccessibility(RenderFrameImpl* render_frame); |
52 ~RendererAccessibility() override; | 50 ~RendererAccessibility() override; |
53 | 51 |
52 // RenderFrameObserver implementation. | |
53 bool OnMessageReceived(const IPC::Message& message) override; | |
54 | |
54 // Called when an accessibility notification occurs in Blink. | 55 // Called when an accessibility notification occurs in Blink. |
55 virtual void HandleWebAccessibilityEvent( | 56 void HandleWebAccessibilityEvent(const blink::WebAXObject& obj, |
56 const blink::WebAXObject& obj, blink::WebAXEvent event) = 0; | 57 blink::WebAXEvent event); |
57 virtual void FocusedNodeChanged(const blink::WebNode& node) = 0; | |
58 | 58 |
59 // Gets the type of this RendererAccessibility object. Primarily intended for | 59 void FocusedNodeChanged(const blink::WebNode& node); |
60 // testing. | |
61 virtual RendererAccessibilityType GetType() = 0; | |
62 | 60 |
63 // This can be called before deleting a RendererAccessibility instance due | 61 // This can be called before deleting a RendererAccessibility instance due |
64 // to the accessibility mode changing, as opposed to during frame destruction | 62 // to the accessibility mode changing, as opposed to during frame destruction |
65 // (when there'd be no point). | 63 // (when there'd be no point). |
66 virtual void DisableAccessibility() {} | 64 void DisableAccessibility(); |
65 | |
66 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event); | |
67 | 67 |
68 protected: | 68 protected: |
69 // Returns the main top-level document for this page, or NULL if there's | 69 // Returns the main top-level document for this page, or NULL if there's |
70 // no view or frame. | 70 // no view or frame. |
71 blink::WebDocument GetMainDocument(); | 71 blink::WebDocument GetMainDocument(); |
72 | 72 |
73 // Send queued events from the renderer to the browser. | |
74 void SendPendingAccessibilityEvents(); | |
75 | |
76 // Check the entire accessibility tree to see if any nodes have | |
77 // changed location, by comparing their locations to the cached | |
78 // versions. If any have moved, send an IPC with the new locations. | |
79 void SendLocationChanges(); | |
80 | |
73 // The RenderFrameImpl that owns us. | 81 // The RenderFrameImpl that owns us. |
74 RenderFrameImpl* render_frame_; | 82 RenderFrameImpl* render_frame_; |
75 | 83 |
84 private: | |
85 // Handlers for messages from the browser to the renderer. | |
86 void OnDoDefaultAction(int acc_obj_id); | |
87 void OnEventsAck(); | |
88 void OnFatalError(); | |
89 void OnHitTest(gfx::Point point); | |
90 void OnReset(int reset_token); | |
91 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus); | |
92 void OnScrollToPoint(int acc_obj_id, gfx::Point point); | |
93 void OnSetFocus(int acc_obj_id); | |
94 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); | |
95 | |
96 // Events from Blink are collected until they are ready to be | |
97 // sent to the browser. | |
98 std::vector<AccessibilityHostMsg_EventParams> pending_events_; | |
99 | |
100 // The adapter that exposes Blink's accessibility tree to AXTreeSerializer. | |
101 BlinkAXTreeSource tree_source_; | |
102 | |
103 // The serializer that sends accessibility messages to the browser process. | |
104 ui::AXTreeSerializer<blink::WebAXObject> serializer_; | |
105 | |
106 // Current location of every object, so we can detect when it moves. | |
107 base::hash_map<int, gfx::Rect> locations_; | |
108 | |
109 // The most recently observed scroll offset of the root document element. | |
110 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460 | |
111 // is fixed. | |
112 gfx::Size last_scroll_offset_; | |
113 | |
114 // Set if we are waiting for an accessibility event ack. | |
115 bool ack_pending_; | |
116 | |
117 // Nonzero if the browser requested we reset the accessibility state. | |
118 // We need to return this token in the next IPC. | |
119 int reset_token_; | |
120 | |
121 // So we can queue up tasks to be executed later. | |
122 base::WeakPtrFactory<RendererAccessibility> weak_factory_; | |
123 | |
76 DISALLOW_COPY_AND_ASSIGN(RendererAccessibility); | 124 DISALLOW_COPY_AND_ASSIGN(RendererAccessibility); |
77 }; | 125 }; |
78 | 126 |
79 } // namespace content | 127 } // namespace content |
80 | 128 |
81 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_ | 129 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_ |
OLD | NEW |