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

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

Powered by Google App Engine
This is Rietveld 408576698