Chromium Code Reviews| 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/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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 if (style_ == STYLE_INACTIVE) { | 146 if (style_ == STYLE_INACTIVE) { |
| 147 UpdateImagesForStyle(); | 147 UpdateImagesForStyle(); |
| 148 // Opacity is baked into inactive image, so set fully opaque. | 148 // Opacity is baked into inactive image, so set fully opaque. |
| 149 shadow_layer_->SetOpacity(1.0f); | 149 shadow_layer_->SetOpacity(1.0f); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 void Shadow::UpdateImagesForStyle() { | 153 void Shadow::UpdateImagesForStyle() { |
| 154 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); | 154 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); |
| 155 shadow_layer_->UpdateNinePatchLayerImage(details.ninebox_image); | 155 shadow_layer_->UpdateNinePatchLayerImage(details.ninebox_image); |
| 156 // The ninebox grid is defined in terms of the image size. The shadow blurs in | |
| 157 // both inward and outward directions from the edge of the contents, so the | |
| 158 // aperture goes further inside the image than the shadow margins (which | |
| 159 // represent exterior blur). | |
| 160 gfx::Rect aperture(details.ninebox_image.size()); | |
| 161 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) + | |
| 162 gfx::Insets(kRoundedCornerRadius); | |
| 163 aperture.Inset(blur_region); | |
| 164 shadow_layer_->UpdateNinePatchLayerAperture(aperture); | |
| 165 UpdateLayerBounds(); | 156 UpdateLayerBounds(); |
| 166 } | 157 } |
| 167 | 158 |
| 168 void Shadow::UpdateLayerBounds() { | 159 void Shadow::UpdateLayerBounds() { |
| 169 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); | 160 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); |
| 170 // Shadow margins are negative, so this expands outwards from | 161 // Shadow margins are negative, so this expands outwards from |
| 171 // |content_bounds_|. | 162 // |content_bounds_|. |
| 172 const gfx::Insets margins = gfx::ShadowValue::GetMargin(details.values); | 163 const gfx::Insets margins = gfx::ShadowValue::GetMargin(details.values); |
| 173 gfx::Rect layer_bounds = content_bounds_; | 164 gfx::Rect layer_bounds = content_bounds_; |
| 174 layer_bounds.Inset(margins); | 165 layer_bounds.Inset(margins); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 186 // larger than the shadow layer. When the shadow layer is too small, shrink | 177 // larger than the shadow layer. When the shadow layer is too small, shrink |
| 187 // the dimensions proportionally. | 178 // the dimensions proportionally. |
| 188 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) + | 179 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) + |
| 189 gfx::Insets(kRoundedCornerRadius); | 180 gfx::Insets(kRoundedCornerRadius); |
| 190 int border_w = std::min(blur_region.width(), shadow_layer_bounds.width()); | 181 int border_w = std::min(blur_region.width(), shadow_layer_bounds.width()); |
| 191 int border_x = border_w * blur_region.left() / blur_region.width(); | 182 int border_x = border_w * blur_region.left() / blur_region.width(); |
| 192 int border_h = std::min(blur_region.height(), shadow_layer_bounds.height()); | 183 int border_h = std::min(blur_region.height(), shadow_layer_bounds.height()); |
| 193 int border_y = border_h * blur_region.top() / blur_region.height(); | 184 int border_y = border_h * blur_region.top() / blur_region.height(); |
| 194 shadow_layer_->UpdateNinePatchLayerBorder( | 185 shadow_layer_->UpdateNinePatchLayerBorder( |
| 195 gfx::Rect(border_x, border_y, border_w, border_h)); | 186 gfx::Rect(border_x, border_y, border_w, border_h)); |
| 187 | |
| 188 // The ninebox grid is defined in terms of the image size. The shadow blurs in | |
| 189 // both inward and outward directions from the edge of the contents, so the | |
| 190 // aperture goes further inside the image than the shadow margins (which | |
| 191 // represent exterior blur). | |
| 192 gfx::Rect aperture(details.ninebox_image.size()); | |
| 193 // The insets for the aperture are nominally |blur_region| but we need to | |
| 194 // resize them if the contents are too small. | |
| 195 // TODO(estade): by cutting out parts of ninebox, we lose the smooth | |
| 196 // horizontal or vertical transition. This isn't very noticeable, but we may | |
| 197 // need to address it by using a separate shadow layer for each ShadowValue, | |
| 198 // by adjusting the shadow for very small windows, or other means. | |
|
James Cook
2016/12/09 19:40:13
Aside: I vaguely recall from long ago that we deci
Evan Stade
2016/12/09 21:09:18
I ran into this problem for the message center bub
| |
| 199 aperture.Inset(gfx::Insets(border_y, border_x, border_h - border_y, | |
| 200 border_w - border_x)); | |
| 201 shadow_layer_->UpdateNinePatchLayerAperture(aperture); | |
| 196 } | 202 } |
| 197 | 203 |
| 198 int Shadow::ElevationForStyle() { | 204 int Shadow::ElevationForStyle() { |
| 199 switch (style_) { | 205 switch (style_) { |
| 200 case STYLE_ACTIVE: | 206 case STYLE_ACTIVE: |
| 201 return 24; | 207 return 24; |
| 202 case STYLE_INACTIVE: | 208 case STYLE_INACTIVE: |
| 203 return 8; | 209 return 8; |
| 204 case STYLE_SMALL: | 210 case STYLE_SMALL: |
| 205 return 6; | 211 return 6; |
| 206 } | 212 } |
| 207 NOTREACHED(); | 213 NOTREACHED(); |
| 208 return 0; | 214 return 0; |
| 209 } | 215 } |
| 210 | 216 |
| 211 } // namespace wm | 217 } // namespace wm |
| OLD | NEW |