Commit 017cad77 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

Tab dragging: Update the dragged window's bounds before adding to overview.

Before the dragged window is added to overview, its bounds might needs
to update as the dragged window's bounds might have changed during
dragging and as a result its transform might be different with other
window's transform in overview.

Bug: 873284
Change-Id: I1257f8d4526b62bcf6d3174f611bc4d576818755
Reviewed-on: https://chromium-review.googlesource.com/1180376
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarMitsuru Oshima (Slow) <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584821}
parent 38906838
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "ash/wm/overview/window_selector_delegate.h" #include "ash/wm/overview/window_selector_delegate.h"
#include "ash/wm/overview/window_selector_item.h" #include "ash/wm/overview/window_selector_item.h"
#include "ash/wm/splitview/split_view_drag_indicators.h" #include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ash/wm/tablet_mode/tablet_mode_window_state.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "base/i18n/string_search.h" #include "base/i18n/string_search.h"
#include "base/numerics/ranges.h" #include "base/numerics/ranges.h"
...@@ -700,6 +701,21 @@ void WindowGrid::OnWindowDragEnded(aura::Window* dragged_window, ...@@ -700,6 +701,21 @@ void WindowGrid::OnWindowDragEnded(aura::Window* dragged_window,
// end of this function. // end of this function.
if (SelectedWindow()) { if (SelectedWindow()) {
if (IsNewSelectorItemWindow(SelectedWindow()->GetWindow())) { if (IsNewSelectorItemWindow(SelectedWindow()->GetWindow())) {
// Update the dragged window's bounds before adding it to overview. The
// dragged window might have resized to a smaller size if the drag
// happens on tab(s).
const gfx::Rect old_bounds = dragged_window->bounds();
TabletModeWindowState::UpdateWindowPosition(
wm::GetWindowState(dragged_window));
const gfx::Rect new_bounds = dragged_window->bounds();
if (old_bounds != new_bounds) {
// It's for smoother animation.
gfx::Transform transform =
ScopedTransformOverviewWindow::GetTransformForRect(new_bounds,
old_bounds);
dragged_window->SetTransform(transform);
}
window_selector_->AddItem(dragged_window, /*reposition=*/false, window_selector_->AddItem(dragged_window, /*reposition=*/false,
/*animate=*/false); /*animate=*/false);
} }
......
...@@ -2443,6 +2443,44 @@ TEST_F(SplitViewTabDraggingTest, AdjustOverviewBoundsDuringDragging) { ...@@ -2443,6 +2443,44 @@ TEST_F(SplitViewTabDraggingTest, AdjustOverviewBoundsDuringDragging) {
CompleteDrag(std::move(resizer)); CompleteDrag(std::move(resizer));
} }
// Tests that a dragged window's bounds should be updated before dropping onto
// the new selector item to add into overview.
TEST_F(SplitViewTabDraggingTest, WindowBoundsUpdatedBeforeAddingToOverview) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
const gfx::Rect tablet_mode_bounds = window1->bounds();
EXPECT_NE(bounds, tablet_mode_bounds);
// Drag |window1|. Overview should open behind the dragged window.
std::unique_ptr<WindowResizer> resizer =
StartDrag(window1.get(), window1.get());
EXPECT_TRUE(Shell::Get()->window_selector_controller()->IsSelecting());
// Change the |window1|'s bounds to simulate what might happen in reality.
window1->SetBounds(bounds);
EXPECT_EQ(bounds, window1->bounds());
// Drop |window1| to the new selector item in overview.
WindowSelector* window_selector =
Shell::Get()->window_selector_controller()->window_selector();
WindowGrid* current_grid =
window_selector->GetGridWithRootWindow(window1->GetRootWindow());
ASSERT_TRUE(current_grid);
EXPECT_EQ(1u, current_grid->window_list().size());
WindowSelectorItem* new_selector_item = current_grid->GetNewSelectorItem();
ASSERT_TRUE(new_selector_item);
const gfx::Rect new_selector_bounds = new_selector_item->target_bounds();
DragWindowTo(resizer.get(), new_selector_bounds.CenterPoint());
CompleteDrag(std::move(resizer));
// |window1| should have been merged into overview.
EXPECT_EQ(current_grid->window_list().size(), 1u);
EXPECT_TRUE(window_selector->IsWindowInOverview(window1.get()));
// |wiindow1|'s bounds should have been updated to its tablet mode bounds.
EXPECT_EQ(tablet_mode_bounds, window1->bounds());
}
class TestWindowDelegateWithWidget : public views::WidgetDelegate { class TestWindowDelegateWithWidget : public views::WidgetDelegate {
public: public:
TestWindowDelegateWithWidget(bool can_activate) TestWindowDelegateWithWidget(bool can_activate)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment