| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 void Shadow::RecreateShadowLayer() { | 126 void Shadow::RecreateShadowLayer() { |
| 127 shadow_layer_.reset(new ui::Layer(ui::LAYER_NINE_PATCH)); | 127 shadow_layer_.reset(new ui::Layer(ui::LAYER_NINE_PATCH)); |
| 128 shadow_layer_->set_name("Shadow"); | 128 shadow_layer_->set_name("Shadow"); |
| 129 shadow_layer_->SetVisible(true); | 129 shadow_layer_->SetVisible(true); |
| 130 shadow_layer_->SetFillsBoundsOpaquely(false); | 130 shadow_layer_->SetFillsBoundsOpaquely(false); |
| 131 layer()->Add(shadow_layer_.get()); | 131 layer()->Add(shadow_layer_.get()); |
| 132 | 132 |
| 133 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); | 133 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); |
| 134 shadow_layer_->UpdateNinePatchLayerImage(details.ninebox_image); | 134 shadow_layer_->UpdateNinePatchLayerImage(details.ninebox_image); |
| 135 // The ninebox grid is defined in terms of the image size. The shadow blurs in | |
| 136 // both inward and outward directions from the edge of the contents, so the | |
| 137 // aperture goes further inside the image than the shadow margins (which | |
| 138 // represent exterior blur). | |
| 139 gfx::Rect aperture(details.ninebox_image.size()); | |
| 140 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) + | |
| 141 gfx::Insets(kRoundedCornerRadius); | |
| 142 aperture.Inset(blur_region); | |
| 143 shadow_layer_->UpdateNinePatchLayerAperture(aperture); | |
| 144 UpdateLayerBounds(); | 135 UpdateLayerBounds(); |
| 145 } | 136 } |
| 146 | 137 |
| 147 void Shadow::UpdateLayerBounds() { | 138 void Shadow::UpdateLayerBounds() { |
| 148 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); | 139 const ShadowDetails& details = GetDetailsForElevation(ElevationForStyle()); |
| 149 // Shadow margins are negative, so this expands outwards from | 140 // Shadow margins are negative, so this expands outwards from |
| 150 // |content_bounds_|. | 141 // |content_bounds_|. |
| 151 const gfx::Insets margins = gfx::ShadowValue::GetMargin(details.values); | 142 const gfx::Insets margins = gfx::ShadowValue::GetMargin(details.values); |
| 152 gfx::Rect new_layer_bounds = content_bounds_; | 143 gfx::Rect new_layer_bounds = content_bounds_; |
| 153 new_layer_bounds.Inset(margins); | 144 new_layer_bounds.Inset(margins); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // larger than the shadow layer. When the shadow layer is too small, shrink | 178 // larger than the shadow layer. When the shadow layer is too small, shrink |
| 188 // the dimensions proportionally. | 179 // the dimensions proportionally. |
| 189 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) + | 180 gfx::Insets blur_region = gfx::ShadowValue::GetBlurRegion(details.values) + |
| 190 gfx::Insets(kRoundedCornerRadius); | 181 gfx::Insets(kRoundedCornerRadius); |
| 191 int border_w = std::min(blur_region.width(), shadow_layer_bounds.width()); | 182 int border_w = std::min(blur_region.width(), shadow_layer_bounds.width()); |
| 192 int border_x = border_w * blur_region.left() / blur_region.width(); | 183 int border_x = border_w * blur_region.left() / blur_region.width(); |
| 193 int border_h = std::min(blur_region.height(), shadow_layer_bounds.height()); | 184 int border_h = std::min(blur_region.height(), shadow_layer_bounds.height()); |
| 194 int border_y = border_h * blur_region.top() / blur_region.height(); | 185 int border_y = border_h * blur_region.top() / blur_region.height(); |
| 195 shadow_layer_->UpdateNinePatchLayerBorder( | 186 shadow_layer_->UpdateNinePatchLayerBorder( |
| 196 gfx::Rect(border_x, border_y, border_w, border_h)); | 187 gfx::Rect(border_x, border_y, border_w, border_h)); |
| 188 |
| 189 // The ninebox grid is defined in terms of the image size. The shadow blurs in |
| 190 // both inward and outward directions from the edge of the contents, so the |
| 191 // aperture goes further inside the image than the shadow margins (which |
| 192 // represent exterior blur). |
| 193 gfx::Rect aperture(details.ninebox_image.size()); |
| 194 // The insets for the aperture are nominally |blur_region| but we need to |
| 195 // resize them if the contents are too small. |
| 196 // TODO(estade): by cutting out parts of ninebox, we lose the smooth |
| 197 // horizontal or vertical transition. This isn't very noticeable, but we may |
| 198 // need to address it by using a separate shadow layer for each ShadowValue, |
| 199 // by adjusting the shadow for very small windows, or other means. |
| 200 aperture.Inset(gfx::Insets(border_y, border_x, border_h - border_y, |
| 201 border_w - border_x)); |
| 202 shadow_layer_->UpdateNinePatchLayerAperture(aperture); |
| 197 } | 203 } |
| 198 | 204 |
| 199 int Shadow::ElevationForStyle() { | 205 int Shadow::ElevationForStyle() { |
| 200 switch (style_) { | 206 switch (style_) { |
| 201 case STYLE_ACTIVE: | 207 case STYLE_ACTIVE: |
| 202 return 24; | 208 return 24; |
| 203 case STYLE_INACTIVE: | 209 case STYLE_INACTIVE: |
| 204 return 8; | 210 return 8; |
| 205 case STYLE_SMALL: | 211 case STYLE_SMALL: |
| 206 return 6; | 212 return 6; |
| 207 } | 213 } |
| 208 NOTREACHED(); | 214 NOTREACHED(); |
| 209 return 0; | 215 return 0; |
| 210 } | 216 } |
| 211 | 217 |
| 212 } // namespace wm | 218 } // namespace wm |
| OLD | NEW |