Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / renderer / accessibility / renderer_accessibility_complete.h
index 174062a..cb34c15 100644 (file)
 
 #include "base/containers/hash_tables.h"
 #include "base/memory/weak_ptr.h"
-#include "content/common/accessibility_node_data.h"
 #include "content/public/renderer/render_view_observer.h"
+#include "content/renderer/accessibility/blink_ax_tree_source.h"
 #include "content/renderer/accessibility/renderer_accessibility.h"
 #include "third_party/WebKit/public/web/WebAXEnums.h"
 #include "third_party/WebKit/public/web/WebAXObject.h"
+#include "ui/accessibility/ax_node_data.h"
+#include "ui/accessibility/ax_tree_serializer.h"
 
-namespace WebKit {
+namespace blink {
 class WebDocument;
 class WebNode;
 };
@@ -28,38 +30,26 @@ class RenderViewImpl;
 // complete accessibility support for assistive technology (as opposed to
 // partial support - see RendererAccessibilityFocusOnly).
 //
-// This version turns on WebKit's accessibility code and sends
+// This version turns on Blink's accessibility code and sends
 // a serialized representation of that tree whenever it changes. It also
 // handles requests from the browser to perform accessibility actions on
 // nodes in the tree (e.g., change focus, or click on a button).
 class CONTENT_EXPORT RendererAccessibilityComplete
     : public RendererAccessibility {
  public:
-  explicit RendererAccessibilityComplete(RenderViewImpl* render_view);
+  explicit RendererAccessibilityComplete(RenderFrameImpl* render_frame);
   virtual ~RendererAccessibilityComplete();
 
-  // RenderView::Observer implementation.
+  // RenderFrameObserver implementation.
   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
-  virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE;
-  virtual void DidFinishLoad(WebKit::WebFrame* frame) OVERRIDE;
 
   // RendererAccessibility.
   virtual void HandleWebAccessibilityEvent(
-      const WebKit::WebAXObject& obj, WebKit::WebAXEvent event) OVERRIDE;
-
-  // In order to keep track of what nodes the browser knows about, we keep a
-  // representation of the browser tree - just IDs and parent/child
-  // relationships.
-  struct CONTENT_EXPORT BrowserTreeNode {
-    BrowserTreeNode();
-    virtual ~BrowserTreeNode();
-    int32 id;
-    gfx::Rect location;
-    BrowserTreeNode* parent;
-    std::vector<BrowserTreeNode*> children;
-  };
-
-  virtual BrowserTreeNode* CreateBrowserTreeNode();
+      const blink::WebAXObject& obj, blink::WebAXEvent event) OVERRIDE;
+  virtual RendererAccessibilityType GetType() OVERRIDE;
+  virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE;
+
+  void HandleAXEvent(const blink::WebAXObject& obj, ui::AXEvent event);
 
  protected:
   // Send queued events from the renderer to the browser.
@@ -67,25 +57,10 @@ class CONTENT_EXPORT RendererAccessibilityComplete
 
   // Check the entire accessibility tree to see if any nodes have
   // changed location, by comparing their locations to the cached
-  // versions. If any have moved, append a event to |events|
-  // that updates the coordinates of these objects.
-  void AppendLocationChangeEvents(
-      std::vector<AccessibilityHostMsg_EventParams>* events);
+  // versions. If any have moved, send an IPC with the new locations.
+  void SendLocationChanges();
 
  private:
-  // Serialize the given accessibility object |obj| and append it to
-  // |dst|, and then recursively also serialize any *new* children of
-  // |obj|, based on what object ids we know the browser already has.
-  // The set of ids serialized is added to |ids_serialized|, and any
-  // ids previously in that set are not serialized again.
-  void SerializeChangedNodes(const WebKit::WebAXObject& obj,
-                             std::vector<AccessibilityNodeData>* dst,
-                             std::set<int>* ids_serialized);
-
-  // Clear the given node and recursively delete all of its descendants
-  // from the browser tree. (Does not delete |browser_node|).
-  void ClearBrowserTreeNode(BrowserTreeNode* browser_node);
-
   // Handlers for messages from the browser to the renderer.
   void OnDoDefaultAction(int acc_obj_id);
   void OnEventsAck();
@@ -94,52 +69,33 @@ class CONTENT_EXPORT RendererAccessibilityComplete
   void OnScrollToPoint(int acc_obj_id, gfx::Point point);
   void OnSetFocus(int acc_obj_id);
   void OnSetTextSelection(int acc_obj_id, int start_offset, int end_offset);
+  void OnHitTest(gfx::Point point);
   void OnFatalError();
 
-  // Checks if a WebKit accessibility object is an editable text node.
-  bool IsEditableText(const WebKit::WebAXObject& node);
-
-  // Recursively explore the tree of WebKit accessibility objects rooted
-  // at |src|, and for each editable text node encountered, add a
-  // corresponding WebAccessibility node as a child of |dst|.
-  void RecursiveAddEditableTextNodesToTree(
-      const WebKit::WebAXObject& src,
-      AccessibilityNodeData* dst);
-
-  // Build a tree of serializable AccessibilityNodeData nodes to send to the
-  // browser process, given a WebAXObject node from WebKit.
-  // Modifies |dst| in-place, it's assumed to be empty.
-  void BuildAccessibilityTree(const WebKit::WebAXObject& src,
-                              bool include_children,
-                              AccessibilityNodeData* dst);
-
   // So we can queue up tasks to be executed later.
   base::WeakPtrFactory<RendererAccessibilityComplete> weak_factory_;
 
-  // Events from WebKit are collected until they are ready to be
+  // Events from Blink are collected until they are ready to be
   // sent to the browser.
   std::vector<AccessibilityHostMsg_EventParams> pending_events_;
 
-  // Our representation of the browser tree.
-  BrowserTreeNode* browser_root_;
+  // The adapter that exposes Blink's accessibility tree to AXTreeSerializer.
+  BlinkAXTreeSource tree_source_;
+
+  // The serializer that sends accessibility messages to the browser process.
+  ui::AXTreeSerializer<blink::WebAXObject> serializer_;
 
-  // A map from IDs to nodes in the browser tree.
-  base::hash_map<int32, BrowserTreeNode*> browser_id_map_;
+  // Current location of every object, so we can detect when it moves.
+  base::hash_map<int, gfx::Rect> locations_;
 
   // The most recently observed scroll offset of the root document element.
   // TODO(dmazzoni): remove once https://bugs.webkit.org/show_bug.cgi?id=73460
   // is fixed.
   gfx::Size last_scroll_offset_;
 
-  // The current accessibility mode.
-  AccessibilityMode mode_;
-
   // Set if we are waiting for an accessibility event ack.
   bool ack_pending_;
 
-  // True if verbose logging of accessibility events is on.
-  bool logging_;
-
   DISALLOW_COPY_AND_ASSIGN(RendererAccessibilityComplete);
 };