Skip to content

Commit

Permalink
Only allow dragging on a browser window's caption area.
Browse files Browse the repository at this point in the history
In tablet mode, we only allow dragging on a browser window's caption area.
Other windows dragging on non-caption area should be handled by
TabletModeAppDragController.

Bug: 823769
Change-Id: I3da88ad7a88c8a39e576aa268331af0e09045def
Reviewed-on: https://chromium-review.googlesource.com/1187732
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585974}
  • Loading branch information
Xiaoqian Dai authored and Commit Bot committed Aug 24, 2018
1 parent 0a96157 commit 41e6543
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 35 deletions.
96 changes: 62 additions & 34 deletions ash/wm/splitview/split_view_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class SplitViewControllerTest : public AshTestBase {

int divider_position() { return split_view_controller()->divider_position(); }

private:
protected:
class SplitViewTestWindowDelegate : public aura::test::TestWindowDelegate {
public:
SplitViewTestWindowDelegate() = default;
Expand All @@ -167,6 +167,7 @@ class SplitViewControllerTest : public AshTestBase {
void OnWindowDestroyed(aura::Window* window) override { delete this; }
};

private:
DISALLOW_COPY_AND_ASSIGN(SplitViewControllerTest);
};

Expand Down Expand Up @@ -1606,6 +1607,16 @@ class SplitViewTabDraggingTest : public SplitViewControllerTest {
~SplitViewTabDraggingTest() override = default;

protected:
aura::Window* CreateBrowserTypeWindow(
const gfx::Rect& bounds,
aura::client::WindowType type = aura::client::WINDOW_TYPE_NORMAL) {
aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
new SplitViewTestWindowDelegate, type, -1, bounds);
window->SetProperty(aura::client::kAppType,
static_cast<int>(AppType::BROWSER));
return window;
}

// Starts tab dragging on |dragged_window|. |source_window| indicates which
// window the drag originates from. Returns the newly created WindowResizer
// for the |dragged_window|.
Expand Down Expand Up @@ -1701,11 +1712,28 @@ class SplitViewTabDraggingTest : public SplitViewControllerTest {
DISALLOW_COPY_AND_ASSIGN(SplitViewTabDraggingTest);
};

// Test that in tablet mode, we only allow dragging on browser window's caption
// area.
TEST_F(SplitViewTabDraggingTest, OnlyAllowDraggingOnBrowserWindow) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));

std::unique_ptr<WindowResizer> resizer =
CreateResizerForTest(window1.get(), gfx::Point(), HTCAPTION);
EXPECT_TRUE(resizer.get());
resizer->CompleteDrag();
resizer.reset();

resizer = CreateResizerForTest(window2.get(), gfx::Point(), HTCAPTION);
EXPECT_FALSE(resizer.get());
}

// Test that in tablet mode, we only allow dragging that happens on window
// caption area.
TEST_F(SplitViewTabDraggingTest, OnlyAllowDraggingOnCaptionArea) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
std::unique_ptr<aura::Window> window(CreateBrowserTypeWindow(bounds));

// Only dragging on HTCAPTION area is allowed.
std::unique_ptr<WindowResizer> resizer =
Expand Down Expand Up @@ -1737,7 +1765,7 @@ TEST_F(SplitViewTabDraggingTest, OnlyAllowDraggingOnCaptionArea) {
// cursor should be properly locked.
TEST_F(SplitViewTabDraggingTest, LockCursor) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
std::unique_ptr<aura::Window> window(CreateBrowserTypeWindow(bounds));
SetIsInTabDragging(window.get(), /*is_dragging=*/true);
EXPECT_FALSE(Shell::Get()->cursor_manager()->IsCursorLocked());

Expand All @@ -1755,7 +1783,7 @@ TEST_F(SplitViewTabDraggingTest, LockCursor) {
// backdrop is disabled during dragging process.
TEST_F(SplitViewTabDraggingTest, NoBackDropDuringDragging) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
std::unique_ptr<aura::Window> window(CreateBrowserTypeWindow(bounds));
EXPECT_EQ(window->GetProperty(kBackdropWindowMode),
BackdropWindowMode::kAuto);

Expand All @@ -1778,8 +1806,8 @@ TEST_F(SplitViewTabDraggingTest, NoBackDropDuringDragging) {
// not be shown in overview mode.
TEST_F(SplitViewTabDraggingTest, DoNotShowDraggedWindowInOverview) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));

Shell::Get()->window_selector_controller()->ToggleOverview();
EXPECT_TRUE(Shell::Get()->window_selector_controller()->IsSelecting());
Expand Down Expand Up @@ -1808,8 +1836,8 @@ TEST_F(SplitViewTabDraggingTest, DoNotShowDraggedWindowInOverview) {
// below the current dragged window.
TEST_F(SplitViewTabDraggingTest, DividerIsBelowDraggedWindow) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));

