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> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 title_label_(NULL), | 88 title_label_(NULL), |
89 title_hint_label_(NULL), | 89 title_hint_label_(NULL), |
90 splitter_up1_(NULL), | 90 splitter_up1_(NULL), |
91 splitter_up2_(NULL), | 91 splitter_up2_(NULL), |
92 splitter_down1_(NULL), | 92 splitter_down1_(NULL), |
93 splitter_down2_(NULL), | 93 splitter_down2_(NULL), |
94 sign_in_button_(NULL), | 94 sign_in_button_(NULL), |
95 create_account_link_(NULL), | 95 create_account_link_(NULL), |
96 guest_link_(NULL), | 96 guest_link_(NULL), |
97 languages_menubutton_(NULL), | 97 languages_menubutton_(NULL), |
98 throbber_(NULL), | |
99 accel_focus_pass_(views::Accelerator(app::VKEY_P, false, false, true)), | 98 accel_focus_pass_(views::Accelerator(app::VKEY_P, false, false, true)), |
100 accel_focus_user_(views::Accelerator(app::VKEY_U, false, false, true)), | 99 accel_focus_user_(views::Accelerator(app::VKEY_U, false, false, true)), |
101 accel_login_off_the_record_( | 100 accel_login_off_the_record_( |
102 views::Accelerator(app::VKEY_B, false, false, true)), | 101 views::Accelerator(app::VKEY_B, false, false, true)), |
103 accel_enable_accessibility_(WizardAccessibilityHelper::GetAccelerator()), | 102 accel_enable_accessibility_(WizardAccessibilityHelper::GetAccelerator()), |
104 delegate_(delegate), | 103 delegate_(delegate), |
105 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)), | 104 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)), |
106 focus_delayed_(false), | 105 focus_delayed_(false), |
107 login_in_process_(false), | 106 login_in_process_(false), |
108 need_border_(need_border), | 107 need_border_(need_border), |
109 need_guest_link_(false), | 108 need_guest_link_(false), |
110 need_create_account_(false), | 109 need_create_account_(false), |
111 languages_menubutton_order_(-1), | 110 languages_menubutton_order_(-1), |
112 sign_in_button_order_(-1) { | 111 sign_in_button_order_(-1), |
112 throbber_center_y_(0) { | |
113 if (need_guest_link && UserCrosSettingsProvider::cached_allow_guest()) | 113 if (need_guest_link && UserCrosSettingsProvider::cached_allow_guest()) |
114 need_guest_link_ = true; | 114 need_guest_link_ = true; |
115 } | 115 } |
116 | 116 |
117 NewUserView::~NewUserView() { | 117 NewUserView::~NewUserView() { |
118 } | 118 } |
119 | 119 |
120 void NewUserView::Init() { | 120 void NewUserView::Init() { |
121 if (need_border_) { | 121 if (need_border_) { |
122 // Use rounded rect background. | 122 // Use rounded rect background. |
(...skipping 28 matching lines...) Expand all Loading... | |
151 splitter_down2_ = CreateSplitter(kSplitterDown2Color); | 151 splitter_down2_ = CreateSplitter(kSplitterDown2Color); |
152 | 152 |
153 username_field_ = new UsernameField(); | 153 username_field_ = new UsernameField(); |
154 username_field_->set_background(new CopyBackground(this)); | 154 username_field_->set_background(new CopyBackground(this)); |
155 AddChildView(username_field_); | 155 AddChildView(username_field_); |
156 | 156 |
157 password_field_ = new TextfieldWithMargin(views::Textfield::STYLE_PASSWORD); | 157 password_field_ = new TextfieldWithMargin(views::Textfield::STYLE_PASSWORD); |
158 password_field_->set_background(new CopyBackground(this)); | 158 password_field_->set_background(new CopyBackground(this)); |
159 AddChildView(password_field_); | 159 AddChildView(password_field_); |
160 | 160 |
161 throbber_ = CreateDefaultSmoothedThrobber(); | |
162 AddChildView(throbber_); | |
163 | |
164 language_switch_menu_.InitLanguageMenu(); | 161 language_switch_menu_.InitLanguageMenu(); |
165 | 162 |
166 RecreatePeculiarControls(); | 163 RecreatePeculiarControls(); |
167 | 164 |
168 AddChildView(sign_in_button_); | 165 AddChildView(sign_in_button_); |
169 if (need_create_account_) { | 166 if (need_create_account_) { |
170 InitLink(&create_account_link_); | 167 InitLink(&create_account_link_); |
171 } | 168 } |
172 if (need_guest_link_) { | 169 if (need_guest_link_) { |
173 InitLink(&guest_link_); | 170 InitLink(&guest_link_); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 sign_in_button_->GetPreferredSize().height() + | 410 sign_in_button_->GetPreferredSize().height() + |
414 2 * kRowPad; | 411 2 * kRowPad; |
415 y = title_end + (bottom_start - title_end - height) / 2; | 412 y = title_end + (bottom_start - title_end - height) / 2; |
416 | 413 |
417 y += setViewBounds(username_field_, x, y, width, true) + kRowPad; | 414 y += setViewBounds(username_field_, x, y, width, true) + kRowPad; |
418 y += setViewBounds(password_field_, x, y, width, true) + kRowPad; | 415 y += setViewBounds(password_field_, x, y, width, true) + kRowPad; |
419 | 416 |
420 int throbber_y = y; | 417 int throbber_y = y; |
421 int sign_in_button_width = sign_in_button_->GetPreferredSize().width(); | 418 int sign_in_button_width = sign_in_button_->GetPreferredSize().width(); |
422 setViewBounds(sign_in_button_, x, y, sign_in_button_width,true); | 419 setViewBounds(sign_in_button_, x, y, sign_in_button_width,true); |
423 setViewBounds(throbber_, | 420 |
424 x + width - throbber_->GetPreferredSize().width(), | 421 |
425 throbber_y + (sign_in_button_->GetPreferredSize().height() - | 422 throbber_right_ = x + width; |
426 throbber_->GetPreferredSize().height()) / 2, | 423 throbber_center_y_ = |
427 width, | 424 throbber_y + sign_in_button_->GetPreferredSize().height() / 2; |
whywhat
2010/12/13 07:57:35
Guess we could use y here and eliminate throbber_y
altimofeev
2010/12/13 15:42:45
Good point! Fixed.
| |
428 false); | |
429 | 425 |
430 SchedulePaint(); | 426 SchedulePaint(); |
431 } | 427 } |
432 | 428 |
433 gfx::Size NewUserView::GetPreferredSize() { | 429 gfx::Size NewUserView::GetPreferredSize() { |
434 return need_guest_link_ ? | 430 return need_guest_link_ ? |
435 gfx::Size(kNewUserPodFullWidth, kNewUserPodFullHeight) : | 431 gfx::Size(kNewUserPodFullWidth, kNewUserPodFullHeight) : |
436 gfx::Size(kNewUserPodSmallWidth, kNewUserPodSmallHeight); | 432 gfx::Size(kNewUserPodSmallWidth, kNewUserPodSmallHeight); |
437 } | 433 } |
438 | 434 |
439 void NewUserView::SetUsername(const std::string& username) { | 435 void NewUserView::SetUsername(const std::string& username) { |
440 username_field_->SetText(UTF8ToUTF16(username)); | 436 username_field_->SetText(UTF8ToUTF16(username)); |
441 } | 437 } |
442 | 438 |
443 void NewUserView::SetPassword(const std::string& password) { | 439 void NewUserView::SetPassword(const std::string& password) { |
444 password_field_->SetText(UTF8ToUTF16(password)); | 440 password_field_->SetText(UTF8ToUTF16(password)); |
445 } | 441 } |
446 | 442 |
447 void NewUserView::Login() { | 443 void NewUserView::Login() { |
448 if (login_in_process_ || username_field_->text().empty()) | 444 if (login_in_process_ || username_field_->text().empty()) |
449 return; | 445 return; |
450 | 446 |
451 StartThrobber(); | |
452 login_in_process_ = true; | 447 login_in_process_ = true; |
453 EnableInputControls(false); | |
454 std::string username = UTF16ToUTF8(username_field_->text()); | 448 std::string username = UTF16ToUTF8(username_field_->text()); |
455 // todo(cmasone) Need to sanitize memory used to store password. | 449 // todo(cmasone) Need to sanitize memory used to store password. |
456 std::string password = UTF16ToUTF8(password_field_->text()); | 450 std::string password = UTF16ToUTF8(password_field_->text()); |
457 | 451 |
458 if (username.find('@') == std::string::npos) { | 452 if (username.find('@') == std::string::npos) { |
459 username += kDefaultDomain; | 453 username += kDefaultDomain; |
460 username_field_->SetText(UTF8ToUTF16(username)); | 454 username_field_->SetText(UTF8ToUTF16(username)); |
461 } | 455 } |
462 | 456 |
463 delegate_->OnLogin(username, password); | 457 delegate_->OnLogin(username, password); |
464 } | 458 } |
465 | 459 |
466 // Sign in button causes a login attempt. | 460 // Sign in button causes a login attempt. |
467 void NewUserView::ButtonPressed(views::Button* sender, | 461 void NewUserView::ButtonPressed(views::Button* sender, |
468 const views::Event& event) { | 462 const views::Event& event) { |
469 DCHECK(sender == sign_in_button_); | 463 DCHECK(sender == sign_in_button_); |
470 Login(); | 464 Login(); |
471 } | 465 } |
472 | 466 |
473 void NewUserView::LinkActivated(views::Link* source, int event_flags) { | 467 void NewUserView::LinkActivated(views::Link* source, int event_flags) { |
474 if (source == create_account_link_) { | 468 if (source == create_account_link_) { |
475 delegate_->OnCreateAccount(); | 469 delegate_->OnCreateAccount(); |
476 } else if (source == guest_link_) { | 470 } else if (source == guest_link_) { |
477 delegate_->OnLoginOffTheRecord(); | 471 delegate_->OnLoginOffTheRecord(); |
478 } | 472 } |
479 } | 473 } |
480 | 474 |
481 void NewUserView::ClearAndEnablePassword() { | 475 void NewUserView::ClearAndFocusControls() { |
482 login_in_process_ = false; | 476 login_in_process_ = false; |
483 EnableInputControls(true); | |
484 SetPassword(std::string()); | |
485 password_field_->RequestFocus(); | |
486 StopThrobber(); | |
487 } | |
488 | |
489 void NewUserView::ClearAndEnableFields() { | |
490 login_in_process_ = false; | |
491 EnableInputControls(true); | |
492 SetUsername(std::string()); | 477 SetUsername(std::string()); |
493 SetPassword(std::string()); | 478 SetPassword(std::string()); |
494 username_field_->RequestFocus(); | 479 username_field_->RequestFocus(); |
495 StopThrobber(); | 480 } |
481 | |
482 void NewUserView::ClearAndFocusPassword() { | |
483 login_in_process_ = false; | |
484 SetPassword(std::string()); | |
485 password_field_->RequestFocus(); | |
486 } | |
487 | |
488 gfx::Rect NewUserView::GetMainInputScreenBounds() const { | |
489 return GetUsernameBounds(); | |
490 } | |
491 | |
492 bool NewUserView::UseCustomBoundsForThrobber(const gfx::Size& throbber, | |
493 gfx::Rect* bounds) { | |
494 DCHECK(password_field_); // Check that Init() has been called. | |
495 // Call Layout() if it hasn't been called yet. | |
496 if (throbber_center_y_ == 0) | |
497 Layout(); | |
498 | |
499 gfx::Point origin(throbber_right_- throbber.width(), | |
500 throbber_center_y_ - throbber.height() / 2); | |
501 bounds->set_origin(origin); | |
502 bounds->set_size(throbber); | |
503 return true; | |
496 } | 504 } |
497 | 505 |
498 gfx::Rect NewUserView::GetPasswordBounds() const { | 506 gfx::Rect NewUserView::GetPasswordBounds() const { |
499 return password_field_->GetScreenBounds(); | 507 return password_field_->GetScreenBounds(); |
500 } | 508 } |
501 | 509 |
502 gfx::Rect NewUserView::GetUsernameBounds() const { | 510 gfx::Rect NewUserView::GetUsernameBounds() const { |
503 return username_field_->GetScreenBounds(); | 511 return username_field_->GetScreenBounds(); |
504 } | 512 } |
505 | 513 |
506 void NewUserView::StartThrobber() { | |
507 throbber_->Start(); | |
508 } | |
509 | |
510 void NewUserView::StopThrobber() { | |
511 throbber_->Stop(); | |
512 } | |
513 | |
514 bool NewUserView::HandleKeystroke(views::Textfield* s, | 514 bool NewUserView::HandleKeystroke(views::Textfield* s, |
515 const views::Textfield::Keystroke& keystroke) { | 515 const views::Textfield::Keystroke& keystroke) { |
516 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_) | 516 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_) |
517 return false; | 517 return false; |
518 | 518 |
519 if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { | 519 if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { |
520 Login(); | 520 Login(); |
521 // Return true so that processing ends | 521 // Return true so that processing ends |
522 return true; | 522 return true; |
523 } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { | 523 } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { |
(...skipping 18 matching lines...) Expand all Loading... | |
542 languages_menubutton_->SetEnabled(enabled); | 542 languages_menubutton_->SetEnabled(enabled); |
543 username_field_->SetEnabled(enabled); | 543 username_field_->SetEnabled(enabled); |
544 password_field_->SetEnabled(enabled); | 544 password_field_->SetEnabled(enabled); |
545 sign_in_button_->SetEnabled(enabled); | 545 sign_in_button_->SetEnabled(enabled); |
546 if (need_create_account_) { | 546 if (need_create_account_) { |
547 create_account_link_->SetEnabled(enabled); | 547 create_account_link_->SetEnabled(enabled); |
548 } | 548 } |
549 if (need_guest_link_) { | 549 if (need_guest_link_) { |
550 guest_link_->SetEnabled(enabled); | 550 guest_link_->SetEnabled(enabled); |
551 } | 551 } |
552 delegate_->SetStatusAreaEnabled(enabled); | |
553 } | 552 } |
554 | 553 |
555 void NewUserView::InitLink(views::Link** link) { | 554 void NewUserView::InitLink(views::Link** link) { |
556 *link = new views::Link(std::wstring()); | 555 *link = new views::Link(std::wstring()); |
557 (*link)->SetController(this); | 556 (*link)->SetController(this); |
558 (*link)->SetNormalColor(login::kLinkColor); | 557 (*link)->SetNormalColor(login::kLinkColor); |
559 (*link)->SetHighlightedColor(login::kLinkColor); | 558 (*link)->SetHighlightedColor(login::kLinkColor); |
560 AddChildView(*link); | 559 AddChildView(*link); |
561 } | 560 } |
562 | 561 |
563 } // namespace chromeos | 562 } // namespace chromeos |
OLD | NEW |