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 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 controller_->OnCancelButton(); | 91 controller_->OnCancelButton(); |
| 89 } | 92 } |
| 90 GetWidget()->Close(); | 93 GetWidget()->Close(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { | 96 void SaveCardBubbleViews::LinkClicked(views::Link* source, int event_flags) { |
| 94 DCHECK_EQ(source, learn_more_link_); | 97 DCHECK_EQ(source, learn_more_link_); |
| 95 controller_->OnLearnMoreClicked(); | 98 controller_->OnLearnMoreClicked(); |
| 96 } | 99 } |
| 97 | 100 |
| 98 void SaveCardBubbleViews::Init() { | 101 void SaveCardBubbleViews::StyledLabelLinkClicked(const gfx::Range& range, |
| 102 int event_flags) { | |
| 103 controller_->OnLegalMessageLinkClicked(range); | |
| 104 } | |
| 105 | |
| 106 // Create view containing everything except for the footnote. | |
| 107 // ASCII art diagram of view contents: | |
| 108 // +---------------------------------------------------------------------------+ | |
| 109 // | | | |
| 110 // | learn_more_link_ save_button_ cancel_button_ | | |
| 111 // | | | |
| 112 // +---------------------------------------------------------------------------+ | |
| 113 views::View* SaveCardBubbleViews::CreateMainContentView() { | |
| 99 enum { | 114 enum { |
| 100 COLUMN_SET_ID_MESSAGE, | 115 COLUMN_SET_ID_MESSAGE, |
| 101 COLUMN_SET_ID_BUTTONS, | 116 COLUMN_SET_ID_BUTTONS, |
| 102 }; | 117 }; |
| 103 | 118 |
| 104 GridLayout* layout = new GridLayout(this); | 119 View* view = new View(); |
| 105 SetLayoutManager(layout); | 120 GridLayout* layout = new GridLayout(view); |
| 121 view->SetLayoutManager(layout); | |
| 106 | 122 |
| 107 // Set up ColumnSet that will contain the full-width message text. | 123 // Set up ColumnSet that will contain the full-width message text. |
| 108 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); | 124 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); |
| 109 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); | 125 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); |
| 110 cs->AddPaddingColumn(0, horizontal_inset); | 126 cs->AddPaddingColumn(0, horizontal_inset); |
| 111 // TODO(bondd): Current dialog layout has no message text, but future layouts | 127 // 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. | 128 // will. This padding column is used until then to set the dialog width. |
| 113 cs->AddPaddingColumn(1, kWidthOfMessageText); | 129 cs->AddPaddingColumn(1, kWidthOfMessageText); |
| 114 cs->AddPaddingColumn(0, horizontal_inset); | 130 cs->AddPaddingColumn(0, horizontal_inset); |
| 115 | 131 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 144 | 160 |
| 145 if (kIsOkButtonOnLeftSide) { | 161 if (kIsOkButtonOnLeftSide) { |
| 146 layout->AddView(save_button_); | 162 layout->AddView(save_button_); |
| 147 layout->AddView(cancel_button_); | 163 layout->AddView(cancel_button_); |
| 148 } else { | 164 } else { |
| 149 layout->AddView(cancel_button_); | 165 layout->AddView(cancel_button_); |
| 150 layout->AddView(save_button_); | 166 layout->AddView(save_button_); |
| 151 } | 167 } |
| 152 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 168 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 153 | 169 |
| 170 return view; | |
| 171 } | |
| 172 | |
| 173 // Create view containing the legal message text. | |
| 174 views::View* SaveCardBubbleViews::CreateFootnoteView() { | |
| 175 // Use BoxLayout to provide insets around the label. | |
| 176 View* view = new View(); | |
| 177 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); | |
| 178 view->SetLayoutManager( | |
| 179 new views::BoxLayout(views::BoxLayout::kHorizontal, horizontal_inset, | |
| 180 views::kRelatedControlVerticalSpacing, 0)); | |
| 181 view->SetBorder( | |
| 182 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); | |
| 183 view->set_background( | |
| 184 views::Background::CreateSolidBackground(kLightShadingColor)); | |
|
Evan Stade
2015/11/07 03:03:19
this should probably actually use color_utils::Ble
bondd
2015/11/11 01:53:36
How about I change all of these at once in a follo
Evan Stade
2015/11/11 22:22:54
sure, can you file a bug for it
bondd
2015/11/13 01:19:52
Done. https://code.google.com/p/chromium/issues/de
| |
| 185 | |
| 186 // Create the StyledLabel. | |
| 187 views::StyledLabel* label = | |
| 188 new views::StyledLabel(controller_->GetLegalMessage(), this); | |
| 189 views::StyledLabel::RangeStyleInfo style = | |
| 190 views::StyledLabel::RangeStyleInfo::CreateForLink(); | |
|
Evan Stade
2015/11/07 03:03:19
no need to put this here, you're copying it over a
Justin Donnelly
2015/11/09 16:04:35
The default for CreateForLink in not underlined. (
Evan Stade
2015/11/09 18:59:10
uh, well it's a little different. A standalone lin
bondd
2015/11/11 01:53:36
Done. And I removed the underline from the "Learn
| |
| 191 | |
| 192 // Add all of the label's links. | |
| 193 for (size_t i = 0; i < controller_->GetLegalMessageNumLinks(); ++i) { | |
| 194 label->AddStyleRange(controller_->GetLegalMessageLinkRange(i), style); | |
| 195 } | |
| 196 label->SizeToFit(kWidthOfMessageText); | |
| 197 view->AddChildView(label); | |
| 198 | |
| 199 return view; | |
| 200 } | |
| 201 | |
| 202 void SaveCardBubbleViews::Init() { | |
| 203 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 204 AddChildView(CreateMainContentView()); | |
| 205 if (!controller_->GetLegalMessage().empty()) | |
| 206 AddChildView(CreateFootnoteView()); | |
| 207 | |
| 154 set_margins(gfx::Insets(1, 0, 1, 0)); | 208 set_margins(gfx::Insets(1, 0, 1, 0)); |
| 155 Layout(); | |
| 156 } | 209 } |
| 157 | 210 |
| 158 } // namespace autofill | 211 } // namespace autofill |
| OLD | NEW |