Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/views/payments/view_stack.h" | 5 #include "chrome/browser/ui/views/payments/view_stack.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 } else { | 42 } else { |
| 43 view->SetBoundsRect(destination); | 43 view->SetBoundsRect(destination); |
| 44 view->Layout(); | 44 view->Layout(); |
| 45 AddChildView(view.get()); | 45 AddChildView(view.get()); |
| 46 } | 46 } |
| 47 | 47 |
| 48 view->set_owned_by_client(); | 48 view->set_owned_by_client(); |
| 49 // Add the new view to the stack so it can be popped later when navigating | 49 // Add the new view to the stack so it can be popped later when navigating |
| 50 // back to the previous screen. | 50 // back to the previous screen. |
| 51 stack_.push_back(std::move(view)); | 51 stack_.push_back(std::move(view)); |
| 52 RequestFocus(); | |
|
Mathieu
2017/05/02 13:16:10
I'm curious, does this still work even though the
anthonyvd
2017/05/02 13:43:32
Yeah, the other view gets focused right away but d
| |
| 52 } | 53 } |
| 53 | 54 |
| 54 void ViewStack::Pop() { | 55 void ViewStack::Pop() { |
| 55 gfx::Rect destination = bounds(); | 56 gfx::Rect destination = bounds(); |
| 56 destination.set_origin(gfx::Point(width(), 0)); | 57 destination.set_origin(gfx::Point(width(), 0)); |
| 57 | 58 |
| 58 slide_out_animator_->AnimateViewTo( | 59 slide_out_animator_->AnimateViewTo( |
| 59 stack_.back().get(), destination); | 60 stack_.back().get(), destination); |
| 60 } | 61 } |
| 61 | 62 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 88 gfx::Rect in_new_destination = bounds(); | 89 gfx::Rect in_new_destination = bounds(); |
| 89 in_new_destination.set_origin(gfx::Point(0, 0)); | 90 in_new_destination.set_origin(gfx::Point(0, 0)); |
| 90 UpdateAnimatorBounds(slide_in_animator_.get(), in_new_destination); | 91 UpdateAnimatorBounds(slide_in_animator_.get(), in_new_destination); |
| 91 | 92 |
| 92 | 93 |
| 93 gfx::Rect out_new_destination = bounds(); | 94 gfx::Rect out_new_destination = bounds(); |
| 94 out_new_destination.set_origin(gfx::Point(width(), 0)); | 95 out_new_destination.set_origin(gfx::Point(width(), 0)); |
| 95 UpdateAnimatorBounds(slide_out_animator_.get(), out_new_destination); | 96 UpdateAnimatorBounds(slide_out_animator_.get(), out_new_destination); |
| 96 } | 97 } |
| 97 | 98 |
| 99 void ViewStack::RequestFocus() { | |
| 100 // The view can only be focused if it has a widget already. It's possible that | |
| 101 // this isn't the case if some views are pushed before the stack is added to a | |
| 102 // hierarchy that has a widget. | |
| 103 if (top()->GetWidget()) | |
| 104 top()->RequestFocus(); | |
| 105 } | |
| 106 | |
| 98 void ViewStack::UpdateAnimatorBounds( | 107 void ViewStack::UpdateAnimatorBounds( |
| 99 views::BoundsAnimator* animator, const gfx::Rect& target) { | 108 views::BoundsAnimator* animator, const gfx::Rect& target) { |
| 100 // If an animator is currently animating, figure out which views and update | 109 // If an animator is currently animating, figure out which views and update |
| 101 // their target bounds. | 110 // their target bounds. |
| 102 if (animator->IsAnimating()) { | 111 if (animator->IsAnimating()) { |
| 103 for (auto& view : stack_) { | 112 for (auto& view : stack_) { |
| 104 if (animator->IsAnimating(view.get())) { | 113 if (animator->IsAnimating(view.get())) { |
| 105 animator->SetTargetBounds(view.get(), target); | 114 animator->SetTargetBounds(view.get(), target); |
| 106 } | 115 } |
| 107 } | 116 } |
| 108 } | 117 } |
| 109 } | 118 } |
| 110 | 119 |
| 111 void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 120 void ViewStack::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
| 112 // This should only be called from slide_out_animator_ when the views going | 121 // This should only be called from slide_out_animator_ when the views going |
| 113 // out are done animating. | 122 // out are done animating. |
| 114 DCHECK_EQ(animator, slide_out_animator_.get()); | 123 DCHECK_EQ(animator, slide_out_animator_.get()); |
| 115 | 124 |
| 116 stack_.pop_back(); | 125 stack_.pop_back(); |
| 117 DCHECK(!stack_.empty()) << "State stack should never be empty"; | 126 DCHECK(!stack_.empty()) << "State stack should never be empty"; |
| 127 RequestFocus(); | |
| 118 } | 128 } |
| OLD | NEW |