Commit fc28da5f authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Fix shadow layer not being updated correctly when recreated.

BUG=988530
TEST=Manually

Change-Id: Ifbd2b8184490b14e146bb822791347de4b36a975
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724121
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682358}
parent 738e8998
...@@ -19,9 +19,9 @@ constexpr int kShadowAnimationDurationMs = 100; ...@@ -19,9 +19,9 @@ constexpr int kShadowAnimationDurationMs = 100;
} // namespace } // namespace
Shadow::Shadow() {} Shadow::Shadow() : shadow_layer_owner_(this) {}
Shadow::~Shadow() {} Shadow::~Shadow() = default;
void Shadow::Init(int elevation) { void Shadow::Init(int elevation) {
DCHECK_GE(elevation, 0); DCHECK_GE(elevation, 0);
...@@ -91,17 +91,33 @@ void Shadow::OnImplicitAnimationsCompleted() { ...@@ -91,17 +91,33 @@ void Shadow::OnImplicitAnimationsCompleted() {
UpdateLayerBounds(); UpdateLayerBounds();
} }
// -----------------------------------------------------------------------------
// Shadow::ShadowLayerOwner:
Shadow::ShadowLayerOwner::ShadowLayerOwner(Shadow* owner,
std::unique_ptr<Layer> layer)
: LayerOwner(std::move(layer)), owner_shadow_(owner) {}
Shadow::ShadowLayerOwner::~ShadowLayerOwner() = default;
std::unique_ptr<Layer> Shadow::ShadowLayerOwner::RecreateLayer() {
auto result = ui::LayerOwner::RecreateLayer();
// Now update the newly recreated shadow layer with the correct nine patch
// image details.
owner_shadow_->details_ = nullptr;
owner_shadow_->UpdateLayerBounds();
return result;
}
// -----------------------------------------------------------------------------
// Shadow:
void Shadow::RecreateShadowLayer() { void Shadow::RecreateShadowLayer() {
if (shadow_layer_owner_.OwnsLayer()) { shadow_layer_owner_.Reset(std::make_unique<ui::Layer>(ui::LAYER_NINE_PATCH));
shadow_layer_owner_.RecreateLayer();
} else {
shadow_layer_owner_.Reset(
std::make_unique<ui::Layer>(ui::LAYER_NINE_PATCH));
shadow_layer()->set_name("Shadow"); shadow_layer()->set_name("Shadow");
shadow_layer()->SetVisible(true); shadow_layer()->SetVisible(true);
shadow_layer()->SetFillsBoundsOpaquely(false); shadow_layer()->SetFillsBoundsOpaquely(false);
layer()->Add(shadow_layer()); layer()->Add(shadow_layer());
}
UpdateLayerBounds(); UpdateLayerBounds();
} }
......
...@@ -57,6 +57,23 @@ class Shadow : public ui::ImplicitAnimationObserver, public ui::LayerOwner { ...@@ -57,6 +57,23 @@ class Shadow : public ui::ImplicitAnimationObserver, public ui::LayerOwner {
void OnImplicitAnimationsCompleted() override; void OnImplicitAnimationsCompleted() override;
private: private:
// A shadow layer owner that correctly updates the nine patch layer details
// when it gets recreated.
class ShadowLayerOwner : public ui::LayerOwner {
public:
explicit ShadowLayerOwner(Shadow* owner,
std::unique_ptr<Layer> layer = nullptr);
~ShadowLayerOwner() override;
// ui::LayerOwner:
std::unique_ptr<Layer> RecreateLayer() override;
private:
Shadow* const owner_shadow_;
DISALLOW_COPY_AND_ASSIGN(ShadowLayerOwner);
};
// Updates the shadow layer and its image to reflect |desired_elevation_|. // Updates the shadow layer and its image to reflect |desired_elevation_|.
void RecreateShadowLayer(); void RecreateShadowLayer();
...@@ -82,7 +99,7 @@ class Shadow : public ui::ImplicitAnimationObserver, public ui::LayerOwner { ...@@ -82,7 +99,7 @@ class Shadow : public ui::ImplicitAnimationObserver, public ui::LayerOwner {
const gfx::ShadowDetails* details_ = nullptr; const gfx::ShadowDetails* details_ = nullptr;
// The owner of the actual shadow layer corresponding to a cc::NinePatchLayer. // The owner of the actual shadow layer corresponding to a cc::NinePatchLayer.
ui::LayerOwner shadow_layer_owner_; ShadowLayerOwner shadow_layer_owner_;
// When the elevation changes, the old shadow cross-fades with the new one. // When the elevation changes, the old shadow cross-fades with the new one.
// When non-null, this owns an old |shadow_layer()| that's being animated out. // When non-null, this owns an old |shadow_layer()| that's being animated out.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment