Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: chrome/browser/chromeos/login/new_user_view.cc

Issue 5709001: Place the spinner in the right corner of the controls window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/chromeos/login
Patch Set: Merged with trunk. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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)),
whywhat 2010/12/09 16:20:18 Do we need to initialize throbber positions here t
altimofeev 2010/12/10 16:37:40 Added impossible initial value for |throbber_cente
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),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 splitter_down2_ = CreateSplitter(kSplitterDown2Color); 150 splitter_down2_ = CreateSplitter(kSplitterDown2Color);
152 151
153 username_field_ = new UsernameField(); 152 username_field_ = new UsernameField();
154 username_field_->set_background(new CopyBackground(this)); 153 username_field_->set_background(new CopyBackground(this));
155 AddChildView(username_field_); 154 AddChildView(username_field_);
156 155
157 password_field_ = new TextfieldWithMargin(views::Textfield::STYLE_PASSWORD); 156 password_field_ = new TextfieldWithMargin(views::Textfield::STYLE_PASSWORD);
158 password_field_->set_background(new CopyBackground(this)); 157 password_field_->set_background(new CopyBackground(this));
159 AddChildView(password_field_); 158 AddChildView(password_field_);
160 159
161 throbber_ = CreateDefaultSmoothedThrobber();
162 AddChildView(throbber_);
163
164 language_switch_menu_.InitLanguageMenu(); 160 language_switch_menu_.InitLanguageMenu();
165 161
166 RecreatePeculiarControls(); 162 RecreatePeculiarControls();
167 163
168 AddChildView(sign_in_button_); 164 AddChildView(sign_in_button_);
169 if (need_create_account_) { 165 if (need_create_account_) {
170 InitLink(&create_account_link_); 166 InitLink(&create_account_link_);
171 } 167 }
172 if (need_guest_link_) { 168 if (need_guest_link_) {
173 InitLink(&guest_link_); 169 InitLink(&guest_link_);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 sign_in_button_->GetPreferredSize().height() + 409 sign_in_button_->GetPreferredSize().height() +
414 2 * kRowPad; 410 2 * kRowPad;
415 y = title_end + (bottom_start - title_end - height) / 2; 411 y = title_end + (bottom_start - title_end - height) / 2;
416 412
417 y += setViewBounds(username_field_, x, y, width, true) + kRowPad; 413 y += setViewBounds(username_field_, x, y, width, true) + kRowPad;
418 y += setViewBounds(password_field_, x, y, width, true) + kRowPad; 414 y += setViewBounds(password_field_, x, y, width, true) + kRowPad;
419 415
420 int throbber_y = y; 416 int throbber_y = y;
421 int sign_in_button_width = sign_in_button_->GetPreferredSize().width(); 417 int sign_in_button_width = sign_in_button_->GetPreferredSize().width();
422 setViewBounds(sign_in_button_, x, y, sign_in_button_width,true); 418 setViewBounds(sign_in_button_, x, y, sign_in_button_width,true);
423 setViewBounds(throbber_, 419
424 x + width - throbber_->GetPreferredSize().width(), 420
425 throbber_y + (sign_in_button_->GetPreferredSize().height() - 421 throbber_right_ = x + width;
426 throbber_->GetPreferredSize().height()) / 2, 422 throbber_center_y_ =
427 width, 423 throbber_y + sign_in_button_->GetPreferredSize().height() / 2;
428 false);
429 424
430 SchedulePaint(); 425 SchedulePaint();
431 } 426 }
432 427
433 gfx::Size NewUserView::GetPreferredSize() { 428 gfx::Size NewUserView::GetPreferredSize() {
434 return need_guest_link_ ? 429 return need_guest_link_ ?
435 gfx::Size(kNewUserPodFullWidth, kNewUserPodFullHeight) : 430 gfx::Size(kNewUserPodFullWidth, kNewUserPodFullHeight) :
436 gfx::Size(kNewUserPodSmallWidth, kNewUserPodSmallHeight); 431 gfx::Size(kNewUserPodSmallWidth, kNewUserPodSmallHeight);
437 } 432 }
438 433
439 void NewUserView::SetUsername(const std::string& username) { 434 void NewUserView::SetUsername(const std::string& username) {
440 username_field_->SetText(UTF8ToUTF16(username)); 435 username_field_->SetText(UTF8ToUTF16(username));
441 } 436 }
442 437
443 void NewUserView::SetPassword(const std::string& password) { 438 void NewUserView::SetPassword(const std::string& password) {
444 password_field_->SetText(UTF8ToUTF16(password)); 439 password_field_->SetText(UTF8ToUTF16(password));
445 } 440 }
446 441
447 void NewUserView::Login() { 442 void NewUserView::Login() {
448 if (login_in_process_ || username_field_->text().empty()) 443 if (login_in_process_ || username_field_->text().empty())
449 return; 444 return;
450 445
451 StartThrobber();
452 login_in_process_ = true; 446 login_in_process_ = true;
453 EnableInputControls(false);
454 std::string username = UTF16ToUTF8(username_field_->text()); 447 std::string username = UTF16ToUTF8(username_field_->text());
455 // todo(cmasone) Need to sanitize memory used to store password. 448 // todo(cmasone) Need to sanitize memory used to store password.
456 std::string password = UTF16ToUTF8(password_field_->text()); 449 std::string password = UTF16ToUTF8(password_field_->text());
457 450
458 if (username.find('@') == std::string::npos) { 451 if (username.find('@') == std::string::npos) {
459 username += kDefaultDomain; 452 username += kDefaultDomain;
460 username_field_->SetText(UTF8ToUTF16(username)); 453 username_field_->SetText(UTF8ToUTF16(username));
461 } 454 }
462 455
463 delegate_->OnLogin(username, password); 456 delegate_->OnLogin(username, password);
464 } 457 }
465 458
466 // Sign in button causes a login attempt. 459 // Sign in button causes a login attempt.
467 void NewUserView::ButtonPressed(views::Button* sender, 460 void NewUserView::ButtonPressed(views::Button* sender,
468 const views::Event& event) { 461 const views::Event& event) {
469 DCHECK(sender == sign_in_button_); 462 DCHECK(sender == sign_in_button_);
470 Login(); 463 Login();
471 } 464 }
472 465
473 void NewUserView::LinkActivated(views::Link* source, int event_flags) { 466 void NewUserView::LinkActivated(views::Link* source, int event_flags) {
474 if (source == create_account_link_) { 467 if (source == create_account_link_) {
475 delegate_->OnCreateAccount(); 468 delegate_->OnCreateAccount();
476 } else if (source == guest_link_) { 469 } else if (source == guest_link_) {
477 delegate_->OnLoginOffTheRecord(); 470 delegate_->OnLoginOffTheRecord();
478 } 471 }
479 } 472 }
480 473
481 void NewUserView::ClearAndEnablePassword() { 474 void NewUserView::ClearAndFocusControls() {
482 login_in_process_ = false; 475 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()); 476 SetUsername(std::string());
493 SetPassword(std::string()); 477 SetPassword(std::string());
494 username_field_->RequestFocus(); 478 username_field_->RequestFocus();
495 StopThrobber(); 479 }
480
481 void NewUserView::ClearAndFocusPassword() {
482 login_in_process_ = false;
483 SetPassword(std::string());
484 password_field_->RequestFocus();
485 }
486
487 gfx::Rect NewUserView::GetControlWithErrorBounds() const {
488 return GetUsernameBounds();
489 }
490
491 bool NewUserView::UseCustomBoundsForThrobber(const gfx::Size& throbber,
492 gfx::Rect* bounds) const {
493 gfx::Point origin(throbber_right_- throbber.width(),
494 throbber_center_y_ - throbber.height() / 2);
whywhat 2010/12/09 16:20:18 Move this one space to the right. Also as I noted
altimofeev 2010/12/10 16:37:40 Added call to Layout() if there wasn't any.
495 bounds->set_origin(origin);
496 bounds->set_size(throbber);
497 return true;
496 } 498 }
497 499
498 gfx::Rect NewUserView::GetPasswordBounds() const { 500 gfx::Rect NewUserView::GetPasswordBounds() const {
499 return password_field_->GetScreenBounds(); 501 return password_field_->GetScreenBounds();
500 } 502 }
501 503
502 gfx::Rect NewUserView::GetUsernameBounds() const { 504 gfx::Rect NewUserView::GetUsernameBounds() const {
503 return username_field_->GetScreenBounds(); 505 return username_field_->GetScreenBounds();
504 } 506 }
505 507
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, 508 bool NewUserView::HandleKeystroke(views::Textfield* s,
515 const views::Textfield::Keystroke& keystroke) { 509 const views::Textfield::Keystroke& keystroke) {
516 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_) 510 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_)
517 return false; 511 return false;
518 512
519 if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { 513 if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) {
520 Login(); 514 Login();
521 // Return true so that processing ends 515 // Return true so that processing ends
522 return true; 516 return true;
523 } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { 517 } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) {
(...skipping 18 matching lines...) Expand all
542 languages_menubutton_->SetEnabled(enabled); 536 languages_menubutton_->SetEnabled(enabled);
543 username_field_->SetEnabled(enabled); 537 username_field_->SetEnabled(enabled);
544 password_field_->SetEnabled(enabled); 538 password_field_->SetEnabled(enabled);
545 sign_in_button_->SetEnabled(enabled); 539 sign_in_button_->SetEnabled(enabled);
546 if (need_create_account_) { 540 if (need_create_account_) {
547 create_account_link_->SetEnabled(enabled); 541 create_account_link_->SetEnabled(enabled);
548 } 542 }
549 if (need_guest_link_) { 543 if (need_guest_link_) {
550 guest_link_->SetEnabled(enabled); 544 guest_link_->SetEnabled(enabled);
551 } 545 }
552 delegate_->SetStatusAreaEnabled(enabled);
553 } 546 }
554 547
555 void NewUserView::InitLink(views::Link** link) { 548 void NewUserView::InitLink(views::Link** link) {
556 *link = new views::Link(std::wstring()); 549 *link = new views::Link(std::wstring());
557 (*link)->SetController(this); 550 (*link)->SetController(this);
558 (*link)->SetNormalColor(login::kLinkColor); 551 (*link)->SetNormalColor(login::kLinkColor);
559 (*link)->SetHighlightedColor(login::kLinkColor); 552 (*link)->SetHighlightedColor(login::kLinkColor);
560 AddChildView(*link); 553 AddChildView(*link);
561 } 554 }
562 555
563 } // namespace chromeos 556 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698