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

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: Fix warning which causes one of the bots to fail 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_delegate.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 ChromeLayoutDelegate* layout_delegate = ChromeLayoutDelegate::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 (layout_delegate->UseExtraDialogPadding())
57 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); 57 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing);
58 column_set->AddColumn(layout_delegate->GetControlLabelGridAlignment(), 58 column_set->AddColumn(layout_delegate->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, layout_delegate->GetDistanceMetric(
62 layout_delegate->GetMetric( 62 ChromeDistanceMetric::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 (layout_delegate->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,
77 0, 76 layout_delegate->GetDistanceMetric(
78 layout_delegate->GetMetric( 77 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL));
79 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING));
80 layout->StartRow(0, single_column_view_set_id); 78 layout->StartRow(0, single_column_view_set_id);
81 layout->AddView(message_label_); 79 layout->AddView(message_label_);
82 } 80 }
83 81
84 layout->AddPaddingRow( 82 layout->AddPaddingRow(
85 0, 83 0, layout_delegate->GetDistanceMetric(
86 layout_delegate->GetMetric( 84 ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL_LARGE));
87 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING_LARGE));
88 85
89 layout->StartRow(0, labels_column_set_id); 86 layout->StartRow(0, labels_column_set_id);
90 layout->AddView(username_label_); 87 layout->AddView(username_label_);
91 layout->AddView(username_field_); 88 layout->AddView(username_field_);
92 89
93 layout->AddPaddingRow( 90 layout->AddPaddingRow(0, layout_delegate->GetDistanceMetric(
94 0, 91 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL));
95 layout_delegate->GetMetric(
96 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING));
97 92
98 layout->StartRow(0, labels_column_set_id); 93 layout->StartRow(0, labels_column_set_id);
99 layout->AddView(password_label_); 94 layout->AddView(password_label_);
100 layout->AddView(password_field_); 95 layout->AddView(password_field_);
101 96
102 if (layout_delegate->UseExtraDialogPadding()) { 97 if (layout_delegate->UseExtraDialogPadding()) {
103 layout->AddPaddingRow( 98 layout->AddPaddingRow(
104 0, 99 0, layout_delegate->GetDistanceMetric(
105 layout_delegate->GetMetric( 100 ChromeDistanceMetric::UNRELATED_CONTROL_VERTICAL));
106 LayoutDelegate::Metric::UNRELATED_CONTROL_VERTICAL_SPACING));
107 } 101 }
108 102
109 if (login_model_data) { 103 if (login_model_data) {
110 login_model_->AddObserverAndDeliverCredentials(this, 104 login_model_->AddObserverAndDeliverCredentials(this,
111 login_model_data->form); 105 login_model_data->form);
112 } 106 }
113 } 107 }
114 108
115 LoginView::~LoginView() { 109 LoginView::~LoginView() {
116 if (login_model_) 110 if (login_model_)
(...skipping 27 matching lines...) Expand all
144 138
145 void LoginView::OnLoginModelDestroying() { 139 void LoginView::OnLoginModelDestroying() {
146 login_model_->RemoveObserver(this); 140 login_model_->RemoveObserver(this);
147 login_model_ = NULL; 141 login_model_ = NULL;
148 } 142 }
149 143
150 const char* LoginView::GetClassName() const { 144 const char* LoginView::GetClassName() const {
151 return "LoginView"; 145 return "LoginView";
152 } 146 }
153 147
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698