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.
5 #include "athena/input/public/input_manager.h"
7 #include "athena/input/accelerator_manager_impl.h"
8 #include "base/logging.h"
9 #include "ui/aura/client/event_client.h"
10 #include "ui/aura/env.h"
11 #include "ui/aura/window.h"
12 #include "ui/events/event_target.h"
17 InputManager
* instance
= NULL
;
19 class InputManagerImpl
: public InputManager
,
20 public ui::EventTarget
,
21 public aura::client::EventClient
{
24 virtual ~InputManagerImpl();
31 virtual void OnRootWindowCreated(aura::Window
* root_window
) OVERRIDE
;
32 virtual ui::EventTarget
* GetTopmostEventTarget() OVERRIDE
{ return this; }
33 virtual AcceleratorManager
* GetAcceleratorManager() OVERRIDE
{
34 return accelerator_manager_
.get();
37 // Overridden from aura::client::EventClient:
38 virtual bool CanProcessEventsWithinSubtree(
39 const aura::Window
* window
) const OVERRIDE
{
40 return window
&& !window
->ignore_events();
42 virtual ui::EventTarget
* GetToplevelEventTarget() OVERRIDE
{ return this; }
45 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
46 virtual ui::EventTarget
* GetParentTarget() OVERRIDE
;
47 virtual scoped_ptr
<ui::EventTargetIterator
> GetChildIterator() const OVERRIDE
;
48 virtual ui::EventTargeter
* GetEventTargeter() OVERRIDE
;
49 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
51 scoped_ptr
<AcceleratorManagerImpl
> accelerator_manager_
;
53 DISALLOW_COPY_AND_ASSIGN(InputManagerImpl
);
56 InputManagerImpl::InputManagerImpl()
57 : accelerator_manager_(
58 AcceleratorManagerImpl::CreateGlobalAcceleratorManager()) {
63 InputManagerImpl::~InputManagerImpl() {
64 DCHECK_EQ(instance
, this);
69 void InputManagerImpl::Init() {
70 accelerator_manager_
->Init();
73 void InputManagerImpl::Shutdown() {
74 accelerator_manager_
.reset();
77 void InputManagerImpl::OnRootWindowCreated(aura::Window
* root_window
) {
78 aura::client::SetEventClient(root_window
, this);
79 accelerator_manager_
->OnRootWindowCreated(root_window
);
82 bool InputManagerImpl::CanAcceptEvent(const ui::Event
& event
) {
86 ui::EventTarget
* InputManagerImpl::GetParentTarget() {
87 return aura::Env::GetInstance();
90 scoped_ptr
<ui::EventTargetIterator
> InputManagerImpl::GetChildIterator() const {
91 return scoped_ptr
<ui::EventTargetIterator
>();
94 ui::EventTargeter
* InputManagerImpl::GetEventTargeter() {
99 void InputManagerImpl::OnEvent(ui::Event
* event
) {
105 InputManager
* InputManager::Create() {
106 (new InputManagerImpl
)->Init();
112 InputManager
* InputManager::Get() {
118 void InputManager::Shutdown() {
124 } // namespace athena