Commit 5159609e authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Dismiss the multi window resizer when the user clicks outside of the multi

window resizer

BUG=437125
TEST=MultiWindowResizeController.ClickOutside

Review URL: https://codereview.chromium.org/753933003

Cr-Commit-Position: refs/heads/master@{#308402}
parent 72b4a2c5
......@@ -130,7 +130,9 @@ class MultiWindowResizeController::ResizeMouseWatcherHost :
// MouseWatcherHost overrides:
bool Contains(const gfx::Point& point_in_screen,
MouseEventType type) override {
return host_->IsOverWindows(point_in_screen);
return (type == MOUSE_PRESS)
? host_->IsOverResizeWidget(point_in_screen)
: host_->IsOverWindows(point_in_screen);
}
private:
......@@ -517,9 +519,15 @@ gfx::Rect MultiWindowResizeController::CalculateResizeWidgetBounds(
return gfx::Rect(x, y, pref.width(), pref.height());
}
bool MultiWindowResizeController::IsOverResizeWidget(
const gfx::Point& location_in_screen) const {
return resize_widget_->GetWindowBoundsInScreen().Contains(
location_in_screen);
}
bool MultiWindowResizeController::IsOverWindows(
const gfx::Point& location_in_screen) const {
if (resize_widget_->GetWindowBoundsInScreen().Contains(location_in_screen))
if (IsOverResizeWidget(location_in_screen))
return true;
if (windows_.direction == TOP_BOTTOM) {
......
......@@ -140,6 +140,9 @@ class ASH_EXPORT MultiWindowResizeController :
gfx::Rect CalculateResizeWidgetBounds(
const gfx::Point& location_in_parent) const;
// Returns true if |location_in_screen| is over the resize widget.
bool IsOverResizeWidget(const gfx::Point& location_in_screen) const;
// Returns true if |location_in_screen| is over the resize windows
// (or the resize widget itself).
bool IsOverWindows(const gfx::Point& location_in_screen) const;
......
......@@ -338,4 +338,39 @@ TEST_F(MultiWindowResizeControllerTest, Three) {
generator.PressLeftButton();
}
// Tests that clicking outside of the resize handle dismisses it.
TEST_F(MultiWindowResizeControllerTest, ClickOutside) {
aura::test::TestWindowDelegate delegate1;
scoped_ptr<aura::Window> w1(
CreateTestWindow(&delegate1, gfx::Rect(0, 0, 100, 100)));
delegate1.set_window_component(HTRIGHT);
aura::test::TestWindowDelegate delegate2;
scoped_ptr<aura::Window> w2(
CreateTestWindow(&delegate2, gfx::Rect(100, 0, 100, 100)));
delegate2.set_window_component(HTLEFT);
ui::test::EventGenerator& generator(GetEventGenerator());
gfx::Point w1_center_in_screen = w1->GetBoundsInScreen().CenterPoint();
generator.MoveMouseTo(w1_center_in_screen);
EXPECT_TRUE(HasPendingShow());
EXPECT_TRUE(IsShowing());
ShowNow();
EXPECT_TRUE(IsShowing());
gfx::Rect resize_widget_bounds_in_screen =
resize_widget()->GetWindowBoundsInScreen();
// Clicking on the resize handle should not do anything.
generator.MoveMouseTo(resize_widget_bounds_in_screen.CenterPoint());
generator.ClickLeftButton();
EXPECT_TRUE(IsShowing());
// Clicking outside the resize handle should immediately hide the resize
// handle.
EXPECT_FALSE(resize_widget_bounds_in_screen.Contains(w1_center_in_screen));
generator.MoveMouseTo(w1_center_in_screen);
generator.ClickLeftButton();
EXPECT_FALSE(IsShowing());
}
} // namespace ash
......@@ -69,11 +69,6 @@ void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) {
click_component_ = HTNOWHERE;
}
// The multi window resizer does not hide as a result of a single click
// because this code is never reached as a result of a single click.
// TODO(pkotwicz): Fix this. http://crbug.com/437125
multi_window_resize_controller_.Hide();
HandleVerticalResizeDoubleClick(target_state, event);
break;
}
......
......@@ -39,6 +39,9 @@ class MouseWatcher::Observer : public ui::EventHandler {
case ui::ET_MOUSE_EXITED:
HandleMouseEvent(MouseWatcherHost::MOUSE_EXIT);
break;
case ui::ET_MOUSE_PRESSED:
HandleMouseEvent(MouseWatcherHost::MOUSE_PRESS);
break;
default:
break;
}
......@@ -52,9 +55,11 @@ class MouseWatcher::Observer : public ui::EventHandler {
// It's safe to use last_mouse_location() here as this function is invoked
// during event dispatching.
if (!host()->Contains(EventMonitor::GetLastMouseLocation(), event_type)) {
// Mouse moved outside the host's zone, start a timer to notify the
// listener.
if (!notify_listener_factory_.HasWeakPtrs()) {
if (event_type == MouseWatcherHost::MOUSE_PRESS) {
NotifyListener();
} else if (!notify_listener_factory_.HasWeakPtrs()) {
// Mouse moved outside the host's zone, start a timer to notify the
// listener.
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&Observer::NotifyListener,
......
......@@ -29,14 +29,11 @@ class VIEWS_EXPORT MouseWatcherListener {
// The MouseWatcherHost determines what region is to be monitored.
class VIEWS_EXPORT MouseWatcherHost {
public:
// The MouseEventType can be used as a hint.
// The type of mouse event.
enum MouseEventType {
// The mouse moved within the window which was current when the MouseWatcher
// was created.
MOUSE_MOVE,
// The mouse moved exited the window which was current when the MouseWatcher
// was created.
MOUSE_EXIT
MOUSE_EXIT,
MOUSE_PRESS
};
virtual ~MouseWatcherHost();
......
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