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

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

Issue 2480273003: Revert of Improves focus/activation for aura-mus and DesktopNativeWidgetAura (Closed)
Patch Set: Created 4 years, 1 month 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/focus_client.h"
12 #include "ui/aura/env_observer.h" 11 #include "ui/aura/env_observer.h"
13 #include "ui/aura/input_state_lookup.h" 12 #include "ui/aura/input_state_lookup.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_observer.h"
16 #include "ui/aura/window_port_local.h" 13 #include "ui/aura/window_port_local.h"
17 #include "ui/events/event_target_iterator.h" 14 #include "ui/events/event_target_iterator.h"
18 #include "ui/events/platform/platform_event_source.h" 15 #include "ui/events/platform/platform_event_source.h"
19 16
20 #if defined(USE_OZONE) 17 #if defined(USE_OZONE)
21 #include "ui/ozone/public/ozone_platform.h" 18 #include "ui/ozone/public/ozone_platform.h"
22 #endif 19 #endif
23 20
24 namespace aura { 21 namespace aura {
25 22
26 namespace { 23 namespace {
27 24
28 // Env is thread local so that aura may be used on multiple threads. 25 // Env is thread local so that aura may be used on multiple threads.
29 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = 26 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr =
30 LAZY_INSTANCE_INITIALIZER; 27 LAZY_INSTANCE_INITIALIZER;
31 28
32 // Returns true if running inside of mus. Checks for mojo specific flag. 29 // Returns true if running inside of mus. Checks for mojo specific flag.
33 bool RunningInsideMus() { 30 bool RunningInsideMus() {
34 return base::CommandLine::ForCurrentProcess()->HasSwitch( 31 return base::CommandLine::ForCurrentProcess()->HasSwitch(
35 "primordial-pipe-token"); 32 "primordial-pipe-token");
36 } 33 }
37 34
38 } // namespace 35 } // namespace
39 36
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
70 //////////////////////////////////////////////////////////////////////////////// 37 ////////////////////////////////////////////////////////////////////////////////
71 // Env, public: 38 // Env, public:
72 39
73 Env::~Env() { 40 Env::~Env() {
74 for (EnvObserver& observer : observers_) 41 for (EnvObserver& observer : observers_)
75 observer.OnWillDestroyEnv(); 42 observer.OnWillDestroyEnv();
76 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); 43 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get());
77 lazy_tls_ptr.Pointer()->Set(NULL); 44 lazy_tls_ptr.Pointer()->Set(NULL);
78 } 45 }
79 46
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 78
112 void Env::RemoveObserver(EnvObserver* observer) { 79 void Env::RemoveObserver(EnvObserver* observer) {
113 observers_.RemoveObserver(observer); 80 observers_.RemoveObserver(observer);
114 } 81 }
115 82
116 bool Env::IsMouseButtonDown() const { 83 bool Env::IsMouseButtonDown() const {
117 return input_state_lookup_.get() ? input_state_lookup_->IsMouseButtonDown() : 84 return input_state_lookup_.get() ? input_state_lookup_->IsMouseButtonDown() :
118 mouse_button_flags_ != 0; 85 mouse_button_flags_ != 0;
119 } 86 }
120 87
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
139 //////////////////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////////////////
140 // Env, private: 89 // Env, private:
141 90
142 Env::Env(const WindowPortFactory& window_port_factory) 91 Env::Env(const WindowPortFactory& window_port_factory)
143 : window_port_factory_(window_port_factory), 92 : window_port_factory_(window_port_factory),
144 mouse_button_flags_(0), 93 mouse_button_flags_(0),
145 is_touch_down_(false), 94 is_touch_down_(false),
146 input_state_lookup_(InputStateLookup::Create()), 95 input_state_lookup_(InputStateLookup::Create()),
147 context_factory_(NULL) { 96 context_factory_(NULL) {
148 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); 97 DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL);
(...skipping 21 matching lines...) Expand all
170 void Env::NotifyHostInitialized(WindowTreeHost* host) { 119 void Env::NotifyHostInitialized(WindowTreeHost* host) {
171 for (EnvObserver& observer : observers_) 120 for (EnvObserver& observer : observers_)
172 observer.OnHostInitialized(host); 121 observer.OnHostInitialized(host);
173 } 122 }
174 123
175 void Env::NotifyHostActivated(WindowTreeHost* host) { 124 void Env::NotifyHostActivated(WindowTreeHost* host) {
176 for (EnvObserver& observer : observers_) 125 for (EnvObserver& observer : observers_)
177 observer.OnHostActivated(host); 126 observer.OnHostActivated(host);
178 } 127 }
179 128
180 void Env::OnActiveFocusClientWindowDestroying() {
181 SetActiveFocusClient(nullptr, nullptr);
182 }
183
184 //////////////////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////////////////
185 // Env, ui::EventTarget implementation: 130 // Env, ui::EventTarget implementation:
186 131
187 bool Env::CanAcceptEvent(const ui::Event& event) { 132 bool Env::CanAcceptEvent(const ui::Event& event) {
188 return true; 133 return true;
189 } 134 }
190 135
191 ui::EventTarget* Env::GetParentTarget() { 136 ui::EventTarget* Env::GetParentTarget() {
192 return NULL; 137 return NULL;
193 } 138 }
194 139
195 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { 140 std::unique_ptr<ui::EventTargetIterator> Env::GetChildIterator() const {
196 return nullptr; 141 return nullptr;
197 } 142 }
198 143
199 ui::EventTargeter* Env::GetEventTargeter() { 144 ui::EventTargeter* Env::GetEventTargeter() {
200 NOTREACHED(); 145 NOTREACHED();
201 return NULL; 146 return NULL;
202 } 147 }
203 148
204 } // namespace aura 149 } // 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