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

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 14. 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
23 namespace autofill {
24
20 namespace { 25 namespace {
21 26
22 // Fixed width of the column holding the message text. 27 // Fixed width of the column holding the message text.
23 const int kWidthOfMessageText = 375; 28 const int kWidthOfMessageText = 375;
24 29
25 // TODO(bondd): BubbleManager will eventually move this logic somewhere else, 30 // TODO(bondd): BubbleManager will eventually move this logic somewhere else,
26 // and then kIsOkButtonOnLeftSide can be removed from here and 31 // and then kIsOkButtonOnLeftSide can be removed from here and
27 // dialog_client_view.cc. 32 // dialog_client_view.cc.
28 #if defined(OS_WIN) || defined(OS_CHROMEOS) 33 #if defined(OS_WIN) || defined(OS_CHROMEOS)
29 const bool kIsOkButtonOnLeftSide = true; 34 const bool kIsOkButtonOnLeftSide = true;
30 #else 35 #else
31 const bool kIsOkButtonOnLeftSide = false; 36 const bool kIsOkButtonOnLeftSide = false;
32 #endif 37 #endif
33 38
39 scoped_ptr<views::StyledLabel> CreateLegalMessageLineLabel(
40 const SaveCardBubbleController::LegalMessageLine& line,
41 views::StyledLabelListener* listener) {
42 scoped_ptr<views::StyledLabel> label(
43 new views::StyledLabel(line.text, listener));
44 for (const SaveCardBubbleController::LegalMessageLine::Link& link :
45 line.links) {
46 label->AddStyleRange(link.range,
47 views::StyledLabel::RangeStyleInfo::CreateForLink());
48 }
49 label->SizeToFit(kWidthOfMessageText);
50 return label;
51 }
52
34 } // namespace 53 } // namespace
35 54
36 namespace autofill {
37
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),
44 cancel_button_(nullptr), 61 cancel_button_(nullptr),
45 learn_more_link_(nullptr) { 62 learn_more_link_(nullptr) {
46 DCHECK(controller); 63 DCHECK(controller);
47 views::BubbleDelegateView::CreateBubble(this); 64 views::BubbleDelegateView::CreateBubble(this);
(...skipping 36 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_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() {
95 enum { 136 enum {
96 COLUMN_SET_ID_MESSAGE, 137 COLUMN_SET_ID_MESSAGE,
97 COLUMN_SET_ID_BUTTONS, 138 COLUMN_SET_ID_BUTTONS,
98 }; 139 };
99 140
100 GridLayout* layout = new GridLayout(this); 141 scoped_ptr<View> view(new View());
101 SetLayoutManager(layout); 142 GridLayout* layout = new GridLayout(view.get());
143 view->SetLayoutManager(layout);
102 144
103 // Set up ColumnSet that will contain the full-width message text. 145 // Set up ColumnSet that will contain the full-width message text.
104 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); 146 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
105 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); 147 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE);
106 cs->AddPaddingColumn(0, horizontal_inset); 148 cs->AddPaddingColumn(0, horizontal_inset);
107 // TODO(bondd): Current dialog layout has no message text, but future layouts 149 // 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. 150 // will. This padding column is used until then to set the dialog width.
109 cs->AddPaddingColumn(1, kWidthOfMessageText); 151 cs->AddPaddingColumn(1, kWidthOfMessageText);
110 cs->AddPaddingColumn(0, horizontal_inset); 152 cs->AddPaddingColumn(0, horizontal_inset);
111 153
112 // Set up ColumnSet that will contain the buttons and "learn more" link. 154 // Set up ColumnSet that will contain the buttons and "learn more" link.
113 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); 155 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS);
114 cs->AddPaddingColumn(0, horizontal_inset); 156 cs->AddPaddingColumn(0, horizontal_inset);
115 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 157 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
116 GridLayout::USE_PREF, 0, 0); 158 GridLayout::USE_PREF, 0, 0);
117 cs->AddPaddingColumn(1, 0); 159 cs->AddPaddingColumn(1, 0);
118 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 160 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
119 GridLayout::USE_PREF, 0, 0); 161 GridLayout::USE_PREF, 0, 0);
120 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 162 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
121 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 163 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
122 GridLayout::USE_PREF, 0, 0); 164 GridLayout::USE_PREF, 0, 0);
123 cs->AddPaddingColumn(0, horizontal_inset); 165 cs->AddPaddingColumn(0, horizontal_inset);
124 166
125 // Create "learn more" link and add it to layout. 167 // Create "learn more" link and add it to layout.
126 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 168 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
169 learn_more_link_->SetUnderline(false);
127 learn_more_link_->set_listener(this); 170 learn_more_link_->set_listener(this);
128 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); 171 layout->StartRow(0, COLUMN_SET_ID_BUTTONS);
129 layout->AddView(learn_more_link_); 172 layout->AddView(learn_more_link_);
130 173
131 // Create accept button. 174 // Create accept button.
132 save_button_ = new views::BlueButton( 175 save_button_ = new views::BlueButton(
133 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); 176 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT));
134 save_button_->SetIsDefault(true); 177 save_button_->SetIsDefault(true);
135 178
136 // Create cancel button. 179 // Create cancel button.
137 cancel_button_ = new views::LabelButton( 180 cancel_button_ = new views::LabelButton(
138 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); 181 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY));
139 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); 182 cancel_button_->SetStyle(views::Button::STYLE_BUTTON);
140 183
141 if (kIsOkButtonOnLeftSide) { 184 if (kIsOkButtonOnLeftSide) {
142 layout->AddView(save_button_); 185 layout->AddView(save_button_);
143 layout->AddView(cancel_button_); 186 layout->AddView(cancel_button_);
144 } else { 187 } else {
145 layout->AddView(cancel_button_); 188 layout->AddView(cancel_button_);
146 layout->AddView(save_button_); 189 layout->AddView(save_button_);
147 } 190 }
148 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 191 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
149 192
193 return view;
194 }
195
196 // Create view containing the legal message text.
197 scoped_ptr<views::View> SaveCardBubbleViews::CreateFootnoteView() {
198 // Use BoxLayout to provide insets around the label.
199 scoped_ptr<View> view(new View());
200 view->SetLayoutManager(
201 new views::BoxLayout(views::BoxLayout::kVertical,
202 GetBubbleFrameView()->GetTitleInsets().left(),
203 views::kRelatedControlVerticalSpacing, 0));
204 view->SetBorder(
205 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor));
206 view->set_background(
207 views::Background::CreateSolidBackground(kLightShadingColor));
208
209 // Add a StyledLabel for each line of the legal message.
210 for (const SaveCardBubbleController::LegalMessageLine& line :
211 controller_->GetLegalMessageLines()) {
212 view->AddChildView(CreateLegalMessageLineLabel(line, this).release());
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