| 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" | |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
| 8 #include "ui/aura/window.h" |
| 9 #include "ui/aura/window_property.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
| 11 #include "ui/compositor/scoped_layer_animation_settings.h" | 12 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 12 #include "ui/resources/grit/ui_resources.h" | 13 #include "ui/resources/grit/ui_resources.h" |
| 13 | 14 |
| 15 DECLARE_WINDOW_PROPERTY_TYPE(ash::mus::Shadow*); |
| 16 |
| 14 namespace ash { | 17 namespace ash { |
| 15 namespace mus { | 18 namespace mus { |
| 19 namespace { |
| 16 | 20 |
| 17 namespace { | 21 DEFINE_WINDOW_PROPERTY_KEY(Shadow*, kShadowProperty, nullptr); |
| 18 | 22 |
| 19 // The opacity used for active shadow when animating between | 23 // The opacity used for active shadow when animating between |
| 20 // inactive/active shadow. | 24 // inactive/active shadow. |
| 21 const float kInactiveShadowAnimationOpacity = 0.2f; | 25 const float kInactiveShadowAnimationOpacity = 0.2f; |
| 22 | 26 |
| 23 // Shadow aperture for different styles. | 27 // Shadow aperture for different styles. |
| 24 // Note that this may be greater than interior inset to allow shadows with | 28 // Note that this may be greater than interior inset to allow shadows with |
| 25 // curved corners that extend inwards beyond a window's borders. | 29 // curved corners that extend inwards beyond a window's borders. |
| 26 const int kActiveInteriorAperture = 134; | 30 const int kActiveInteriorAperture = 134; |
| 27 const int kInactiveInteriorAperture = 134; | 31 const int kInactiveInteriorAperture = 134; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 50 } | 54 } |
| 51 return 0; | 55 return 0; |
| 52 } | 56 } |
| 53 | 57 |
| 54 } // namespace | 58 } // namespace |
| 55 | 59 |
| 56 Shadow::Shadow() : style_(STYLE_ACTIVE), interior_inset_(0), window_(nullptr) {} | 60 Shadow::Shadow() : style_(STYLE_ACTIVE), interior_inset_(0), window_(nullptr) {} |
| 57 | 61 |
| 58 Shadow::~Shadow() { | 62 Shadow::~Shadow() { |
| 59 if (window_) { | 63 if (window_) { |
| 60 SetShadow(window_, nullptr); | 64 window_->ClearProperty(kShadowProperty); |
| 61 window_->RemoveObserver(this); | 65 window_->RemoveObserver(this); |
| 62 } | 66 } |
| 63 } | 67 } |
| 64 | 68 |
| 65 void Shadow::Init(Style style) { | 69 void Shadow::Init(Style style) { |
| 66 style_ = style; | 70 style_ = style; |
| 67 | 71 |
| 68 layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN)); | 72 layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN)); |
| 69 shadow_layer_.reset(new ui::Layer(ui::LAYER_NINE_PATCH)); | 73 shadow_layer_.reset(new ui::Layer(ui::LAYER_NINE_PATCH)); |
| 70 layer()->Add(shadow_layer_.get()); | 74 layer()->Add(shadow_layer_.get()); |
| 71 | 75 |
| 72 UpdateImagesForStyle(); | 76 UpdateImagesForStyle(); |
| 73 shadow_layer_->set_name("Shadow"); | 77 shadow_layer_->set_name("Shadow"); |
| 74 shadow_layer_->SetVisible(true); | 78 shadow_layer_->SetVisible(true); |
| 75 shadow_layer_->SetFillsBoundsOpaquely(false); | 79 shadow_layer_->SetFillsBoundsOpaquely(false); |
| 76 } | 80 } |
| 77 | 81 |
| 78 // static | 82 // static |
| 83 Shadow* Shadow::Get(aura::Window* window) { |
| 84 return window->GetProperty(kShadowProperty); |
| 85 } |
| 86 |
| 87 // static |
| 79 int Shadow::GetInteriorInsetForStyle(Shadow::Style style) { | 88 int Shadow::GetInteriorInsetForStyle(Shadow::Style style) { |
| 80 switch (style) { | 89 switch (style) { |
| 81 case Shadow::STYLE_ACTIVE: | 90 case Shadow::STYLE_ACTIVE: |
| 82 return kActiveInteriorInset; | 91 return kActiveInteriorInset; |
| 83 case Shadow::STYLE_INACTIVE: | 92 case Shadow::STYLE_INACTIVE: |
| 84 return kInactiveInteriorInset; | 93 return kInactiveInteriorInset; |
| 85 case Shadow::STYLE_SMALL: | 94 case Shadow::STYLE_SMALL: |
| 86 return kSmallInteriorInset; | 95 return kSmallInteriorInset; |
| 87 } | 96 } |
| 88 return 0; | 97 return 0; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // The opacity will be reset to 1.0f when animation is completed. | 146 // The opacity will be reset to 1.0f when animation is completed. |
| 138 shadow_layer_->SetOpacity(kInactiveShadowAnimationOpacity); | 147 shadow_layer_->SetOpacity(kInactiveShadowAnimationOpacity); |
| 139 break; | 148 break; |
| 140 default: | 149 default: |
| 141 NOTREACHED() << "Unhandled style " << style_; | 150 NOTREACHED() << "Unhandled style " << style_; |
| 142 break; | 151 break; |
| 143 } | 152 } |
| 144 } | 153 } |
| 145 } | 154 } |
| 146 | 155 |
| 147 void Shadow::Install(ui::Window* window) { | 156 void Shadow::Install(aura::Window* window) { |
| 148 SetShadow(window, this); | 157 window->SetProperty(kShadowProperty, this); |
| 149 window_ = window; | 158 window_ = window; |
| 150 window_->AddObserver(this); | 159 window_->AddObserver(this); |
| 151 } | 160 } |
| 152 | 161 |
| 153 void Shadow::OnImplicitAnimationsCompleted() { | 162 void Shadow::OnImplicitAnimationsCompleted() { |
| 154 // If we just finished going inactive, switch images. This doesn't cause | 163 // If we just finished going inactive, switch images. This doesn't cause |
| 155 // a visual pop because the inactive image opacity is so low. | 164 // a visual pop because the inactive image opacity is so low. |
| 156 if (style_ == STYLE_INACTIVE) { | 165 if (style_ == STYLE_INACTIVE) { |
| 157 UpdateImagesForStyle(); | 166 UpdateImagesForStyle(); |
| 158 // Opacity is baked into inactive image, so set fully opaque. | 167 // Opacity is baked into inactive image, so set fully opaque. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // The content bounds in the shadow's layer space are offsetted by | 218 // The content bounds in the shadow's layer space are offsetted by |
| 210 // |interior_inset_|. The occlusion area also has to be shrunk to allow | 219 // |interior_inset_|. The occlusion area also has to be shrunk to allow |
| 211 // rounded corners overdrawing on top of the window's content. | 220 // rounded corners overdrawing on top of the window's content. |
| 212 gfx::Rect content_bounds(interior_inset_ + kRoundedCornerRadius, | 221 gfx::Rect content_bounds(interior_inset_ + kRoundedCornerRadius, |
| 213 interior_inset_ + kRoundedCornerRadius, | 222 interior_inset_ + kRoundedCornerRadius, |
| 214 content_bounds_.width() - 2 * kRoundedCornerRadius, | 223 content_bounds_.width() - 2 * kRoundedCornerRadius, |
| 215 content_bounds_.height() - 2 * kRoundedCornerRadius); | 224 content_bounds_.height() - 2 * kRoundedCornerRadius); |
| 216 shadow_layer_->UpdateNinePatchOcclusion(content_bounds); | 225 shadow_layer_->UpdateNinePatchOcclusion(content_bounds); |
| 217 } | 226 } |
| 218 | 227 |
| 219 void Shadow::OnWindowDestroyed(ui::Window* window) { | 228 void Shadow::OnWindowDestroyed(aura::Window* window) { |
| 220 DCHECK_EQ(window_, window); | 229 DCHECK_EQ(window_, window); |
| 221 window_ = nullptr; | 230 window_ = nullptr; |
| 222 } | 231 } |
| 223 | 232 |
| 224 } // namespace mus | 233 } // namespace mus |
| 225 } // namespace ash | 234 } // namespace ash |
| OLD | NEW |