| 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 "ash/common/wm_window.h" | 5 #include "ash/common/wm_window.h" |
| 6 | 6 |
| 7 #include "ash/aura/aura_layout_manager_adapter.h" | 7 #include "ash/aura/aura_layout_manager_adapter.h" |
| 8 #include "ash/aura/wm_shell_aura.h" | 8 #include "ash/aura/wm_shell_aura.h" |
| 9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
| 10 #include "ash/common/shelf/shelf_item_types.h" | 10 #include "ash/common/shelf/shelf_item_types.h" |
| 11 #include "ash/common/wm/window_state.h" | 11 #include "ash/common/wm/window_state.h" |
| 12 #include "ash/common/wm_layout_manager.h" | 12 #include "ash/common/wm_layout_manager.h" |
| 13 #include "ash/common/wm_transient_window_observer.h" | 13 #include "ash/common/wm_transient_window_observer.h" |
| 14 #include "ash/common/wm_window_observer.h" | |
| 15 #include "ash/common/wm_window_property.h" | 14 #include "ash/common/wm_window_property.h" |
| 16 #include "ash/public/cpp/shell_window_ids.h" | 15 #include "ash/public/cpp/shell_window_ids.h" |
| 17 #include "ash/public/cpp/window_properties.h" | 16 #include "ash/public/cpp/window_properties.h" |
| 18 #include "ash/root_window_controller.h" | 17 #include "ash/root_window_controller.h" |
| 19 #include "ash/screen_util.h" | 18 #include "ash/screen_util.h" |
| 20 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 21 #include "ash/wm/resize_handle_window_targeter.h" | 20 #include "ash/wm/resize_handle_window_targeter.h" |
| 22 #include "ash/wm/resize_shadow_controller.h" | 21 #include "ash/wm/resize_shadow_controller.h" |
| 23 #include "ash/wm/window_animations.h" | 22 #include "ash/wm/window_animations.h" |
| 24 #include "ash/wm/window_mirror_view.h" | 23 #include "ash/wm/window_mirror_view.h" |
| 25 #include "ash/wm/window_properties.h" | 24 #include "ash/wm/window_properties.h" |
| 26 #include "ash/wm/window_state_aura.h" | 25 #include "ash/wm/window_state_aura.h" |
| 27 #include "ash/wm/window_util.h" | 26 #include "ash/wm/window_util.h" |
| 28 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
| 29 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 28 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 30 #include "ui/aura/client/aura_constants.h" | 29 #include "ui/aura/client/aura_constants.h" |
| 31 #include "ui/aura/client/focus_client.h" | 30 #include "ui/aura/client/focus_client.h" |
| 32 #include "ui/aura/client/window_parenting_client.h" | 31 #include "ui/aura/client/window_parenting_client.h" |
| 33 #include "ui/aura/env.h" | 32 #include "ui/aura/env.h" |
| 34 #include "ui/aura/layout_manager.h" | 33 #include "ui/aura/layout_manager.h" |
| 35 #include "ui/aura/mus/window_manager_delegate.h" | 34 #include "ui/aura/mus/window_manager_delegate.h" |
| 36 #include "ui/aura/mus/window_mus.h" | 35 #include "ui/aura/mus/window_mus.h" |
| 37 #include "ui/aura/mus/window_tree_client.h" | 36 #include "ui/aura/mus/window_tree_client.h" |
| 38 #include "ui/aura/window.h" | 37 #include "ui/aura/window.h" |
| 39 #include "ui/aura/window_delegate.h" | 38 #include "ui/aura/window_delegate.h" |
| 39 #include "ui/aura/window_observer.h" |
| 40 #include "ui/base/class_property.h" | 40 #include "ui/base/class_property.h" |
| 41 #include "ui/base/hit_test.h" | 41 #include "ui/base/hit_test.h" |
| 42 #include "ui/compositor/layer_tree_owner.h" | 42 #include "ui/compositor/layer_tree_owner.h" |
| 43 #include "ui/compositor/scoped_layer_animation_settings.h" | 43 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 44 #include "ui/display/screen.h" | 44 #include "ui/display/screen.h" |
| 45 #include "ui/gfx/geometry/insets.h" | 45 #include "ui/gfx/geometry/insets.h" |
| 46 #include "ui/views/widget/widget.h" | 46 #include "ui/views/widget/widget.h" |
| 47 #include "ui/views/widget/widget_delegate.h" | 47 #include "ui/views/widget/widget_delegate.h" |
| 48 #include "ui/wm/core/coordinate_conversion.h" | 48 #include "ui/wm/core/coordinate_conversion.h" |
| 49 #include "ui/wm/core/easy_resize_window_targeter.h" | 49 #include "ui/wm/core/easy_resize_window_targeter.h" |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 // events to be dispatched to windows outside the windows bounds that this | 849 // events to be dispatched to windows outside the windows bounds that this |
| 850 // function calls into. http://crbug.com/679056. | 850 // function calls into. http://crbug.com/679056. |
| 851 window_->SetEventTargeter(base::MakeUnique<::wm::EasyResizeWindowTargeter>( | 851 window_->SetEventTargeter(base::MakeUnique<::wm::EasyResizeWindowTargeter>( |
| 852 window_, mouse_extend, touch_extend)); | 852 window_, mouse_extend, touch_extend)); |
| 853 } | 853 } |
| 854 | 854 |
| 855 std::unique_ptr<views::View> WmWindow::CreateViewWithRecreatedLayers() { | 855 std::unique_ptr<views::View> WmWindow::CreateViewWithRecreatedLayers() { |
| 856 return base::MakeUnique<wm::WindowMirrorView>(this); | 856 return base::MakeUnique<wm::WindowMirrorView>(this); |
| 857 } | 857 } |
| 858 | 858 |
| 859 void WmWindow::AddObserver(WmWindowObserver* observer) { | |
| 860 observers_.AddObserver(observer); | |
| 861 } | |
| 862 | |
| 863 void WmWindow::RemoveObserver(WmWindowObserver* observer) { | |
| 864 observers_.RemoveObserver(observer); | |
| 865 } | |
| 866 | |
| 867 bool WmWindow::HasObserver(const WmWindowObserver* observer) const { | |
| 868 return observers_.HasObserver(observer); | |
| 869 } | |
| 870 | |
| 871 void WmWindow::AddTransientWindowObserver(WmTransientWindowObserver* observer) { | 859 void WmWindow::AddTransientWindowObserver(WmTransientWindowObserver* observer) { |
| 872 if (!added_transient_observer_) { | 860 if (!added_transient_observer_) { |
| 873 added_transient_observer_ = true; | 861 added_transient_observer_ = true; |
| 874 ::wm::TransientWindowManager::Get(window_)->AddObserver(this); | 862 ::wm::TransientWindowManager::Get(window_)->AddObserver(this); |
| 875 } | 863 } |
| 876 transient_observers_.AddObserver(observer); | 864 transient_observers_.AddObserver(observer); |
| 877 } | 865 } |
| 878 | 866 |
| 879 void WmWindow::RemoveTransientWindowObserver( | 867 void WmWindow::RemoveTransientWindowObserver( |
| 880 WmTransientWindowObserver* observer) { | 868 WmTransientWindowObserver* observer) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 893 aura::WindowMus::Get(window_))); | 881 aura::WindowMus::Get(window_))); |
| 894 window_->AddPreTargetHandler(handler); | 882 window_->AddPreTargetHandler(handler); |
| 895 } | 883 } |
| 896 | 884 |
| 897 void WmWindow::RemoveLimitedPreTargetHandler(ui::EventHandler* handler) { | 885 void WmWindow::RemoveLimitedPreTargetHandler(ui::EventHandler* handler) { |
| 898 window_->RemovePreTargetHandler(handler); | 886 window_->RemovePreTargetHandler(handler); |
| 899 } | 887 } |
| 900 | 888 |
| 901 WmWindow::WmWindow(aura::Window* window) | 889 WmWindow::WmWindow(aura::Window* window) |
| 902 : window_(window), | 890 : window_(window), |
| 903 // Mirrors that of aura::Window. | |
| 904 observers_(base::ObserverList<WmWindowObserver>::NOTIFY_EXISTING_ONLY), | |
| 905 use_empty_minimum_size_for_testing_( | 891 use_empty_minimum_size_for_testing_( |
| 906 default_use_empty_minimum_size_for_testing_) { | 892 default_use_empty_minimum_size_for_testing_) { |
| 907 window_->AddObserver(this); | 893 window_->AddObserver(this); |
| 908 window_->SetProperty(kWmWindowKey, this); | 894 window_->SetProperty(kWmWindowKey, this); |
| 909 } | 895 } |
| 910 | 896 |
| 911 void WmWindow::OnWindowHierarchyChanging(const HierarchyChangeParams& params) { | |
| 912 WmWindowObserver::TreeChangeParams wm_params; | |
| 913 wm_params.target = Get(params.target); | |
| 914 wm_params.new_parent = Get(params.new_parent); | |
| 915 wm_params.old_parent = Get(params.old_parent); | |
| 916 for (auto& observer : observers_) | |
| 917 observer.OnWindowTreeChanging(this, wm_params); | |
| 918 } | |
| 919 | |
| 920 void WmWindow::OnWindowHierarchyChanged(const HierarchyChangeParams& params) { | |
| 921 WmWindowObserver::TreeChangeParams wm_params; | |
| 922 wm_params.target = Get(params.target); | |
| 923 wm_params.new_parent = Get(params.new_parent); | |
| 924 wm_params.old_parent = Get(params.old_parent); | |
| 925 for (auto& observer : observers_) | |
| 926 observer.OnWindowTreeChanged(this, wm_params); | |
| 927 } | |
| 928 | |
| 929 void WmWindow::OnWindowStackingChanged(aura::Window* window) { | |
| 930 for (auto& observer : observers_) | |
| 931 observer.OnWindowStackingChanged(this); | |
| 932 } | |
| 933 | |
| 934 void WmWindow::OnWindowPropertyChanged(aura::Window* window, | 897 void WmWindow::OnWindowPropertyChanged(aura::Window* window, |
| 935 const void* key, | 898 const void* key, |
| 936 intptr_t old) { | 899 intptr_t old) { |
| 937 if (key == aura::client::kShowStateKey) { | 900 if (key == aura::client::kShowStateKey) { |
| 938 ash::wm::GetWindowState(window_)->OnWindowShowStateChanged(); | 901 ash::wm::GetWindowState(window_)->OnWindowShowStateChanged(); |
| 939 return; | 902 return; |
| 940 } | 903 } |
| 941 if (key == aura::client::kImmersiveFullscreenKey) { | 904 if (key == aura::client::kImmersiveFullscreenKey) { |
| 942 bool enable = window_->GetProperty(aura::client::kImmersiveFullscreenKey); | 905 bool enable = window_->GetProperty(aura::client::kImmersiveFullscreenKey); |
| 943 GetWindowState()->set_in_immersive_fullscreen(enable); | 906 GetWindowState()->set_in_immersive_fullscreen(enable); |
| 944 return; | 907 return; |
| 945 } | 908 } |
| 946 WmWindowProperty wm_property; | |
| 947 if (key == aura::client::kAlwaysOnTopKey) { | |
| 948 wm_property = WmWindowProperty::ALWAYS_ON_TOP; | |
| 949 } else if (key == aura::client::kAppIconKey) { | |
| 950 wm_property = WmWindowProperty::APP_ICON; | |
| 951 } else if (key == aura::client::kDrawAttentionKey) { | |
| 952 wm_property = WmWindowProperty::DRAW_ATTENTION; | |
| 953 } else if (key == aura::client::kModalKey) { | |
| 954 wm_property = WmWindowProperty::MODAL_TYPE; | |
| 955 } else if (key == kPanelAttachedKey) { | |
| 956 wm_property = WmWindowProperty::PANEL_ATTACHED; | |
| 957 } else if (key == kShelfIDKey) { | |
| 958 wm_property = WmWindowProperty::SHELF_ID; | |
| 959 } else if (key == kShelfItemTypeKey) { | |
| 960 wm_property = WmWindowProperty::SHELF_ITEM_TYPE; | |
| 961 } else if (key == kSnapChildrenToPixelBoundary) { | |
| 962 wm_property = WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY; | |
| 963 } else if (key == aura::client::kTopViewInset) { | |
| 964 wm_property = WmWindowProperty::TOP_VIEW_INSET; | |
| 965 } else if (key == aura::client::kWindowIconKey) { | |
| 966 wm_property = WmWindowProperty::WINDOW_ICON; | |
| 967 } else { | |
| 968 return; | |
| 969 } | |
| 970 for (auto& observer : observers_) | |
| 971 observer.OnWindowPropertyChanged(this, wm_property); | |
| 972 } | |
| 973 | |
| 974 void WmWindow::OnWindowBoundsChanged(aura::Window* window, | |
| 975 const gfx::Rect& old_bounds, | |
| 976 const gfx::Rect& new_bounds) { | |
| 977 for (auto& observer : observers_) | |
| 978 observer.OnWindowBoundsChanged(this, old_bounds, new_bounds); | |
| 979 } | |
| 980 | |
| 981 void WmWindow::OnWindowDestroying(aura::Window* window) { | |
| 982 for (auto& observer : observers_) | |
| 983 observer.OnWindowDestroying(this); | |
| 984 } | |
| 985 | |
| 986 void WmWindow::OnWindowDestroyed(aura::Window* window) { | |
| 987 for (auto& observer : observers_) | |
| 988 observer.OnWindowDestroyed(this); | |
| 989 } | |
| 990 | |
| 991 void WmWindow::OnWindowVisibilityChanging(aura::Window* window, bool visible) { | |
| 992 DCHECK_EQ(window, window_); | |
| 993 for (auto& observer : observers_) | |
| 994 observer.OnWindowVisibilityChanging(this, visible); | |
| 995 } | |
| 996 | |
| 997 void WmWindow::OnWindowVisibilityChanged(aura::Window* window, bool visible) { | |
| 998 for (auto& observer : observers_) | |
| 999 observer.OnWindowVisibilityChanged(Get(window), visible); | |
| 1000 } | |
| 1001 | |
| 1002 void WmWindow::OnWindowTitleChanged(aura::Window* window) { | |
| 1003 for (auto& observer : observers_) | |
| 1004 observer.OnWindowTitleChanged(this); | |
| 1005 } | 909 } |
| 1006 | 910 |
| 1007 void WmWindow::OnTransientChildAdded(aura::Window* window, | 911 void WmWindow::OnTransientChildAdded(aura::Window* window, |
| 1008 aura::Window* transient) { | 912 aura::Window* transient) { |
| 1009 for (auto& observer : transient_observers_) | 913 for (auto& observer : transient_observers_) |
| 1010 observer.OnTransientChildAdded(this, Get(transient)); | 914 observer.OnTransientChildAdded(this, Get(transient)); |
| 1011 } | 915 } |
| 1012 | 916 |
| 1013 void WmWindow::OnTransientChildRemoved(aura::Window* window, | 917 void WmWindow::OnTransientChildRemoved(aura::Window* window, |
| 1014 aura::Window* transient) { | 918 aura::Window* transient) { |
| 1015 for (auto& observer : transient_observers_) | 919 for (auto& observer : transient_observers_) |
| 1016 observer.OnTransientChildRemoved(this, Get(transient)); | 920 observer.OnTransientChildRemoved(this, Get(transient)); |
| 1017 } | 921 } |
| 1018 | 922 |
| 1019 } // namespace ash | 923 } // namespace ash |
| OLD | NEW |