| 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/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/client/focus_client.h" | |
| 13 #include "ui/aura/env_observer.h" | 12 #include "ui/aura/env_observer.h" |
| 14 #include "ui/aura/input_state_lookup.h" | 13 #include "ui/aura/input_state_lookup.h" |
| 15 #include "ui/aura/mus/mus_types.h" | 14 #include "ui/aura/mus/mus_types.h" |
| 16 #include "ui/aura/mus/window_port_mus.h" | 15 #include "ui/aura/mus/window_port_mus.h" |
| 17 #include "ui/aura/mus/window_tree_client.h" | 16 #include "ui/aura/mus/window_tree_client.h" |
| 18 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_observer.h" | |
| 20 #include "ui/aura/window_port_local.h" | 18 #include "ui/aura/window_port_local.h" |
| 21 #include "ui/events/event_target_iterator.h" | 19 #include "ui/events/event_target_iterator.h" |
| 22 #include "ui/events/platform/platform_event_source.h" | 20 #include "ui/events/platform/platform_event_source.h" |
| 23 | 21 |
| 24 #if defined(USE_OZONE) | 22 #if defined(USE_OZONE) |
| 25 #include "ui/ozone/public/ozone_platform.h" | 23 #include "ui/ozone/public/ozone_platform.h" |
| 26 #endif | 24 #endif |
| 27 | 25 |
| 28 namespace aura { | 26 namespace aura { |
| 29 | 27 |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 // Env is thread local so that aura may be used on multiple threads. | 30 // Env is thread local so that aura may be used on multiple threads. |
| 33 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = | 31 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = |
| 34 LAZY_INSTANCE_INITIALIZER; | 32 LAZY_INSTANCE_INITIALIZER; |
| 35 | 33 |
| 36 // Returns true if running inside of mus. Checks for mojo specific flag. | 34 // Returns true if running inside of mus. Checks for mojo specific flag. |
| 37 bool RunningInsideMus() { | 35 bool RunningInsideMus() { |
| 38 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 36 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 39 "primordial-pipe-token"); | 37 "primordial-pipe-token"); |
| 40 } | 38 } |
| 41 | 39 |
| 42 } // namespace | 40 } // namespace |
| 43 | 41 |
| 44 // Observes destruction and changes of the FocusClient for a window. | |
| 45 // ActiveFocusClientWindowObserver is created for the window the FocusClient is | |
| 46 // associated with. | |
| 47 class Env::ActiveFocusClientWindowObserver : public WindowObserver { | |
| 48 public: | |
| 49 explicit ActiveFocusClientWindowObserver(Window* window) : window_(window) { | |
| 50 window_->AddObserver(this); | |
| 51 } | |
| 52 ~ActiveFocusClientWindowObserver() override { window_->RemoveObserver(this); } | |
| 53 | |
| 54 // WindowObserver: | |
| 55 void OnWindowDestroying(Window* window) override { | |
| 56 Env::GetInstance()->OnActiveFocusClientWindowDestroying(); | |
| 57 } | |
| 58 void OnWindowPropertyChanged(Window* window, | |
| 59 const void* key, | |
| 60 intptr_t old) override { | |
| 61 if (key != client::kFocusClientKey) | |
| 62 return; | |
| 63 | |
| 64 // Assume if the focus client changes the window is being destroyed. | |
| 65 Env::GetInstance()->OnActiveFocusClientWindowDestroying(); | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 Window* window_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(ActiveFocusClientWindowObserver); | |
| 72 }; | |
| 73 | |
| 74 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
| 75 // Env, public: | 43 // Env, public: |
| 76 | 44 |
| 77 Env::~Env() { | 45 Env::~Env() { |
| 78 for (EnvObserver& observer : observers_) | 46 for (EnvObserver& observer : observers_) |
| 79 observer.OnWillDestroyEnv(); | 47 observer.OnWillDestroyEnv(); |
| 80 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); | 48 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); |
| 81 lazy_tls_ptr.Pointer()->Set(NULL); | 49 lazy_tls_ptr.Pointer()->Set(NULL); |
| 82 } | 50 } |
| 83 | 51 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return last_mouse_location_; | 119 return last_mouse_location_; |
| 152 } | 120 } |
| 153 | 121 |
| 154 void Env::SetWindowTreeClient(WindowTreeClient* window_tree_client) { | 122 void Env::SetWindowTreeClient(WindowTreeClient* window_tree_client) { |
| 155 // The WindowTreeClient should only be set once. Test code may need to change | 123 // The WindowTreeClient should only be set once. Test code may need to change |
| 156 // the value after the fact, to do that use EnvTestHelper. | 124 // the value after the fact, to do that use EnvTestHelper. |
| 157 DCHECK(!window_tree_client_); | 125 DCHECK(!window_tree_client_); |
| 158 window_tree_client_ = window_tree_client; | 126 window_tree_client_ = window_tree_client; |
| 159 } | 127 } |
| 160 | 128 |
| 161 void Env::SetActiveFocusClient(client::FocusClient* focus_client, | |
| 162 Window* focus_client_root) { | |
| 163 if (focus_client == active_focus_client_ && | |
| 164 focus_client_root == active_focus_client_root_) { | |
| 165 return; | |
| 166 } | |
| 167 | |
| 168 active_focus_client_window_observer_.reset(); | |
| 169 active_focus_client_ = focus_client; | |
| 170 active_focus_client_root_ = focus_client_root; | |
| 171 if (focus_client_root) { | |
| 172 active_focus_client_window_observer_ = | |
| 173 base::MakeUnique<ActiveFocusClientWindowObserver>(focus_client_root); | |
| 174 } | |
| 175 for (EnvObserver& observer : observers_) | |
| 176 observer.OnActiveFocusClientChanged(focus_client, focus_client_root); | |
| 177 } | |
| 178 | |
| 179 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
| 180 // Env, private: | 130 // Env, private: |
| 181 | 131 |
| 182 Env::Env(Mode mode) | 132 Env::Env(Mode mode) |
| 183 : mode_(mode), | 133 : mode_(mode), |
| 184 mouse_button_flags_(0), | 134 mouse_button_flags_(0), |
| 185 is_touch_down_(false), | 135 is_touch_down_(false), |
| 186 get_last_mouse_location_from_mus_(mode_ == Mode::MUS), | 136 get_last_mouse_location_from_mus_(mode_ == Mode::MUS), |
| 187 input_state_lookup_(InputStateLookup::Create()), | 137 input_state_lookup_(InputStateLookup::Create()), |
| 188 context_factory_(nullptr), | 138 context_factory_(nullptr), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 212 void Env::NotifyHostInitialized(WindowTreeHost* host) { | 162 void Env::NotifyHostInitialized(WindowTreeHost* host) { |
| 213 for (EnvObserver& observer : observers_) | 163 for (EnvObserver& observer : observers_) |
| 214 observer.OnHostInitialized(host); | 164 observer.OnHostInitialized(host); |
| 215 } | 165 } |
| 216 | 166 |
| 217 void Env::NotifyHostActivated(WindowTreeHost* host) { | 167 void Env::NotifyHostActivated(WindowTreeHost* host) { |
| 218 for (EnvObserver& observer : observers_) | 168 for (EnvObserver& observer : observers_) |
| 219 observer.OnHostActivated(host); | 169 observer.OnHostActivated(host); |
| 220 } | 170 } |
| 221 | 171 |
| 222 void Env::OnActiveFocusClientWindowDestroying() { | |
| 223 SetActiveFocusClient(nullptr, nullptr); | |
| 224 } | |
| 225 | |
| 226 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
| 227 // Env, ui::EventTarget implementation: | 173 // Env, ui::EventTarget implementation: |
| 228 | 174 |
| 229 bool Env::CanAcceptEvent(const ui::Event& event) { | 175 bool Env::CanAcceptEvent(const ui::Event& event) { |
| 230 return true; | 176 return true; |
| 231 } | 177 } |
| 232 | 178 |
| 233 ui::EventTarget* Env::GetParentTarget() { | 179 ui::EventTarget* Env::GetParentTarget() { |
| 234 return NULL; | 180 return NULL; |
| 235 } | 181 } |
| 236 | 182 |
| 237 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { | 183 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { |
| 238 return nullptr; | 184 return nullptr; |
| 239 } | 185 } |
| 240 | 186 |
| 241 ui::EventTargeter* Env::GetEventTargeter() { | 187 ui::EventTargeter* Env::GetEventTargeter() { |
| 242 NOTREACHED(); | 188 NOTREACHED(); |
| 243 return NULL; | 189 return NULL; |
| 244 } | 190 } |
| 245 | 191 |
| 246 } // namespace aura | 192 } // namespace aura |
| OLD | NEW |