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_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ 6 #define CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ 7 8 #include <set> 9 #include <vector> 10 11 #include "base/containers/hash_tables.h" 12 #include "base/memory/weak_ptr.h" 13 #include "content/public/renderer/render_view_observer.h" 14 #include "content/renderer/accessibility/blink_ax_tree_source.h" 15 #include "content/renderer/accessibility/renderer_accessibility.h" 16 #include "third_party/WebKit/public/web/WebAXEnums.h" 17 #include "third_party/WebKit/public/web/WebAXObject.h" 18 #include "ui/accessibility/ax_node_data.h" 19 #include "ui/accessibility/ax_tree_serializer.h" 20 21 namespace blink { 22 class WebDocument; 23 class WebNode; 24 }; 25 26 namespace content { 27 class RenderViewImpl; 28 29 // This is the subclass of RendererAccessibility that implements 30 // complete accessibility support for assistive technology (as opposed to 31 // partial support - see RendererAccessibilityFocusOnly). 32 // 33 // This version turns on Blink's accessibility code and sends 34 // a serialized representation of that tree whenever it changes. It also 35 // handles requests from the browser to perform accessibility actions on 36 // nodes in the tree (e.g., change focus, or click on a button). 37 class CONTENT_EXPORT RendererAccessibilityComplete 38 : public RendererAccessibility { 39 public: 40 explicit RendererAccessibilityComplete(RenderViewImpl* render_view); 41 virtual ~RendererAccessibilityComplete(); 42 43 // RenderView::Observer implementation. 44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 45 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; 46 virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE; 47 48 // RendererAccessibility. 49 virtual void HandleWebAccessibilityEvent( 50 const blink::WebAXObject& obj, blink::WebAXEvent event) OVERRIDE; 51 virtual RendererAccessibilityType GetType() OVERRIDE; 52 53 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event); 54 55 protected: 56 // Send queued events from the renderer to the browser. 57 void SendPendingAccessibilityEvents(); 58 59 // Check the entire accessibility tree to see if any nodes have 60 // changed location, by comparing their locations to the cached 61 // versions. If any have moved, send an IPC with the new locations. 62 void SendLocationChanges(); 63 64 private: 65 // Handlers for messages from the browser to the renderer. 66 void OnDoDefaultAction(int acc_obj_id); 67 void OnEventsAck(); 68 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y); 69 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus); 70 void OnScrollToPoint(int acc_obj_id, gfx::Point point); 71 void OnSetFocus(int acc_obj_id); 72 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); 73 void OnHitTest(gfx::Point point); 74 void OnFatalError(); 75 76 // So we can queue up tasks to be executed later. 77 base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_; 78 79 // Events from Blink are collected until they are ready to be 80 // sent to the browser. 81 std::vector<AccessibilityHostMsg_EventParams> pending_events_; 82 83 // The adapter that exposes Blink's accessibility tree to AXTreeSerializer. 84 BlinkAXTreeSource tree_source_; 85 86 // The serializer that sends accessibility messages to the browser process. 87 ui::AXTreeSerializer<blink::WebAXObject> serializer_; 88 89 // Current location of every object, so we can detect when it moves. 90 base::hash_map<int, gfx::Rect> locations_; 91 92 // The most recently observed scroll offset of the root document element. 93 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460 94 // is fixed. 95 gfx::Size last_scroll_offset_; 96 97 // Set if we are waiting for an accessibility event ack. 98 bool ack_pending_; 99 100 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete); 101 }; 102 103 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ 104 105 } // namespace content 106