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