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/stringprintf.h" |
(...skipping 2914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2925 // sure the bounds are correct. | 2925 // sure the bounds are correct. |
2926 View* v2 = new View; | 2926 View* v2 = new View; |
2927 v2->SetBounds(50, 10, 30, 10); | 2927 v2->SetBounds(50, 10, 30, 10); |
2928 EXPECT_FALSE(v2->layer()); | 2928 EXPECT_FALSE(v2->layer()); |
2929 view->AddChildView(v2); | 2929 view->AddChildView(v2); |
2930 v2->SetPaintToLayer(true); | 2930 v2->SetPaintToLayer(true); |
2931 EXPECT_EQ(gfx::Rect(content_width - 80, 10, 30, 10), | 2931 EXPECT_EQ(gfx::Rect(content_width - 80, 10, 30, 10), |
2932 v2->layer()->bounds()); | 2932 v2->layer()->bounds()); |
2933 gfx::Rect l2bounds = v2->layer()->bounds(); | 2933 gfx::Rect l2bounds = v2->layer()->bounds(); |
2934 | 2934 |
| 2935 // Now attach a paints-to-layer View as a child view of |v1|. |
| 2936 View* v3 = new View; |
| 2937 v3->SetPaintToLayer(true); |
| 2938 v3->SetBounds(3, 5, 6, 4); |
| 2939 EXPECT_EQ(gfx::Rect(3, 5, 6, 4), |
| 2940 v3->layer()->bounds()); |
| 2941 v1->AddChildView(v3); |
| 2942 // Check that |v3| now has RTL-appropriate bounds. |
| 2943 EXPECT_EQ(gfx::Rect(11, 5, 6, 4), |
| 2944 v3->layer()->bounds()); |
| 2945 gfx::Rect l3bounds = v3->layer()->bounds(); |
| 2946 |
2935 view->SetPaintToLayer(true); | 2947 view->SetPaintToLayer(true); |
2936 EXPECT_EQ(l1bounds, v1->layer()->bounds()); | 2948 EXPECT_EQ(l1bounds, v1->layer()->bounds()); |
2937 EXPECT_EQ(l2bounds, v2->layer()->bounds()); | 2949 EXPECT_EQ(l2bounds, v2->layer()->bounds()); |
| 2950 EXPECT_EQ(l3bounds, v3->layer()->bounds()); |
2938 | 2951 |
2939 // Move one of the views. Make sure the layer is positioned correctly | 2952 // Move one of the views. Make sure the layer is positioned correctly |
2940 // afterwards. | 2953 // afterwards. |
2941 v1->SetBounds(v1->x() - 5, v1->y(), v1->width(), v1->height()); | 2954 v1->SetBounds(v1->x() - 5, v1->y(), v1->width(), v1->height()); |
2942 l1bounds.set_x(l1bounds.x() + 5); | 2955 l1bounds.set_x(l1bounds.x() + 5); |
2943 EXPECT_EQ(l1bounds, v1->layer()->bounds()); | 2956 EXPECT_EQ(l1bounds, v1->layer()->bounds()); |
2944 | 2957 |
2945 view->SetPaintToLayer(false); | 2958 view->SetPaintToLayer(false); |
2946 EXPECT_EQ(l1bounds, v1->layer()->bounds()); | 2959 EXPECT_EQ(l1bounds, v1->layer()->bounds()); |
2947 EXPECT_EQ(l2bounds, v2->layer()->bounds()); | 2960 EXPECT_EQ(l2bounds, v2->layer()->bounds()); |
| 2961 EXPECT_EQ(l3bounds, v3->layer()->bounds()); |
2948 | 2962 |
2949 // Move a view again. | 2963 // Move a view again. |
2950 v2->SetBounds(v2->x() + 5, v2->y(), v2->width(), v2->height()); | 2964 v2->SetBounds(v2->x() + 5, v2->y(), v2->width(), v2->height()); |
2951 l2bounds.set_x(l2bounds.x() - 5); | 2965 l2bounds.set_x(l2bounds.x() - 5); |
2952 EXPECT_EQ(l2bounds, v2->layer()->bounds()); | 2966 EXPECT_EQ(l2bounds, v2->layer()->bounds()); |
2953 | 2967 |
| 2968 // Resize |v1|. Make sure that |v3|'s layer has been moved correctly to |
| 2969 // RTL-appropriate bounds. |
| 2970 v1->SetSize(gfx::Size(30, 10)); |
| 2971 EXPECT_EQ(gfx::Rect(21, 5, 6, 4), |
| 2972 v3->layer()->bounds()); |
| 2973 |
2954 // Reset locale. | 2974 // Reset locale. |
2955 base::i18n::SetICUDefaultLocale(locale); | 2975 base::i18n::SetICUDefaultLocale(locale); |
2956 } | 2976 } |
2957 | 2977 |
2958 // Makes sure a transform persists after toggling the visibility. | 2978 // Makes sure a transform persists after toggling the visibility. |
2959 TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) { | 2979 TEST_F(ViewLayerTest, ToggleVisibilityWithTransform) { |
2960 View* view = new View; | 2980 View* view = new View; |
2961 gfx::Transform transform; | 2981 gfx::Transform transform; |
2962 transform.Scale(2.0, 2.0); | 2982 transform.Scale(2.0, 2.0); |
2963 view->SetTransform(transform); | 2983 view->SetTransform(transform); |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3688 // notification. | 3708 // notification. |
3689 TestView* test_view_child_2 = new TestView(); | 3709 TestView* test_view_child_2 = new TestView(); |
3690 test_view->AddChildView(test_view_child_2); | 3710 test_view->AddChildView(test_view_child_2); |
3691 EXPECT_TRUE(test_view_child_2->native_theme_); | 3711 EXPECT_TRUE(test_view_child_2->native_theme_); |
3692 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 3712 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
3693 | 3713 |
3694 widget->CloseNow(); | 3714 widget->CloseNow(); |
3695 } | 3715 } |
3696 | 3716 |
3697 } // namespace views | 3717 } // namespace views |
OLD | NEW |