Chromium Code Reviews| Index: chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| diff --git a/chrome/browser/ui/views/autofill/save_card_bubble_views.cc b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| index 214f508e7316c2e04f5ea2459ded67a8425f03c9..647072f8555cefed6135f526f740fbe8fd0512da 100644 |
| --- a/chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| +++ b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc |
| @@ -5,6 +5,7 @@ |
| #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
| #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" |
| #include "grit/components_strings.h" |
| #include "ui/base/l10n/l10n_util.h" |
| @@ -12,6 +13,8 @@ |
| #include "ui/views/controls/button/blue_button.h" |
| #include "ui/views/controls/button/label_button.h" |
| #include "ui/views/controls/link.h" |
| +#include "ui/views/controls/styled_label.h" |
| +#include "ui/views/layout/box_layout.h" |
| #include "ui/views/layout/grid_layout.h" |
| #include "ui/views/layout/layout_constants.h" |
| @@ -31,6 +34,20 @@ const bool kIsOkButtonOnLeftSide = true; |
| const bool kIsOkButtonOnLeftSide = false; |
| #endif |
| +views::StyledLabel* CreateLegalMessageLineLabel( |
| + const autofill::SaveCardBubbleController::LegalMessageLine& line, |
| + views::StyledLabelListener& listener) { |
| + views::StyledLabel* label = new views::StyledLabel(line.text, &listener); |
| + const std::vector<autofill::SaveCardBubbleController::LegalMessageLine::Link>& |
| + links = line.links; |
| + for (size_t i = 0; i < links.size(); ++i) { |
| + label->AddStyleRange(links[i].range, |
| + views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| + } |
| + label->SizeToFit(kWidthOfMessageText); |
| + return label; |
| +} |
| + |
| } // namespace |
| namespace autofill { |
| @@ -95,14 +112,37 @@ void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { |
| controller_->OnLearnMoreClicked(); |
| } |
| -void SaveCardBubbleViews::Init() { |
| +void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel& label, |
| + const gfx::Range& range, |
| + int event_flags) { |
| + const std::vector<SaveCardBubbleController::LegalMessageLine::Link>& links = |
| + legal_message_lines_[&label]->links; |
| + for (size_t i = 0; i < links.size(); ++i) { |
|
Evan Stade
2015/11/13 01:33:07
this is why i suggested a map for range->url. But
bondd
2015/11/13 22:30:43
Yep, I tried a map and decided against it when I f
|
| + if (links[i].range == range) { |
| + controller_->OnLegalMessageLinkClicked(links[i].url); |
| + return; |
| + } |
| + } |
| + // |range| was not found. |
| + NOTREACHED(); |
| +} |
| + |
| +// Create view containing everything except for the footnote. |
| +// ASCII art diagram of view contents: |
| +// +---------------------------------------------------------------------------+ |
| +// | | |
| +// | learn_more_link_ save_button_ cancel_button_ | |
| +// | | |
| +// +---------------------------------------------------------------------------+ |
| +views::View* SaveCardBubbleViews::CreateMainContentView() { |
| enum { |
| COLUMN_SET_ID_MESSAGE, |
| COLUMN_SET_ID_BUTTONS, |
| }; |
| - GridLayout* layout = new GridLayout(this); |
| - SetLayoutManager(layout); |
| + View* view = new View(); |
|
Evan Stade
2015/11/13 01:33:07
nit: scoped_ptr
bondd
2015/11/13 22:30:43
Sorry, can you explain this out a bit further, or
Justin Donnelly
2015/11/13 22:51:04
The idea is to be defensive against future changes
bondd
2015/11/17 00:12:04
Done. Thanks for the detailed explanation.
|
| + GridLayout* layout = new GridLayout(view); |
| + view->SetLayoutManager(layout); |
| // Set up ColumnSet that will contain the full-width message text. |
| int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); |
| @@ -128,6 +168,7 @@ void SaveCardBubbleViews::Init() { |
| // Create "learn more" link and add it to layout. |
| learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| + learn_more_link_->SetUnderline(false); |
| learn_more_link_->set_listener(this); |
| layout->StartRow(0, COLUMN_SET_ID_BUTTONS); |
| layout->AddView(learn_more_link_); |
| @@ -151,8 +192,41 @@ void SaveCardBubbleViews::Init() { |
| } |
| layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| + return view; |
| +} |
| + |
| +// Create view containing the legal message text. |
| +views::View* SaveCardBubbleViews::CreateFootnoteView() { |
| + // Use BoxLayout to provide insets around the label. |
| + View* view = new View(); |
|
Evan Stade
2015/11/13 01:33:07
nit: scoped_ptr
|
| + int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); |
| + view->SetLayoutManager( |
| + new views::BoxLayout(views::BoxLayout::kVertical, horizontal_inset, |
| + views::kRelatedControlVerticalSpacing, 0)); |
| + view->SetBorder( |
| + views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); |
| + view->set_background( |
| + views::Background::CreateSolidBackground(kLightShadingColor)); |
| + |
| + // Add a StyledLabel for each line of the legal message. |
| + for (size_t i = 0; i < controller_->GetLegalMessageLines().size(); ++i) { |
| + views::StyledLabel* label = CreateLegalMessageLineLabel( |
| + controller_->GetLegalMessageLines()[i], *this); |
| + view->AddChildView(label); |
| + |
| + legal_message_lines_[label] = &controller_->GetLegalMessageLines()[i]; |
| + } |
| + |
| + return view; |
| +} |
| + |
| +void SaveCardBubbleViews::Init() { |
| + SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| + AddChildView(CreateMainContentView()); |
| + if (!controller_->GetLegalMessageLines().empty()) |
| + AddChildView(CreateFootnoteView()); |
| + |
| set_margins(gfx::Insets(1, 0, 1, 0)); |
| - Layout(); |
| } |
| } // namespace autofill |