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 |
116 // Set up ColumnSet that will contain the buttons and "learn more" link. | 132 // Set up ColumnSet that will contain the buttons and "learn more" link. |
117 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); | 133 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); |
118 cs->AddPaddingColumn(0, horizontal_inset); | 134 cs->AddPaddingColumn(0, horizontal_inset); |
119 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 135 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
120 GridLayout::USE_PREF, 0, 0); | 136 GridLayout::USE_PREF, 0, 0); |
121 cs->AddPaddingColumn(1, 0); | 137 cs->AddPaddingColumn(1, 0); |
122 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 138 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
123 GridLayout::USE_PREF, 0, 0); | 139 GridLayout::USE_PREF, 0, 0); |
124 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | 140 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
125 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 141 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
126 GridLayout::USE_PREF, 0, 0); | 142 GridLayout::USE_PREF, 0, 0); |
127 cs->AddPaddingColumn(0, horizontal_inset); | 143 cs->AddPaddingColumn(0, horizontal_inset); |
128 | 144 |
129 // Create "learn more" link and add it to layout. | 145 // Create "learn more" link and add it to layout. |
130 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 146 learn_more_link_ = new views::Link(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 147 learn_more_link_->SetUnderline(false); |
131 learn_more_link_->set_listener(this); | 148 learn_more_link_->set_listener(this); |
132 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); | 149 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); |
133 layout->AddView(learn_more_link_); | 150 layout->AddView(learn_more_link_); |
134 | 151 |
135 // Create accept button. | 152 // Create accept button. |
136 save_button_ = new views::BlueButton( | 153 save_button_ = new views::BlueButton( |
137 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); | 154 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT)); |
138 save_button_->SetIsDefault(true); | 155 save_button_->SetIsDefault(true); |
139 | 156 |
140 // Create cancel button. | 157 // Create cancel button. |
141 cancel_button_ = new views::LabelButton( | 158 cancel_button_ = new views::LabelButton( |
142 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); | 159 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY)); |
143 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); | 160 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); |
144 | 161 |
145 if (kIsOkButtonOnLeftSide) { | 162 if (kIsOkButtonOnLeftSide) { |
146 layout->AddView(save_button_); | 163 layout->AddView(save_button_); |
147 layout->AddView(cancel_button_); | 164 layout->AddView(cancel_button_); |
148 } else { | 165 } else { |
149 layout->AddView(cancel_button_); | 166 layout->AddView(cancel_button_); |
150 layout->AddView(save_button_); | 167 layout->AddView(save_button_); |
151 } | 168 } |
152 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 169 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
153 | 170 |
| 171 return view; |
| 172 } |
| 173 |
| 174 // Create view containing the legal message text. |
| 175 views::View* SaveCardBubbleViews::CreateFootnoteView() { |
| 176 // Use BoxLayout to provide insets around the label. |
| 177 View* view = new View(); |
| 178 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); |
| 179 view->SetLayoutManager( |
| 180 new views::BoxLayout(views::BoxLayout::kHorizontal, horizontal_inset, |
| 181 views::kRelatedControlVerticalSpacing, 0)); |
| 182 view->SetBorder( |
| 183 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kSubtleBorderColor)); |
| 184 view->set_background( |
| 185 views::Background::CreateSolidBackground(kLightShadingColor)); |
| 186 |
| 187 // Create the StyledLabel and add all of legal message's links. |
| 188 views::StyledLabel* label = |
| 189 new views::StyledLabel(controller_->GetLegalMessage(), this); |
| 190 const std::vector<gfx::Range>& ranges = |
| 191 controller_->GetLegalMessageLinkRanges(); |
| 192 for (size_t i = 0; i < ranges.size(); ++i) { |
| 193 label->AddStyleRange(ranges[i], |
| 194 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 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 |