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