Revert of Copy the contents of the ASan/Win blacklist to work around http://llvm...
[chromium-blink-merge.git] / content / renderer / accessibility / renderer_accessibility.h
blobbe0ca590a5e81c8097b70520188f15090c21eb97
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_
6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_
8 #include <vector>
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/common/accessibility_messages.h"
13 #include "content/public/renderer/render_frame_observer.h"
14 #include "content/renderer/accessibility/blink_ax_tree_source.h"
15 #include "third_party/WebKit/public/web/WebAXObject.h"
16 #include "ui/accessibility/ax_tree_serializer.h"
18 namespace blink {
19 class WebDocument;
20 class WebNode;
23 namespace content {
24 class RenderFrameImpl;
26 // The browser process implements native accessibility APIs, allowing
27 // assistive technology (e.g., screen readers, magnifiers) to access and
28 // control the web contents with high-level APIs. These APIs are also used
29 // by automation tools, and Windows 8 uses them to determine when the
30 // on-screen keyboard should be shown.
32 // An instance of this class belongs to RenderFrameImpl. Accessibility is
33 // initialized based on the AccessibilityMode of RenderFrameImpl; it lazily
34 // starts as Off or EditableTextOnly depending on the operating system, and
35 // switches to Complete if assistive technology is detected or a flag is set.
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
39 // accessible objects that can be used to respond to accessibility requests
40 // from other processes.
42 // This class implements complete accessibility support for assistive
43 // technology. It turns on Blink's accessibility code and sends a serialized
44 // representation of that tree whenever it changes. It also handles requests
45 // from the browser to perform accessibility actions on nodes in the tree
46 // (e.g., change focus, or click on a button).
47 class CONTENT_EXPORT RendererAccessibility : public RenderFrameObserver {
48 public:
49 explicit RendererAccessibility(RenderFrameImpl* render_frame);
50 ~RendererAccessibility() override;
52 // RenderFrameObserver implementation.
53 bool OnMessageReceived(const IPC::Message& message) override;
55 // Called when an accessibility notification occurs in Blink.
56 void HandleWebAccessibilityEvent(const blink::WebAXObject& obj,
57 blink::WebAXEvent event);
59 // Called when a new find in page result is highlighted.
60 void HandleAccessibilityFindInPageResult(
61 int identifier,
62 int match_index,
63 const blink::WebAXObject& start_object,
64 int start_offset,
65 const blink::WebAXObject& end_object,
66 int end_offset);
68 void AccessibilityFocusedNodeChanged(const blink::WebNode& node);
70 // This can be called before deleting a RendererAccessibility instance due
71 // to the accessibility mode changing, as opposed to during frame destruction
72 // (when there'd be no point).
73 void DisableAccessibility();
75 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event);
77 protected:
78 // Returns the main top-level document for this page, or NULL if there's
79 // no view or frame.
80 blink::WebDocument GetMainDocument();
82 // Send queued events from the renderer to the browser.
83 void SendPendingAccessibilityEvents();
85 // Check the entire accessibility tree to see if any nodes have
86 // changed location, by comparing their locations to the cached
87 // versions. If any have moved, send an IPC with the new locations.
88 void SendLocationChanges();
90 // The RenderFrameImpl that owns us.
91 RenderFrameImpl* render_frame_;
93 private:
94 // Handlers for messages from the browser to the renderer.
95 void OnDoDefaultAction(int acc_obj_id);
96 void OnEventsAck();
97 void OnFatalError();
98 void OnHitTest(gfx::Point point);
99 void OnSetAccessibilityFocus(int acc_obj_id);
100 void OnReset(int reset_token);
101 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus);
102 void OnScrollToPoint(int acc_obj_id, gfx::Point point);
103 void OnSetFocus(int acc_obj_id);
104 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset);
105 void OnSetValue(int acc_obj_id, base::string16 value);
107 // Events from Blink are collected until they are ready to be
108 // sent to the browser.
109 std::vector<AccessibilityHostMsg_EventParams> pending_events_;
111 // The adapter that exposes Blink's accessibility tree to AXTreeSerializer.
112 BlinkAXTreeSource tree_source_;
114 // The serializer that sends accessibility messages to the browser process.
115 ui::AXTreeSerializer<blink::WebAXObject> serializer_;
117 // Current location of every object, so we can detect when it moves.
118 base::hash_map<int, gfx::Rect> locations_;
120 // The most recently observed scroll offset of the root document element.
121 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460
122 // is fixed.
123 gfx::Size last_scroll_offset_;
125 // Set if we are waiting for an accessibility event ack.
126 bool ack_pending_;
128 // Nonzero if the browser requested we reset the accessibility state.
129 // We need to return this token in the next IPC.
130 int reset_token_;
132 // So we can queue up tasks to be executed later.
133 base::WeakPtrFactory<RendererAccessibility> weak_factory_;
135 DISALLOW_COPY_AND_ASSIGN(RendererAccessibility);
138 } // namespace content
140 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_H_