Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Sammie Quon | 83146debf | 2018-01-16 17:48:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/wm/overview/overview_utils.h" |
| 6 | |
Lei Zhang | da65e85e | 2018-08-30 18:46:40 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
Katie Dektar | 582ae10 | 2023-12-13 03:15:54 | [diff] [blame] | 9 | #include "ash/accessibility/accessibility_controller.h" |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 10 | #include "ash/public/cpp/shelf_config.h" |
Ahmed Fakhry | 927eabc6 | 2019-05-11 00:14:15 | [diff] [blame] | 11 | #include "ash/public/cpp/window_properties.h" |
Sophie Wen | 3fe03cb | 2023-09-25 20:53:16 | [diff] [blame] | 12 | #include "ash/root_window_controller.h" |
Mitsuru Oshima | c327ca9d | 2019-04-08 23:17:45 | [diff] [blame] | 13 | #include "ash/scoped_animation_disabler.h" |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 14 | #include "ash/screen_util.h" |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 15 | #include "ash/shelf/shelf.h" |
| 16 | #include "ash/shelf/shelf_layout_manager.h" |
wutao | 61d55b8 | 2018-02-15 07:09:38 | [diff] [blame] | 17 | #include "ash/shell.h" |
Sammie Quon | 1f4a8bec | 2020-01-13 19:22:00 | [diff] [blame] | 18 | #include "ash/wm/mru_window_tracker.h" |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 19 | #include "ash/wm/overview/cleanup_animation_observer.h" |
Sammie Quon | f3a420a | 2019-04-12 16:14:54 | [diff] [blame] | 20 | #include "ash/wm/overview/delayed_animation_observer_impl.h" |
Sammie Quon | 80e82a1 | 2019-01-23 19:55:22 | [diff] [blame] | 21 | #include "ash/wm/overview/overview_controller.h" |
Sammie Quon | 16a7627 | 2023-08-29 22:32:35 | [diff] [blame] | 22 | #include "ash/wm/overview/overview_focus_cycler.h" |
Avery Musbach | 8f34929 | 2019-11-12 17:29:53 | [diff] [blame] | 23 | #include "ash/wm/overview/overview_grid.h" |
Sammie Quon | 1f4a8bec | 2020-01-13 19:22:00 | [diff] [blame] | 24 | #include "ash/wm/overview/overview_item.h" |
Yongshun Liu | 0c76bec | 2022-08-18 23:40:57 | [diff] [blame] | 25 | #include "ash/wm/overview/overview_session.h" |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 26 | #include "ash/wm/overview/scoped_overview_animation_settings.h" |
wutao | 61d55b8 | 2018-02-15 07:09:38 | [diff] [blame] | 27 | #include "ash/wm/splitview/split_view_controller.h" |
Sophie Wen | 3fe03cb | 2023-09-25 20:53:16 | [diff] [blame] | 28 | #include "ash/wm/splitview/split_view_overview_session.h" |
Michele Fan | 11c9ad84 | 2023-12-08 01:27:26 | [diff] [blame] | 29 | #include "ash/wm/splitview/split_view_types.h" |
Sammie Quon | 17d0def | 2018-12-14 22:19:15 | [diff] [blame] | 30 | #include "ash/wm/splitview/split_view_utils.h" |
wutao | 61d55b8 | 2018-02-15 07:09:38 | [diff] [blame] | 31 | #include "ash/wm/window_state.h" |
Min Chen | 9620213 | 2018-08-24 22:45:50 | [diff] [blame] | 32 | #include "ash/wm/window_transient_descendant_iterator.h" |
Richard Chui | 6acff532 | 2020-09-21 21:39:19 | [diff] [blame] | 33 | #include "ash/wm/window_util.h" |
Mitsuru Oshima | c327ca9d | 2019-04-08 23:17:45 | [diff] [blame] | 34 | #include "ash/wm/wm_event.h" |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 35 | #include "ash/wm/work_area_insets.h" |
Michele Fan | 3c6da02 | 2023-12-09 00:52:45 | [diff] [blame] | 36 | #include "chromeos/ui/frame/caption_buttons/snap_controller.h" |
Ahmed Fakhry | 363a158 | 2019-05-07 19:11:10 | [diff] [blame] | 37 | #include "ui/aura/client/aura_constants.h" |
wutao | 61d55b8 | 2018-02-15 07:09:38 | [diff] [blame] | 38 | #include "ui/aura/window.h" |
Lei Zhang | 0c04332 | 2021-04-27 16:43:05 | [diff] [blame] | 39 | #include "ui/compositor/layer.h" |
Eriko Kurimoto | 408253e | 2023-11-30 01:04:32 | [diff] [blame] | 40 | #include "ui/display/screen.h" |
Sammie Quon | b9de106 | 2018-02-21 21:58:17 | [diff] [blame] | 41 | #include "ui/gfx/canvas.h" |
Xianzhu Wang | 65ef1ad3 | 2021-10-07 03:12:33 | [diff] [blame] | 42 | #include "ui/gfx/geometry/transform_util.h" |
Sammie Quon | b9de106 | 2018-02-21 21:58:17 | [diff] [blame] | 43 | #include "ui/views/view.h" |
| 44 | #include "ui/views/widget/widget.h" |
Richard Chui | c6ad600e | 2022-08-18 17:21:13 | [diff] [blame] | 45 | #include "ui/views/widget/widget_delegate.h" |
Min Chen | 9620213 | 2018-08-24 22:45:50 | [diff] [blame] | 46 | #include "ui/wm/core/coordinate_conversion.h" |
Sammie Quon | b9de106 | 2018-02-21 21:58:17 | [diff] [blame] | 47 | #include "ui/wm/core/window_animations.h" |
Sammie Quon | 83146debf | 2018-01-16 17:48:14 | [diff] [blame] | 48 | |
| 49 | namespace ash { |
| 50 | |
Sophie Wen | e872b3f | 2023-08-30 02:47:25 | [diff] [blame] | 51 | bool IsInOverviewSession() { |
Michele Fan | a551232 | 2023-10-18 04:46:30 | [diff] [blame] | 52 | OverviewController* overview_controller = OverviewController::Get(); |
Sophie Wen | e872b3f | 2023-08-30 02:47:25 | [diff] [blame] | 53 | return overview_controller && overview_controller->InOverviewSession(); |
| 54 | } |
| 55 | |
| 56 | OverviewSession* GetOverviewSession() { |
Michele Fan | a551232 | 2023-10-18 04:46:30 | [diff] [blame] | 57 | OverviewController* overview_controller = OverviewController::Get(); |
Sophie Wen | e872b3f | 2023-08-30 02:47:25 | [diff] [blame] | 58 | return overview_controller && overview_controller->InOverviewSession() |
| 59 | ? overview_controller->overview_session() |
| 60 | : nullptr; |
| 61 | } |
| 62 | |
wutao | 61d55b8 | 2018-02-15 07:09:38 | [diff] [blame] | 63 | bool CanCoverAvailableWorkspace(aura::Window* window) { |
Sammie Quon | 277c616 | 2023-10-25 03:12:59 | [diff] [blame] | 64 | if (!window) { |
| 65 | return false; |
| 66 | } |
Friedrich [CET] | 7c79100 | 2019-12-03 15:35:35 | [diff] [blame] | 67 | SplitViewController* split_view_controller = SplitViewController::Get(window); |
| 68 | if (split_view_controller->InSplitViewMode()) |
Toshiki Kikuchi | d4dfe5f | 2024-01-11 02:47:03 | [diff] [blame] | 69 | return split_view_controller->CanKeepCurrentSnapRatio(window); |
James Cook | 00e65e9 | 2019-07-25 03:19:08 | [diff] [blame] | 70 | return WindowState::Get(window)->IsMaximizedOrFullscreenOrPinned(); |
wutao | 61d55b8 | 2018-02-15 07:09:38 | [diff] [blame] | 71 | } |
| 72 | |
Toni Barzic | d9238d8f | 2020-10-21 18:47:14 | [diff] [blame] | 73 | void FadeInWidgetToOverview(views::Widget* widget, |
| 74 | OverviewAnimationType animation_type, |
| 75 | bool observe) { |
Sammie Quon | cce7708 | 2018-08-08 17:23:22 | [diff] [blame] | 76 | aura::Window* window = widget->GetNativeWindow(); |
Toni Barzic | d9238d8f | 2020-10-21 18:47:14 | [diff] [blame] | 77 | if (window->layer()->GetTargetOpacity() == 1.f) |
Sammie Quon | cce7708 | 2018-08-08 17:23:22 | [diff] [blame] | 78 | return; |
| 79 | |
Xiaoqian Dai | 97f4956a | 2019-12-04 22:19:01 | [diff] [blame] | 80 | // Fade in the widget from its current opacity. |
Sammie Quon | cce7708 | 2018-08-08 17:23:22 | [diff] [blame] | 81 | ScopedOverviewAnimationSettings scoped_overview_animation_settings( |
Sammie Quon | f118208 | 2018-08-20 18:20:09 | [diff] [blame] | 82 | animation_type, window); |
Sammie Quon | cce7708 | 2018-08-08 17:23:22 | [diff] [blame] | 83 | window->layer()->SetOpacity(1.0f); |
Mitsuru Oshima | 6b7d5bc7 | 2018-11-03 01:00:59 | [diff] [blame] | 84 | |
Sammie Quon | 346d22f | 2019-05-02 16:29:58 | [diff] [blame] | 85 | if (observe) { |
Sammie Quon | e5575e1 | 2019-04-12 23:05:25 | [diff] [blame] | 86 | auto enter_observer = std::make_unique<EnterAnimationObserver>(); |
| 87 | scoped_overview_animation_settings.AddObserver(enter_observer.get()); |
Michele Fan | a551232 | 2023-10-18 04:46:30 | [diff] [blame] | 88 | OverviewController::Get()->AddEnterAnimationObserver( |
Sammie Quon | e5575e1 | 2019-04-12 23:05:25 | [diff] [blame] | 89 | std::move(enter_observer)); |
Mitsuru Oshima | 6b7d5bc7 | 2018-11-03 01:00:59 | [diff] [blame] | 90 | } |
Sammie Quon | cce7708 | 2018-08-08 17:23:22 | [diff] [blame] | 91 | } |
| 92 | |
Sammie Quon | 45981be2 | 2023-12-04 19:16:42 | [diff] [blame] | 93 | void PrepareWidgetForOverviewShutdown(views::Widget* widget) { |
| 94 | // The widget should no longer process events at this point. |
| 95 | widget->SetVisibilityChangedAnimationsEnabled(false); |
| 96 | widget->widget_delegate()->SetCanActivate(false); |
| 97 | widget->GetNativeWindow()->SetEventTargetingPolicy( |
| 98 | aura::EventTargetingPolicy::kNone); |
| 99 | widget->GetContentsView()->SetCanProcessEventsWithinSubtree(false); |
| 100 | widget->GetFocusManager()->set_shortcut_handling_suspended(true); |
| 101 | } |
| 102 | |
Toni Barzic | d9238d8f | 2020-10-21 18:47:14 | [diff] [blame] | 103 | void FadeOutWidgetFromOverview(std::unique_ptr<views::Widget> widget, |
| 104 | OverviewAnimationType animation_type) { |
Sammie Quon | 45981be2 | 2023-12-04 19:16:42 | [diff] [blame] | 105 | PrepareWidgetForOverviewShutdown(widget.get()); |
Richard Chui | c6ad600e | 2022-08-18 17:21:13 | [diff] [blame] | 106 | |
Sammie Quon | 244a5cb | 2019-02-08 17:27:41 | [diff] [blame] | 107 | // The overview controller may be nullptr on shutdown. |
Michele Fan | a551232 | 2023-10-18 04:46:30 | [diff] [blame] | 108 | OverviewController* controller = OverviewController::Get(); |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 109 | if (!controller) { |
| 110 | widget->SetOpacity(0.f); |
| 111 | return; |
| 112 | } |
| 113 | |
Xiaoqian Dai | 97f4956a | 2019-12-04 22:19:01 | [diff] [blame] | 114 | // Fade out the widget from its current opacity. This animation continues past |
| 115 | // the lifetime of overview mode items. |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 116 | ScopedOverviewAnimationSettings animation_settings(animation_type, |
| 117 | widget->GetNativeWindow()); |
| 118 | // CleanupAnimationObserver will delete itself (and the widget) when the |
Sammie Quon | f118208 | 2018-08-20 18:20:09 | [diff] [blame] | 119 | // opacity animation is complete. Ownership over the observer is passed to the |
Sammie Quon | 244a5cb | 2019-02-08 17:27:41 | [diff] [blame] | 120 | // overview controller which has longer lifetime so that animations can |
Sammie Quon | f118208 | 2018-08-20 18:20:09 | [diff] [blame] | 121 | // continue even after the overview mode is shut down. |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 122 | views::Widget* widget_ptr = widget.get(); |
Sammie Quon | 317deb5 | 2018-09-06 16:36:28 | [diff] [blame] | 123 | auto observer = std::make_unique<CleanupAnimationObserver>(std::move(widget)); |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 124 | animation_settings.AddObserver(observer.get()); |
Sammie Quon | f3a420a | 2019-04-12 16:14:54 | [diff] [blame] | 125 | controller->AddExitAnimationObserver(std::move(observer)); |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 126 | widget_ptr->SetOpacity(0.f); |
Sammie Quon | 855e372 | 2018-05-04 02:03:17 | [diff] [blame] | 127 | } |
| 128 | |
Ahmed Fakhry | 38657f2 | 2019-05-02 17:22:56 | [diff] [blame] | 129 | void ImmediatelyCloseWidgetOnExit(std::unique_ptr<views::Widget> widget) { |
Ahmed Fakhry | 363a158 | 2019-05-07 19:11:10 | [diff] [blame] | 130 | widget->GetNativeWindow()->SetProperty(aura::client::kAnimationsDisabledKey, |
| 131 | true); |
Ahmed Fakhry | 38657f2 | 2019-05-02 17:22:56 | [diff] [blame] | 132 | widget->Close(); |
| 133 | widget.reset(); |
| 134 | } |
| 135 | |
Michele Fan | 6e090462 | 2023-10-20 00:25:18 | [diff] [blame] | 136 | gfx::RectF GetUnionScreenBoundsForWindow(aura::Window* window) { |
Sammie Quon | 82fb979 | 2019-02-22 08:42:43 | [diff] [blame] | 137 | gfx::RectF bounds; |
Richard Chui | 6acff532 | 2020-09-21 21:39:19 | [diff] [blame] | 138 | for (auto* window_iter : |
| 139 | window_util::GetVisibleTransientTreeIterator(window)) { |
Sammie Quon | 244a5cb | 2019-02-08 17:27:41 | [diff] [blame] | 140 | // Ignore other window types when computing bounding box of overview target |
| 141 | // item. |
Xiaoqian Dai | 219bf06e | 2018-09-07 16:55:09 | [diff] [blame] | 142 | if (window_iter != window && |
Allen Bauer | 6d2399c | 2021-05-13 16:06:25 | [diff] [blame] | 143 | window_iter->GetType() != aura::client::WINDOW_TYPE_NORMAL) { |
Xiaoqian Dai | 219bf06e | 2018-09-07 16:55:09 | [diff] [blame] | 144 | continue; |
| 145 | } |
Sammie Quon | 82fb979 | 2019-02-22 08:42:43 | [diff] [blame] | 146 | gfx::RectF target_bounds(window_iter->GetTargetBounds()); |
Michele Fan | 6e090462 | 2023-10-20 00:25:18 | [diff] [blame] | 147 | wm::TranslateRectToScreen(window_iter->parent(), &target_bounds); |
Xiaoqian Dai | 219bf06e | 2018-09-07 16:55:09 | [diff] [blame] | 148 | bounds.Union(target_bounds); |
| 149 | } |
Michele Fan | 00c1147 | 2023-10-04 03:47:47 | [diff] [blame] | 150 | |
Xiaoqian Dai | 219bf06e | 2018-09-07 16:55:09 | [diff] [blame] | 151 | return bounds; |
| 152 | } |
| 153 | |
Mitsuru Oshima | c327ca9d | 2019-04-08 23:17:45 | [diff] [blame] | 154 | void MaximizeIfSnapped(aura::Window* window) { |
James Cook | 00e65e9 | 2019-07-25 03:19:08 | [diff] [blame] | 155 | auto* window_state = WindowState::Get(window); |
Mitsuru Oshima | c327ca9d | 2019-04-08 23:17:45 | [diff] [blame] | 156 | if (window_state && window_state->IsSnapped()) { |
| 157 | ScopedAnimationDisabler disabler(window); |
James Cook | 00e65e9 | 2019-07-25 03:19:08 | [diff] [blame] | 158 | WMEvent event(WM_EVENT_MAXIMIZE); |
Mitsuru Oshima | c327ca9d | 2019-04-08 23:17:45 | [diff] [blame] | 159 | window_state->OnWMEvent(&event); |
| 160 | } |
| 161 | } |
| 162 | |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 163 | gfx::Rect GetGridBoundsInScreen(aura::Window* target_root) { |
| 164 | return GetGridBoundsInScreen(target_root, |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 165 | /*window_dragging_state=*/std::nullopt, |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 166 | /*account_for_hotseat=*/true); |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | gfx::Rect GetGridBoundsInScreen( |
Avery Musbach | 8f34929 | 2019-11-12 17:29:53 | [diff] [blame] | 170 | aura::Window* target_root, |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 171 | std::optional<SplitViewDragIndicators::WindowDraggingState> |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 172 | window_dragging_state, |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 173 | bool account_for_hotseat) { |
Avery Musbach | 8f34929 | 2019-11-12 17:29:53 | [diff] [blame] | 174 | auto* split_view_controller = SplitViewController::Get(target_root); |
Michele Fan | 16a0f0c | 2023-06-22 02:55:30 | [diff] [blame] | 175 | SplitViewController::State state = split_view_controller->state(); |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 176 | |
| 177 | // If we are in splitview mode already just use the given state, otherwise |
Sophie Wen | 3fe03cb | 2023-09-25 20:53:16 | [diff] [blame] | 178 | // convert `window_dragging_state` to a split view state. Note this will |
| 179 | // override `state` from `split_view_overview_session` if there is any. |
Avery Musbach | abe3a2d | 2019-11-04 21:51:27 | [diff] [blame] | 180 | if (!split_view_controller->InSplitViewMode() && window_dragging_state) { |
| 181 | switch (*window_dragging_state) { |
Xiaoqian Dai | 6bdc337 | 2022-09-19 23:06:04 | [diff] [blame] | 182 | case SplitViewDragIndicators::WindowDraggingState::kToSnapPrimary: |
| 183 | state = SplitViewController::State::kPrimarySnapped; |
Avery Musbach | abe3a2d | 2019-11-04 21:51:27 | [diff] [blame] | 184 | break; |
Xiaoqian Dai | 6bdc337 | 2022-09-19 23:06:04 | [diff] [blame] | 185 | case SplitViewDragIndicators::WindowDraggingState::kToSnapSecondary: |
| 186 | state = SplitViewController::State::kSecondarySnapped; |
Avery Musbach | abe3a2d | 2019-11-04 21:51:27 | [diff] [blame] | 187 | break; |
| 188 | default: |
| 189 | break; |
| 190 | } |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 191 | } |
| 192 | |
Michele Fan | 50496c61 | 2024-01-26 22:27:57 | [diff] [blame] | 193 | const gfx::Rect work_area = |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 194 | WorkAreaInsets::ForWindow(target_root)->ComputeStableWorkArea(); |
Michele Fan | 50496c61 | 2024-01-26 22:27:57 | [diff] [blame] | 195 | gfx::Rect bounds = work_area; |
Michele Fan | 11c9ad84 | 2023-12-08 01:27:26 | [diff] [blame] | 196 | std::optional<SnapPosition> opposite_position; |
Michele Fan | 16a0f0c | 2023-06-22 02:55:30 | [diff] [blame] | 197 | |
| 198 | // We should show partial overview for the following use cases: |
Michele Fan | 50496c61 | 2024-01-26 22:27:57 | [diff] [blame] | 199 | // 1. In tablet split view mode with one window snapped. |
| 200 | // 2. In clamshell `SplitViewOverviewSession`. |
| 201 | if (auto* split_view_overview_session = |
| 202 | RootWindowController::ForWindow(target_root) |
| 203 | ->split_view_overview_session()) { |
Michele Fan | bb51aa4 | 2024-02-13 00:13:41 | [diff] [blame] | 204 | aura::Window* snapped_window = split_view_overview_session->window(); |
| 205 | gfx::Rect target_bounds_in_screen(snapped_window->GetTargetBounds()); |
| 206 | WindowState* window_state = WindowState::Get(snapped_window); |
| 207 | CHECK(window_state->IsSnapped()); |
| 208 | opposite_position = window_state->GetStateType() == |
| 209 | chromeos::WindowStateType::kPrimarySnapped |
| 210 | ? SnapPosition::kSecondary |
| 211 | : SnapPosition::kPrimary; |
Michele Fan | 50496c61 | 2024-01-26 22:27:57 | [diff] [blame] | 212 | wm::ConvertRectToScreen(target_root, &target_bounds_in_screen); |
| 213 | bounds.Subtract(target_bounds_in_screen); |
Sophie Wen | c1d74e85 | 2023-10-26 21:30:44 | [diff] [blame] | 214 | } else { |
| 215 | switch (state) { |
| 216 | case SplitViewController::State::kPrimarySnapped: |
| 217 | bounds = split_view_controller->GetSnappedWindowBoundsInScreen( |
Michele Fan | 11c9ad84 | 2023-12-08 01:27:26 | [diff] [blame] | 218 | SnapPosition::kSecondary, |
Michele Fan | 3c6da02 | 2023-12-09 00:52:45 | [diff] [blame] | 219 | /*window_for_minimum_size=*/nullptr, chromeos::kDefaultSnapRatio); |
Michele Fan | 11c9ad84 | 2023-12-08 01:27:26 | [diff] [blame] | 220 | opposite_position = SnapPosition::kSecondary; |
Sophie Wen | c1d74e85 | 2023-10-26 21:30:44 | [diff] [blame] | 221 | break; |
| 222 | case SplitViewController::State::kSecondarySnapped: |
| 223 | bounds = split_view_controller->GetSnappedWindowBoundsInScreen( |
Michele Fan | 11c9ad84 | 2023-12-08 01:27:26 | [diff] [blame] | 224 | SnapPosition::kPrimary, |
Michele Fan | 3c6da02 | 2023-12-09 00:52:45 | [diff] [blame] | 225 | /*window_for_minimum_size=*/nullptr, chromeos::kDefaultSnapRatio); |
Michele Fan | 11c9ad84 | 2023-12-08 01:27:26 | [diff] [blame] | 226 | opposite_position = SnapPosition::kPrimary; |
Sophie Wen | c1d74e85 | 2023-10-26 21:30:44 | [diff] [blame] | 227 | break; |
| 228 | case SplitViewController::State::kNoSnap: |
Sophie Wen | c1d74e85 | 2023-10-26 21:30:44 | [diff] [blame] | 229 | break; |
| 230 | case SplitViewController::State::kBothSnapped: |
Michele Fan | 50496c61 | 2024-01-26 22:27:57 | [diff] [blame] | 231 | // When this function is called, SplitViewController should have |
| 232 | // already handled the state change. |
Sophie Wen | c1d74e85 | 2023-10-26 21:30:44 | [diff] [blame] | 233 | NOTREACHED(); |
| 234 | } |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 235 | } |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 236 | |
Richard Chui | 0b0a195 | 2023-02-03 01:22:48 | [diff] [blame] | 237 | // Hotseat overlaps the work area / split view bounds when extended, but in |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 238 | // some cases we don't want its bounds in our calculations. |
Eriko Kurimoto | 408253e | 2023-11-30 01:04:32 | [diff] [blame] | 239 | if (account_for_hotseat && display::Screen::GetScreen()->InTabletMode()) { |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 240 | const bool hotseat_extended = |
Michele Fan | 50496c61 | 2024-01-26 22:27:57 | [diff] [blame] | 241 | Shelf::ForWindow(target_root) |
| 242 | ->shelf_layout_manager() |
| 243 | ->hotseat_state() == HotseatState::kExtended; |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 244 | // When a window is dragged from the top of the screen, overview gets |
| 245 | // entered immediately but the window does not get deactivated right away so |
| 246 | // the hotseat state does not get updated until the window gets dragged a |
| 247 | // bit. In this case, determine whether the hotseat will be extended to |
| 248 | // avoid doing a expensive double grid layout. |
Michele Fan | a551232 | 2023-10-18 04:46:30 | [diff] [blame] | 249 | auto* overview_session = OverviewController::Get()->overview_session(); |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 250 | const bool hotseat_will_extend = |
Richard Chui | 8a39956 | 2023-02-03 05:35:52 | [diff] [blame] | 251 | overview_session && overview_session->ShouldEnterWithoutAnimations() && |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 252 | !split_view_controller->InSplitViewMode(); |
| 253 | if (hotseat_extended || hotseat_will_extend) { |
Andrew Xu | ec9de8e | 2020-05-07 18:24:26 | [diff] [blame] | 254 | // Use the default hotseat size here to avoid the possible re-layout |
| 255 | // due to the update in HotseatWidget::is_forced_dense_. |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 256 | const int hotseat_bottom_inset = |
Andrew Xu | 08bc494 | 2020-06-02 16:43:32 | [diff] [blame] | 257 | ShelfConfig::Get()->GetHotseatSize( |
| 258 | /*density=*/HotseatDensity::kNormal) + |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 259 | ShelfConfig::Get()->hotseat_bottom_padding(); |
Andrew Xu | ec9de8e | 2020-05-07 18:24:26 | [diff] [blame] | 260 | |
Xianzhu Wang | 549ddc4 | 2022-04-04 17:05:55 | [diff] [blame] | 261 | bounds.Inset(gfx::Insets::TLBR(0, 0, hotseat_bottom_inset, 0)); |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Michele Fan | bb51aa4 | 2024-02-13 00:13:41 | [diff] [blame] | 265 | // Clamp the bounds of the overview grid such that it doesn't go below 1/3 of |
| 266 | // the work area length |
sophiewen | e2e8abd | 2023-12-05 18:04:12 | [diff] [blame] | 267 | const bool horizontal = IsLayoutHorizontal(target_root); |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 268 | const int min_length = |
| 269 | (horizontal ? work_area.width() : work_area.height()) / 3; |
| 270 | const int current_length = horizontal ? bounds.width() : bounds.height(); |
| 271 | |
| 272 | if (current_length > min_length) |
| 273 | return bounds; |
| 274 | |
Michele Fan | bb51aa4 | 2024-02-13 00:13:41 | [diff] [blame] | 275 | // Clamp bounds' corresponding length to the minimum length. |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 276 | if (horizontal) |
| 277 | bounds.set_width(min_length); |
| 278 | else |
| 279 | bounds.set_height(min_length); |
| 280 | |
Michele Fan | bb51aa4 | 2024-02-13 00:13:41 | [diff] [blame] | 281 | // These changes below are crucial for better visualization and help |
| 282 | // preventing crashes when dragging the snapped window towards the edge. In |
| 283 | // this case, the overview components will become too small to allow any |
| 284 | // gradient painting on desk bar or applying shadows. Please ensure to go |
| 285 | // through the bounds update below when one window is snapped in overview both |
| 286 | // in clamshell and tablet mode. See the regression behavior in |
| 287 | // http://b/324478757. |
| 288 | if (opposite_position && |
| 289 | IsPhysicalLeftOrTop(*opposite_position, target_root)) { |
Sammie Quon | 625b56a | 2019-12-27 20:15:38 | [diff] [blame] | 290 | // If we are shifting to the left or top we need to update the origin as |
| 291 | // well. |
| 292 | const int offset = min_length - current_length; |
| 293 | bounds.Offset(horizontal ? gfx::Vector2d(-offset, 0) |
| 294 | : gfx::Vector2d(0, -offset)); |
| 295 | } |
| 296 | |
| 297 | return bounds; |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 298 | } |
| 299 | |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 300 | std::optional<gfx::RectF> GetSplitviewBoundsMaintainingAspectRatio() { |
Eriko Kurimoto | 408253e | 2023-11-30 01:04:32 | [diff] [blame] | 301 | if (!ShouldAllowSplitView()) { |
| 302 | return absl::nullopt; |
| 303 | } |
| 304 | if (!display::Screen::GetScreen()->InTabletMode()) { |
| 305 | return absl::nullopt; |
| 306 | } |
Michele Fan | a551232 | 2023-10-18 04:46:30 | [diff] [blame] | 307 | auto* overview_session = OverviewController::Get()->overview_session(); |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 308 | DCHECK(overview_session); |
Avery Musbach | 8f34929 | 2019-11-12 17:29:53 | [diff] [blame] | 309 | aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 310 | DCHECK(overview_session->GetGridWithRootWindow(root_window) |
| 311 | ->split_view_drag_indicators()); |
Avery Musbach | 8f34929 | 2019-11-12 17:29:53 | [diff] [blame] | 312 | auto window_dragging_state = |
| 313 | overview_session->GetGridWithRootWindow(root_window) |
| 314 | ->split_view_drag_indicators() |
| 315 | ->current_window_dragging_state(); |
| 316 | if (!SplitViewController::Get(root_window)->InSplitViewMode() && |
Avery Musbach | abe3a2d | 2019-11-04 21:51:27 | [diff] [blame] | 317 | SplitViewDragIndicators::GetSnapPosition(window_dragging_state) == |
Michele Fan | 11c9ad84 | 2023-12-08 01:27:26 | [diff] [blame] | 318 | SnapPosition::kNone) { |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 319 | return std::nullopt; |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 320 | } |
| 321 | |
Sammie Quon | 3e9f42b | 2020-01-04 02:42:54 | [diff] [blame] | 322 | // The hotseat bounds do not affect splitview after a window is snapped, so |
| 323 | // the aspect ratio should reflect it and not worry about the hotseat. |
Lei Zhang | f2166c6 | 2022-09-17 02:03:11 | [diff] [blame] | 324 | return gfx::RectF(GetGridBoundsInScreen(root_window, window_dragging_state, |
Lei Zhang | f2166c6 | 2022-09-17 02:03:11 | [diff] [blame] | 325 | /*account_for_hotseat=*/false)); |
Sammie Quon | 8cf3df2 | 2019-10-21 17:52:23 | [diff] [blame] | 326 | } |
| 327 | |
Danton Vu | 1cc0aa84 | 2019-07-31 19:04:49 | [diff] [blame] | 328 | bool ShouldUseTabletModeGridLayout() { |
Eriko Kurimoto | 408253e | 2023-11-30 01:04:32 | [diff] [blame] | 329 | return display::Screen::GetScreen()->InTabletMode(); |
Danton Vu | 1cc0aa84 | 2019-07-31 19:04:49 | [diff] [blame] | 330 | } |
| 331 | |
Mitsuru Oshima | fff5741c | 2019-12-10 00:00:11 | [diff] [blame] | 332 | gfx::Rect ToStableSizeRoundedRect(const gfx::RectF& rect) { |
| 333 | return gfx::Rect(gfx::ToRoundedPoint(rect.origin()), |
| 334 | gfx::ToRoundedSize(rect.size())); |
| 335 | } |
| 336 | |
Sammie Quon | 96c640d | 2023-09-01 22:44:54 | [diff] [blame] | 337 | void MoveFocusToView(OverviewFocusableView* target_view) { |
Michele Fan | a551232 | 2023-10-18 04:46:30 | [diff] [blame] | 338 | auto* overview_session = OverviewController::Get()->overview_session(); |
Sammie Quon | 1ab58e27 | 2023-10-04 17:34:35 | [diff] [blame] | 339 | CHECK(overview_session); |
| 340 | |
| 341 | auto* focus_cycler = overview_session->focus_cycler(); |
Sammie Quon | 16a7627 | 2023-08-29 22:32:35 | [diff] [blame] | 342 | CHECK(focus_cycler); |
Yongshun Liu | 0c76bec | 2022-08-18 23:40:57 | [diff] [blame] | 343 | |
Sammie Quon | 16a7627 | 2023-08-29 22:32:35 | [diff] [blame] | 344 | focus_cycler->MoveFocusToView(target_view); |
Yongshun Liu | 0c76bec | 2022-08-18 23:40:57 | [diff] [blame] | 345 | } |
| 346 | |
Sammie Quon | 277c616 | 2023-10-25 03:12:59 | [diff] [blame] | 347 | void SetWindowsVisibleDuringItemDragging(const aura::Window::Windows& windows, |
| 348 | bool visible, |
| 349 | bool animate) { |
| 350 | float new_opacity = visible ? 1.f : 0.f; |
Ali Hijazi | e63cbaf6 | 2023-12-20 19:29:35 | [diff] [blame] | 351 | for (aura::Window* window : windows) { |
Sammie Quon | 277c616 | 2023-10-25 03:12:59 | [diff] [blame] | 352 | ui::Layer* layer = window->layer(); |
| 353 | if (layer->GetTargetOpacity() == new_opacity) { |
| 354 | continue; |
| 355 | } |
| 356 | |
| 357 | if (animate) { |
| 358 | ScopedOverviewAnimationSettings settings( |
| 359 | OVERVIEW_ANIMATION_OPACITY_ON_WINDOW_DRAG, window); |
| 360 | layer->SetOpacity(new_opacity); |
| 361 | } else { |
| 362 | layer->SetOpacity(new_opacity); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
Sammie Quon | 83146debf | 2018-01-16 17:48:14 | [diff] [blame] | 367 | } // namespace ash |