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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 // Constructs a View tree with the specified depth. | 151 // Constructs a View tree with the specified depth. |
152 void ConstructTree(views::View* view, int depth) { | 152 void ConstructTree(views::View* view, int depth) { |
153 if (depth == 0) | 153 if (depth == 0) |
154 return; | 154 return; |
155 int count = base::RandInt(1, 5); | 155 int count = base::RandInt(1, 5); |
156 for (int i = 0; i < count; i++) { | 156 for (int i = 0; i < count; i++) { |
157 views::View* v = new views::View; | 157 views::View* v = new views::View; |
158 view->AddChildView(v); | 158 view->AddChildView(v); |
159 if (base::RandDouble() > 0.5) | 159 if (base::RandDouble() > 0.5) |
160 v->SetPaintToLayer(true); | 160 v->SetPaintToLayer(); |
161 if (base::RandDouble() < 0.2) | 161 if (base::RandDouble() < 0.2) |
162 v->SetVisible(false); | 162 v->SetVisible(false); |
163 | 163 |
164 ConstructTree(v, depth - 1); | 164 ConstructTree(v, depth - 1); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 void ScrambleTree(views::View* view) { | 168 void ScrambleTree(views::View* view) { |
169 int count = view->child_count(); | 169 int count = view->child_count(); |
170 if (count == 0) | 170 if (count == 0) |
171 return; | 171 return; |
172 for (int i = 0; i < count; i++) { | 172 for (int i = 0; i < count; i++) { |
173 ScrambleTree(view->child_at(i)); | 173 ScrambleTree(view->child_at(i)); |
174 } | 174 } |
175 | 175 |
176 if (count > 1) { | 176 if (count > 1) { |
177 int a = base::RandInt(0, count - 1); | 177 int a = base::RandInt(0, count - 1); |
178 int b = base::RandInt(0, count - 1); | 178 int b = base::RandInt(0, count - 1); |
179 | 179 |
180 views::View* view_a = view->child_at(a); | 180 views::View* view_a = view->child_at(a); |
181 views::View* view_b = view->child_at(b); | 181 views::View* view_b = view->child_at(b); |
182 view->ReorderChildView(view_a, b); | 182 view->ReorderChildView(view_a, b); |
183 view->ReorderChildView(view_b, a); | 183 view->ReorderChildView(view_b, a); |
184 } | 184 } |
185 | 185 |
186 if (!view->layer() && base::RandDouble() < 0.1) | 186 if (!view->layer() && base::RandDouble() < 0.1) |
187 view->SetPaintToLayer(true); | 187 view->SetPaintToLayer(); |
188 | 188 |
189 if (base::RandDouble() < 0.1) | 189 if (base::RandDouble() < 0.1) |
190 view->SetVisible(!view->visible()); | 190 view->SetVisible(!view->visible()); |
191 } | 191 } |
192 | 192 |
193 class ScopedRTL { | 193 class ScopedRTL { |
194 public: | 194 public: |
195 ScopedRTL() { | 195 ScopedRTL() { |
196 locale_ = base::i18n::GetConfiguredLocale(); | 196 locale_ = base::i18n::GetConfiguredLocale(); |
197 base::i18n::SetICUDefaultLocale("he"); | 197 base::i18n::SetICUDefaultLocale("he"); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 776 |
777 TestView* v1 = new TestView; | 777 TestView* v1 = new TestView; |
778 v1->SetBounds(10, 11, 12, 13); | 778 v1->SetBounds(10, 11, 12, 13); |
779 root_view->AddChildView(v1); | 779 root_view->AddChildView(v1); |
780 | 780 |
781 TestView* v2 = new TestView; | 781 TestView* v2 = new TestView; |
782 v2->SetBounds(3, 4, 6, 5); | 782 v2->SetBounds(3, 4, 6, 5); |
783 v1->AddChildView(v2); | 783 v1->AddChildView(v2); |
784 | 784 |
785 // Verify where the layers actually appear. | 785 // Verify where the layers actually appear. |
786 v1->SetPaintToLayer(true); | 786 v1->SetPaintToLayer(); |
787 // x: 25 - 10(x) - 12(width) = 3 | 787 // x: 25 - 10(x) - 12(width) = 3 |
788 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 788 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
789 v1->SetPaintToLayer(false); | 789 v1->DetachLayer(); |
790 | 790 |
791 v2->SetPaintToLayer(true); | 791 v2->SetPaintToLayer(); |
792 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 792 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
793 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 793 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
794 v2->SetPaintToLayer(false); | 794 v2->DetachLayer(); |
795 | 795 |
796 // Paint everything once, since it has to build its cache. Then we can test | 796 // Paint everything once, since it has to build its cache. Then we can test |
797 // invalidation. | 797 // invalidation. |
798 gfx::Rect first_paint(1, 1); | 798 gfx::Rect first_paint(1, 1); |
799 scoped_refptr<cc::DisplayItemList> list = | 799 scoped_refptr<cc::DisplayItemList> list = |
800 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); | 800 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); |
801 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 801 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); |
802 v1->Reset(); | 802 v1->Reset(); |
803 v2->Reset(); | 803 v2->Reset(); |
804 | 804 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 852 |
853 TestView* v1 = new TestView; | 853 TestView* v1 = new TestView; |
854 v1->SetBounds(10, 11, 12, 13); | 854 v1->SetBounds(10, 11, 12, 13); |
855 root_view->AddChildView(v1); | 855 root_view->AddChildView(v1); |
856 | 856 |
857 TestView* v2 = new TestView; | 857 TestView* v2 = new TestView; |
858 v2->SetBounds(3, 4, 6, 5); | 858 v2->SetBounds(3, 4, 6, 5); |
859 v1->AddChildView(v2); | 859 v1->AddChildView(v2); |
860 | 860 |
861 // Verify where the layers actually appear. | 861 // Verify where the layers actually appear. |
862 v1->SetPaintToLayer(true); | 862 v1->SetPaintToLayer(); |
863 // x: 25 - 10(x) - 12(width) = 3 | 863 // x: 25 - 10(x) - 12(width) = 3 |
864 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 864 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
865 v1->SetPaintToLayer(false); | 865 v1->DetachLayer(); |
866 | 866 |
867 v2->SetPaintToLayer(true); | 867 v2->SetPaintToLayer(); |
868 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 868 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
869 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 869 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
870 v2->SetPaintToLayer(false); | 870 v2->DetachLayer(); |
871 | 871 |
872 // Paint everything once, since it has to build its cache. Then we can test | 872 // Paint everything once, since it has to build its cache. Then we can test |
873 // invalidation. | 873 // invalidation. |
874 gfx::Rect first_paint(1, 1); | 874 gfx::Rect first_paint(1, 1); |
875 scoped_refptr<cc::DisplayItemList> list = | 875 scoped_refptr<cc::DisplayItemList> list = |
876 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); | 876 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); |
877 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 877 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); |
878 v1->Reset(); | 878 v1->Reset(); |
879 v2->Reset(); | 879 v2->Reset(); |
880 | 880 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 928 |
929 TestView* v1 = new TestView; | 929 TestView* v1 = new TestView; |
930 v1->SetBounds(10, 11, 12, 13); | 930 v1->SetBounds(10, 11, 12, 13); |
931 root_view->AddChildView(v1); | 931 root_view->AddChildView(v1); |
932 | 932 |
933 TestView* v2 = new TestView; | 933 TestView* v2 = new TestView; |
934 v2->SetBounds(3, 4, 6, 5); | 934 v2->SetBounds(3, 4, 6, 5); |
935 v1->AddChildView(v2); | 935 v1->AddChildView(v2); |
936 | 936 |
937 // Verify where the layers actually appear. | 937 // Verify where the layers actually appear. |
938 v1->SetPaintToLayer(true); | 938 v1->SetPaintToLayer(); |
939 // x: 25 - 10(x) - 12(width) = 3 | 939 // x: 25 - 10(x) - 12(width) = 3 |
940 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 940 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
941 v1->SetPaintToLayer(false); | 941 v1->DetachLayer(); |
942 | 942 |
943 v2->SetPaintToLayer(true); | 943 v2->SetPaintToLayer(); |
944 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 944 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
945 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 945 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
946 v2->SetPaintToLayer(false); | 946 v2->DetachLayer(); |
947 | 947 |
948 // Paint everything once, since it has to build its cache. Then we can test | 948 // Paint everything once, since it has to build its cache. Then we can test |
949 // invalidation. | 949 // invalidation. |
950 gfx::Rect first_paint(1, 1); | 950 gfx::Rect first_paint(1, 1); |
951 scoped_refptr<cc::DisplayItemList> list = | 951 scoped_refptr<cc::DisplayItemList> list = |
952 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); | 952 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); |
953 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 953 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); |
954 v1->Reset(); | 954 v1->Reset(); |
955 v2->Reset(); | 955 v2->Reset(); |
956 | 956 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 | 1004 |
1005 TestView* v1 = new TestView; | 1005 TestView* v1 = new TestView; |
1006 v1->SetBounds(10, 11, 12, 13); | 1006 v1->SetBounds(10, 11, 12, 13); |
1007 root_view->AddChildView(v1); | 1007 root_view->AddChildView(v1); |
1008 | 1008 |
1009 TestView* v2 = new TestView; | 1009 TestView* v2 = new TestView; |
1010 v2->SetBounds(3, 4, 6, 5); | 1010 v2->SetBounds(3, 4, 6, 5); |
1011 v1->AddChildView(v2); | 1011 v1->AddChildView(v2); |
1012 | 1012 |
1013 // Verify where the layers actually appear. | 1013 // Verify where the layers actually appear. |
1014 v1->SetPaintToLayer(true); | 1014 v1->SetPaintToLayer(); |
1015 // x: 25 - 10(x) - 12(width) = 3 | 1015 // x: 25 - 10(x) - 12(width) = 3 |
1016 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 1016 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
1017 v1->SetPaintToLayer(false); | 1017 v1->DetachLayer(); |
1018 | 1018 |
1019 v2->SetPaintToLayer(true); | 1019 v2->SetPaintToLayer(); |
1020 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 1020 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
1021 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 1021 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
1022 v2->SetPaintToLayer(false); | 1022 v2->DetachLayer(); |
1023 | 1023 |
1024 // Paint everything once, since it has to build its cache. Then we can test | 1024 // Paint everything once, since it has to build its cache. Then we can test |
1025 // invalidation. | 1025 // invalidation. |
1026 gfx::Rect first_paint(1, 1); | 1026 gfx::Rect first_paint(1, 1); |
1027 scoped_refptr<cc::DisplayItemList> list = | 1027 scoped_refptr<cc::DisplayItemList> list = |
1028 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); | 1028 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); |
1029 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 1029 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); |
1030 v1->Reset(); | 1030 v1->Reset(); |
1031 v2->Reset(); | 1031 v2->Reset(); |
1032 | 1032 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 | 1092 |
1093 TestView* v1 = new TestView; | 1093 TestView* v1 = new TestView; |
1094 v1->SetBounds(10, 11, 12, 13); | 1094 v1->SetBounds(10, 11, 12, 13); |
1095 root_view->AddChildView(v1); | 1095 root_view->AddChildView(v1); |
1096 | 1096 |
1097 TestView* v2 = new TestView; | 1097 TestView* v2 = new TestView; |
1098 v2->SetBounds(3, 4, 6, 5); | 1098 v2->SetBounds(3, 4, 6, 5); |
1099 root_view->AddChildView(v2); | 1099 root_view->AddChildView(v2); |
1100 | 1100 |
1101 // Verify where the layers actually appear. | 1101 // Verify where the layers actually appear. |
1102 v1->SetPaintToLayer(true); | 1102 v1->SetPaintToLayer(); |
1103 // x: 25 - 10(x) - 12(width) = 3 | 1103 // x: 25 - 10(x) - 12(width) = 3 |
1104 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 1104 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
1105 v1->SetPaintToLayer(false); | 1105 v1->DetachLayer(); |
1106 | 1106 |
1107 v2->SetPaintToLayer(true); | 1107 v2->SetPaintToLayer(); |
1108 // x: 25 - 3(x) - 6(width) = 16 | 1108 // x: 25 - 3(x) - 6(width) = 16 |
1109 EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds()); | 1109 EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds()); |
1110 v2->SetPaintToLayer(false); | 1110 v2->DetachLayer(); |
1111 | 1111 |
1112 // Paint everything once, since it has to build its cache. Then we can test | 1112 // Paint everything once, since it has to build its cache. Then we can test |
1113 // invalidation. | 1113 // invalidation. |
1114 gfx::Rect first_paint(1, 1); | 1114 gfx::Rect first_paint(1, 1); |
1115 scoped_refptr<cc::DisplayItemList> list = | 1115 scoped_refptr<cc::DisplayItemList> list = |
1116 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); | 1116 cc::DisplayItemList::Create(cc::DisplayItemListSettings()); |
1117 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 1117 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); |
1118 v1->Reset(); | 1118 v1->Reset(); |
1119 v2->Reset(); | 1119 v2->Reset(); |
1120 | 1120 |
(...skipping 18 matching lines...) Expand all Loading... |
1139 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1139 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); |
1140 EXPECT_FALSE(v1->did_paint_); | 1140 EXPECT_FALSE(v1->did_paint_); |
1141 EXPECT_TRUE(v2->did_paint_); | 1141 EXPECT_TRUE(v2->did_paint_); |
1142 } | 1142 } |
1143 | 1143 |
1144 TEST_F(ViewTest, PaintInPromotedToLayer) { | 1144 TEST_F(ViewTest, PaintInPromotedToLayer) { |
1145 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 1145 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
1146 View* root_view = widget->GetRootView(); | 1146 View* root_view = widget->GetRootView(); |
1147 | 1147 |
1148 TestView* v1 = new TestView; | 1148 TestView* v1 = new TestView; |
1149 v1->SetPaintToLayer(true); | 1149 v1->SetPaintToLayer(); |
1150 v1->SetBounds(10, 11, 12, 13); | 1150 v1->SetBounds(10, 11, 12, 13); |
1151 root_view->AddChildView(v1); | 1151 root_view->AddChildView(v1); |
1152 | 1152 |
1153 TestView* v2 = new TestView; | 1153 TestView* v2 = new TestView; |
1154 v2->SetBounds(3, 4, 6, 5); | 1154 v2->SetBounds(3, 4, 6, 5); |
1155 v1->AddChildView(v2); | 1155 v1->AddChildView(v2); |
1156 | 1156 |
1157 // Paint everything once, since it has to build its cache. Then we can test | 1157 // Paint everything once, since it has to build its cache. Then we can test |
1158 // invalidation. | 1158 // invalidation. |
1159 gfx::Rect first_paint(1, 1); | 1159 gfx::Rect first_paint(1, 1); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 }; | 1223 }; |
1224 | 1224 |
1225 TEST_F(ViewTest, PaintLocalBounds) { | 1225 TEST_F(ViewTest, PaintLocalBounds) { |
1226 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 1226 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
1227 View* root_view = widget->GetRootView(); | 1227 View* root_view = widget->GetRootView(); |
1228 // Make |root_view|'s bounds larger so |v1|'s visible bounds is not clipped by | 1228 // Make |root_view|'s bounds larger so |v1|'s visible bounds is not clipped by |
1229 // |root_view|. | 1229 // |root_view|. |
1230 root_view->SetBounds(0, 0, 200, 200); | 1230 root_view->SetBounds(0, 0, 200, 200); |
1231 | 1231 |
1232 TestPaintView* v1 = new TestPaintView; | 1232 TestPaintView* v1 = new TestPaintView; |
1233 v1->SetPaintToLayer(true); | 1233 v1->SetPaintToLayer(); |
1234 | 1234 |
1235 // Set bounds for |v1| such that it has an offset to its parent and only part | 1235 // Set bounds for |v1| such that it has an offset to its parent and only part |
1236 // of it is visible. The visible bounds does not intersect with |root_view|'s | 1236 // of it is visible. The visible bounds does not intersect with |root_view|'s |
1237 // bounds. | 1237 // bounds. |
1238 v1->SetBounds(0, -1000, 100, 1100); | 1238 v1->SetBounds(0, -1000, 100, 1100); |
1239 root_view->AddChildView(v1); | 1239 root_view->AddChildView(v1); |
1240 EXPECT_EQ(gfx::Rect(0, 0, 100, 1100), v1->GetLocalBounds()); | 1240 EXPECT_EQ(gfx::Rect(0, 0, 100, 1100), v1->GetLocalBounds()); |
1241 EXPECT_EQ(gfx::Rect(0, 1000, 100, 100), v1->GetVisibleBounds()); | 1241 EXPECT_EQ(gfx::Rect(0, 1000, 100, 100), v1->GetVisibleBounds()); |
1242 | 1242 |
1243 scoped_refptr<cc::DisplayItemList> list = | 1243 scoped_refptr<cc::DisplayItemList> list = |
(...skipping 2482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3726 | 3726 |
3727 TEST_F(ViewLayerTest, LayerToggling) { | 3727 TEST_F(ViewLayerTest, LayerToggling) { |
3728 // Because we lazily create textures the calls to DrawTree are necessary to | 3728 // Because we lazily create textures the calls to DrawTree are necessary to |
3729 // ensure we trigger creation of textures. | 3729 // ensure we trigger creation of textures. |
3730 ui::Layer* root_layer = widget()->GetLayer(); | 3730 ui::Layer* root_layer = widget()->GetLayer(); |
3731 View* content_view = new View; | 3731 View* content_view = new View; |
3732 widget()->SetContentsView(content_view); | 3732 widget()->SetContentsView(content_view); |
3733 | 3733 |
3734 // Create v1, give it a bounds and verify everything is set up correctly. | 3734 // Create v1, give it a bounds and verify everything is set up correctly. |
3735 View* v1 = new View; | 3735 View* v1 = new View; |
3736 v1->SetPaintToLayer(true); | 3736 v1->SetPaintToLayer(); |
3737 EXPECT_TRUE(v1->layer() != NULL); | 3737 EXPECT_TRUE(v1->layer() != NULL); |
3738 v1->SetBoundsRect(gfx::Rect(20, 30, 140, 150)); | 3738 v1->SetBoundsRect(gfx::Rect(20, 30, 140, 150)); |
3739 content_view->AddChildView(v1); | 3739 content_view->AddChildView(v1); |
3740 ASSERT_TRUE(v1->layer() != NULL); | 3740 ASSERT_TRUE(v1->layer() != NULL); |
3741 EXPECT_EQ(root_layer, v1->layer()->parent()); | 3741 EXPECT_EQ(root_layer, v1->layer()->parent()); |
3742 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds()); | 3742 EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds()); |
3743 | 3743 |
3744 // Create v2 as a child of v1 and do basic assertion testing. | 3744 // Create v2 as a child of v1 and do basic assertion testing. |
3745 View* v2 = new View; | 3745 View* v2 = new View; |
3746 v1->AddChildView(v2); | 3746 v1->AddChildView(v2); |
3747 EXPECT_TRUE(v2->layer() == NULL); | 3747 EXPECT_TRUE(v2->layer() == NULL); |
3748 v2->SetBoundsRect(gfx::Rect(10, 20, 30, 40)); | 3748 v2->SetBoundsRect(gfx::Rect(10, 20, 30, 40)); |
3749 v2->SetPaintToLayer(true); | 3749 v2->SetPaintToLayer(); |
3750 ASSERT_TRUE(v2->layer() != NULL); | 3750 ASSERT_TRUE(v2->layer() != NULL); |
3751 EXPECT_EQ(v1->layer(), v2->layer()->parent()); | 3751 EXPECT_EQ(v1->layer(), v2->layer()->parent()); |
3752 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); | 3752 EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds()); |
3753 | 3753 |
3754 // Turn off v1s layer. v2 should still have a layer but its parent should have | 3754 // Turn off v1s layer. v2 should still have a layer but its parent should have |
3755 // changed. | 3755 // changed. |
3756 v1->SetPaintToLayer(false); | 3756 v1->DetachLayer(); |
3757 EXPECT_TRUE(v1->layer() == NULL); | 3757 EXPECT_TRUE(v1->layer() == NULL); |
3758 EXPECT_TRUE(v2->layer() != NULL); | 3758 EXPECT_TRUE(v2->layer() != NULL); |
3759 EXPECT_EQ(root_layer, v2->layer()->parent()); | 3759 EXPECT_EQ(root_layer, v2->layer()->parent()); |
3760 ASSERT_EQ(1u, root_layer->children().size()); | 3760 ASSERT_EQ(1u, root_layer->children().size()); |
3761 EXPECT_EQ(root_layer->children()[0], v2->layer()); | 3761 EXPECT_EQ(root_layer->children()[0], v2->layer()); |
3762 // The bounds of the layer should have changed to be relative to the root view | 3762 // The bounds of the layer should have changed to be relative to the root view |
3763 // now. | 3763 // now. |
3764 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); | 3764 EXPECT_EQ(gfx::Rect(30, 50, 30, 40), v2->layer()->bounds()); |
3765 | 3765 |
3766 // Make v1 have a layer again and verify v2s layer is wired up correctly. | 3766 // Make v1 have a layer again and verify v2s layer is wired up correctly. |
(...skipping 18 matching lines...) Expand all Loading... |
3785 | 3785 |
3786 // Create v1, give it a bounds and verify everything is set up correctly. | 3786 // Create v1, give it a bounds and verify everything is set up correctly. |
3787 View* v1 = new View; | 3787 View* v1 = new View; |
3788 content_view->AddChildView(v1); | 3788 content_view->AddChildView(v1); |
3789 v1->SetBoundsRect(gfx::Rect(20, 30, 140, 150)); | 3789 v1->SetBoundsRect(gfx::Rect(20, 30, 140, 150)); |
3790 | 3790 |
3791 View* v2 = new View; | 3791 View* v2 = new View; |
3792 v1->AddChildView(v2); | 3792 v1->AddChildView(v2); |
3793 | 3793 |
3794 View* v3 = new View; | 3794 View* v3 = new View; |
3795 v3->SetPaintToLayer(true); | 3795 v3->SetPaintToLayer(); |
3796 v2->AddChildView(v3); | 3796 v2->AddChildView(v3); |
3797 ASSERT_TRUE(v3->layer() != NULL); | 3797 ASSERT_TRUE(v3->layer() != NULL); |
3798 | 3798 |
3799 // At this point we have v1-v2-v3. v3 has a layer, v1 and v2 don't. | 3799 // At this point we have v1-v2-v3. v3 has a layer, v1 and v2 don't. |
3800 | 3800 |
3801 v1->SetPaintToLayer(true); | 3801 v1->SetPaintToLayer(); |
3802 EXPECT_EQ(v1->layer(), v3->layer()->parent()); | 3802 EXPECT_EQ(v1->layer(), v3->layer()->parent()); |
3803 } | 3803 } |
3804 | 3804 |
3805 TEST_F(ViewLayerTest, LayerAnimator) { | 3805 TEST_F(ViewLayerTest, LayerAnimator) { |
3806 View* content_view = new View; | 3806 View* content_view = new View; |
3807 widget()->SetContentsView(content_view); | 3807 widget()->SetContentsView(content_view); |
3808 | 3808 |
3809 View* v1 = new View; | 3809 View* v1 = new View; |
3810 content_view->AddChildView(v1); | 3810 content_view->AddChildView(v1); |
3811 v1->SetPaintToLayer(true); | 3811 v1->SetPaintToLayer(); |
3812 EXPECT_TRUE(v1->layer() != NULL); | 3812 EXPECT_TRUE(v1->layer() != NULL); |
3813 | 3813 |
3814 TestLayerAnimator* animator = new TestLayerAnimator(); | 3814 TestLayerAnimator* animator = new TestLayerAnimator(); |
3815 v1->layer()->SetAnimator(animator); | 3815 v1->layer()->SetAnimator(animator); |
3816 | 3816 |
3817 gfx::Rect bounds(1, 2, 3, 4); | 3817 gfx::Rect bounds(1, 2, 3, 4); |
3818 v1->SetBoundsRect(bounds); | 3818 v1->SetBoundsRect(bounds); |
3819 EXPECT_EQ(bounds, animator->last_bounds()); | 3819 EXPECT_EQ(bounds, animator->last_bounds()); |
3820 // TestLayerAnimator doesn't update the layer. | 3820 // TestLayerAnimator doesn't update the layer. |
3821 EXPECT_NE(bounds, v1->layer()->bounds()); | 3821 EXPECT_NE(bounds, v1->layer()->bounds()); |
3822 } | 3822 } |
3823 | 3823 |
3824 // Verifies the bounds of a layer are updated if the bounds of ancestor that | 3824 // Verifies the bounds of a layer are updated if the bounds of ancestor that |
3825 // doesn't have a layer change. | 3825 // doesn't have a layer change. |
3826 TEST_F(ViewLayerTest, BoundsChangeWithLayer) { | 3826 TEST_F(ViewLayerTest, BoundsChangeWithLayer) { |
3827 View* content_view = new View; | 3827 View* content_view = new View; |
3828 widget()->SetContentsView(content_view); | 3828 widget()->SetContentsView(content_view); |
3829 | 3829 |
3830 View* v1 = new View; | 3830 View* v1 = new View; |
3831 content_view->AddChildView(v1); | 3831 content_view->AddChildView(v1); |
3832 v1->SetBoundsRect(gfx::Rect(20, 30, 140, 150)); | 3832 v1->SetBoundsRect(gfx::Rect(20, 30, 140, 150)); |
3833 | 3833 |
3834 View* v2 = new View; | 3834 View* v2 = new View; |
3835 v2->SetBoundsRect(gfx::Rect(10, 11, 40, 50)); | 3835 v2->SetBoundsRect(gfx::Rect(10, 11, 40, 50)); |
3836 v1->AddChildView(v2); | 3836 v1->AddChildView(v2); |
3837 v2->SetPaintToLayer(true); | 3837 v2->SetPaintToLayer(); |
3838 ASSERT_TRUE(v2->layer() != NULL); | 3838 ASSERT_TRUE(v2->layer() != NULL); |
3839 EXPECT_EQ(gfx::Rect(30, 41, 40, 50), v2->layer()->bounds()); | 3839 EXPECT_EQ(gfx::Rect(30, 41, 40, 50), v2->layer()->bounds()); |
3840 | 3840 |
3841 v1->SetPosition(gfx::Point(25, 36)); | 3841 v1->SetPosition(gfx::Point(25, 36)); |
3842 EXPECT_EQ(gfx::Rect(35, 47, 40, 50), v2->layer()->bounds()); | 3842 EXPECT_EQ(gfx::Rect(35, 47, 40, 50), v2->layer()->bounds()); |
3843 | 3843 |
3844 v2->SetPosition(gfx::Point(11, 12)); | 3844 v2->SetPosition(gfx::Point(11, 12)); |
3845 EXPECT_EQ(gfx::Rect(36, 48, 40, 50), v2->layer()->bounds()); | 3845 EXPECT_EQ(gfx::Rect(36, 48, 40, 50), v2->layer()->bounds()); |
3846 | 3846 |
3847 // Bounds of the layer should change even if the view is not invisible. | 3847 // Bounds of the layer should change even if the view is not invisible. |
(...skipping 11 matching lines...) Expand all Loading... |
3859 ScopedRTL rtl; | 3859 ScopedRTL rtl; |
3860 | 3860 |
3861 View* view = new View; | 3861 View* view = new View; |
3862 widget()->SetContentsView(view); | 3862 widget()->SetContentsView(view); |
3863 | 3863 |
3864 int content_width = view->width(); | 3864 int content_width = view->width(); |
3865 | 3865 |
3866 // |v1| is initially not attached to anything. So its layer will have the same | 3866 // |v1| is initially not attached to anything. So its layer will have the same |
3867 // bounds as the view. | 3867 // bounds as the view. |
3868 View* v1 = new View; | 3868 View* v1 = new View; |
3869 v1->SetPaintToLayer(true); | 3869 v1->SetPaintToLayer(); |
3870 v1->SetBounds(10, 10, 20, 10); | 3870 v1->SetBounds(10, 10, 20, 10); |
3871 EXPECT_EQ(gfx::Rect(10, 10, 20, 10), | 3871 EXPECT_EQ(gfx::Rect(10, 10, 20, 10), |
3872 v1->layer()->bounds()); | 3872 v1->layer()->bounds()); |
3873 | 3873 |
3874 // Once |v1| is attached to the widget, its layer will get RTL-appropriate | 3874 // Once |v1| is attached to the widget, its layer will get RTL-appropriate |
3875 // bounds. | 3875 // bounds. |
3876 view->AddChildView(v1); | 3876 view->AddChildView(v1); |
3877 EXPECT_EQ(gfx::Rect(content_width - 30, 10, 20, 10), | 3877 EXPECT_EQ(gfx::Rect(content_width - 30, 10, 20, 10), |
3878 v1->layer()->bounds()); | 3878 v1->layer()->bounds()); |
3879 gfx::Rect l1bounds = v1->layer()->bounds(); | 3879 gfx::Rect l1bounds = v1->layer()->bounds(); |
3880 | 3880 |
3881 // Now attach a View to the widget first, then create a layer for it. Make | 3881 // Now attach a View to the widget first, then create a layer for it. Make |
3882 // sure the bounds are correct. | 3882 // sure the bounds are correct. |
3883 View* v2 = new View; | 3883 View* v2 = new View; |
3884 v2->SetBounds(50, 10, 30, 10); | 3884 v2->SetBounds(50, 10, 30, 10); |
3885 EXPECT_FALSE(v2->layer()); | 3885 EXPECT_FALSE(v2->layer()); |
3886 view->AddChildView(v2); | 3886 view->AddChildView(v2); |
3887 v2->SetPaintToLayer(true); | 3887 v2->SetPaintToLayer(); |
3888 EXPECT_EQ(gfx::Rect(content_width - 80, 10, 30, 10), | 3888 EXPECT_EQ(gfx::Rect(content_width - 80, 10, 30, 10), |
3889 v2->layer()->bounds()); | 3889 v2->layer()->bounds()); |
3890 gfx::Rect l2bounds = v2->layer()->bounds(); | 3890 gfx::Rect l2bounds = v2->layer()->bounds(); |
3891 | 3891 |
3892 view->SetPaintToLayer(true); | 3892 view->SetPaintToLayer(); |
3893 EXPECT_EQ(l1bounds, v1->layer()->bounds()); | 3893 EXPECT_EQ(l1bounds, v1->layer()->bounds()); |
3894 EXPECT_EQ(l2bounds, v2->layer()->bounds()); | 3894 EXPECT_EQ(l2bounds, v2->layer()->bounds()); |
3895 | 3895 |
3896 // Move one of the views. Make sure the layer is positioned correctly | 3896 // Move one of the views. Make sure the layer is positioned correctly |
3897 // afterwards. | 3897 // afterwards. |
3898 v1->SetBounds(v1->x() - 5, v1->y(), v1->width(), v1->height()); | 3898 v1->SetBounds(v1->x() - 5, v1->y(), v1->width(), v1->height()); |
3899 l1bounds.set_x(l1bounds.x() + 5); | 3899 l1bounds.set_x(l1bounds.x() + 5); |
3900 EXPECT_EQ(l1bounds, v1->layer()->bounds()); | 3900 EXPECT_EQ(l1bounds, v1->layer()->bounds()); |
3901 | 3901 |
3902 view->SetPaintToLayer(false); | 3902 view->DetachLayer(); |
3903 EXPECT_EQ(l1bounds, v1->layer()->bounds()); | 3903 EXPECT_EQ(l1bounds, v1->layer()->bounds()); |
3904 EXPECT_EQ(l2bounds, v2->layer()->bounds()); | 3904 EXPECT_EQ(l2bounds, v2->layer()->bounds()); |
3905 | 3905 |
3906 // Move a view again. | 3906 // Move a view again. |
3907 v2->SetBounds(v2->x() + 5, v2->y(), v2->width(), v2->height()); | 3907 v2->SetBounds(v2->x() + 5, v2->y(), v2->width(), v2->height()); |
3908 l2bounds.set_x(l2bounds.x() - 5); | 3908 l2bounds.set_x(l2bounds.x() - 5); |
3909 EXPECT_EQ(l2bounds, v2->layer()->bounds()); | 3909 EXPECT_EQ(l2bounds, v2->layer()->bounds()); |
3910 } | 3910 } |
3911 | 3911 |
3912 // Make sure that resizing a parent in RTL correctly repositions its children. | 3912 // Make sure that resizing a parent in RTL correctly repositions its children. |
3913 TEST_F(ViewLayerTest, ResizeParentInRTL) { | 3913 TEST_F(ViewLayerTest, ResizeParentInRTL) { |
3914 ScopedRTL rtl; | 3914 ScopedRTL rtl; |
3915 | 3915 |
3916 View* view = new View; | 3916 View* view = new View; |
3917 widget()->SetContentsView(view); | 3917 widget()->SetContentsView(view); |
3918 | 3918 |
3919 int content_width = view->width(); | 3919 int content_width = view->width(); |
3920 | 3920 |
3921 // Create a paints-to-layer view |v1|. | 3921 // Create a paints-to-layer view |v1|. |
3922 View* v1 = new View; | 3922 View* v1 = new View; |
3923 v1->SetPaintToLayer(true); | 3923 v1->SetPaintToLayer(); |
3924 v1->SetBounds(10, 10, 20, 10); | 3924 v1->SetBounds(10, 10, 20, 10); |
3925 view->AddChildView(v1); | 3925 view->AddChildView(v1); |
3926 EXPECT_EQ(gfx::Rect(content_width - 30, 10, 20, 10), | 3926 EXPECT_EQ(gfx::Rect(content_width - 30, 10, 20, 10), |
3927 v1->layer()->bounds()); | 3927 v1->layer()->bounds()); |
3928 | 3928 |
3929 // Attach a paints-to-layer child view to |v1|. | 3929 // Attach a paints-to-layer child view to |v1|. |
3930 View* v2 = new View; | 3930 View* v2 = new View; |
3931 v2->SetPaintToLayer(true); | 3931 v2->SetPaintToLayer(); |
3932 v2->SetBounds(3, 5, 6, 4); | 3932 v2->SetBounds(3, 5, 6, 4); |
3933 EXPECT_EQ(gfx::Rect(3, 5, 6, 4), | 3933 EXPECT_EQ(gfx::Rect(3, 5, 6, 4), |
3934 v2->layer()->bounds()); | 3934 v2->layer()->bounds()); |
3935 v1->AddChildView(v2); | 3935 v1->AddChildView(v2); |
3936 // Check that |v2| now has RTL-appropriate bounds. | 3936 // Check that |v2| now has RTL-appropriate bounds. |
3937 EXPECT_EQ(gfx::Rect(11, 5, 6, 4), | 3937 EXPECT_EQ(gfx::Rect(11, 5, 6, 4), |
3938 v2->layer()->bounds()); | 3938 v2->layer()->bounds()); |
3939 | 3939 |
3940 // Attach a non-layer child view to |v1|, and give it a paints-to-layer child. | 3940 // Attach a non-layer child view to |v1|, and give it a paints-to-layer child. |
3941 View* v3 = new View; | 3941 View* v3 = new View; |
3942 v3->SetBounds(1, 1, 18, 8); | 3942 v3->SetBounds(1, 1, 18, 8); |
3943 View* v4 = new View; | 3943 View* v4 = new View; |
3944 v4->SetPaintToLayer(true); | 3944 v4->SetPaintToLayer(); |
3945 v4->SetBounds(2, 4, 6, 4); | 3945 v4->SetBounds(2, 4, 6, 4); |
3946 EXPECT_EQ(gfx::Rect(2, 4, 6, 4), | 3946 EXPECT_EQ(gfx::Rect(2, 4, 6, 4), |
3947 v4->layer()->bounds()); | 3947 v4->layer()->bounds()); |
3948 v3->AddChildView(v4); | 3948 v3->AddChildView(v4); |
3949 EXPECT_EQ(gfx::Rect(10, 4, 6, 4), | 3949 EXPECT_EQ(gfx::Rect(10, 4, 6, 4), |
3950 v4->layer()->bounds()); | 3950 v4->layer()->bounds()); |
3951 v1->AddChildView(v3); | 3951 v1->AddChildView(v3); |
3952 // Check that |v4| now has RTL-appropriate bounds. | 3952 // Check that |v4| now has RTL-appropriate bounds. |
3953 EXPECT_EQ(gfx::Rect(11, 5, 6, 4), | 3953 EXPECT_EQ(gfx::Rect(11, 5, 6, 4), |
3954 v4->layer()->bounds()); | 3954 v4->layer()->bounds()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4006 | 4006 |
4007 // Makes sure that layer visibility is correct after toggling View visibility. | 4007 // Makes sure that layer visibility is correct after toggling View visibility. |
4008 TEST_F(ViewLayerTest, ToggleVisibilityWithLayer) { | 4008 TEST_F(ViewLayerTest, ToggleVisibilityWithLayer) { |
4009 View* content_view = new View; | 4009 View* content_view = new View; |
4010 widget()->SetContentsView(content_view); | 4010 widget()->SetContentsView(content_view); |
4011 | 4011 |
4012 // The view isn't attached to a widget or a parent view yet. But it should | 4012 // The view isn't attached to a widget or a parent view yet. But it should |
4013 // still have a layer, but the layer should not be attached to the root | 4013 // still have a layer, but the layer should not be attached to the root |
4014 // layer. | 4014 // layer. |
4015 View* v1 = new View; | 4015 View* v1 = new View; |
4016 v1->SetPaintToLayer(true); | 4016 v1->SetPaintToLayer(); |
4017 EXPECT_TRUE(v1->layer()); | 4017 EXPECT_TRUE(v1->layer()); |
4018 EXPECT_FALSE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), | 4018 EXPECT_FALSE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), |
4019 v1->layer())); | 4019 v1->layer())); |
4020 | 4020 |
4021 // Once the view is attached to a widget, its layer should be attached to the | 4021 // Once the view is attached to a widget, its layer should be attached to the |
4022 // root layer and visible. | 4022 // root layer and visible. |
4023 content_view->AddChildView(v1); | 4023 content_view->AddChildView(v1); |
4024 EXPECT_TRUE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), | 4024 EXPECT_TRUE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), |
4025 v1->layer())); | 4025 v1->layer())); |
4026 EXPECT_TRUE(v1->layer()->IsDrawn()); | 4026 EXPECT_TRUE(v1->layer()->IsDrawn()); |
(...skipping 15 matching lines...) Expand all Loading... |
4042 // from the parent. | 4042 // from the parent. |
4043 TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) { | 4043 TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) { |
4044 View* content_view = new View; | 4044 View* content_view = new View; |
4045 widget()->SetContentsView(content_view); | 4045 widget()->SetContentsView(content_view); |
4046 | 4046 |
4047 View* v1 = new View; | 4047 View* v1 = new View; |
4048 content_view->AddChildView(v1); | 4048 content_view->AddChildView(v1); |
4049 | 4049 |
4050 View* v2 = new View; | 4050 View* v2 = new View; |
4051 v1->AddChildView(v2); | 4051 v1->AddChildView(v2); |
4052 v2->SetPaintToLayer(true); | 4052 v2->SetPaintToLayer(); |
4053 EXPECT_TRUE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), | 4053 EXPECT_TRUE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), |
4054 v2->layer())); | 4054 v2->layer())); |
4055 EXPECT_TRUE(v2->layer()->IsDrawn()); | 4055 EXPECT_TRUE(v2->layer()->IsDrawn()); |
4056 | 4056 |
4057 content_view->RemoveChildView(v1); | 4057 content_view->RemoveChildView(v1); |
4058 | 4058 |
4059 EXPECT_FALSE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), | 4059 EXPECT_FALSE(LayerIsAncestor(widget()->GetCompositor()->root_layer(), |
4060 v2->layer())); | 4060 v2->layer())); |
4061 | 4061 |
4062 // Reparent |v2|. | 4062 // Reparent |v2|. |
(...skipping 22 matching lines...) Expand all Loading... |
4085 }; | 4085 }; |
4086 | 4086 |
4087 // Makes sure child views with layers aren't painted when paint starts at an | 4087 // Makes sure child views with layers aren't painted when paint starts at an |
4088 // ancestor. | 4088 // ancestor. |
4089 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { | 4089 TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) { |
4090 // TODO(sad): DrawWaiterForTest does not work with mus. crbug.com/618136 | 4090 // TODO(sad): DrawWaiterForTest does not work with mus. crbug.com/618136 |
4091 if (IsMus()) | 4091 if (IsMus()) |
4092 return; | 4092 return; |
4093 PaintTrackingView* content_view = new PaintTrackingView; | 4093 PaintTrackingView* content_view = new PaintTrackingView; |
4094 widget()->SetContentsView(content_view); | 4094 widget()->SetContentsView(content_view); |
4095 content_view->SetPaintToLayer(true); | 4095 content_view->SetPaintToLayer(); |
4096 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 4096 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
4097 ui::DrawWaiterForTest::WaitForCompositingEnded( | 4097 ui::DrawWaiterForTest::WaitForCompositingEnded( |
4098 GetRootLayer()->GetCompositor()); | 4098 GetRootLayer()->GetCompositor()); |
4099 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); | 4099 GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10)); |
4100 content_view->set_painted(false); | 4100 content_view->set_painted(false); |
4101 // content_view no longer has a dirty rect. Paint from the root and make sure | 4101 // content_view no longer has a dirty rect. Paint from the root and make sure |
4102 // PaintTrackingView isn't painted. | 4102 // PaintTrackingView isn't painted. |
4103 GetRootLayer()->GetCompositor()->ScheduleDraw(); | 4103 GetRootLayer()->GetCompositor()->ScheduleDraw(); |
4104 ui::DrawWaiterForTest::WaitForCompositingEnded( | 4104 ui::DrawWaiterForTest::WaitForCompositingEnded( |
4105 GetRootLayer()->GetCompositor()); | 4105 GetRootLayer()->GetCompositor()); |
(...skipping 29 matching lines...) Expand all Loading... |
4135 } | 4135 } |
4136 | 4136 |
4137 TEST_F(ViewLayerTest, ParentPaintWhenSwitchingPaintToLayerFromFalseToTrue) { | 4137 TEST_F(ViewLayerTest, ParentPaintWhenSwitchingPaintToLayerFromFalseToTrue) { |
4138 TestView parent_view; | 4138 TestView parent_view; |
4139 parent_view.SetBounds(10, 11, 12, 13); | 4139 parent_view.SetBounds(10, 11, 12, 13); |
4140 | 4140 |
4141 TestView* child_view = new TestView; | 4141 TestView* child_view = new TestView; |
4142 parent_view.AddChildView(child_view); | 4142 parent_view.AddChildView(child_view); |
4143 | 4143 |
4144 parent_view.scheduled_paint_rects_.clear(); | 4144 parent_view.scheduled_paint_rects_.clear(); |
4145 child_view->SetPaintToLayer(true); | 4145 child_view->SetPaintToLayer(); |
4146 EXPECT_EQ(1U, parent_view.scheduled_paint_rects_.size()); | 4146 EXPECT_EQ(1U, parent_view.scheduled_paint_rects_.size()); |
4147 } | 4147 } |
4148 | 4148 |
4149 TEST_F(ViewLayerTest, NoParentPaintWhenSwitchingPaintToLayerFromTrueToTrue) { | 4149 TEST_F(ViewLayerTest, NoParentPaintWhenSwitchingPaintToLayerFromTrueToTrue) { |
4150 TestView parent_view; | 4150 TestView parent_view; |
4151 parent_view.SetBounds(10, 11, 12, 13); | 4151 parent_view.SetBounds(10, 11, 12, 13); |
4152 | 4152 |
4153 TestView* child_view = new TestView; | 4153 TestView* child_view = new TestView; |
4154 child_view->SetPaintToLayer(true); | 4154 child_view->SetPaintToLayer(); |
4155 parent_view.AddChildView(child_view); | 4155 parent_view.AddChildView(child_view); |
4156 | 4156 |
4157 parent_view.scheduled_paint_rects_.clear(); | 4157 parent_view.scheduled_paint_rects_.clear(); |
4158 EXPECT_EQ(0U, parent_view.scheduled_paint_rects_.size()); | 4158 EXPECT_EQ(0U, parent_view.scheduled_paint_rects_.size()); |
4159 } | 4159 } |
4160 | 4160 |
4161 // Tests that the visibility of child layers are updated correctly when a View's | 4161 // Tests that the visibility of child layers are updated correctly when a View's |
4162 // visibility changes. | 4162 // visibility changes. |
4163 TEST_F(ViewLayerTest, VisibilityChildLayers) { | 4163 TEST_F(ViewLayerTest, VisibilityChildLayers) { |
4164 View* v1 = new View; | 4164 View* v1 = new View; |
4165 v1->SetPaintToLayer(true); | 4165 v1->SetPaintToLayer(); |
4166 widget()->SetContentsView(v1); | 4166 widget()->SetContentsView(v1); |
4167 | 4167 |
4168 View* v2 = new View; | 4168 View* v2 = new View; |
4169 v1->AddChildView(v2); | 4169 v1->AddChildView(v2); |
4170 | 4170 |
4171 View* v3 = new View; | 4171 View* v3 = new View; |
4172 v2->AddChildView(v3); | 4172 v2->AddChildView(v3); |
4173 v3->SetVisible(false); | 4173 v3->SetVisible(false); |
4174 | 4174 |
4175 View* v4 = new View; | 4175 View* v4 = new View; |
4176 v4->SetPaintToLayer(true); | 4176 v4->SetPaintToLayer(); |
4177 v3->AddChildView(v4); | 4177 v3->AddChildView(v4); |
4178 | 4178 |
4179 EXPECT_TRUE(v1->layer()->IsDrawn()); | 4179 EXPECT_TRUE(v1->layer()->IsDrawn()); |
4180 EXPECT_FALSE(v4->layer()->IsDrawn()); | 4180 EXPECT_FALSE(v4->layer()->IsDrawn()); |
4181 | 4181 |
4182 v2->SetVisible(false); | 4182 v2->SetVisible(false); |
4183 EXPECT_TRUE(v1->layer()->IsDrawn()); | 4183 EXPECT_TRUE(v1->layer()->IsDrawn()); |
4184 EXPECT_FALSE(v4->layer()->IsDrawn()); | 4184 EXPECT_FALSE(v4->layer()->IsDrawn()); |
4185 | 4185 |
4186 v2->SetVisible(true); | 4186 v2->SetVisible(true); |
(...skipping 15 matching lines...) Expand all Loading... |
4202 EXPECT_TRUE(v1->layer()->IsDrawn()); | 4202 EXPECT_TRUE(v1->layer()->IsDrawn()); |
4203 EXPECT_TRUE(v4->layer()->IsDrawn()); | 4203 EXPECT_TRUE(v4->layer()->IsDrawn()); |
4204 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(v1, v1->layer())); | 4204 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(v1, v1->layer())); |
4205 } | 4205 } |
4206 | 4206 |
4207 // This test creates a random View tree, and then randomly reorders child views, | 4207 // This test creates a random View tree, and then randomly reorders child views, |
4208 // reparents views etc. Unrelated changes can appear to break this test. So | 4208 // reparents views etc. Unrelated changes can appear to break this test. So |
4209 // marking this as FLAKY. | 4209 // marking this as FLAKY. |
4210 TEST_F(ViewLayerTest, DISABLED_ViewLayerTreesInSync) { | 4210 TEST_F(ViewLayerTest, DISABLED_ViewLayerTreesInSync) { |
4211 View* content = new View; | 4211 View* content = new View; |
4212 content->SetPaintToLayer(true); | 4212 content->SetPaintToLayer(); |
4213 widget()->SetContentsView(content); | 4213 widget()->SetContentsView(content); |
4214 widget()->Show(); | 4214 widget()->Show(); |
4215 | 4215 |
4216 ConstructTree(content, 5); | 4216 ConstructTree(content, 5); |
4217 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 4217 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
4218 | 4218 |
4219 ScrambleTree(content); | 4219 ScrambleTree(content); |
4220 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 4220 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
4221 | 4221 |
4222 ScrambleTree(content); | 4222 ScrambleTree(content); |
4223 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 4223 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
4224 | 4224 |
4225 ScrambleTree(content); | 4225 ScrambleTree(content); |
4226 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); | 4226 EXPECT_TRUE(ViewAndLayerTreeAreConsistent(content, content->layer())); |
4227 } | 4227 } |
4228 | 4228 |
4229 // Verifies when views are reordered the layer is also reordered. The widget is | 4229 // Verifies when views are reordered the layer is also reordered. The widget is |
4230 // providing the parent layer. | 4230 // providing the parent layer. |
4231 TEST_F(ViewLayerTest, ReorderUnderWidget) { | 4231 TEST_F(ViewLayerTest, ReorderUnderWidget) { |
4232 View* content = new View; | 4232 View* content = new View; |
4233 widget()->SetContentsView(content); | 4233 widget()->SetContentsView(content); |
4234 View* c1 = new View; | 4234 View* c1 = new View; |
4235 c1->SetPaintToLayer(true); | 4235 c1->SetPaintToLayer(); |
4236 content->AddChildView(c1); | 4236 content->AddChildView(c1); |
4237 View* c2 = new View; | 4237 View* c2 = new View; |
4238 c2->SetPaintToLayer(true); | 4238 c2->SetPaintToLayer(); |
4239 content->AddChildView(c2); | 4239 content->AddChildView(c2); |
4240 | 4240 |
4241 ui::Layer* parent_layer = c1->layer()->parent(); | 4241 ui::Layer* parent_layer = c1->layer()->parent(); |
4242 ASSERT_TRUE(parent_layer); | 4242 ASSERT_TRUE(parent_layer); |
4243 ASSERT_EQ(2u, parent_layer->children().size()); | 4243 ASSERT_EQ(2u, parent_layer->children().size()); |
4244 EXPECT_EQ(c1->layer(), parent_layer->children()[0]); | 4244 EXPECT_EQ(c1->layer(), parent_layer->children()[0]); |
4245 EXPECT_EQ(c2->layer(), parent_layer->children()[1]); | 4245 EXPECT_EQ(c2->layer(), parent_layer->children()[1]); |
4246 | 4246 |
4247 // Move c1 to the front. The layers should have moved too. | 4247 // Move c1 to the front. The layers should have moved too. |
4248 content->ReorderChildView(c1, -1); | 4248 content->ReorderChildView(c1, -1); |
4249 EXPECT_EQ(c1->layer(), parent_layer->children()[1]); | 4249 EXPECT_EQ(c1->layer(), parent_layer->children()[1]); |
4250 EXPECT_EQ(c2->layer(), parent_layer->children()[0]); | 4250 EXPECT_EQ(c2->layer(), parent_layer->children()[0]); |
4251 } | 4251 } |
4252 | 4252 |
4253 // Verifies that the layer of a view can be acquired properly. | 4253 // Verifies that the layer of a view can be acquired properly. |
4254 TEST_F(ViewLayerTest, AcquireLayer) { | 4254 TEST_F(ViewLayerTest, AcquireLayer) { |
4255 View* content = new View; | 4255 View* content = new View; |
4256 widget()->SetContentsView(content); | 4256 widget()->SetContentsView(content); |
4257 std::unique_ptr<View> c1(new View); | 4257 std::unique_ptr<View> c1(new View); |
4258 c1->SetPaintToLayer(true); | 4258 c1->SetPaintToLayer(); |
4259 EXPECT_TRUE(c1->layer()); | 4259 EXPECT_TRUE(c1->layer()); |
4260 content->AddChildView(c1.get()); | 4260 content->AddChildView(c1.get()); |
4261 | 4261 |
4262 std::unique_ptr<ui::Layer> layer(c1->AcquireLayer()); | 4262 std::unique_ptr<ui::Layer> layer(c1->AcquireLayer()); |
4263 EXPECT_EQ(layer.get(), c1->layer()); | 4263 EXPECT_EQ(layer.get(), c1->layer()); |
4264 | 4264 |
4265 std::unique_ptr<ui::Layer> layer2(c1->RecreateLayer()); | 4265 std::unique_ptr<ui::Layer> layer2(c1->RecreateLayer()); |
4266 EXPECT_NE(c1->layer(), layer2.get()); | 4266 EXPECT_NE(c1->layer(), layer2.get()); |
4267 | 4267 |
4268 // Destroy view before destroying layer. | 4268 // Destroy view before destroying layer. |
4269 c1.reset(); | 4269 c1.reset(); |
4270 } | 4270 } |
4271 | 4271 |
4272 // Verify the z-order of the layers as a result of calling RecreateLayer(). | 4272 // Verify the z-order of the layers as a result of calling RecreateLayer(). |
4273 TEST_F(ViewLayerTest, RecreateLayerZOrder) { | 4273 TEST_F(ViewLayerTest, RecreateLayerZOrder) { |
4274 std::unique_ptr<View> v(new View()); | 4274 std::unique_ptr<View> v(new View()); |
4275 v->SetPaintToLayer(true); | 4275 v->SetPaintToLayer(); |
4276 | 4276 |
4277 View* v1 = new View(); | 4277 View* v1 = new View(); |
4278 v1->SetPaintToLayer(true); | 4278 v1->SetPaintToLayer(); |
4279 v->AddChildView(v1); | 4279 v->AddChildView(v1); |
4280 View* v2 = new View(); | 4280 View* v2 = new View(); |
4281 v2->SetPaintToLayer(true); | 4281 v2->SetPaintToLayer(); |
4282 v->AddChildView(v2); | 4282 v->AddChildView(v2); |
4283 | 4283 |
4284 // Test the initial z-order. | 4284 // Test the initial z-order. |
4285 const std::vector<ui::Layer*>& child_layers_pre = v->layer()->children(); | 4285 const std::vector<ui::Layer*>& child_layers_pre = v->layer()->children(); |
4286 ASSERT_EQ(2u, child_layers_pre.size()); | 4286 ASSERT_EQ(2u, child_layers_pre.size()); |
4287 EXPECT_EQ(v1->layer(), child_layers_pre[0]); | 4287 EXPECT_EQ(v1->layer(), child_layers_pre[0]); |
4288 EXPECT_EQ(v2->layer(), child_layers_pre[1]); | 4288 EXPECT_EQ(v2->layer(), child_layers_pre[1]); |
4289 | 4289 |
4290 std::unique_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); | 4290 std::unique_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); |
4291 | 4291 |
4292 // Test the new layer order. We expect: |v1| |v1_old_layer| |v2|. | 4292 // Test the new layer order. We expect: |v1| |v1_old_layer| |v2|. |
4293 // for |v1| and |v2|. | 4293 // for |v1| and |v2|. |
4294 const std::vector<ui::Layer*>& child_layers_post = v->layer()->children(); | 4294 const std::vector<ui::Layer*>& child_layers_post = v->layer()->children(); |
4295 ASSERT_EQ(3u, child_layers_post.size()); | 4295 ASSERT_EQ(3u, child_layers_post.size()); |
4296 EXPECT_EQ(v1->layer(), child_layers_post[0]); | 4296 EXPECT_EQ(v1->layer(), child_layers_post[0]); |
4297 EXPECT_EQ(v1_old_layer.get(), child_layers_post[1]); | 4297 EXPECT_EQ(v1_old_layer.get(), child_layers_post[1]); |
4298 EXPECT_EQ(v2->layer(), child_layers_post[2]); | 4298 EXPECT_EQ(v2->layer(), child_layers_post[2]); |
4299 } | 4299 } |
4300 | 4300 |
4301 // Verify the z-order of the layers as a result of calling RecreateLayer when | 4301 // Verify the z-order of the layers as a result of calling RecreateLayer when |
4302 // the widget is the parent with the layer. | 4302 // the widget is the parent with the layer. |
4303 TEST_F(ViewLayerTest, RecreateLayerZOrderWidgetParent) { | 4303 TEST_F(ViewLayerTest, RecreateLayerZOrderWidgetParent) { |
4304 View* v = new View(); | 4304 View* v = new View(); |
4305 widget()->SetContentsView(v); | 4305 widget()->SetContentsView(v); |
4306 | 4306 |
4307 View* v1 = new View(); | 4307 View* v1 = new View(); |
4308 v1->SetPaintToLayer(true); | 4308 v1->SetPaintToLayer(); |
4309 v->AddChildView(v1); | 4309 v->AddChildView(v1); |
4310 View* v2 = new View(); | 4310 View* v2 = new View(); |
4311 v2->SetPaintToLayer(true); | 4311 v2->SetPaintToLayer(); |
4312 v->AddChildView(v2); | 4312 v->AddChildView(v2); |
4313 | 4313 |
4314 ui::Layer* root_layer = GetRootLayer(); | 4314 ui::Layer* root_layer = GetRootLayer(); |
4315 | 4315 |
4316 // Test the initial z-order. | 4316 // Test the initial z-order. |
4317 const std::vector<ui::Layer*>& child_layers_pre = root_layer->children(); | 4317 const std::vector<ui::Layer*>& child_layers_pre = root_layer->children(); |
4318 ASSERT_EQ(2u, child_layers_pre.size()); | 4318 ASSERT_EQ(2u, child_layers_pre.size()); |
4319 EXPECT_EQ(v1->layer(), child_layers_pre[0]); | 4319 EXPECT_EQ(v1->layer(), child_layers_pre[0]); |
4320 EXPECT_EQ(v2->layer(), child_layers_pre[1]); | 4320 EXPECT_EQ(v2->layer(), child_layers_pre[1]); |
4321 | 4321 |
4322 std::unique_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); | 4322 std::unique_ptr<ui::Layer> v1_old_layer(v1->RecreateLayer()); |
4323 | 4323 |
4324 // Test the new layer order. We expect: |v1| |v1_old_layer| |v2|. | 4324 // Test the new layer order. We expect: |v1| |v1_old_layer| |v2|. |
4325 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); | 4325 const std::vector<ui::Layer*>& child_layers_post = root_layer->children(); |
4326 ASSERT_EQ(3u, child_layers_post.size()); | 4326 ASSERT_EQ(3u, child_layers_post.size()); |
4327 EXPECT_EQ(v1->layer(), child_layers_post[0]); | 4327 EXPECT_EQ(v1->layer(), child_layers_post[0]); |
4328 EXPECT_EQ(v1_old_layer.get(), child_layers_post[1]); | 4328 EXPECT_EQ(v1_old_layer.get(), child_layers_post[1]); |
4329 EXPECT_EQ(v2->layer(), child_layers_post[2]); | 4329 EXPECT_EQ(v2->layer(), child_layers_post[2]); |
4330 } | 4330 } |
4331 | 4331 |
4332 // Verifies RecreateLayer() moves all Layers over, even those that don't have | 4332 // Verifies RecreateLayer() moves all Layers over, even those that don't have |
4333 // a View. | 4333 // a View. |
4334 TEST_F(ViewLayerTest, RecreateLayerMovesNonViewChildren) { | 4334 TEST_F(ViewLayerTest, RecreateLayerMovesNonViewChildren) { |
4335 View v; | 4335 View v; |
4336 v.SetPaintToLayer(true); | 4336 v.SetPaintToLayer(); |
4337 View child; | 4337 View child; |
4338 child.SetPaintToLayer(true); | 4338 child.SetPaintToLayer(); |
4339 v.AddChildView(&child); | 4339 v.AddChildView(&child); |
4340 ASSERT_TRUE(v.layer() != NULL); | 4340 ASSERT_TRUE(v.layer() != NULL); |
4341 ASSERT_EQ(1u, v.layer()->children().size()); | 4341 ASSERT_EQ(1u, v.layer()->children().size()); |
4342 EXPECT_EQ(v.layer()->children()[0], child.layer()); | 4342 EXPECT_EQ(v.layer()->children()[0], child.layer()); |
4343 | 4343 |
4344 ui::Layer layer(ui::LAYER_NOT_DRAWN); | 4344 ui::Layer layer(ui::LAYER_NOT_DRAWN); |
4345 v.layer()->Add(&layer); | 4345 v.layer()->Add(&layer); |
4346 v.layer()->StackAtBottom(&layer); | 4346 v.layer()->StackAtBottom(&layer); |
4347 | 4347 |
4348 std::unique_ptr<ui::Layer> old_layer(v.RecreateLayer()); | 4348 std::unique_ptr<ui::Layer> old_layer(v.RecreateLayer()); |
(...skipping 23 matching lines...) Expand all Loading... |
4372 View* v11 = new View; | 4372 View* v11 = new View; |
4373 v1->AddChildView(v11); | 4373 v1->AddChildView(v11); |
4374 | 4374 |
4375 widget()->SetContentsView(v1); | 4375 widget()->SetContentsView(v1); |
4376 | 4376 |
4377 const gfx::Size& size = GetRootLayer()->GetCompositor()->size(); | 4377 const gfx::Size& size = GetRootLayer()->GetCompositor()->size(); |
4378 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.25f, size); | 4378 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.25f, size); |
4379 | 4379 |
4380 v11->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); | 4380 v11->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); |
4381 v1->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); | 4381 v1->SetBoundsRect(gfx::Rect(1, 1, 10, 10)); |
4382 v11->SetPaintToLayer(true); | 4382 v11->SetPaintToLayer(); |
4383 | 4383 |
4384 EXPECT_EQ("0.40 0.40", ToString(v11->layer()->subpixel_position_offset())); | 4384 EXPECT_EQ("0.40 0.40", ToString(v11->layer()->subpixel_position_offset())); |
4385 | 4385 |
4386 // Creating a layer in parent should update the child view's layer offset. | 4386 // Creating a layer in parent should update the child view's layer offset. |
4387 v1->SetPaintToLayer(true); | 4387 v1->SetPaintToLayer(); |
4388 EXPECT_EQ("-0.20 -0.20", ToString(v1->layer()->subpixel_position_offset())); | 4388 EXPECT_EQ("-0.20 -0.20", ToString(v1->layer()->subpixel_position_offset())); |
4389 EXPECT_EQ("-0.20 -0.20", ToString(v11->layer()->subpixel_position_offset())); | 4389 EXPECT_EQ("-0.20 -0.20", ToString(v11->layer()->subpixel_position_offset())); |
4390 | 4390 |
4391 // DSF change should get propagated and update offsets. | 4391 // DSF change should get propagated and update offsets. |
4392 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.5f, size); | 4392 GetRootLayer()->GetCompositor()->SetScaleAndSize(1.5f, size); |
4393 EXPECT_EQ("0.33 0.33", ToString(v1->layer()->subpixel_position_offset())); | 4393 EXPECT_EQ("0.33 0.33", ToString(v1->layer()->subpixel_position_offset())); |
4394 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); | 4394 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); |
4395 | 4395 |
4396 // Deleting parent's layer should update the child view's layer's offset. | 4396 // Deleting parent's layer should update the child view's layer's offset. |
4397 v1->SetPaintToLayer(false); | 4397 v1->DetachLayer(); |
4398 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); | 4398 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); |
4399 | 4399 |
4400 // Setting parent view should update the child view's layer's offset. | 4400 // Setting parent view should update the child view's layer's offset. |
4401 v1->SetBoundsRect(gfx::Rect(2, 2, 10, 10)); | 4401 v1->SetBoundsRect(gfx::Rect(2, 2, 10, 10)); |
4402 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); | 4402 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); |
4403 | 4403 |
4404 // Setting integral DSF should reset the offset. | 4404 // Setting integral DSF should reset the offset. |
4405 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); | 4405 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); |
4406 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); | 4406 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); |
4407 } | 4407 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4538 | 4538 |
4539 private: | 4539 private: |
4540 ui::NativeTheme* theme_; | 4540 ui::NativeTheme* theme_; |
4541 | 4541 |
4542 DISALLOW_COPY_AND_ASSIGN(WidgetWithCustomTheme); | 4542 DISALLOW_COPY_AND_ASSIGN(WidgetWithCustomTheme); |
4543 }; | 4543 }; |
4544 | 4544 |
4545 // See comment above test for details. | 4545 // See comment above test for details. |
4546 class ViewThatAddsViewInOnNativeThemeChanged : public View { | 4546 class ViewThatAddsViewInOnNativeThemeChanged : public View { |
4547 public: | 4547 public: |
4548 ViewThatAddsViewInOnNativeThemeChanged() { SetPaintToLayer(true); } | 4548 ViewThatAddsViewInOnNativeThemeChanged() { SetPaintToLayer(); } |
4549 ~ViewThatAddsViewInOnNativeThemeChanged() override {} | 4549 ~ViewThatAddsViewInOnNativeThemeChanged() override {} |
4550 | 4550 |
4551 bool on_native_theme_changed_called() const { | 4551 bool on_native_theme_changed_called() const { |
4552 return on_native_theme_changed_called_; | 4552 return on_native_theme_changed_called_; |
4553 } | 4553 } |
4554 | 4554 |
4555 // View: | 4555 // View: |
4556 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { | 4556 void OnNativeThemeChanged(const ui::NativeTheme* theme) override { |
4557 on_native_theme_changed_called_ = true; | 4557 on_native_theme_changed_called_ = true; |
4558 GetWidget()->GetRootView()->AddChildView(new View); | 4558 GetWidget()->GetRootView()->AddChildView(new View); |
(...skipping 26 matching lines...) Expand all Loading... |
4585 const gfx::Rect& rect, | 4585 const gfx::Rect& rect, |
4586 const ExtraParams& extra) const override {} | 4586 const ExtraParams& extra) const override {} |
4587 | 4587 |
4588 private: | 4588 private: |
4589 DISALLOW_COPY_AND_ASSIGN(TestNativeTheme); | 4589 DISALLOW_COPY_AND_ASSIGN(TestNativeTheme); |
4590 }; | 4590 }; |
4591 | 4591 |
4592 // Creates and adds a new child view to |parent| that has a layer. | 4592 // Creates and adds a new child view to |parent| that has a layer. |
4593 void AddViewWithChildLayer(View* parent) { | 4593 void AddViewWithChildLayer(View* parent) { |
4594 View* child = new View; | 4594 View* child = new View; |
4595 child->SetPaintToLayer(true); | 4595 child->SetPaintToLayer(); |
4596 parent->AddChildView(child); | 4596 parent->AddChildView(child); |
4597 } | 4597 } |
4598 | 4598 |
4599 // This test does the following: | 4599 // This test does the following: |
4600 // . creates a couple of views with layers added to the root. | 4600 // . creates a couple of views with layers added to the root. |
4601 // . Add a view that overrides OnNativeThemeChanged(). In | 4601 // . Add a view that overrides OnNativeThemeChanged(). In |
4602 // OnNativeThemeChanged() another view is added. | 4602 // OnNativeThemeChanged() another view is added. |
4603 // This sequence triggered DCHECKs or crashes previously. This tests verifies | 4603 // This sequence triggered DCHECKs or crashes previously. This tests verifies |
4604 // that doesn't happen. Reason for crash was OnNativeThemeChanged() was called | 4604 // that doesn't happen. Reason for crash was OnNativeThemeChanged() was called |
4605 // before the layer hierarchy was updated. OnNativeThemeChanged() should be | 4605 // before the layer hierarchy was updated. OnNativeThemeChanged() should be |
(...skipping 10 matching lines...) Expand all Loading... |
4616 ViewThatAddsViewInOnNativeThemeChanged* v = | 4616 ViewThatAddsViewInOnNativeThemeChanged* v = |
4617 new ViewThatAddsViewInOnNativeThemeChanged; | 4617 new ViewThatAddsViewInOnNativeThemeChanged; |
4618 widget.GetRootView()->AddChildView(v); | 4618 widget.GetRootView()->AddChildView(v); |
4619 EXPECT_TRUE(v->on_native_theme_changed_called()); | 4619 EXPECT_TRUE(v->on_native_theme_changed_called()); |
4620 } | 4620 } |
4621 | 4621 |
4622 // A View that removes its Layer when hidden. | 4622 // A View that removes its Layer when hidden. |
4623 class NoLayerWhenHiddenView : public View { | 4623 class NoLayerWhenHiddenView : public View { |
4624 public: | 4624 public: |
4625 NoLayerWhenHiddenView() { | 4625 NoLayerWhenHiddenView() { |
4626 SetPaintToLayer(true); | 4626 SetPaintToLayer(); |
4627 set_owned_by_client(); | 4627 set_owned_by_client(); |
4628 SetBounds(0, 0, 100, 100); | 4628 SetBounds(0, 0, 100, 100); |
4629 } | 4629 } |
4630 | 4630 |
4631 bool was_hidden() const { return was_hidden_; } | 4631 bool was_hidden() const { return was_hidden_; } |
4632 | 4632 |
4633 // View: | 4633 // View: |
4634 void VisibilityChanged(View* starting_from, bool is_visible) override { | 4634 void VisibilityChanged(View* starting_from, bool is_visible) override { |
4635 if (!is_visible) { | 4635 if (!is_visible) { |
4636 was_hidden_ = true; | 4636 was_hidden_ = true; |
4637 SetPaintToLayer(false); | 4637 DetachLayer(); |
4638 } | 4638 } |
4639 } | 4639 } |
4640 | 4640 |
4641 private: | 4641 private: |
4642 bool was_hidden_ = false; | 4642 bool was_hidden_ = false; |
4643 | 4643 |
4644 DISALLOW_COPY_AND_ASSIGN(NoLayerWhenHiddenView); | 4644 DISALLOW_COPY_AND_ASSIGN(NoLayerWhenHiddenView); |
4645 }; | 4645 }; |
4646 | 4646 |
4647 // Test that Views can safely manipulate Layers during Widget closure. | 4647 // Test that Views can safely manipulate Layers during Widget closure. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4694 return children; | 4694 return children; |
4695 } | 4695 } |
4696 | 4696 |
4697 private: | 4697 private: |
4698 DISALLOW_COPY_AND_ASSIGN(OrderableView); | 4698 DISALLOW_COPY_AND_ASSIGN(OrderableView); |
4699 }; | 4699 }; |
4700 | 4700 |
4701 TEST_F(ViewTest, ChildViewZOrderChanged) { | 4701 TEST_F(ViewTest, ChildViewZOrderChanged) { |
4702 const int kChildrenCount = 4; | 4702 const int kChildrenCount = 4; |
4703 std::unique_ptr<View> view(new OrderableView()); | 4703 std::unique_ptr<View> view(new OrderableView()); |
4704 view->SetPaintToLayer(true); | 4704 view->SetPaintToLayer(); |
4705 for (int i = 0; i < kChildrenCount; ++i) | 4705 for (int i = 0; i < kChildrenCount; ++i) |
4706 AddViewWithChildLayer(view.get()); | 4706 AddViewWithChildLayer(view.get()); |
4707 View::Views children = view->GetChildrenInZOrder(); | 4707 View::Views children = view->GetChildrenInZOrder(); |
4708 const std::vector<ui::Layer*>& layers = view->layer()->children(); | 4708 const std::vector<ui::Layer*>& layers = view->layer()->children(); |
4709 EXPECT_EQ(kChildrenCount, static_cast<int>(layers.size())); | 4709 EXPECT_EQ(kChildrenCount, static_cast<int>(layers.size())); |
4710 EXPECT_EQ(kChildrenCount, static_cast<int>(children.size())); | 4710 EXPECT_EQ(kChildrenCount, static_cast<int>(children.size())); |
4711 for (int i = 0; i < kChildrenCount; ++i) { | 4711 for (int i = 0; i < kChildrenCount; ++i) { |
4712 EXPECT_EQ(view->child_at(i)->layer(), layers[i]); | 4712 EXPECT_EQ(view->child_at(i)->layer(), layers[i]); |
4713 EXPECT_EQ(view->child_at(i), children[i]); | 4713 EXPECT_EQ(view->child_at(i), children[i]); |
4714 } | 4714 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4882 std::unique_ptr<View> view = NewView(); | 4882 std::unique_ptr<View> view = NewView(); |
4883 std::unique_ptr<View> child_view = NewView(); | 4883 std::unique_ptr<View> child_view = NewView(); |
4884 std::unique_ptr<View> child_view2 = NewView(); | 4884 std::unique_ptr<View> child_view2 = NewView(); |
4885 view->AddChildView(child_view.get()); | 4885 view->AddChildView(child_view.get()); |
4886 view->AddChildView(child_view2.get()); | 4886 view->AddChildView(child_view2.get()); |
4887 view->ReorderChildView(child_view2.get(), 0); | 4887 view->ReorderChildView(child_view2.get(), 0); |
4888 EXPECT_EQ(child_view2.get(), view_reordered()); | 4888 EXPECT_EQ(child_view2.get(), view_reordered()); |
4889 } | 4889 } |
4890 | 4890 |
4891 } // namespace views | 4891 } // namespace views |
OLD | NEW |