| OLD | NEW |
| 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 "components/strings/grit/components_strings.h" | 7 #include "components/strings/grit/components_strings.h" |
| 8 #include "ui/base/l10n/l10n_util.h" | 8 #include "ui/base/l10n/l10n_util.h" |
| 9 #include "ui/harmony/harmony_layout_delegate.h" |
| 9 #include "ui/views/controls/label.h" | 10 #include "ui/views/controls/label.h" |
| 10 #include "ui/views/controls/textfield/textfield.h" | 11 #include "ui/views/controls/textfield/textfield.h" |
| 11 #include "ui/views/layout/grid_layout.h" | 12 #include "ui/views/layout/grid_layout.h" |
| 12 #include "ui/views/layout/layout_constants.h" | 13 #include "ui/views/layout/layout_delegate.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 ui::HarmonyLayoutDelegate::ApplyToViewIfNeeded(this); |
| 37 |
| 35 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 38 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 36 | 39 |
| 37 authority_label_->SetMultiLine(true); | 40 authority_label_->SetMultiLine(true); |
| 38 authority_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 41 authority_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 39 authority_label_->SetAllowCharacterBreak(true); | 42 authority_label_->SetAllowCharacterBreak(true); |
| 40 | 43 |
| 41 // Initialize the Grid Layout Manager used for this dialog box. | 44 // Initialize the Grid Layout Manager used for this dialog box. |
| 42 GridLayout* layout = GridLayout::CreatePanel(this); | 45 GridLayout* layout = GridLayout::CreatePanel(this); |
| 43 SetLayoutManager(layout); | 46 SetLayoutManager(layout); |
| 44 | 47 |
| 45 // Add the column set for the information message at the top of the dialog | 48 // Add the column set for the information message at the top of the dialog |
| 46 // box. | 49 // box. |
| 47 const int single_column_view_set_id = 0; | 50 const int single_column_view_set_id = 0; |
| 48 views::ColumnSet* column_set = | 51 views::ColumnSet* column_set = |
| 49 layout->AddColumnSet(single_column_view_set_id); | 52 layout->AddColumnSet(single_column_view_set_id); |
| 50 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 53 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 51 GridLayout::FIXED, kMessageWidth, 0); | 54 GridLayout::FIXED, kMessageWidth, 0); |
| 52 | 55 |
| 53 // Add the column set for the user name and password fields and labels. | 56 // Add the column set for the user name and password fields and labels. |
| 54 const int labels_column_set_id = 1; | 57 const int labels_column_set_id = 1; |
| 55 column_set = layout->AddColumnSet(labels_column_set_id); | 58 column_set = layout->AddColumnSet(labels_column_set_id); |
| 56 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); | 59 if (GetLayoutDelegate()->UseExtraDialogPadding()) |
| 57 column_set->AddColumn(views::kControlLabelGridAlignment, GridLayout::CENTER, | 60 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); |
| 58 0, GridLayout::USE_PREF, 0, 0); | 61 column_set->AddColumn(GetLayoutDelegate()->GetControlLabelGridAlignment(), |
| 59 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 62 GridLayout::CENTER, 0, GridLayout::USE_PREF, 0, 0); |
| 63 column_set->AddPaddingColumn( |
| 64 0, GetLayoutDelegate()->GetLayoutDistance( |
| 65 views::LayoutDelegate::RELATED_CONTROL_HORIZONTAL_SPACING)); |
| 60 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 66 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
| 61 GridLayout::USE_PREF, 0, 0); | 67 GridLayout::USE_PREF, 0, 0); |
| 62 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); | 68 if (GetLayoutDelegate()->UseExtraDialogPadding()) |
| 69 column_set->AddPaddingColumn(0, kTextfieldStackHorizontalSpacing); |
| 63 | 70 |
| 64 layout->StartRow(0, single_column_view_set_id); | 71 layout->StartRow(0, single_column_view_set_id); |
| 65 layout->AddView(authority_label_); | 72 layout->AddView(authority_label_); |
| 66 if (!explanation.empty()) { | 73 if (!explanation.empty()) { |
| 67 message_label_ = new views::Label(explanation); | 74 message_label_ = new views::Label(explanation); |
| 68 message_label_->SetMultiLine(true); | 75 message_label_->SetMultiLine(true); |
| 69 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 76 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 70 message_label_->SetAllowCharacterBreak(true); | 77 message_label_->SetAllowCharacterBreak(true); |
| 71 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 78 layout->AddPaddingRow( |
| 79 0, GetLayoutDelegate()->GetLayoutDistance( |
| 80 views::LayoutDelegate::RELATED_CONTROL_VERTICAL_SPACING)); |
| 72 layout->StartRow(0, single_column_view_set_id); | 81 layout->StartRow(0, single_column_view_set_id); |
| 73 layout->AddView(message_label_); | 82 layout->AddView(message_label_); |
| 74 } | 83 } |
| 75 | 84 |
| 76 layout->AddPaddingRow(0, views::kUnrelatedControlLargeVerticalSpacing); | 85 layout->AddPaddingRow( |
| 86 0, GetLayoutDelegate()->GetLayoutDistance( |
| 87 views::LayoutDelegate::UNRELATED_CONTROL_LARGE_VERTICAL_SPACING)); |
| 77 | 88 |
| 78 layout->StartRow(0, labels_column_set_id); | 89 layout->StartRow(0, labels_column_set_id); |
| 79 layout->AddView(username_label_); | 90 layout->AddView(username_label_); |
| 80 layout->AddView(username_field_); | 91 layout->AddView(username_field_); |
| 81 | 92 |
| 82 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 93 layout->AddPaddingRow( |
| 94 0, GetLayoutDelegate()->GetLayoutDistance( |
| 95 views::LayoutDelegate::RELATED_CONTROL_VERTICAL_SPACING)); |
| 83 | 96 |
| 84 layout->StartRow(0, labels_column_set_id); | 97 layout->StartRow(0, labels_column_set_id); |
| 85 layout->AddView(password_label_); | 98 layout->AddView(password_label_); |
| 86 layout->AddView(password_field_); | 99 layout->AddView(password_field_); |
| 87 | 100 |
| 88 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 101 if (GetLayoutDelegate()->UseExtraDialogPadding()) { |
| 102 layout->AddPaddingRow( |
| 103 0, GetLayoutDelegate()->GetLayoutDistance( |
| 104 views::LayoutDelegate::UNRELATED_CONTROL_VERTICAL_SPACING)); |
| 105 } |
| 89 | 106 |
| 90 if (login_model_data) { | 107 if (login_model_data) { |
| 91 login_model_->AddObserverAndDeliverCredentials(this, | 108 login_model_->AddObserverAndDeliverCredentials(this, |
| 92 login_model_data->form); | 109 login_model_data->form); |
| 93 } | 110 } |
| 94 } | 111 } |
| 95 | 112 |
| 96 LoginView::~LoginView() { | 113 LoginView::~LoginView() { |
| 97 if (login_model_) | 114 if (login_model_) |
| 98 login_model_->RemoveObserver(this); | 115 login_model_->RemoveObserver(this); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 125 | 142 |
| 126 void LoginView::OnLoginModelDestroying() { | 143 void LoginView::OnLoginModelDestroying() { |
| 127 login_model_->RemoveObserver(this); | 144 login_model_->RemoveObserver(this); |
| 128 login_model_ = NULL; | 145 login_model_ = NULL; |
| 129 } | 146 } |
| 130 | 147 |
| 131 const char* LoginView::GetClassName() const { | 148 const char* LoginView::GetClassName() const { |
| 132 return "LoginView"; | 149 return "LoginView"; |
| 133 } | 150 } |
| 134 | 151 |
| OLD | NEW |