| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/wm/core/capture_controller.h" | 5 #include "ui/wm/core/capture_controller.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "ui/aura/client/capture_delegate.h" | 10 #include "ui/aura/client/capture_delegate.h" |
| 9 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 10 #include "ui/aura/test/aura_test_base.h" | 12 #include "ui/aura/test/aura_test_base.h" |
| 11 #include "ui/aura/test/test_screen.h" | 13 #include "ui/aura/test/test_screen.h" |
| 12 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
| 13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 16 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 EXPECT_FALSE(delegate->HasNativeCapture()); | 210 EXPECT_FALSE(delegate->HasNativeCapture()); |
| 209 EXPECT_FALSE(delegate2->HasNativeCapture()); | 211 EXPECT_FALSE(delegate2->HasNativeCapture()); |
| 210 } | 212 } |
| 211 | 213 |
| 212 // A delegate that deletes a window on scroll cancel gesture event. | 214 // A delegate that deletes a window on scroll cancel gesture event. |
| 213 class GestureEventDeleteWindowOnScrollEnd | 215 class GestureEventDeleteWindowOnScrollEnd |
| 214 : public aura::test::TestWindowDelegate { | 216 : public aura::test::TestWindowDelegate { |
| 215 public: | 217 public: |
| 216 GestureEventDeleteWindowOnScrollEnd() {} | 218 GestureEventDeleteWindowOnScrollEnd() {} |
| 217 | 219 |
| 218 void SetWindow(scoped_ptr<aura::Window> window) { window_ = window.Pass(); } | 220 void SetWindow(scoped_ptr<aura::Window> window) { |
| 221 window_ = std::move(window); |
| 222 } |
| 219 aura::Window* window() { return window_.get(); } | 223 aura::Window* window() { return window_.get(); } |
| 220 | 224 |
| 221 // aura::test::TestWindowDelegate: | 225 // aura::test::TestWindowDelegate: |
| 222 void OnGestureEvent(ui::GestureEvent* gesture) override { | 226 void OnGestureEvent(ui::GestureEvent* gesture) override { |
| 223 TestWindowDelegate::OnGestureEvent(gesture); | 227 TestWindowDelegate::OnGestureEvent(gesture); |
| 224 if (gesture->type() != ui::ET_GESTURE_SCROLL_END) | 228 if (gesture->type() != ui::ET_GESTURE_SCROLL_END) |
| 225 return; | 229 return; |
| 226 window_.reset(); | 230 window_.reset(); |
| 227 } | 231 } |
| 228 | 232 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 239 new GestureEventDeleteWindowOnScrollEnd()); | 243 new GestureEventDeleteWindowOnScrollEnd()); |
| 240 const int kWindowWidth = 123; | 244 const int kWindowWidth = 123; |
| 241 const int kWindowHeight = 45; | 245 const int kWindowHeight = 45; |
| 242 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 246 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
| 243 scoped_ptr<aura::Window> window1( | 247 scoped_ptr<aura::Window> window1( |
| 244 CreateNormalWindowWithBounds(-1235, root_window(), bounds, nullptr)); | 248 CreateNormalWindowWithBounds(-1235, root_window(), bounds, nullptr)); |
| 245 | 249 |
| 246 bounds.Offset(0, 100); | 250 bounds.Offset(0, 100); |
| 247 scoped_ptr<aura::Window> window2(CreateNormalWindowWithBounds( | 251 scoped_ptr<aura::Window> window2(CreateNormalWindowWithBounds( |
| 248 -1234, root_window(), bounds, delegate.get())); | 252 -1234, root_window(), bounds, delegate.get())); |
| 249 delegate->SetWindow(window1.Pass()); | 253 delegate->SetWindow(std::move(window1)); |
| 250 | 254 |
| 251 ui::test::EventGenerator event_generator(root_window()); | 255 ui::test::EventGenerator event_generator(root_window()); |
| 252 const int position_x = bounds.x() + 1; | 256 const int position_x = bounds.x() + 1; |
| 253 int position_y = bounds.y() + 1; | 257 int position_y = bounds.y() + 1; |
| 254 event_generator.MoveTouch(gfx::Point(position_x, position_y)); | 258 event_generator.MoveTouch(gfx::Point(position_x, position_y)); |
| 255 event_generator.PressTouch(); | 259 event_generator.PressTouch(); |
| 256 for (int idx = 0 ; idx < 20 ; idx++, position_y++) | 260 for (int idx = 0 ; idx < 20 ; idx++, position_y++) |
| 257 event_generator.MoveTouch(gfx::Point(position_x, position_y)); | 261 event_generator.MoveTouch(gfx::Point(position_x, position_y)); |
| 258 | 262 |
| 259 // Setting capture on |window1| cancels touch gestures that are active on | 263 // Setting capture on |window1| cancels touch gestures that are active on |
| 260 // |window2|. GestureEventDeleteWindowOnScrollEnd will then delete |window1| | 264 // |window2|. GestureEventDeleteWindowOnScrollEnd will then delete |window1| |
| 261 // and should release capture on it. | 265 // and should release capture on it. |
| 262 delegate->window()->SetCapture(); | 266 delegate->window()->SetCapture(); |
| 263 | 267 |
| 264 // capture should not be set upon exit from SetCapture() above. | 268 // capture should not be set upon exit from SetCapture() above. |
| 265 aura::client::CaptureClient* capture_client = | 269 aura::client::CaptureClient* capture_client = |
| 266 aura::client::GetCaptureClient(root_window()); | 270 aura::client::GetCaptureClient(root_window()); |
| 267 ASSERT_NE(nullptr, capture_client); | 271 ASSERT_NE(nullptr, capture_client); |
| 268 EXPECT_EQ(nullptr, capture_client->GetCaptureWindow()); | 272 EXPECT_EQ(nullptr, capture_client->GetCaptureWindow()); |
| 269 | 273 |
| 270 // Send a mouse click. We no longer hold capture so this should not crash. | 274 // Send a mouse click. We no longer hold capture so this should not crash. |
| 271 ui::MouseEvent mouse_press(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 275 ui::MouseEvent mouse_press(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 272 base::TimeDelta(), 0, 0); | 276 base::TimeDelta(), 0, 0); |
| 273 DispatchEventUsingWindowDispatcher(&mouse_press); | 277 DispatchEventUsingWindowDispatcher(&mouse_press); |
| 274 } | 278 } |
| 275 | 279 |
| 276 } // namespace wm | 280 } // namespace wm |
| OLD | NEW |