Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/aura/env.cc

Issue 2714763002: Change FocusSynchronizer to maintain active focus client and window. (Closed)
Patch Set: test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/env.h ('k') | ui/aura/env_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/os_exchange_data_provider_mus.h" 15 #include "ui/aura/mus/os_exchange_data_provider_mus.h"
17 #include "ui/aura/mus/window_port_mus.h" 16 #include "ui/aura/mus/window_port_mus.h"
18 #include "ui/aura/mus/window_tree_client.h" 17 #include "ui/aura/mus/window_tree_client.h"
19 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
20 #include "ui/aura/window_observer.h"
21 #include "ui/aura/window_port_local.h" 19 #include "ui/aura/window_port_local.h"
22 #include "ui/events/event_target_iterator.h" 20 #include "ui/events/event_target_iterator.h"
23 #include "ui/events/platform/platform_event_source.h" 21 #include "ui/events/platform/platform_event_source.h"
24 22
25 #if defined(USE_OZONE) 23 #if defined(USE_OZONE)
26 #include "ui/ozone/public/ozone_platform.h" 24 #include "ui/ozone/public/ozone_platform.h"
27 #endif 25 #endif
28 26
29 namespace aura { 27 namespace aura {
30 28
31 namespace { 29 namespace {
32 30
33 // 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.
34 base::LazyInstance<base::ThreadLocalPointer<Env>>::Leaky lazy_tls_ptr = 32 base::LazyInstance<base::ThreadLocalPointer<Env>>::Leaky lazy_tls_ptr =
35 LAZY_INSTANCE_INITIALIZER; 33 LAZY_INSTANCE_INITIALIZER;
36 34
37 // 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.
38 bool RunningInsideMus() { 36 bool RunningInsideMus() {
39 return base::CommandLine::ForCurrentProcess()->HasSwitch( 37 return base::CommandLine::ForCurrentProcess()->HasSwitch(
40 "primordial-pipe-token"); 38 "primordial-pipe-token");
41 } 39 }
42 40
43 } // namespace 41 } // namespace
44 42
45 // Observes destruction and changes of the FocusClient for a window.
46 // ActiveFocusClientWindowObserver is created for the window the FocusClient is
47 // associated with.
48 class Env::ActiveFocusClientWindowObserver : public WindowObserver {
49 public:
50 explicit ActiveFocusClientWindowObserver(Window* window) : window_(window) {
51 window_->AddObserver(this);
52 }
53 ~ActiveFocusClientWindowObserver() override { window_->RemoveObserver(this); }
54
55 // WindowObserver:
56 void OnWindowDestroying(Window* window) override {
57 Env::GetInstance()->OnActiveFocusClientWindowDestroying();
58 }
59 void OnWindowPropertyChanged(Window* window,
60 const void* key,
61 intptr_t old) override {
62 if (key != client::kFocusClientKey)
63 return;
64
65 // Assume if the focus client changes the window is being destroyed.
66 Env::GetInstance()->OnActiveFocusClientWindowDestroying();
67 }
68
69 private:
70 Window* window_;
71
72 DISALLOW_COPY_AND_ASSIGN(ActiveFocusClientWindowObserver);
73 };
74
75 //////////////////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////////
76 // Env, public: 44 // Env, public:
77 45
78 Env::~Env() { 46 Env::~Env() {
79 if (is_os_exchange_data_provider_factory_) 47 if (is_os_exchange_data_provider_factory_)
80 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); 48 ui::OSExchangeDataProviderFactory::SetFactory(nullptr);
81 49
82 for (EnvObserver& observer : observers_) 50 for (EnvObserver& observer : observers_)
83 observer.OnWillDestroyEnv(); 51 observer.OnWillDestroyEnv();
84 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); 52 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return last_mouse_location_; 123 return last_mouse_location_;
156 } 124 }
157 125
158 void Env::SetWindowTreeClient(WindowTreeClient* window_tree_client) { 126 void Env::SetWindowTreeClient(WindowTreeClient* window_tree_client) {
159 // The WindowTreeClient should only be set once. Test code may need to change 127 // The WindowTreeClient should only be set once. Test code may need to change
160 // the value after the fact, to do that use EnvTestHelper. 128 // the value after the fact, to do that use EnvTestHelper.
161 DCHECK(!window_tree_client_); 129 DCHECK(!window_tree_client_);
162 window_tree_client_ = window_tree_client; 130 window_tree_client_ = window_tree_client;
163 } 131 }
164 132
165 void Env::SetActiveFocusClient(client::FocusClient* focus_client,
166 Window* focus_client_root) {
167 if (focus_client == active_focus_client_ &&
168 focus_client_root == active_focus_client_root_) {
169 return;
170 }
171
172 active_focus_client_window_observer_.reset();
173 active_focus_client_ = focus_client;
174 active_focus_client_root_ = focus_client_root;
175 if (focus_client_root) {
176 active_focus_client_window_observer_ =
177 base::MakeUnique<ActiveFocusClientWindowObserver>(focus_client_root);
178 }
179 for (EnvObserver& observer : observers_)
180 observer.OnActiveFocusClientChanged(focus_client, focus_client_root);
181 }
182
183 //////////////////////////////////////////////////////////////////////////////// 133 ////////////////////////////////////////////////////////////////////////////////
184 // Env, private: 134 // Env, private:
185 135
186 Env::Env(Mode mode) 136 Env::Env(Mode mode)
187 : mode_(mode), 137 : mode_(mode),
188 mouse_button_flags_(0), 138 mouse_button_flags_(0),
189 is_touch_down_(false), 139 is_touch_down_(false),
190 get_last_mouse_location_from_mus_(mode_ == Mode::MUS), 140 get_last_mouse_location_from_mus_(mode_ == Mode::MUS),
191 input_state_lookup_(InputStateLookup::Create()), 141 input_state_lookup_(InputStateLookup::Create()),
192 context_factory_(nullptr), 142 context_factory_(nullptr),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void Env::NotifyHostInitialized(WindowTreeHost* host) { 176 void Env::NotifyHostInitialized(WindowTreeHost* host) {
227 for (EnvObserver& observer : observers_) 177 for (EnvObserver& observer : observers_)
228 observer.OnHostInitialized(host); 178 observer.OnHostInitialized(host);
229 } 179 }
230 180
231 void Env::NotifyHostActivated(WindowTreeHost* host) { 181 void Env::NotifyHostActivated(WindowTreeHost* host) {
232 for (EnvObserver& observer : observers_) 182 for (EnvObserver& observer : observers_)
233 observer.OnHostActivated(host); 183 observer.OnHostActivated(host);
234 } 184 }
235 185
236 void Env::OnActiveFocusClientWindowDestroying() {
237 SetActiveFocusClient(nullptr, nullptr);
238 }
239
240 //////////////////////////////////////////////////////////////////////////////// 186 ////////////////////////////////////////////////////////////////////////////////
241 // Env, ui::EventTarget implementation: 187 // Env, ui::EventTarget implementation:
242 188
243 bool Env::CanAcceptEvent(const ui::Event& event) { 189 bool Env::CanAcceptEvent(const ui::Event& event) {
244 return true; 190 return true;
245 } 191 }
246 192
247 ui::EventTarget* Env::GetParentTarget() { 193 ui::EventTarget* Env::GetParentTarget() {
248 return NULL; 194 return NULL;
249 } 195 }
250 196
251 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { 197 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const {
252 return nullptr; 198 return nullptr;
253 } 199 }
254 200
255 ui::EventTargeter* Env::GetEventTargeter() { 201 ui::EventTargeter* Env::GetEventTargeter() {
256 NOTREACHED(); 202 NOTREACHED();
257 return NULL; 203 return NULL;
258 } 204 }
259 205
260 std::unique_ptr<ui::OSExchangeData::Provider> Env::BuildProvider() { 206 std::unique_ptr<ui::OSExchangeData::Provider> Env::BuildProvider() {
261 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); 207 return base::MakeUnique<aura::OSExchangeDataProviderMus>();
262 } 208 }
263 209
264 } // namespace aura 210 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/env.h ('k') | ui/aura/env_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698