| 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 384 } |
| 385 | 385 |
| 386 TEST_F(ViewTest, MouseEvent) { | 386 TEST_F(ViewTest, MouseEvent) { |
| 387 TestView* v1 = new TestView(); | 387 TestView* v1 = new TestView(); |
| 388 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 388 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
| 389 | 389 |
| 390 TestView* v2 = new TestView(); | 390 TestView* v2 = new TestView(); |
| 391 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); | 391 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); |
| 392 | 392 |
| 393 scoped_ptr<Widget> widget(new Widget); | 393 scoped_ptr<Widget> widget(new Widget); |
| 394 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 394 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 395 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 396 params.bounds = gfx::Rect(50, 50, 650, 650); | 395 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 397 widget->Init(params); | 396 widget->Init(params); |
| 398 internal::RootView* root = | 397 internal::RootView* root = |
| 399 static_cast<internal::RootView*>(widget->GetRootView()); | 398 static_cast<internal::RootView*>(widget->GetRootView()); |
| 400 | 399 |
| 401 root->AddChildView(v1); | 400 root->AddChildView(v1); |
| 402 v1->AddChildView(v2); | 401 v1->AddChildView(v2); |
| 403 | 402 |
| 404 v1->Reset(); | 403 v1->Reset(); |
| 405 v2->Reset(); | 404 v2->Reset(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 TestView* v1 = new TestView(); | 445 TestView* v1 = new TestView(); |
| 447 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 446 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
| 448 | 447 |
| 449 TestView* v2 = new TestView(); | 448 TestView* v2 = new TestView(); |
| 450 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); | 449 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); |
| 451 | 450 |
| 452 v1->Reset(); | 451 v1->Reset(); |
| 453 v2->Reset(); | 452 v2->Reset(); |
| 454 | 453 |
| 455 scoped_ptr<Widget> widget(new Widget); | 454 scoped_ptr<Widget> widget(new Widget); |
| 456 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 455 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 457 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 458 params.bounds = gfx::Rect(50, 50, 650, 650); | 456 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 459 widget->Init(params); | 457 widget->Init(params); |
| 460 View* root = widget->GetRootView(); | 458 View* root = widget->GetRootView(); |
| 461 | 459 |
| 462 root->AddChildView(v1); | 460 root->AddChildView(v1); |
| 463 v1->AddChildView(v2); | 461 v1->AddChildView(v2); |
| 464 | 462 |
| 465 v2->delete_on_pressed_ = true; | 463 v2->delete_on_pressed_ = true; |
| 466 gfx::Point point(110, 120); | 464 gfx::Point point(110, 120); |
| 467 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, | 465 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 TestView* v1 = new TestView(); | 500 TestView* v1 = new TestView(); |
| 503 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 501 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
| 504 | 502 |
| 505 TestView* v2 = new TestView(); | 503 TestView* v2 = new TestView(); |
| 506 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); | 504 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); |
| 507 | 505 |
| 508 TestView* v3 = new TestViewIgnoreTouch(); | 506 TestView* v3 = new TestViewIgnoreTouch(); |
| 509 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 507 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
| 510 | 508 |
| 511 scoped_ptr<Widget> widget(new Widget()); | 509 scoped_ptr<Widget> widget(new Widget()); |
| 512 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 510 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 513 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 514 params.bounds = gfx::Rect(50, 50, 650, 650); | 511 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 515 widget->Init(params); | 512 widget->Init(params); |
| 516 internal::RootView* root = | 513 internal::RootView* root = |
| 517 static_cast<internal::RootView*>(widget->GetRootView()); | 514 static_cast<internal::RootView*>(widget->GetRootView()); |
| 518 | 515 |
| 519 root->AddChildView(v1); | 516 root->AddChildView(v1); |
| 520 v1->AddChildView(v2); | 517 v1->AddChildView(v2); |
| 521 v2->AddChildView(v3); | 518 v2->AddChildView(v3); |
| 522 | 519 |
| 523 // |v3| completely obscures |v2|, but all the touch events on |v3| should | 520 // |v3| completely obscures |v2|, but all the touch events on |v3| should |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 TestView* v1 = new TestViewConsumeGesture(); | 600 TestView* v1 = new TestViewConsumeGesture(); |
| 604 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 601 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
| 605 | 602 |
| 606 TestView* v2 = new TestViewConsumeGesture(); | 603 TestView* v2 = new TestViewConsumeGesture(); |
| 607 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); | 604 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); |
| 608 | 605 |
| 609 TestView* v3 = new TestViewIgnoreGesture(); | 606 TestView* v3 = new TestViewIgnoreGesture(); |
| 610 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 607 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
| 611 | 608 |
| 612 scoped_ptr<Widget> widget(new Widget()); | 609 scoped_ptr<Widget> widget(new Widget()); |
| 613 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 610 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 614 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 615 params.bounds = gfx::Rect(50, 50, 650, 650); | 611 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 616 widget->Init(params); | 612 widget->Init(params); |
| 617 internal::RootView* root = | 613 internal::RootView* root = |
| 618 static_cast<internal::RootView*>(widget->GetRootView()); | 614 static_cast<internal::RootView*>(widget->GetRootView()); |
| 619 | 615 |
| 620 root->AddChildView(v1); | 616 root->AddChildView(v1); |
| 621 v1->AddChildView(v2); | 617 v1->AddChildView(v2); |
| 622 v2->AddChildView(v3); | 618 v2->AddChildView(v3); |
| 623 | 619 |
| 624 // |v3| completely obscures |v2|, but all the gesture events on |v3| should | 620 // |v3| completely obscures |v2|, but all the gesture events on |v3| should |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 TestView* v1 = new TestViewConsumeGesture(); | 665 TestView* v1 = new TestViewConsumeGesture(); |
| 670 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); | 666 v1->SetBoundsRect(gfx::Rect(0, 0, 300, 300)); |
| 671 | 667 |
| 672 TestView* v2 = new TestViewIgnoreScrollGestures(); | 668 TestView* v2 = new TestViewIgnoreScrollGestures(); |
| 673 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); | 669 v2->SetBoundsRect(gfx::Rect(100, 100, 100, 100)); |
| 674 | 670 |
| 675 TestView* v3 = new TestViewIgnoreGesture(); | 671 TestView* v3 = new TestViewIgnoreGesture(); |
| 676 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 672 v3->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
| 677 | 673 |
| 678 scoped_ptr<Widget> widget(new Widget()); | 674 scoped_ptr<Widget> widget(new Widget()); |
| 679 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 675 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 680 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 681 params.bounds = gfx::Rect(50, 50, 650, 650); | 676 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 682 widget->Init(params); | 677 widget->Init(params); |
| 683 internal::RootView* root = | 678 internal::RootView* root = |
| 684 static_cast<internal::RootView*>(widget->GetRootView()); | 679 static_cast<internal::RootView*>(widget->GetRootView()); |
| 685 | 680 |
| 686 root->AddChildView(v1); | 681 root->AddChildView(v1); |
| 687 v1->AddChildView(v2); | 682 v1->AddChildView(v2); |
| 688 v2->AddChildView(v3); | 683 v2->AddChildView(v3); |
| 689 | 684 |
| 690 // |v3| completely obscures |v2|, but all the gesture events on |v3| should | 685 // |v3| completely obscures |v2|, but all the gesture events on |v3| should |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 void RotateClockwise(gfx::Transform* transform) { | 973 void RotateClockwise(gfx::Transform* transform) { |
| 979 transform->matrix().set3x3( 0, 1, 0, | 974 transform->matrix().set3x3( 0, 1, 0, |
| 980 -1, 0, 0, | 975 -1, 0, 0, |
| 981 0, 0, 1); | 976 0, 0, 1); |
| 982 } | 977 } |
| 983 | 978 |
| 984 } // namespace | 979 } // namespace |
| 985 | 980 |
| 986 TEST_F(ViewTest, HitTestMasks) { | 981 TEST_F(ViewTest, HitTestMasks) { |
| 987 Widget* widget = new Widget; | 982 Widget* widget = new Widget; |
| 988 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP)); | 983 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 984 widget->Init(params); |
| 989 View* root_view = widget->GetRootView(); | 985 View* root_view = widget->GetRootView(); |
| 990 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); | 986 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); |
| 991 | 987 |
| 992 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); | 988 gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100); |
| 993 HitTestView* v1 = new HitTestView(false); | 989 HitTestView* v1 = new HitTestView(false); |
| 994 v1->SetBoundsRect(v1_bounds); | 990 v1->SetBoundsRect(v1_bounds); |
| 995 root_view->AddChildView(v1); | 991 root_view->AddChildView(v1); |
| 996 | 992 |
| 997 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); | 993 gfx::Rect v2_bounds = gfx::Rect(105, 0, 100, 100); |
| 998 HitTestView* v2 = new HitTestView(true); | 994 HitTestView* v2 = new HitTestView(true); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint)); | 1030 EXPECT_EQ(v2, root_view->GetEventHandlerForPoint(v2_centerpoint)); |
| 1035 | 1031 |
| 1036 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin)); | 1032 EXPECT_EQ(v1, root_view->GetEventHandlerForPoint(v1_origin)); |
| 1037 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin)); | 1033 EXPECT_EQ(root_view, root_view->GetEventHandlerForPoint(v2_origin)); |
| 1038 | 1034 |
| 1039 widget->CloseNow(); | 1035 widget->CloseNow(); |
| 1040 } | 1036 } |
| 1041 | 1037 |
| 1042 TEST_F(ViewTest, NotifyEnterExitOnChild) { | 1038 TEST_F(ViewTest, NotifyEnterExitOnChild) { |
| 1043 Widget* widget = new Widget; | 1039 Widget* widget = new Widget; |
| 1044 widget->Init(Widget::InitParams(Widget::InitParams::TYPE_POPUP)); | 1040 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 1041 widget->Init(params); |
| 1045 View* root_view = widget->GetRootView(); | 1042 View* root_view = widget->GetRootView(); |
| 1046 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); | 1043 root_view->SetBoundsRect(gfx::Rect(0, 0, 500, 500)); |
| 1047 | 1044 |
| 1048 // Have this hierarchy of views (the coords here are in root coord): | 1045 // Have this hierarchy of views (the coords here are in root coord): |
| 1049 // v1 (0, 0, 100, 100) | 1046 // v1 (0, 0, 100, 100) |
| 1050 // - v11 (0, 0, 20, 30) | 1047 // - v11 (0, 0, 20, 30) |
| 1051 // - v111 (5, 5, 5, 15) | 1048 // - v111 (5, 5, 5, 15) |
| 1052 // - v12 (50, 10, 30, 90) | 1049 // - v12 (50, 10, 30, 90) |
| 1053 // - v121 (60, 20, 10, 10) | 1050 // - v121 (60, 20, 10, 10) |
| 1054 // v2 (105, 0, 100, 100) | 1051 // v2 (105, 0, 100, 100) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 widget->CloseNow(); | 1166 widget->CloseNow(); |
| 1170 } | 1167 } |
| 1171 | 1168 |
| 1172 TEST_F(ViewTest, Textfield) { | 1169 TEST_F(ViewTest, Textfield) { |
| 1173 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop " | 1170 const string16 kText = ASCIIToUTF16("Reality is that which, when you stop " |
| 1174 "believing it, doesn't go away."); | 1171 "believing it, doesn't go away."); |
| 1175 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!"); | 1172 const string16 kExtraText = ASCIIToUTF16("Pretty deep, Philip!"); |
| 1176 const string16 kEmptyString; | 1173 const string16 kEmptyString; |
| 1177 | 1174 |
| 1178 Widget* widget = new Widget; | 1175 Widget* widget = new Widget; |
| 1179 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 1176 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 1180 params.bounds = gfx::Rect(0, 0, 100, 100); | 1177 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 1181 widget->Init(params); | 1178 widget->Init(params); |
| 1182 View* root_view = widget->GetRootView(); | 1179 View* root_view = widget->GetRootView(); |
| 1183 | 1180 |
| 1184 Textfield* textfield = new Textfield(); | 1181 Textfield* textfield = new Textfield(); |
| 1185 root_view->AddChildView(textfield); | 1182 root_view->AddChildView(textfield); |
| 1186 | 1183 |
| 1187 // Test setting, appending text. | 1184 // Test setting, appending text. |
| 1188 textfield->SetText(kText); | 1185 textfield->SetText(kText); |
| 1189 EXPECT_EQ(kText, textfield->text()); | 1186 EXPECT_EQ(kText, textfield->text()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1207 | 1204 |
| 1208 // Tests that the Textfield view respond appropiately to cut/copy/paste. | 1205 // Tests that the Textfield view respond appropiately to cut/copy/paste. |
| 1209 TEST_F(ViewTest, TextfieldCutCopyPaste) { | 1206 TEST_F(ViewTest, TextfieldCutCopyPaste) { |
| 1210 const string16 kNormalText = ASCIIToUTF16("Normal"); | 1207 const string16 kNormalText = ASCIIToUTF16("Normal"); |
| 1211 const string16 kReadOnlyText = ASCIIToUTF16("Read only"); | 1208 const string16 kReadOnlyText = ASCIIToUTF16("Read only"); |
| 1212 const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **"); | 1209 const string16 kPasswordText = ASCIIToUTF16("Password! ** Secret stuff **"); |
| 1213 | 1210 |
| 1214 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 1211 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
| 1215 | 1212 |
| 1216 Widget* widget = new Widget; | 1213 Widget* widget = new Widget; |
| 1217 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 1214 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 1218 params.bounds = gfx::Rect(0, 0, 100, 100); | 1215 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 1219 widget->Init(params); | 1216 widget->Init(params); |
| 1220 View* root_view = widget->GetRootView(); | 1217 View* root_view = widget->GetRootView(); |
| 1221 | 1218 |
| 1222 Textfield* normal = new Textfield(); | 1219 Textfield* normal = new Textfield(); |
| 1223 Textfield* read_only = new Textfield(); | 1220 Textfield* read_only = new Textfield(); |
| 1224 read_only->SetReadOnly(true); | 1221 read_only->SetReadOnly(true); |
| 1225 Textfield* password = new Textfield(Textfield::STYLE_OBSCURED); | 1222 Textfield* password = new Textfield(Textfield::STYLE_OBSCURED); |
| 1226 | 1223 |
| 1227 root_view->AddChildView(normal); | 1224 root_view->AddChildView(normal); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 TEST_F(ViewTest, ActivateAccelerator) { | 1326 TEST_F(ViewTest, ActivateAccelerator) { |
| 1330 // Register a keyboard accelerator before the view is added to a window. | 1327 // Register a keyboard accelerator before the view is added to a window. |
| 1331 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); | 1328 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); |
| 1332 TestView* view = new TestView(); | 1329 TestView* view = new TestView(); |
| 1333 view->Reset(); | 1330 view->Reset(); |
| 1334 view->AddAccelerator(return_accelerator); | 1331 view->AddAccelerator(return_accelerator); |
| 1335 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 1332 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
| 1336 | 1333 |
| 1337 // Create a window and add the view as its child. | 1334 // Create a window and add the view as its child. |
| 1338 scoped_ptr<Widget> widget(new Widget); | 1335 scoped_ptr<Widget> widget(new Widget); |
| 1339 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 1336 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 1340 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 1341 params.bounds = gfx::Rect(0, 0, 100, 100); | 1337 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 1342 widget->Init(params); | 1338 widget->Init(params); |
| 1343 View* root = widget->GetRootView(); | 1339 View* root = widget->GetRootView(); |
| 1344 root->AddChildView(view); | 1340 root->AddChildView(view); |
| 1345 widget->Show(); | 1341 widget->Show(); |
| 1346 | 1342 |
| 1347 // Get the focus manager. | 1343 // Get the focus manager. |
| 1348 FocusManager* focus_manager = widget->GetFocusManager(); | 1344 FocusManager* focus_manager = widget->GetFocusManager(); |
| 1349 ASSERT_TRUE(focus_manager); | 1345 ASSERT_TRUE(focus_manager); |
| 1350 | 1346 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 | 1390 |
| 1395 #if defined(OS_WIN) && !defined(USE_AURA) | 1391 #if defined(OS_WIN) && !defined(USE_AURA) |
| 1396 TEST_F(ViewTest, HiddenViewWithAccelerator) { | 1392 TEST_F(ViewTest, HiddenViewWithAccelerator) { |
| 1397 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); | 1393 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); |
| 1398 TestView* view = new TestView(); | 1394 TestView* view = new TestView(); |
| 1399 view->Reset(); | 1395 view->Reset(); |
| 1400 view->AddAccelerator(return_accelerator); | 1396 view->AddAccelerator(return_accelerator); |
| 1401 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 1397 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
| 1402 | 1398 |
| 1403 scoped_ptr<Widget> widget(new Widget); | 1399 scoped_ptr<Widget> widget(new Widget); |
| 1404 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 1400 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 1405 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 1406 params.bounds = gfx::Rect(0, 0, 100, 100); | 1401 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 1407 widget->Init(params); | 1402 widget->Init(params); |
| 1408 View* root = widget->GetRootView(); | 1403 View* root = widget->GetRootView(); |
| 1409 root->AddChildView(view); | 1404 root->AddChildView(view); |
| 1410 widget->Show(); | 1405 widget->Show(); |
| 1411 | 1406 |
| 1412 FocusManager* focus_manager = widget->GetFocusManager(); | 1407 FocusManager* focus_manager = widget->GetFocusManager(); |
| 1413 ASSERT_TRUE(focus_manager); | 1408 ASSERT_TRUE(focus_manager); |
| 1414 | 1409 |
| 1415 view->SetVisible(false); | 1410 view->SetVisible(false); |
| 1416 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | 1411 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 1417 | 1412 |
| 1418 view->SetVisible(true); | 1413 view->SetVisible(true); |
| 1419 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); | 1414 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 1420 | 1415 |
| 1421 widget->CloseNow(); | 1416 widget->CloseNow(); |
| 1422 } | 1417 } |
| 1423 #endif | 1418 #endif |
| 1424 | 1419 |
| 1425 #if defined(OS_WIN) && !defined(USE_AURA) | 1420 #if defined(OS_WIN) && !defined(USE_AURA) |
| 1426 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) { | 1421 TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) { |
| 1427 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); | 1422 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); |
| 1428 TestView* view = new TestView(); | 1423 TestView* view = new TestView(); |
| 1429 view->Reset(); | 1424 view->Reset(); |
| 1430 view->AddAccelerator(return_accelerator); | 1425 view->AddAccelerator(return_accelerator); |
| 1431 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 1426 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
| 1432 | 1427 |
| 1433 scoped_ptr<Widget> widget(new Widget); | 1428 scoped_ptr<Widget> widget(new Widget); |
| 1434 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 1429 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 1435 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 1436 params.bounds = gfx::Rect(0, 0, 100, 100); | 1430 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 1437 widget->Init(params); | 1431 widget->Init(params); |
| 1438 View* root = widget->GetRootView(); | 1432 View* root = widget->GetRootView(); |
| 1439 root->AddChildView(view); | 1433 root->AddChildView(view); |
| 1440 | 1434 |
| 1441 FocusManager* focus_manager = widget->GetFocusManager(); | 1435 FocusManager* focus_manager = widget->GetFocusManager(); |
| 1442 ASSERT_TRUE(focus_manager); | 1436 ASSERT_TRUE(focus_manager); |
| 1443 | 1437 |
| 1444 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | 1438 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 1445 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); | 1439 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 : focus_manager_(NULL), | 1689 : focus_manager_(NULL), |
| 1696 test_dialog_(NULL), | 1690 test_dialog_(NULL), |
| 1697 client_view_(NULL), | 1691 client_view_(NULL), |
| 1698 ok_button_(NULL), | 1692 ok_button_(NULL), |
| 1699 cancel_button_(NULL) { | 1693 cancel_button_(NULL) { |
| 1700 } | 1694 } |
| 1701 | 1695 |
| 1702 virtual void SetUp() OVERRIDE { | 1696 virtual void SetUp() OVERRIDE { |
| 1703 ViewTest::SetUp(); | 1697 ViewTest::SetUp(); |
| 1704 test_dialog_ = new TestDialog(NULL); | 1698 test_dialog_ = new TestDialog(NULL); |
| 1705 Widget* window = | 1699 |
| 1706 Widget::CreateWindowWithBounds(test_dialog_, gfx::Rect(0, 0, 100, 100)); | 1700 Widget* window = new Widget; |
| 1701 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 1702 params.delegate = test_dialog_; |
| 1703 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 1704 window->Init(params); |
| 1705 |
| 1707 test_dialog_->widget_ = window; | 1706 test_dialog_->widget_ = window; |
| 1708 window->Show(); | 1707 window->Show(); |
| 1709 focus_manager_ = test_dialog_->contents_->GetFocusManager(); | 1708 focus_manager_ = test_dialog_->contents_->GetFocusManager(); |
| 1710 ASSERT_TRUE(focus_manager_ != NULL); | 1709 ASSERT_TRUE(focus_manager_ != NULL); |
| 1711 client_view_ = | 1710 client_view_ = |
| 1712 static_cast<DialogClientView*>(window->client_view()); | 1711 static_cast<DialogClientView*>(window->client_view()); |
| 1713 ok_button_ = client_view_->ok_button(); | 1712 ok_button_ = client_view_->ok_button(); |
| 1714 cancel_button_ = client_view_->cancel_button(); | 1713 cancel_button_ = client_view_->cancel_button(); |
| 1715 } | 1714 } |
| 1716 | 1715 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 class ButtonDropDownTest : public ViewTest { | 1805 class ButtonDropDownTest : public ViewTest { |
| 1807 public: | 1806 public: |
| 1808 ButtonDropDownTest() | 1807 ButtonDropDownTest() |
| 1809 : test_dialog_(NULL), | 1808 : test_dialog_(NULL), |
| 1810 button_as_view_(NULL) { | 1809 button_as_view_(NULL) { |
| 1811 } | 1810 } |
| 1812 | 1811 |
| 1813 virtual void SetUp() OVERRIDE { | 1812 virtual void SetUp() OVERRIDE { |
| 1814 ViewTest::SetUp(); | 1813 ViewTest::SetUp(); |
| 1815 test_dialog_ = new TestDialog(new MockMenuModel()); | 1814 test_dialog_ = new TestDialog(new MockMenuModel()); |
| 1816 Widget* window = | 1815 |
| 1817 Widget::CreateWindowWithBounds(test_dialog_, gfx::Rect(0, 0, 100, 100)); | 1816 Widget* window = new Widget; |
| 1817 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 1818 params.delegate = test_dialog_; |
| 1819 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 1820 window->Init(params); |
| 1821 |
| 1818 test_dialog_->widget_ = window; | 1822 test_dialog_->widget_ = window; |
| 1819 window->Show(); | 1823 window->Show(); |
| 1820 test_dialog_->button_drop_->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 1824 test_dialog_->button_drop_->SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
| 1821 // We have to cast the button back into a View in order to invoke it's | 1825 // We have to cast the button back into a View in order to invoke it's |
| 1822 // OnMouseReleased method. | 1826 // OnMouseReleased method. |
| 1823 button_as_view_ = static_cast<View*>(test_dialog_->button_drop_); | 1827 button_as_view_ = static_cast<View*>(test_dialog_->button_drop_); |
| 1824 } | 1828 } |
| 1825 | 1829 |
| 1826 virtual void TearDown() OVERRIDE { | 1830 virtual void TearDown() OVERRIDE { |
| 1827 test_dialog_->TearDown(); | 1831 test_dialog_->TearDown(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2033 }; | 2037 }; |
| 2034 | 2038 |
| 2035 TEST_F(ViewTest, TransformPaint) { | 2039 TEST_F(ViewTest, TransformPaint) { |
| 2036 TransformPaintView* v1 = new TransformPaintView(); | 2040 TransformPaintView* v1 = new TransformPaintView(); |
| 2037 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300)); | 2041 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300)); |
| 2038 | 2042 |
| 2039 TestView* v2 = new TestView(); | 2043 TestView* v2 = new TestView(); |
| 2040 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100)); | 2044 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100)); |
| 2041 | 2045 |
| 2042 Widget* widget = new Widget; | 2046 Widget* widget = new Widget; |
| 2043 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 2047 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 2044 params.bounds = gfx::Rect(50, 50, 650, 650); | 2048 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 2045 widget->Init(params); | 2049 widget->Init(params); |
| 2046 widget->Show(); | 2050 widget->Show(); |
| 2047 View* root = widget->GetRootView(); | 2051 View* root = widget->GetRootView(); |
| 2048 | 2052 |
| 2049 root->AddChildView(v1); | 2053 root->AddChildView(v1); |
| 2050 v1->AddChildView(v2); | 2054 v1->AddChildView(v2); |
| 2051 | 2055 |
| 2052 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. | 2056 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. |
| 2053 v1->ClearScheduledPaintRect(); | 2057 v1->ClearScheduledPaintRect(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2072 } | 2076 } |
| 2073 | 2077 |
| 2074 TEST_F(ViewTest, TransformEvent) { | 2078 TEST_F(ViewTest, TransformEvent) { |
| 2075 TestView* v1 = new TestView(); | 2079 TestView* v1 = new TestView(); |
| 2076 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300)); | 2080 v1->SetBoundsRect(gfx::Rect(0, 0, 500, 300)); |
| 2077 | 2081 |
| 2078 TestView* v2 = new TestView(); | 2082 TestView* v2 = new TestView(); |
| 2079 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100)); | 2083 v2->SetBoundsRect(gfx::Rect(100, 100, 200, 100)); |
| 2080 | 2084 |
| 2081 Widget* widget = new Widget; | 2085 Widget* widget = new Widget; |
| 2082 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 2086 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 2083 params.bounds = gfx::Rect(50, 50, 650, 650); | 2087 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 2084 widget->Init(params); | 2088 widget->Init(params); |
| 2085 View* root = widget->GetRootView(); | 2089 View* root = widget->GetRootView(); |
| 2086 | 2090 |
| 2087 root->AddChildView(v1); | 2091 root->AddChildView(v1); |
| 2088 v1->AddChildView(v2); | 2092 v1->AddChildView(v2); |
| 2089 | 2093 |
| 2090 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. | 2094 // At this moment, |v2| occupies (100, 100) to (300, 200) in |root|. |
| 2091 | 2095 |
| 2092 // Rotate |v1| counter-clockwise. | 2096 // Rotate |v1| counter-clockwise. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 | 2213 |
| 2210 root->OnMouseReleased(released); | 2214 root->OnMouseReleased(released); |
| 2211 | 2215 |
| 2212 widget->CloseNow(); | 2216 widget->CloseNow(); |
| 2213 } | 2217 } |
| 2214 | 2218 |
| 2215 TEST_F(ViewTest, TransformVisibleBound) { | 2219 TEST_F(ViewTest, TransformVisibleBound) { |
| 2216 gfx::Rect viewport_bounds(0, 0, 100, 100); | 2220 gfx::Rect viewport_bounds(0, 0, 100, 100); |
| 2217 | 2221 |
| 2218 scoped_ptr<Widget> widget(new Widget); | 2222 scoped_ptr<Widget> widget(new Widget); |
| 2219 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 2223 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 2220 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 2221 params.bounds = viewport_bounds; | 2224 params.bounds = viewport_bounds; |
| 2222 widget->Init(params); | 2225 widget->Init(params); |
| 2223 widget->GetRootView()->SetBoundsRect(viewport_bounds); | 2226 widget->GetRootView()->SetBoundsRect(viewport_bounds); |
| 2224 | 2227 |
| 2225 View* viewport = new View; | 2228 View* viewport = new View; |
| 2226 widget->SetContentsView(viewport); | 2229 widget->SetContentsView(viewport); |
| 2227 View* contents = new View; | 2230 View* contents = new View; |
| 2228 viewport->AddChildView(contents); | 2231 viewport->AddChildView(contents); |
| 2229 viewport->SetBoundsRect(viewport_bounds); | 2232 viewport->SetBoundsRect(viewport_bounds); |
| 2230 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); | 2233 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2268 | 2271 |
| 2269 bool received_notification_; | 2272 bool received_notification_; |
| 2270 | 2273 |
| 2271 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView); | 2274 DISALLOW_COPY_AND_ASSIGN(VisibleBoundsView); |
| 2272 }; | 2275 }; |
| 2273 | 2276 |
| 2274 TEST_F(ViewTest, OnVisibleBoundsChanged) { | 2277 TEST_F(ViewTest, OnVisibleBoundsChanged) { |
| 2275 gfx::Rect viewport_bounds(0, 0, 100, 100); | 2278 gfx::Rect viewport_bounds(0, 0, 100, 100); |
| 2276 | 2279 |
| 2277 scoped_ptr<Widget> widget(new Widget); | 2280 scoped_ptr<Widget> widget(new Widget); |
| 2278 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 2281 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 2279 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 2280 params.bounds = viewport_bounds; | 2282 params.bounds = viewport_bounds; |
| 2281 widget->Init(params); | 2283 widget->Init(params); |
| 2282 widget->GetRootView()->SetBoundsRect(viewport_bounds); | 2284 widget->GetRootView()->SetBoundsRect(viewport_bounds); |
| 2283 | 2285 |
| 2284 View* viewport = new View; | 2286 View* viewport = new View; |
| 2285 widget->SetContentsView(viewport); | 2287 widget->SetContentsView(viewport); |
| 2286 View* contents = new View; | 2288 View* contents = new View; |
| 2287 viewport->AddChildView(contents); | 2289 viewport->AddChildView(contents); |
| 2288 viewport->SetBoundsRect(viewport_bounds); | 2290 viewport->SetBoundsRect(viewport_bounds); |
| 2289 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); | 2291 contents->SetBoundsRect(gfx::Rect(0, 0, 100, 200)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2443 gfx::Point point(6, 18); | 2445 gfx::Point point(6, 18); |
| 2444 View::ConvertPointToTarget(&top_view, child, &point); | 2446 View::ConvertPointToTarget(&top_view, child, &point); |
| 2445 EXPECT_EQ(-1, point.x()); | 2447 EXPECT_EQ(-1, point.x()); |
| 2446 EXPECT_EQ(-1, point.y()); | 2448 EXPECT_EQ(-1, point.y()); |
| 2447 } | 2449 } |
| 2448 } | 2450 } |
| 2449 | 2451 |
| 2450 // Tests conversion methods for rectangles. | 2452 // Tests conversion methods for rectangles. |
| 2451 TEST_F(ViewTest, ConvertRectWithTransform) { | 2453 TEST_F(ViewTest, ConvertRectWithTransform) { |
| 2452 scoped_ptr<Widget> widget(new Widget); | 2454 scoped_ptr<Widget> widget(new Widget); |
| 2453 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 2455 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 2454 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 2455 params.bounds = gfx::Rect(50, 50, 650, 650); | 2456 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 2456 widget->Init(params); | 2457 widget->Init(params); |
| 2457 View* root = widget->GetRootView(); | 2458 View* root = widget->GetRootView(); |
| 2458 | 2459 |
| 2459 TestView* v1 = new TestView; | 2460 TestView* v1 = new TestView; |
| 2460 TestView* v2 = new TestView; | 2461 TestView* v2 = new TestView; |
| 2461 root->AddChildView(v1); | 2462 root->AddChildView(v1); |
| 2462 v1->AddChildView(v2); | 2463 v1->AddChildView(v2); |
| 2463 | 2464 |
| 2464 v1->SetBoundsRect(gfx::Rect(10, 10, 500, 500)); | 2465 v1->SetBoundsRect(gfx::Rect(10, 10, 500, 500)); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2915 widget()->CalculateOffsetToAncestorWithLayer(&root_layer); | 2916 widget()->CalculateOffsetToAncestorWithLayer(&root_layer); |
| 2916 return root_layer; | 2917 return root_layer; |
| 2917 } | 2918 } |
| 2918 | 2919 |
| 2919 virtual void SetUp() OVERRIDE { | 2920 virtual void SetUp() OVERRIDE { |
| 2920 ViewTest::SetUp(); | 2921 ViewTest::SetUp(); |
| 2921 old_use_acceleration_ = View::get_use_acceleration_when_possible(); | 2922 old_use_acceleration_ = View::get_use_acceleration_when_possible(); |
| 2922 View::set_use_acceleration_when_possible(true); | 2923 View::set_use_acceleration_when_possible(true); |
| 2923 | 2924 |
| 2924 widget_ = new Widget; | 2925 widget_ = new Widget; |
| 2925 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 2926 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 2926 params.bounds = gfx::Rect(50, 50, 200, 200); | 2927 params.bounds = gfx::Rect(50, 50, 200, 200); |
| 2927 widget_->Init(params); | 2928 widget_->Init(params); |
| 2928 widget_->Show(); | 2929 widget_->Show(); |
| 2929 widget_->GetRootView()->SetBounds(0, 0, 200, 200); | 2930 widget_->GetRootView()->SetBounds(0, 0, 200, 200); |
| 2930 } | 2931 } |
| 2931 | 2932 |
| 2932 virtual void TearDown() OVERRIDE { | 2933 virtual void TearDown() OVERRIDE { |
| 2933 View::set_use_acceleration_when_possible(old_use_acceleration_); | 2934 View::set_use_acceleration_when_possible(old_use_acceleration_); |
| 2934 widget_->CloseNow(); | 2935 widget_->CloseNow(); |
| 2935 ViewsTestBase::TearDown(); | 2936 ViewsTestBase::TearDown(); |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3391 // Set to non default value. | 3392 // Set to non default value. |
| 3392 v->layer()->set_scale_content(false); | 3393 v->layer()->set_scale_content(false); |
| 3393 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); | 3394 scoped_ptr<ui::Layer> old_layer(v->RecreateLayer()); |
| 3394 ui::Layer* new_layer = v->layer(); | 3395 ui::Layer* new_layer = v->layer(); |
| 3395 EXPECT_FALSE(new_layer->scale_content()); | 3396 EXPECT_FALSE(new_layer->scale_content()); |
| 3396 } | 3397 } |
| 3397 | 3398 |
| 3398 #endif // USE_AURA | 3399 #endif // USE_AURA |
| 3399 | 3400 |
| 3400 } // namespace views | 3401 } // namespace views |
| OLD | NEW |