| 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/passwords/account_chooser_dialog_view.h" | 5 #include "chrome/browser/ui/views/passwords/account_chooser_dialog_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 9 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 10 #include "chrome/browser/ui/passwords/password_dialog_controller.h" | 10 #include "chrome/browser/ui/passwords/password_dialog_controller.h" |
| 11 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
| 11 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 12 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
| 12 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 13 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
| 14 #include "components/constrained_window/constrained_window_views.h" | 15 #include "components/constrained_window/constrained_window_views.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/strings/grit/ui_strings.h" | 19 #include "ui/strings/grit/ui_strings.h" |
| 19 #include "ui/views/border.h" | 20 #include "ui/views/border.h" |
| 20 #include "ui/views/controls/scroll_view.h" | 21 #include "ui/views/controls/scroll_view.h" |
| 21 #include "ui/views/controls/styled_label.h" | 22 #include "ui/views/controls/styled_label.h" |
| 22 #include "ui/views/layout/box_layout.h" | 23 #include "ui/views/layout/box_layout.h" |
| 23 #include "ui/views/layout/grid_layout.h" | 24 #include "ui/views/layout/grid_layout.h" |
| 24 #include "ui/views/layout/layout_constants.h" | 25 #include "ui/views/style/typography.h" |
| 25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Maximum height of the credential list. The unit is one row's height. | 30 // Maximum height of the credential list. The unit is one row's height. |
| 30 constexpr double kMaxHeightAccounts = 3.5; | 31 constexpr double kMaxHeightAccounts = 3.5; |
| 31 | 32 |
| 32 constexpr int kVerticalAvatarMargin = 8; | |
| 33 | |
| 34 // An identifier for views::ColumnSet. | 33 // An identifier for views::ColumnSet. |
| 35 enum ColumnSetType { | 34 enum ColumnSetType { |
| 36 SINGLE_VIEW_COLUMN_SET, | 35 SINGLE_VIEW_COLUMN_SET, |
| 37 SINGLE_VIEW_COLUMN_SET_NO_PADDING, | 36 SINGLE_VIEW_COLUMN_SET_NO_PADDING, |
| 38 }; | 37 }; |
| 39 | 38 |
| 40 // Construct a |type| ColumnSet and add it to |layout|. | 39 // Construct a |type| ColumnSet and add it to |layout|. |
| 41 void BuildColumnSet(ColumnSetType type, views::GridLayout* layout) { | 40 void BuildColumnSet(ColumnSetType type, views::GridLayout* layout) { |
| 42 views::ColumnSet* column_set = layout->AddColumnSet(type); | 41 views::ColumnSet* column_set = layout->AddColumnSet(type); |
| 43 bool padding = (type == SINGLE_VIEW_COLUMN_SET); | 42 const int horizontal_padding = |
| 44 if (padding) | 43 type == SINGLE_VIEW_COLUMN_SET |
| 45 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | 44 ? ChromeLayoutProvider::Get()->GetDistanceMetric( |
| 45 DISTANCE_DIALOG_BUTTON_MARGIN) |
| 46 : 0; |
| 47 column_set->AddPaddingColumn(0, horizontal_padding); |
| 46 column_set->AddColumn(views::GridLayout::FILL, | 48 column_set->AddColumn(views::GridLayout::FILL, |
| 47 views::GridLayout::FILL, | 49 views::GridLayout::FILL, |
| 48 1, | 50 1, |
| 49 views::GridLayout::USE_PREF, | 51 views::GridLayout::USE_PREF, |
| 50 0, | 52 0, |
| 51 0); | 53 0); |
| 52 if (padding) | 54 column_set->AddPaddingColumn(0, horizontal_padding); |
| 53 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | |
| 54 } | 55 } |
| 55 | 56 |
| 56 views::StyledLabel::RangeStyleInfo GetLinkStyle() { | 57 views::StyledLabel::RangeStyleInfo GetLinkStyle() { |
| 57 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink(); | 58 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| 58 result.disable_line_wrapping = false; | 59 result.disable_line_wrapping = false; |
| 59 return result; | 60 return result; |
| 60 } | 61 } |
| 61 | 62 |
| 62 Profile* GetProfileFromWebContents(content::WebContents* web_contents) { | 63 Profile* GetProfileFromWebContents(content::WebContents* web_contents) { |
| 63 if (!web_contents) | 64 if (!web_contents) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 list_view->SetLayoutManager( | 75 list_view->SetLayoutManager( |
| 75 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 76 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 76 int item_height = 0; | 77 int item_height = 0; |
| 77 for (const auto& form : forms) { | 78 for (const auto& form : forms) { |
| 78 std::pair<base::string16, base::string16> titles = | 79 std::pair<base::string16, base::string16> titles = |
| 79 GetCredentialLabelsForAccountChooser(*form); | 80 GetCredentialLabelsForAccountChooser(*form); |
| 80 CredentialsItemView* credential_view = new CredentialsItemView( | 81 CredentialsItemView* credential_view = new CredentialsItemView( |
| 81 button_listener, titles.first, titles.second, kButtonHoverColor, | 82 button_listener, titles.first, titles.second, kButtonHoverColor, |
| 82 form.get(), request_context); | 83 form.get(), request_context); |
| 83 credential_view->SetLowerLabelColor(kAutoSigninTextColor); | 84 credential_view->SetLowerLabelColor(kAutoSigninTextColor); |
| 84 credential_view->SetBorder(views::CreateEmptyBorder( | 85 ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get(); |
| 85 kVerticalAvatarMargin, views::kButtonHEdgeMarginNew, | 86 gfx::Insets dialog_insets = |
| 86 kVerticalAvatarMargin, views::kButtonHEdgeMarginNew)); | 87 layout_provider->GetInsetsMetric(views::INSETS_PANEL); |
| 88 const int vertical_padding = layout_provider->GetDistanceMetric( |
| 89 views::DISTANCE_RELATED_CONTROL_VERTICAL); |
| 90 credential_view->SetBorder( |
| 91 views::CreateEmptyBorder(vertical_padding, dialog_insets.left(), |
| 92 vertical_padding, dialog_insets.right())); |
| 87 item_height = std::max(item_height, credential_view->GetPreferredHeight()); | 93 item_height = std::max(item_height, credential_view->GetPreferredHeight()); |
| 88 list_view->AddChildView(credential_view); | 94 list_view->AddChildView(credential_view); |
| 89 } | 95 } |
| 90 views::ScrollView* scroll_view = new views::ScrollView; | 96 views::ScrollView* scroll_view = new views::ScrollView; |
| 91 scroll_view->ClipHeightTo(0, kMaxHeightAccounts * item_height); | 97 scroll_view->ClipHeightTo(0, kMaxHeightAccounts * item_height); |
| 92 scroll_view->SetContents(list_view); | 98 scroll_view->SetContents(list_view); |
| 93 return scroll_view; | 99 return scroll_view; |
| 94 } | 100 } |
| 95 | 101 |
| 96 } // namespace | 102 } // namespace |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 void AccountChooserDialogView::InitWindow() { | 197 void AccountChooserDialogView::InitWindow() { |
| 192 views::GridLayout* layout = new views::GridLayout(this); | 198 views::GridLayout* layout = new views::GridLayout(this); |
| 193 SetLayoutManager(layout); | 199 SetLayoutManager(layout); |
| 194 BuildColumnSet(SINGLE_VIEW_COLUMN_SET, layout); | 200 BuildColumnSet(SINGLE_VIEW_COLUMN_SET, layout); |
| 195 | 201 |
| 196 // Create the title. | 202 // Create the title. |
| 197 std::pair<base::string16, gfx::Range> title_content = | 203 std::pair<base::string16, gfx::Range> title_content = |
| 198 controller_->GetAccoutChooserTitle(); | 204 controller_->GetAccoutChooserTitle(); |
| 199 views::StyledLabel* title_label = | 205 views::StyledLabel* title_label = |
| 200 new views::StyledLabel(title_content.first, this); | 206 new views::StyledLabel(title_content.first, this); |
| 201 title_label->SetBaseFontList( | 207 title_label->SetBaseFontList(views::style::GetFont( |
| 202 ui::ResourceBundle::GetSharedInstance().GetFontList( | 208 views::style::CONTEXT_DIALOG_TITLE, views::style::STYLE_PRIMARY)); |
| 203 ui::ResourceBundle::MediumFont)); | 209 if (!title_content.second.is_empty()) |
| 204 if (!title_content.second.is_empty()) { | |
| 205 title_label->AddStyleRange(title_content.second, GetLinkStyle()); | 210 title_label->AddStyleRange(title_content.second, GetLinkStyle()); |
| 206 } | 211 |
| 207 layout->StartRowWithPadding(0, SINGLE_VIEW_COLUMN_SET, 0, kTitleTopInset); | 212 // Show the title. |
| 213 ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get(); |
| 214 layout->StartRowWithPadding( |
| 215 0, SINGLE_VIEW_COLUMN_SET, 0, |
| 216 layout_provider->GetInsetsMetric(views::INSETS_DIALOG_TITLE).top()); |
| 208 layout->AddView(title_label); | 217 layout->AddView(title_label); |
| 209 layout->AddPaddingRow(0, 2*views::kRelatedControlVerticalSpacing); | |
| 210 | 218 |
| 211 // Show credentials. | 219 // Show credentials. |
| 220 gfx::Insets dialog_insets = |
| 221 layout_provider->GetInsetsMetric(views::INSETS_PANEL); |
| 212 BuildColumnSet(SINGLE_VIEW_COLUMN_SET_NO_PADDING, layout); | 222 BuildColumnSet(SINGLE_VIEW_COLUMN_SET_NO_PADDING, layout); |
| 213 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET_NO_PADDING); | 223 layout->StartRowWithPadding(0, SINGLE_VIEW_COLUMN_SET_NO_PADDING, 0, |
| 224 dialog_insets.top()); |
| 214 layout->AddView(CreateCredentialsView( | 225 layout->AddView(CreateCredentialsView( |
| 215 controller_->GetLocalForms(), | 226 controller_->GetLocalForms(), |
| 216 this, | 227 this, |
| 217 GetProfileFromWebContents(web_contents_)->GetRequestContext())); | 228 GetProfileFromWebContents(web_contents_)->GetRequestContext())); |
| 218 // DialogClientView adds kRelatedControlVerticalSpacing padding once more for | 229 layout->AddPaddingRow(0, dialog_insets.bottom()); |
| 219 // the buttons. | |
| 220 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 221 } | 230 } |
| 222 | 231 |
| 223 AccountChooserPrompt* CreateAccountChooserPromptView( | 232 AccountChooserPrompt* CreateAccountChooserPromptView( |
| 224 PasswordDialogController* controller, content::WebContents* web_contents) { | 233 PasswordDialogController* controller, content::WebContents* web_contents) { |
| 225 return new AccountChooserDialogView(controller, web_contents); | 234 return new AccountChooserDialogView(controller, web_contents); |
| 226 } | 235 } |
| OLD | NEW |