1// Copyright 2014 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 CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AUTOMATION_MANAGER_ASH_H_
6#define CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AUTOMATION_MANAGER_ASH_H_
7
8#include "base/basictypes.h"
9#include "base/memory/scoped_ptr.h"
10
11#include "chrome/browser/extensions/api/automation_internal/automation_action_adapter.h"
12#include "chrome/browser/ui/ash/accessibility/ax_tree_source_ash.h"
13#include "ui/accessibility/ax_tree_serializer.h"
14
15template <typename T> struct DefaultSingletonTraits;
16
17namespace content {
18class BrowserContext;
19}  // namespace content
20
21namespace views {
22class AXAuraObjWrapper;
23class View;
24}  // namespace views
25
26// Manages a tree of automation nodes.
27class AutomationManagerAsh : public extensions::AutomationActionAdapter {
28 public:
29  // Get the single instance of this class.
30  static AutomationManagerAsh* GetInstance();
31
32  // Enable automation support for views.
33  void Enable(content::BrowserContext* context);
34
35  // Disable automation support for views.
36  void Disable();
37
38  // Handle an event fired upon a |View|.
39  void HandleEvent(content::BrowserContext* context,
40                   views::View* view,
41                   ui::AXEvent event_type);
42
43  // AutomationActionAdapter implementation.
44  virtual void DoDefault(int32 id) OVERRIDE;
45  virtual void Focus(int32 id) OVERRIDE;
46  virtual void MakeVisible(int32 id) OVERRIDE;
47  virtual void SetSelection(int32 id, int32 start, int32 end) OVERRIDE;
48
49 protected:
50  virtual ~AutomationManagerAsh();
51
52 private:
53  friend struct DefaultSingletonTraits<AutomationManagerAsh>;
54
55  AutomationManagerAsh();
56
57    // Reset all state in this manager.
58  void Reset();
59
60  void SendEvent(content::BrowserContext* context,
61                 views::AXAuraObjWrapper* aura_obj,
62                 ui::AXEvent event_type);
63
64  // Whether automation support for views is enabled.
65  bool enabled_;
66
67  // Holds the active views-based accessibility tree. A tree currently consists
68  // of all views descendant to a |Widget| (see |AXTreeSourceViews|).
69  // A tree becomes active when an event is fired on a descendant view.
70  scoped_ptr <AXTreeSourceAsh> current_tree_;
71
72  // Serializes incremental updates on the currently active tree
73  // |current_tree_|.
74  scoped_ptr<ui::AXTreeSerializer<views::AXAuraObjWrapper*> >
75      current_tree_serializer_;
76
77  DISALLOW_COPY_AND_ASSIGN(AutomationManagerAsh);
78};
79
80#endif  // CHROME_BROWSER_UI_ASH_ACCESSIBILITY_AUTOMATION_MANAGER_ASH_H_
81