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

Side by Side Diff: ash/wm/shadow_controller.cc

Issue 9414028: Aura: New window shadows, desktop background debug toggle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
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 "ash/wm/shadow_controller.h" 5 #include "ash/wm/shadow_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/wm/shadow.h" 10 #include "ash/wm/shadow.h"
11 #include "ash/wm/shadow_types.h" 11 #include "ash/wm/shadow_types.h"
12 #include "ash/wm/window_properties.h" 12 #include "ash/wm/window_properties.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "ui/aura/client/activation_client.h"
15 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
16 #include "ui/aura/root_window.h" 17 #include "ui/aura/root_window.h"
17 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
18 19
19 using std::make_pair; 20 using std::make_pair;
20 21
21 namespace ash { 22 namespace ash {
22 namespace internal { 23 namespace internal {
23 24
24 namespace { 25 namespace {
25 26
26 ShadowType GetShadowTypeFromWindow(aura::Window* window) { 27 ShadowType GetShadowTypeFromWindow(aura::Window* window) {
27 // No shadow for transparent window. 28 // No shadow for transparent window.
28 if (window->transparent()) 29 if (window->transparent())
29 return SHADOW_TYPE_NONE; 30 return SHADOW_TYPE_NONE;
30 31
31 switch (window->type()) { 32 switch (window->type()) {
32 case aura::client::WINDOW_TYPE_NORMAL: 33 case aura::client::WINDOW_TYPE_NORMAL:
33 case aura::client::WINDOW_TYPE_PANEL: 34 case aura::client::WINDOW_TYPE_PANEL:
34 return CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kAuraTranslucentFrames) ?
36 SHADOW_TYPE_NONE : SHADOW_TYPE_RECTANGULAR;
37 case aura::client::WINDOW_TYPE_MENU: 35 case aura::client::WINDOW_TYPE_MENU:
38 case aura::client::WINDOW_TYPE_TOOLTIP: 36 case aura::client::WINDOW_TYPE_TOOLTIP:
39 return SHADOW_TYPE_RECTANGULAR; 37 return SHADOW_TYPE_RECTANGULAR;
40 default: 38 default:
41 break; 39 break;
42 } 40 }
43 return SHADOW_TYPE_NONE; 41 return SHADOW_TYPE_NONE;
44 } 42 }
45 43
46 } // namespace 44 } // namespace
47 45
48 ShadowController::ShadowController() { 46 ShadowController::ShadowController() {
49 aura::Env::GetInstance()->AddObserver(this); 47 aura::Env::GetInstance()->AddObserver(this);
48 // Watch for window activation changes.
49 aura::RootWindow::GetInstance()->AddObserver(this);
50 } 50 }
51 51
52 ShadowController::~ShadowController() { 52 ShadowController::~ShadowController() {
53 for (WindowShadowMap::const_iterator it = window_shadows_.begin(); 53 for (WindowShadowMap::const_iterator it = window_shadows_.begin();
54 it != window_shadows_.end(); ++it) { 54 it != window_shadows_.end(); ++it) {
55 it->first->RemoveObserver(this); 55 it->first->RemoveObserver(this);
56 } 56 }
57 aura::RootWindow::GetInstance()->RemoveObserver(this);
57 aura::Env::GetInstance()->RemoveObserver(this); 58 aura::Env::GetInstance()->RemoveObserver(this);
58 } 59 }
59 60
60 void ShadowController::OnWindowInitialized(aura::Window* window) { 61 void ShadowController::OnWindowInitialized(aura::Window* window) {
61 window->AddObserver(this); 62 window->AddObserver(this);
62 SetShadowType(window, GetShadowTypeFromWindow(window)); 63 SetShadowType(window, GetShadowTypeFromWindow(window));
63 HandlePossibleShadowVisibilityChange(window); 64 HandlePossibleShadowVisibilityChange(window);
64 } 65 }
65 66
66 void ShadowController::OnWindowPropertyChanged(aura::Window* window, 67 void ShadowController::OnWindowPropertyChanged(aura::Window* window,
67 const void* key, 68 const void* key,
68 intptr_t old) { 69 intptr_t old) {
69 if (key == kShadowTypeKey) 70 if (key == kShadowTypeKey) {
70 HandlePossibleShadowVisibilityChange(window); 71 HandlePossibleShadowVisibilityChange(window);
72 return;
73 }
74 if (key == aura::client::kRootWindowActiveWindowKey) {
75 aura::Window* inactive = reinterpret_cast<aura::Window*>(old);
76 HandleWindowActivationChange(inactive, false);
Daniel Erat 2012/02/17 00:18:32 mind moving the NULL check out of HandleWindowActi
James Cook 2012/02/17 03:41:27 Done.
77 aura::Window* active =
78 window->GetProperty(aura::client::kRootWindowActiveWindowKey);
79 HandleWindowActivationChange(active, true);
80 return;
81 }
71 } 82 }
72 83
73 void ShadowController::OnWindowBoundsChanged(aura::Window* window, 84 void ShadowController::OnWindowBoundsChanged(aura::Window* window,
74 const gfx::Rect& bounds) { 85 const gfx::Rect& bounds) {
75 Shadow* shadow = GetShadowForWindow(window); 86 Shadow* shadow = GetShadowForWindow(window);
76 if (shadow) 87 if (shadow)
77 shadow->SetContentBounds(gfx::Rect(bounds.size())); 88 shadow->SetContentBounds(gfx::Rect(bounds.size()));
78 } 89 }
79 90
80 void ShadowController::OnWindowDestroyed(aura::Window* window) { 91 void ShadowController::OnWindowDestroyed(aura::Window* window) {
(...skipping 11 matching lines...) Expand all
92 NOTREACHED() << "Unknown shadow type " << type; 103 NOTREACHED() << "Unknown shadow type " << type;
93 return false; 104 return false;
94 } 105 }
95 } 106 }
96 107
97 Shadow* ShadowController::GetShadowForWindow(aura::Window* window) { 108 Shadow* ShadowController::GetShadowForWindow(aura::Window* window) {
98 WindowShadowMap::const_iterator it = window_shadows_.find(window); 109 WindowShadowMap::const_iterator it = window_shadows_.find(window);
99 return it != window_shadows_.end() ? it->second.get() : NULL; 110 return it != window_shadows_.end() ? it->second.get() : NULL;
100 } 111 }
101 112
113 void ShadowController::HandleWindowActivationChange(aura::Window* window,
114 bool active) {
115 if (!window)
116 return;
117 Shadow* shadow = GetShadowForWindow(window);
118 if (shadow)
119 shadow->SetStyle(active ? Shadow::STYLE_ACTIVE : Shadow::STYLE_INACTIVE);
120 }
121
102 void ShadowController::HandlePossibleShadowVisibilityChange( 122 void ShadowController::HandlePossibleShadowVisibilityChange(
103 aura::Window* window) { 123 aura::Window* window) {
104 const bool should_show = ShouldShowShadowForWindow(window); 124 const bool should_show = ShouldShowShadowForWindow(window);
105 Shadow* shadow = GetShadowForWindow(window); 125 Shadow* shadow = GetShadowForWindow(window);
106 if (shadow) 126 if (shadow)
107 shadow->layer()->SetVisible(should_show); 127 shadow->layer()->SetVisible(should_show);
108 else if (should_show && !shadow) 128 else if (should_show && !shadow)
109 CreateShadowForWindow(window); 129 CreateShadowForWindow(window);
110 } 130 }
111 131
112 void ShadowController::CreateShadowForWindow(aura::Window* window) { 132 void ShadowController::CreateShadowForWindow(aura::Window* window) {
113 linked_ptr<Shadow> shadow(new Shadow()); 133 linked_ptr<Shadow> shadow(new Shadow());
114 window_shadows_.insert(make_pair(window, shadow)); 134 window_shadows_.insert(make_pair(window, shadow));
115 135
116 shadow->Init(); 136 shadow->Init();
117 shadow->SetContentBounds(gfx::Rect(window->bounds().size())); 137 shadow->SetContentBounds(gfx::Rect(window->bounds().size()));
118 shadow->layer()->SetVisible(ShouldShowShadowForWindow(window)); 138 shadow->layer()->SetVisible(ShouldShowShadowForWindow(window));
119 window->layer()->Add(shadow->layer()); 139 window->layer()->Add(shadow->layer());
120 } 140 }
121 141
122 } // namespace internal 142 } // namespace internal
123 } // namespace ash 143 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698