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

Side by Side Diff: chrome/browser/ui/views/autofill/save_card_bubble_views.cc

Issue 1396923003: Autofill: Replace "save credit card" infobar with a bubble (Views only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change object lifecycles + add interface classes. Created 5 years, 2 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h"
9 #include "grit/components_strings.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/views/bubble/bubble_frame_view.h"
12 #include "ui/views/controls/button/blue_button.h"
13 #include "ui/views/controls/button/label_button.h"
14 #include "ui/views/layout/grid_layout.h"
15 #include "ui/views/layout/layout_constants.h"
16
17 using views::GridLayout;
18
19 namespace {
20
21 // Fixed width of the column holding the message text.
22 const int kWidthOfMessageText = 375;
23
24 } // namespace
25
26 namespace autofill {
27
28 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
29 content::WebContents* web_contents,
30 SaveCardBubbleController* controller)
31 : ManagedFullScreenBubbleDelegateView(anchor_view, web_contents),
32 controller_(controller),
33 save_button_(nullptr),
34 cancel_button_(nullptr) {
35 views::BubbleDelegateView::CreateBubble(this);
36 }
37
38 SaveCardBubbleViews::~SaveCardBubbleViews() {}
39
40 void SaveCardBubbleViews::Show() {
41 GetWidget()->Show();
42 }
43
44 void SaveCardBubbleViews::Close() {
45 GetWidget()->Close();
46 }
47
48 void SaveCardBubbleViews::ControllerGone() {
49 controller_ = nullptr;
50 GetWidget()->Close();
51 }
52
53 views::View* SaveCardBubbleViews::GetInitiallyFocusedView() {
54 return save_button_;
55 }
56
57 base::string16 SaveCardBubbleViews::GetWindowTitle() const {
58 return l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_TITLE_LOCAL);
59 }
60
61 bool SaveCardBubbleViews::ShouldShowWindowTitle() const {
62 return true;
63 }
64
65 void SaveCardBubbleViews::WindowClosing() {
66 if (controller_)
67 controller_->OnBubbleClosed();
68 }
69
70 void SaveCardBubbleViews::ButtonPressed(views::Button* sender,
71 const ui::Event& event) {
72 if (sender == save_button_) {
73 controller_->OnSaveButton();
74 } else {
75 DCHECK(sender == cancel_button_);
hcarmona 2015/10/16 21:16:35 DCHECK_EQ
bondd 2015/10/22 02:15:17 Done.
76 controller_->OnCancelButton();
77 }
78 GetWidget()->Close();
79 }
80
81 void SaveCardBubbleViews::Init() {
82 enum {
83 COLUMN_SET_ID_MESSAGE,
84 COLUMN_SET_ID_BUTTONS,
85 };
86
87 GridLayout* layout = new GridLayout(this);
88 SetLayoutManager(layout);
89
90 // Set up ColumnSet that will contain the full-width message text.
91 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
92 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE);
93 cs->AddPaddingColumn(0, horizontal_inset);
94 // TODO(bondd): Current dialog layout has no message text, but future layouts
95 // will. This padding column is used until then to set the dialog width.
96 cs->AddPaddingColumn(1, kWidthOfMessageText);
97 cs->AddPaddingColumn(0, horizontal_inset);
98
99 // Set up ColumnSet that will contain the buttons.
100 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS);
101 cs->AddPaddingColumn(1, 0);
102 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
103 GridLayout::USE_PREF, 0, 0);
104 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
105 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
106 GridLayout::USE_PREF, 0, 0);
107 cs->AddPaddingColumn(0, horizontal_inset);
108
109 // Create accept button and add it to layout.
110 save_button_ = new views::BlueButton(
111 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT));
112 save_button_->SetIsDefault(true);
113 layout->StartRow(0, COLUMN_SET_ID_BUTTONS);
114 layout->AddView(save_button_);
115
116 // Create cancel button and add it to layout.
117 cancel_button_ = new views::LabelButton(
118 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY));
119 cancel_button_->SetStyle(views::Button::STYLE_BUTTON);
120 layout->AddView(cancel_button_);
121 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
122
123 set_margins(gfx::Insets(1, 0, 1, 0));
124 Layout();
125 }
126
127 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698