1 // Copyright (c) 2012 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.
5 #include "ui/aura/env.h"
7 #include "base/command_line.h"
8 #include "base/message_loop/message_pump_dispatcher.h"
9 #include "ui/aura/env_observer.h"
10 #include "ui/aura/input_state_lookup.h"
11 #include "ui/aura/window.h"
12 #include "ui/compositor/compositor.h"
13 #include "ui/compositor/compositor_switches.h"
14 #include "ui/events/event_target_iterator.h"
17 #include "base/message_loop/message_pump_x11.h"
23 Env
* Env::instance_
= NULL
;
25 ////////////////////////////////////////////////////////////////////////////////
29 : mouse_button_flags_(0),
30 is_touch_down_(false),
31 input_state_lookup_(InputStateLookup::Create().Pass()) {
36 base::MessagePumpX11::Current()->RemoveObserver(
37 &device_list_updater_aurax11_
);
40 FOR_EACH_OBSERVER(EnvObserver
, observers_
, OnWillDestroyEnv());
42 ui::Compositor::Terminate();
46 void Env::CreateInstance() {
54 Env
* Env::GetInstance() {
55 DCHECK(instance_
) << "Env::CreateInstance must be called before getting "
56 "the instance of Env.";
61 void Env::DeleteInstance() {
66 void Env::AddObserver(EnvObserver
* observer
) {
67 observers_
.AddObserver(observer
);
70 void Env::RemoveObserver(EnvObserver
* observer
) {
71 observers_
.RemoveObserver(observer
);
74 bool Env::IsMouseButtonDown() const {
75 return input_state_lookup_
.get() ? input_state_lookup_
->IsMouseButtonDown() :
76 mouse_button_flags_
!= 0;
79 ////////////////////////////////////////////////////////////////////////////////
84 // We can't do this with a root window listener because XI_HierarchyChanged
85 // messages don't have a target window.
86 base::MessagePumpX11::Current()->AddObserver(
87 &device_list_updater_aurax11_
);
89 ui::Compositor::Initialize();
92 void Env::NotifyWindowInitialized(Window
* window
) {
93 FOR_EACH_OBSERVER(EnvObserver
, observers_
, OnWindowInitialized(window
));
96 void Env::NotifyHostInitialized(WindowTreeHost
* host
) {
97 FOR_EACH_OBSERVER(EnvObserver
, observers_
, OnHostInitialized(host
));
100 void Env::NotifyHostActivated(WindowTreeHost
* host
) {
101 FOR_EACH_OBSERVER(EnvObserver
, observers_
, OnHostActivated(host
));
104 ////////////////////////////////////////////////////////////////////////////////
105 // Env, ui::EventTarget implementation:
107 bool Env::CanAcceptEvent(const ui::Event
& event
) {
111 ui::EventTarget
* Env::GetParentTarget() {
115 scoped_ptr
<ui::EventTargetIterator
> Env::GetChildIterator() const {
116 return scoped_ptr
<ui::EventTargetIterator
>();
119 ui::EventTargeter
* Env::GetEventTargeter() {