Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/ui/views/payments/view_stack.cc

Issue 2853163002: [Web Payments] Implement proper focusing in Payment Request (Closed)
Patch Set: Address comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/payments/view_stack.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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();
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/view_stack.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698