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

Side by Side Diff: ui/views/mus/desktop_window_tree_host_mus.cc

Issue 2714763002: Change FocusSynchronizer to maintain active focus client and window. (Closed)
Patch Set: fix crash in aura_test_helper tear down Created 3 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/views/mus/desktop_window_tree_host_mus.h" 5 #include "ui/views/mus/desktop_window_tree_host_mus.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "ui/aura/client/aura_constants.h" 11 #include "ui/aura/client/aura_constants.h"
12 #include "ui/aura/client/capture_client.h" 12 #include "ui/aura/client/capture_client.h"
13 #include "ui/aura/client/cursor_client.h" 13 #include "ui/aura/client/cursor_client.h"
14 #include "ui/aura/client/drag_drop_client.h" 14 #include "ui/aura/client/drag_drop_client.h"
15 #include "ui/aura/client/focus_client.h" 15 #include "ui/aura/client/focus_client.h"
16 #include "ui/aura/client/transient_window_client.h" 16 #include "ui/aura/client/transient_window_client.h"
17 #include "ui/aura/env.h" 17 #include "ui/aura/mus/focus_synchronizer.h"
18 #include "ui/aura/mus/window_port_mus.h" 18 #include "ui/aura/mus/window_port_mus.h"
19 #include "ui/aura/mus/window_tree_client.h"
19 #include "ui/aura/mus/window_tree_host_mus.h" 20 #include "ui/aura/mus/window_tree_host_mus.h"
20 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
21 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
22 #include "ui/display/screen.h" 23 #include "ui/display/screen.h"
23 #include "ui/gfx/geometry/dip_util.h" 24 #include "ui/gfx/geometry/dip_util.h"
24 #include "ui/views/corewm/tooltip_aura.h" 25 #include "ui/views/corewm/tooltip_aura.h"
25 #include "ui/views/mus/mus_client.h" 26 #include "ui/views/mus/mus_client.h"
26 #include "ui/views/mus/mus_property_mirror.h" 27 #include "ui/views/mus/mus_property_mirror.h"
27 #include "ui/views/mus/window_manager_frame_values.h" 28 #include "ui/views/mus/window_manager_frame_values.h"
28 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 29 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 185
185 DesktopWindowTreeHostMus::DesktopWindowTreeHostMus( 186 DesktopWindowTreeHostMus::DesktopWindowTreeHostMus(
186 internal::NativeWidgetDelegate* native_widget_delegate, 187 internal::NativeWidgetDelegate* native_widget_delegate,
187 DesktopNativeWidgetAura* desktop_native_widget_aura, 188 DesktopNativeWidgetAura* desktop_native_widget_aura,
188 const std::map<std::string, std::vector<uint8_t>>* mus_properties) 189 const std::map<std::string, std::vector<uint8_t>>* mus_properties)
189 : aura::WindowTreeHostMus(MusClient::Get()->window_tree_client(), 190 : aura::WindowTreeHostMus(MusClient::Get()->window_tree_client(),
190 mus_properties), 191 mus_properties),
191 native_widget_delegate_(native_widget_delegate), 192 native_widget_delegate_(native_widget_delegate),
192 desktop_native_widget_aura_(desktop_native_widget_aura), 193 desktop_native_widget_aura_(desktop_native_widget_aura),
193 close_widget_factory_(this) { 194 close_widget_factory_(this) {
194 aura::Env::GetInstance()->AddObserver(this);
195 MusClient::Get()->AddObserver(this); 195 MusClient::Get()->AddObserver(this);
196 MusClient::Get()->window_tree_client()->focus_synchronizer()->AddObserver(
197 this);
196 native_widget_delegate_->AsWidget()->AddObserver(this); 198 native_widget_delegate_->AsWidget()->AddObserver(this);
197 desktop_native_widget_aura_->content_window()->AddObserver(this); 199 desktop_native_widget_aura_->content_window()->AddObserver(this);
198 // DesktopNativeWidgetAura registers the association between |content_window_| 200 // DesktopNativeWidgetAura registers the association between |content_window_|
199 // and Widget, but code may also want to go from the root (window()) to the 201 // and Widget, but code may also want to go from the root (window()) to the
200 // Widget. This call enables that. 202 // Widget. This call enables that.
201 NativeWidgetAura::RegisterNativeWidgetForWindow(desktop_native_widget_aura, 203 NativeWidgetAura::RegisterNativeWidgetForWindow(desktop_native_widget_aura,
202 window()); 204 window());
203 // TODO: use display id and bounds if available, likely need to pass in 205 // TODO: use display id and bounds if available, likely need to pass in
204 // InitParams for that. 206 // InitParams for that.
205 } 207 }
206 208
207 DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() { 209 DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() {
208 // The cursor-client can be accessed during WindowTreeHostMus tear-down. So 210 // The cursor-client can be accessed during WindowTreeHostMus tear-down. So
209 // the cursor-client needs to be unset on the root-window before 211 // the cursor-client needs to be unset on the root-window before
210 // |cursor_manager_| is destroyed. 212 // |cursor_manager_| is destroyed.
211 aura::client::SetCursorClient(window(), nullptr); 213 aura::client::SetCursorClient(window(), nullptr);
212 desktop_native_widget_aura_->content_window()->RemoveObserver(this); 214 desktop_native_widget_aura_->content_window()->RemoveObserver(this);
213 native_widget_delegate_->AsWidget()->RemoveObserver(this); 215 native_widget_delegate_->AsWidget()->RemoveObserver(this);
214 MusClient::Get()->RemoveObserver(this); 216 MusClient::Get()->RemoveObserver(this);
215 aura::Env::GetInstance()->RemoveObserver(this); 217 MusClient::Get()->window_tree_client()->focus_synchronizer()->RemoveObserver(
218 this);
216 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); 219 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
217 } 220 }
218 221
219 // TODO(afakhry): Remove Docked Windows in M58. 222 // TODO(afakhry): Remove Docked Windows in M58.
220 bool DesktopWindowTreeHostMus::IsDocked() const { 223 bool DesktopWindowTreeHostMus::IsDocked() const {
221 return window()->GetProperty(aura::client::kShowStateKey) == 224 return window()->GetProperty(aura::client::kShowStateKey) ==
222 ui::SHOW_STATE_DOCKED; 225 ui::SHOW_STATE_DOCKED;
223 } 226 }
224 227
225 void DesktopWindowTreeHostMus::SendClientAreaToServer() { 228 void DesktopWindowTreeHostMus::SendClientAreaToServer() {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 // Close doesn't delete this immediately, as 'this' may still be on the stack 365 // Close doesn't delete this immediately, as 'this' may still be on the stack
363 // resulting in possible crashes when the stack unwindes. 366 // resulting in possible crashes when the stack unwindes.
364 base::ThreadTaskRunnerHandle::Get()->PostTask( 367 base::ThreadTaskRunnerHandle::Get()->PostTask(
365 FROM_HERE, base::Bind(&DesktopWindowTreeHostMus::CloseNow, 368 FROM_HERE, base::Bind(&DesktopWindowTreeHostMus::CloseNow,
366 close_widget_factory_.GetWeakPtr())); 369 close_widget_factory_.GetWeakPtr()));
367 } 370 }
368 371
369 void DesktopWindowTreeHostMus::CloseNow() { 372 void DesktopWindowTreeHostMus::CloseNow() {
370 MusClient::Get()->OnCaptureClientUnset( 373 MusClient::Get()->OnCaptureClientUnset(
371 aura::client::GetCaptureClient(window())); 374 aura::client::GetCaptureClient(window()));
375 MusClient::Get()
376 ->window_tree_client()
377 ->focus_synchronizer()
378 ->DetachFromFocusClient(aura::client::GetFocusClient(window()));
372 379
373 native_widget_delegate_->OnNativeWidgetDestroying(); 380 native_widget_delegate_->OnNativeWidgetDestroying();
374 381
375 // If we have children, close them. Use a copy for iteration because they'll 382 // If we have children, close them. Use a copy for iteration because they'll
376 // remove themselves from |children_|. 383 // remove themselves from |children_|.
377 std::set<DesktopWindowTreeHostMus*> children_copy = children_; 384 std::set<DesktopWindowTreeHostMus*> children_copy = children_;
378 for (DesktopWindowTreeHostMus* child : children_copy) 385 for (DesktopWindowTreeHostMus* child : children_copy)
379 child->CloseNow(); 386 child->CloseNow();
380 DCHECK(children_.empty()); 387 DCHECK(children_.empty());
381 388
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 NOTIMPLEMENTED(); 549 NOTIMPLEMENTED();
543 } 550 }
544 551
545 void DesktopWindowTreeHostMus::Activate() { 552 void DesktopWindowTreeHostMus::Activate() {
546 if (!IsVisible()) 553 if (!IsVisible())
547 return; 554 return;
548 555
549 // This should result in OnActiveFocusClientChanged() being called, which 556 // This should result in OnActiveFocusClientChanged() being called, which
550 // triggers a call to DesktopNativeWidgetAura::HandleActivationChanged(), 557 // triggers a call to DesktopNativeWidgetAura::HandleActivationChanged(),
551 // which focuses the right window. 558 // which focuses the right window.
552 aura::Env::GetInstance()->SetActiveFocusClient( 559 MusClient::Get()
553 aura::client::GetFocusClient(window()), window()); 560 ->window_tree_client()
561 ->focus_synchronizer()
562 ->AttachToFocusClient(aura::client::GetFocusClient(window()), window());
554 if (is_active_) 563 if (is_active_)
555 window()->SetProperty(aura::client::kDrawAttentionKey, false); 564 window()->SetProperty(aura::client::kDrawAttentionKey, false);
556 } 565 }
557 566
558 void DesktopWindowTreeHostMus::Deactivate() { 567 void DesktopWindowTreeHostMus::Deactivate() {
559 if (is_active_) 568 if (is_active_)
560 DeactivateWindow(); 569 DeactivateWindow();
561 } 570 }
562 571
563 bool DesktopWindowTreeHostMus::IsActive() const { 572 bool DesktopWindowTreeHostMus::IsActive() const {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 757
749 void DesktopWindowTreeHostMus::OnWidgetActivationChanged(Widget* widget, 758 void DesktopWindowTreeHostMus::OnWidgetActivationChanged(Widget* widget,
750 bool active) { 759 bool active) {
751 // TODO(erg): Theoretically, this shouldn't be necessary. We should be able 760 // TODO(erg): Theoretically, this shouldn't be necessary. We should be able
752 // to just set |is_active_| in OnNativeWidgetActivationChanged() above, 761 // to just set |is_active_| in OnNativeWidgetActivationChanged() above,
753 // instead of asking the Widget to change the activation and have the widget 762 // instead of asking the Widget to change the activation and have the widget
754 // then tell us the activation has changed. But if we do that, focus breaks. 763 // then tell us the activation has changed. But if we do that, focus breaks.
755 is_active_ = active; 764 is_active_ = active;
756 } 765 }
757 766
767 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged(
768 aura::client::FocusClient* focus_client,
769 aura::Window* window) {
770 if (window == this->window()) {
sadrul 2017/03/09 02:01:23 Could it not do this by just being a FocusChangeOb
771 desktop_native_widget_aura_->HandleActivationChanged(true);
772 } else if (is_active_) {
773 desktop_native_widget_aura_->HandleActivationChanged(false);
774 }
775 }
776
758 void DesktopWindowTreeHostMus::OnWindowPropertyChanged(aura::Window* window, 777 void DesktopWindowTreeHostMus::OnWindowPropertyChanged(aura::Window* window,
759 const void* key, 778 const void* key,
760 intptr_t old) { 779 intptr_t old) {
761 DCHECK_EQ(window, desktop_native_widget_aura_->content_window()); 780 DCHECK_EQ(window, desktop_native_widget_aura_->content_window());
762 DCHECK(!window->GetRootWindow() || this->window() == window->GetRootWindow()); 781 DCHECK(!window->GetRootWindow() || this->window() == window->GetRootWindow());
763 if (!this->window()) 782 if (!this->window())
764 return; 783 return;
765 784
766 // Allow mus clients to mirror widget window properties to their root windows. 785 // Allow mus clients to mirror widget window properties to their root windows.
767 MusPropertyMirror* property_mirror = MusClient::Get()->mus_property_mirror(); 786 MusPropertyMirror* property_mirror = MusClient::Get()->mus_property_mirror();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 final_bounds_in_pixels.set_size(size); 819 final_bounds_in_pixels.set_size(size);
801 } 820 }
802 const gfx::Rect old_bounds_in_pixels = GetBoundsInPixels(); 821 const gfx::Rect old_bounds_in_pixels = GetBoundsInPixels();
803 WindowTreeHostMus::SetBoundsInPixels(final_bounds_in_pixels); 822 WindowTreeHostMus::SetBoundsInPixels(final_bounds_in_pixels);
804 if (old_bounds_in_pixels.size() != final_bounds_in_pixels.size()) { 823 if (old_bounds_in_pixels.size() != final_bounds_in_pixels.size()) {
805 SendClientAreaToServer(); 824 SendClientAreaToServer();
806 SendHitTestMaskToServer(); 825 SendHitTestMaskToServer();
807 } 826 }
808 } 827 }
809 828
810 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {}
811
812 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged(
813 aura::client::FocusClient* focus_client,
814 aura::Window* window) {
815 if (window == this->window()) {
816 desktop_native_widget_aura_->HandleActivationChanged(true);
817 } else if (is_active_) {
818 desktop_native_widget_aura_->HandleActivationChanged(false);
819 }
820 }
821
822 } // namespace views 829 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/desktop_window_tree_host_mus.h ('k') | ui/views/mus/desktop_window_tree_host_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698