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