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 "chrome/grit/generated_resources.h" | 7 #include "chrome/grit/generated_resources.h" |
8 #include "ui/base/l10n/l10n_util.h" | 8 #include "ui/base/l10n/l10n_util.h" |
9 #include "ui/views/controls/label.h" | 9 #include "ui/views/controls/label.h" |
10 #include "ui/views/controls/textfield/textfield.h" | 10 #include "ui/views/controls/textfield/textfield.h" |
11 #include "ui/views/layout/grid_layout.h" | 11 #include "ui/views/layout/grid_layout.h" |
12 #include "ui/views/layout/layout_constants.h" | 12 #include "ui/views/layout/layout_constants.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& explanation, | 23 LoginView::LoginView(const base::string16& explanation, |
24 LoginModel* model) | 24 LoginHandler::LoginModelData* login_model_data) |
25 : username_field_(new views::Textfield()), | 25 : username_field_(new views::Textfield()), |
26 password_field_(new views::Textfield()), | 26 password_field_(new views::Textfield()), |
27 username_label_(new views::Label( | 27 username_label_(new views::Label( |
28 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_USERNAME_FIELD))), | 28 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_USERNAME_FIELD))), |
29 password_label_(new views::Label( | 29 password_label_(new views::Label( |
30 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_PASSWORD_FIELD))), | 30 l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_PASSWORD_FIELD))), |
31 message_label_(new views::Label(explanation)), | 31 message_label_(new views::Label(explanation)), |
32 login_model_(model) { | 32 login_model_(login_model_data ? login_model_data->model : nullptr) { |
33 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 33 password_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
34 message_label_->SetMultiLine(true); | 34 message_label_->SetMultiLine(true); |
35 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 35 message_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
36 message_label_->SetAllowCharacterBreak(true); | 36 message_label_->SetAllowCharacterBreak(true); |
37 | 37 |
38 // Initialize the Grid Layout Manager used for this dialog box. | 38 // Initialize the Grid Layout Manager used for this dialog box. |
39 GridLayout* layout = GridLayout::CreatePanel(this); | 39 GridLayout* layout = GridLayout::CreatePanel(this); |
40 SetLayoutManager(layout); | 40 SetLayoutManager(layout); |
41 | 41 |
42 // Add the column set for the information message at the top of the dialog | 42 // Add the column set for the information message at the top of the dialog |
(...skipping 25 matching lines...) Expand all Loading... |
68 layout->AddView(username_field_); | 68 layout->AddView(username_field_); |
69 | 69 |
70 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 70 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
71 | 71 |
72 layout->StartRow(0, labels_column_set_id); | 72 layout->StartRow(0, labels_column_set_id); |
73 layout->AddView(password_label_); | 73 layout->AddView(password_label_); |
74 layout->AddView(password_field_); | 74 layout->AddView(password_field_); |
75 | 75 |
76 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 76 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
77 | 77 |
78 if (login_model_) | 78 if (login_model_data) { |
79 login_model_->AddObserver(this); | 79 login_model_->AddObserverAndDeliverCredentials(this, |
| 80 login_model_data->form); |
| 81 } |
80 } | 82 } |
81 | 83 |
82 LoginView::~LoginView() { | 84 LoginView::~LoginView() { |
83 if (login_model_) | 85 if (login_model_) |
84 login_model_->RemoveObserver(this); | 86 login_model_->RemoveObserver(this); |
85 } | 87 } |
86 | 88 |
87 const base::string16& LoginView::GetUsername() const { | 89 const base::string16& LoginView::GetUsername() const { |
88 return username_field_->text(); | 90 return username_field_->text(); |
89 } | 91 } |
90 | 92 |
91 const base::string16& LoginView::GetPassword() const { | 93 const base::string16& LoginView::GetPassword() const { |
92 return password_field_->text(); | 94 return password_field_->text(); |
93 } | 95 } |
94 | 96 |
95 views::View* LoginView::GetInitiallyFocusedView() { | 97 views::View* LoginView::GetInitiallyFocusedView() { |
96 return username_field_; | 98 return username_field_; |
97 } | 99 } |
98 | 100 |
99 /////////////////////////////////////////////////////////////////////////////// | 101 /////////////////////////////////////////////////////////////////////////////// |
100 // LoginView, views::View, password_manager::LoginModelObserver overrides: | 102 // LoginView, views::View, password_manager::LoginModelObserver overrides: |
101 | 103 |
102 void LoginView::OnAutofillDataAvailable(const base::string16& username, | 104 void LoginView::OnAutofillDataAvailableInternal( |
103 const base::string16& password) { | 105 const base::string16& username, |
| 106 const base::string16& password) { |
104 if (username_field_->text().empty()) { | 107 if (username_field_->text().empty()) { |
105 username_field_->SetText(username); | 108 username_field_->SetText(username); |
106 password_field_->SetText(password); | 109 password_field_->SetText(password); |
107 username_field_->SelectAll(true); | 110 username_field_->SelectAll(true); |
108 } | 111 } |
109 } | 112 } |
110 | 113 |
111 void LoginView::OnLoginModelDestroying() { | 114 void LoginView::OnLoginModelDestroying() { |
112 login_model_->RemoveObserver(this); | 115 login_model_->RemoveObserver(this); |
113 login_model_ = NULL; | 116 login_model_ = NULL; |
114 } | 117 } |
115 | 118 |
116 const char* LoginView::GetClassName() const { | 119 const char* LoginView::GetClassName() const { |
117 return "LoginView"; | 120 return "LoginView"; |
118 } | 121 } |
119 | 122 |
OLD | NEW |