| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "athena/input/input_manager_impl.h" | |
| 6 | |
| 7 #include "athena/input/power_button_controller.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "ui/aura/env.h" | |
| 10 #include "ui/aura/window.h" | |
| 11 | |
| 12 namespace athena { | |
| 13 namespace { | |
| 14 | |
| 15 InputManager* instance = nullptr; | |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 InputManagerImpl::InputManagerImpl() | |
| 20 : accelerator_manager_( | |
| 21 AcceleratorManagerImpl::CreateGlobalAcceleratorManager()), | |
| 22 power_button_controller_(new PowerButtonController) { | |
| 23 DCHECK(!instance); | |
| 24 instance = this; | |
| 25 } | |
| 26 | |
| 27 InputManagerImpl::~InputManagerImpl() { | |
| 28 DCHECK_EQ(instance, this); | |
| 29 Shutdown(); | |
| 30 instance = nullptr; | |
| 31 } | |
| 32 | |
| 33 void InputManagerImpl::Init() { | |
| 34 accelerator_manager_->Init(); | |
| 35 power_button_controller_->InstallAccelerators(); | |
| 36 } | |
| 37 | |
| 38 void InputManagerImpl::Shutdown() { | |
| 39 accelerator_manager_.reset(); | |
| 40 } | |
| 41 | |
| 42 void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) { | |
| 43 aura::client::SetEventClient(root_window, this); | |
| 44 accelerator_manager_->OnRootWindowCreated(root_window); | |
| 45 } | |
| 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 | |
| 72 bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) { | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 ui::EventTarget* InputManagerImpl::GetParentTarget() { | |
| 77 return aura::Env::GetInstance(); | |
| 78 } | |
| 79 | |
| 80 scoped_ptr<ui::EventTargetIterator> InputManagerImpl::GetChildIterator() const { | |
| 81 return scoped_ptr<ui::EventTargetIterator>(); | |
| 82 } | |
| 83 | |
| 84 ui::EventTargeter* InputManagerImpl::GetEventTargeter() { | |
| 85 NOTREACHED(); | |
| 86 return nullptr; | |
| 87 } | |
| 88 | |
| 89 void InputManagerImpl::OnEvent(ui::Event* event) { | |
| 90 } | |
| 91 | |
| 92 int InputManagerImpl::SetPowerButtonTimeoutMsForTest(int timeout) { | |
| 93 return power_button_controller_->SetPowerButtonTimeoutMsForTest(timeout); | |
| 94 } | |
| 95 | |
| 96 // static | |
| 97 InputManager* InputManager::Create() { | |
| 98 (new InputManagerImpl)->Init(); | |
| 99 DCHECK(instance); | |
| 100 return instance; | |
| 101 } | |
| 102 | |
| 103 // static | |
| 104 InputManager* InputManager::Get() { | |
| 105 DCHECK(instance); | |
| 106 return instance; | |
| 107 } | |
| 108 | |
| 109 // static | |
| 110 void InputManager::Shutdown() { | |
| 111 DCHECK(instance); | |
| 112 delete instance; | |
| 113 DCHECK(!instance); | |
| 114 } | |
| 115 | |
| 116 } // namespace athena | |
| OLD | NEW |