Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: ui/wm/core/shadow_controller.cc

Issue 455543004: Use ShadowController instead of creating its own. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « athena/wm/window_overview_mode.cc ('k') | ui/wm/core/shadow_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 switch (window->type()) { 44 switch (window->type()) {
45 case ui::wm::WINDOW_TYPE_MENU: 45 case ui::wm::WINDOW_TYPE_MENU:
46 case ui::wm::WINDOW_TYPE_TOOLTIP: 46 case ui::wm::WINDOW_TYPE_TOOLTIP:
47 return true; 47 return true;
48 default: 48 default:
49 break; 49 break;
50 } 50 }
51 return false; 51 return false;
52 } 52 }
53 53
54 bool IsShadowAlwaysActive(aura::Window* window) {
55 return GetShadowType(window) == SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE;
56 }
57
58 Shadow::Style GetShadowStyleForWindow(aura::Window* window) {
59 return ShouldUseSmallShadowForWindow(window) ? Shadow::STYLE_SMALL :
60 ((IsActiveWindow(window) || IsShadowAlwaysActive(window)) ?
61 Shadow::STYLE_ACTIVE : Shadow::STYLE_INACTIVE);
62 }
63
54 // Returns the shadow style to be applied to |losing_active| when it is losing 64 // Returns the shadow style to be applied to |losing_active| when it is losing
55 // active to |gaining_active|. |gaining_active| may be of a type that hides when 65 // active to |gaining_active|. |gaining_active| may be of a type that hides when
56 // inactive, and as such we do not want to render |losing_active| as inactive. 66 // inactive, and as such we do not want to render |losing_active| as inactive.
57 Shadow::Style GetShadowStyleForWindowLosingActive( 67 Shadow::Style GetShadowStyleForWindowLosingActive(
58 aura::Window* losing_active, 68 aura::Window* losing_active,
59 aura::Window* gaining_active) { 69 aura::Window* gaining_active) {
70 if (IsShadowAlwaysActive(losing_active))
71 return Shadow::STYLE_ACTIVE;
72
60 if (gaining_active && aura::client::GetHideOnDeactivate(gaining_active)) { 73 if (gaining_active && aura::client::GetHideOnDeactivate(gaining_active)) {
61 aura::Window::Windows::const_iterator it = 74 aura::Window::Windows::const_iterator it =
62 std::find(GetTransientChildren(losing_active).begin(), 75 std::find(GetTransientChildren(losing_active).begin(),
63 GetTransientChildren(losing_active).end(), 76 GetTransientChildren(losing_active).end(),
64 gaining_active); 77 gaining_active);
65 if (it != GetTransientChildren(losing_active).end()) 78 if (it != GetTransientChildren(losing_active).end())
66 return Shadow::STYLE_ACTIVE; 79 return Shadow::STYLE_ACTIVE;
67 } 80 }
68 return Shadow::STYLE_INACTIVE; 81 return Shadow::STYLE_INACTIVE;
69 } 82 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 206 }
194 } 207 }
195 208
196 bool ShadowController::Impl::ShouldShowShadowForWindow( 209 bool ShadowController::Impl::ShouldShowShadowForWindow(
197 aura::Window* window) const { 210 aura::Window* window) const {
198 const ShadowType type = GetShadowType(window); 211 const ShadowType type = GetShadowType(window);
199 switch (type) { 212 switch (type) {
200 case SHADOW_TYPE_NONE: 213 case SHADOW_TYPE_NONE:
201 return false; 214 return false;
202 case SHADOW_TYPE_RECTANGULAR: 215 case SHADOW_TYPE_RECTANGULAR:
216 case SHADOW_TYPE_RECTANGULAR_ALWAYS_ACTIVE:
203 return true; 217 return true;
204 default: 218 default:
205 NOTREACHED() << "Unknown shadow type " << type; 219 NOTREACHED() << "Unknown shadow type " << type;
206 return false; 220 return false;
207 } 221 }
208 } 222 }
209 223
210 Shadow* ShadowController::Impl::GetShadowForWindow(aura::Window* window) { 224 Shadow* ShadowController::Impl::GetShadowForWindow(aura::Window* window) {
211 WindowShadowMap::const_iterator it = window_shadows_.find(window); 225 WindowShadowMap::const_iterator it = window_shadows_.find(window);
212 return it != window_shadows_.end() ? it->second.get() : NULL; 226 return it != window_shadows_.end() ? it->second.get() : NULL;
213 } 227 }
214 228
215 void ShadowController::Impl::HandlePossibleShadowVisibilityChange( 229 void ShadowController::Impl::HandlePossibleShadowVisibilityChange(
216 aura::Window* window) { 230 aura::Window* window) {
217 const bool should_show = ShouldShowShadowForWindow(window); 231 const bool should_show = ShouldShowShadowForWindow(window);
218 Shadow* shadow = GetShadowForWindow(window); 232 Shadow* shadow = GetShadowForWindow(window);
219 if (shadow) 233 if (shadow) {
234 shadow->SetStyle(GetShadowStyleForWindow(window));
220 shadow->layer()->SetVisible(should_show); 235 shadow->layer()->SetVisible(should_show);
221 else if (should_show && !shadow) 236 } else if (should_show && !shadow) {
222 CreateShadowForWindow(window); 237 CreateShadowForWindow(window);
238 }
223 } 239 }
224 240
225 void ShadowController::Impl::CreateShadowForWindow(aura::Window* window) { 241 void ShadowController::Impl::CreateShadowForWindow(aura::Window* window) {
226 linked_ptr<Shadow> shadow(new Shadow()); 242 linked_ptr<Shadow> shadow(new Shadow());
227 window_shadows_.insert(make_pair(window, shadow)); 243 window_shadows_.insert(make_pair(window, shadow));
228 244 shadow->Init(GetShadowStyleForWindow(window));
229 shadow->Init(ShouldUseSmallShadowForWindow(window) ?
230 Shadow::STYLE_SMALL : Shadow::STYLE_ACTIVE);
231 shadow->SetContentBounds(gfx::Rect(window->bounds().size())); 245 shadow->SetContentBounds(gfx::Rect(window->bounds().size()));
232 shadow->layer()->SetVisible(ShouldShowShadowForWindow(window)); 246 shadow->layer()->SetVisible(ShouldShowShadowForWindow(window));
233 window->layer()->Add(shadow->layer()); 247 window->layer()->Add(shadow->layer());
234 } 248 }
235 249
236 ShadowController::Impl::Impl() 250 ShadowController::Impl::Impl()
237 : observer_manager_(this) { 251 : observer_manager_(this) {
238 aura::Env::GetInstance()->AddObserver(this); 252 aura::Env::GetInstance()->AddObserver(this);
239 } 253 }
240 254
(...skipping 22 matching lines...) Expand all
263 impl_->OnWindowActivated(gained_active, lost_active); 277 impl_->OnWindowActivated(gained_active, lost_active);
264 } 278 }
265 279
266 // ShadowController::TestApi --------------------------------------------------- 280 // ShadowController::TestApi ---------------------------------------------------
267 281
268 Shadow* ShadowController::TestApi::GetShadowForWindow(aura::Window* window) { 282 Shadow* ShadowController::TestApi::GetShadowForWindow(aura::Window* window) {
269 return controller_->impl_->GetShadowForWindow(window); 283 return controller_->impl_->GetShadowForWindow(window);
270 } 284 }
271 285
272 } // namespace wm 286 } // namespace wm
OLDNEW
« no previous file with comments | « athena/wm/window_overview_mode.cc ('k') | ui/wm/core/shadow_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698