OLD | NEW |
(Empty) | |
| 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 #include "ash/shell.h" |
| 6 #include "ash/shell_factory.h" |
| 7 #include "ash/wm/window_properties.h" |
| 8 #include "ui/aura/root_window.h" |
| 9 #include "ui/aura/ui_controls_aura.h" |
| 10 #include "ui/gfx/screen.h" |
| 11 #include "ui/ui_controls/ui_controls_aura.h" |
| 12 |
| 13 namespace ash { |
| 14 namespace internal { |
| 15 namespace { |
| 16 |
| 17 // Returns the UIControls object for RootWindow. |
| 18 // kUIControlsKey is owned property and UIControls object |
| 19 // will be deleted when the root window is deleted. |
| 20 ui_controls::UIControlsAura* GetUIControlsForRootWindow( |
| 21 aura::RootWindow* root_window) { |
| 22 ui_controls::UIControlsAura* native_ui_control = |
| 23 root_window->GetProperty(kUIControlsKey); |
| 24 if (!native_ui_control) { |
| 25 native_ui_control = aura::CreateUIControlsAura(root_window); |
| 26 // Pass the ownership to the |root_window|. |
| 27 root_window->SetProperty(kUIControlsKey, native_ui_control); |
| 28 } |
| 29 return native_ui_control; |
| 30 } |
| 31 |
| 32 // Returns the UIControls object for the RootWindow at the |point| in |
| 33 // absolute screen coordinates. NULL if there is no RootWindow under the |
| 34 // |point|. |
| 35 ui_controls::UIControlsAura* GetUIControlsAt(const gfx::Point& point) { |
| 36 aura::RootWindow* root = Shell::GetRootWindowAt(point); |
| 37 return root ? GetUIControlsForRootWindow(root) : NULL; |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 |
| 42 class UIControlsAsh : public ui_controls::UIControlsAura { |
| 43 public: |
| 44 UIControlsAsh() { |
| 45 } |
| 46 virtual ~UIControlsAsh() { |
| 47 } |
| 48 |
| 49 // ui_controls::UIControslAura overrides: |
| 50 virtual bool SendKeyPress(gfx::NativeWindow window, |
| 51 ui::KeyboardCode key, |
| 52 bool control, |
| 53 bool shift, |
| 54 bool alt, |
| 55 bool command) OVERRIDE { |
| 56 return SendKeyPressNotifyWhenDone( |
| 57 window, key, control, shift, alt, command, base::Closure()); |
| 58 } |
| 59 |
| 60 virtual bool SendKeyPressNotifyWhenDone( |
| 61 gfx::NativeWindow window, |
| 62 ui::KeyboardCode key, |
| 63 bool control, |
| 64 bool shift, |
| 65 bool alt, |
| 66 bool command, |
| 67 const base::Closure& closure) OVERRIDE { |
| 68 aura::RootWindow* root = |
| 69 window ? window->GetRootWindow() : Shell::GetActiveRootWindow(); |
| 70 ui_controls::UIControlsAura* ui_controls = GetUIControlsForRootWindow(root); |
| 71 return ui_controls && ui_controls->SendKeyPressNotifyWhenDone( |
| 72 window, key, control, shift, alt, command, closure); |
| 73 } |
| 74 |
| 75 virtual bool SendMouseMove(long x, long y) OVERRIDE { |
| 76 ui_controls::UIControlsAura* ui_controls = |
| 77 GetUIControlsAt(gfx::Point(x, y)); |
| 78 return ui_controls && ui_controls->SendMouseMove(x, y); |
| 79 } |
| 80 |
| 81 virtual bool SendMouseMoveNotifyWhenDone( |
| 82 long x, |
| 83 long y, |
| 84 const base::Closure& closure) OVERRIDE { |
| 85 ui_controls::UIControlsAura* ui_controls = |
| 86 GetUIControlsAt(gfx::Point(x, y)); |
| 87 return ui_controls && |
| 88 ui_controls->SendMouseMoveNotifyWhenDone(x, y, closure); |
| 89 } |
| 90 |
| 91 virtual bool SendMouseEvents(ui_controls::MouseButton type, |
| 92 int state) OVERRIDE { |
| 93 ui_controls::UIControlsAura* ui_controls = |
| 94 GetUIControlsAt(gfx::Screen::GetCursorScreenPoint()); |
| 95 return ui_controls && ui_controls->SendMouseEvents(type, state); |
| 96 } |
| 97 |
| 98 virtual bool SendMouseEventsNotifyWhenDone( |
| 99 ui_controls::MouseButton type, |
| 100 int state, |
| 101 const base::Closure& closure) OVERRIDE { |
| 102 ui_controls::UIControlsAura* ui_controls = |
| 103 GetUIControlsAt(gfx::Screen::GetCursorScreenPoint()); |
| 104 return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone( |
| 105 type, state, closure); |
| 106 } |
| 107 |
| 108 virtual bool SendMouseClick(ui_controls::MouseButton type) OVERRIDE { |
| 109 ui_controls::UIControlsAura* ui_controls = |
| 110 GetUIControlsAt(gfx::Screen::GetCursorScreenPoint()); |
| 111 return ui_controls && ui_controls->SendMouseClick(type); |
| 112 } |
| 113 |
| 114 virtual void RunClosureAfterAllPendingUIEvents( |
| 115 const base::Closure& closure) OVERRIDE { |
| 116 ui_controls::UIControlsAura* ui_controls = GetUIControlsForRootWindow( |
| 117 Shell::GetActiveRootWindow()); |
| 118 if (ui_controls) |
| 119 ui_controls->RunClosureAfterAllPendingUIEvents(closure); |
| 120 } |
| 121 |
| 122 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(UIControlsAsh); |
| 124 }; |
| 125 |
| 126 ui_controls::UIControlsAura* CreateUIControls() { |
| 127 return new UIControlsAsh(); |
| 128 } |
| 129 |
| 130 } // namespace internal |
| 131 } // namespace ash |
OLD | NEW |