Commit 176a3f20 authored by Elaine Chien's avatar Elaine Chien Committed by Commit Bot

remove set_owned_by_client() in view_stack

Bug: 1044687
Change-Id: Iaa6e84f3d71382a0f783ddabcdb1383203f473e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391900Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Elaine Chien <elainec@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804994}
parent 8339dba5
...@@ -41,17 +41,16 @@ void ViewStack::Push(std::unique_ptr<views::View> view, bool animate) { ...@@ -41,17 +41,16 @@ void ViewStack::Push(std::unique_ptr<views::View> view, bool animate) {
view->SetBoundsRect(destination); view->SetBoundsRect(destination);
} }
view->Layout(); view->Layout();
AddChildView(view.get());
view->set_owned_by_client();
// Add the new view to the stack so it can be popped later when navigating // Add the new view to the stack so it can be popped later when navigating
// back to the previous screen. // back to the previous screen.
stack_.push_back(std::move(view)); stack_.push_back(view.get());
AddChildView(std::move(view));
if (animate) { if (animate) {
// Animate the new view to be right on top of this one. // Animate the new view to be right on top of this one.
slide_in_animator_->AnimateViewTo(stack_.back().get(), destination); slide_in_animator_->AnimateViewTo(stack_.back(), destination);
} else { } else {
// This is handled by the post-animation callback in the animated case, so // This is handled by the post-animation callback in the animated case, so
// trigger it synchronously here. // trigger it synchronously here.
...@@ -70,8 +69,9 @@ void ViewStack::Pop(bool animate) { ...@@ -70,8 +69,9 @@ void ViewStack::Pop(bool animate) {
if (animate) { if (animate) {
gfx::Rect destination = bounds(); gfx::Rect destination = bounds();
destination.set_origin(gfx::Point(width(), 0)); destination.set_origin(gfx::Point(width(), 0));
slide_out_animator_->AnimateViewTo(stack_.back().get(), destination); slide_out_animator_->AnimateViewTo(stack_.back(), destination);
} else { } else {
RemoveChildViewT(stack_.back());
stack_.pop_back(); stack_.pop_back();
} }
} }
...@@ -80,6 +80,13 @@ void ViewStack::PopMany(int n, bool animate) { ...@@ -80,6 +80,13 @@ void ViewStack::PopMany(int n, bool animate) {
DCHECK_LT(static_cast<size_t>(n), size()); // The stack can never be empty. DCHECK_LT(static_cast<size_t>(n), size()); // The stack can never be empty.
size_t pre_size = stack_.size(); size_t pre_size = stack_.size();
// Remove N - 1 child views from the hierarchy now, the last one will be
// removed when its animation completes
for (unsigned i = pre_size - n; i < (pre_size - 1); i++) {
RemoveChildViewT(stack_.at(i));
}
// Erase N - 1 elements now, the last one will be erased when its animation // Erase N - 1 elements now, the last one will be erased when its animation
// completes // completes
stack_.erase(stack_.end() - n, stack_.end() - 1); stack_.erase(stack_.end() - n, stack_.end() - 1);
...@@ -122,9 +129,9 @@ void ViewStack::UpdateAnimatorBounds( ...@@ -122,9 +129,9 @@ void ViewStack::UpdateAnimatorBounds(
// If an animator is currently animating, figure out which views and update // If an animator is currently animating, figure out which views and update
// their target bounds. // their target bounds.
if (animator->IsAnimating()) { if (animator->IsAnimating()) {
for (auto& view : stack_) { for (auto* view : stack_) {
if (animator->IsAnimating(view.get())) { if (animator->IsAnimating(view)) {
animator->SetTargetBounds(view.get(), target); animator->SetTargetBounds(view, target);
} }
} }
} }
...@@ -132,6 +139,7 @@ void ViewStack::UpdateAnimatorBounds( ...@@ -132,6 +139,7 @@ void ViewStack::UpdateAnimatorBounds(
void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
if (animator == slide_out_animator_.get()) { if (animator == slide_out_animator_.get()) {
RemoveChildViewT(stack_.back());
stack_.pop_back(); stack_.pop_back();
DCHECK(!stack_.empty()) << "State stack should never be empty"; DCHECK(!stack_.empty()) << "State stack should never be empty";
} else if (animator == slide_in_animator_.get()) { } else if (animator == slide_in_animator_.get()) {
......
...@@ -25,8 +25,7 @@ class ViewStack : public views::BoundsAnimatorObserver, ...@@ -25,8 +25,7 @@ class ViewStack : public views::BoundsAnimatorObserver,
ViewStack(); ViewStack();
~ViewStack() override; ~ViewStack() override;
// Adds a view to the stack and starts animating it in from the right. This // Adds a view to the stack and starts animating it in from the right.
// takes ownership of the view and calls set_owned_by_client() on it.
// If |animate| is false, the view will simply be added to the hierarchy // If |animate| is false, the view will simply be added to the hierarchy
// without the sliding animation. // without the sliding animation.
void Push(std::unique_ptr<views::View> state, bool animate); void Push(std::unique_ptr<views::View> state, bool animate);
...@@ -53,7 +52,7 @@ class ViewStack : public views::BoundsAnimatorObserver, ...@@ -53,7 +52,7 @@ class ViewStack : public views::BoundsAnimatorObserver,
void OnBoundsChanged(const gfx::Rect& previous_bounds) override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
// Returns the top state of the stack. // Returns the top state of the stack.
views::View* top() { return stack_.back().get(); } views::View* top() { return stack_.back(); }
private: private:
FRIEND_TEST_ALL_PREFIXES( FRIEND_TEST_ALL_PREFIXES(
...@@ -80,7 +79,7 @@ class ViewStack : public views::BoundsAnimatorObserver, ...@@ -80,7 +79,7 @@ class ViewStack : public views::BoundsAnimatorObserver,
// Should be the last member, because views need to be destroyed before other // Should be the last member, because views need to be destroyed before other
// members, and members are destroyed in reverse order of their creation. // members, and members are destroyed in reverse order of their creation.
std::vector<std::unique_ptr<views::View>> stack_; std::vector<views::View*> stack_;
DISALLOW_COPY_AND_ASSIGN(ViewStack); DISALLOW_COPY_AND_ASSIGN(ViewStack);
}; };
......
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