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/corewm/shadow_controller.h" | 5 #include "ui/views/corewm/shadow_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 scoped_ptr<ShadowController> shadow_controller_; | 47 scoped_ptr<ShadowController> shadow_controller_; |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest); | 49 DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest); |
50 }; | 50 }; |
51 | 51 |
52 // Tests that various methods in Window update the Shadow object as expected. | 52 // Tests that various methods in Window update the Shadow object as expected. |
53 TEST_F(ShadowControllerTest, Shadow) { | 53 TEST_F(ShadowControllerTest, Shadow) { |
54 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 54 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
55 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 55 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
56 window->Init(ui::LAYER_TEXTURED); | 56 window->Init(ui::LAYER_TEXTURED); |
57 window->SetParent(NULL); | 57 SetDefaultParentByPrimaryRootWindow(window.get()); |
58 | 58 |
59 // We should create the shadow before the window is visible (the shadow's | 59 // We should create the shadow before the window is visible (the shadow's |
60 // layer won't get drawn yet since it's a child of the window's layer). | 60 // layer won't get drawn yet since it's a child of the window's layer). |
61 ShadowController::TestApi api(shadow_controller()); | 61 ShadowController::TestApi api(shadow_controller()); |
62 const Shadow* shadow = api.GetShadowForWindow(window.get()); | 62 const Shadow* shadow = api.GetShadowForWindow(window.get()); |
63 ASSERT_TRUE(shadow != NULL); | 63 ASSERT_TRUE(shadow != NULL); |
64 EXPECT_TRUE(shadow->layer()->visible()); | 64 EXPECT_TRUE(shadow->layer()->visible()); |
65 | 65 |
66 // The shadow should remain visible after window visibility changes. | 66 // The shadow should remain visible after window visibility changes. |
67 window->Show(); | 67 window->Show(); |
(...skipping 15 matching lines...) Expand all Loading... |
83 aura::Window* window_ptr = window.get(); | 83 aura::Window* window_ptr = window.get(); |
84 window.reset(); | 84 window.reset(); |
85 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); | 85 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); |
86 } | 86 } |
87 | 87 |
88 // Tests that the window's shadow's bounds are updated correctly. | 88 // Tests that the window's shadow's bounds are updated correctly. |
89 TEST_F(ShadowControllerTest, ShadowBounds) { | 89 TEST_F(ShadowControllerTest, ShadowBounds) { |
90 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 90 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
91 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 91 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
92 window->Init(ui::LAYER_TEXTURED); | 92 window->Init(ui::LAYER_TEXTURED); |
93 window->SetParent(NULL); | 93 SetDefaultParentByPrimaryRootWindow(window.get()); |
94 window->Show(); | 94 window->Show(); |
95 | 95 |
96 const gfx::Rect kOldBounds(20, 30, 400, 300); | 96 const gfx::Rect kOldBounds(20, 30, 400, 300); |
97 window->SetBounds(kOldBounds); | 97 window->SetBounds(kOldBounds); |
98 | 98 |
99 // When the shadow is first created, it should use the window's size (but | 99 // When the shadow is first created, it should use the window's size (but |
100 // remain at the origin, since it's a child of the window's layer). | 100 // remain at the origin, since it's a child of the window's layer). |
101 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); | 101 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); |
102 ShadowController::TestApi api(shadow_controller()); | 102 ShadowController::TestApi api(shadow_controller()); |
103 const Shadow* shadow = api.GetShadowForWindow(window.get()); | 103 const Shadow* shadow = api.GetShadowForWindow(window.get()); |
104 ASSERT_TRUE(shadow != NULL); | 104 ASSERT_TRUE(shadow != NULL); |
105 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), | 105 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), |
106 shadow->content_bounds().ToString()); | 106 shadow->content_bounds().ToString()); |
107 | 107 |
108 // When we change the window's bounds, the shadow's should be updated too. | 108 // When we change the window's bounds, the shadow's should be updated too. |
109 gfx::Rect kNewBounds(50, 60, 500, 400); | 109 gfx::Rect kNewBounds(50, 60, 500, 400); |
110 window->SetBounds(kNewBounds); | 110 window->SetBounds(kNewBounds); |
111 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), | 111 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), |
112 shadow->content_bounds().ToString()); | 112 shadow->content_bounds().ToString()); |
113 } | 113 } |
114 | 114 |
115 // Tests that activating a window changes the shadow style. | 115 // Tests that activating a window changes the shadow style. |
116 TEST_F(ShadowControllerTest, ShadowStyle) { | 116 TEST_F(ShadowControllerTest, ShadowStyle) { |
117 ShadowController::TestApi api(shadow_controller()); | 117 ShadowController::TestApi api(shadow_controller()); |
118 | 118 |
119 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); | 119 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); |
120 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); | 120 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); |
121 window1->Init(ui::LAYER_TEXTURED); | 121 window1->Init(ui::LAYER_TEXTURED); |
122 window1->SetParent(NULL); | 122 SetDefaultParentByPrimaryRootWindow(window1.get()); |
123 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); | 123 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); |
124 window1->Show(); | 124 window1->Show(); |
125 ActivateWindow(window1.get()); | 125 ActivateWindow(window1.get()); |
126 | 126 |
127 // window1 is active, so style should have active appearance. | 127 // window1 is active, so style should have active appearance. |
128 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); | 128 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); |
129 ASSERT_TRUE(shadow1 != NULL); | 129 ASSERT_TRUE(shadow1 != NULL); |
130 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 130 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
131 | 131 |
132 // Create another window and activate it. | 132 // Create another window and activate it. |
133 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | 133 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
134 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); | 134 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); |
135 window2->Init(ui::LAYER_TEXTURED); | 135 window2->Init(ui::LAYER_TEXTURED); |
136 window2->SetParent(NULL); | 136 SetDefaultParentByPrimaryRootWindow(window2.get()); |
137 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); | 137 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); |
138 window2->Show(); | 138 window2->Show(); |
139 ActivateWindow(window2.get()); | 139 ActivateWindow(window2.get()); |
140 | 140 |
141 // window1 is now inactive, so shadow should go inactive. | 141 // window1 is now inactive, so shadow should go inactive. |
142 Shadow* shadow2 = api.GetShadowForWindow(window2.get()); | 142 Shadow* shadow2 = api.GetShadowForWindow(window2.get()); |
143 ASSERT_TRUE(shadow2 != NULL); | 143 ASSERT_TRUE(shadow2 != NULL); |
144 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style()); | 144 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style()); |
145 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style()); | 145 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style()); |
146 } | 146 } |
147 | 147 |
148 // Tests that we use smaller shadows for tooltips and menus. | 148 // Tests that we use smaller shadows for tooltips and menus. |
149 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) { | 149 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) { |
150 ShadowController::TestApi api(shadow_controller()); | 150 ShadowController::TestApi api(shadow_controller()); |
151 | 151 |
152 scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL)); | 152 scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL)); |
153 tooltip_window->SetType(aura::client::WINDOW_TYPE_TOOLTIP); | 153 tooltip_window->SetType(aura::client::WINDOW_TYPE_TOOLTIP); |
154 tooltip_window->Init(ui::LAYER_TEXTURED); | 154 tooltip_window->Init(ui::LAYER_TEXTURED); |
155 tooltip_window->SetParent(NULL); | 155 SetDefaultParentByPrimaryRootWindow(tooltip_window.get()); |
156 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400)); | 156 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400)); |
157 tooltip_window->Show(); | 157 tooltip_window->Show(); |
158 | 158 |
159 Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get()); | 159 Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get()); |
160 ASSERT_TRUE(tooltip_shadow != NULL); | 160 ASSERT_TRUE(tooltip_shadow != NULL); |
161 EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style()); | 161 EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style()); |
162 | 162 |
163 scoped_ptr<aura::Window> menu_window(new aura::Window(NULL)); | 163 scoped_ptr<aura::Window> menu_window(new aura::Window(NULL)); |
164 menu_window->SetType(aura::client::WINDOW_TYPE_MENU); | 164 menu_window->SetType(aura::client::WINDOW_TYPE_MENU); |
165 menu_window->Init(ui::LAYER_TEXTURED); | 165 menu_window->Init(ui::LAYER_TEXTURED); |
166 menu_window->SetParent(NULL); | 166 SetDefaultParentByPrimaryRootWindow(menu_window.get()); |
167 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400)); | 167 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400)); |
168 menu_window->Show(); | 168 menu_window->Show(); |
169 | 169 |
170 Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get()); | 170 Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get()); |
171 ASSERT_TRUE(menu_shadow != NULL); | 171 ASSERT_TRUE(menu_shadow != NULL); |
172 EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style()); | 172 EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style()); |
173 } | 173 } |
174 | 174 |
175 // http://crbug.com/120210 - transient parents of certain types of transients | 175 // http://crbug.com/120210 - transient parents of certain types of transients |
176 // should not lose their shadow when they lose activation to the transient. | 176 // should not lose their shadow when they lose activation to the transient. |
177 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) { | 177 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) { |
178 ShadowController::TestApi api(shadow_controller()); | 178 ShadowController::TestApi api(shadow_controller()); |
179 | 179 |
180 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); | 180 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); |
181 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); | 181 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); |
182 window1->Init(ui::LAYER_TEXTURED); | 182 window1->Init(ui::LAYER_TEXTURED); |
183 window1->SetParent(NULL); | 183 SetDefaultParentByPrimaryRootWindow(window1.get()); |
184 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); | 184 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); |
185 window1->Show(); | 185 window1->Show(); |
186 ActivateWindow(window1.get()); | 186 ActivateWindow(window1.get()); |
187 | 187 |
188 // window1 is active, so style should have active appearance. | 188 // window1 is active, so style should have active appearance. |
189 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); | 189 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); |
190 ASSERT_TRUE(shadow1 != NULL); | 190 ASSERT_TRUE(shadow1 != NULL); |
191 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 191 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
192 | 192 |
193 // Create a window that is transient to window1, and that has the 'hide on | 193 // Create a window that is transient to window1, and that has the 'hide on |
194 // deactivate' property set. Upon activation, window1 should still have an | 194 // deactivate' property set. Upon activation, window1 should still have an |
195 // active shadow. | 195 // active shadow. |
196 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | 196 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
197 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); | 197 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); |
198 window2->Init(ui::LAYER_TEXTURED); | 198 window2->Init(ui::LAYER_TEXTURED); |
199 window2->SetParent(NULL); | 199 SetDefaultParentByPrimaryRootWindow(window2.get()); |
200 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); | 200 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); |
201 window1->AddTransientChild(window2.get()); | 201 window1->AddTransientChild(window2.get()); |
202 aura::client::SetHideOnDeactivate(window2.get(), true); | 202 aura::client::SetHideOnDeactivate(window2.get(), true); |
203 window2->Show(); | 203 window2->Show(); |
204 ActivateWindow(window2.get()); | 204 ActivateWindow(window2.get()); |
205 | 205 |
206 // window1 is now inactive, but its shadow should still appear active. | 206 // window1 is now inactive, but its shadow should still appear active. |
207 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 207 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
208 } | 208 } |
209 | 209 |
210 } // namespace corewm | 210 } // namespace corewm |
211 } // namespace views | 211 } // namespace views |
OLD | NEW |