OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 243 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
244 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 244 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
245 params.context = root_window(); | 245 params.context = root_window(); |
246 params.bounds = gfx::Rect(0, 0, 100, 200); | 246 params.bounds = gfx::Rect(0, 0, 100, 200); |
247 widget->Init(params); | 247 widget->Init(params); |
248 widget->SetContentsView(view); | 248 widget->SetContentsView(view); |
249 widget->Show(); | 249 widget->Show(); |
250 | 250 |
251 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(41, 51), 1, | 251 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(41, 51), 1, |
252 base::TimeDelta()); | 252 base::TimeDelta()); |
253 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 253 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); |
254 // Both views should get the press. | 254 // Both views should get the press. |
255 EXPECT_TRUE(view->got_gesture_event()); | 255 EXPECT_TRUE(view->got_gesture_event()); |
256 EXPECT_TRUE(child->got_gesture_event()); | 256 EXPECT_TRUE(child->got_gesture_event()); |
257 view->clear_got_gesture_event(); | 257 view->clear_got_gesture_event(); |
258 child->clear_got_gesture_event(); | 258 child->clear_got_gesture_event(); |
259 // Touch events should not automatically grab capture. | 259 // Touch events should not automatically grab capture. |
260 EXPECT_FALSE(widget->HasCapture()); | 260 EXPECT_FALSE(widget->HasCapture()); |
261 | 261 |
262 // Release touch. Only |view| should get the release since that it consumed | 262 // Release touch. Only |view| should get the release since that it consumed |
263 // the press. | 263 // the press. |
264 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(250, 251), 1, | 264 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(250, 251), 1, |
265 base::TimeDelta()); | 265 base::TimeDelta()); |
266 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 266 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release); |
267 EXPECT_TRUE(view->got_gesture_event()); | 267 EXPECT_TRUE(view->got_gesture_event()); |
268 EXPECT_FALSE(child->got_gesture_event()); | 268 EXPECT_FALSE(child->got_gesture_event()); |
269 view->clear_got_gesture_event(); | 269 view->clear_got_gesture_event(); |
270 | 270 |
271 // Work around for bug in NativeWidgetAura. | 271 // Work around for bug in NativeWidgetAura. |
272 // TODO: fix bug and remove this. | 272 // TODO: fix bug and remove this. |
273 widget->Close(); | 273 widget->Close(); |
274 } | 274 } |
275 | 275 |
276 TEST_F(NativeWidgetAuraTest, ReleaseCaptureOnTouchRelease) { | 276 TEST_F(NativeWidgetAuraTest, ReleaseCaptureOnTouchRelease) { |
277 GestureTrackingView* view = new GestureTrackingView(); | 277 GestureTrackingView* view = new GestureTrackingView(); |
278 scoped_ptr<TestWidget> widget(new TestWidget()); | 278 scoped_ptr<TestWidget> widget(new TestWidget()); |
279 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 279 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
280 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 280 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
281 params.context = root_window(); | 281 params.context = root_window(); |
282 params.bounds = gfx::Rect(0, 0, 100, 200); | 282 params.bounds = gfx::Rect(0, 0, 100, 200); |
283 widget->Init(params); | 283 widget->Init(params); |
284 widget->SetContentsView(view); | 284 widget->SetContentsView(view); |
285 widget->Show(); | 285 widget->Show(); |
286 | 286 |
287 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(41, 51), 1, | 287 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(41, 51), 1, |
288 base::TimeDelta()); | 288 base::TimeDelta()); |
289 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 289 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); |
290 EXPECT_TRUE(view->got_gesture_event()); | 290 EXPECT_TRUE(view->got_gesture_event()); |
291 view->clear_got_gesture_event(); | 291 view->clear_got_gesture_event(); |
292 // Set the capture. | 292 // Set the capture. |
293 widget->SetCapture(view); | 293 widget->SetCapture(view); |
294 EXPECT_TRUE(widget->HasCapture()); | 294 EXPECT_TRUE(widget->HasCapture()); |
295 | 295 |
296 // Generate a release, this should trigger releasing capture. | 296 // Generate a release, this should trigger releasing capture. |
297 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(41, 51), 1, | 297 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(41, 51), 1, |
298 base::TimeDelta()); | 298 base::TimeDelta()); |
299 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 299 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release); |
300 EXPECT_TRUE(view->got_gesture_event()); | 300 EXPECT_TRUE(view->got_gesture_event()); |
301 view->clear_got_gesture_event(); | 301 view->clear_got_gesture_event(); |
302 EXPECT_FALSE(widget->HasCapture()); | 302 EXPECT_FALSE(widget->HasCapture()); |
303 | 303 |
304 // Work around for bug in NativeWidgetAura. | 304 // Work around for bug in NativeWidgetAura. |
305 // TODO: fix bug and remove this. | 305 // TODO: fix bug and remove this. |
306 widget->Close(); | 306 widget->Close(); |
307 } | 307 } |
308 | 308 |
309 // Verifies views with layers are targeted for events properly. | 309 // Verifies views with layers are targeted for events properly. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 scoped_ptr<Widget> widget(new Widget()); | 396 scoped_ptr<Widget> widget(new Widget()); |
397 NativeWidgetAura* window = Init(parent.get(), widget.get()); | 397 NativeWidgetAura* window = Init(parent.get(), widget.get()); |
398 window->Show(); | 398 window->Show(); |
399 window->Close(); | 399 window->Close(); |
400 base::MessageLoop::current()->RunUntilIdle(); | 400 base::MessageLoop::current()->RunUntilIdle(); |
401 widget->GetNativeTheme(); // Shouldn't crash. | 401 widget->GetNativeTheme(); // Shouldn't crash. |
402 } | 402 } |
403 | 403 |
404 } // namespace | 404 } // namespace |
405 } // namespace views | 405 } // namespace views |
OLD | NEW |