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 3877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3897 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); | 3898 EXPECT_EQ(1U, test_view->last_cull_set_.count(v1)); |
3898 | 3899 |
3899 // We should find v2 and v3 in the widget_view cull_set. | 3900 // We should find v2 and v3 in the widget_view cull_set. |
3900 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); | 3901 EXPECT_EQ(4U, widget_view->last_cull_set_.size()); |
3901 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); | 3902 EXPECT_EQ(1U, widget_view->last_cull_set_.count(test_widget->GetRootView())); |
3902 EXPECT_EQ(1U, widget_view->last_cull_set_.count(widget_view)); | 3903 EXPECT_EQ(1U, widget_view->last_cull_set_.count(widget_view)); |
3903 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v2)); | 3904 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v2)); |
3904 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v3)); | 3905 EXPECT_EQ(1U, widget_view->last_cull_set_.count(v3)); |
3905 } | 3906 } |
3906 | 3907 |
3908 namespace { | |
3909 | |
3910 std::string ToString(const gfx::Vector2dF& vector) { | |
3911 return base::StringPrintf("%.2f %0.2f", vector.x(), vector.y()); | |
3912 } | |
3913 | |
3914 } // namespace | |
3915 | |
3916 TEST_F(ViewLayerTest, SnapLayerToPixel) { | |
3917 View* v1 = new View; | |
3918 | |
3919 View* v11 = new View; | |
3920 v1->AddChildView(v11); | |
3921 | |
3922 widget()->SetContentsView(v1); | |
3923 | |
3924 const gfx::Size& size = GetRootLayer()->GetCompositor()->size(); | |
3925 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.25f, size); | |
3926 | |
3927 v11->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); | |
3928 v1->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); | |
3929 v11->SetPaintToLayer(true); | |
3930 | |
3931 EXPECT_EQ("0.40 0.40", ToString(v11->layer()->subpixel_position_offset())); | |
3932 | |
3933 // Creating a layer in parent should update the child view's layer offset. | |
3934 v1->SetPaintToLayer(true); | |
3935 EXPECT_EQ("-0.20 -0.20", ToString(v1->layer()->subpixel_position_offset())); | |
3936 EXPECT_EQ("-0.20 -0.20", ToString(v11->layer()->subpixel_position_offset())); | |
3937 | |
3938 // DSF change shoud get propagated and update offsets. | |
danakj
2014/07/15 21:11:02
should
oshima
2014/07/15 22:28:42
Done.
| |
3939 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.5f, size); | |
3940 EXPECT_EQ("0.33 0.33", ToString(v1->layer()->subpixel_position_offset())); | |
3941 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); | |
3942 | |
3943 // Deleting parent' layer should update the child view's layer's offset. | |
danakj
2014/07/15 21:11:02
s/'//
oshima
2014/07/15 22:28:42
Done.
| |
3944 v1->SetPaintToLayer(false); | |
3945 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); | |
3946 | |
3947 // Setting parent view should update the child view's layer's offset. | |
3948 v1->SetBoundsRect(gfx::Rect(2, 2, 10, 10)); | |
3949 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); | |
3950 | |
3951 // Setting integral DSF should reset the offset. | |
3952 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); | |
3953 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); | |
3954 } | |
3955 | |
3907 TEST_F(ViewTest, FocusableAssertions) { | 3956 TEST_F(ViewTest, FocusableAssertions) { |
3908 // View subclasses may change insets based on whether they are focusable, | 3957 // View subclasses may change insets based on whether they are focusable, |
3909 // which effects the preferred size. To avoid preferred size changing around | 3958 // which effects the preferred size. To avoid preferred size changing around |
3910 // these Views need to key off the last value set to SetFocusable(), not | 3959 // these Views need to key off the last value set to SetFocusable(), not |
3911 // whether the View is focusable right now. For this reason it's important | 3960 // whether the View is focusable right now. For this reason it's important |
3912 // that focusable() return the last value passed to SetFocusable and not | 3961 // that focusable() return the last value passed to SetFocusable and not |
3913 // whether the View is focusable right now. | 3962 // whether the View is focusable right now. |
3914 TestView view; | 3963 TestView view; |
3915 view.SetFocusable(true); | 3964 view.SetFocusable(true); |
3916 EXPECT_TRUE(view.focusable()); | 3965 EXPECT_TRUE(view.focusable()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3964 // notification. | 4013 // notification. |
3965 TestView* test_view_child_2 = new TestView(); | 4014 TestView* test_view_child_2 = new TestView(); |
3966 test_view->AddChildView(test_view_child_2); | 4015 test_view->AddChildView(test_view_child_2); |
3967 EXPECT_TRUE(test_view_child_2->native_theme_); | 4016 EXPECT_TRUE(test_view_child_2->native_theme_); |
3968 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 4017 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3969 | 4018 |
3970 widget->CloseNow(); | 4019 widget->CloseNow(); |
3971 } | 4020 } |
3972 | 4021 |
3973 } // namespace views | 4022 } // namespace views |
OLD | NEW |