| 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/env_observer.h" | 12 #include "ui/aura/env_observer.h" |
| 12 #include "ui/aura/input_state_lookup.h" | 13 #include "ui/aura/input_state_lookup.h" |
| 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_observer.h" |
| 13 #include "ui/aura/window_port_local.h" | 16 #include "ui/aura/window_port_local.h" |
| 14 #include "ui/events/event_target_iterator.h" | 17 #include "ui/events/event_target_iterator.h" |
| 15 #include "ui/events/platform/platform_event_source.h" | 18 #include "ui/events/platform/platform_event_source.h" |
| 16 | 19 |
| 17 #if defined(USE_OZONE) | 20 #if defined(USE_OZONE) |
| 18 #include "ui/ozone/public/ozone_platform.h" | 21 #include "ui/ozone/public/ozone_platform.h" |
| 19 #endif | 22 #endif |
| 20 | 23 |
| 21 namespace aura { | 24 namespace aura { |
| 22 | 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 // Env is thread local so that aura may be used on multiple threads. | 28 // Env is thread local so that aura may be used on multiple threads. |
| 26 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = | 29 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = |
| 27 LAZY_INSTANCE_INITIALIZER; | 30 LAZY_INSTANCE_INITIALIZER; |
| 28 | 31 |
| 29 // Returns true if running inside of mus. Checks for mojo specific flag. | 32 // Returns true if running inside of mus. Checks for mojo specific flag. |
| 30 bool RunningInsideMus() { | 33 bool RunningInsideMus() { |
| 31 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 34 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 32 "primordial-pipe-token"); | 35 "primordial-pipe-token"); |
| 33 } | 36 } |
| 34 | 37 |
| 35 } // namespace | 38 } // namespace |
| 36 | 39 |
| 40 // Observes destruction and changes of the FocusClient for a window. |
| 41 // ActiveFocusClientWindowObserver is created for the window the FocusClient is |
| 42 // associated with. |
| 43 class Env::ActiveFocusClientWindowObserver : public WindowObserver { |
| 44 public: |
| 45 explicit ActiveFocusClientWindowObserver(Window* window) : window_(window) { |
| 46 window_->AddObserver(this); |
| 47 } |
| 48 ~ActiveFocusClientWindowObserver() override { window_->RemoveObserver(this); } |
| 49 |
| 50 // WindowObserver: |
| 51 void OnWindowDestroying(Window* window) override { |
| 52 Env::GetInstance()->OnActiveFocusClientWindowDestroying(); |
| 53 } |
| 54 void OnWindowPropertyChanged(Window* window, |
| 55 const void* key, |
| 56 intptr_t old) override { |
| 57 if (key != client::kFocusClientKey) |
| 58 return; |
| 59 |
| 60 // Assume if the focus client changes the window is being destroyed. |
| 61 Env::GetInstance()->OnActiveFocusClientWindowDestroying(); |
| 62 } |
| 63 |
| 64 private: |
| 65 Window* window_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(ActiveFocusClientWindowObserver); |
| 68 }; |
| 69 |
| 37 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
| 38 // Env, public: | 71 // Env, public: |
| 39 | 72 |
| 40 Env::~Env() { | 73 Env::~Env() { |
| 41 for (EnvObserver& observer : observers_) | 74 for (EnvObserver& observer : observers_) |
| 42 observer.OnWillDestroyEnv(); | 75 observer.OnWillDestroyEnv(); |
| 43 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); | 76 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); |
| 44 lazy_tls_ptr.Pointer()->Set(NULL); | 77 lazy_tls_ptr.Pointer()->Set(NULL); |
| 45 } | 78 } |
| 46 | 79 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 111 |
| 79 void Env::RemoveObserver(EnvObserver* observer) { | 112 void Env::RemoveObserver(EnvObserver* observer) { |
| 80 observers_.RemoveObserver(observer); | 113 observers_.RemoveObserver(observer); |
| 81 } | 114 } |
| 82 | 115 |
| 83 bool Env::IsMouseButtonDown() const { | 116 bool Env::IsMouseButtonDown() const { |
| 84 return input_state_lookup_.get() ? input_state_lookup_->IsMouseButtonDown() : | 117 return input_state_lookup_.get() ? input_state_lookup_->IsMouseButtonDown() : |
| 85 mouse_button_flags_ != 0; | 118 mouse_button_flags_ != 0; |
| 86 } | 119 } |
| 87 | 120 |
| 121 void Env::SetActiveFocusClient(client::FocusClient* focus_client, |
| 122 Window* focus_client_root) { |
| 123 if (focus_client == active_focus_client_ && |
| 124 focus_client_root == active_focus_client_root_) { |
| 125 return; |
| 126 } |
| 127 |
| 128 active_focus_client_window_observer_.reset(); |
| 129 active_focus_client_ = focus_client; |
| 130 active_focus_client_root_ = focus_client_root; |
| 131 if (focus_client_root) { |
| 132 active_focus_client_window_observer_ = |
| 133 base::MakeUnique<ActiveFocusClientWindowObserver>(focus_client_root); |
| 134 } |
| 135 for (EnvObserver& observer : observers_) |
| 136 observer.OnActiveFocusClientChanged(focus_client, focus_client_root); |
| 137 } |
| 138 |
| 88 //////////////////////////////////////////////////////////////////////////////// | 139 //////////////////////////////////////////////////////////////////////////////// |
| 89 // Env, private: | 140 // Env, private: |
| 90 | 141 |
| 91 Env::Env(const WindowPortFactory& window_port_factory) | 142 Env::Env(const WindowPortFactory& window_port_factory) |
| 92 : window_port_factory_(window_port_factory), | 143 : window_port_factory_(window_port_factory), |
| 93 mouse_button_flags_(0), | 144 mouse_button_flags_(0), |
| 94 is_touch_down_(false), | 145 is_touch_down_(false), |
| 95 input_state_lookup_(InputStateLookup::Create()), | 146 input_state_lookup_(InputStateLookup::Create()), |
| 96 context_factory_(NULL) { | 147 context_factory_(NULL) { |
| 97 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); | 148 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 119 void Env::NotifyHostInitialized(WindowTreeHost* host) { | 170 void Env::NotifyHostInitialized(WindowTreeHost* host) { |
| 120 for (EnvObserver& observer : observers_) | 171 for (EnvObserver& observer : observers_) |
| 121 observer.OnHostInitialized(host); | 172 observer.OnHostInitialized(host); |
| 122 } | 173 } |
| 123 | 174 |
| 124 void Env::NotifyHostActivated(WindowTreeHost* host) { | 175 void Env::NotifyHostActivated(WindowTreeHost* host) { |
| 125 for (EnvObserver& observer : observers_) | 176 for (EnvObserver& observer : observers_) |
| 126 observer.OnHostActivated(host); | 177 observer.OnHostActivated(host); |
| 127 } | 178 } |
| 128 | 179 |
| 180 void Env::OnActiveFocusClientWindowDestroying() { |
| 181 SetActiveFocusClient(nullptr, nullptr); |
| 182 } |
| 183 |
| 129 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
| 130 // Env, ui::EventTarget implementation: | 185 // Env, ui::EventTarget implementation: |
| 131 | 186 |
| 132 bool Env::CanAcceptEvent(const ui::Event& event) { | 187 bool Env::CanAcceptEvent(const ui::Event& event) { |
| 133 return true; | 188 return true; |
| 134 } | 189 } |
| 135 | 190 |
| 136 ui::EventTarget* Env::GetParentTarget() { | 191 ui::EventTarget* Env::GetParentTarget() { |
| 137 return NULL; | 192 return NULL; |
| 138 } | 193 } |
| 139 | 194 |
| 140 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { | 195 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { |
| 141 return nullptr; | 196 return nullptr; |
| 142 } | 197 } |
| 143 | 198 |
| 144 ui::EventTargeter* Env::GetEventTargeter() { | 199 ui::EventTargeter* Env::GetEventTargeter() { |
| 145 NOTREACHED(); | 200 NOTREACHED(); |
| 146 return NULL; | 201 return NULL; |
| 147 } | 202 } |
| 148 | 203 |
| 149 } // namespace aura | 204 } // namespace aura |
| OLD | NEW |