This source file includes following definitions.
- DECLARE_WINDOW_PROPERTY_TYPE
- SendKeyPress
- SendKeyPressNotifyWhenDone
- SendMouseMove
- SendMouseMoveNotifyWhenDone
- SendMouseEvents
- SendMouseEventsNotifyWhenDone
- SendMouseClick
- RunClosureAfterAllPendingUIEvents
- CreateAshUIControls
#include "ash/shell.h"
#include "ash/shell_factory.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/window_properties.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/ui_controls_factory_aura.h"
#include "ui/aura/window_property.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/test/ui_controls.h"
#include "ui/base/test/ui_controls_aura.h"
#include "ui/gfx/screen.h"
DECLARE_WINDOW_PROPERTY_TYPE(ui_controls::UIControlsAura*)
namespace ash {
namespace test {
namespace {
using ui_controls::UIControlsAura;
using ui_controls::MouseButton;
DEFINE_OWNED_WINDOW_PROPERTY_KEY(UIControlsAura, kUIControlsKey, NULL);
UIControlsAura* GetUIControlsForRootWindow(aura::Window* root_window) {
UIControlsAura* native_ui_control =
root_window->GetProperty(kUIControlsKey);
if (!native_ui_control) {
native_ui_control =
aura::test::CreateUIControlsAura(root_window->GetHost());
root_window->SetProperty(kUIControlsKey, native_ui_control);
}
return native_ui_control;
}
UIControlsAura* GetUIControlsAt(const gfx::Point& point_in_screen) {
return GetUIControlsForRootWindow(ash::wm::GetRootWindowAt(point_in_screen));
}
}
class UIControlsAsh : public UIControlsAura {
public:
UIControlsAsh() {
}
virtual ~UIControlsAsh() {
}
virtual bool SendKeyPress(gfx::NativeWindow window,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
bool command) OVERRIDE {
return SendKeyPressNotifyWhenDone(
window, key, control, shift, alt, command, base::Closure());
}
virtual bool SendKeyPressNotifyWhenDone(
gfx::NativeWindow window,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
bool command,
const base::Closure& closure) OVERRIDE {
aura::Window* root =
window ? window->GetRootWindow() : ash::Shell::GetTargetRootWindow();
UIControlsAura* ui_controls = GetUIControlsForRootWindow(root);
return ui_controls && ui_controls->SendKeyPressNotifyWhenDone(
window, key, control, shift, alt, command, closure);
}
virtual bool SendMouseMove(long x, long y) OVERRIDE {
gfx::Point p(x, y);
UIControlsAura* ui_controls = GetUIControlsAt(p);
return ui_controls && ui_controls->SendMouseMove(p.x(), p.y());
}
virtual bool SendMouseMoveNotifyWhenDone(
long x,
long y,
const base::Closure& closure) OVERRIDE {
gfx::Point p(x, y);
UIControlsAura* ui_controls = GetUIControlsAt(p);
return ui_controls &&
ui_controls->SendMouseMoveNotifyWhenDone(p.x(), p.y(), closure);
}
virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE {
gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint());
UIControlsAura* ui_controls = GetUIControlsAt(p);
return ui_controls && ui_controls->SendMouseEvents(type, state);
}
virtual bool SendMouseEventsNotifyWhenDone(
MouseButton type, int state, const base::Closure& closure) OVERRIDE {
gfx::Point p(aura::Env::GetInstance()->last_mouse_location());
UIControlsAura* ui_controls = GetUIControlsAt(p);
return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone(
type, state, closure);
}
virtual bool SendMouseClick(MouseButton type) OVERRIDE {
gfx::Point p(ash::Shell::GetScreen()->GetCursorScreenPoint());
UIControlsAura* ui_controls = GetUIControlsAt(p);
return ui_controls && ui_controls->SendMouseClick(type);
}
virtual void RunClosureAfterAllPendingUIEvents(
const base::Closure& closure) OVERRIDE {
UIControlsAura* ui_controls = GetUIControlsForRootWindow(
ash::Shell::GetTargetRootWindow());
if (ui_controls)
ui_controls->RunClosureAfterAllPendingUIEvents(closure);
}
private:
DISALLOW_COPY_AND_ASSIGN(UIControlsAsh);
};
ui_controls::UIControlsAura* CreateAshUIControls() {
return new ash::test::UIControlsAsh();
}
}
}