Chromium Code Reviews| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1348 | 1348 |
| 1349 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| | 1349 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| |
| 1350 // will not receive the event. | 1350 // will not receive the event. |
| 1351 gfx::Point click_location(45, 15); | 1351 gfx::Point click_location(45, 15); |
| 1352 | 1352 |
| 1353 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | 1353 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, |
| 1354 ui::EF_LEFT_MOUSE_BUTTON); | 1354 ui::EF_LEFT_MOUSE_BUTTON); |
| 1355 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, | 1355 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, |
| 1356 ui::EF_LEFT_MOUSE_BUTTON); | 1356 ui::EF_LEFT_MOUSE_BUTTON); |
| 1357 | 1357 |
| 1358 EXPECT_TRUE(toplevel->HasCapture()); | |
| 1359 | |
| 1358 toplevel->OnMouseEvent(&press); | 1360 toplevel->OnMouseEvent(&press); |
| 1359 toplevel->OnMouseEvent(&release); | 1361 toplevel->OnMouseEvent(&release); |
| 1360 EXPECT_EQ(0, mouse->pressed()); | 1362 EXPECT_EQ(0, mouse->pressed()); |
| 1361 | 1363 |
| 1364 EXPECT_FALSE(toplevel->HasCapture()); | |
| 1365 | |
| 1362 // The end of the gesture should release the capture, and pressing on |mouse| | 1366 // The end of the gesture should release the capture, and pressing on |mouse| |
| 1363 // should now reach |mouse|. | 1367 // should now reach |mouse|. |
| 1364 toplevel->OnGestureEvent(&end); | 1368 toplevel->OnGestureEvent(&end); |
| 1365 toplevel->OnMouseEvent(&press); | 1369 toplevel->OnMouseEvent(&press); |
| 1366 toplevel->OnMouseEvent(&release); | 1370 toplevel->OnMouseEvent(&release); |
| 1367 EXPECT_EQ(1, mouse->pressed()); | 1371 EXPECT_EQ(1, mouse->pressed()); |
| 1368 | 1372 |
| 1369 toplevel->Close(); | 1373 toplevel->Close(); |
| 1370 RunPendingMessages(); | 1374 RunPendingMessages(); |
| 1371 } | 1375 } |
| 1372 | 1376 |
| 1377 TEST_F(WidgetTest, CaptureAutoReset) { | |
|
sky
2013/09/04 23:32:15
Any time you're messing with capture your window n
Evan Stade
2013/09/04 23:35:52
how does the test above it get away with it?
| |
| 1378 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); | |
| 1379 View* container = new View; | |
| 1380 toplevel->SetContentsView(container); | |
| 1381 | |
| 1382 EXPECT_FALSE(toplevel->HasCapture()); | |
| 1383 toplevel->SetCapture(NULL); | |
| 1384 EXPECT_TRUE(toplevel->HasCapture()); | |
| 1385 | |
| 1386 // By default, mouse release removes capture. | |
| 1387 gfx::Point click_location(45, 15); | |
| 1388 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, | |
| 1389 ui::EF_LEFT_MOUSE_BUTTON); | |
| 1390 toplevel->OnMouseEvent(&release); | |
| 1391 EXPECT_FALSE(toplevel->HasCapture()); | |
| 1392 | |
| 1393 // Now a mouse release shouldn't remove capture. | |
| 1394 toplevel->set_auto_release_capture(false); | |
| 1395 toplevel->SetCapture(NULL); | |
| 1396 EXPECT_TRUE(toplevel->HasCapture()); | |
| 1397 toplevel->OnMouseEvent(&release); | |
| 1398 EXPECT_TRUE(toplevel->HasCapture()); | |
| 1399 toplevel->ReleaseCapture(); | |
| 1400 EXPECT_FALSE(toplevel->HasCapture()); | |
| 1401 | |
| 1402 toplevel->Close(); | |
| 1403 RunPendingMessages(); | |
| 1404 } | |
| 1405 | |
| 1373 #if defined(USE_AURA) | 1406 #if defined(USE_AURA) |
| 1374 // The key-event propagation from Widget happens differently on aura and | 1407 // The key-event propagation from Widget happens differently on aura and |
| 1375 // non-aura systems because of the difference in IME. So this test works only on | 1408 // non-aura systems because of the difference in IME. So this test works only on |
| 1376 // aura. | 1409 // aura. |
| 1377 TEST_F(WidgetTest, KeyboardInputEvent) { | 1410 TEST_F(WidgetTest, KeyboardInputEvent) { |
| 1378 Widget* toplevel = CreateTopLevelPlatformWidget(); | 1411 Widget* toplevel = CreateTopLevelPlatformWidget(); |
| 1379 View* container = toplevel->client_view(); | 1412 View* container = toplevel->client_view(); |
| 1380 | 1413 |
| 1381 Textfield* textfield = new Textfield(); | 1414 Textfield* textfield = new Textfield(); |
| 1382 textfield->SetText(ASCIIToUTF16("some text")); | 1415 textfield->SetText(ASCIIToUTF16("some text")); |
| (...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2378 | 2411 |
| 2379 std::set<Widget*> widgets; | 2412 std::set<Widget*> widgets; |
| 2380 Widget::GetAllChildWidgets(toplevel->GetNativeView(), &widgets); | 2413 Widget::GetAllChildWidgets(toplevel->GetNativeView(), &widgets); |
| 2381 | 2414 |
| 2382 EXPECT_EQ(expected.size(), widgets.size()); | 2415 EXPECT_EQ(expected.size(), widgets.size()); |
| 2383 EXPECT_TRUE(std::equal(expected.begin(), expected.end(), widgets.begin())); | 2416 EXPECT_TRUE(std::equal(expected.begin(), expected.end(), widgets.begin())); |
| 2384 } | 2417 } |
| 2385 | 2418 |
| 2386 } // namespace test | 2419 } // namespace test |
| 2387 } // namespace views | 2420 } // namespace views |
| OLD | NEW |