| 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/password_dialog_controller.h" | 9 #include "chrome/browser/ui/passwords/password_dialog_controller.h" |
| 10 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 10 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/autofill/core/common/password_form.h" | 12 #include "components/autofill/core/common/password_form.h" |
| 13 #include "components/constrained_window/constrained_window_views.h" | 13 #include "components/constrained_window/constrained_window_views.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/strings/grit/ui_strings.h" | 17 #include "ui/strings/grit/ui_strings.h" |
| 18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 19 #include "ui/views/controls/styled_label.h" | 19 #include "ui/views/controls/styled_label.h" |
| 20 #include "ui/views/layout/grid_layout.h" | 20 #include "ui/views/layout/grid_layout.h" |
| 21 #include "ui/views/layout/layout_constants.h" | 21 #include "ui/views/layout/layout_constants.h" |
| 22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const int kVerticalAvatarMargin = 8; |
| 27 |
| 26 // An identifier for views::ColumnSet. | 28 // An identifier for views::ColumnSet. |
| 27 enum ColumnSetType { | 29 enum ColumnSetType { |
| 28 SINGLE_VIEW_COLUMN_SET, | 30 SINGLE_VIEW_COLUMN_SET, |
| 31 SINGLE_VIEW_COLUMN_SET_NO_PADDING, |
| 29 }; | 32 }; |
| 30 | 33 |
| 31 // Construct a SINGLE_VIEW_COLUMN_SET ColumnSet and add it to |layout|. | 34 // Construct a |type| ColumnSet and add it to |layout|. |
| 32 void BuildOneColumnSet(views::GridLayout* layout) { | 35 void BuildColumnSet(ColumnSetType type, views::GridLayout* layout) { |
| 33 views::ColumnSet* column_set = layout->AddColumnSet(SINGLE_VIEW_COLUMN_SET); | 36 views::ColumnSet* column_set = layout->AddColumnSet(type); |
| 34 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | 37 bool padding = (type == SINGLE_VIEW_COLUMN_SET); |
| 38 if (padding) |
| 39 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); |
| 35 column_set->AddColumn(views::GridLayout::FILL, | 40 column_set->AddColumn(views::GridLayout::FILL, |
| 36 views::GridLayout::FILL, | 41 views::GridLayout::FILL, |
| 37 1, | 42 1, |
| 38 views::GridLayout::USE_PREF, | 43 views::GridLayout::USE_PREF, |
| 39 0, | 44 0, |
| 40 0); | 45 0); |
| 41 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | 46 if (padding) |
| 47 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); |
| 42 } | 48 } |
| 43 | 49 |
| 44 views::StyledLabel::RangeStyleInfo GetLinkStyle() { | 50 views::StyledLabel::RangeStyleInfo GetLinkStyle() { |
| 45 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink(); | 51 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| 46 result.disable_line_wrapping = false; | 52 result.disable_line_wrapping = false; |
| 47 return result; | 53 return result; |
| 48 } | 54 } |
| 49 | 55 |
| 50 Profile* GetProfileFromWebContents(content::WebContents* web_contents) { | 56 Profile* GetProfileFromWebContents(content::WebContents* web_contents) { |
| 51 if (!web_contents) | 57 if (!web_contents) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 119 |
| 114 void AccountChooserDialogView::StyledLabelLinkClicked(views::StyledLabel* label, | 120 void AccountChooserDialogView::StyledLabelLinkClicked(views::StyledLabel* label, |
| 115 const gfx::Range& range, | 121 const gfx::Range& range, |
| 116 int event_flags) { | 122 int event_flags) { |
| 117 controller_->OnSmartLockLinkClicked(); | 123 controller_->OnSmartLockLinkClicked(); |
| 118 } | 124 } |
| 119 | 125 |
| 120 void AccountChooserDialogView::ButtonPressed(views::Button* sender, | 126 void AccountChooserDialogView::ButtonPressed(views::Button* sender, |
| 121 const ui::Event& event) { | 127 const ui::Event& event) { |
| 122 CredentialsItemView* view = static_cast<CredentialsItemView*>(sender); | 128 CredentialsItemView* view = static_cast<CredentialsItemView*>(sender); |
| 123 controller_->OnChooseCredentials(*view->form(), | 129 controller_->OnChooseCredentials( |
| 124 view->credential_type()); | 130 *view->form(), |
| 131 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 125 } | 132 } |
| 126 | 133 |
| 127 void AccountChooserDialogView::InitWindow() { | 134 void AccountChooserDialogView::InitWindow() { |
| 128 views::GridLayout* layout = new views::GridLayout(this); | 135 views::GridLayout* layout = new views::GridLayout(this); |
| 129 SetLayoutManager(layout); | 136 SetLayoutManager(layout); |
| 130 BuildOneColumnSet(layout); | 137 BuildColumnSet(SINGLE_VIEW_COLUMN_SET, layout); |
| 131 | 138 |
| 132 // Create the title. | 139 // Create the title. |
| 133 std::pair<base::string16, gfx::Range> title_content = | 140 std::pair<base::string16, gfx::Range> title_content = |
| 134 controller_->GetAccoutChooserTitle(); | 141 controller_->GetAccoutChooserTitle(); |
| 135 views::StyledLabel* title_label = | 142 views::StyledLabel* title_label = |
| 136 new views::StyledLabel(title_content.first, this); | 143 new views::StyledLabel(title_content.first, this); |
| 137 title_label->SetBaseFontList( | 144 title_label->SetBaseFontList( |
| 138 ui::ResourceBundle::GetSharedInstance().GetFontList( | 145 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 139 ui::ResourceBundle::MediumFont)); | 146 ui::ResourceBundle::MediumFont)); |
| 140 if (!title_content.second.is_empty()) { | 147 if (!title_content.second.is_empty()) { |
| 141 title_label->AddStyleRange(title_content.second, GetLinkStyle()); | 148 title_label->AddStyleRange(title_content.second, GetLinkStyle()); |
| 142 } | 149 } |
| 143 layout->StartRowWithPadding(0, SINGLE_VIEW_COLUMN_SET, 0, kTitleTopInset); | 150 layout->StartRowWithPadding(0, SINGLE_VIEW_COLUMN_SET, 0, kTitleTopInset); |
| 144 layout->AddView(title_label); | 151 layout->AddView(title_label); |
| 145 layout->AddPaddingRow(0, 2*views::kRelatedControlVerticalSpacing); | 152 layout->AddPaddingRow(0, 2*views::kRelatedControlVerticalSpacing); |
| 146 | 153 |
| 147 // Show credentials. | 154 // Show credentials. |
| 148 net::URLRequestContextGetter* request_context = | 155 net::URLRequestContextGetter* request_context = |
| 149 GetProfileFromWebContents(web_contents_)->GetRequestContext(); | 156 GetProfileFromWebContents(web_contents_)->GetRequestContext(); |
| 157 BuildColumnSet(SINGLE_VIEW_COLUMN_SET_NO_PADDING, layout); |
| 150 for (const auto& form : controller_->GetLocalForms()) { | 158 for (const auto& form : controller_->GetLocalForms()) { |
| 151 const base::string16& upper_string = | 159 const base::string16& upper_string = |
| 152 form->display_name.empty() ? form->username_value : form->display_name; | 160 form->display_name.empty() ? form->username_value : form->display_name; |
| 153 base::string16 lower_string; | 161 base::string16 lower_string; |
| 154 if (form->federation_url.is_empty()) { | 162 if (form->federation_url.is_empty()) { |
| 155 if (!form->display_name.empty()) | 163 if (!form->display_name.empty()) |
| 156 lower_string = form->username_value; | 164 lower_string = form->username_value; |
| 157 } else { | 165 } else { |
| 158 lower_string = l10n_util::GetStringFUTF16( | 166 lower_string = l10n_util::GetStringFUTF16( |
| 159 IDS_PASSWORDS_VIA_FEDERATION, | 167 IDS_PASSWORDS_VIA_FEDERATION, |
| 160 base::UTF8ToUTF16(form->federation_url.host())); | 168 base::UTF8ToUTF16(form->federation_url.host())); |
| 161 } | 169 } |
| 162 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 170 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET_NO_PADDING); |
| 163 layout->AddView(new CredentialsItemView( | 171 CredentialsItemView* view = new CredentialsItemView( |
| 164 this, form.get(), | 172 this, upper_string, lower_string, kButtonHoverColor, |
| 165 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD, | 173 form.get(), request_context); |
| 166 upper_string, lower_string, request_context)); | 174 view->SetLowerLabelColor(kAutoSigninTextColor); |
| 175 view->SetBorder(views::Border::CreateEmptyBorder( |
| 176 kVerticalAvatarMargin, views::kButtonHEdgeMarginNew, |
| 177 kVerticalAvatarMargin, views::kButtonHEdgeMarginNew)); |
| 178 layout->AddView(view); |
| 167 } | 179 } |
| 168 // DialogClientView adds kRelatedControlVerticalSpacing padding once more for | 180 // DialogClientView adds kRelatedControlVerticalSpacing padding once more for |
| 169 // the buttons. | 181 // the buttons. |
| 170 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 182 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 171 } | 183 } |
| 172 | 184 |
| 173 AccountChooserPrompt* CreateAccountChooserPromptView( | 185 AccountChooserPrompt* CreateAccountChooserPromptView( |
| 174 PasswordDialogController* controller, content::WebContents* web_contents) { | 186 PasswordDialogController* controller, content::WebContents* web_contents) { |
| 175 return new AccountChooserDialogView(controller, web_contents); | 187 return new AccountChooserDialogView(controller, web_contents); |
| 176 } | 188 } |
| OLD | NEW |