OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mus/shadow.h" | 5 #include "ash/mus/shadow.h" |
6 | 6 |
7 #include "ash/mus/property_util.h" | 7 #include "ash/mus/property_util.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // curved corners that extend inwards beyond a window's borders. | 25 // curved corners that extend inwards beyond a window's borders. |
26 const int kActiveInteriorAperture = 134; | 26 const int kActiveInteriorAperture = 134; |
27 const int kInactiveInteriorAperture = 134; | 27 const int kInactiveInteriorAperture = 134; |
28 const int kSmallInteriorAperture = 9; | 28 const int kSmallInteriorAperture = 9; |
29 | 29 |
30 // Interior inset for different styles. | 30 // Interior inset for different styles. |
31 const int kActiveInteriorInset = 64; | 31 const int kActiveInteriorInset = 64; |
32 const int kInactiveInteriorInset = 64; | 32 const int kInactiveInteriorInset = 64; |
33 const int kSmallInteriorInset = 4; | 33 const int kSmallInteriorInset = 4; |
34 | 34 |
| 35 // Rounded corners are overdrawn on top of the window's content layer, |
| 36 // we need to exclude them from the occlusion area. |
| 37 const int kRoundedCornerRadius = 2; |
| 38 |
35 // Duration for opacity animation in milliseconds. | 39 // Duration for opacity animation in milliseconds. |
36 const int kShadowAnimationDurationMs = 100; | 40 const int kShadowAnimationDurationMs = 100; |
37 | 41 |
38 int GetShadowApertureForStyle(Shadow::Style style) { | 42 int GetShadowApertureForStyle(Shadow::Style style) { |
39 switch (style) { | 43 switch (style) { |
40 case Shadow::STYLE_ACTIVE: | 44 case Shadow::STYLE_ACTIVE: |
41 return kActiveInteriorAperture; | 45 return kActiveInteriorAperture; |
42 case Shadow::STYLE_INACTIVE: | 46 case Shadow::STYLE_INACTIVE: |
43 return kInactiveInteriorAperture; | 47 return kInactiveInteriorAperture; |
44 case Shadow::STYLE_SMALL: | 48 case Shadow::STYLE_SMALL: |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 gfx::Rect layer_bounds = content_bounds_; | 191 gfx::Rect layer_bounds = content_bounds_; |
188 layer_bounds.Inset(-interior_inset_, -interior_inset_); | 192 layer_bounds.Inset(-interior_inset_, -interior_inset_); |
189 layer()->SetBounds(layer_bounds); | 193 layer()->SetBounds(layer_bounds); |
190 shadow_layer_->SetBounds(gfx::Rect(layer_bounds.size())); | 194 shadow_layer_->SetBounds(gfx::Rect(layer_bounds.size())); |
191 | 195 |
192 // Update the shadow aperture and border for style. Note that border is in | 196 // Update the shadow aperture and border for style. Note that border is in |
193 // layer space and it cannot exceed the bounds of the layer. | 197 // layer space and it cannot exceed the bounds of the layer. |
194 int aperture = GetShadowApertureForStyle(style_); | 198 int aperture = GetShadowApertureForStyle(style_); |
195 int aperture_x = std::min(aperture, layer_bounds.width() / 2); | 199 int aperture_x = std::min(aperture, layer_bounds.width() / 2); |
196 int aperture_y = std::min(aperture, layer_bounds.height() / 2); | 200 int aperture_y = std::min(aperture, layer_bounds.height() / 2); |
197 shadow_layer_->UpdateNinePatchLayerAperture( | 201 gfx::Rect aperture_rect(aperture_x, aperture_y, |
198 gfx::Rect(aperture_x, aperture_y, image_size_.width() - aperture_x * 2, | 202 image_size_.width() - aperture_x * 2, |
199 image_size_.height() - aperture_y * 2)); | 203 image_size_.height() - aperture_y * 2); |
| 204 |
| 205 shadow_layer_->UpdateNinePatchLayerAperture(aperture_rect); |
200 shadow_layer_->UpdateNinePatchLayerBorder( | 206 shadow_layer_->UpdateNinePatchLayerBorder( |
201 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2)); | 207 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2)); |
| 208 |
| 209 // The content bounds in the shadow's layer space are offsetted by |
| 210 // |interior_inset_|. The occlusion area also has to be shrinked to |
| 211 // allow rounded corners overdrawing on top of the window's content. |
| 212 gfx::Rect content_bounds( |
| 213 content_bounds_.x() + interior_inset_ + kRoundedCornerRadius, |
| 214 content_bounds_.y() + interior_inset_ + kRoundedCornerRadius, |
| 215 content_bounds_.width() - 2 * kRoundedCornerRadius, |
| 216 content_bounds_.height() - 2 * kRoundedCornerRadius); |
| 217 shadow_layer_->UpdateNinePatchOcclusion(content_bounds); |
202 } | 218 } |
203 | 219 |
204 void Shadow::OnWindowDestroyed(::ui::Window* window) { | 220 void Shadow::OnWindowDestroyed(::ui::Window* window) { |
205 DCHECK_EQ(window_, window); | 221 DCHECK_EQ(window_, window); |
206 window_ = nullptr; | 222 window_ = nullptr; |
207 } | 223 } |
208 | 224 |
209 } // namespace mus | 225 } // namespace mus |
210 } // namespace ash | 226 } // namespace ash |
OLD | NEW |