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 CONTENT_SHELL_RENDERER_TEST_RUNNER_ACCESSIBILITY_CONTROLLER_H_
6#define CONTENT_SHELL_RENDERER_TEST_RUNNER_ACCESSIBILITY_CONTROLLER_H_
7
8#include <vector>
9
10#include "base/memory/weak_ptr.h"
11#include "content/shell/renderer/test_runner/web_ax_object_proxy.h"
12#include "third_party/WebKit/public/web/WebAXObject.h"
13#include "v8/include/v8.h"
14
15namespace blink {
16class WebFrame;
17class WebString;
18class WebView;
19}
20
21namespace content {
22
23class WebTestDelegate;
24
25class AccessibilityController :
26      public base::SupportsWeakPtr<AccessibilityController> {
27 public:
28  AccessibilityController();
29  ~AccessibilityController();
30
31  void Reset();
32  void Install(blink::WebFrame* frame);
33  void SetFocusedElement(const blink::WebAXObject&);
34  bool ShouldLogAccessibilityEvents();
35  void NotificationReceived(const blink::WebAXObject& target,
36                            const std::string& notification_name);
37
38  void SetDelegate(WebTestDelegate* delegate);
39  void SetWebView(blink::WebView* web_view);
40
41 private:
42  friend class AccessibilityControllerBindings;
43
44  // Bound methods and properties
45  void LogAccessibilityEvents();
46  void SetNotificationListener(v8::Handle<v8::Function> callback);
47  void UnsetNotificationListener();
48  v8::Handle<v8::Object> FocusedElement();
49  v8::Handle<v8::Object> RootElement();
50  v8::Handle<v8::Object> AccessibleElementById(const std::string& id);
51
52  v8::Handle<v8::Object> FindAccessibleElementByIdRecursive(
53      const blink::WebAXObject&, const blink::WebString& id);
54
55  // If true, will log all accessibility notifications.
56  bool log_accessibility_events_;
57
58  blink::WebAXObject focused_element_;
59  blink::WebAXObject root_element_;
60
61  WebAXObjectProxyList elements_;
62
63  v8::Persistent<v8::Function> notification_callback_;
64
65  WebTestDelegate* delegate_;
66  blink::WebView* web_view_;
67
68  base::WeakPtrFactory<AccessibilityController> weak_factory_;
69
70  DISALLOW_COPY_AND_ASSIGN(AccessibilityController);
71};
72
73}  // namespace content
74
75#endif  // CONTENT_SHELL_RENDERER_TEST_RUNNER_ACCESSIBILITY_CONTROLLER_H_
76