OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/login/new_user_view.h" | 5 #include "chrome/browser/chromeos/login/new_user_view.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "app/keyboard_codes.h" | 13 #include "app/keyboard_codes.h" |
14 #include "app/l10n_util.h" | 14 #include "app/l10n_util.h" |
15 #include "app/resource_bundle.h" | 15 #include "app/resource_bundle.h" |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/chromeos/cros/cros_library.h" | 22 #include "chrome/browser/chromeos/cros/cros_library.h" |
23 #include "chrome/browser/chromeos/login/helper.h" | 23 #include "chrome/browser/chromeos/login/helper.h" |
24 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | 24 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
25 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" | 25 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" |
| 26 #include "gfx/font.h" |
26 #include "grit/app_resources.h" | 27 #include "grit/app_resources.h" |
27 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
28 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
29 #include "views/controls/button/native_button.h" | 30 #include "views/controls/button/native_button.h" |
30 #include "views/controls/label.h" | 31 #include "views/controls/label.h" |
31 #include "views/controls/throbber.h" | 32 #include "views/controls/throbber.h" |
32 #include "views/widget/widget_gtk.h" | 33 #include "views/widget/widget_gtk.h" |
33 | 34 |
34 using views::Label; | 35 using views::Label; |
35 using views::Textfield; | 36 using views::Textfield; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 title_hint_label_->SetColor(SK_ColorGRAY); | 131 title_hint_label_->SetColor(SK_ColorGRAY); |
131 title_hint_label_->SetMultiLine(true); | 132 title_hint_label_->SetMultiLine(true); |
132 AddChildView(title_hint_label_); | 133 AddChildView(title_hint_label_); |
133 | 134 |
134 splitter_ = new views::View(); | 135 splitter_ = new views::View(); |
135 splitter_->set_background( | 136 splitter_->set_background( |
136 views::Background::CreateSolidBackground(SK_ColorGRAY)); | 137 views::Background::CreateSolidBackground(SK_ColorGRAY)); |
137 AddChildView(splitter_); | 138 AddChildView(splitter_); |
138 | 139 |
139 username_field_ = new UsernameField(); | 140 username_field_ = new UsernameField(); |
| 141 login::CorrectTextfieldFontSize(username_field_); |
140 AddChildView(username_field_); | 142 AddChildView(username_field_); |
141 | 143 |
142 password_field_ = new views::Textfield(views::Textfield::STYLE_PASSWORD); | 144 password_field_ = new views::Textfield(views::Textfield::STYLE_PASSWORD); |
| 145 login::CorrectTextfieldFontSize(password_field_); |
143 AddChildView(password_field_); | 146 AddChildView(password_field_); |
144 | 147 |
145 throbber_ = CreateDefaultSmoothedThrobber(); | 148 throbber_ = CreateDefaultSmoothedThrobber(); |
146 AddChildView(throbber_); | 149 AddChildView(throbber_); |
147 | 150 |
148 language_switch_menu_.InitLanguageMenu(); | 151 language_switch_menu_.InitLanguageMenu(); |
149 | 152 |
150 RecreatePeculiarControls(); | 153 RecreatePeculiarControls(); |
151 | 154 |
152 AddChildView(sign_in_button_); | 155 AddChildView(sign_in_button_); |
153 if (need_create_account_) { | 156 if (need_create_account_) { |
154 InitLink(&create_account_link_); | 157 InitLink(&create_account_link_); |
155 } | 158 } |
156 if (need_browse_without_signin_) { | 159 if (need_browse_without_signin_) { |
157 InitLink(&browse_without_signin_link_); | 160 InitLink(&browse_without_signin_link_); |
158 } | 161 } |
159 AddChildView(languages_menubutton_); | 162 AddChildView(languages_menubutton_); |
160 | 163 |
161 // Set up accelerators. | 164 // Set up accelerators. |
162 AddAccelerator(accel_focus_user_); | 165 AddAccelerator(accel_focus_user_); |
163 AddAccelerator(accel_focus_pass_); | 166 AddAccelerator(accel_focus_pass_); |
164 AddAccelerator(accel_login_off_the_record_); | 167 AddAccelerator(accel_login_off_the_record_); |
165 AddAccelerator(accel_enable_accessibility_); | 168 AddAccelerator(accel_enable_accessibility_); |
166 | 169 |
167 UpdateLocalizedStrings(); | 170 OnLocaleChanged(); |
168 RequestFocus(); | |
169 | 171 |
170 // Controller to handle events from textfields | 172 // Controller to handle events from textfields |
171 username_field_->SetController(this); | 173 username_field_->SetController(this); |
172 password_field_->SetController(this); | 174 password_field_->SetController(this); |
173 if (!CrosLibrary::Get()->EnsureLoaded()) { | 175 if (!CrosLibrary::Get()->EnsureLoaded()) { |
174 EnableInputControls(false); | 176 EnableInputControls(false); |
175 } | 177 } |
176 | 178 |
177 // The 'Sign in' button should be disabled when there is no text in the | 179 // The 'Sign in' button should be disabled when there is no text in the |
178 // username and password fields. | 180 // username and password fields. |
(...skipping 24 matching lines...) Expand all Loading... |
203 languages_menubutton_->set_menu_marker( | 205 languages_menubutton_->set_menu_marker( |
204 ResourceBundle::GetSharedInstance().GetBitmapNamed( | 206 ResourceBundle::GetSharedInstance().GetBitmapNamed( |
205 IDR_MENU_DROPARROW_SHARP)); | 207 IDR_MENU_DROPARROW_SHARP)); |
206 languages_menubutton_->SetEnabledColor(kLanguagesMenuTextColor); | 208 languages_menubutton_->SetEnabledColor(kLanguagesMenuTextColor); |
207 languages_menubutton_->SetFocusable(true); | 209 languages_menubutton_->SetFocusable(true); |
208 | 210 |
209 // There is no way to get native button preferred size after the button was | 211 // There is no way to get native button preferred size after the button was |
210 // sized so delete and recreate the button on text update. | 212 // sized so delete and recreate the button on text update. |
211 delete sign_in_button_; | 213 delete sign_in_button_; |
212 sign_in_button_ = new views::NativeButton(this, std::wstring()); | 214 sign_in_button_ = new views::NativeButton(this, std::wstring()); |
| 215 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 216 login::CorrectNativeButtonFontSize(sign_in_button_); |
213 UpdateSignInButtonState(); | 217 UpdateSignInButtonState(); |
214 | 218 |
215 if (!CrosLibrary::Get()->EnsureLoaded()) | 219 if (!CrosLibrary::Get()->EnsureLoaded()) |
216 sign_in_button_->SetEnabled(false); | 220 sign_in_button_->SetEnabled(false); |
217 } | 221 } |
218 | 222 |
219 void NewUserView::UpdateSignInButtonState() { | 223 void NewUserView::UpdateSignInButtonState() { |
220 bool enabled = !username_field_->text().empty() && | 224 bool enabled = !username_field_->text().empty() && |
221 !password_field_->text().empty(); | 225 !password_field_->text().empty(); |
222 sign_in_button_->SetEnabled(enabled); | 226 sign_in_button_->SetEnabled(enabled); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 283 } |
280 | 284 |
281 void NewUserView::ViewHierarchyChanged(bool is_add, | 285 void NewUserView::ViewHierarchyChanged(bool is_add, |
282 View *parent, | 286 View *parent, |
283 View *child) { | 287 View *child) { |
284 if (is_add && child == this) { | 288 if (is_add && child == this) { |
285 MessageLoop::current()->PostTask(FROM_HERE, | 289 MessageLoop::current()->PostTask(FROM_HERE, |
286 focus_grabber_factory_.NewRunnableMethod( | 290 focus_grabber_factory_.NewRunnableMethod( |
287 &NewUserView::FocusFirstField)); | 291 &NewUserView::FocusFirstField)); |
288 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); | 292 WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); |
| 293 } else if (is_add && (child == username_field_ || child == password_field_)) { |
| 294 MessageLoop::current()->PostTask(FROM_HERE, |
| 295 focus_grabber_factory_.NewRunnableMethod( |
| 296 &NewUserView::Layout)); |
289 } | 297 } |
290 } | 298 } |
291 | 299 |
292 void NewUserView::NativeViewHierarchyChanged(bool attached, | 300 void NewUserView::NativeViewHierarchyChanged(bool attached, |
293 gfx::NativeView native_view, | 301 gfx::NativeView native_view, |
294 views::RootView* root_view) { | 302 views::RootView* root_view) { |
295 if (focus_delayed_ && attached) { | 303 if (focus_delayed_ && attached) { |
296 focus_delayed_ = false; | 304 focus_delayed_ = false; |
297 MessageLoop::current()->PostTask(FROM_HERE, | 305 MessageLoop::current()->PostTask(FROM_HERE, |
298 focus_grabber_factory_.NewRunnableMethod( | 306 focus_grabber_factory_.NewRunnableMethod( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 y += (this->height() - y - height) / 2; | 378 y += (this->height() - y - height) / 2; |
371 | 379 |
372 int corner_radius = need_border_ ? login::kScreenCornerRadius : 0; | 380 int corner_radius = need_border_ ? login::kScreenCornerRadius : 0; |
373 splitter_->SetBounds(insets.left() - corner_radius / 2, | 381 splitter_->SetBounds(insets.left() - corner_radius / 2, |
374 title_end + (y - title_end) / 2, | 382 title_end + (y - title_end) / 2, |
375 this->width() - insets.width() + corner_radius, | 383 this->width() - insets.width() + corner_radius, |
376 kSplitterHeight); | 384 kSplitterHeight); |
377 | 385 |
378 y += (setViewBounds(username_field_, x, y, width, true) + kRowPad); | 386 y += (setViewBounds(username_field_, x, y, width, true) + kRowPad); |
379 y += (setViewBounds(password_field_, x, y, width, true) + 3 * kRowPad); | 387 y += (setViewBounds(password_field_, x, y, width, true) + 3 * kRowPad); |
| 388 |
380 int throbber_y = y; | 389 int throbber_y = y; |
381 y += (setViewBounds(sign_in_button_, x, y, width, false) + kRowPad); | 390 int sign_in_button_width = |
| 391 std::max(login::kButtonMinWidth, |
| 392 sign_in_button_->GetPreferredSize().width()); |
| 393 y += (setViewBounds(sign_in_button_, x, y, sign_in_button_width,true) + |
| 394 kRowPad); |
382 setViewBounds(throbber_, | 395 setViewBounds(throbber_, |
383 x + width - throbber_->GetPreferredSize().width(), | 396 x + width - throbber_->GetPreferredSize().width(), |
384 throbber_y + (sign_in_button_->GetPreferredSize().height() - | 397 throbber_y + (sign_in_button_->GetPreferredSize().height() - |
385 throbber_->GetPreferredSize().height()) / 2, | 398 throbber_->GetPreferredSize().height()) / 2, |
386 width, | 399 width, |
387 false); | 400 false); |
388 if (need_create_account_) { | 401 if (need_create_account_) { |
389 y += setViewBounds(create_account_link_, x, y, max_width, false); | 402 y += setViewBounds(create_account_link_, x, y, max_width, false); |
390 } | 403 } |
391 | 404 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 create_account_link_->SetEnabled(enabled); | 519 create_account_link_->SetEnabled(enabled); |
507 } | 520 } |
508 if (need_browse_without_signin_) { | 521 if (need_browse_without_signin_) { |
509 browse_without_signin_link_->SetEnabled(enabled); | 522 browse_without_signin_link_->SetEnabled(enabled); |
510 } | 523 } |
511 } | 524 } |
512 | 525 |
513 void NewUserView::InitLink(views::Link** link) { | 526 void NewUserView::InitLink(views::Link** link) { |
514 *link = new views::Link(std::wstring()); | 527 *link = new views::Link(std::wstring()); |
515 (*link)->SetController(this); | 528 (*link)->SetController(this); |
| 529 (*link)->SetNormalColor(login::kLinkColor); |
| 530 (*link)->SetHighlightedColor(login::kLinkColor); |
516 AddChildView(*link); | 531 AddChildView(*link); |
517 } | 532 } |
518 | 533 |
519 } // namespace chromeos | 534 } // namespace chromeos |
OLD | NEW |