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

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

Issue 2694213003: mash: wires up shadows for mash (Closed)
Patch Set: cleanup Created 3 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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ShadowElevation::SMALL; 47 return ShadowElevation::SMALL;
48 48
49 default: 49 default:
50 break; 50 break;
51 } 51 }
52 return ShadowElevation::NONE; 52 return ShadowElevation::NONE;
53 } 53 }
54 54
55 // Returns the ShadowElevation for |window|, converting |DEFAULT| to the
56 // appropriate ShadowElevation.
57 ShadowElevation GetShadowElevationUseDefault(aura::Window* window) {
msw 2017/02/15 01:37:29 optional nit: replace 'Use' with 'Convert', 'Looku
sky 2017/02/15 03:58:25 Done.
58 ShadowElevation elevation = window->GetProperty(kShadowElevationKey);
59 return elevation == ShadowElevation::DEFAULT
60 ? GetDefaultShadowElevationForWindow(window)
61 : elevation;
62 }
63
55 ShadowElevation GetShadowElevationForActiveState(aura::Window* window) { 64 ShadowElevation GetShadowElevationForActiveState(aura::Window* window) {
56 if (IsActiveWindow(window)) 65 if (IsActiveWindow(window))
57 return kActiveNormalShadowElevation; 66 return kActiveNormalShadowElevation;
58 67
59 return GetShadowElevation(window); 68 return GetShadowElevationUseDefault(window);
60 } 69 }
61 70
62 // Returns the shadow style to be applied to |losing_active| when it is losing 71 // Returns the shadow style to be applied to |losing_active| when it is losing
63 // active to |gaining_active|. |gaining_active| may be of a type that hides when 72 // active to |gaining_active|. |gaining_active| may be of a type that hides when
64 // inactive, and as such we do not want to render |losing_active| as inactive. 73 // inactive, and as such we do not want to render |losing_active| as inactive.
65 ShadowElevation GetShadowElevationForWindowLosingActive( 74 ShadowElevation GetShadowElevationForWindowLosingActive(
66 aura::Window* losing_active, 75 aura::Window* losing_active,
67 aura::Window* gaining_active) { 76 aura::Window* gaining_active) {
68 if (gaining_active && aura::client::GetHideOnDeactivate(gaining_active)) { 77 if (gaining_active && aura::client::GetHideOnDeactivate(gaining_active)) {
69 aura::Window::Windows::const_iterator it = 78 aura::Window::Windows::const_iterator it =
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 153
145 // static 154 // static
146 ShadowController::Impl* ShadowController::Impl::GetInstance() { 155 ShadowController::Impl* ShadowController::Impl::GetInstance() {
147 if (!instance_) 156 if (!instance_)
148 instance_ = new Impl(); 157 instance_ = new Impl();
149 return instance_; 158 return instance_;
150 } 159 }
151 160
152 void ShadowController::Impl::OnWindowInitialized(aura::Window* window) { 161 void ShadowController::Impl::OnWindowInitialized(aura::Window* window) {
153 observer_manager_.Add(window); 162 observer_manager_.Add(window);
154 SetShadowElevation(window, GetDefaultShadowElevationForWindow(window));
155 HandlePossibleShadowVisibilityChange(window); 163 HandlePossibleShadowVisibilityChange(window);
156 } 164 }
157 165
158 void ShadowController::Impl::OnWindowPropertyChanged(aura::Window* window, 166 void ShadowController::Impl::OnWindowPropertyChanged(aura::Window* window,
159 const void* key, 167 const void* key,
160 intptr_t old) { 168 intptr_t old) {
161 if (key == kShadowElevationKey) { 169 if (key == kShadowElevationKey) {
162 if (window->GetProperty(kShadowElevationKey) == 170 if (window->GetProperty(kShadowElevationKey) ==
163 static_cast<ShadowElevation>(old)) 171 static_cast<ShadowElevation>(old))
164 return; 172 return;
(...skipping 26 matching lines...) Expand all
191 aura::Window* gained_active, 199 aura::Window* gained_active,
192 aura::Window* lost_active) { 200 aura::Window* lost_active) {
193 if (gained_active) { 201 if (gained_active) {
194 Shadow* shadow = GetShadowForWindow(gained_active); 202 Shadow* shadow = GetShadowForWindow(gained_active);
195 if (shadow) 203 if (shadow)
196 shadow->SetElevation(GetShadowElevationForActiveState(gained_active)); 204 shadow->SetElevation(GetShadowElevationForActiveState(gained_active));
197 } 205 }
198 if (lost_active) { 206 if (lost_active) {
199 Shadow* shadow = GetShadowForWindow(lost_active); 207 Shadow* shadow = GetShadowForWindow(lost_active);
200 if (shadow && 208 if (shadow &&
201 GetShadowElevation(lost_active) == kInactiveNormalShadowElevation) { 209 GetShadowElevationUseDefault(lost_active) ==
210 kInactiveNormalShadowElevation) {
202 shadow->SetElevation( 211 shadow->SetElevation(
203 GetShadowElevationForWindowLosingActive(lost_active, gained_active)); 212 GetShadowElevationForWindowLosingActive(lost_active, gained_active));
204 } 213 }
205 } 214 }
206 } 215 }
207 216
208 bool ShadowController::Impl::ShouldShowShadowForWindow( 217 bool ShadowController::Impl::ShouldShowShadowForWindow(
209 aura::Window* window) const { 218 aura::Window* window) const {
210 ui::WindowShowState show_state = 219 ui::WindowShowState show_state =
211 window->GetProperty(aura::client::kShowStateKey); 220 window->GetProperty(aura::client::kShowStateKey);
212 if (show_state == ui::SHOW_STATE_FULLSCREEN || 221 if (show_state == ui::SHOW_STATE_FULLSCREEN ||
213 show_state == ui::SHOW_STATE_MAXIMIZED) { 222 show_state == ui::SHOW_STATE_MAXIMIZED) {
214 return false; 223 return false;
215 } 224 }
216 225
217 return static_cast<int>(GetShadowElevation(window)) > 0; 226 return static_cast<int>(GetShadowElevationUseDefault(window)) > 0;
218 } 227 }
219 228
220 void ShadowController::Impl::HandlePossibleShadowVisibilityChange( 229 void ShadowController::Impl::HandlePossibleShadowVisibilityChange(
221 aura::Window* window) { 230 aura::Window* window) {
222 const bool should_show = ShouldShowShadowForWindow(window); 231 const bool should_show = ShouldShowShadowForWindow(window);
223 Shadow* shadow = GetShadowForWindow(window); 232 Shadow* shadow = GetShadowForWindow(window);
224 if (shadow) { 233 if (shadow) {
225 shadow->SetElevation(GetShadowElevationForActiveState(window)); 234 shadow->SetElevation(GetShadowElevationForActiveState(window));
226 shadow->layer()->SetVisible(should_show); 235 shadow->layer()->SetVisible(should_show);
227 } else if (should_show && !shadow) { 236 } else if (should_show && !shadow) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 activation_client_->RemoveObserver(this); 276 activation_client_->RemoveObserver(this);
268 } 277 }
269 278
270 void ShadowController::OnWindowActivated(ActivationReason reason, 279 void ShadowController::OnWindowActivated(ActivationReason reason,
271 aura::Window* gained_active, 280 aura::Window* gained_active,
272 aura::Window* lost_active) { 281 aura::Window* lost_active) {
273 impl_->OnWindowActivated(reason, gained_active, lost_active); 282 impl_->OnWindowActivated(reason, gained_active, lost_active);
274 } 283 }
275 284
276 } // namespace wm 285 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698