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