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