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 |
| 23 namespace autofill { | |
| 24 | |
|
bondd
2015/11/18 01:59:40
Other autofill files seem evenly split on whether
| |
| 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 const std::vector<SaveCardBubbleController::LegalMessageLine::Link>& links = | |
| 45 line.links; | |
| 46 for (size_t i = 0; i < links.size(); ++i) { | |
|
Evan Stade
2015/11/18 22:01:19
for (const SaveCardBubbleController::LegalMessageL
bondd
2015/11/18 23:41:42
Done.
| |
| 47 label->AddStyleRange(links[i].range, | |
| 48 views::StyledLabel::RangeStyleInfo::CreateForLink()); | |
| 49 } | |
| 50 label->SizeToFit(kWidthOfMessageText); | |
| 51 return label; | |
| 52 } | |
| 53 | |
| 34 } // namespace | 54 } // namespace |
| 35 | 55 |
| 36 namespace autofill { | |
| 37 | |
| 38 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, | 56 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, |
| 39 content::WebContents* web_contents, | 57 content::WebContents* web_contents, |
| 40 SaveCardBubbleController* controller) | 58 SaveCardBubbleController* controller) |
| 41 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 59 : LocationBarBubbleDelegateView(anchor_view, web_contents), |
| 42 controller_(controller), | 60 controller_(controller), |
| 43 save_button_(nullptr), | 61 save_button_(nullptr), |
| 44 cancel_button_(nullptr), | 62 cancel_button_(nullptr), |
| 45 learn_more_link_(nullptr) { | 63 learn_more_link_(nullptr) { |
| 46 DCHECK(controller); | 64 DCHECK(controller); |
| 47 views::BubbleDelegateView::CreateBubble(this); | 65 views::BubbleDelegateView::CreateBubble(this); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 controller_->OnCancelButton(); | 102 controller_->OnCancelButton(); |
| 85 } | 103 } |
| 86 Close(); | 104 Close(); |
| 87 } | 105 } |
| 88 | 106 |
| 89 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { | 107 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { |
| 90 DCHECK_EQ(source, learn_more_link_); | 108 DCHECK_EQ(source, learn_more_link_); |
| 91 controller_->OnLearnMoreClicked(); | 109 controller_->OnLearnMoreClicked(); |
| 92 } | 110 } |
| 93 | 111 |
| 94 void SaveCardBubbleViews::Init() { | 112 void SaveCardBubbleViews::StyledLabelLinkClicked(views::StyledLabel* label, |
| 113 const gfx::Range& range, | |
| 114 int event_flags) { | |
| 115 // Index of |label| within its parent's view hierarchy is the same as the | |
| 116 // legal message line index. DCHECK this assumption to guard against future | |
| 117 // layout changes. | |
| 118 DCHECK_EQ(static_cast<size_t>(label->parent()->child_count()), | |
| 119 controller_->GetLegalMessageLines().size()); | |
| 120 | |
| 121 const std::vector<SaveCardBubbleController::LegalMessageLine::Link>& links = | |
|
Evan Stade
2015/11/18 22:01:19
I'd say this is a good candidate for auto
const a
bondd
2015/11/18 23:41:42
Done.
| |
| 122 controller_->GetLegalMessageLines()[label->parent()->GetIndexOf(label)] | |
| 123 .links; | |
| 124 for (size_t i = 0; i < links.size(); ++i) { | |
| 125 if (links[i].range == range) { | |
| 126 controller_->OnLegalMessageLinkClicked(links[i].url); | |
| 127 return; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 // |range| was not found. | |
| 132 NOTREACHED(); | |
| 133 } | |
| 134 | |
| 135 // Create view containing everything except for the footnote. | |
| 136 scoped_ptr<views::View> SaveCardBubbleViews::CreateMainContentView() { | |
| 95 enum { | 137 enum { |
| 96 COLUMN_SET_ID_MESSAGE, | 138 COLUMN_SET_ID_MESSAGE, |
| 97 COLUMN_SET_ID_BUTTONS, | 139 COLUMN_SET_ID_BUTTONS, |
| 98 }; | 140 }; |
| 99 | 141 |
| 100 GridLayout* layout = new GridLayout(this); | 142 scoped_ptr<View> view(new View()); |
| 101 SetLayoutManager(layout); | 143 GridLayout* layout = new GridLayout(view.get()); |
| 144 view->SetLayoutManager(layout); | |
| 102 | 145 |
| 103 // Set up ColumnSet that will contain the full-width message text. | 146 // Set up ColumnSet that will contain the full-width message text. |
| 104 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); | 147 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); |
| 105 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); | 148 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); |
| 106 cs->AddPaddingColumn(0, horizontal_inset); | 149 cs->AddPaddingColumn(0, horizontal_inset); |
| 107 // TODO(bondd): Current dialog layout has no message text, but future layouts | 150 // 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. | 151 // will. This padding column is used until then to set the dialog width. |
| 109 cs->AddPaddingColumn(1, kWidthOfMessageText); | 152 cs->AddPaddingColumn(1, kWidthOfMessageText); |
| 110 cs->AddPaddingColumn(0, horizontal_inset); | 153 cs->AddPaddingColumn(0, horizontal_inset); |
| 111 | 154 |
| 112 // Set up ColumnSet that will contain the buttons and "learn more" link. | 155 // Set up ColumnSet that will contain the buttons and "learn more" link. |
| 113 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); | 156 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); |
| 114 cs->AddPaddingColumn(0, horizontal_inset); | 157 cs->AddPaddingColumn(0, horizontal_inset); |
| 115 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 158 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 116 GridLayout::USE_PREF, 0, 0); | 159 GridLayout::USE_PREF, 0, 0); |
| 117 cs->AddPaddingColumn(1, 0); | 160 cs->AddPaddingColumn(1, 0); |
| 118 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 161 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 119 GridLayout::USE_PREF, 0, 0); | 162 GridLayout::USE_PREF, 0, 0); |
| 120 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | 163 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
| 121 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 164 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 122 GridLayout::USE_PREF, 0, 0); | 165 GridLayout::USE_PREF, 0, 0); |
| 123 cs->AddPaddingColumn(0, horizontal_inset); | 166 cs->AddPaddingColumn(0, horizontal_inset); |
| 124 | 167 |
| 125 // Create "learn more" link and add it to layout. | 168 // Create "learn more" link and add it to layout. |
| 126 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 169 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 170 learn_more_link_->SetUnderline(false); | |
| 127 learn_more_link_->set_listener(this); | 171 learn_more_link_->set_listener(this); |
| 128 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); | 172 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); |
| 129 layout->AddView(learn_more_link_); | 173 layout->AddView(learn_more_link_); |
| 130 | 174 |
| 131 // Create accept button. | 175 // Create accept button. |
| 132 save_button_ = new views::BlueButton( | 176 save_button_ = new views::BlueButton( |
| 133 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); | 177 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); |
| 134 save_button_->SetIsDefault(true); | 178 save_button_->SetIsDefault(true); |
| 135 | 179 |
| 136 // Create cancel button. | 180 // Create cancel button. |
| 137 cancel_button_ = new views::LabelButton( | 181 cancel_button_ = new views::LabelButton( |
| 138 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); | 182 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); |
| 139 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); | 183 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 140 | 184 |
| 141 if (kIsOkButtonOnLeftSide) { | 185 if (kIsOkButtonOnLeftSide) { |
| 142 layout->AddView(save_button_); | 186 layout->AddView(save_button_); |
| 143 layout->AddView(cancel_button_); | 187 layout->AddView(cancel_button_); |
| 144 } else { | 188 } else { |
| 145 layout->AddView(cancel_button_); | 189 layout->AddView(cancel_button_); |
| 146 layout->AddView(save_button_); | 190 layout->AddView(save_button_); |
| 147 } | 191 } |
| 148 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 192 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 149 | 193 |
| 194 return view; | |
| 195 } | |
| 196 | |
| 197 // Create view containing the legal message text. | |
| 198 scoped_ptr<views::View> SaveCardBubbleViews::CreateFootnoteView() { | |
| 199 // Use BoxLayout to provide insets around the label. | |
| 200 scoped_ptr<View> view(new View()); | |
| 201 view->SetLayoutManager( | |
| 202 new views::BoxLayout(views::BoxLayout::kVertical, | |
| 203 GetBubbleFrameView()->GetTitleInsets().left(), | |
| 204 views::kRelatedControlVerticalSpacing, 0)); | |
| 205 view->SetBorder( | |
| 206 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); | |
| 207 view->set_background( | |
| 208 views::Background::CreateSolidBackground(kLightShadingColor)); | |
| 209 | |
| 210 // Add a StyledLabel for each line of the legal message. | |
| 211 for (size_t i = 0; i < controller_->GetLegalMessageLines().size(); ++i) { | |
| 212 view->AddChildView(CreateLegalMessageLineLabel( | |
| 213 controller_->GetLegalMessageLines()[i], this) | |
| 214 .release()); | |
| 215 } | |
| 216 | |
| 217 return view; | |
| 218 } | |
| 219 | |
| 220 void SaveCardBubbleViews::Init() { | |
| 221 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 222 AddChildView(CreateMainContentView().release()); | |
| 223 if (!controller_->GetLegalMessageLines().empty()) | |
| 224 AddChildView(CreateFootnoteView().release()); | |
| 225 | |
| 150 set_margins(gfx::Insets(1, 0, 1, 0)); | 226 set_margins(gfx::Insets(1, 0, 1, 0)); |
| 151 Layout(); | |
| 152 } | 227 } |
| 153 | 228 |
| 154 } // namespace autofill | 229 } // namespace autofill |
| OLD | NEW |