summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-15 14:30:07 +0000
committerjonross@chromium.org <jonross@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-15 14:30:07 +0000
commitc2c7eedd925458f895f7134f47e88551b28e1709 (patch)
treeab5154c644da71850da06aa469e00ba2410a35b8 /ash
parentd5ec2063a3039897a4adb6addc027362b57fb36a (diff)
downloadchromium_src-c2c7eedd925458f895f7134f47e88551b28e1709.zip
chromium_src-c2c7eedd925458f895f7134f47e88551b28e1709.tar.gz
chromium_src-c2c7eedd925458f895f7134f47e88551b28e1709.tar.bz2
Prevents double-clicks on a tab close button from aslo maximizing the browser
The code responsible for listening to a double-click, and for maximizing the browser is platform dependant. The path on Aura desktop differs from that of Chrome OS. In both cases they use alternate means to trigger the maximizing. This change modifies both so that they only attempt to maximize if the initial click has the same target as the second click. Tab deletion is destructive by nature, lead do different targets processing different parts of the same series of user events. TEST=WorkspaceEventHandlerTest BUG=348817 Review URL: https://codereview.chromium.org/222203006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/toplevel_window_event_handler.cc12
-rw-r--r--ash/wm/workspace/workspace_event_handler.cc92
-rw-r--r--ash/wm/workspace/workspace_event_handler.h7
-rw-r--r--ash/wm/workspace/workspace_event_handler_unittest.cc180
4 files changed, 213 insertions, 78 deletions
diff --git a/ash/wm/toplevel_window_event_handler.cc b/ash/wm/toplevel_window_event_handler.cc
index 8b6c9ba..f20a13f 100644
--- a/ash/wm/toplevel_window_event_handler.cc
+++ b/ash/wm/toplevel_window_event_handler.cc
@@ -476,7 +476,10 @@ void ToplevelWindowEventHandler::HandleMousePressed(
ConvertPointToParent(target, event->location()));
AttemptToStartDrag(target, location_in_parent, component,
aura::client::WINDOW_MOVE_SOURCE_MOUSE);
- event->StopPropagation();
+ // Set as handled so that other event handlers do no act upon the event
+ // but still receive it so that they receive both parts of each pressed/
+ // released pair.
+ event->SetHandled();
} else {
CompleteDrag(DRAG_COMPLETE);
}
@@ -491,12 +494,13 @@ void ToplevelWindowEventHandler::HandleMouseReleased(
CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ?
DRAG_COMPLETE : DRAG_REVERT);
// Completing the drag may result in hiding the window. If this happens
- // return true so no other handlers/observers see the event. Otherwise
- // they see the event on a hidden window.
+ // mark the event as handled so no other handlers/observers act upon the
+ // event. They should see the event on a hidden window, to determine targets
+ // of destructive actions such as hiding. They should not act upon them.
if (window_resizer_ &&
event->type() == ui::ET_MOUSE_CAPTURE_CHANGED &&
!target->IsVisible()) {
- event->StopPropagation();
+ event->SetHandled();
}
}
diff --git a/ash/wm/workspace/workspace_event_handler.cc b/ash/wm/workspace/workspace_event_handler.cc
index bfc8104..bba3f76 100644
--- a/ash/wm/workspace/workspace_event_handler.cc
+++ b/ash/wm/workspace/workspace_event_handler.cc
@@ -15,16 +15,26 @@
namespace ash {
-WorkspaceEventHandler::WorkspaceEventHandler() {
+WorkspaceEventHandler::WorkspaceEventHandler()
+ : click_component_(HTNOWHERE) {
}
WorkspaceEventHandler::~WorkspaceEventHandler() {
}
void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
+ aura::Window* target = static_cast<aura::Window*>(event->target());
+ if (event->type() == ui::ET_MOUSE_PRESSED &&
+ event->IsOnlyLeftMouseButton() &&
+ ((event->flags() &
+ (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0)) {
+ click_component_ = target->delegate()->
+ GetNonClientComponent(event->location());
+ }
+
if (event->handled())
return;
- aura::Window* target = static_cast<aura::Window*>(event->target());
+
switch (event->type()) {
case ui::ET_MOUSE_MOVED: {
int component =
@@ -40,16 +50,29 @@ void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
break;
case ui::ET_MOUSE_PRESSED: {
wm::WindowState* target_state = wm::GetWindowState(target);
- if (event->flags() & ui::EF_IS_DOUBLE_CLICK &&
- event->IsOnlyLeftMouseButton() &&
- target->delegate()->GetNonClientComponent(event->location()) ==
- HTCAPTION) {
- ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
- ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
- const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
- target_state->OnWMEvent(&wm_event);
- event->StopPropagation();
+
+ if (event->IsOnlyLeftMouseButton()) {
+ if (event->flags() & ui::EF_IS_DOUBLE_CLICK) {
+ int component = target->delegate()->
+ GetNonClientComponent(event->location());
+ if (component == HTCAPTION &&
+ component == click_component_) {
+ ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
+ ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
+ const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
+ target_state->OnWMEvent(&wm_event);
+ event->StopPropagation();
+ }
+ // WindowEventHandler can receive each event up to two times. Once a
+ // double-click has been received clear the target. Otherwise a
+ // duplicate of the event will be checking target history against
+ // itself.
+ click_component_ = HTNOWHERE;
+ }
+ } else {
+ click_component_ = HTNOWHERE;
}
+
multi_window_resize_controller_.Hide();
HandleVerticalResizeDoubleClick(target_state, event);
break;
@@ -60,29 +83,36 @@ void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
}
void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
- if (event->handled())
+ if (event->handled() || event->type() != ui::ET_GESTURE_TAP)
return;
+
aura::Window* target = static_cast<aura::Window*>(event->target());
- if (event->type() == ui::ET_GESTURE_TAP &&
- target->delegate()->GetNonClientComponent(event->location()) ==
- HTCAPTION) {
- if (event->details().tap_count() == 2) {
- ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
- ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
- // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time
- // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once.
- TouchUMA::GetInstance()->RecordGestureAction(
- TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP);
- const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
- wm::GetWindowState(target)->OnWMEvent(&wm_event);
- event->StopPropagation();
- return;
- } else {
- // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap.
- TouchUMA::GetInstance()->RecordGestureAction(
- TouchUMA::GESTURE_FRAMEVIEW_TAP);
- }
+ int previous_target_component = click_component_;
+ click_component_ = target->delegate()->
+ GetNonClientComponent(event->location());
+
+ if (click_component_ != HTCAPTION)
+ return;
+
+ if (event->details().tap_count() != 2) {
+ // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap.
+ TouchUMA::GetInstance()->
+ RecordGestureAction(TouchUMA::GESTURE_FRAMEVIEW_TAP);
+ return;
+ }
+
+ if (click_component_ == previous_target_component) {
+ ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
+ ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
+ // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time
+ // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once.
+ TouchUMA::GetInstance()->RecordGestureAction(
+ TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP);
+ const wm::WMEvent wm_event(wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION);
+ wm::GetWindowState(target)->OnWMEvent(&wm_event);
+ event->StopPropagation();
}
+ click_component_ = HTNOWHERE;
}
void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
diff --git a/ash/wm/workspace/workspace_event_handler.h b/ash/wm/workspace/workspace_event_handler.h
index f949821..0610537 100644
--- a/ash/wm/workspace/workspace_event_handler.h
+++ b/ash/wm/workspace/workspace_event_handler.h
@@ -36,6 +36,13 @@ class WorkspaceEventHandler : public ui::EventHandler {
MultiWindowResizeController multi_window_resize_controller_;
+ // The non-client component for the target of a MouseEvent or GestureEvent.
+ // Events can be destructive to the window tree, which can cause the
+ // component of a ui::EF_IS_DOUBLE_CLICK event to no longer be the same as
+ // that of the initial click. Acting on a double click should only occur for
+ // matching components. This will be set for left clicks, and tap events.
+ int click_component_;
+
DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandler);
};
diff --git a/ash/wm/workspace/workspace_event_handler_unittest.cc b/ash/wm/workspace/workspace_event_handler_unittest.cc
index fe9ec8c..ce69947 100644
--- a/ash/wm/workspace/workspace_event_handler_unittest.cc
+++ b/ash/wm/workspace/workspace_event_handler_unittest.cc
@@ -85,8 +85,8 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
// Double clicking the vertical resize edge of a window should maximize it
// vertically.
gfx::Rect restored_bounds(10, 10, 50, 50);
- aura::test::TestWindowDelegate wd;
- scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds));
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
wm::ActivateWindow(window.get());
@@ -97,7 +97,7 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
window.get());
// Double-click the top resize edge.
- wd.set_window_component(HTTOP);
+ delegate.set_window_component(HTTOP);
// On X a double click actually generates a drag between each press/release.
// Explicitly trigger this path since we had bugs in dealing with it
// correctly.
@@ -126,7 +126,7 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
EXPECT_FALSE(window_state->HasRestoreBounds());
// Double clicking the left resize edge should maximize horizontally.
- wd.set_window_component(HTLEFT);
+ delegate.set_window_component(HTLEFT);
generator.DoubleClickLeftButton();
bounds_in_screen = window->GetBoundsInScreen();
EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
@@ -149,14 +149,14 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
// Verify the double clicking the resize edge works on 2nd display too.
UpdateDisplay("200x200,400x300");
gfx::Rect work_area2 = ScreenUtil::GetSecondaryDisplay().work_area();
- restored_bounds.SetRect(220,20, 50, 50);
+ restored_bounds.SetRect(220, 20, 50, 50);
window->SetBoundsInScreen(restored_bounds, ScreenUtil::GetSecondaryDisplay());
aura::Window* second_root = Shell::GetAllRootWindows()[1];
EXPECT_EQ(second_root, window->GetRootWindow());
aura::test::EventGenerator generator2(second_root, window.get());
// Y-axis maximization.
- wd.set_window_component(HTTOP);
+ delegate.set_window_component(HTTOP);
generator2.PressLeftButton();
generator2.ReleaseLeftButton();
generator2.set_flags(ui::EF_IS_DOUBLE_CLICK);
@@ -176,7 +176,7 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
// X-axis maximization.
- wd.set_window_component(HTLEFT);
+ delegate.set_window_component(HTLEFT);
generator2.DoubleClickLeftButton();
bounds_in_screen = window->GetBoundsInScreen();
EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
@@ -193,8 +193,8 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
// Tests the behavior when double clicking the border of a side snapped window.
TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) {
gfx::Rect restored_bounds(10, 10, 50, 50);
- aura::test::TestWindowDelegate wd;
- scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds));
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
gfx::Rect work_area_in_screen = Shell::GetScreen()->GetDisplayNearestWindow(
window.get()).work_area();
@@ -214,7 +214,7 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) {
// to the restored bounds would be weird).
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
window.get());
- wd.set_window_component(HTTOP);
+ delegate.set_window_component(HTTOP);
generator.DoubleClickLeftButton();
EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
EXPECT_EQ(snapped_bounds_in_screen.ToString(),
@@ -222,7 +222,7 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) {
// Double clicking the right border should exit the side snapped state and
// make the window take up the entire work area.
- wd.set_window_component(HTRIGHT);
+ delegate.set_window_component(HTRIGHT);
generator.DoubleClickLeftButton();
EXPECT_TRUE(window_state->IsNormalStateType());
EXPECT_EQ(work_area_in_screen.ToString(),
@@ -232,20 +232,20 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) {
TEST_F(WorkspaceEventHandlerTest,
DoubleClickSingleAxisDoesntResizeVerticalEdgeIfConstrained) {
gfx::Rect restored_bounds(10, 10, 50, 50);
- aura::test::TestWindowDelegate wd;
- scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds));
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
wm::ActivateWindow(window.get());
gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
window.get()).work_area();
- wd.set_maximum_size(gfx::Size(0, 100));
+ delegate.set_maximum_size(gfx::Size(0, 100));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
window.get());
// Double-click the top resize edge.
- wd.set_window_component(HTTOP);
+ delegate.set_window_component(HTTOP);
generator.DoubleClickLeftButton();
// The size of the window should be unchanged.
@@ -256,20 +256,20 @@ TEST_F(WorkspaceEventHandlerTest,
TEST_F(WorkspaceEventHandlerTest,
DoubleClickSingleAxisDoesntResizeHorizontalEdgeIfConstrained) {
gfx::Rect restored_bounds(10, 10, 50, 50);
- aura::test::TestWindowDelegate wd;
- scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds));
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
wm::ActivateWindow(window.get());
gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
window.get()).work_area();
- wd.set_maximum_size(gfx::Size(100, 0));
+ delegate.set_maximum_size(gfx::Size(100, 0));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
window.get());
// Double-click the top resize edge.
- wd.set_window_component(HTRIGHT);
+ delegate.set_window_component(HTRIGHT);
generator.DoubleClickLeftButton();
// The size of the window should be unchanged.
@@ -279,14 +279,14 @@ TEST_F(WorkspaceEventHandlerTest,
TEST_F(WorkspaceEventHandlerTest,
DoubleClickOrTapWithModalChildDoesntMaximize) {
- aura::test::TestWindowDelegate wd1;
- aura::test::TestWindowDelegate wd2;
+ aura::test::TestWindowDelegate delegate1;
+ aura::test::TestWindowDelegate delegate2;
scoped_ptr<aura::Window> window(
- CreateTestWindow(&wd1, gfx::Rect(10, 20, 30, 40)));
+ CreateTestWindow(&delegate1, gfx::Rect(10, 20, 30, 40)));
scoped_ptr<aura::Window> child(
- CreateTestWindow(&wd2, gfx::Rect(0, 0, 1, 1)));
+ CreateTestWindow(&delegate2, gfx::Rect(0, 0, 1, 1)));
window->SetProperty(aura::client::kCanMaximizeKey, true);
- wd1.set_window_component(HTCAPTION);
+ delegate1.set_window_component(HTCAPTION);
child->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
::wm::AddTransientChild(window.get(), child.get());
@@ -308,9 +308,9 @@ TEST_F(WorkspaceEventHandlerTest,
// Test the behavior as a result of double clicking the window header.
TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
- aura::test::TestWindowDelegate wd;
+ aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> window(
- CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40)));
+ CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
window->SetProperty(aura::client::kCanMaximizeKey, true);
wm::WindowState* window_state = wm::GetWindowState(window.get());
@@ -321,19 +321,22 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
EXPECT_FALSE(window_state->IsMaximized());
// 1) Double clicking a normal window should maximize.
- wd.set_window_component(HTCAPTION);
+ delegate.set_window_component(HTCAPTION);
aura::Window* root = Shell::GetPrimaryRootWindow();
aura::test::EventGenerator generator(root, window.get());
+ generator.ClickLeftButton();
generator.DoubleClickLeftButton();
EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString());
EXPECT_TRUE(window_state->IsMaximized());
+ generator.ClickLeftButton();
generator.DoubleClickLeftButton();
EXPECT_TRUE(window_state->IsNormalStateType());
EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
// 2) Double clicking a horizontally maximized window should maximize.
- wd.set_window_component(HTLEFT);
+ delegate.set_window_component(HTLEFT);
+ generator.ClickLeftButton();
generator.DoubleClickLeftButton();
EXPECT_TRUE(window_state->IsNormalStateType());
EXPECT_EQ(work_area_in_parent.x(), window->bounds().x());
@@ -341,10 +344,12 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
EXPECT_EQ(work_area_in_parent.width(), window->bounds().width());
EXPECT_EQ(restore_bounds.height(), window->bounds().height());
- wd.set_window_component(HTCAPTION);
+ delegate.set_window_component(HTCAPTION);
+ generator.ClickLeftButton();
generator.DoubleClickLeftButton();
EXPECT_TRUE(window_state->IsMaximized());
+ generator.ClickLeftButton();
generator.DoubleClickLeftButton();
EXPECT_TRUE(window_state->IsNormalStateType());
EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
@@ -354,9 +359,11 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
window_state->OnWMEvent(&snap_event);
EXPECT_TRUE(window_state->IsSnapped());
generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint());
+ generator.ClickLeftButton();
generator.DoubleClickLeftButton();
EXPECT_TRUE(window_state->IsMaximized());
+ generator.ClickLeftButton();
generator.DoubleClickLeftButton();
EXPECT_TRUE(window_state->IsNormalStateType());
EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
@@ -366,11 +373,11 @@ TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
// toggle the maximized state.
TEST_F(WorkspaceEventHandlerTest,
DoubleClickMiddleButtonDoesNotToggleMaximize) {
- aura::test::TestWindowDelegate wd;
+ aura::test::TestWindowDelegate delegate;
scoped_ptr<aura::Window> window(
- CreateTestWindow(&wd, gfx::Rect(1, 2, 30, 40)));
+ CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
window->SetProperty(aura::client::kCanMaximizeKey, true);
- wd.set_window_component(HTCAPTION);
+ delegate.set_window_component(HTCAPTION);
aura::Window* root = Shell::GetPrimaryRootWindow();
aura::test::EventGenerator generator(root, window.get());
@@ -395,11 +402,11 @@ TEST_F(WorkspaceEventHandlerTest,
}
TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
- aura::test::TestWindowDelegate wd;
+ aura::test::TestWindowDelegate delegate;
gfx::Rect bounds(10, 20, 30, 40);
- scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
+ scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
window->SetProperty(aura::client::kCanMaximizeKey, true);
- wd.set_window_component(HTCAPTION);
+ delegate.set_window_component(HTCAPTION);
wm::WindowState* window_state = wm::GetWindowState(window.get());
EXPECT_FALSE(window_state->IsMaximized());
@@ -422,14 +429,14 @@ TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
// Create a large window in the background. This is necessary so that when we
// delete |window| WorkspaceEventHandler is still the active event handler.
- aura::test::TestWindowDelegate wd2;
+ aura::test::TestWindowDelegate delegate2;
scoped_ptr<aura::Window> window2(
- CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500)));
+ CreateTestWindow(&delegate2, gfx::Rect(0, 0, 500, 500)));
- aura::test::TestWindowDelegate wd;
+ aura::test::TestWindowDelegate delegate;
const gfx::Rect bounds(10, 20, 30, 40);
- scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
- wd.set_window_component(HTCAPTION);
+ scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
+ delegate.set_window_component(HTCAPTION);
aura::test::EventGenerator generator(window->GetRootWindow());
generator.MoveMouseToCenterOf(window.get());
generator.PressLeftButton();
@@ -441,10 +448,10 @@ TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
// Verifies deleting the window while in a run loop doesn't crash.
TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
- aura::test::TestWindowDelegate wd;
+ aura::test::TestWindowDelegate delegate;
const gfx::Rect bounds(10, 20, 30, 40);
- scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
- wd.set_window_component(HTCAPTION);
+ scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
+ delegate.set_window_component(HTCAPTION);
ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow()));
base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
@@ -454,4 +461,91 @@ TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
aura::client::WINDOW_MOVE_SOURCE_MOUSE);
}
+// Verifies that double clicking in the header does not maximize if the target
+// component has changed.
+TEST_F(WorkspaceEventHandlerTest,
+ DoubleClickTwoDifferentTargetsDoesntMaximize) {
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(
+ CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
+ window->SetProperty(aura::client::kCanMaximizeKey, true);
+
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
+ gfx::Rect restore_bounds = window->bounds();
+ gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
+ window.get());
+
+ EXPECT_FALSE(window_state->IsMaximized());
+
+ // First click will go to a client
+ delegate.set_window_component(HTCLIENT);
+ aura::Window* root = Shell::GetPrimaryRootWindow();
+ aura::test::EventGenerator generator(root, window.get());
+ generator.ClickLeftButton();
+ EXPECT_FALSE(window_state->IsMaximized());
+
+ // Second click will go to the header
+ delegate.set_window_component(HTCAPTION);
+ generator.DoubleClickLeftButton();
+ EXPECT_FALSE(window_state->IsMaximized());
+}
+
+// Verifies that double tapping in the header does not maximize if the target
+// component has changed.
+TEST_F(WorkspaceEventHandlerTest, DoubleTapTwoDifferentTargetsDoesntMaximize) {
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(
+ CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
+ window->SetProperty(aura::client::kCanMaximizeKey, true);
+
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
+ gfx::Rect restore_bounds = window->bounds();
+ gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
+ window.get());
+
+ EXPECT_FALSE(window_state->IsMaximized());
+
+ // First tap will go to a client
+ delegate.set_window_component(HTCLIENT);
+ aura::Window* root = Shell::GetPrimaryRootWindow();
+ aura::test::EventGenerator generator(root, window.get());
+ generator.GestureTapAt(gfx::Point(25, 25));
+ EXPECT_FALSE(window_state->IsMaximized());
+
+ // Second tap will go to the header
+ delegate.set_window_component(HTCAPTION);
+ generator.GestureTapAt(gfx::Point(25, 25));
+ EXPECT_FALSE(window_state->IsMaximized());
+}
+
+TEST_F(WorkspaceEventHandlerTest,
+ RightClickDuringDoubleClickDoesntMaximize) {
+ aura::test::TestWindowDelegate delegate;
+ scoped_ptr<aura::Window> window(
+ CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
+ window->SetProperty(aura::client::kCanMaximizeKey, true);
+
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
+ gfx::Rect restore_bounds = window->bounds();
+ gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
+ window.get());
+
+ EXPECT_FALSE(window_state->IsMaximized());
+
+ // First click will go to a client
+ delegate.set_window_component(HTCLIENT);
+ aura::Window* root = Shell::GetPrimaryRootWindow();
+ aura::test::EventGenerator generator(root, window.get());
+ generator.ClickLeftButton();
+ EXPECT_FALSE(window_state->IsMaximized());
+
+ // Second click will go to the header
+ delegate.set_window_component(HTCAPTION);
+ generator.PressRightButton();
+ generator.ReleaseRightButton();
+ EXPECT_FALSE(window_state->IsMaximized());
+ generator.DoubleClickLeftButton();
+ EXPECT_FALSE(window_state->IsMaximized());
+}
+
} // namespace ash