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

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

Issue 2596743002: Replace WM shadow types (on/off) and styles (small/inactive/active) (Closed)
Patch Set: . Created 4 years 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.h" 5 #include "ui/wm/core/shadow.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/scoped_layer_animation_settings.h" 10 #include "ui/compositor/scoped_layer_animation_settings.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 shadow->values, kRoundedCornerRadius); 60 shadow->values, kRoundedCornerRadius);
61 return *shadow; 61 return *shadow;
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 65
66 Shadow::Shadow() {} 66 Shadow::Shadow() {}
67 67
68 Shadow::~Shadow() {} 68 Shadow::~Shadow() {}
69 69
70 void Shadow::Init(Style style) { 70 void Shadow::Init(ShadowElevation elevation) {
71 style_ = style; 71 desired_elevation_ = static_cast<int>(elevation);
72 layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN)); 72 layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN));
73 RecreateShadowLayer(); 73 RecreateShadowLayer();
74 } 74 }
75 75
76 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) { 76 void Shadow::SetContentBounds(const gfx::Rect& content_bounds) {
77 // When the window moves but doesn't change size, this is a no-op. (The 77 // When the window moves but doesn't change size, this is a no-op. (The
78 // origin stays the same in this case.) 78 // origin stays the same in this case.)
79 if (content_bounds == content_bounds_) 79 if (content_bounds == content_bounds_)
80 return; 80 return;
81 81
82 content_bounds_ = content_bounds; 82 content_bounds_ = content_bounds;
83 UpdateLayerBounds(); 83 UpdateLayerBounds();
84 } 84 }
85 85
86 void Shadow::SetStyle(Style style) { 86 void Shadow::SetElevation(ShadowElevation elevation) {
87 if (style_ == style) 87 const int elevation_value = static_cast<int>(elevation);
88 if (desired_elevation_ == elevation_value)
88 return; 89 return;
89 90
90 style_ = style; 91 desired_elevation_ = elevation_value;
91 92
92 // Stop waiting for any as yet unfinished implicit animations. 93 // Stop waiting for any as yet unfinished implicit animations.
93 StopObservingImplicitAnimations(); 94 StopObservingImplicitAnimations();
94 95
95 // The old shadow layer is the new fading out layer. 96 // The old shadow layer is the new fading out layer.
96 DCHECK(shadow_layer_); 97 DCHECK(shadow_layer_);
97 fading_layer_ = std::move(shadow_layer_); 98 fading_layer_ = std::move(shadow_layer_);
98 RecreateShadowLayer(); 99 RecreateShadowLayer();
99 shadow_layer_->SetOpacity(0.f); 100 shadow_layer_->SetOpacity(0.f);
100 101
(...skipping 29 matching lines...) Expand all
130 shadow_layer_->SetFillsBoundsOpaquely(false); 131 shadow_layer_->SetFillsBoundsOpaquely(false);
131 layer()->Add(shadow_layer_.get()); 132 layer()->Add(shadow_layer_.get());
132 133
133 UpdateLayerBounds(); 134 UpdateLayerBounds();
134 } 135 }
135 136
136 void Shadow::UpdateLayerBounds() { 137 void Shadow::UpdateLayerBounds() {
137 if (content_bounds_.IsEmpty()) 138 if (content_bounds_.IsEmpty())
138 return; 139 return;
139 140
140 // The elevation depends on the style, but the ninebox assumption breaks down 141 // The ninebox assumption breaks down when the window is too small for the
141 // when the window is too small. The height/width of |blur_region| will be 142 // desired elevation. The height/width of |blur_region| will be 4 * elevation
142 // 4 * elevation (see GetDetailsForElevation), so cap elevation at the most we 143 // (see GetDetailsForElevation), so cap elevation at the most we can handle.
143 // can handle.
144 const int smaller_dimension = 144 const int smaller_dimension =
145 std::min(content_bounds_.width(), content_bounds_.height()); 145 std::min(content_bounds_.width(), content_bounds_.height());
146 const int size_adjusted_elevation = std::min( 146 const int size_adjusted_elevation = std::min(
147 (smaller_dimension - 2 * kRoundedCornerRadius) / 4, ElevationForStyle()); 147 (smaller_dimension - 2 * kRoundedCornerRadius) / 4, desired_elevation_);
148 const ShadowDetails& details = 148 const ShadowDetails& details =
149 GetDetailsForElevation(size_adjusted_elevation); 149 GetDetailsForElevation(size_adjusted_elevation);
150 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) + 150 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) +
151 gfx::Insets(kRoundedCornerRadius); 151 gfx::Insets(kRoundedCornerRadius);
152 if (size_adjusted_elevation != effective_elevation_) { 152 if (size_adjusted_elevation != effective_elevation_) {
153 shadow_layer_->UpdateNinePatchLayerImage(details.ninebox_image); 153 shadow_layer_->UpdateNinePatchLayerImage(details.ninebox_image);
154 // The ninebox grid is defined in terms of the image size. The shadow blurs 154 // The ninebox grid is defined in terms of the image size. The shadow blurs
155 // in both inward and outward directions from the edge of the contents, so 155 // in both inward and outward directions from the edge of the contents, so
156 // the aperture goes further inside the image than the shadow margins (which 156 // the aperture goes further inside the image than the shadow margins (which
157 // represent exterior blur). 157 // represent exterior blur).
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 gfx::Rect occlusion_bounds(shadow_layer_bounds.size()); 197 gfx::Rect occlusion_bounds(shadow_layer_bounds.size());
198 occlusion_bounds.Inset(-margins + gfx::Insets(kRoundedCornerRadius)); 198 occlusion_bounds.Inset(-margins + gfx::Insets(kRoundedCornerRadius));
199 shadow_layer_->UpdateNinePatchOcclusion(occlusion_bounds); 199 shadow_layer_->UpdateNinePatchOcclusion(occlusion_bounds);
200 200
201 // The border is the same inset as the aperture. 201 // The border is the same inset as the aperture.
202 shadow_layer_->UpdateNinePatchLayerBorder( 202 shadow_layer_->UpdateNinePatchLayerBorder(
203 gfx::Rect(blur_region.left(), blur_region.top(), blur_region.width(), 203 gfx::Rect(blur_region.left(), blur_region.top(), blur_region.width(),
204 blur_region.height())); 204 blur_region.height()));
205 } 205 }
206 206
207 int Shadow::ElevationForStyle() {
208 switch (style_) {
209 case STYLE_ACTIVE:
210 return 24;
211 case STYLE_INACTIVE:
212 return 8;
213 case STYLE_SMALL:
214 return 6;
215 }
216 NOTREACHED();
217 return 0;
218 }
219
220 } // namespace wm 207 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698