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

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: Rebase. 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/label.h" 15 #include "ui/views/controls/label.h"
15 #include "ui/views/controls/link.h" 16 #include "ui/views/controls/link.h"
17 #include "ui/views/controls/styled_label.h"
18 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/layout/grid_layout.h" 19 #include "ui/views/layout/grid_layout.h"
17 #include "ui/views/layout/layout_constants.h" 20 #include "ui/views/layout/layout_constants.h"
18 21
19 using views::GridLayout; 22 using views::GridLayout;
20 23
24 namespace autofill {
25
21 namespace { 26 namespace {
22 27
23 // Fixed width of the bubble. 28 // Fixed width of the bubble.
24 const int kBubbleWidth = 395; 29 const int kBubbleWidth = 395;
25 30
26 // TODO(bondd): BubbleManager will eventually move this logic somewhere else, 31 // TODO(bondd): BubbleManager will eventually move this logic somewhere else,
27 // and then kIsOkButtonOnLeftSide can be removed from here and 32 // and then kIsOkButtonOnLeftSide can be removed from here and
28 // dialog_client_view.cc. 33 // dialog_client_view.cc.
29 #if defined(OS_WIN) || defined(OS_CHROMEOS) 34 #if defined(OS_WIN) || defined(OS_CHROMEOS)
30 const bool kIsOkButtonOnLeftSide = true; 35 const bool kIsOkButtonOnLeftSide = true;
31 #else 36 #else
32 const bool kIsOkButtonOnLeftSide = false; 37 const bool kIsOkButtonOnLeftSide = false;
33 #endif 38 #endif
34 39
40 scoped_ptr<views::StyledLabel> CreateLegalMessageLineLabel(
41 const SaveCardBubbleController::LegalMessageLine& line,
42 views::StyledLabelListener* listener) {
43 scoped_ptr<views::StyledLabel> label(
44 new views::StyledLabel(line.text, listener));
45 for (const SaveCardBubbleController::LegalMessageLine::Link& link :
46 line.links) {
47 label->AddStyleRange(link.range,
48 views::StyledLabel::RangeStyleInfo::CreateForLink());
49 }
50 return label;
51 }
52
35 } // namespace 53 } // namespace
36 54
37 namespace autofill {
38
39 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, 55 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
40 content::WebContents* web_contents, 56 content::WebContents* web_contents,
41 SaveCardBubbleController* controller) 57 SaveCardBubbleController* controller)
42 : LocationBarBubbleDelegateView(anchor_view, web_contents), 58 : LocationBarBubbleDelegateView(anchor_view, web_contents),
43 controller_(controller), 59 controller_(controller),
44 save_button_(nullptr), 60 save_button_(nullptr),
45 cancel_button_(nullptr), 61 cancel_button_(nullptr),
46 learn_more_link_(nullptr) { 62 learn_more_link_(nullptr) {
47 DCHECK(controller); 63 DCHECK(controller);
48 views::BubbleDelegateView::CreateBubble(this); 64 views::BubbleDelegateView::CreateBubble(this);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 controller_->OnCancelButton(); 101 controller_->OnCancelButton();
86 } 102 }
87 Close(); 103 Close();
88 } 104 }
89 105
90 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { 106 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) {
91 DCHECK_EQ(source, learn_more_link_); 107 DCHECK_EQ(source, learn_more_link_);
92 controller_->OnLearnMoreClicked(); 108 controller_->OnLearnMoreClicked();
93 } 109 }
94 110
95 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_EQ(static_cast<size_t>(label->parent()->child_count()),
118 controller_->GetLegalMessageLines().size());
119
120 const auto& links =
121 controller_->GetLegalMessageLines()[label->parent()->GetIndexOf(label)]
122 .links;
123 for (const SaveCardBubbleController::LegalMessageLine::Link& link : links) {
124 if (link.range == range) {
125 controller_->OnLegalMessageLinkClicked(link.url);
126 return;
127 }
128 }
129
130 // |range| was not found.
131 NOTREACHED();
132 }
133
134 // Create view containing everything except for the footnote.
135 scoped_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
96 enum { 136 enum {
97 COLUMN_SET_ID_SPACER, 137 COLUMN_SET_ID_SPACER,
98 COLUMN_SET_ID_EXPLANATION, 138 COLUMN_SET_ID_EXPLANATION,
99 COLUMN_SET_ID_BUTTONS, 139 COLUMN_SET_ID_BUTTONS,
100 }; 140 };
101 141
102 GridLayout* layout = new GridLayout(this); 142 scoped_ptr<View> view(new View());
103 SetLayoutManager(layout); 143 GridLayout* layout = new GridLayout(view.get());
144 view->SetLayoutManager(layout);
104 145
105 // Add a column set with padding to establish a minimum width. 146 // Add a column set with padding to establish a minimum width.
106 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_SPACER); 147 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_SPACER);
107 cs->AddPaddingColumn(0, kBubbleWidth); 148 cs->AddPaddingColumn(0, kBubbleWidth);
108 layout->StartRow(0, COLUMN_SET_ID_SPACER); 149 layout->StartRow(0, COLUMN_SET_ID_SPACER);
109 150
110 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); 151 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
111 // Optionally set up ColumnSet and label that will contain an explanation for 152 // Optionally set up ColumnSet and label that will contain an explanation for
112 // upload. 153 // upload.
113 base::string16 explanation = controller_->GetExplanatoryMessage(); 154 base::string16 explanation = controller_->GetExplanatoryMessage();
(...skipping 23 matching lines...) Expand all
137 cs->AddPaddingColumn(1, 0); 178 cs->AddPaddingColumn(1, 0);
138 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 179 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
139 GridLayout::USE_PREF, 0, 0); 180 GridLayout::USE_PREF, 0, 0);
140 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 181 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
141 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 182 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
142 GridLayout::USE_PREF, 0, 0); 183 GridLayout::USE_PREF, 0, 0);
143 cs->AddPaddingColumn(0, horizontal_inset); 184 cs->AddPaddingColumn(0, horizontal_inset);
144 185
145 // Create "learn more" link and add it to layout. 186 // Create "learn more" link and add it to layout.
146 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 187 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
188 learn_more_link_->SetUnderline(false);
147 learn_more_link_->set_listener(this); 189 learn_more_link_->set_listener(this);
148 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); 190 layout->StartRow(0, COLUMN_SET_ID_BUTTONS);
149 layout->AddView(learn_more_link_); 191 layout->AddView(learn_more_link_);
150 192
151 // Create accept button. 193 // Create accept button.
152 save_button_ = new views::BlueButton( 194 save_button_ = new views::BlueButton(
153 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); 195 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT));
154 save_button_->SetIsDefault(true); 196 save_button_->SetIsDefault(true);
155 197
156 // Create cancel button. 198 // Create cancel button.
157 cancel_button_ = new views::LabelButton( 199 cancel_button_ = new views::LabelButton(
158 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); 200 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY));
159 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); 201 cancel_button_->SetStyle(views::Button::STYLE_BUTTON);
160 202
161 if (kIsOkButtonOnLeftSide) { 203 if (kIsOkButtonOnLeftSide) {
162 layout->AddView(save_button_); 204 layout->AddView(save_button_);
163 layout->AddView(cancel_button_); 205 layout->AddView(cancel_button_);
164 } else { 206 } else {
165 layout->AddView(cancel_button_); 207 layout->AddView(cancel_button_);
166 layout->AddView(save_button_); 208 layout->AddView(save_button_);
167 } 209 }
168 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 210 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
169 211
212 return view;
213 }
214
215 // Create view containing the legal message text.
216 scoped_ptr<views::View> SaveCardBubbleViews::CreateFootnoteView() {
217 // Use BoxLayout to provide insets around the label.
218 scoped_ptr<View> view(new View());
219 view->SetLayoutManager(
220 new views::BoxLayout(views::BoxLayout::kVertical,
221 GetBubbleFrameView()->GetTitleInsets().left(),
222 views::kRelatedControlVerticalSpacing, 0));
223 view->SetBorder(
224 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor));
225 view->set_background(
226 views::Background::CreateSolidBackground(kLightShadingColor));
227
228 // Add a StyledLabel for each line of the legal message.
229 for (const SaveCardBubbleController::LegalMessageLine& line :
230 controller_->GetLegalMessageLines()) {
231 view->AddChildView(CreateLegalMessageLineLabel(line, this).release());
232 }
233
234 return view;
235 }
236
237 void SaveCardBubbleViews::Init() {
238 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
239 AddChildView(CreateMainContentView().release());
240 if (!controller_->GetLegalMessageLines().empty())
241 AddChildView(CreateFootnoteView().release());
242
170 set_margins(gfx::Insets(1, 0, 1, 0)); 243 set_margins(gfx::Insets(1, 0, 1, 0));
171 Layout();
172 } 244 }
173 245
174 } // namespace autofill 246 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698