Commit 4882310f authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Set capture to the window being dragged when dragging a window on Ash

This CL sets capture to the window being dragged when dragging a window on
Ash. This allows state to be reset when a user opens the Ctrl+Alt+Delete dialog
on Windows Ash.

As a side effect, this CL fixes dragging windows from one screen to another on
ChromeOS ozone. Dragging windows from one screen to another
worked on X11 because X11 does an implicit grab when the mouse is pressed. This
implicit grab guarantees that events are sent to WindowTreeHost where the drag
started for the duration of the drag.

BUG=439703, 423383
TEST=None

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

Cr-Commit-Position: refs/heads/master@{#309364}
parent 39046bbd
...@@ -288,41 +288,6 @@ TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) { ...@@ -288,41 +288,6 @@ TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) {
EXPECT_EQ(current_bounds.ToString(), right_tile_bounds.ToString()); EXPECT_EQ(current_bounds.ToString(), right_tile_bounds.ToString());
} }
TEST_F(SystemGestureEventFilterTest, TwoFingerDragTwoWindows) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
ui::GestureConfiguration::GetInstance()
->set_max_separation_for_gesture_touches_in_pixels(0);
views::Widget* first = views::Widget::CreateWindowWithContextAndBounds(
new ResizableWidgetDelegate, root_window, gfx::Rect(10, 0, 50, 100));
first->Show();
views::Widget* second = views::Widget::CreateWindowWithContextAndBounds(
new ResizableWidgetDelegate, root_window, gfx::Rect(100, 0, 100, 100));
second->Show();
// Start a two-finger drag on |first|, and then try to use another two-finger
// drag to move |second|. The attempt to move |second| should fail.
const gfx::Rect& first_bounds = first->GetWindowBoundsInScreen();
const gfx::Rect& second_bounds = second->GetWindowBoundsInScreen();
const int kSteps = 15;
const int kTouchPoints = 4;
gfx::Point points[kTouchPoints] = {
first_bounds.origin() + gfx::Vector2d(5, 5),
first_bounds.origin() + gfx::Vector2d(30, 10),
second_bounds.origin() + gfx::Vector2d(5, 5),
second_bounds.origin() + gfx::Vector2d(40, 20)
};
ui::test::EventGenerator generator(root_window);
// Do not drag too fast to avoid fling.
generator.GestureMultiFingerScroll(kTouchPoints, points,
50, kSteps, 0, 150);
EXPECT_NE(first_bounds.ToString(),
first->GetWindowBoundsInScreen().ToString());
EXPECT_EQ(second_bounds.ToString(),
second->GetWindowBoundsInScreen().ToString());
}
TEST_F(SystemGestureEventFilterTest, WindowsWithMaxSizeDontSnap) { TEST_F(SystemGestureEventFilterTest, WindowsWithMaxSizeDontSnap) {
gfx::Rect bounds(250, 150, 100, 100); gfx::Rect bounds(250, 150, 100, 100);
aura::Window* root_window = Shell::GetPrimaryRootWindow(); aura::Window* root_window = Shell::GetPrimaryRootWindow();
......
...@@ -110,6 +110,9 @@ class ToplevelWindowEventHandler::ScopedWindowResizer ...@@ -110,6 +110,9 @@ class ToplevelWindowEventHandler::ScopedWindowResizer
ToplevelWindowEventHandler* handler_; ToplevelWindowEventHandler* handler_;
scoped_ptr<WindowResizer> resizer_; scoped_ptr<WindowResizer> resizer_;
// Whether ScopedWindowResizer grabbed capture.
bool grabbed_capture_;
DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer);
}; };
...@@ -117,14 +120,24 @@ ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( ...@@ -117,14 +120,24 @@ ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer(
ToplevelWindowEventHandler* handler, ToplevelWindowEventHandler* handler,
WindowResizer* resizer) WindowResizer* resizer)
: handler_(handler), : handler_(handler),
resizer_(resizer) { resizer_(resizer),
resizer_->GetTarget()->AddObserver(this); grabbed_capture_(false) {
wm::GetWindowState(resizer_->GetTarget())->AddObserver(this); aura::Window* target = resizer_->GetTarget();
target->AddObserver(this);
wm::GetWindowState(target)->AddObserver(this);
if (!target->HasCapture()) {
grabbed_capture_ = true;
target->SetCapture();
}
} }
ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() {
resizer_->GetTarget()->RemoveObserver(this); aura::Window* target = resizer_->GetTarget();
wm::GetWindowState(resizer_->GetTarget())->RemoveObserver(this); target->RemoveObserver(this);
wm::GetWindowState(target)->RemoveObserver(this);
if (grabbed_capture_)
target->ReleaseCapture();
} }
bool ToplevelWindowEventHandler::ScopedWindowResizer::IsMove() const { bool ToplevelWindowEventHandler::ScopedWindowResizer::IsMove() const {
......
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