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/view.h" | 5 #include "ui/views/view.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 3408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3419 | 3419 |
3420 View* child = new View(); | 3420 View* child = new View(); |
3421 root.AddChildView(child); | 3421 root.AddChildView(child); |
3422 | 3422 |
3423 View* foo1 = new View(); | 3423 View* foo1 = new View(); |
3424 child->AddChildView(foo1); | 3424 child->AddChildView(foo1); |
3425 View* foo2 = new View(); | 3425 View* foo2 = new View(); |
3426 child->AddChildView(foo2); | 3426 child->AddChildView(foo2); |
3427 View* foo3 = new View(); | 3427 View* foo3 = new View(); |
3428 child->AddChildView(foo3); | 3428 child->AddChildView(foo3); |
3429 foo1->SetFocusable(true); | 3429 foo1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
3430 foo2->SetFocusable(true); | 3430 foo2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
3431 foo3->SetFocusable(true); | 3431 foo3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
3432 | 3432 |
3433 ASSERT_EQ(0, child->GetIndexOf(foo1)); | 3433 ASSERT_EQ(0, child->GetIndexOf(foo1)); |
3434 ASSERT_EQ(1, child->GetIndexOf(foo2)); | 3434 ASSERT_EQ(1, child->GetIndexOf(foo2)); |
3435 ASSERT_EQ(2, child->GetIndexOf(foo3)); | 3435 ASSERT_EQ(2, child->GetIndexOf(foo3)); |
3436 ASSERT_EQ(foo2, foo1->GetNextFocusableView()); | 3436 ASSERT_EQ(foo2, foo1->GetNextFocusableView()); |
3437 ASSERT_EQ(foo3, foo2->GetNextFocusableView()); | 3437 ASSERT_EQ(foo3, foo2->GetNextFocusableView()); |
3438 ASSERT_EQ(NULL, foo3->GetNextFocusableView()); | 3438 ASSERT_EQ(NULL, foo3->GetNextFocusableView()); |
3439 | 3439 |
3440 // Move |foo2| at the end. | 3440 // Move |foo2| at the end. |
3441 child->ReorderChildView(foo2, -1); | 3441 child->ReorderChildView(foo2, -1); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3566 }; | 3566 }; |
3567 | 3567 |
3568 TEST_F(ViewTest, AdvanceFocusIfNecessaryForUnfocusableView) { | 3568 TEST_F(ViewTest, AdvanceFocusIfNecessaryForUnfocusableView) { |
3569 // Create a widget with two views and give the first one focus. | 3569 // Create a widget with two views and give the first one focus. |
3570 ActiveWidget widget; | 3570 ActiveWidget widget; |
3571 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 3571 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
3572 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 3572 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
3573 widget.Init(params); | 3573 widget.Init(params); |
3574 | 3574 |
3575 View* view1 = new View(); | 3575 View* view1 = new View(); |
3576 view1->SetFocusable(true); | 3576 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 3577 |
3577 widget.GetRootView()->AddChildView(view1); | 3578 widget.GetRootView()->AddChildView(view1); |
3578 View* view2 = new View(); | 3579 View* view2 = new View(); |
3579 view2->SetFocusable(true); | 3580 view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
3580 widget.GetRootView()->AddChildView(view2); | 3581 widget.GetRootView()->AddChildView(view2); |
3581 | 3582 |
3582 FocusManager* focus_manager = widget.GetFocusManager(); | 3583 FocusManager* focus_manager = widget.GetFocusManager(); |
3583 ASSERT_TRUE(focus_manager); | 3584 ASSERT_TRUE(focus_manager); |
3584 | 3585 |
3585 focus_manager->SetFocusedView(view1); | 3586 focus_manager->SetFocusedView(view1); |
3586 EXPECT_EQ(view1, focus_manager->GetFocusedView()); | 3587 EXPECT_EQ(view1, focus_manager->GetFocusedView()); |
3587 | 3588 |
3588 // Disable the focused view and check if the next view gets focused. | 3589 // Disable the focused view and check if the next view gets focused. |
3589 view1->SetEnabled(false); | 3590 view1->SetEnabled(false); |
3590 EXPECT_EQ(view2, focus_manager->GetFocusedView()); | 3591 EXPECT_EQ(view2, focus_manager->GetFocusedView()); |
3591 | 3592 |
3592 // Re-enable and re-focus. | 3593 // Re-enable and re-focus. |
3593 view1->SetEnabled(true); | 3594 view1->SetEnabled(true); |
3594 focus_manager->SetFocusedView(view1); | 3595 focus_manager->SetFocusedView(view1); |
3595 EXPECT_EQ(view1, focus_manager->GetFocusedView()); | 3596 EXPECT_EQ(view1, focus_manager->GetFocusedView()); |
3596 | 3597 |
3597 // Hide the focused view and check it the next view gets focused. | 3598 // Hide the focused view and check it the next view gets focused. |
3598 view1->SetVisible(false); | 3599 view1->SetVisible(false); |
3599 EXPECT_EQ(view2, focus_manager->GetFocusedView()); | 3600 EXPECT_EQ(view2, focus_manager->GetFocusedView()); |
3600 | 3601 |
3601 // Re-show and re-focus. | 3602 // Re-show and re-focus. |
3602 view1->SetVisible(true); | 3603 view1->SetVisible(true); |
3603 focus_manager->SetFocusedView(view1); | 3604 focus_manager->SetFocusedView(view1); |
3604 EXPECT_EQ(view1, focus_manager->GetFocusedView()); | 3605 EXPECT_EQ(view1, focus_manager->GetFocusedView()); |
3605 | 3606 |
3606 // Set the focused view as not focusable and check if the next view gets | 3607 // Set the focused view as not focusable and check if the next view gets |
3607 // focused. | 3608 // focused. |
3608 view1->SetFocusable(false); | 3609 view1->SetFocusBehavior(views::View::FocusBehavior::NEVER); |
3609 EXPECT_EQ(view2, focus_manager->GetFocusedView()); | 3610 EXPECT_EQ(view2, focus_manager->GetFocusedView()); |
3610 } | 3611 } |
3611 | 3612 |
3612 //////////////////////////////////////////////////////////////////////////////// | 3613 //////////////////////////////////////////////////////////////////////////////// |
3613 // Layers | 3614 // Layers |
3614 //////////////////////////////////////////////////////////////////////////////// | 3615 //////////////////////////////////////////////////////////////////////////////// |
3615 | 3616 |
3616 namespace { | 3617 namespace { |
3617 | 3618 |
3618 // Test implementation of LayerAnimator. | 3619 // Test implementation of LayerAnimator. |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4361 } | 4362 } |
4362 | 4363 |
4363 TEST_F(ViewTest, FocusableAssertions) { | 4364 TEST_F(ViewTest, FocusableAssertions) { |
4364 // View subclasses may change insets based on whether they are focusable, | 4365 // View subclasses may change insets based on whether they are focusable, |
4365 // which effects the preferred size. To avoid preferred size changing around | 4366 // which effects the preferred size. To avoid preferred size changing around |
4366 // these Views need to key off the last value set to SetFocusable(), not | 4367 // these Views need to key off the last value set to SetFocusable(), not |
4367 // whether the View is focusable right now. For this reason it's important | 4368 // whether the View is focusable right now. For this reason it's important |
4368 // that focusable() return the last value passed to SetFocusable and not | 4369 // that focusable() return the last value passed to SetFocusable and not |
4369 // whether the View is focusable right now. | 4370 // whether the View is focusable right now. |
4370 TestView view; | 4371 TestView view; |
4371 view.SetFocusable(true); | 4372 view.SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
4372 EXPECT_TRUE(view.focusable()); | 4373 EXPECT_TRUE(view.focusable()); |
4373 view.SetEnabled(false); | 4374 view.SetEnabled(false); |
4374 EXPECT_TRUE(view.focusable()); | 4375 EXPECT_TRUE(view.focusable()); |
4375 view.SetFocusable(false); | 4376 view.SetFocusBehavior(views::View::FocusBehavior::NEVER); |
4376 EXPECT_FALSE(view.focusable()); | 4377 EXPECT_FALSE(view.focusable()); |
4377 } | 4378 } |
4378 | 4379 |
4379 // Verifies when a view is deleted it is removed from ViewStorage. | 4380 // Verifies when a view is deleted it is removed from ViewStorage. |
4380 TEST_F(ViewTest, UpdateViewStorageOnDelete) { | 4381 TEST_F(ViewTest, UpdateViewStorageOnDelete) { |
4381 ViewStorage* view_storage = ViewStorage::GetInstance(); | 4382 ViewStorage* view_storage = ViewStorage::GetInstance(); |
4382 const int storage_id = view_storage->CreateStorageID(); | 4383 const int storage_id = view_storage->CreateStorageID(); |
4383 { | 4384 { |
4384 View view; | 4385 View view; |
4385 view_storage->StoreView(storage_id, &view); | 4386 view_storage->StoreView(storage_id, &view); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4565 widget.Init(params); | 4566 widget.Init(params); |
4566 | 4567 |
4567 AddViewWithChildLayer(widget.GetRootView()); | 4568 AddViewWithChildLayer(widget.GetRootView()); |
4568 ViewThatAddsViewInOnNativeThemeChanged* v = | 4569 ViewThatAddsViewInOnNativeThemeChanged* v = |
4569 new ViewThatAddsViewInOnNativeThemeChanged; | 4570 new ViewThatAddsViewInOnNativeThemeChanged; |
4570 widget.GetRootView()->AddChildView(v); | 4571 widget.GetRootView()->AddChildView(v); |
4571 EXPECT_TRUE(v->on_native_theme_changed_called()); | 4572 EXPECT_TRUE(v->on_native_theme_changed_called()); |
4572 } | 4573 } |
4573 | 4574 |
4574 } // namespace views | 4575 } // namespace views |
OLD | NEW |