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

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

Issue 2485083003: views: add layout delegates (Closed)
Patch Set: first round of fixes :) Created 4 years, 1 month 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"
8 #include "chrome/browser/ui/views/layout_utils.h"
7 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
8 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
9 #include "ui/views/controls/label.h" 11 #include "ui/views/controls/label.h"
10 #include "ui/views/controls/textfield/textfield.h" 12 #include "ui/views/controls/textfield/textfield.h"
11 #include "ui/views/layout/grid_layout.h" 13 #include "ui/views/layout/grid_layout.h"
12 #include "ui/views/layout/layout_constants.h"
13 14
14 static const int kMessageWidth = 320; 15 static const int kMessageWidth = 320;
15 static const int kTextfieldStackHorizontalSpacing = 30; 16 static const int kTextfieldStackHorizontalSpacing = 30;
16 17
17 using password_manager::LoginModel; 18 using password_manager::LoginModel;
18 using views::GridLayout; 19 using views::GridLayout;
19 20
20 /////////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////////
21 // LoginView, public: 22 // LoginView, public:
22 23
23 LoginView::LoginView(const base::string16& authority, 24 LoginView::LoginView(const base::string16& authority,
24 const base::string16& explanation, 25 const base::string16& explanation,
25 LoginHandler::LoginModelData* login_model_data) 26 LoginHandler::LoginModelData* login_model_data)
26 : username_field_(new views::Textfield()), 27 : username_field_(new views::Textfield()),
27 password_field_(new views::Textfield()), 28 password_field_(new views::Textfield()),
28 username_label_(new views::Label( 29 username_label_(new views::Label(
29 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_USERNAME_FIELD))), 30 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_USERNAME_FIELD))),
30 password_label_(new views::Label( 31 password_label_(new views::Label(
31 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_PASSWORD_FIELD))), 32 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_PASSWORD_FIELD))),
32 authority_label_(new views::Label(authority)), 33 authority_label_(new views::Label(authority)),
33 message_label_(nullptr), 34 message_label_(nullptr),
34 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::GetActiveInstance();
35 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 37 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
36 38
37 authority_label_->SetMultiLine(true); 39 authority_label_->SetMultiLine(true);
38 authority_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 40 authority_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
39 authority_label_->SetAllowCharacterBreak(true); 41 authority_label_->SetAllowCharacterBreak(true);
40 42
41 // Initialize the Grid Layout Manager used for this dialog box. 43 // Initialize the Grid Layout Manager used for this dialog box.
42 GridLayout* layout = GridLayout::CreatePanel(this); 44 GridLayout* layout = layout_utils::CreatePanelLayout(this);
43 SetLayoutManager(layout);
44 45
45 // 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
46 // box. 47 // box.
47 const int single_column_view_set_id = 0; 48 const int single_column_view_set_id = 0;
48 views::ColumnSet* column_set = 49 views::ColumnSet* column_set =
49 layout->AddColumnSet(single_column_view_set_id); 50 layout->AddColumnSet(single_column_view_set_id);
50 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 51 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
51 GridLayout::FIXED, kMessageWidth, 0); 52 GridLayout::FIXED, kMessageWidth, 0);
52 53
53 // 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.
54 const int labels_column_set_id = 1; 55 const int labels_column_set_id = 1;
55 column_set = layout->AddColumnSet(labels_column_set_id); 56 column_set = layout->AddColumnSet(labels_column_set_id);
56 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); 57 if (layout_delegate->UseExtraDialogPadding())
57 column_set->AddColumn(views::kControlLabelGridAlignment, GridLayout::CENTER, 58 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing);
58 0, GridLayout::USE_PREF, 0, 0); 59 column_set->AddColumn(layout_delegate->GetControlLabelGridAlignment(),
59 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 60 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0);
61 column_set->AddPaddingColumn(0, layout_delegate->GetLayoutDistance(
62 LayoutDelegate::LayoutDistanceType::
63 RELATED_CONTROL_HORIZONTAL_SPACING));
60 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 64 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
61 GridLayout::USE_PREF, 0, 0); 65 GridLayout::USE_PREF, 0, 0);
62 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); 66 if (layout_delegate->UseExtraDialogPadding())
67 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing);
63 68
64 layout->StartRow(0, single_column_view_set_id); 69 layout->StartRow(0, single_column_view_set_id);
65 layout->AddView(authority_label_); 70 layout->AddView(authority_label_);
66 if (!explanation.empty()) { 71 if (!explanation.empty()) {
67 message_label_ = new views::Label(explanation); 72 message_label_ = new views::Label(explanation);
68 message_label_->SetMultiLine(true); 73 message_label_->SetMultiLine(true);
69 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 74 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
70 message_label_->SetAllowCharacterBreak(true); 75 message_label_->SetAllowCharacterBreak(true);
71 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 76 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance(
77 LayoutDelegate::LayoutDistanceType::
78 RELATED_CONTROL_VERTICAL_SPACING));
72 layout->StartRow(0, single_column_view_set_id); 79 layout->StartRow(0, single_column_view_set_id);
73 layout->AddView(message_label_); 80 layout->AddView(message_label_);
74 } 81 }
75 82
76 layout->AddPaddingRow(0, views::kUnrelatedControlLargeVerticalSpacing); 83 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance(
84 LayoutDelegate::LayoutDistanceType::
85 UNRELATED_CONTROL_LARGE_VERTICAL_SPACING));
77 86
78 layout->StartRow(0, labels_column_set_id); 87 layout->StartRow(0, labels_column_set_id);
79 layout->AddView(username_label_); 88 layout->AddView(username_label_);
80 layout->AddView(username_field_); 89 layout->AddView(username_field_);
81 90
82 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 91 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance(
92 LayoutDelegate::LayoutDistanceType::
93 RELATED_CONTROL_VERTICAL_SPACING));
83 94
84 layout->StartRow(0, labels_column_set_id); 95 layout->StartRow(0, labels_column_set_id);
85 layout->AddView(password_label_); 96 layout->AddView(password_label_);
86 layout->AddView(password_field_); 97 layout->AddView(password_field_);
87 98
88 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 99 if (layout_delegate->UseExtraDialogPadding()) {
100 layout->AddPaddingRow(0, layout_delegate->GetLayoutDistance(
101 LayoutDelegate::LayoutDistanceType::
102 UNRELATED_CONTROL_VERTICAL_SPACING));
103 }
89 104
90 if (login_model_data) { 105 if (login_model_data) {
91 login_model_->AddObserverAndDeliverCredentials(this, 106 login_model_->AddObserverAndDeliverCredentials(this,
92 login_model_data->form); 107 login_model_data->form);
93 } 108 }
94 } 109 }
95 110
96 LoginView::~LoginView() { 111 LoginView::~LoginView() {
97 if (login_model_) 112 if (login_model_)
98 login_model_->RemoveObserver(this); 113 login_model_->RemoveObserver(this);
(...skipping 26 matching lines...) Expand all
125 140
126 void LoginView::OnLoginModelDestroying() { 141 void LoginView::OnLoginModelDestroying() {
127 login_model_->RemoveObserver(this); 142 login_model_->RemoveObserver(this);
128 login_model_ = NULL; 143 login_model_ = NULL;
129 } 144 }
130 145
131 const char* LoginView::GetClassName() const { 146 const char* LoginView::GetClassName() const {
132 return "LoginView"; 147 return "LoginView";
133 } 148 }
134 149
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698