Utilize the window.speechSynthesis.onvoiceschanged event in ChromeVox.
[chromium-blink-merge.git] / ash / test / ui_controls_factory_ash.cc
blobcbdeddb0847ccfd292f5fc6b74a16a701928337f
1 // Copyright 2013 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.
5 #include "ash/shell.h"
6 #include "ash/shell_factory.h"
7 #include "ash/wm/coordinate_conversion.h"
8 #include "ash/wm/window_properties.h"
9 #include "ui/aura/client/capture_client.h"
10 #include "ui/aura/client/screen_position_client.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/test/ui_controls_factory_aura.h"
13 #include "ui/aura/window_property.h"
14 #include "ui/aura/window_tree_host.h"
15 #include "ui/base/test/ui_controls.h"
16 #include "ui/base/test/ui_controls_aura.h"
17 #include "ui/gfx/screen.h"
19 DECLARE_WINDOW_PROPERTY_TYPE(ui_controls::UIControlsAura*)
21 namespace ash {
22 namespace test {
23 namespace {
25 using ui_controls::UIControlsAura;
26 using ui_controls::MouseButton;
28 DEFINE_OWNED_WINDOW_PROPERTY_KEY(UIControlsAura, kUIControlsKey, NULL);
30 // Returns the UIControls object for RootWindow.
31 // kUIControlsKey is owned property and UIControls object
32 // will be deleted when the root window is deleted.
33 UIControlsAura* GetUIControlsForRootWindow(aura::Window* root_window) {
34 UIControlsAura* native_ui_control =
35 root_window->GetProperty(kUIControlsKey);
36 if (!native_ui_control) {
37 native_ui_control =
38 aura::test::CreateUIControlsAura(root_window->GetHost());
39 // Pass the ownership to the |root_window|.
40 root_window->SetProperty(kUIControlsKey, native_ui_control);
42 return native_ui_control;
45 // Returns the UIControls object for the RootWindow at |point_in_screen|.
46 UIControlsAura* GetUIControlsAt(const gfx::Point& point_in_screen) {
47 // TODO(mazda): Support the case passive grab is taken.
48 return GetUIControlsForRootWindow(ash::wm::GetRootWindowAt(point_in_screen));
51 } // namespace
53 class UIControlsAsh : public UIControlsAura {
54 public:
55 UIControlsAsh() {
57 virtual ~UIControlsAsh() {
60 // UIControslAura overrides:
61 virtual bool SendKeyPress(gfx::NativeWindow window,
62 ui::KeyboardCode key,
63 bool control,
64 bool shift,
65 bool alt,
66 bool command) OVERRIDE {
67 return SendKeyPressNotifyWhenDone(
68 window, key, control, shift, alt, command, base::Closure());
71 virtual bool SendKeyPressNotifyWhenDone(
72 gfx::NativeWindow window,
73 ui::KeyboardCode key,
74 bool control,
75 bool shift,
76 bool alt,
77 bool command,
78 const base::Closure& closure) OVERRIDE {
79 aura::Window* root =
80 window ? window->GetRootWindow() : ash::Shell::GetTargetRootWindow();
81 UIControlsAura* ui_controls = GetUIControlsForRootWindow(root);
82 return ui_controls && ui_controls->SendKeyPressNotifyWhenDone(
83 window, key, control, shift, alt, command, closure);
86 virtual bool SendMouseMove(long x, long y) OVERRIDE {
87 gfx::Point p(x, y);
88 UIControlsAura* ui_controls = GetUIControlsAt(p);
89 return ui_controls && ui_controls->SendMouseMove(p.x(), p.y());
92 virtual bool SendMouseMoveNotifyWhenDone(
93 long x,
94 long y,
95 const base::Closure& closure) OVERRIDE {
96 gfx::Point p(x, y);
97 UIControlsAura* ui_controls = GetUIControlsAt(p);
98 return ui_controls &&
99 ui_controls->SendMouseMoveNotifyWhenDone(p.x(), p.y(), closure);
102 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE {
103 gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint());
104 UIControlsAura* ui_controls = GetUIControlsAt(p);
105 return ui_controls && ui_controls->SendMouseEvents(type, state);
108 virtual bool SendMouseEventsNotifyWhenDone(
109 MouseButton type, int state, const base::Closure& closure) OVERRIDE {
110 gfx::Point p(aura::Env::GetInstance()->last_mouse_location());
111 UIControlsAura* ui_controls = GetUIControlsAt(p);
112 return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone(
113 type, state, closure);
116 virtual bool SendMouseClick(MouseButton type) OVERRIDE {
117 gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint());
118 UIControlsAura* ui_controls = GetUIControlsAt(p);
119 return ui_controls && ui_controls->SendMouseClick(type);
122 virtual void RunClosureAfterAllPendingUIEvents(
123 const base::Closure& closure) OVERRIDE {
124 UIControlsAura* ui_controls = GetUIControlsForRootWindow(
125 ash::Shell::GetTargetRootWindow());
126 if (ui_controls)
127 ui_controls->RunClosureAfterAllPendingUIEvents(closure);
130 private:
131 DISALLOW_COPY_AND_ASSIGN(UIControlsAsh);
134 ui_controls::UIControlsAura* CreateAshUIControls() {
135 return new ash::test::UIControlsAsh();
138 } // namespace test
139 } // namespace ash