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 "mash/wm/shadow.h" | 5 #include "ash/mus/shadow.h" |
6 | 6 |
7 #include "mash/wm/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" |
11 #include "ui/compositor/scoped_layer_animation_settings.h" | 11 #include "ui/compositor/scoped_layer_animation_settings.h" |
12 #include "ui/resources/grit/ui_resources.h" | 12 #include "ui/resources/grit/ui_resources.h" |
13 | 13 |
14 namespace mash { | 14 namespace ash { |
15 namespace wm { | 15 namespace mus { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // The opacity used for active shadow when animating between | 19 // The opacity used for active shadow when animating between |
20 // inactive/active shadow. | 20 // inactive/active shadow. |
21 const float kInactiveShadowAnimationOpacity = 0.2f; | 21 const float kInactiveShadowAnimationOpacity = 0.2f; |
22 | 22 |
23 // Shadow aperture for different styles. | 23 // Shadow aperture for different styles. |
24 // Note that this may be greater than interior inset to allow shadows with | 24 // Note that this may be greater than interior inset to allow shadows with |
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 // Duration for opacity animation in milliseconds. | 35 // Duration for opacity animation in milliseconds. |
36 const int kShadowAnimationDurationMs = 100; | 36 const int kShadowAnimationDurationMs = 100; |
37 | 37 |
38 int GetShadowApertureForStyle(wm::Shadow::Style style) { | 38 int GetShadowApertureForStyle(Shadow::Style style) { |
39 switch (style) { | 39 switch (style) { |
40 case wm::Shadow::STYLE_ACTIVE: | 40 case Shadow::STYLE_ACTIVE: |
41 return kActiveInteriorAperture; | 41 return kActiveInteriorAperture; |
42 case wm::Shadow::STYLE_INACTIVE: | 42 case Shadow::STYLE_INACTIVE: |
43 return kInactiveInteriorAperture; | 43 return kInactiveInteriorAperture; |
44 case wm::Shadow::STYLE_SMALL: | 44 case Shadow::STYLE_SMALL: |
45 return kSmallInteriorAperture; | 45 return kSmallInteriorAperture; |
46 } | 46 } |
47 return 0; | 47 return 0; |
48 } | 48 } |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 Shadow::Shadow() : style_(STYLE_ACTIVE), interior_inset_(0), window_(nullptr) { | 52 Shadow::Shadow() : style_(STYLE_ACTIVE), interior_inset_(0), window_(nullptr) {} |
53 } | |
54 | 53 |
55 Shadow::~Shadow() { | 54 Shadow::~Shadow() { |
56 if (window_) { | 55 if (window_) { |
57 SetShadow(window_, nullptr); | 56 SetShadow(window_, nullptr); |
58 window_->RemoveObserver(this); | 57 window_->RemoveObserver(this); |
59 } | 58 } |
60 } | 59 } |
61 | 60 |
62 void Shadow::Init(Style style) { | 61 void Shadow::Init(Style style) { |
63 style_ = style; | 62 style_ = style; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // The opacity will be reset to 1.0f when animation is completed. | 133 // The opacity will be reset to 1.0f when animation is completed. |
135 shadow_layer_->SetOpacity(kInactiveShadowAnimationOpacity); | 134 shadow_layer_->SetOpacity(kInactiveShadowAnimationOpacity); |
136 break; | 135 break; |
137 default: | 136 default: |
138 NOTREACHED() << "Unhandled style " << style_; | 137 NOTREACHED() << "Unhandled style " << style_; |
139 break; | 138 break; |
140 } | 139 } |
141 } | 140 } |
142 } | 141 } |
143 | 142 |
144 void Shadow::Install(mus::Window* window) { | 143 void Shadow::Install(::mus::Window* window) { |
145 SetShadow(window, this); | 144 SetShadow(window, this); |
146 window_ = window; | 145 window_ = window; |
147 window_->AddObserver(this); | 146 window_->AddObserver(this); |
148 } | 147 } |
149 | 148 |
150 void Shadow::OnImplicitAnimationsCompleted() { | 149 void Shadow::OnImplicitAnimationsCompleted() { |
151 // If we just finished going inactive, switch images. This doesn't cause | 150 // If we just finished going inactive, switch images. This doesn't cause |
152 // a visual pop because the inactive image opacity is so low. | 151 // a visual pop because the inactive image opacity is so low. |
153 if (style_ == STYLE_INACTIVE) { | 152 if (style_ == STYLE_INACTIVE) { |
154 UpdateImagesForStyle(); | 153 UpdateImagesForStyle(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 layer_bounds.Inset(-interior_inset_, -interior_inset_); | 188 layer_bounds.Inset(-interior_inset_, -interior_inset_); |
190 layer()->SetBounds(layer_bounds); | 189 layer()->SetBounds(layer_bounds); |
191 shadow_layer_->SetBounds(gfx::Rect(layer_bounds.size())); | 190 shadow_layer_->SetBounds(gfx::Rect(layer_bounds.size())); |
192 | 191 |
193 // Update the shadow aperture and border for style. Note that border is in | 192 // Update the shadow aperture and border for style. Note that border is in |
194 // layer space and it cannot exceed the bounds of the layer. | 193 // layer space and it cannot exceed the bounds of the layer. |
195 int aperture = GetShadowApertureForStyle(style_); | 194 int aperture = GetShadowApertureForStyle(style_); |
196 int aperture_x = std::min(aperture, layer_bounds.width() / 2); | 195 int aperture_x = std::min(aperture, layer_bounds.width() / 2); |
197 int aperture_y = std::min(aperture, layer_bounds.height() / 2); | 196 int aperture_y = std::min(aperture, layer_bounds.height() / 2); |
198 shadow_layer_->UpdateNinePatchLayerAperture( | 197 shadow_layer_->UpdateNinePatchLayerAperture( |
199 gfx::Rect(aperture_x, aperture_y, | 198 gfx::Rect(aperture_x, aperture_y, image_size_.width() - aperture_x * 2, |
200 image_size_.width() - aperture_x * 2, | |
201 image_size_.height() - aperture_y * 2)); | 199 image_size_.height() - aperture_y * 2)); |
202 shadow_layer_->UpdateNinePatchLayerBorder( | 200 shadow_layer_->UpdateNinePatchLayerBorder( |
203 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2)); | 201 gfx::Rect(aperture_x, aperture_y, aperture_x * 2, aperture_y * 2)); |
204 } | 202 } |
205 | 203 |
206 void Shadow::OnWindowDestroyed(mus::Window* window) { | 204 void Shadow::OnWindowDestroyed(::mus::Window* window) { |
207 DCHECK_EQ(window_, window); | 205 DCHECK_EQ(window_, window); |
208 window_ = nullptr; | 206 window_ = nullptr; |
209 } | 207 } |
210 | 208 |
211 } // namespace wm | 209 } // namespace mus |
212 } // namespace mash | 210 } // namespace ash |
OLD | NEW |