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

Side by Side Diff: chrome/browser/ui/views/login_view.cc

Issue 2758323002: Broke out layout metric information from ViewsDelegate to LayoutProvider (Closed)
Patch Set: Final feedback addressed Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/login_view.h" 5 #include "chrome/browser/ui/views/login_view.h"
6 6
7 #include "chrome/browser/ui/views/harmony/layout_delegate.h" 7 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
8 #include "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/views/controls/label.h" 10 #include "ui/views/controls/label.h"
11 #include "ui/views/controls/textfield/textfield.h" 11 #include "ui/views/controls/textfield/textfield.h"
12 #include "ui/views/layout/grid_layout.h" 12 #include "ui/views/layout/grid_layout.h"
13 13
14 static const int kMessageWidth = 320; 14 static const int kMessageWidth = 320;
15 static const int kTextfieldStackHorizontalSpacing = 30; 15 static const int kTextfieldStackHorizontalSpacing = 30;
16 16
17 using password_manager::LoginModel; 17 using password_manager::LoginModel;
18 using views::GridLayout; 18 using views::GridLayout;
19 19
20 /////////////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////////////
21 // LoginView, public: 21 // LoginView, public:
22 22
23 LoginView::LoginView(const base::string16& authority, 23 LoginView::LoginView(const base::string16& authority,
24 const base::string16& explanation, 24 const base::string16& explanation,
25 LoginHandler::LoginModelData* login_model_data) 25 LoginHandler::LoginModelData* login_model_data)
26 : username_field_(new views::Textfield()), 26 : username_field_(new views::Textfield()),
27 password_field_(new views::Textfield()), 27 password_field_(new views::Textfield()),
28 username_label_(new views::Label( 28 username_label_(new views::Label(
29 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_USERNAME_FIELD))), 29 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_USERNAME_FIELD))),
30 password_label_(new views::Label( 30 password_label_(new views::Label(
31 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_PASSWORD_FIELD))), 31 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_PASSWORD_FIELD))),
32 authority_label_(new views::Label(authority)), 32 authority_label_(new views::Label(authority)),
33 message_label_(nullptr), 33 message_label_(nullptr),
34 login_model_(login_model_data ? login_model_data->model : nullptr) { 34 login_model_(login_model_data ? login_model_data->model : nullptr) {
35 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 35 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
36 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 36 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
37 37
38 authority_label_->SetMultiLine(true); 38 authority_label_->SetMultiLine(true);
39 authority_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 39 authority_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
40 authority_label_->SetAllowCharacterBreak(true); 40 authority_label_->SetAllowCharacterBreak(true);
41 41
42 // Initialize the Grid Layout Manager used for this dialog box. 42 // Initialize the Grid Layout Manager used for this dialog box.
43 GridLayout* layout = GridLayout::CreatePanel(this); 43 GridLayout* layout = GridLayout::CreatePanel(this);
44 44
45 // Add the column set for the information message at the top of the dialog 45 // Add the column set for the information message at the top of the dialog
46 // box. 46 // box.
47 const int single_column_view_set_id = 0; 47 const int single_column_view_set_id = 0;
48 views::ColumnSet* column_set = 48 views::ColumnSet* column_set =
49 layout->AddColumnSet(single_column_view_set_id); 49 layout->AddColumnSet(single_column_view_set_id);
50 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 50 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
51 GridLayout::FIXED, kMessageWidth, 0); 51 GridLayout::FIXED, kMessageWidth, 0);
52 52
53 // Add the column set for the user name and password fields and labels. 53 // Add the column set for the user name and password fields and labels.
54 const int labels_column_set_id = 1; 54 const int labels_column_set_id = 1;
55 column_set = layout->AddColumnSet(labels_column_set_id); 55 column_set = layout->AddColumnSet(labels_column_set_id);
56 if (layout_delegate->UseExtraDialogPadding()) 56 if (provider->UseExtraDialogPadding())
57 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); 57 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing);
58 column_set->AddColumn(layout_delegate->GetControlLabelGridAlignment(), 58 column_set->AddColumn(provider->GetControlLabelGridAlignment(),
59 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); 59 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
60 column_set->AddPaddingColumn( 60 column_set->AddPaddingColumn(
61 0, 61 0,
62 layout_delegate->GetMetric( 62 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_HORIZONTAL));
63 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING));
64 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 63 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
65 GridLayout::USE_PREF, 0, 0); 64 GridLayout::USE_PREF, 0, 0);
66 if (layout_delegate->UseExtraDialogPadding()) 65 if (provider->UseExtraDialogPadding())
67 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); 66 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing);
68 67
69 layout->StartRow(0, single_column_view_set_id); 68 layout->StartRow(0, single_column_view_set_id);
70 layout->AddView(authority_label_); 69 layout->AddView(authority_label_);
71 if (!explanation.empty()) { 70 if (!explanation.empty()) {
72 message_label_ = new views::Label(explanation); 71 message_label_ = new views::Label(explanation);
73 message_label_->SetMultiLine(true); 72 message_label_->SetMultiLine(true);
74 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 73 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
75 message_label_->SetAllowCharacterBreak(true); 74 message_label_->SetAllowCharacterBreak(true);
76 layout->AddPaddingRow( 75 layout->AddPaddingRow(0, provider->GetDistanceMetric(
77 0, 76 views::DISTANCE_RELATED_CONTROL_VERTICAL));
78 layout_delegate->GetMetric(
79 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING));
80 layout->StartRow(0, single_column_view_set_id); 77 layout->StartRow(0, single_column_view_set_id);
81 layout->AddView(message_label_); 78 layout->AddView(message_label_);
82 } 79 }
83 80
84 layout->AddPaddingRow( 81 layout->AddPaddingRow(0, provider->GetDistanceMetric(
85 0, 82 DISTANCE_UNRELATED_CONTROL_VERTICAL_LARGE));
86 layout_delegate->GetMetric(
87 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING_LARGE));
88 83
89 layout->StartRow(0, labels_column_set_id); 84 layout->StartRow(0, labels_column_set_id);
90 layout->AddView(username_label_); 85 layout->AddView(username_label_);
91 layout->AddView(username_field_); 86 layout->AddView(username_field_);
92 87
93 layout->AddPaddingRow( 88 layout->AddPaddingRow(
94 0, 89 0, provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL));
95 layout_delegate->GetMetric(
96 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING));
97 90
98 layout->StartRow(0, labels_column_set_id); 91 layout->StartRow(0, labels_column_set_id);
99 layout->AddView(password_label_); 92 layout->AddView(password_label_);
100 layout->AddView(password_field_); 93 layout->AddView(password_field_);
101 94
102 if (layout_delegate->UseExtraDialogPadding()) { 95 if (provider->UseExtraDialogPadding()) {
103 layout->AddPaddingRow( 96 layout->AddPaddingRow(
104 0, 97 0, provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_VERTICAL));
105 layout_delegate->GetMetric(
106 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING));
107 } 98 }
108 99
109 if (login_model_data) { 100 if (login_model_data) {
110 login_model_->AddObserverAndDeliverCredentials(this, 101 login_model_->AddObserverAndDeliverCredentials(this,
111 login_model_data->form); 102 login_model_data->form);
112 } 103 }
113 } 104 }
114 105
115 LoginView::~LoginView() { 106 LoginView::~LoginView() {
116 if (login_model_) 107 if (login_model_)
(...skipping 27 matching lines...) Expand all
144 135
145 void LoginView::OnLoginModelDestroying() { 136 void LoginView::OnLoginModelDestroying() {
146 login_model_->RemoveObserver(this); 137 login_model_->RemoveObserver(this);
147 login_model_ = NULL; 138 login_model_ = NULL;
148 } 139 }
149 140
150 const char* LoginView::GetClassName() const { 141 const char* LoginView::GetClassName() const {
151 return "LoginView"; 142 return "LoginView";
152 } 143 }
153 144
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698