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

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: Move new unittests file to non_mobile sources. 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(
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>&
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 const std::vector<SaveCardBubbleController::LegalMessageLine::Link>& links =
115 legal_message_lines_[label]->links;
116 for (size_t i = 0; i < links.size(); ++i) {
117 if (links[i].range == range) {
118 controller_->OnLegalMessageLinkClicked(links[i].url);
119 return;
120 }
121 }
122 // |range| was not found.
123 NOTREACHED();
124 }
125
126 // Create view containing everything except for the footnote.
127 // ASCII art diagram of view contents:
128 // +---------------------------------------------------------------------------+
129 // | |
130 // | learn_more_link_ save_button_ cancel_button_ |
Evan Stade 2015/11/17 19:38:19 I'm not a huge fan of this art (sorry, I may be a
bondd 2015/11/17 23:48:58 Done.
131 // | |
132 // +---------------------------------------------------------------------------+
133 scoped_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() {
95 enum { 134 enum {
96 COLUMN_SET_ID_MESSAGE, 135 COLUMN_SET_ID_MESSAGE,
97 COLUMN_SET_ID_BUTTONS, 136 COLUMN_SET_ID_BUTTONS,
98 }; 137 };
99 138
100 GridLayout* layout = new GridLayout(this); 139 scoped_ptr<View> view(new View());
101 SetLayoutManager(layout); 140 GridLayout* layout = new GridLayout(view.get());
141 view->SetLayoutManager(layout);
102 142
103 // Set up ColumnSet that will contain the full-width message text. 143 // Set up ColumnSet that will contain the full-width message text.
104 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); 144 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
105 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); 145 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE);
106 cs->AddPaddingColumn(0, horizontal_inset); 146 cs->AddPaddingColumn(0, horizontal_inset);
107 // TODO(bondd): Current dialog layout has no message text, but future layouts 147 // 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. 148 // will. This padding column is used until then to set the dialog width.
109 cs->AddPaddingColumn(1, kWidthOfMessageText); 149 cs->AddPaddingColumn(1, kWidthOfMessageText);
110 cs->AddPaddingColumn(0, horizontal_inset); 150 cs->AddPaddingColumn(0, horizontal_inset);
111 151
112 // Set up ColumnSet that will contain the buttons and "learn more" link. 152 // Set up ColumnSet that will contain the buttons and "learn more" link.
113 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); 153 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS);
114 cs->AddPaddingColumn(0, horizontal_inset); 154 cs->AddPaddingColumn(0, horizontal_inset);
115 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 155 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
116 GridLayout::USE_PREF, 0, 0); 156 GridLayout::USE_PREF, 0, 0);
117 cs->AddPaddingColumn(1, 0); 157 cs->AddPaddingColumn(1, 0);
118 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 158 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
119 GridLayout::USE_PREF, 0, 0); 159 GridLayout::USE_PREF, 0, 0);
120 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 160 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
121 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, 161 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
122 GridLayout::USE_PREF, 0, 0); 162 GridLayout::USE_PREF, 0, 0);
123 cs->AddPaddingColumn(0, horizontal_inset); 163 cs->AddPaddingColumn(0, horizontal_inset);
124 164
125 // Create "learn more" link and add it to layout. 165 // Create "learn more" link and add it to layout.
126 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); 166 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE));
167 learn_more_link_->SetUnderline(false);
127 learn_more_link_->set_listener(this); 168 learn_more_link_->set_listener(this);
128 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); 169 layout->StartRow(0, COLUMN_SET_ID_BUTTONS);
129 layout->AddView(learn_more_link_); 170 layout->AddView(learn_more_link_);
130 171
131 // Create accept button. 172 // Create accept button.
132 save_button_ = new views::BlueButton( 173 save_button_ = new views::BlueButton(
133 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); 174 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT));
134 save_button_->SetIsDefault(true); 175 save_button_->SetIsDefault(true);
135 176
136 // Create cancel button. 177 // Create cancel button.
137 cancel_button_ = new views::LabelButton( 178 cancel_button_ = new views::LabelButton(
138 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); 179 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY));
139 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); 180 cancel_button_->SetStyle(views::Button::STYLE_BUTTON);
140 181
141 if (kIsOkButtonOnLeftSide) { 182 if (kIsOkButtonOnLeftSide) {
142 layout->AddView(save_button_); 183 layout->AddView(save_button_);
143 layout->AddView(cancel_button_); 184 layout->AddView(cancel_button_);
144 } else { 185 } else {
145 layout->AddView(cancel_button_); 186 layout->AddView(cancel_button_);
146 layout->AddView(save_button_); 187 layout->AddView(save_button_);
147 } 188 }
148 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 189 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
149 190
191 return view;
192 }
193
194 // Create view containing the legal message text.
195 scoped_ptr<views::View> SaveCardBubbleViews::CreateFootnoteView() {
196 // Use BoxLayout to provide insets around the label.
197 scoped_ptr<View> view(new View());
198 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
199 view->SetLayoutManager(
200 new views::BoxLayout(views::BoxLayout::kVertical, horizontal_inset,
201 views::kRelatedControlVerticalSpacing, 0));
202 view->SetBorder(
203 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor));
204 view->set_background(
205 views::Background::CreateSolidBackground(kLightShadingColor));
206
207 // Add a StyledLabel for each line of the legal message.
208 for (size_t i = 0; i < controller_->GetLegalMessageLines().size(); ++i) {
209 views::StyledLabel* label = CreateLegalMessageLineLabel(
210 controller_->GetLegalMessageLines()[i], *this);
211 view->AddChildView(label);
212
213 legal_message_lines_[label] = &controller_->GetLegalMessageLines()[i];
214 }
215
216 return view;
217 }
218
219 void SaveCardBubbleViews::Init() {
220 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
221 AddChildView(CreateMainContentView().release());
222 if (!controller_->GetLegalMessageLines().empty())
223 AddChildView(CreateFootnoteView().release());
224
150 set_margins(gfx::Insets(1, 0, 1, 0)); 225 set_margins(gfx::Insets(1, 0, 1, 0));
151 Layout();
152 } 226 }
153 227
154 } // namespace autofill 228 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698