Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: athena/input/input_manager_impl.cc

Issue 659923002: Revert of Intorduce PowerButtonObserver API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/input/input_manager_impl.h ('k') | athena/input/input_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/input_manager_impl.h" 5 #include "athena/input/public/input_manager.h"
6 6
7 #include "athena/input/power_button_controller.h" 7 #include "athena/input/accelerator_manager_impl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "ui/aura/client/event_client.h"
9 #include "ui/aura/env.h" 10 #include "ui/aura/env.h"
10 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/events/event_target.h"
11 13
12 namespace athena { 14 namespace athena {
13 namespace { 15 namespace {
14 16
15 InputManager* instance = NULL; 17 InputManager* instance = NULL;
16 18
17 } // namespace 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 };
18 55
19 InputManagerImpl::InputManagerImpl() 56 InputManagerImpl::InputManagerImpl()
20 : accelerator_manager_( 57 : accelerator_manager_(
21 AcceleratorManagerImpl::CreateGlobalAcceleratorManager()), 58 AcceleratorManagerImpl::CreateGlobalAcceleratorManager()) {
22 power_button_controller_(new PowerButtonController) {
23 DCHECK(!instance); 59 DCHECK(!instance);
24 instance = this; 60 instance = this;
25 } 61 }
26 62
27 InputManagerImpl::~InputManagerImpl() { 63 InputManagerImpl::~InputManagerImpl() {
28 DCHECK_EQ(instance, this); 64 DCHECK_EQ(instance, this);
29 Shutdown(); 65 Shutdown();
30 instance = NULL; 66 instance = NULL;
31 } 67 }
32 68
33 void InputManagerImpl::Init() { 69 void InputManagerImpl::Init() {
34 accelerator_manager_->Init(); 70 accelerator_manager_->Init();
35 power_button_controller_->InstallAccelerators();
36 } 71 }
37 72
38 void InputManagerImpl::Shutdown() { 73 void InputManagerImpl::Shutdown() {
39 accelerator_manager_.reset(); 74 accelerator_manager_.reset();
40 } 75 }
41 76
42 void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) { 77 void InputManagerImpl::OnRootWindowCreated(aura::Window* root_window) {
43 aura::client::SetEventClient(root_window, this); 78 aura::client::SetEventClient(root_window, this);
44 accelerator_manager_->OnRootWindowCreated(root_window); 79 accelerator_manager_->OnRootWindowCreated(root_window);
45 } 80 }
46 81
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) { 82 bool InputManagerImpl::CanAcceptEvent(const ui::Event& event) {
73 return true; 83 return true;
74 } 84 }
75 85
76 ui::EventTarget* InputManagerImpl::GetParentTarget() { 86 ui::EventTarget* InputManagerImpl::GetParentTarget() {
77 return aura::Env::GetInstance(); 87 return aura::Env::GetInstance();
78 } 88 }
79 89
80 scoped_ptr<ui::EventTargetIterator> InputManagerImpl::GetChildIterator() const { 90 scoped_ptr<ui::EventTargetIterator> InputManagerImpl::GetChildIterator() const {
81 return scoped_ptr<ui::EventTargetIterator>(); 91 return scoped_ptr<ui::EventTargetIterator>();
82 } 92 }
83 93
84 ui::EventTargeter* InputManagerImpl::GetEventTargeter() { 94 ui::EventTargeter* InputManagerImpl::GetEventTargeter() {
85 NOTREACHED(); 95 NOTREACHED();
86 return NULL; 96 return NULL;
87 } 97 }
88 98
89 void InputManagerImpl::OnEvent(ui::Event* event) { 99 void InputManagerImpl::OnEvent(ui::Event* event) {
90 } 100 }
91 101
92 int InputManagerImpl::SetPowerButtonTimeoutMsForTest(int timeout) { 102 } // namespace
93 return power_button_controller_->SetPowerButtonTimeoutMsForTest(timeout);
94 }
95 103
96 // static 104 // static
97 InputManager* InputManager::Create() { 105 InputManager* InputManager::Create() {
98 (new InputManagerImpl)->Init(); 106 (new InputManagerImpl)->Init();
99 DCHECK(instance); 107 DCHECK(instance);
100 return instance; 108 return instance;
101 } 109 }
102 110
103 // static 111 // static
104 InputManager* InputManager::Get() { 112 InputManager* InputManager::Get() {
105 DCHECK(instance); 113 DCHECK(instance);
106 return instance; 114 return instance;
107 } 115 }
108 116
109 // static 117 // static
110 void InputManager::Shutdown() { 118 void InputManager::Shutdown() {
111 DCHECK(instance); 119 DCHECK(instance);
112 delete instance; 120 delete instance;
113 DCHECK(!instance); 121 DCHECK(!instance);
114 } 122 }
115 123
116 } // namespace athena 124 } // namespace athena
OLDNEW
« no previous file with comments | « athena/input/input_manager_impl.h ('k') | athena/input/input_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698