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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "grit/ui_strings.h" | 12 #include "grit/ui_strings.h" |
12 #include "ui/base/accelerators/accelerator.h" | 13 #include "ui/base/accelerators/accelerator.h" |
13 #include "ui/base/clipboard/clipboard.h" | 14 #include "ui/base/clipboard/clipboard.h" |
14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/compositor/compositor.h" | 16 #include "ui/compositor/compositor.h" |
16 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
17 #include "ui/compositor/layer_animator.h" | 18 #include "ui/compositor/layer_animator.h" |
18 #include "ui/compositor/test/draw_waiter_for_test.h" | 19 #include "ui/compositor/test/draw_waiter_for_test.h" |
19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
(...skipping 3767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3787 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3788 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3788 | 3789 |
3789 // We should find v2 and v3 in the widget_view cull_set. | 3790 // We should find v2 and v3 in the widget_view cull_set. |
3790 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3791 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
3791 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3792 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); |
3792 EXPECT_EQ(1U, widget_view->last_cull_set_.count(widget_view)); | 3793 EXPECT_EQ(1U, widget_view->last_cull_set_.count(widget_view)); |
3793 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v2)); | 3794 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v2)); |
3794 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v3)); | 3795 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v3)); |
3795 } | 3796 } |
3796 | 3797 |
| 3798 namespace { |
| 3799 |
| 3800 std::string ToString(const gfx::Vector2dF& vector) { |
| 3801 return base::StringPrintf("%.2f %0.2f", vector.x(), vector.y()); |
| 3802 } |
| 3803 |
| 3804 } // namespace |
| 3805 |
| 3806 TEST_F(ViewLayerTest, SnapLayerToPixel) { |
| 3807 View* v1 = new View; |
| 3808 |
| 3809 View* v11 = new View; |
| 3810 v1->AddChildView(v11); |
| 3811 |
| 3812 widget()->SetContentsView(v1); |
| 3813 |
| 3814 const gfx::Size& size = GetRootLayer()->GetCompositor()->size(); |
| 3815 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.25f, size); |
| 3816 |
| 3817 v11->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); |
| 3818 v1->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); |
| 3819 v11->SetPaintToLayer(true); |
| 3820 |
| 3821 EXPECT_EQ("0.40 0.40", ToString(v11->layer()->subpixel_position_offset())); |
| 3822 |
| 3823 // Creating a layer in parent should update the child view's layer offset. |
| 3824 v1->SetPaintToLayer(true); |
| 3825 EXPECT_EQ("-0.20 -0.20", ToString(v1->layer()->subpixel_position_offset())); |
| 3826 EXPECT_EQ("-0.20 -0.20", ToString(v11->layer()->subpixel_position_offset())); |
| 3827 |
| 3828 // DSF change should get propagated and update offsets. |
| 3829 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.5f, size); |
| 3830 EXPECT_EQ("0.33 0.33", ToString(v1->layer()->subpixel_position_offset())); |
| 3831 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); |
| 3832 |
| 3833 // Deleting parent's layer should update the child view's layer's offset. |
| 3834 v1->SetPaintToLayer(false); |
| 3835 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); |
| 3836 |
| 3837 // Setting parent view should update the child view's layer's offset. |
| 3838 v1->SetBoundsRect(gfx::Rect(2, 2, 10, 10)); |
| 3839 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); |
| 3840 |
| 3841 // Setting integral DSF should reset the offset. |
| 3842 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); |
| 3843 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); |
| 3844 } |
| 3845 |
3797 TEST_F(ViewTest, FocusableAssertions) { | 3846 TEST_F(ViewTest, FocusableAssertions) { |
3798 // View subclasses may change insets based on whether they are focusable, | 3847 // View subclasses may change insets based on whether they are focusable, |
3799 // which effects the preferred size. To avoid preferred size changing around | 3848 // which effects the preferred size. To avoid preferred size changing around |
3800 // these Views need to key off the last value set to SetFocusable(), not | 3849 // these Views need to key off the last value set to SetFocusable(), not |
3801 // whether the View is focusable right now. For this reason it's important | 3850 // whether the View is focusable right now. For this reason it's important |
3802 // that focusable() return the last value passed to SetFocusable and not | 3851 // that focusable() return the last value passed to SetFocusable and not |
3803 // whether the View is focusable right now. | 3852 // whether the View is focusable right now. |
3804 TestView view; | 3853 TestView view; |
3805 view.SetFocusable(true); | 3854 view.SetFocusable(true); |
3806 EXPECT_TRUE(view.focusable()); | 3855 EXPECT_TRUE(view.focusable()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3854 // notification. | 3903 // notification. |
3855 TestView* test_view_child_2 = new TestView(); | 3904 TestView* test_view_child_2 = new TestView(); |
3856 test_view->AddChildView(test_view_child_2); | 3905 test_view->AddChildView(test_view_child_2); |
3857 EXPECT_TRUE(test_view_child_2->native_theme_); | 3906 EXPECT_TRUE(test_view_child_2->native_theme_); |
3858 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3907 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3859 | 3908 |
3860 widget->CloseNow(); | 3909 widget->CloseNow(); |
3861 } | 3910 } |
3862 | 3911 |
3863 } // namespace views | 3912 } // namespace views |
OLD | NEW |