| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "athena/input/public/input_manager.h" | 5 #include "athena/input/input_manager_impl.h" |
| 6 | 6 |
| 7 #include "athena/input/accelerator_manager_impl.h" | 7 #include "athena/input/power_button_controller.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/aura/client/event_client.h" | |
| 10 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
| 11 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 12 #include "ui/events/event_target.h" | |
| 13 | 11 |
| 14 namespace athena { | 12 namespace athena { |
| 15 namespace { | 13 namespace { |
| 16 | 14 |
| 17 InputManager* instance = NULL; | 15 InputManager* instance = NULL; |
| 18 | 16 |
| 19 class InputManagerImpl : public InputManager, | 17 } // namespace |
| 20 public ui::EventTarget, | |
| 21 public aura::client::EventClient { | |
| 22 public: | |
| 23 InputManagerImpl(); | |
| 24 virtual ~InputManagerImpl(); | |
| 25 | |
| 26 void Init(); | |
| 27 void Shutdown(); | |
| 28 | |
| 29 private: | |
| 30 // InputManager: | |
| 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(); | |
| 35 } | |
| 36 | |
| 37 // Overridden from aura::client::EventClient: | |
| 38 virtual bool CanProcessEventsWithinSubtree( | |
| 39 const aura::Window* window) const override { | |
| 40 return window && !window->ignore_events(); | |
| 41 } | |
| 42 virtual ui::EventTarget* GetToplevelEventTarget() override { return this; } | |
| 43 | |
| 44 // ui::EventTarget: | |
| 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; | |
| 50 | |
| 51 scoped_ptr<AcceleratorManagerImpl> accelerator_manager_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(InputManagerImpl); | |
| 54 }; | |
| 55 | 18 |
| 56 InputManagerImpl::InputManagerImpl() | 19 InputManagerImpl::InputManagerImpl() |
| 57 : accelerator_manager_( | 20 : accelerator_manager_( |
| 58 AcceleratorManagerImpl::CreateGlobalAcceleratorManager()) { | 21 AcceleratorManagerImpl::CreateGlobalAcceleratorManager()), |
| 22 power_button_controller_(new PowerButtonController) { |
| 59 DCHECK(!instance); | 23 DCHECK(!instance); |
| 60 instance = this; | 24 instance = this; |
| 61 } | 25 } |
| 62 | 26 |
| 63 InputManagerImpl::~InputManagerImpl() { | 27 InputManagerImpl::~InputManagerImpl() { |
| 64 DCHECK_EQ(instance, this); | 28 DCHECK_EQ(instance, this); |
| 65 Shutdown(); | 29 Shutdown(); |
| 66 instance = NULL; | 30 instance = NULL; |
| 67 } | 31 } |
| 68 | 32 |
| 69 void InputManagerImpl::Init() { | 33 void InputManagerImpl::Init() { |
| 70 accelerator_manager_->Init(); | 34 accelerator_manager_->Init(); |
| 35 power_button_controller_->InstallAccelerators(); |
| 71 } | 36 } |
| 72 | 37 |
| 73 void InputManagerImpl::Shutdown() { | 38 void InputManagerImpl::Shutdown() { |
| 74 accelerator_manager_.reset(); | 39 accelerator_manager_.reset(); |
| 75 } | 40 } |
| 76 | 41 |
| 77 void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) { | 42 void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) { |
| 78 aura::client::SetEventClient(root_window, this); | 43 aura::client::SetEventClient(root_window, this); |
| 79 accelerator_manager_->OnRootWindowCreated(root_window); | 44 accelerator_manager_->OnRootWindowCreated(root_window); |
| 80 } | 45 } |
| 81 | 46 |
| 47 ui::EventTarget* InputManagerImpl::GetTopmostEventTarget() { |
| 48 return this; |
| 49 } |
| 50 |
| 51 AcceleratorManager* InputManagerImpl::GetAcceleratorManager() { |
| 52 return accelerator_manager_.get(); |
| 53 } |
| 54 |
| 55 void InputManagerImpl::AddPowerButtonObserver(PowerButtonObserver* observer) { |
| 56 power_button_controller_->AddPowerButtonObserver(observer); |
| 57 } |
| 58 void InputManagerImpl::RemovePowerButtonObserver( |
| 59 PowerButtonObserver* observer) { |
| 60 power_button_controller_->RemovePowerButtonObserver(observer); |
| 61 } |
| 62 |
| 63 bool InputManagerImpl::CanProcessEventsWithinSubtree( |
| 64 const aura::Window* window) const { |
| 65 return window && !window->ignore_events(); |
| 66 } |
| 67 |
| 68 ui::EventTarget* InputManagerImpl::GetToplevelEventTarget() { |
| 69 return this; |
| 70 } |
| 71 |
| 82 bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) { | 72 bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) { |
| 83 return true; | 73 return true; |
| 84 } | 74 } |
| 85 | 75 |
| 86 ui::EventTarget* InputManagerImpl::GetParentTarget() { | 76 ui::EventTarget* InputManagerImpl::GetParentTarget() { |
| 87 return aura::Env::GetInstance(); | 77 return aura::Env::GetInstance(); |
| 88 } | 78 } |
| 89 | 79 |
| 90 scoped_ptr<ui::EventTargetIterator> InputManagerImpl::GetChildIterator() const { | 80 scoped_ptr<ui::EventTargetIterator> InputManagerImpl::GetChildIterator() const { |
| 91 return scoped_ptr<ui::EventTargetIterator>(); | 81 return scoped_ptr<ui::EventTargetIterator>(); |
| 92 } | 82 } |
| 93 | 83 |
| 94 ui::EventTargeter* InputManagerImpl::GetEventTargeter() { | 84 ui::EventTargeter* InputManagerImpl::GetEventTargeter() { |
| 95 NOTREACHED(); | 85 NOTREACHED(); |
| 96 return NULL; | 86 return NULL; |
| 97 } | 87 } |
| 98 | 88 |
| 99 void InputManagerImpl::OnEvent(ui::Event* event) { | 89 void InputManagerImpl::OnEvent(ui::Event* event) { |
| 100 } | 90 } |
| 101 | 91 |
| 102 } // namespace | 92 int InputManagerImpl::SetPowerButtonTimeoutMsForTest(int timeout) { |
| 93 return power_button_controller_->SetPowerButtonTimeoutMsForTest(timeout); |
| 94 } |
| 103 | 95 |
| 104 // static | 96 // static |
| 105 InputManager* InputManager::Create() { | 97 InputManager* InputManager::Create() { |
| 106 (new InputManagerImpl)->Init(); | 98 (new InputManagerImpl)->Init(); |
| 107 DCHECK(instance); | 99 DCHECK(instance); |
| 108 return instance; | 100 return instance; |
| 109 } | 101 } |
| 110 | 102 |
| 111 // static | 103 // static |
| 112 InputManager* InputManager::Get() { | 104 InputManager* InputManager::Get() { |
| 113 DCHECK(instance); | 105 DCHECK(instance); |
| 114 return instance; | 106 return instance; |
| 115 } | 107 } |
| 116 | 108 |
| 117 // static | 109 // static |
| 118 void InputManager::Shutdown() { | 110 void InputManager::Shutdown() { |
| 119 DCHECK(instance); | 111 DCHECK(instance); |
| 120 delete instance; | 112 delete instance; |
| 121 DCHECK(!instance); | 113 DCHECK(!instance); |
| 122 } | 114 } |
| 123 | 115 |
| 124 } // namespace athena | 116 } // namespace athena |
| OLD | NEW |