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