Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/ui/views/passwords/account_chooser_dialog_view.cc

Issue 2869683003: Views/Harmony: Remove references to layout constants in c/b/u/v/passwords. (Closed)
Patch Set: Review comments + other whitespace changes. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 constexpr int kVerticalAvatarMargin = 8;
33 34
34 // An identifier for views::ColumnSet. 35 // An identifier for views::ColumnSet.
35 enum ColumnSetType { 36 enum ColumnSetType {
36 SINGLE_VIEW_COLUMN_SET, 37 SINGLE_VIEW_COLUMN_SET,
37 SINGLE_VIEW_COLUMN_SET_NO_PADDING, 38 SINGLE_VIEW_COLUMN_SET_NO_PADDING,
38 }; 39 };
39 40
40 // Construct a |type| ColumnSet and add it to |layout|. 41 // Construct a |type| ColumnSet and add it to |layout|.
41 void BuildColumnSet(ColumnSetType type, views::GridLayout* layout) { 42 void BuildColumnSet(ColumnSetType type, views::GridLayout* layout) {
42 views::ColumnSet* column_set = layout->AddColumnSet(type); 43 views::ColumnSet* column_set = layout->AddColumnSet(type);
43 bool padding = (type == SINGLE_VIEW_COLUMN_SET); 44 const int horizontal_padding =
44 if (padding) 45 type == SINGLE_VIEW_COLUMN_SET
45 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); 46 ? ChromeLayoutProvider::Get()->GetDistanceMetric(
47 DISTANCE_DIALOG_BUTTON_MARGIN)
48 : 0;
49 column_set->AddPaddingColumn(0, horizontal_padding);
46 column_set->AddColumn(views::GridLayout::FILL, 50 column_set->AddColumn(views::GridLayout::FILL,
47 views::GridLayout::FILL, 51 views::GridLayout::FILL,
48 1, 52 1,
49 views::GridLayout::USE_PREF, 53 views::GridLayout::USE_PREF,
50 0, 54 0,
51 0); 55 0);
52 if (padding) 56 column_set->AddPaddingColumn(0, horizontal_padding);
53 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
54 } 57 }
55 58
56 views::StyledLabel::RangeStyleInfo GetLinkStyle() { 59 views::StyledLabel::RangeStyleInfo GetLinkStyle() {
57 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink(); 60 auto result = views::StyledLabel::RangeStyleInfo::CreateForLink();
58 result.disable_line_wrapping = false; 61 result.disable_line_wrapping = false;
59 return result; 62 return result;
60 } 63 }
61 64
62 Profile* GetProfileFromWebContents(content::WebContents* web_contents) { 65 Profile* GetProfileFromWebContents(content::WebContents* web_contents) {
63 if (!web_contents) 66 if (!web_contents)
(...skipping 10 matching lines...) Expand all
74 list_view->SetLayoutManager( 77 list_view->SetLayoutManager(
75 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 78 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
76 int item_height = 0; 79 int item_height = 0;
77 for (const auto& form : forms) { 80 for (const auto& form : forms) {
78 std::pair<base::string16, base::string16> titles = 81 std::pair<base::string16, base::string16> titles =
79 GetCredentialLabelsForAccountChooser(*form); 82 GetCredentialLabelsForAccountChooser(*form);
80 CredentialsItemView* credential_view = new CredentialsItemView( 83 CredentialsItemView* credential_view = new CredentialsItemView(
81 button_listener, titles.first, titles.second, kButtonHoverColor, 84 button_listener, titles.first, titles.second, kButtonHoverColor,
82 form.get(), request_context); 85 form.get(), request_context);
83 credential_view->SetLowerLabelColor(kAutoSigninTextColor); 86 credential_view->SetLowerLabelColor(kAutoSigninTextColor);
84 credential_view->SetBorder(views::CreateEmptyBorder( 87 const int horizontal_padding =
85 kVerticalAvatarMargin, views::kButtonHEdgeMarginNew, 88 ChromeLayoutProvider::Get()->GetDistanceMetric(
86 kVerticalAvatarMargin, views::kButtonHEdgeMarginNew)); 89 DISTANCE_DIALOG_BUTTON_MARGIN);
90 credential_view->SetBorder(
91 views::CreateEmptyBorder(kVerticalAvatarMargin, horizontal_padding,
92 kVerticalAvatarMargin, horizontal_padding));
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
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_BUBBLE_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 bubble_insets =
221 layout_provider->GetInsetsMetric(views::INSETS_BUBBLE_CONTENTS);
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 bubble_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 // DialogClientView adds more vertical padding for space above the buttons.
tapted 2017/05/12 03:36:10 nit: this comment probably not needed, since `bubb
Patti Lor 2017/05/15 01:53:48 Done.
219 // the buttons. 230 layout->AddPaddingRow(0, bubble_insets.bottom());
220 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 231 layout->AddPaddingRow(
tapted 2017/05/12 03:36:10 did you mean to keep this second row? (if DialogCl
Patti Lor 2017/05/15 01:53:48 Deleted! Thanks :)
232 0, layout_provider->GetInsetsMetric(views::INSETS_DIALOG_BUTTON).top());
221 } 233 }
222 234
223 AccountChooserPrompt* CreateAccountChooserPromptView( 235 AccountChooserPrompt* CreateAccountChooserPromptView(
224 PasswordDialogController* controller, content::WebContents* web_contents) { 236 PasswordDialogController* controller, content::WebContents* web_contents) {
225 return new AccountChooserDialogView(controller, web_contents); 237 return new AccountChooserDialogView(controller, web_contents);
226 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698