chromeos: dbus: add Bluetooth properties support
[chromium-blink-merge.git] / content / renderer / renderer_accessibility.h
blob835a00f93ca50fea67a403e8a8894c2853ca2ae6
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_RENDERER_ACCESSIBILITY_H_
6 #define CONTENT_RENDERER_RENDERER_ACCESSIBILITY_H_
7 #pragma once
9 #include <vector>
11 #include "base/hash_tables.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/renderer/render_view_observer.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityNotification.h"
16 class RenderViewImpl;
18 namespace WebKit {
19 class WebAccessibilityObject;
20 class WebDocument;
21 class WebNode;
24 namespace webkit_glue {
25 struct WebAccessibility;
28 // RendererAccessibility belongs to the RenderView. It's responsible for
29 // sending a serialized representation of WebKit's accessibility tree from
30 // the renderer to the browser and sending updates whenever it changes, and
31 // handling requests from the browser to perform accessibility actions on
32 // nodes in the tree (e.g., change focus, or click on a button).
33 class RendererAccessibility : public content::RenderViewObserver {
34 public:
35 RendererAccessibility(RenderViewImpl* render_view);
36 virtual ~RendererAccessibility();
38 // RenderView::Observer implementation.
39 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
40 virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE;
41 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE;
43 // Called when an accessibility notification occurs in WebKit.
44 virtual void PostAccessibilityNotification(
45 const WebKit::WebAccessibilityObject& obj,
46 WebKit::WebAccessibilityNotification notification);
48 private:
49 // One accessibility notification from WebKit. These are queued up and
50 // used to send tree updates and notification messages from the
51 // renderer to the browser.
52 struct Notification {
53 public:
54 // The id of the accessibility object.
55 int32 id;
57 // The accessibility notification type.
58 WebKit::WebAccessibilityNotification type;
61 // In order to keep track of what nodes the browser knows about, we keep a
62 // representation of the browser tree - just IDs and parent/child
63 // relationships.
64 struct BrowserTreeNode {
65 BrowserTreeNode() : id(0) {}
66 ~BrowserTreeNode() {}
67 int32 id;
68 std::vector<BrowserTreeNode*> children;
71 // Send queued notifications from the renderer to the browser.
72 void SendPendingAccessibilityNotifications();
74 // Update our representation of what nodes the browser has, given a
75 // tree of nodes.
76 void UpdateBrowserTree(const webkit_glue::WebAccessibility& renderer_node);
78 // Clear the given node and recursively delete all of its descendants
79 // from the browser tree. (Does not delete |browser_node|).
80 void ClearBrowserTreeNode(BrowserTreeNode* browser_node);
82 // Handlers for messages from the browser to the renderer.
83 void OnDoDefaultAction(int acc_obj_id);
84 void OnNotificationsAck();
85 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y);
86 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus);
87 void OnScrollToPoint(int acc_obj_id, gfx::Point point);
88 void OnEnable();
89 void OnSetFocus(int acc_obj_id);
91 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset);
93 // Whether or not this notification typically needs to send
94 // updates to its children, too.
95 bool ShouldIncludeChildren(const Notification& notification);
97 // Returns the main top-level document for this page, or NULL if there's
98 // no view or frame.
99 WebKit::WebDocument GetMainDocument();
101 // So we can queue up tasks to be executed later.
102 base::WeakPtrFactory<RendererAccessibility> weak_factory_;
104 // Notifications from WebKit are collected until they are ready to be
105 // sent to the browser.
106 std::vector<Notification> pending_notifications_;
108 // Our representation of the browser tree.
109 BrowserTreeNode* browser_root_;
111 // A map from IDs to nodes in the browser tree.
112 base::hash_map<int32, BrowserTreeNode*> browser_id_map_;
114 // The most recently observed scroll offset of the root document element.
115 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460
116 // is fixed.
117 gfx::Size last_scroll_offset_;
119 // Set if we are waiting for an accessibility notification ack.
120 bool ack_pending_;
122 // True if verbose logging of accessibility events is on.
123 bool logging_;
125 DISALLOW_COPY_AND_ASSIGN(RendererAccessibility);
128 #endif // CONTENT_RENDERER_RENDERER_ACCESSIBILITY_H_