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/wm/core/shadow_controller.h" | 5 #include "ui/wm/core/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 scoped_ptr<ShadowController> shadow_controller_; | 56 scoped_ptr<ShadowController> shadow_controller_; |
57 scoped_ptr<wm::WMState> wm_state_; | 57 scoped_ptr<wm::WMState> wm_state_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest); | 59 DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest); |
60 }; | 60 }; |
61 | 61 |
62 // Tests that various methods in Window update the Shadow object as expected. | 62 // Tests that various methods in Window update the Shadow object as expected. |
63 TEST_F(ShadowControllerTest, Shadow) { | 63 TEST_F(ShadowControllerTest, Shadow) { |
64 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 64 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
65 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 65 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
66 window->Init(aura::WINDOW_LAYER_TEXTURED); | 66 window->Init(ui::LAYER_TEXTURED); |
67 ParentWindow(window.get()); | 67 ParentWindow(window.get()); |
68 | 68 |
69 // We should create the shadow before the window is visible (the shadow's | 69 // We should create the shadow before the window is visible (the shadow's |
70 // layer won't get drawn yet since it's a child of the window's layer). | 70 // layer won't get drawn yet since it's a child of the window's layer). |
71 ShadowController::TestApi api(shadow_controller()); | 71 ShadowController::TestApi api(shadow_controller()); |
72 const Shadow* shadow = api.GetShadowForWindow(window.get()); | 72 const Shadow* shadow = api.GetShadowForWindow(window.get()); |
73 ASSERT_TRUE(shadow != NULL); | 73 ASSERT_TRUE(shadow != NULL); |
74 EXPECT_TRUE(shadow->layer()->visible()); | 74 EXPECT_TRUE(shadow->layer()->visible()); |
75 | 75 |
76 // The shadow should remain visible after window visibility changes. | 76 // The shadow should remain visible after window visibility changes. |
(...skipping 15 matching lines...) Expand all Loading... |
92 window->parent()->RemoveChild(window.get()); | 92 window->parent()->RemoveChild(window.get()); |
93 aura::Window* window_ptr = window.get(); | 93 aura::Window* window_ptr = window.get(); |
94 window.reset(); | 94 window.reset(); |
95 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); | 95 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); |
96 } | 96 } |
97 | 97 |
98 // Tests that the window's shadow's bounds are updated correctly. | 98 // Tests that the window's shadow's bounds are updated correctly. |
99 TEST_F(ShadowControllerTest, ShadowBounds) { | 99 TEST_F(ShadowControllerTest, ShadowBounds) { |
100 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 100 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
101 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 101 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
102 window->Init(aura::WINDOW_LAYER_TEXTURED); | 102 window->Init(ui::LAYER_TEXTURED); |
103 ParentWindow(window.get()); | 103 ParentWindow(window.get()); |
104 window->Show(); | 104 window->Show(); |
105 | 105 |
106 const gfx::Rect kOldBounds(20, 30, 400, 300); | 106 const gfx::Rect kOldBounds(20, 30, 400, 300); |
107 window->SetBounds(kOldBounds); | 107 window->SetBounds(kOldBounds); |
108 | 108 |
109 // When the shadow is first created, it should use the window's size (but | 109 // When the shadow is first created, it should use the window's size (but |
110 // remain at the origin, since it's a child of the window's layer). | 110 // remain at the origin, since it's a child of the window's layer). |
111 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); | 111 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); |
112 ShadowController::TestApi api(shadow_controller()); | 112 ShadowController::TestApi api(shadow_controller()); |
113 const Shadow* shadow = api.GetShadowForWindow(window.get()); | 113 const Shadow* shadow = api.GetShadowForWindow(window.get()); |
114 ASSERT_TRUE(shadow != NULL); | 114 ASSERT_TRUE(shadow != NULL); |
115 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), | 115 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), |
116 shadow->content_bounds().ToString()); | 116 shadow->content_bounds().ToString()); |
117 | 117 |
118 // When we change the window's bounds, the shadow's should be updated too. | 118 // When we change the window's bounds, the shadow's should be updated too. |
119 gfx::Rect kNewBounds(50, 60, 500, 400); | 119 gfx::Rect kNewBounds(50, 60, 500, 400); |
120 window->SetBounds(kNewBounds); | 120 window->SetBounds(kNewBounds); |
121 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), | 121 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), |
122 shadow->content_bounds().ToString()); | 122 shadow->content_bounds().ToString()); |
123 } | 123 } |
124 | 124 |
125 // Tests that activating a window changes the shadow style. | 125 // Tests that activating a window changes the shadow style. |
126 TEST_F(ShadowControllerTest, ShadowStyle) { | 126 TEST_F(ShadowControllerTest, ShadowStyle) { |
127 ShadowController::TestApi api(shadow_controller()); | 127 ShadowController::TestApi api(shadow_controller()); |
128 | 128 |
129 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); | 129 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); |
130 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 130 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
131 window1->Init(aura::WINDOW_LAYER_TEXTURED); | 131 window1->Init(ui::LAYER_TEXTURED); |
132 ParentWindow(window1.get()); | 132 ParentWindow(window1.get()); |
133 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); | 133 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); |
134 window1->Show(); | 134 window1->Show(); |
135 ActivateWindow(window1.get()); | 135 ActivateWindow(window1.get()); |
136 | 136 |
137 // window1 is active, so style should have active appearance. | 137 // window1 is active, so style should have active appearance. |
138 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); | 138 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); |
139 ASSERT_TRUE(shadow1 != NULL); | 139 ASSERT_TRUE(shadow1 != NULL); |
140 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 140 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
141 | 141 |
142 // Create another window and activate it. | 142 // Create another window and activate it. |
143 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | 143 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
144 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 144 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
145 window2->Init(aura::WINDOW_LAYER_TEXTURED); | 145 window2->Init(ui::LAYER_TEXTURED); |
146 ParentWindow(window2.get()); | 146 ParentWindow(window2.get()); |
147 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); | 147 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); |
148 window2->Show(); | 148 window2->Show(); |
149 ActivateWindow(window2.get()); | 149 ActivateWindow(window2.get()); |
150 | 150 |
151 // window1 is now inactive, so shadow should go inactive. | 151 // window1 is now inactive, so shadow should go inactive. |
152 Shadow* shadow2 = api.GetShadowForWindow(window2.get()); | 152 Shadow* shadow2 = api.GetShadowForWindow(window2.get()); |
153 ASSERT_TRUE(shadow2 != NULL); | 153 ASSERT_TRUE(shadow2 != NULL); |
154 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style()); | 154 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style()); |
155 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style()); | 155 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style()); |
156 } | 156 } |
157 | 157 |
158 // Tests that shadow gets updated when the window show state chagnes. | 158 // Tests that shadow gets updated when the window show state chagnes. |
159 TEST_F(ShadowControllerTest, ShowState) { | 159 TEST_F(ShadowControllerTest, ShowState) { |
160 ShadowController::TestApi api(shadow_controller()); | 160 ShadowController::TestApi api(shadow_controller()); |
161 | 161 |
162 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 162 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
163 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 163 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
164 window->Init(aura::WINDOW_LAYER_TEXTURED); | 164 window->Init(ui::LAYER_TEXTURED); |
165 ParentWindow(window.get()); | 165 ParentWindow(window.get()); |
166 window->Show(); | 166 window->Show(); |
167 | 167 |
168 Shadow* shadow = api.GetShadowForWindow(window.get()); | 168 Shadow* shadow = api.GetShadowForWindow(window.get()); |
169 ASSERT_TRUE(shadow != NULL); | 169 ASSERT_TRUE(shadow != NULL); |
170 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow->style()); | 170 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow->style()); |
171 | 171 |
172 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 172 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
173 EXPECT_FALSE(shadow->layer()->visible()); | 173 EXPECT_FALSE(shadow->layer()->visible()); |
174 | 174 |
175 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 175 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
176 EXPECT_TRUE(shadow->layer()->visible()); | 176 EXPECT_TRUE(shadow->layer()->visible()); |
177 | 177 |
178 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 178 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
179 EXPECT_FALSE(shadow->layer()->visible()); | 179 EXPECT_FALSE(shadow->layer()->visible()); |
180 } | 180 } |
181 | 181 |
182 // Tests that we use smaller shadows for tooltips and menus. | 182 // Tests that we use smaller shadows for tooltips and menus. |
183 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) { | 183 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) { |
184 ShadowController::TestApi api(shadow_controller()); | 184 ShadowController::TestApi api(shadow_controller()); |
185 | 185 |
186 scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL)); | 186 scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL)); |
187 tooltip_window->SetType(ui::wm::WINDOW_TYPE_TOOLTIP); | 187 tooltip_window->SetType(ui::wm::WINDOW_TYPE_TOOLTIP); |
188 tooltip_window->Init(aura::WINDOW_LAYER_TEXTURED); | 188 tooltip_window->Init(ui::LAYER_TEXTURED); |
189 ParentWindow(tooltip_window.get()); | 189 ParentWindow(tooltip_window.get()); |
190 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400)); | 190 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400)); |
191 tooltip_window->Show(); | 191 tooltip_window->Show(); |
192 | 192 |
193 Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get()); | 193 Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get()); |
194 ASSERT_TRUE(tooltip_shadow != NULL); | 194 ASSERT_TRUE(tooltip_shadow != NULL); |
195 EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style()); | 195 EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style()); |
196 | 196 |
197 scoped_ptr<aura::Window> menu_window(new aura::Window(NULL)); | 197 scoped_ptr<aura::Window> menu_window(new aura::Window(NULL)); |
198 menu_window->SetType(ui::wm::WINDOW_TYPE_MENU); | 198 menu_window->SetType(ui::wm::WINDOW_TYPE_MENU); |
199 menu_window->Init(aura::WINDOW_LAYER_TEXTURED); | 199 menu_window->Init(ui::LAYER_TEXTURED); |
200 ParentWindow(menu_window.get()); | 200 ParentWindow(menu_window.get()); |
201 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400)); | 201 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400)); |
202 menu_window->Show(); | 202 menu_window->Show(); |
203 | 203 |
204 Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get()); | 204 Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get()); |
205 ASSERT_TRUE(menu_shadow != NULL); | 205 ASSERT_TRUE(menu_shadow != NULL); |
206 EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style()); | 206 EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style()); |
207 } | 207 } |
208 | 208 |
209 // http://crbug.com/120210 - transient parents of certain types of transients | 209 // http://crbug.com/120210 - transient parents of certain types of transients |
210 // should not lose their shadow when they lose activation to the transient. | 210 // should not lose their shadow when they lose activation to the transient. |
211 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) { | 211 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) { |
212 ShadowController::TestApi api(shadow_controller()); | 212 ShadowController::TestApi api(shadow_controller()); |
213 | 213 |
214 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); | 214 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); |
215 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 215 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
216 window1->Init(aura::WINDOW_LAYER_TEXTURED); | 216 window1->Init(ui::LAYER_TEXTURED); |
217 ParentWindow(window1.get()); | 217 ParentWindow(window1.get()); |
218 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); | 218 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); |
219 window1->Show(); | 219 window1->Show(); |
220 ActivateWindow(window1.get()); | 220 ActivateWindow(window1.get()); |
221 | 221 |
222 // window1 is active, so style should have active appearance. | 222 // window1 is active, so style should have active appearance. |
223 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); | 223 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); |
224 ASSERT_TRUE(shadow1 != NULL); | 224 ASSERT_TRUE(shadow1 != NULL); |
225 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 225 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
226 | 226 |
227 // Create a window that is transient to window1, and that has the 'hide on | 227 // Create a window that is transient to window1, and that has the 'hide on |
228 // deactivate' property set. Upon activation, window1 should still have an | 228 // deactivate' property set. Upon activation, window1 should still have an |
229 // active shadow. | 229 // active shadow. |
230 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | 230 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
231 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 231 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
232 window2->Init(aura::WINDOW_LAYER_TEXTURED); | 232 window2->Init(ui::LAYER_TEXTURED); |
233 ParentWindow(window2.get()); | 233 ParentWindow(window2.get()); |
234 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); | 234 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); |
235 AddTransientChild(window1.get(), window2.get()); | 235 AddTransientChild(window1.get(), window2.get()); |
236 aura::client::SetHideOnDeactivate(window2.get(), true); | 236 aura::client::SetHideOnDeactivate(window2.get(), true); |
237 window2->Show(); | 237 window2->Show(); |
238 ActivateWindow(window2.get()); | 238 ActivateWindow(window2.get()); |
239 | 239 |
240 // window1 is now inactive, but its shadow should still appear active. | 240 // window1 is now inactive, but its shadow should still appear active. |
241 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 241 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
242 } | 242 } |
243 | 243 |
244 } // namespace wm | 244 } // namespace wm |
OLD | NEW |