| OLD | NEW |
| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 cc::FrameSinkId& frame_sink_id, | 189 const cc::FrameSinkId& frame_sink_id, |
| 189 const std::map<std::string, std::vector<uint8_t>>* mus_properties) | 190 const std::map<std::string, std::vector<uint8_t>>* mus_properties) |
| 190 : aura::WindowTreeHostMus(MusClient::Get()->window_tree_client(), | 191 : aura::WindowTreeHostMus(MusClient::Get()->window_tree_client(), |
| 191 frame_sink_id, | 192 frame_sink_id, |
| 192 mus_properties), | 193 mus_properties), |
| 193 native_widget_delegate_(native_widget_delegate), | 194 native_widget_delegate_(native_widget_delegate), |
| 194 desktop_native_widget_aura_(desktop_native_widget_aura), | 195 desktop_native_widget_aura_(desktop_native_widget_aura), |
| 195 close_widget_factory_(this) { | 196 close_widget_factory_(this) { |
| 196 aura::Env::GetInstance()->AddObserver(this); | |
| 197 MusClient::Get()->AddObserver(this); | 197 MusClient::Get()->AddObserver(this); |
| 198 MusClient::Get()->window_tree_client()->focus_synchronizer()->AddObserver( |
| 199 this); |
| 198 native_widget_delegate_->AsWidget()->AddObserver(this); | 200 native_widget_delegate_->AsWidget()->AddObserver(this); |
| 199 desktop_native_widget_aura_->content_window()->AddObserver(this); | 201 desktop_native_widget_aura_->content_window()->AddObserver(this); |
| 200 // DesktopNativeWidgetAura registers the association between |content_window_| | 202 // DesktopNativeWidgetAura registers the association between |content_window_| |
| 201 // and Widget, but code may also want to go from the root (window()) to the | 203 // and Widget, but code may also want to go from the root (window()) to the |
| 202 // Widget. This call enables that. | 204 // Widget. This call enables that. |
| 203 NativeWidgetAura::RegisterNativeWidgetForWindow(desktop_native_widget_aura, | 205 NativeWidgetAura::RegisterNativeWidgetForWindow(desktop_native_widget_aura, |
| 204 window()); | 206 window()); |
| 205 // TODO: use display id and bounds if available, likely need to pass in | 207 // TODO: use display id and bounds if available, likely need to pass in |
| 206 // InitParams for that. | 208 // InitParams for that. |
| 207 } | 209 } |
| 208 | 210 |
| 209 DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() { | 211 DesktopWindowTreeHostMus::~DesktopWindowTreeHostMus() { |
| 210 // The cursor-client can be accessed during WindowTreeHostMus tear-down. So | 212 // The cursor-client can be accessed during WindowTreeHostMus tear-down. So |
| 211 // the cursor-client needs to be unset on the root-window before | 213 // the cursor-client needs to be unset on the root-window before |
| 212 // |cursor_manager_| is destroyed. | 214 // |cursor_manager_| is destroyed. |
| 213 aura::client::SetCursorClient(window(), nullptr); | 215 aura::client::SetCursorClient(window(), nullptr); |
| 214 desktop_native_widget_aura_->content_window()->RemoveObserver(this); | 216 desktop_native_widget_aura_->content_window()->RemoveObserver(this); |
| 215 native_widget_delegate_->AsWidget()->RemoveObserver(this); | 217 native_widget_delegate_->AsWidget()->RemoveObserver(this); |
| 216 MusClient::Get()->RemoveObserver(this); | 218 MusClient::Get()->RemoveObserver(this); |
| 217 aura::Env::GetInstance()->RemoveObserver(this); | 219 MusClient::Get()->window_tree_client()->focus_synchronizer()->RemoveObserver( |
| 220 this); |
| 218 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); | 221 desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this); |
| 219 } | 222 } |
| 220 | 223 |
| 221 void DesktopWindowTreeHostMus::SendClientAreaToServer() { | 224 void DesktopWindowTreeHostMus::SendClientAreaToServer() { |
| 222 if (!ShouldSendClientAreaToServer()) | 225 if (!ShouldSendClientAreaToServer()) |
| 223 return; | 226 return; |
| 224 | 227 |
| 225 NonClientView* non_client_view = | 228 NonClientView* non_client_view = |
| 226 native_widget_delegate_->AsWidget()->non_client_view(); | 229 native_widget_delegate_->AsWidget()->non_client_view(); |
| 227 if (!non_client_view || !non_client_view->client_view()) | 230 if (!non_client_view || !non_client_view->client_view()) |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 NOTIMPLEMENTED(); | 527 NOTIMPLEMENTED(); |
| 525 } | 528 } |
| 526 | 529 |
| 527 void DesktopWindowTreeHostMus::Activate() { | 530 void DesktopWindowTreeHostMus::Activate() { |
| 528 if (!IsVisible()) | 531 if (!IsVisible()) |
| 529 return; | 532 return; |
| 530 | 533 |
| 531 // This should result in OnActiveFocusClientChanged() being called, which | 534 // This should result in OnActiveFocusClientChanged() being called, which |
| 532 // triggers a call to DesktopNativeWidgetAura::HandleActivationChanged(), | 535 // triggers a call to DesktopNativeWidgetAura::HandleActivationChanged(), |
| 533 // which focuses the right window. | 536 // which focuses the right window. |
| 534 aura::Env::GetInstance()->SetActiveFocusClient( | 537 MusClient::Get() |
| 535 aura::client::GetFocusClient(window()), window()); | 538 ->window_tree_client() |
| 539 ->focus_synchronizer() |
| 540 ->SetActiveFocusClient(aura::client::GetFocusClient(window()), window()); |
| 536 if (is_active_) | 541 if (is_active_) |
| 537 window()->SetProperty(aura::client::kDrawAttentionKey, false); | 542 window()->SetProperty(aura::client::kDrawAttentionKey, false); |
| 538 } | 543 } |
| 539 | 544 |
| 540 void DesktopWindowTreeHostMus::Deactivate() { | 545 void DesktopWindowTreeHostMus::Deactivate() { |
| 541 if (is_active_) | 546 if (is_active_) |
| 542 DeactivateWindow(); | 547 DeactivateWindow(); |
| 543 } | 548 } |
| 544 | 549 |
| 545 bool DesktopWindowTreeHostMus::IsActive() const { | 550 bool DesktopWindowTreeHostMus::IsActive() const { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 | 735 |
| 731 void DesktopWindowTreeHostMus::OnWidgetActivationChanged(Widget* widget, | 736 void DesktopWindowTreeHostMus::OnWidgetActivationChanged(Widget* widget, |
| 732 bool active) { | 737 bool active) { |
| 733 // TODO(erg): Theoretically, this shouldn't be necessary. We should be able | 738 // TODO(erg): Theoretically, this shouldn't be necessary. We should be able |
| 734 // to just set |is_active_| in OnNativeWidgetActivationChanged() above, | 739 // to just set |is_active_| in OnNativeWidgetActivationChanged() above, |
| 735 // instead of asking the Widget to change the activation and have the widget | 740 // instead of asking the Widget to change the activation and have the widget |
| 736 // then tell us the activation has changed. But if we do that, focus breaks. | 741 // then tell us the activation has changed. But if we do that, focus breaks. |
| 737 is_active_ = active; | 742 is_active_ = active; |
| 738 } | 743 } |
| 739 | 744 |
| 745 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged( |
| 746 aura::client::FocusClient* focus_client, |
| 747 aura::Window* focus_client_root) { |
| 748 if (focus_client_root == this->window()) { |
| 749 desktop_native_widget_aura_->HandleActivationChanged(true); |
| 750 } else if (is_active_) { |
| 751 desktop_native_widget_aura_->HandleActivationChanged(false); |
| 752 } |
| 753 } |
| 754 |
| 740 void DesktopWindowTreeHostMus::OnWindowPropertyChanged(aura::Window* window, | 755 void DesktopWindowTreeHostMus::OnWindowPropertyChanged(aura::Window* window, |
| 741 const void* key, | 756 const void* key, |
| 742 intptr_t old) { | 757 intptr_t old) { |
| 743 DCHECK_EQ(window, desktop_native_widget_aura_->content_window()); | 758 DCHECK_EQ(window, desktop_native_widget_aura_->content_window()); |
| 744 DCHECK(!window->GetRootWindow() || this->window() == window->GetRootWindow()); | 759 DCHECK(!window->GetRootWindow() || this->window() == window->GetRootWindow()); |
| 745 if (!this->window()) | 760 if (!this->window()) |
| 746 return; | 761 return; |
| 747 | 762 |
| 748 // Allow mus clients to mirror widget window properties to their root windows. | 763 // Allow mus clients to mirror widget window properties to their root windows. |
| 749 MusPropertyMirror* property_mirror = MusClient::Get()->mus_property_mirror(); | 764 MusPropertyMirror* property_mirror = MusClient::Get()->mus_property_mirror(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 final_bounds_in_pixels.set_size(size); | 797 final_bounds_in_pixels.set_size(size); |
| 783 } | 798 } |
| 784 const gfx::Rect old_bounds_in_pixels = GetBoundsInPixels(); | 799 const gfx::Rect old_bounds_in_pixels = GetBoundsInPixels(); |
| 785 WindowTreeHostMus::SetBoundsInPixels(final_bounds_in_pixels); | 800 WindowTreeHostMus::SetBoundsInPixels(final_bounds_in_pixels); |
| 786 if (old_bounds_in_pixels.size() != final_bounds_in_pixels.size()) { | 801 if (old_bounds_in_pixels.size() != final_bounds_in_pixels.size()) { |
| 787 SendClientAreaToServer(); | 802 SendClientAreaToServer(); |
| 788 SendHitTestMaskToServer(); | 803 SendHitTestMaskToServer(); |
| 789 } | 804 } |
| 790 } | 805 } |
| 791 | 806 |
| 792 void DesktopWindowTreeHostMus::OnWindowInitialized(aura::Window* window) {} | |
| 793 | |
| 794 void DesktopWindowTreeHostMus::OnActiveFocusClientChanged( | |
| 795 aura::client::FocusClient* focus_client, | |
| 796 aura::Window* window) { | |
| 797 if (window == this->window()) { | |
| 798 desktop_native_widget_aura_->HandleActivationChanged(true); | |
| 799 } else if (is_active_) { | |
| 800 desktop_native_widget_aura_->HandleActivationChanged(false); | |
| 801 } | |
| 802 } | |
| 803 | |
| 804 } // namespace views | 807 } // namespace views |
| OLD | NEW |