Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / renderer / accessibility / renderer_accessibility_complete.h
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 OnFatalError();
74
75   // Events from Blink are collected until they are ready to be
76   // sent to the browser.
77   std::vector<AccessibilityHostMsg_EventParams> pending_events_;
78
79   // The adapter that exposes Blink's accessibility tree to AXTreeSerializer.
80   BlinkAXTreeSource tree_source_;
81
82   // The serializer that sends accessibility messages to the browser process.
83   ui::AXTreeSerializer<blink::WebAXObject> serializer_;
84
85   // Current location of every object, so we can detect when it moves.
86   base::hash_map<int, gfx::Rect> locations_;
87
88   // The most recently observed scroll offset of the root document element.
89   // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460
90   // is fixed.
91   gfx::Size last_scroll_offset_;
92
93   // Set if we are waiting for an accessibility event ack.
94   bool ack_pending_;
95
96   // So we can queue up tasks to be executed later.
97   base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_;
98
99   DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete);
100 };
101
102 #endif  // CONTENT_RENDERER_ACCESSIBILITY_RENDERER_ACCESSIBILITY_COMPLETE_H_
103
104 }  // namespace content