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

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

Issue 1407093007: Autofill: Add legal message footer to save credit card bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address estade@ comments for patch set 12. Created 5 years, 1 month 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/autofill/save_card_bubble_views.h" 5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
8 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" 9 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h"
9 #include "grit/components_strings.h" 10 #include "grit/components_strings.h"
10 #include "ui/base/l10n/l10n_util.h" 11 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/views/bubble/bubble_frame_view.h" 12 #include "ui/views/bubble/bubble_frame_view.h"
12 #include "ui/views/controls/button/blue_button.h" 13 #include "ui/views/controls/button/blue_button.h"
13 #include "ui/views/controls/button/label_button.h" 14 #include "ui/views/controls/button/label_button.h"
14 #include "ui/views/controls/link.h" 15 #include "ui/views/controls/link.h"
16 #include "ui/views/controls/styled_label.h"
17 #include "ui/views/layout/box_layout.h"
15 #include "ui/views/layout/grid_layout.h" 18 #include "ui/views/layout/grid_layout.h"
16 #include "ui/views/layout/layout_constants.h" 19 #include "ui/views/layout/layout_constants.h"
17 20
18 using views::GridLayout; 21 using views::GridLayout;
19 22
20 namespace { 23 namespace {
21 24
22 // Fixed width of the column holding the message text. 25 // Fixed width of the column holding the message text.
23 const int kWidthOfMessageText = 375; 26 const int kWidthOfMessageText = 375;
24 27
25 // TODO(bondd): BubbleManager will eventually move this logic somewhere else, 28 // TODO(bondd): BubbleManager will eventually move this logic somewhere else,
26 // and then kIsOkButtonOnLeftSide can be removed from here and 29 // and then kIsOkButtonOnLeftSide can be removed from here and
27 // dialog_client_view.cc. 30 // dialog_client_view.cc.
28 #if defined(OS_WIN) || defined(OS_CHROMEOS) 31 #if defined(OS_WIN) || defined(OS_CHROMEOS)
29 const bool kIsOkButtonOnLeftSide = true; 32 const bool kIsOkButtonOnLeftSide = true;
30 #else 33 #else
31 const bool kIsOkButtonOnLeftSide = false; 34 const bool kIsOkButtonOnLeftSide = false;
32 #endif 35 #endif
33 36
37 views::StyledLabel* CreateLegalMessageLineLabel(
Evan Stade 2015/11/18 00:21:13 return scoped_ptr
bondd 2015/11/18 01:59:40 Done.
38 const autofill::SaveCardBubbleController::LegalMessageLine& line,
39 views::StyledLabelListener* listener) {
40 views::StyledLabel* label = new views::StyledLabel(line.text, listener);
41 const std::vector<autofill::SaveCardBubbleController::LegalMessageLine::Link>&
Evan Stade 2015/11/18 00:21:13 this anonymous namespace should be inside the auto
bondd 2015/11/18 01:59:40 Done.
42 links = line.links;
43 for (size_t i = 0; i < links.size(); ++i) {
44 label->AddStyleRange(links[i].range,
45 views::StyledLabel::RangeStyleInfo::CreateForLink());
46 }
47 label->SizeToFit(kWidthOfMessageText);
48 return label;
49 }
50
34 } // namespace 51 } // namespace
35 52
36 namespace autofill { 53 namespace autofill {
37 54
38 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, 55 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
39 content::WebContents* web_contents, 56 content::WebContents* web_contents,
40 SaveCardBubbleController* controller) 57 SaveCardBubbleController* controller)
41 : LocationBarBubbleDelegateView(anchor_view, web_contents), 58 : LocationBarBubbleDelegateView(anchor_view, web_contents),
42 controller_(controller), 59 controller_(controller),
43 save_button_(nullptr), 60 save_button_(nullptr),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 controller_->OnCancelButton(); 101 controller_->OnCancelButton();
85 } 102 }
86 Close(); 103 Close();
87 } 104 }
88 105
89 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { 106 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) {
90 DCHECK_EQ(source, learn_more_link_); 107 DCHECK_EQ(source, learn_more_link_);
91 controller_->OnLearnMoreClicked(); 108 controller_->OnLearnMoreClicked();
92 } 109 }
93 110
94 void SaveCardBubbleViews::Init() { 111 void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label,
112 const gfx::Range& range,
113 int event_flags) {
114 // Index of |label| within its parent's view hierarchy is the same as the
115 // legal message line index. DCHECK this assumption to guard against future
116 // layout changes.
117 DCHECK(static_cast<size_t>(label->parent()->child_count()) ==
Evan Stade 2015/11/18 00:21:13 DCHECK_EQ
bondd 2015/11/18 01:59:40 Done.
118 controller_->GetLegalMessageLines().size());
119 int line_index = label->parent()->GetIndexOf(label);
Evan Stade 2015/11/18 00:21:13 don't need this local variable
bondd 2015/11/18 01:59:40 Done. Sometimes I prefer breaking a line up with a
Evan Stade 2015/11/18 22:01:18 my reasoning is that saving it as a local variable
120
121 const std::vector<SaveCardBubbleController::LegalMessageLine::Link>& links =
122 controller_->GetLegalMessageLines()[line_index].links;
123 for (size_t i = 0; i < links.size(); ++i) {
124 if (links[i].range == range) {
125 controller_->OnLegalMessageLinkClicked(links[i].url);
126 return;
127 }
128 }
Evan Stade 2015/11/18 00:21:13 nit: \n
bondd 2015/11/18 01:59:40 Done.
129 // |range| was not found.
130 NOTREACHED();
131 }
132
133 // Create view containing everything except for the footnote.
134 scoped_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
95 enum { 135 enum {
96 COLUMN_SET_ID_MESSAGE, 136 COLUMN_SET_ID_MESSAGE,
97 COLUMN_SET_ID_BUTTONS, 137 COLUMN_SET_ID_BUTTONS,
98 }; 138 };
99 139
100 GridLayout* layout = new GridLayout(this); 140 scoped_ptr<View> view(new View());
101 SetLayoutManager(layout); 141 GridLayout* layout = new GridLayout(view.get());
142 view->SetLayoutManager(layout);
102 143
103 // Set up ColumnSet that will contain the full-width message text. 144 // Set up ColumnSet that will contain the full-width message text.
104 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); 145 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
105 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); 146 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE);
106 cs->AddPaddingColumn(0, horizontal_inset); 147 cs->AddPaddingColumn(0, horizontal_inset);
107 // TODO(bondd): Current dialog layout has no message text, but future layouts 148 // TODO(bondd): Current dialog layout has no message text, but future layouts
108 // will. This padding column is used until then to set the dialog width. 149 // will. This padding column is used until then to set the dialog width.
109 cs->AddPaddingColumn(1, kWidthOfMessageText); 150 cs->AddPaddingColumn(1, kWidthOfMessageText);
110 cs->AddPaddingColumn(0, horizontal_inset); 151 cs->AddPaddingColumn(0, horizontal_inset);
111 152
112 // Set up ColumnSet that will contain the buttons and "learn more" link. 153 // Set up ColumnSet that will contain the buttons and "learn more" link.
113 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); 154 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS);
114 cs->AddPaddingColumn(0, horizontal_inset); 155 cs->AddPaddingColumn(0, horizontal_inset);
115 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 156 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
116 GridLayout::USE_PREF, 0, 0); 157 GridLayout::USE_PREF, 0, 0);
117 cs->AddPaddingColumn(1, 0); 158 cs->AddPaddingColumn(1, 0);
118 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 159 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
119 GridLayout::USE_PREF, 0, 0); 160 GridLayout::USE_PREF, 0, 0);
120 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 161 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
121 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 162 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
122 GridLayout::USE_PREF, 0, 0); 163 GridLayout::USE_PREF, 0, 0);
123 cs->AddPaddingColumn(0, horizontal_inset); 164 cs->AddPaddingColumn(0, horizontal_inset);
124 165
125 // Create "learn more" link and add it to layout. 166 // Create "learn more" link and add it to layout.
126 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 167 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
168 learn_more_link_->SetUnderline(false);
127 learn_more_link_->set_listener(this); 169 learn_more_link_->set_listener(this);
128 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); 170 layout->StartRow(0, COLUMN_SET_ID_BUTTONS);
129 layout->AddView(learn_more_link_); 171 layout->AddView(learn_more_link_);
130 172
131 // Create accept button. 173 // Create accept button.
132 save_button_ = new views::BlueButton( 174 save_button_ = new views::BlueButton(
133 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); 175 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT));
134 save_button_->SetIsDefault(true); 176 save_button_->SetIsDefault(true);
135 177
136 // Create cancel button. 178 // Create cancel button.
137 cancel_button_ = new views::LabelButton( 179 cancel_button_ = new views::LabelButton(
138 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); 180 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY));
139 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); 181 cancel_button_->SetStyle(views::Button::STYLE_BUTTON);
140 182
141 if (kIsOkButtonOnLeftSide) { 183 if (kIsOkButtonOnLeftSide) {
142 layout->AddView(save_button_); 184 layout->AddView(save_button_);
143 layout->AddView(cancel_button_); 185 layout->AddView(cancel_button_);
144 } else { 186 } else {
145 layout->AddView(cancel_button_); 187 layout->AddView(cancel_button_);
146 layout->AddView(save_button_); 188 layout->AddView(save_button_);
147 } 189 }
148 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 190 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
149 191
192 return view;
193 }
194
195 // Create view containing the legal message text.
196 scoped_ptr<views::View> SaveCardBubbleViews::CreateFootnoteView() {
197 // Use BoxLayout to provide insets around the label.
198 scoped_ptr<View> view(new View());
199 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
Evan Stade 2015/11/18 00:21:13 don't need this local var
bondd 2015/11/18 01:59:40 Done.
200 view->SetLayoutManager(
201 new views::BoxLayout(views::BoxLayout::kVertical, horizontal_inset,
202 views::kRelatedControlVerticalSpacing, 0));
203 view->SetBorder(
204 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor));
205 view->set_background(
206 views::Background::CreateSolidBackground(kLightShadingColor));
207
208 // Add a StyledLabel for each line of the legal message.
209 for (size_t i = 0; i < controller_->GetLegalMessageLines().size(); ++i) {
210 views::StyledLabel* label = CreateLegalMessageLineLabel(
211 controller_->GetLegalMessageLines()[i], this);
Evan Stade 2015/11/18 00:21:13 no need for a local var for this
bondd 2015/11/18 01:59:40 Done.
212 view->AddChildView(label);
213 }
214
215 return view;
216 }
217
218 void SaveCardBubbleViews::Init() {
219 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
220 AddChildView(CreateMainContentView().release());
221 if (!controller_->GetLegalMessageLines().empty())
222 AddChildView(CreateFootnoteView().release());
223
150 set_margins(gfx::Insets(1, 0, 1, 0)); 224 set_margins(gfx::Insets(1, 0, 1, 0));
151 Layout();
152 } 225 }
153 226
154 } // namespace autofill 227 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698