| 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" | |
| 24 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | 23 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
| 25 #include "chrome/browser/chromeos/login/textfield_with_margin.h" | 24 #include "chrome/browser/chromeos/login/textfield_with_margin.h" |
| 26 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" | 25 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" |
| 27 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 26 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
| 28 #include "chrome/browser/chromeos/views/copy_background.h" | 27 #include "chrome/browser/chromeos/views/copy_background.h" |
| 29 #include "gfx/font.h" | 28 #include "gfx/font.h" |
| 30 #include "grit/app_resources.h" | 29 #include "grit/app_resources.h" |
| 31 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| 32 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 33 #include "views/controls/label.h" | 32 #include "views/controls/label.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 title_label_(NULL), | 87 title_label_(NULL), |
| 89 title_hint_label_(NULL), | 88 title_hint_label_(NULL), |
| 90 splitter_up1_(NULL), | 89 splitter_up1_(NULL), |
| 91 splitter_up2_(NULL), | 90 splitter_up2_(NULL), |
| 92 splitter_down1_(NULL), | 91 splitter_down1_(NULL), |
| 93 splitter_down2_(NULL), | 92 splitter_down2_(NULL), |
| 94 sign_in_button_(NULL), | 93 sign_in_button_(NULL), |
| 95 create_account_link_(NULL), | 94 create_account_link_(NULL), |
| 96 guest_link_(NULL), | 95 guest_link_(NULL), |
| 97 languages_menubutton_(NULL), | 96 languages_menubutton_(NULL), |
| 98 throbber_(NULL), | |
| 99 accel_focus_pass_(views::Accelerator(app::VKEY_P, false, false, true)), | 97 accel_focus_pass_(views::Accelerator(app::VKEY_P, false, false, true)), |
| 100 accel_focus_user_(views::Accelerator(app::VKEY_U, false, false, true)), | 98 accel_focus_user_(views::Accelerator(app::VKEY_U, false, false, true)), |
| 101 accel_login_off_the_record_( | 99 accel_login_off_the_record_( |
| 102 views::Accelerator(app::VKEY_B, false, false, true)), | 100 views::Accelerator(app::VKEY_B, false, false, true)), |
| 103 accel_enable_accessibility_(WizardAccessibilityHelper::GetAccelerator()), | 101 accel_enable_accessibility_(WizardAccessibilityHelper::GetAccelerator()), |
| 104 delegate_(delegate), | 102 delegate_(delegate), |
| 105 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)), | 103 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)), |
| 106 focus_delayed_(false), | 104 focus_delayed_(false), |
| 107 login_in_process_(false), | 105 login_in_process_(false), |
| 108 need_border_(need_border), | 106 need_border_(need_border), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 splitter_down2_ = CreateSplitter(kSplitterDown2Color); | 149 splitter_down2_ = CreateSplitter(kSplitterDown2Color); |
| 152 | 150 |
| 153 username_field_ = new UsernameField(); | 151 username_field_ = new UsernameField(); |
| 154 username_field_->set_background(new CopyBackground(this)); | 152 username_field_->set_background(new CopyBackground(this)); |
| 155 AddChildView(username_field_); | 153 AddChildView(username_field_); |
| 156 | 154 |
| 157 password_field_ = new TextfieldWithMargin(views::Textfield::STYLE_PASSWORD); | 155 password_field_ = new TextfieldWithMargin(views::Textfield::STYLE_PASSWORD); |
| 158 password_field_->set_background(new CopyBackground(this)); | 156 password_field_->set_background(new CopyBackground(this)); |
| 159 AddChildView(password_field_); | 157 AddChildView(password_field_); |
| 160 | 158 |
| 161 throbber_ = CreateDefaultSmoothedThrobber(); | |
| 162 AddChildView(throbber_); | |
| 163 | |
| 164 language_switch_menu_.InitLanguageMenu(); | 159 language_switch_menu_.InitLanguageMenu(); |
| 165 | 160 |
| 166 RecreatePeculiarControls(); | 161 RecreatePeculiarControls(); |
| 167 | 162 |
| 168 AddChildView(sign_in_button_); | 163 AddChildView(sign_in_button_); |
| 169 if (need_create_account_) { | 164 if (need_create_account_) { |
| 170 InitLink(&create_account_link_); | 165 InitLink(&create_account_link_); |
| 171 } | 166 } |
| 172 if (need_guest_link_) { | 167 if (need_guest_link_) { |
| 173 InitLink(&guest_link_); | 168 InitLink(&guest_link_); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 // Center main controls. | 405 // Center main controls. |
| 411 height = username_field_->GetPreferredSize().height() + | 406 height = username_field_->GetPreferredSize().height() + |
| 412 password_field_->GetPreferredSize().height() + | 407 password_field_->GetPreferredSize().height() + |
| 413 sign_in_button_->GetPreferredSize().height() + | 408 sign_in_button_->GetPreferredSize().height() + |
| 414 2 * kRowPad; | 409 2 * kRowPad; |
| 415 y = title_end + (bottom_start - title_end - height) / 2; | 410 y = title_end + (bottom_start - title_end - height) / 2; |
| 416 | 411 |
| 417 y += setViewBounds(username_field_, x, y, width, true) + kRowPad; | 412 y += setViewBounds(username_field_, x, y, width, true) + kRowPad; |
| 418 y += setViewBounds(password_field_, x, y, width, true) + kRowPad; | 413 y += setViewBounds(password_field_, x, y, width, true) + kRowPad; |
| 419 | 414 |
| 420 int throbber_y = y; | |
| 421 int sign_in_button_width = sign_in_button_->GetPreferredSize().width(); | 415 int sign_in_button_width = sign_in_button_->GetPreferredSize().width(); |
| 422 setViewBounds(sign_in_button_, x, y, sign_in_button_width,true); | 416 setViewBounds(sign_in_button_, x, y, sign_in_button_width,true); |
| 423 setViewBounds(throbber_, | |
| 424 x + width - throbber_->GetPreferredSize().width(), | |
| 425 throbber_y + (sign_in_button_->GetPreferredSize().height() - | |
| 426 throbber_->GetPreferredSize().height()) / 2, | |
| 427 width, | |
| 428 false); | |
| 429 | 417 |
| 430 SchedulePaint(); | 418 SchedulePaint(); |
| 431 } | 419 } |
| 432 | 420 |
| 433 gfx::Size NewUserView::GetPreferredSize() { | 421 gfx::Size NewUserView::GetPreferredSize() { |
| 434 return need_guest_link_ ? | 422 return need_guest_link_ ? |
| 435 gfx::Size(kNewUserPodFullWidth, kNewUserPodFullHeight) : | 423 gfx::Size(kNewUserPodFullWidth, kNewUserPodFullHeight) : |
| 436 gfx::Size(kNewUserPodSmallWidth, kNewUserPodSmallHeight); | 424 gfx::Size(kNewUserPodSmallWidth, kNewUserPodSmallHeight); |
| 437 } | 425 } |
| 438 | 426 |
| 439 void NewUserView::SetUsername(const std::string& username) { | 427 void NewUserView::SetUsername(const std::string& username) { |
| 440 username_field_->SetText(UTF8ToUTF16(username)); | 428 username_field_->SetText(UTF8ToUTF16(username)); |
| 441 } | 429 } |
| 442 | 430 |
| 443 void NewUserView::SetPassword(const std::string& password) { | 431 void NewUserView::SetPassword(const std::string& password) { |
| 444 password_field_->SetText(UTF8ToUTF16(password)); | 432 password_field_->SetText(UTF8ToUTF16(password)); |
| 445 } | 433 } |
| 446 | 434 |
| 447 void NewUserView::Login() { | 435 void NewUserView::Login() { |
| 448 if (login_in_process_ || username_field_->text().empty()) | 436 if (login_in_process_ || username_field_->text().empty()) |
| 449 return; | 437 return; |
| 450 | 438 |
| 451 StartThrobber(); | |
| 452 login_in_process_ = true; | 439 login_in_process_ = true; |
| 453 EnableInputControls(false); | |
| 454 std::string username = UTF16ToUTF8(username_field_->text()); | 440 std::string username = UTF16ToUTF8(username_field_->text()); |
| 455 // todo(cmasone) Need to sanitize memory used to store password. | 441 // todo(cmasone) Need to sanitize memory used to store password. |
| 456 std::string password = UTF16ToUTF8(password_field_->text()); | 442 std::string password = UTF16ToUTF8(password_field_->text()); |
| 457 | 443 |
| 458 if (username.find('@') == std::string::npos) { | 444 if (username.find('@') == std::string::npos) { |
| 459 username += kDefaultDomain; | 445 username += kDefaultDomain; |
| 460 username_field_->SetText(UTF8ToUTF16(username)); | 446 username_field_->SetText(UTF8ToUTF16(username)); |
| 461 } | 447 } |
| 462 | 448 |
| 463 delegate_->OnLogin(username, password); | 449 delegate_->OnLogin(username, password); |
| 464 } | 450 } |
| 465 | 451 |
| 466 // Sign in button causes a login attempt. | 452 // Sign in button causes a login attempt. |
| 467 void NewUserView::ButtonPressed(views::Button* sender, | 453 void NewUserView::ButtonPressed(views::Button* sender, |
| 468 const views::Event& event) { | 454 const views::Event& event) { |
| 469 DCHECK(sender == sign_in_button_); | 455 DCHECK(sender == sign_in_button_); |
| 470 Login(); | 456 Login(); |
| 471 } | 457 } |
| 472 | 458 |
| 473 void NewUserView::LinkActivated(views::Link* source, int event_flags) { | 459 void NewUserView::LinkActivated(views::Link* source, int event_flags) { |
| 474 if (source == create_account_link_) { | 460 if (source == create_account_link_) { |
| 475 delegate_->OnCreateAccount(); | 461 delegate_->OnCreateAccount(); |
| 476 } else if (source == guest_link_) { | 462 } else if (source == guest_link_) { |
| 477 delegate_->OnLoginOffTheRecord(); | 463 delegate_->OnLoginOffTheRecord(); |
| 478 } | 464 } |
| 479 } | 465 } |
| 480 | 466 |
| 481 void NewUserView::ClearAndEnablePassword() { | 467 void NewUserView::ClearAndFocusControls() { |
| 482 login_in_process_ = false; | 468 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()); | 469 SetUsername(std::string()); |
| 493 SetPassword(std::string()); | 470 SetPassword(std::string()); |
| 494 username_field_->RequestFocus(); | 471 username_field_->RequestFocus(); |
| 495 StopThrobber(); | 472 } |
| 473 |
| 474 void NewUserView::ClearAndFocusPassword() { |
| 475 login_in_process_ = false; |
| 476 SetPassword(std::string()); |
| 477 password_field_->RequestFocus(); |
| 478 } |
| 479 |
| 480 gfx::Rect NewUserView::GetMainInputScreenBounds() const { |
| 481 return GetUsernameBounds(); |
| 482 } |
| 483 |
| 484 gfx::Rect NewUserView::CalculateThrobberBounds(views::Throbber* throbber) { |
| 485 DCHECK(password_field_); |
| 486 DCHECK(sign_in_button_); |
| 487 |
| 488 gfx::Size throbber_size = throbber->GetPreferredSize(); |
| 489 int x = password_field_->x(); |
| 490 x += password_field_->width() - throbber_size.width(); |
| 491 int y = sign_in_button_->y(); |
| 492 y += (sign_in_button_->height() - throbber_size.height()) / 2; |
| 493 |
| 494 return gfx::Rect(gfx::Point(x, y), throbber_size); |
| 496 } | 495 } |
| 497 | 496 |
| 498 gfx::Rect NewUserView::GetPasswordBounds() const { | 497 gfx::Rect NewUserView::GetPasswordBounds() const { |
| 499 return password_field_->GetScreenBounds(); | 498 return password_field_->GetScreenBounds(); |
| 500 } | 499 } |
| 501 | 500 |
| 502 gfx::Rect NewUserView::GetUsernameBounds() const { | 501 gfx::Rect NewUserView::GetUsernameBounds() const { |
| 503 return username_field_->GetScreenBounds(); | 502 return username_field_->GetScreenBounds(); |
| 504 } | 503 } |
| 505 | 504 |
| 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, | 505 bool NewUserView::HandleKeystroke(views::Textfield* s, |
| 515 const views::Textfield::Keystroke& keystroke) { | 506 const views::Textfield::Keystroke& keystroke) { |
| 516 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_) | 507 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_) |
| 517 return false; | 508 return false; |
| 518 | 509 |
| 519 if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { | 510 if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { |
| 520 Login(); | 511 Login(); |
| 521 // Return true so that processing ends | 512 // Return true so that processing ends |
| 522 return true; | 513 return true; |
| 523 } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { | 514 } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 542 languages_menubutton_->SetEnabled(enabled); | 533 languages_menubutton_->SetEnabled(enabled); |
| 543 username_field_->SetEnabled(enabled); | 534 username_field_->SetEnabled(enabled); |
| 544 password_field_->SetEnabled(enabled); | 535 password_field_->SetEnabled(enabled); |
| 545 sign_in_button_->SetEnabled(enabled); | 536 sign_in_button_->SetEnabled(enabled); |
| 546 if (need_create_account_) { | 537 if (need_create_account_) { |
| 547 create_account_link_->SetEnabled(enabled); | 538 create_account_link_->SetEnabled(enabled); |
| 548 } | 539 } |
| 549 if (need_guest_link_) { | 540 if (need_guest_link_) { |
| 550 guest_link_->SetEnabled(enabled); | 541 guest_link_->SetEnabled(enabled); |
| 551 } | 542 } |
| 552 delegate_->SetStatusAreaEnabled(enabled); | |
| 553 } | 543 } |
| 554 | 544 |
| 555 void NewUserView::InitLink(views::Link** link) { | 545 void NewUserView::InitLink(views::Link** link) { |
| 556 *link = new views::Link(std::wstring()); | 546 *link = new views::Link(std::wstring()); |
| 557 (*link)->SetController(this); | 547 (*link)->SetController(this); |
| 558 (*link)->SetNormalColor(login::kLinkColor); | 548 (*link)->SetNormalColor(login::kLinkColor); |
| 559 (*link)->SetHighlightedColor(login::kLinkColor); | 549 (*link)->SetHighlightedColor(login::kLinkColor); |
| 560 AddChildView(*link); | 550 AddChildView(*link); |
| 561 } | 551 } |
| 562 | 552 |
| 563 } // namespace chromeos | 553 } // namespace chromeos |
| OLD | NEW |