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(RenderFrameImpl* render_frame); 41 virtual ~RendererAccessibilityComplete(); 42 43 // RenderFrameObserver implementation. 44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 45 46 // RendererAccessibility. 47 virtual void HandleWebAccessibilityEvent( 48 const blink::WebAXObject& obj, blink::WebAXEvent event) OVERRIDE; 49 virtual RendererAccessibilityType GetType() OVERRIDE; 50 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; 51 52 void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event); 53 54 protected: 55 // Send queued events from the renderer to the browser. 56 void SendPendingAccessibilityEvents(); 57 58 // Check the entire accessibility tree to see if any nodes have 59 // changed location, by comparing their locations to the cached 60 // versions. If any have moved, send an IPC with the new locations. 61 void SendLocationChanges(); 62 63 private: 64 // Handlers for messages from the browser to the renderer. 65 void OnDoDefaultAction(int acc_obj_id); 66 void OnEventsAck(); 67 void OnChangeScrollPosition(int acc_obj_id, int scroll_x, int scroll_y); 68 void OnScrollToMakeVisible(int acc_obj_id, gfx::Rect subfocus); 69 void OnScrollToPoint(int acc_obj_id, gfx::Point point); 70 void OnSetFocus(int acc_obj_id); 71 void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset); 72 void OnHitTest(gfx::Point point); 73 void OnReset(int reset_token); 74 void OnFatalError(); 75 76 // Events from Blink are collected until they are ready to be 77 // sent to the browser. 78 std::vector<AccessibilityHostMsg_EventParams> pending_events_; 79 80 // The adapter that exposes Blink's accessibility tree to AXTreeSerializer. 81 BlinkAXTreeSource tree_source_; 82 83 // The serializer that sends accessibility messages to the browser process. 84 ui::AXTreeSerializer<blink::WebAXObject> serializer_; 85 86 // Current location of every object, so we can detect when it moves. 87 base::hash_map<int, gfx::Rect> locations_; 88 89 // The most recently observed scroll offset of the root document element. 90 // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460 91 // is fixed. 92 gfx::Size last_scroll_offset_; 93 94 // Set if we are waiting for an accessibility event ack. 95 bool ack_pending_; 96 97 // Nonzero if the browser requested we reset the accessibility state. 98 // We need to return this token in the next IPC. 99 int reset_token_; 100 101 // So we can queue up tasks to be executed later. 102 base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_; 103 104 DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete); 105 }; 106 107 #endif // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_ 108 109 } // namespace content 110