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/public/input_manager.h" 6 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" 13 14 namespace athena { 15 namespace { 16 17 InputManager* instance = NULL; 18 19 class InputManagerImpl : public InputManager, 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 56 InputManagerImpl::InputManagerImpl() 57 : accelerator_manager_( 58 AcceleratorManagerImpl::CreateGlobalAcceleratorManager()) { 59 DCHECK(!instance); 60 instance = this; 61 } 62 63 InputManagerImpl::~InputManagerImpl() { 64 DCHECK_EQ(instance, this); 65 Shutdown(); 66 instance = NULL; 67 } 68 69 void InputManagerImpl::Init() { 70 accelerator_manager_->Init(); 71 } 72 73 void InputManagerImpl::Shutdown() { 74 accelerator_manager_.reset(); 75 } 76 77 void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) { 78 aura::client::SetEventClient(root_window, this); 79 accelerator_manager_->OnRootWindowCreated(root_window); 80 } 81 82 bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) { 83 return true; 84 } 85 86 ui::EventTarget* InputManagerImpl::GetParentTarget() { 87 return aura::Env::GetInstance(); 88 } 89 90 scoped_ptr<ui::EventTargetIterator> InputManagerImpl::GetChildIterator() const { 91 return scoped_ptr<ui::EventTargetIterator>(); 92 } 93 94 ui::EventTargeter* InputManagerImpl::GetEventTargeter() { 95 NOTREACHED(); 96 return NULL; 97 } 98 99 void InputManagerImpl::OnEvent(ui::Event* event) { 100 } 101 102 } // namespace 103 104 // static 105 InputManager* InputManager::Create() { 106 (new InputManagerImpl)->Init(); 107 DCHECK(instance); 108 return instance; 109 } 110 111 // static 112 InputManager* InputManager::Get() { 113 DCHECK(instance); 114 return instance; 115 } 116 117 // static 118 void InputManager::Shutdown() { 119 DCHECK(instance); 120 delete instance; 121 DCHECK(!instance); 122 } 123 124 } // namespace athena 125