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