summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvarkha <varkha@chromium.org>2015-06-06 16:13:49 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-06 23:14:22 +0000
commit3cf4fa484a5aa92211f937148c9ab80d6f0be163 (patch)
tree3a852316eb43b8dfb2a5bee8ba94a66bc110f630
parentdfbf569c4c37aa656c9320abf837e4f0649661a5 (diff)
downloadchromium_src-3cf4fa484a5aa92211f937148c9ab80d6f0be163.zip
chromium_src-3cf4fa484a5aa92211f937148c9ab80d6f0be163.tar.gz
chromium_src-3cf4fa484a5aa92211f937148c9ab80d6f0be163.tar.bz2
Fixes tab dragging out of a window with maximzied bounds
The breaking change was a fix for http://crbug.com/392599 (https://codereview.chromium.org/424463002/) that causes a browser window to be maximized at creation time if its size is as big as a work area. When a tab is dragged into a new browser window this new window may be maximized and so not draggable. BUG=491502 TEST=DetachToBrowserTabDragControllerTest.DetachFromFullsizeWindow Review URL: https://codereview.chromium.org/1156893008 Cr-Commit-Position: refs/heads/master@{#333220}
-rw-r--r--ash/wm/default_state.cc10
-rw-r--r--chrome/browser/ui/views/tabs/tab_drag_controller.cc20
-rw-r--r--chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc68
3 files changed, 95 insertions, 3 deletions
diff --git a/ash/wm/default_state.cc b/ash/wm/default_state.cc
index 61a3dc6..58e00b7 100644
--- a/ash/wm/default_state.cc
+++ b/ash/wm/default_state.cc
@@ -31,6 +31,11 @@ namespace {
// must be visible when the window is added to the workspace.
const float kMinimumPercentOnScreenArea = 0.3f;
+// When a window that has restore bounds at least as large as a work area is
+// unmaximized, inset the bounds slightly so that they are not exactly the same.
+// This makes it easier to resize the window.
+const int kMaximizedWindowInset = 10; // Pixels.
+
bool IsMinimizedWindowState(const WindowStateType state_type) {
return state_type == WINDOW_STATE_TYPE_MINIMIZED ||
state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED;
@@ -643,10 +648,9 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state,
if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED &&
bounds_in_parent.width() >= work_area_in_parent.width() &&
bounds_in_parent.height() >= work_area_in_parent.height()) {
- // Inset the bounds slightly so that they are not exactly same as
- // the work area bounds and it is easier to resize the window.
bounds_in_parent = work_area_in_parent;
- bounds_in_parent.Inset(10, 10, 10, 10);
+ bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset,
+ kMaximizedWindowInset, kMaximizedWindowInset);
}
} else {
bounds_in_parent = window->bounds();
diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.cc b/chrome/browser/ui/views/tabs/tab_drag_controller.cc
index 53e78b4..b3461fe 100644
--- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc
+++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc
@@ -77,6 +77,12 @@ const int kHorizontalMoveThreshold = 16; // Pixels.
// close enough to trigger moving.
const int kStackedDistance = 36;
+// A dragged window is forced to be a bit smaller than maximized bounds during a
+// drag. This prevents the dragged browser widget from getting maximized at
+// creation and makes it easier to drag tabs out of a restored window that had
+// maximized size.
+const int kMaximizedWindowInset = 10; // Pixels.
+
#if defined(USE_ASH)
void SetWindowPositionManaged(gfx::NativeWindow window, bool value) {
ash::wm::GetWindowState(window)->set_window_position_managed(value);
@@ -1640,6 +1646,20 @@ gfx::Rect TabDragController::CalculateDraggedBrowserBounds(
gfx::Point center(0, source->height() / 2);
views::View::ConvertPointToWidget(source, &center);
gfx::Rect new_bounds(source->GetWidget()->GetRestoredBounds());
+
+ gfx::Rect work_area =
+ screen_->GetDisplayNearestPoint(last_point_in_screen_).work_area();
+ if (new_bounds.size().width() >= work_area.size().width() &&
+ new_bounds.size().height() >= work_area.size().height()) {
+ new_bounds = work_area;
+ new_bounds.Inset(kMaximizedWindowInset, kMaximizedWindowInset,
+ kMaximizedWindowInset, kMaximizedWindowInset);
+ // Behave as if the |source| was maximized at the start of a drag since this
+ // is consistent with a browser window creation logic in case of windows
+ // that are as large as the |work_area|.
+ was_source_maximized_ = true;
+ }
+
if (source->GetWidget()->IsMaximized()) {
// If the restore bounds is really small, we don't want to honor it
// (dragging a really small window looks wrong), instead make sure the new
diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc b/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc
index f69b34c..2790730 100644
--- a/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc
+++ b/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc
@@ -795,6 +795,74 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
#if defined(OS_CHROMEOS) || defined(OS_LINUX)
// TODO(sky,sad): Disabled as it fails due to resize locks with a real
// compositor. crbug.com/331924
+#define MAYBE_DetachFromFullsizeWindow DISABLED_DetachFromFullsizeWindow
+#else
+#define MAYBE_DetachFromFullsizeWindow DetachFromFullsizeWindow
+#endif
+// Tests that a tab can be dragged from a browser window that is resized to full
+// screen.
+IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
+ MAYBE_DetachFromFullsizeWindow) {
+ // Resize the browser window so that it is as big as the work area.
+ gfx::Rect work_area =
+ gfx::Screen::GetNativeScreen()
+ ->GetDisplayNearestWindow(browser()->window()->GetNativeWindow())
+ .work_area();
+ browser()->window()->SetBounds(work_area);
+ const gfx::Rect initial_bounds(browser()->window()->GetBounds());
+ // Add another tab.
+ AddTabAndResetBrowser(browser());
+ TabStrip* tab_strip = GetTabStripForBrowser(browser());
+
+ // Move to the first tab and drag it enough so that it detaches.
+ gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
+ ASSERT_TRUE(PressInput(tab_0_center));
+ ASSERT_TRUE(DragInputToNotifyWhenDone(
+ tab_0_center.x(), tab_0_center.y() + GetDetachY(tab_strip),
+ base::Bind(&DetachToOwnWindowStep2, this)));
+ if (input_source() == INPUT_SOURCE_MOUSE) {
+ ASSERT_TRUE(ReleaseMouseAsync());
+ QuitWhenNotDragging();
+ }
+
+ // Should no longer be dragging.
+ ASSERT_FALSE(tab_strip->IsDragSessionActive());
+ ASSERT_FALSE(TabDragController::IsActive());
+
+ // There should now be another browser.
+ ASSERT_EQ(2u, native_browser_list->size());
+ Browser* new_browser = native_browser_list->get(1);
+ ASSERT_TRUE(new_browser->window()->IsActive());
+ TabStrip* tab_strip2 = GetTabStripForBrowser(new_browser);
+ ASSERT_FALSE(tab_strip2->IsDragSessionActive());
+
+ EXPECT_EQ("0", IDString(new_browser->tab_strip_model()));
+ EXPECT_EQ("1", IDString(browser()->tab_strip_model()));
+
+ // The bounds of the initial window should not have changed.
+ EXPECT_EQ(initial_bounds.ToString(),
+ browser()->window()->GetBounds().ToString());
+
+ EXPECT_FALSE(GetIsDragged(browser()));
+ EXPECT_FALSE(GetIsDragged(new_browser));
+ // After this both windows should still be manageable.
+ EXPECT_TRUE(IsWindowPositionManaged(browser()->window()->GetNativeWindow()));
+ EXPECT_TRUE(
+ IsWindowPositionManaged(new_browser->window()->GetNativeWindow()));
+
+ // Only second window should be maximized.
+ EXPECT_FALSE(browser()->window()->IsMaximized());
+ EXPECT_TRUE(new_browser->window()->IsMaximized());
+
+ // The tab strip should no longer have capture because the drag was ended and
+ // mouse/touch was released.
+ EXPECT_FALSE(tab_strip->GetWidget()->HasCapture());
+ EXPECT_FALSE(tab_strip2->GetWidget()->HasCapture());
+}
+
+#if defined(OS_CHROMEOS) || defined(OS_LINUX)
+// TODO(sky,sad): Disabled as it fails due to resize locks with a real
+// compositor. crbug.com/331924
#define MAYBE_DetachToOwnWindowFromMaximizedWindow \
DISABLED_DetachToOwnWindowFromMaximizedWindow
#else