OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ui/aura/env.h" | 5 #include "ui/aura/env.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
11 #include "ui/aura/client/focus_client.h" | 11 #include "ui/aura/client/focus_client.h" |
12 #include "ui/aura/env_observer.h" | 12 #include "ui/aura/env_observer.h" |
13 #include "ui/aura/input_state_lookup.h" | 13 #include "ui/aura/input_state_lookup.h" |
14 #include "ui/aura/mus/window_port_mus.h" | 14 #include "ui/aura/mus/window_port_mus.h" |
15 #include "ui/aura/mus/window_tree_client.h" | 15 #include "ui/aura/mus/window_tree_client.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
18 #include "ui/aura/window_port_local.h" | 18 #include "ui/aura/window_port_local.h" |
19 #include "ui/events/event_target_iterator.h" | 19 #include "ui/events/event_target_iterator.h" |
20 #include "ui/events/platform/platform_event_source.h" | 20 #include "ui/events/platform/platform_event_source.h" |
| 21 #include "ui/gfx/switches.h" |
21 | 22 |
22 #if defined(USE_OZONE) | 23 #if defined(USE_OZONE) |
23 #include "ui/ozone/public/ozone_platform.h" | 24 #include "ui/ozone/public/ozone_platform.h" |
24 #endif | 25 #endif |
25 | 26 |
26 namespace aura { | 27 namespace aura { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Env is thread local so that aura may be used on multiple threads. | 31 // Env is thread local so that aura may be used on multiple threads. |
31 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = | 32 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = |
32 LAZY_INSTANCE_INITIALIZER; | 33 LAZY_INSTANCE_INITIALIZER; |
33 | 34 |
34 // Returns true if running inside of mus. Checks for mojo specific flag. | 35 // Returns true if running inside of mus. Checks for mojo specific flag. |
35 bool RunningInsideMus() { | 36 bool RunningInsideMus() { |
36 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 37 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
37 "primordial-pipe-token"); | 38 "primordial-pipe-token"); |
38 } | 39 } |
39 | 40 |
| 41 bool RunningInHeadlessMode() { |
| 42 return base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless); |
| 43 } |
| 44 |
40 } // namespace | 45 } // namespace |
41 | 46 |
42 // Observes destruction and changes of the FocusClient for a window. | 47 // Observes destruction and changes of the FocusClient for a window. |
43 // ActiveFocusClientWindowObserver is created for the window the FocusClient is | 48 // ActiveFocusClientWindowObserver is created for the window the FocusClient is |
44 // associated with. | 49 // associated with. |
45 class Env::ActiveFocusClientWindowObserver : public WindowObserver { | 50 class Env::ActiveFocusClientWindowObserver : public WindowObserver { |
46 public: | 51 public: |
47 explicit ActiveFocusClientWindowObserver(Window* window) : window_(window) { | 52 explicit ActiveFocusClientWindowObserver(Window* window) : window_(window) { |
48 window_->AddObserver(this); | 53 window_->AddObserver(this); |
49 } | 54 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 : mode_(mode), | 160 : mode_(mode), |
156 mouse_button_flags_(0), | 161 mouse_button_flags_(0), |
157 is_touch_down_(false), | 162 is_touch_down_(false), |
158 input_state_lookup_(InputStateLookup::Create()), | 163 input_state_lookup_(InputStateLookup::Create()), |
159 context_factory_(NULL) { | 164 context_factory_(NULL) { |
160 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); | 165 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); |
161 lazy_tls_ptr.Pointer()->Set(this); | 166 lazy_tls_ptr.Pointer()->Set(this); |
162 } | 167 } |
163 | 168 |
164 void Env::Init() { | 169 void Env::Init() { |
165 if (RunningInsideMus()) | 170 if (RunningInsideMus() || RunningInHeadlessMode()) |
166 return; | 171 return; |
167 #if defined(USE_OZONE) | 172 #if defined(USE_OZONE) |
168 // The ozone platform can provide its own event source. So initialize the | 173 // The ozone platform can provide its own event source. So initialize the |
169 // platform before creating the default event source. If running inside mus | 174 // platform before creating the default event source. If running inside mus |
170 // let the mus process initialize ozone instead. | 175 // let the mus process initialize ozone instead. |
171 ui::OzonePlatform::InitializeForUI(); | 176 ui::OzonePlatform::InitializeForUI(); |
172 #endif | 177 #endif |
173 if (!ui::PlatformEventSource::GetInstance()) | 178 if (!ui::PlatformEventSource::GetInstance()) |
174 event_source_ = ui::PlatformEventSource::CreateDefault(); | 179 event_source_ = ui::PlatformEventSource::CreateDefault(); |
175 } | 180 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { | 212 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { |
208 return nullptr; | 213 return nullptr; |
209 } | 214 } |
210 | 215 |
211 ui::EventTargeter* Env::GetEventTargeter() { | 216 ui::EventTargeter* Env::GetEventTargeter() { |
212 NOTREACHED(); | 217 NOTREACHED(); |
213 return NULL; | 218 return NULL; |
214 } | 219 } |
215 | 220 |
216 } // namespace aura | 221 } // namespace aura |
OLD | NEW |