| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_RENDERER_ACCESSIBILITY_COMPLETE_H_ | |
| 6 #define CONTENT_RENDERER_RENDERER_ACCESSIBILITY_COMPLETE_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/hash_tables.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "content/common/accessibility_node_data.h" | |
| 13 #include "content/public/renderer/render_view_observer.h" | |
| 14 #include "content/renderer/renderer_accessibility.h" | |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityNotif
ication.h" | |
| 16 | |
| 17 namespace WebKit { | |
| 18 class WebAccessibilityObject; | |
| 19 class WebDocument; | |
| 20 class WebNode; | |
| 21 }; | |
| 22 | |
| 23 namespace content { | |
| 24 class RenderViewImpl; | |
| 25 | |
| 26 // This is the subclass of RendererAccessibility that implements | |
| 27 // complete accessibility support for assistive technology (as opposed to | |
| 28 // partial support - see RendererAccessibilityFocusOnly). | |
| 29 // | |
| 30 // This version turns on WebKit's accessibility code and sends | |
| 31 // a serialized representation of that tree whenever it changes. It also | |
| 32 // handles requests from the browser to perform accessibility actions on | |
| 33 // nodes in the tree (e.g., change focus, or click on a button). | |
| 34 class RendererAccessibilityComplete : public RendererAccessibility { | |
| 35 public: | |
| 36 explicit RendererAccessibilityComplete(RenderViewImpl* render_view); | |
| 37 virtual ~RendererAccessibilityComplete(); | |
| 38 | |
| 39 // RenderView::Observer implementation. | |
| 40 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 41 virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE; | |
| 42 virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE; | |
| 43 | |
| 44 // RendererAccessibility. | |
| 45 virtual void HandleWebAccessibilityNotification( | |
| 46 const WebKit::WebAccessibilityObject& obj, | |
| 47 WebKit::WebAccessibilityNotification notification) OVERRIDE; | |
| 48 | |
| 49 private: | |
| 50 // Handle an accessibility notification to be sent to the browser process. | |
| 51 void HandleAccessibilityNotification( | |
| 52 const WebKit::WebAccessibilityObject& obj, | |
| 53 AccessibilityNotification notification); | |
| 54 | |
| 55 // In order to keep track of what nodes the browser knows about, we keep a | |
| 56 // representation of the browser tree - just IDs and parent/child | |
| 57 // relationships. | |
| 58 struct BrowserTreeNode { | |
| 59 BrowserTreeNode(); | |
| 60 ~BrowserTreeNode(); | |
| 61 int32 id; | |
| 62 std::vector<BrowserTreeNode*> children; | |
| 63 }; | |
| 64 | |
| 65 // Send queued notifications from the renderer to the browser. | |
| 66 void SendPendingAccessibilityNotifications(); | |
| 67 | |
| 68 // Update our representation of what nodes the browser has, given a | |
| 69 // tree of nodes. | |
| 70 void UpdateBrowserTree(const AccessibilityNodeData& renderer_node); | |
| 71 | |
| 72 // Clear the given node and recursively delete all of its descendants | |
| 73 // from the browser tree. (Does not delete |browser_node|). | |
| 74 void ClearBrowserTreeNode(BrowserTreeNode* browser_node); | |
| 75 | |
| 76 // Handlers for messages from the browser to the renderer. | |
| 77 void OnDoDefaultAction(int acc_obj_id); | |
| 78 void OnNotificationsAck(); | |
| 79 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y); | |
| 80 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus); | |
| 81 void OnScrollToPoint(int acc_obj_id, gfx::Point point); | |
| 82 void OnSetFocus(int acc_obj_id); | |
| 83 | |
| 84 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); | |
| 85 | |
| 86 // Whether or not this notification typically needs to send | |
| 87 // updates to its children, too. | |
| 88 bool ShouldIncludeChildren( | |
| 89 const AccessibilityHostMsg_NotificationParams& notification); | |
| 90 | |
| 91 // Checks if a WebKit accessibility object is an editable text node. | |
| 92 bool IsEditableText(const WebKit::WebAccessibilityObject& node); | |
| 93 | |
| 94 // Recursively explore the tree of WebKit accessibility objects rooted | |
| 95 // at |src|, and for each editable text node encountered, add a | |
| 96 // corresponding WebAccessibility node as a child of |dst|. | |
| 97 void RecursiveAddEditableTextNodesToTree( | |
| 98 const WebKit::WebAccessibilityObject& src, | |
| 99 AccessibilityNodeData* dst); | |
| 100 | |
| 101 // Build a tree of serializable AccessibilityNodeData nodes to send to the | |
| 102 // browser process, given a WebAccessibilityObject node from WebKit. | |
| 103 // Modifies |dst| in-place, it's assumed to be empty. | |
| 104 void BuildAccessibilityTree(const WebKit::WebAccessibilityObject& src, | |
| 105 bool include_children, | |
| 106 AccessibilityNodeData* dst); | |
| 107 | |
| 108 // So we can queue up tasks to be executed later. | |
| 109 base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_; | |
| 110 | |
| 111 // Notifications from WebKit are collected until they are ready to be | |
| 112 // sent to the browser. | |
| 113 std::vector<AccessibilityHostMsg_NotificationParams> pending_notifications_; | |
| 114 | |
| 115 // Our representation of the browser tree. | |
| 116 BrowserTreeNode* browser_root_; | |
| 117 | |
| 118 // A map from IDs to nodes in the browser tree. | |
| 119 base::hash_map<int32, BrowserTreeNode*> browser_id_map_; | |
| 120 | |
| 121 // The most recently observed scroll offset of the root document element. | |
| 122 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460 | |
| 123 // is fixed. | |
| 124 gfx::Size last_scroll_offset_; | |
| 125 | |
| 126 // The current accessibility mode. | |
| 127 AccessibilityMode mode_; | |
| 128 | |
| 129 // Set if we are waiting for an accessibility notification ack. | |
| 130 bool ack_pending_; | |
| 131 | |
| 132 // True if verbose logging of accessibility events is on. | |
| 133 bool logging_; | |
| 134 | |
| 135 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete); | |
| 136 }; | |
| 137 | |
| 138 #endif // CONTENT_RENDERER_RENDERER_ACCESSIBILITY_COMPLETE_H_ | |
| 139 | |
| 140 } // namespace content | |
| OLD | NEW |