[go: nahoru, domu]

WebUI tab strip: support drop tab into overview mode

In WebUI tab strip, the browser window is created only when a tab is
dropped. This CL implements dropping the newly created browser
window to overview when the drop point is over the overview window and
not in the snapping zone.

Bug: 1257840
Change-Id: I4b9d824f44fdea077c56bd25f93c15840c905396
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3438047
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Commit-Queue: Yuheng Huang <yuhengh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#970154}
diff --git a/ash/drag_drop/tab_drag_drop_delegate.cc b/ash/drag_drop/tab_drag_drop_delegate.cc
index a8ea436..9f5e6a9 100644
--- a/ash/drag_drop/tab_drag_drop_delegate.cc
+++ b/ash/drag_drop/tab_drag_drop_delegate.cc
@@ -12,6 +12,8 @@
 #include "ash/screen_util.h"
 #include "ash/shell.h"
 #include "ash/shell_delegate.h"
+#include "ash/wm/overview/overview_controller.h"
+#include "ash/wm/overview/overview_session.h"
 #include "ash/wm/splitview/split_view_constants.h"
 #include "ash/wm/splitview/split_view_controller.h"
 #include "ash/wm/splitview/split_view_drag_indicators.h"
@@ -66,6 +68,14 @@
   return app_type == AppType::LACROS;
 }
 
+// Returns the overview session if overview mode is active, otherwise returns
+// nullptr.
+OverviewSession* GetOverviewSession() {
+  return Shell::Get()->overview_controller()->InOverviewSession()
+             ? Shell::Get()->overview_controller()->overview_session()
+             : nullptr;
+}
+
 }  // namespace
 
 // static
@@ -167,17 +177,20 @@
       screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
           root_window_);
 
-  SplitViewController::SnapPosition snap_position = ash::GetSnapPosition(
-      root_window_, new_window, location_in_screen, start_location_in_screen_,
-      /*snap_distance_from_edge=*/kDistanceFromEdgeDp,
-      /*minimum_drag_distance=*/kMinimumDragToSnapDistanceDp,
-      /*horizontal_edge_inset=*/area.width() *
-              kHighlightScreenPrimaryAxisRatio +
-          kHighlightScreenEdgePaddingDp,
-      /*vertical_edge_inset=*/area.height() * kHighlightScreenPrimaryAxisRatio +
-          kHighlightScreenEdgePaddingDp);
+  SplitViewController::SnapPosition snap_position_in_snapping_zone =
+      ash::GetSnapPosition(
+          root_window_, new_window, location_in_screen,
+          start_location_in_screen_,
+          /*snap_distance_from_edge=*/kDistanceFromEdgeDp,
+          /*minimum_drag_distance=*/kMinimumDragToSnapDistanceDp,
+          /*horizontal_edge_inset=*/area.width() *
+                  kHighlightScreenPrimaryAxisRatio +
+              kHighlightScreenEdgePaddingDp,
+          /*vertical_edge_inset=*/area.height() *
+                  kHighlightScreenPrimaryAxisRatio +
+              kHighlightScreenEdgePaddingDp);
 
-  if (snap_position == SplitViewController::SnapPosition::NONE)
+  if (snap_position_in_snapping_zone == SplitViewController::SnapPosition::NONE)
     RestoreSourceWindowBounds();
 
   // This must be done after restoring the source window's bounds since
@@ -190,6 +203,8 @@
   // If it's already in split view mode, either snap the new window
   // to the left or the right depending on the drop location.
   const bool in_split_view_mode = split_view_controller->InSplitViewMode();
+  SplitViewController::SnapPosition snap_position =
+      snap_position_in_snapping_zone;
   if (in_split_view_mode) {
     snap_position =
         split_view_controller->ComputeSnapPosition(location_in_screen);
@@ -198,8 +213,20 @@
   if (snap_position == SplitViewController::SnapPosition::NONE)
     return;
 
-  split_view_controller->SnapWindow(new_window, snap_position,
-                                    /*activate_window=*/true);
+  OverviewSession* overview_session = GetOverviewSession();
+  // If overview session is present on the other side and the new window is
+  // about to snap to that side but not in the snapping zone then drop the new
+  // window into overview.
+  if (overview_session &&
+      snap_position_in_snapping_zone ==
+          SplitViewController::SnapPosition::NONE &&
+      split_view_controller->GetPositionOfSnappedWindow(source_window_) !=
+          snap_position) {
+    overview_session->MergeWindowIntoOverviewForWebUITabStrip(new_window);
+  } else {
+    split_view_controller->SnapWindow(new_window, snap_position,
+                                      /*activate_window=*/true);
+  }
 
   // Do not snap the source window if already in split view mode.
   if (in_split_view_mode)