split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
split_view_controller()->SnapWindow(window2.get(),
Expand All @@ -1835,8 +1863,8 @@ TEST_F(SplitViewTabDraggingTest, DividerIsBelowDraggedWindow) {
TEST_F(SplitViewTabDraggingTest, DragMaximizedWindow) {
UpdateDisplay("600x600");
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
wm::GetWindowState(window1.get())->Maximize();
wm::GetWindowState(window2.get())->Maximize();
EXPECT_TRUE(wm::GetWindowState(window1.get())->IsMaximized());
Expand Down Expand Up @@ -1960,9 +1988,9 @@ TEST_F(SplitViewTabDraggingTest, DragMaximizedWindow) {
TEST_F(SplitViewTabDraggingTest, DragSnappedWindow) {
UpdateDisplay("600x600");
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateBrowserTypeWindow(bounds));

split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
split_view_controller()->SnapWindow(window2.get(),
Expand Down Expand Up @@ -2036,7 +2064,7 @@ TEST_F(SplitViewTabDraggingTest, DragSnappedWindow) {
EXPECT_TRUE(Shell::Get()->window_selector_controller()->IsSelecting());

// Recreate |window1| and snap it to test the following senarioes.
window1.reset(CreateWindow(bounds));
window1.reset(CreateBrowserTypeWindow(bounds));
split_view_controller()->SnapWindow(window1.get(),
SplitViewController::RIGHT);
EXPECT_EQ(split_view_controller()->state(),
Expand Down Expand Up @@ -2105,9 +2133,9 @@ TEST_F(SplitViewTabDraggingTest, DragSnappedWindow) {
TEST_F(SplitViewTabDraggingTest, DragSnappedWindowWhileOverviewOpen) {
UpdateDisplay("600x600");
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateBrowserTypeWindow(bounds));

// Prepare the testing senario:
split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
Expand Down Expand Up @@ -2226,9 +2254,9 @@ TEST_F(SplitViewTabDraggingTest, DragSnappedWindowWhileOverviewOpen) {
// the drag ends.
TEST_F(SplitViewTabDraggingTest, ShowNewWindowItemWhenDragStarts) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateBrowserTypeWindow(bounds));

split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
split_view_controller()->SnapWindow(window2.get(),
Expand Down Expand Up @@ -2284,9 +2312,9 @@ TEST_F(SplitViewTabDraggingTest, ShowNewWindowItemWhenDragStarts) {
// should not do animation when exiting overview.
TEST_F(SplitViewTabDraggingTest, OverviewExitAnimationTest) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateBrowserTypeWindow(bounds));
std::unique_ptr<OverviewStatesObserver> overview_observer =
std::make_unique<OverviewStatesObserver>(window1->GetRootWindow());

Expand Down Expand Up @@ -2342,7 +2370,7 @@ TEST_F(SplitViewTabDraggingTest, DragIndicatorsInPortraitOrientationTest) {
OrientationLockType::kLandscapePrimary);

const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
std::unique_ptr<aura::Window> window(CreateBrowserTypeWindow(bounds));
wm::GetWindowState(window.get())->Maximize();
EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
std::unique_ptr<WindowResizer> resizer =
Expand Down Expand Up @@ -2375,9 +2403,9 @@ TEST_F(SplitViewTabDraggingTest, DragIndicatorsInPortraitOrientationTest) {
// should be adjusted accordingly.
TEST_F(SplitViewTabDraggingTest, AdjustOverviewBoundsDuringDragging) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateBrowserTypeWindow(bounds));

WindowSelectorController* selector_controller =
Shell::Get()->window_selector_controller();
Expand Down Expand Up @@ -2476,7 +2504,7 @@ TEST_F(SplitViewTabDraggingTest, AdjustOverviewBoundsDuringDragging) {
// 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));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
const gfx::Rect tablet_mode_bounds = window1->bounds();
EXPECT_NE(bounds, tablet_mode_bounds);

Expand Down Expand Up @@ -2518,8 +2546,8 @@ TEST_F(SplitViewTabDraggingTest, WindowBoundsUpdatedBeforeAddingToOverview) {
// dragging.
TEST_F(SplitViewTabDraggingTest, DraggedWindowShouldHaveActiveWindowShadow) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
wm::ActivateWindow(window1.get());
wm::ActivateWindow(window2.get());
window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
Expand Down Expand Up @@ -2560,10 +2588,10 @@ TEST_F(SplitViewTabDraggingTest, DraggedWindowShouldHaveActiveWindowShadow) {
// visibility should change accordingly.
TEST_F(SplitViewTabDraggingTest, SourceWindowBackgroundTest) {
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateWindow(bounds));
std::unique_ptr<aura::Window> window4(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window3(CreateBrowserTypeWindow(bounds));
std::unique_ptr<aura::Window> window4(CreateBrowserTypeWindow(bounds));
EXPECT_TRUE(window1->IsVisible());
EXPECT_TRUE(window2->IsVisible());
EXPECT_TRUE(window3->IsVisible());
Expand Down
8 changes: 7 additions & 1 deletion ash/wm/workspace/workspace_window_resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <utility>
#include <vector>

#include "ash/public/cpp/app_types.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
Expand All @@ -25,9 +26,11 @@
#include "ash/wm/workspace/two_step_edge_cycler.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/user_metrics.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_types.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/class_property.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/layer.h"
#include "ui/display/display.h"
Expand Down Expand Up @@ -69,8 +72,11 @@ std::unique_ptr<WindowResizer> CreateWindowResizer(
!window_state->IsPip()) {
// We still don't allow any dragging or resizing happening on the area other
// then caption area.
if (window_component != HTCAPTION)
if (window_component != HTCAPTION ||
window->GetProperty(aura::client::kAppType) !=
static_cast<int>(AppType::BROWSER)) {
return nullptr;
}

window_state->CreateDragDetails(point_in_parent, window_component, source);
window_resizer =
Expand Down

0 comments on commit 41e6543

Please sign in to comment.