diff options
Diffstat (limited to 'chrome')
19 files changed, 370 insertions, 265 deletions
diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc index 2e2bb5a..55a347c 100644 --- a/chrome/browser/chromeos/login/existing_user_controller.cc +++ b/chrome/browser/chromeos/login/existing_user_controller.cc @@ -214,14 +214,11 @@ void ExistingUserController::LoginNewUser(const std::string& username, DCHECK(new_user->is_new_user()); if (!new_user->is_new_user()) return; - NewUserView* new_user_view = new_user->new_user_view(); - new_user_view->SetUsername(username); if (password.empty()) return; - new_user_view->SetPassword(password); - new_user_view->Login(); + new_user->OnLogin(username, password); } void ExistingUserController::SelectNewUser() { @@ -361,6 +358,7 @@ void ExistingUserController::ActivateWizard(const std::string& screen_name) { // is doing an animation with our windows. DCHECK(!delete_scheduled_instance_); delete_scheduled_instance_ = this; + delete_timer_.Start(base::TimeDelta::FromSeconds(1), this, &ExistingUserController::Delete); } @@ -469,7 +467,8 @@ void ExistingUserController::ShowError(int error_id, // For now just ignore it because error_text contains all required information // for end users, developers can see details string in Chrome logs. - gfx::Rect bounds = controllers_[selected_view_index_]->GetScreenBounds(); + gfx::Rect bounds = + controllers_[selected_view_index_]->GetMainInputScreenBounds(); BubbleBorder::ArrowLocation arrow; if (controllers_[selected_view_index_]->is_new_user()) { arrow = BubbleBorder::LEFT_TOP; @@ -510,6 +509,7 @@ void ExistingUserController::OnLoginSuccess( performer = NULL; bool known_user = UserManager::Get()->IsKnownUser(username); AppendStartUrlToCmdline(); + controllers_[selected_view_index_]->StopThrobber(); if (selected_view_index_ + 1 == controllers_.size() && !known_user) { #if defined(OFFICIAL_BUILD) CommandLine::ForCurrentProcess()->AppendSwitchPath( diff --git a/chrome/browser/chromeos/login/existing_user_view.cc b/chrome/browser/chromeos/login/existing_user_view.cc index d5bb4c3..6f4e60e 100644 --- a/chrome/browser/chromeos/login/existing_user_view.cc +++ b/chrome/browser/chromeos/login/existing_user_view.cc @@ -5,7 +5,7 @@ #include "chrome/browser/chromeos/login/existing_user_view.h" #include "app/l10n_util.h" -#include "chrome/browser/chromeos/login/helper.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/login/user_controller.h" #include "chrome/browser/chromeos/login/textfield_with_margin.h" #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" @@ -34,8 +34,7 @@ class UserEntryTextfield : public TextfieldWithMargin { // Overridden from views::View: virtual bool OnKeyPressed(const views::KeyEvent& e) { if (e.GetKeyCode() == app::VKEY_TAB) { - int index = controller_->user_index() + (e.IsShiftDown() ? -1 : 1); - controller_->SelectUser(index); + controller_->SelectUserRelative(e.IsShiftDown() ? -1 : 1); return true; } else { return false; @@ -56,11 +55,11 @@ class UserEntryTextfield : public TextfieldWithMargin { }; -ExistingUserView::ExistingUserView(UserController* uc) - : accel_login_off_the_record_( - views::Accelerator(app::VKEY_B, false, false, true)), +ExistingUserView::ExistingUserView(UserController* user_controller) + : user_controller_(user_controller), password_field_(NULL), - user_controller_(uc), + accel_login_off_the_record_( + views::Accelerator(app::VKEY_B, false, false, true)), accel_enable_accessibility_( WizardAccessibilityHelper::GetAccelerator()) { AddAccelerator(accel_login_off_the_record_); @@ -76,7 +75,7 @@ void ExistingUserView::RecreateFields() { views::Background::CreateVerticalGradientBackground( kBackgroundColorTop, kBackgroundColorBottom)); password_field_->SetFocusable(true); - password_field_->SetController(user_controller_); + password_field_->SetController(this); AddChildView(password_field_); } password_field_->set_text_to_display_when_empty( @@ -97,6 +96,39 @@ bool ExistingUserView::AcceleratorPressed( return false; } +bool ExistingUserView::HandleKeystroke( + views::Textfield* sender, + const views::Textfield::Keystroke& keystroke) { + if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { + user_controller_->OnLogin("", UTF16ToUTF8(password_field_->text())); + } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { + user_controller_->SelectUserRelative(-1); + } else if (keystroke.GetKeyboardCode() == app::VKEY_RIGHT) { + user_controller_->SelectUserRelative(1); + } else { + user_controller_->ClearErrors(); + return false; + } + return true; +} + +void ExistingUserView::ContentsChanged(views::Textfield* sender, + const string16& new_contents) { +} + +void ExistingUserView::EnableInputControls(bool enabled) { + password_field_->SetEnabled(enabled); +} + +void ExistingUserView::ClearAndFocusControls() { + ClearAndFocusPassword(); +} + +void ExistingUserView::ClearAndFocusPassword() { + password_field_->SetText(string16()); + FocusPasswordField(); +} + void ExistingUserView::ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child) { @@ -105,9 +137,11 @@ void ExistingUserView::ViewHierarchyChanged(bool is_add, } void ExistingUserView::FocusPasswordField() { - if (GetFocusManager()) { - password_field()->RequestFocus(); - } + password_field_->RequestFocus(); +} + +gfx::Rect ExistingUserView::GetMainInputScreenBounds() const { + return password_field_->GetScreenBounds(); } void ExistingUserView::OnLocaleChanged() { diff --git a/chrome/browser/chromeos/login/existing_user_view.h b/chrome/browser/chromeos/login/existing_user_view.h index 004ff2166..42253d4 100644 --- a/chrome/browser/chromeos/login/existing_user_view.h +++ b/chrome/browser/chromeos/login/existing_user_view.h @@ -6,6 +6,8 @@ #define CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_VIEW_H_ #pragma once +#include "chrome/browser/chromeos/login/helper.h" +#include "chrome/browser/chromeos/login/user_input.h" #include "views/accelerator.h" #include "views/controls/button/native_button.h" #include "views/controls/textfield/textfield.h" @@ -15,19 +17,31 @@ namespace chromeos { class UserController; -class ExistingUserView : public views::View { +class ExistingUserView : public ThrobberHostView, + public UserInput, + public views::Textfield::Controller { public: - explicit ExistingUserView(UserController* uc); + explicit ExistingUserView(UserController* user_controller); void RecreateFields(); - views::Textfield* password_field() { return password_field_; } - void FocusPasswordField(); // Overridden from views::View: virtual bool AcceleratorPressed(const views::Accelerator& accelerator); + // Overriden from Textfield::Controller: + virtual void ContentsChanged(views::Textfield* sender, + const string16& new_contents); + virtual bool HandleKeystroke(views::Textfield* sender, + const views::Textfield::Keystroke& keystroke); + + // Overriden from UserInput: + virtual void EnableInputControls(bool enabled); + virtual void ClearAndFocusControls(); + virtual void ClearAndFocusPassword(); + virtual gfx::Rect GetMainInputScreenBounds() const; + protected: // Overridden from views::View: virtual void OnLocaleChanged(); @@ -35,14 +49,13 @@ class ExistingUserView : public views::View { views::View* parent, views::View* child); - views::Accelerator accel_login_off_the_record_; + private: + UserController* user_controller_; // For editing the password. views::Textfield* password_field_; - UserController* user_controller_; - - private: + views::Accelerator accel_login_off_the_record_; views::Accelerator accel_enable_accessibility_; DISALLOW_COPY_AND_ASSIGN(ExistingUserView); diff --git a/chrome/browser/chromeos/login/guest_user_view.cc b/chrome/browser/chromeos/login/guest_user_view.cc index a06e017..049879d 100644 --- a/chrome/browser/chromeos/login/guest_user_view.cc +++ b/chrome/browser/chromeos/login/guest_user_view.cc @@ -5,7 +5,6 @@ #include "chrome/browser/chromeos/login/guest_user_view.h" #include "app/l10n_util.h" -#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/user_controller.h" #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" #include "grit/generated_resources.h" @@ -15,16 +14,16 @@ namespace chromeos { // Button with custom processing for Tab/Shift+Tab to select entries. class UserEntryButton : public login::WideButton { public: - UserEntryButton(UserController* controller, + UserEntryButton(views::ButtonListener* button_listener, + UserController* user_controller, const std::wstring& label) - : WideButton(controller, label), - controller_(controller) {} + : WideButton(button_listener, label), + user_controller_(user_controller) {} // Overridden from views::View: virtual bool OnKeyPressed(const views::KeyEvent& e) { if (e.GetKeyCode() == app::VKEY_TAB) { - int index = controller_->user_index() + (e.IsShiftDown() ? -1 : 1); - controller_->SelectUser(index); + user_controller_->SelectUserRelative(e.IsShiftDown() ? -1 : 1); return true; } return WideButton::OnKeyPressed(e); @@ -37,7 +36,7 @@ class UserEntryButton : public login::WideButton { } private: - UserController* controller_; + UserController* user_controller_; DISALLOW_COPY_AND_ASSIGN(UserEntryButton); }; @@ -63,6 +62,7 @@ GuestUserView::GuestUserView(UserController* uc) void GuestUserView::RecreateFields() { delete submit_button_; submit_button_ = new UserEntryButton( + this, user_controller_, l10n_util::GetString(IDS_ENTER_GUEST_SESSION_BUTTON)); AddChildView(submit_button_); @@ -71,8 +71,7 @@ void GuestUserView::RecreateFields() { } void GuestUserView::FocusSignInButton() { - if (GetFocusManager()) - submit_button_->RequestFocus(); + submit_button_->RequestFocus(); } bool GuestUserView::AcceleratorPressed( @@ -82,14 +81,24 @@ bool GuestUserView::AcceleratorPressed( else if (accelerator == accel_enable_accessibility_) WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); else if (accelerator == accel_previous_pod_by_arrow_) - user_controller_->SelectUser(user_controller_->user_index() - 1); + user_controller_->SelectUserRelative(-1); else if (accelerator == accel_next_pod_by_arrow_) - user_controller_->SelectUser(user_controller_->user_index() + 1); + user_controller_->SelectUserRelative(1); else return false; return true; } +void GuestUserView::ButtonPressed( + views::Button* sender, const views::Event& event) { + DCHECK(sender == submit_button_); + user_controller_->OnLoginOffTheRecord(); +} + +void GuestUserView::EnableInputControls(bool enabled) { + submit_button_->SetEnabled(enabled); +} + void GuestUserView::ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child) { @@ -111,4 +120,15 @@ void GuestUserView::Layout() { submit_button_size.height()); } +void GuestUserView::ClearAndFocusControls() { +} + +void GuestUserView::ClearAndFocusPassword() { +} + +gfx::Rect GuestUserView::GetMainInputScreenBounds() const { + NOTREACHED(); + return gfx::Rect(); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/guest_user_view.h b/chrome/browser/chromeos/login/guest_user_view.h index d9590f5..1820f0e 100644 --- a/chrome/browser/chromeos/login/guest_user_view.h +++ b/chrome/browser/chromeos/login/guest_user_view.h @@ -6,6 +6,8 @@ #define CHROME_BROWSER_CHROMEOS_LOGIN_GUEST_USER_VIEW_H_ #pragma once +#include "chrome/browser/chromeos/login/helper.h" +#include "chrome/browser/chromeos/login/user_input.h" #include "views/accelerator.h" #include "views/controls/button/native_button.h" #include "views/controls/textfield/textfield.h" @@ -18,7 +20,9 @@ class UserController; // This view is for controls window of Guest mode pod that allows user to // get temporary profile and use it for browsing. Contains only one Sign-in // button and handles different common keyboard shortcuts. -class GuestUserView : public views::View { +class GuestUserView : public ThrobberHostView, + public UserInput, + public views::ButtonListener { public: explicit GuestUserView(UserController* uc); @@ -29,6 +33,15 @@ class GuestUserView : public views::View { // Overridden from views::View: virtual bool AcceleratorPressed(const views::Accelerator& accelerator); + // Overridden from views::ButtonListener. + virtual void ButtonPressed(views::Button* sender, const views::Event& event); + + // Overridden from UserInput: + virtual void EnableInputControls(bool enabled); + virtual void ClearAndFocusControls(); + virtual void ClearAndFocusPassword(); + virtual gfx::Rect GetMainInputScreenBounds() const; + private: // Overridden from views::View: virtual void OnLocaleChanged(); diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index 1b7ebba..188a3ce 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -17,6 +17,7 @@ #include "views/controls/throbber.h" #include "views/painter.h" #include "views/screen.h" +#include "views/widget/widget.h" namespace chromeos { @@ -67,7 +68,52 @@ class BackgroundPainter : public views::Painter { } // namespace -views::Throbber* CreateDefaultSmoothedThrobber() { +ThrobberHostView::ThrobberHostView() + : host_view_(this), + throbber_widget_(NULL) { +} + +ThrobberHostView::~ThrobberHostView() { + StopThrobber(); +} + +void ThrobberHostView::StartThrobber() { + StopThrobber(); + views::Widget* widget = host_view_->GetWidget(); + if (widget) { + views::SmoothedThrobber* throbber = CreateDefaultSmoothedThrobber(); + throbber->set_stop_delay_ms(0); + gfx::Rect throbber_bounds = CalculateThrobberBounds(throbber); + + throbber_widget_ = + views::Widget::CreatePopupWidget(views::Widget::Transparent, + views::Widget::NotAcceptEvents, + views::Widget::DeleteOnDestroy, + views::Widget::DontMirrorOriginInRTL); + throbber_bounds.Offset(host_view_->GetScreenBounds().origin()); + throbber_widget_->InitWithWidget(widget, throbber_bounds); + throbber_widget_->SetContentsView(throbber); + throbber_widget_->Show(); + throbber->Start(); + } +} + +void ThrobberHostView::StopThrobber() { + if (throbber_widget_) { + throbber_widget_->Close(); + throbber_widget_ = NULL; + } +} + +gfx::Rect ThrobberHostView::CalculateThrobberBounds(views::Throbber* throbber) { + gfx::Rect bounds(throbber->GetPreferredSize()); + bounds.set_x( + host_view_->width() - login::kThrobberRightMargin - bounds.width()); + bounds.set_y((host_view_->height() - bounds.height()) / 2); + return bounds; +} + +views::SmoothedThrobber* CreateDefaultSmoothedThrobber() { views::SmoothedThrobber* throbber = new views::SmoothedThrobber(kThrobberFrameMs); throbber->SetFrames( @@ -94,7 +140,6 @@ gfx::Rect CalculateScreenBounds(const gfx::Size& size) { int vertical_diff = bounds.height() - size.height(); bounds.Inset(horizontal_diff / 2, vertical_diff / 2); } - return bounds; } @@ -138,4 +183,3 @@ gfx::Size WideButton::GetPreferredSize() { } // namespace login } // namespace chromeos - diff --git a/chrome/browser/chromeos/login/helper.h b/chrome/browser/chromeos/login/helper.h index 0ecfe4f..1c3851a 100644 --- a/chrome/browser/chromeos/login/helper.h +++ b/chrome/browser/chromeos/login/helper.h @@ -8,8 +8,10 @@ #define CHROME_BROWSER_CHROMEOS_LOGIN_HELPER_H_ #pragma once -#include "views/controls/button/native_button.h" #include "third_party/skia/include/core/SkColor.h" +#include "views/controls/button/native_button.h" +#include "views/view.h" +#include "views/widget/widget_gtk.h" class GURL; @@ -22,14 +24,49 @@ namespace views { class Label; class MenuButton; class Painter; +class SmoothedThrobber; class Textfield; class Throbber; +class Widget; } // namespace views namespace chromeos { +// View that provides interface for start/stop throbber above the view. +class ThrobberHostView : public views::View { + public: + ThrobberHostView(); + virtual ~ThrobberHostView(); + + // Creates throbber above the view in the right side with the default + // margin. Also places throbber in the middle of the vertical host size. + // Override |CalculateThrobberBounds| method to change the throbber placing. + virtual void StartThrobber(); + + // Stops the throbber. + virtual void StopThrobber(); + + protected: + // Calculates the bounds of the throbber relatively to the host view. + // Default position is vertically centered right side of the host view. + virtual gfx::Rect CalculateThrobberBounds(views::Throbber* throbber); + + void set_host_view(views::View* host_view) { + host_view_ = host_view; + } + + private: + // View to show the throbber above (default is |this|). + views::View* host_view_; + + // Popup that contains the throbber. + views::Widget* throbber_widget_; + + DISALLOW_COPY_AND_ASSIGN(ThrobberHostView); +}; + // Creates default smoothed throbber for time consuming operations on login. -views::Throbber* CreateDefaultSmoothedThrobber(); +views::SmoothedThrobber* CreateDefaultSmoothedThrobber(); // Creates default throbber. views::Throbber* CreateDefaultThrobber(); @@ -81,6 +118,9 @@ const SkColor kTextColor = SK_ColorWHITE; // Default link color on login/OOBE controls. const SkColor kLinkColor = 0xFF0066CC; +// Right margin for placing throbber above the view. +const int kThrobberRightMargin = 10; + // Default size of the OOBE screen. Includes 10px shadow from each side. // See rounded_rect_painter.cc for border definitions. const int kWizardScreenWidth = 800; diff --git a/chrome/browser/chromeos/login/login_screen.cc b/chrome/browser/chromeos/login/login_screen.cc index f14b5f35..c26a552 100644 --- a/chrome/browser/chromeos/login/login_screen.cc +++ b/chrome/browser/chromeos/login/login_screen.cc @@ -91,7 +91,8 @@ void LoginScreen::OnLoginFailure(const LoginFailure& failure) { ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error); } - view()->ClearAndEnablePassword(); + view()->ClearAndFocusPassword(); + view()->EnableInputControls(true); } void LoginScreen::OnLoginSuccess( diff --git a/chrome/browser/chromeos/login/new_user_view.cc b/chrome/browser/chromeos/login/new_user_view.cc index 974ad66..6331fbb 100644 --- a/chrome/browser/chromeos/login/new_user_view.cc +++ b/chrome/browser/chromeos/login/new_user_view.cc @@ -20,7 +20,6 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/rounded_rect_painter.h" #include "chrome/browser/chromeos/login/textfield_with_margin.h" #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" @@ -95,7 +94,6 @@ NewUserView::NewUserView(Delegate* delegate, create_account_link_(NULL), guest_link_(NULL), languages_menubutton_(NULL), - throbber_(NULL), accel_focus_pass_(views::Accelerator(app::VKEY_P, false, false, true)), accel_focus_user_(views::Accelerator(app::VKEY_U, false, false, true)), accel_login_off_the_record_( @@ -158,9 +156,6 @@ void NewUserView::Init() { password_field_->set_background(new CopyBackground(this)); AddChildView(password_field_); - throbber_ = CreateDefaultSmoothedThrobber(); - AddChildView(throbber_); - language_switch_menu_.InitLanguageMenu(); RecreatePeculiarControls(); @@ -417,15 +412,8 @@ void NewUserView::Layout() { y += setViewBounds(username_field_, x, y, width, true) + kRowPad; y += setViewBounds(password_field_, x, y, width, true) + kRowPad; - int throbber_y = y; int sign_in_button_width = sign_in_button_->GetPreferredSize().width(); setViewBounds(sign_in_button_, x, y, sign_in_button_width,true); - setViewBounds(throbber_, - x + width - throbber_->GetPreferredSize().width(), - throbber_y + (sign_in_button_->GetPreferredSize().height() - - throbber_->GetPreferredSize().height()) / 2, - width, - false); SchedulePaint(); } @@ -448,9 +436,7 @@ void NewUserView::Login() { if (login_in_process_ || username_field_->text().empty()) return; - StartThrobber(); login_in_process_ = true; - EnableInputControls(false); std::string username = UTF16ToUTF8(username_field_->text()); // todo(cmasone) Need to sanitize memory used to store password. std::string password = UTF16ToUTF8(password_field_->text()); @@ -478,37 +464,42 @@ void NewUserView::LinkActivated(views::Link* source, int event_flags) { } } -void NewUserView::ClearAndEnablePassword() { +void NewUserView::ClearAndFocusControls() { login_in_process_ = false; - EnableInputControls(true); + SetUsername(std::string()); SetPassword(std::string()); - password_field_->RequestFocus(); - StopThrobber(); + username_field_->RequestFocus(); } -void NewUserView::ClearAndEnableFields() { +void NewUserView::ClearAndFocusPassword() { login_in_process_ = false; - EnableInputControls(true); - SetUsername(std::string()); SetPassword(std::string()); - username_field_->RequestFocus(); - StopThrobber(); + password_field_->RequestFocus(); } -gfx::Rect NewUserView::GetPasswordBounds() const { - return password_field_->GetScreenBounds(); +gfx::Rect NewUserView::GetMainInputScreenBounds() const { + return GetUsernameBounds(); } -gfx::Rect NewUserView::GetUsernameBounds() const { - return username_field_->GetScreenBounds(); +gfx::Rect NewUserView::CalculateThrobberBounds(views::Throbber* throbber) { + DCHECK(password_field_); + DCHECK(sign_in_button_); + + gfx::Size throbber_size = throbber->GetPreferredSize(); + int x = password_field_->x(); + x += password_field_->width() - throbber_size.width(); + int y = sign_in_button_->y(); + y += (sign_in_button_->height() - throbber_size.height()) / 2; + + return gfx::Rect(gfx::Point(x, y), throbber_size); } -void NewUserView::StartThrobber() { - throbber_->Start(); +gfx::Rect NewUserView::GetPasswordBounds() const { + return password_field_->GetScreenBounds(); } -void NewUserView::StopThrobber() { - throbber_->Stop(); +gfx::Rect NewUserView::GetUsernameBounds() const { + return username_field_->GetScreenBounds(); } bool NewUserView::HandleKeystroke(views::Textfield* s, @@ -549,7 +540,6 @@ void NewUserView::EnableInputControls(bool enabled) { if (need_guest_link_) { guest_link_->SetEnabled(enabled); } - delegate_->SetStatusAreaEnabled(enabled); } void NewUserView::InitLink(views::Link** link) { diff --git a/chrome/browser/chromeos/login/new_user_view.h b/chrome/browser/chromeos/login/new_user_view.h index bfeed4e..6b282d0 100644 --- a/chrome/browser/chromeos/login/new_user_view.h +++ b/chrome/browser/chromeos/login/new_user_view.h @@ -9,7 +9,9 @@ #include <string> #include "base/task.h" +#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/language_switch_menu.h" +#include "chrome/browser/chromeos/login/user_input.h" #include "views/accelerator.h" #include "views/controls/button/button.h" #include "views/controls/button/menu_button.h" @@ -20,14 +22,14 @@ namespace views { class Label; class NativeButton; -class Throbber; } // namespace views namespace chromeos { // View that is used for new user login. It asks for username and password, // allows to specify language preferences or initiate new account creation. -class NewUserView : public views::View, +class NewUserView : public ThrobberHostView, + public UserInput, public views::Textfield::Controller, public views::LinkController, public views::ButtonListener { @@ -73,18 +75,6 @@ class NewUserView : public views::View, // Update strings from the resources. Executed on language change. void UpdateLocalizedStrings(); - // Resets password text and sets the enabled state of the password. - void ClearAndEnablePassword(); - - // Resets password and username text and focuses on username. - void ClearAndEnableFields(); - - // Starts throbber shown during login. - void StartThrobber(); - - // Stops throbber shown during login. - void StopThrobber(); - // Returns bounds of password field in screen coordinates. gfx::Rect GetPasswordBounds() const; @@ -115,9 +105,17 @@ class NewUserView : public views::View, // Overridden from views::LinkController. virtual void LinkActivated(views::Link* source, int event_flags); - virtual bool AcceleratorPressed(const views::Accelerator& accelerator); + // Overridden from ThrobberHostView: + virtual gfx::Rect CalculateThrobberBounds(views::Throbber* throbber); + + // Overridden from UserInput: + virtual void EnableInputControls(bool enabled); + virtual void ClearAndFocusControls(); + virtual void ClearAndFocusPassword(); + virtual gfx::Rect GetMainInputScreenBounds() const; + protected: // views::View overrides: virtual void ViewHierarchyChanged(bool is_add, @@ -130,8 +128,6 @@ class NewUserView : public views::View, void AddChildView(View* view); private: - // Enables/disables input controls (textfields, buttons). - void EnableInputControls(bool enabled); void FocusFirstField(); // Creates Link control and adds it as a child. @@ -165,7 +161,6 @@ class NewUserView : public views::View, views::Link* create_account_link_; views::Link* guest_link_; views::MenuButton* languages_menubutton_; - views::Throbber* throbber_; views::Accelerator accel_focus_pass_; views::Accelerator accel_focus_user_; diff --git a/chrome/browser/chromeos/login/rounded_view.h b/chrome/browser/chromeos/login/rounded_view.h index b58e44d..6a1bea5 100644 --- a/chrome/browser/chromeos/login/rounded_view.h +++ b/chrome/browser/chromeos/login/rounded_view.h @@ -1,5 +1,9 @@ -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_ROUNDED_VIEW_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_ROUNDED_VIEW_H_ #include "gfx/canvas.h" #include "gfx/canvas_skia.h" @@ -124,4 +128,4 @@ void RoundedView<C>::DrawFrame(gfx::Canvas* canvas) { } -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_ROUNDED_VIEW_H_ diff --git a/chrome/browser/chromeos/login/screen_lock_view.cc b/chrome/browser/chromeos/login/screen_lock_view.cc index 2500dae..7b3f4ea 100644 --- a/chrome/browser/chromeos/login/screen_lock_view.cc +++ b/chrome/browser/chromeos/login/screen_lock_view.cc @@ -7,7 +7,6 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/rounded_rect_painter.h" #include "chrome/browser/chromeos/login/screen_locker.h" #include "chrome/browser/chromeos/login/user_manager.h" @@ -67,6 +66,9 @@ ScreenLockView::ScreenLockView(ScreenLocker* screen_locker) DCHECK(screen_locker_); } +ScreenLockView::~ScreenLockView() { +} + gfx::Size ScreenLockView::GetPreferredSize() { return main_->GetPreferredSize(); } @@ -100,9 +102,13 @@ void ScreenLockView::Init() { // Password field. password_field_ = new PasswordField(); + password_field_->SetController(this); password_field_->set_background(new CopyBackground(main_)); + // Setup ThrobberView's host view. + set_host_view(password_field_); + // User icon. UserManager::User user = screen_locker_->user(); user_view_->SetImage(user.image(), user.image()); @@ -160,11 +166,11 @@ gfx::Rect ScreenLockView::GetPasswordBoundsRelativeTo(const views::View* view) { return gfx::Rect(p, size()); } + void ScreenLockView::SetEnabled(bool enabled) { views::View::SetEnabled(enabled); if (!enabled) { - user_view_->StartThrobber(); // TODO(oshima): Re-enabling does not move the focus to the view // that had a focus (issue http://crbug.com/43131). // Clear focus on the textfield so that re-enabling can set focus @@ -173,8 +179,6 @@ void ScreenLockView::SetEnabled(bool enabled) { // associated Widget yet. if (password_field_->GetFocusManager()) password_field_->GetFocusManager()->ClearFocus(); - } else { - user_view_->StopThrobber(); } password_field_->SetEnabled(enabled); } @@ -213,4 +217,5 @@ void ScreenLockView::ViewHierarchyChanged(bool is_add, if (is_add && this == child) WizardAccessibilityHelper::GetInstance()->MaybeEnableAccessibility(this); } + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/screen_lock_view.h b/chrome/browser/chromeos/login/screen_lock_view.h index 9ceefd1..1e3916e 100644 --- a/chrome/browser/chromeos/login/screen_lock_view.h +++ b/chrome/browser/chromeos/login/screen_lock_view.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREEN_LOCK_VIEW_H_ #pragma once +#include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/user_view.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" @@ -27,13 +28,13 @@ class ScreenLockerTester; // ScreenLockView creates view components necessary to authenticate // a user to unlock the screen. -class ScreenLockView : public views::View, +class ScreenLockView : public ThrobberHostView, public views::Textfield::Controller, public NotificationObserver, public UserView::Delegate { public: explicit ScreenLockView(ScreenLocker* screen_locker); - virtual ~ScreenLockView() {} + virtual ~ScreenLockView(); void Init(); diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index c4ca040..329a5fc 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -648,6 +648,7 @@ void ScreenLocker::Init() { screen_lock_view_ = new ScreenLockView(this); screen_lock_view_->Init(); screen_lock_view_->SetEnabled(false); + screen_lock_view_->StartThrobber(); } else { input_event_observer_.reset(new InputEventObserver(this)); MessageLoopForUI::current()->AddObserver(input_event_observer_.get()); @@ -784,6 +785,7 @@ void ScreenLocker::Authenticate(const string16& password) { authentication_start_time_ = base::Time::Now(); screen_lock_view_->SetEnabled(false); screen_lock_view_->SetSignoutEnabled(false); + screen_lock_view_->StartThrobber(); // If LoginPerformer instance exists, // initial online login phase is still active. @@ -812,6 +814,7 @@ void ScreenLocker::EnableInput() { if (screen_lock_view_) { screen_lock_view_->SetEnabled(true); screen_lock_view_->ClearAndSetFocusToPassword(); + screen_lock_view_->StopThrobber(); } } diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc index 8a1436c6..7412c8c 100644 --- a/chrome/browser/chromeos/login/user_controller.cc +++ b/chrome/browser/chromeos/login/user_controller.cc @@ -28,6 +28,7 @@ #include "views/background.h" #include "views/controls/button/native_button.h" #include "views/controls/label.h" +#include "views/controls/throbber.h" #include "views/grid_layout.h" #include "views/painter.h" #include "views/screen.h" @@ -69,7 +70,7 @@ class ClickNotifyingWidget : public views::WidgetGtk { private: gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event) { if (!controller_->is_user_selected()) - controller_->SelectUser(controller_->user_index()); + controller_->SelectUserRelative(0); return views::WidgetGtk::OnButtonPress(widget, event); } @@ -114,11 +115,10 @@ UserController::UserController(Delegate* delegate, bool is_guest) label_window_(NULL), unselected_label_window_(NULL), user_view_(NULL), - new_user_view_(NULL), - existing_user_view_(NULL), - guest_user_view_(NULL), label_view_(NULL), unselected_label_view_(NULL), + user_input_(NULL), + throbber_host_(NULL), method_factory_(this) { registrar_.Add( this, @@ -144,11 +144,10 @@ UserController::UserController(Delegate* delegate, label_window_(NULL), unselected_label_window_(NULL), user_view_(NULL), - new_user_view_(NULL), - existing_user_view_(NULL), - guest_user_view_(NULL), label_view_(NULL), unselected_label_view_(NULL), + user_input_(NULL), + throbber_host_(NULL), method_factory_(this) { DCHECK(!user.email().empty()); registrar_.Add( @@ -183,16 +182,12 @@ void UserController::Init(int index, CreateLabelWindow(index, WM_IPC_WINDOW_LOGIN_UNSELECTED_LABEL); } -void UserController::SetPasswordEnabled(bool enable) { - DCHECK(!is_new_user_); - existing_user_view_->password_field()->SetEnabled(enable); - if (enable) { - user_view_->StopThrobber(); - delegate_->SetStatusAreaEnabled(enable); - } else { - delegate_->SetStatusAreaEnabled(enable); - user_view_->StartThrobber(); - } +void UserController::StartThrobber() { + throbber_host_->StartThrobber(); +} + +void UserController::StopThrobber() { + throbber_host_->StopThrobber(); } std::wstring UserController::GetNameTooltip() const { @@ -217,25 +212,22 @@ std::wstring UserController::GetNameTooltip() const { domain.c_str())); } +void UserController::ClearAndEnableFields() { + user_input_->ClearAndFocusControls(); + user_input_->EnableInputControls(true); + SetStatusAreaEnabled(true); + StopThrobber(); +} + void UserController::ClearAndEnablePassword() { - if (is_new_user_) { - // TODO(avayvod): This code seems not reachable to me. - new_user_view_->ClearAndEnablePassword(); - } else { - existing_user_view_->password_field()->SetText(string16()); - SetPasswordEnabled(true); - FocusPasswordField(); - } + user_input_->ClearAndFocusPassword(); + user_input_->EnableInputControls(true); + SetStatusAreaEnabled(true); + StopThrobber(); } -void UserController::ClearAndEnableFields() { - if (is_new_user_) { - new_user_view_->ClearAndEnableFields(); - } else if (is_guest_) { - guest_user_view_->FocusSignInButton(); - } else { - ClearAndEnablePassword(); - } +gfx::Rect UserController::GetMainInputScreenBounds() const { + return user_input_->GetMainInputScreenBounds(); } void UserController::EnableNameTooltip(bool enable) { @@ -251,32 +243,6 @@ void UserController::EnableNameTooltip(bool enable) { unselected_label_view_->SetTooltipText(tooltip_text); } -void UserController::ButtonPressed(views::Button* sender, - const views::Event& event) { - Login(); -} - -bool UserController::HandleKeystroke( - views::Textfield* sender, - const views::Textfield::Keystroke& keystroke) { - if (keystroke.GetKeyboardCode() == app::VKEY_RETURN) { - Login(); - return true; - } else if (keystroke.GetKeyboardCode() == app::VKEY_LEFT) { - SelectUser(user_index() - 1); - return true; - } else if (keystroke.GetKeyboardCode() == app::VKEY_RIGHT) { - SelectUser(user_index() + 1); - return true; - } - delegate_->ClearErrors(); - return false; -} - -void UserController::ContentsChanged(views::Textfield* sender, - const string16& new_contents) { -} - void UserController::Observe( NotificationType type, const NotificationSource& source, @@ -293,17 +259,6 @@ void UserController::Observe( user_view_->SetImage(user_.image(), user_.image()); } -void UserController::Login() { - if (is_guest_) { - delegate_->LoginOffTheRecord(); - } else { - // Delegate will reenable as necessary. - SetPasswordEnabled(false); - - delegate_->Login(this, existing_user_view_->password_field()->text()); - } -} - void UserController::IsActiveChanged(bool active) { is_user_selected_ = active; if (active) { @@ -345,25 +300,30 @@ WidgetGtk* UserController::CreateControlsWindow( bool need_browse_without_signin) { views::View* control_view; if (is_new_user_) { - new_user_view_ = + NewUserView* new_user_view = new NewUserView(this, true, need_browse_without_signin); - new_user_view_->Init(); - control_view = new_user_view_; + new_user_view->Init(); + control_view = new_user_view; + user_input_ = new_user_view; + throbber_host_ = new_user_view; } else if (is_guest_) { - guest_user_view_ = new GuestUserView(this); - guest_user_view_->RecreateFields(); - control_view = guest_user_view_; + GuestUserView* guest_user_view = new GuestUserView(this); + guest_user_view->RecreateFields(); + control_view = guest_user_view; + user_input_ = guest_user_view; + throbber_host_ = guest_user_view; } else { - existing_user_view_ = new ExistingUserView(this); - existing_user_view_->RecreateFields(); - control_view = existing_user_view_; + ExistingUserView* existing_user_view = new ExistingUserView(this); + existing_user_view->RecreateFields(); + control_view = existing_user_view; + user_input_ = existing_user_view; + throbber_host_ = existing_user_view; } *height = kControlsHeight; *width = kUserImageSize; if (is_new_user_) { - DCHECK(new_user_view_); - gfx::Size size = new_user_view_->GetPreferredSize(); + gfx::Size size = control_view->GetPreferredSize(); *width = size.width(); *height = size.height(); } @@ -502,16 +462,15 @@ WidgetGtk* UserController::CreateLabelWindow(int index, return window; } -gfx::Rect UserController::GetScreenBounds() const { - if (is_new_user_) - return new_user_view_->GetUsernameBounds(); - else - return existing_user_view_->password_field()->GetScreenBounds(); -} - void UserController::OnLogin(const std::string& username, const std::string& password) { - user_.set_email(username); + if (is_new_user_) + user_.set_email(username); + + user_input_->EnableInputControls(false); + SetStatusAreaEnabled(false); + StartThrobber(); + delegate_->Login(this, UTF8ToUTF16(password)); } @@ -520,6 +479,10 @@ void UserController::OnCreateAccount() { } void UserController::OnLoginOffTheRecord() { + user_input_->EnableInputControls(false); + SetStatusAreaEnabled(false); + StartThrobber(); + delegate_->LoginOffTheRecord(); } @@ -528,7 +491,7 @@ void UserController::ClearErrors() { } void UserController::NavigateAway() { - SelectUser(user_index() - 1); + SelectUserRelative(-1); } void UserController::OnRemoveUser() { @@ -548,12 +511,8 @@ void UserController::OnRemoveUser() { delegate_->RemoveUser(this); } -void UserController::SelectUser(int index) { - delegate_->SelectUser(index); -} - -void UserController::FocusPasswordField() { - existing_user_view_->FocusPasswordField(); +void UserController::SelectUserRelative(int shift) { + delegate_->SelectUser(user_index() + shift); } } // namespace chromeos diff --git a/chrome/browser/chromeos/login/user_controller.h b/chrome/browser/chromeos/login/user_controller.h index 0de0e4b..7b894f1 100644 --- a/chrome/browser/chromeos/login/user_controller.h +++ b/chrome/browser/chromeos/login/user_controller.h @@ -26,16 +26,12 @@ class WidgetGtk; namespace chromeos { -class ExistingUserView; -class GuestUserView; -class UserView; +class ThrobberManager; // UserController manages the set of windows needed to login a single existing // user or first time login for a new user. ExistingUserController creates // the nececessary set of UserControllers. -class UserController : public views::ButtonListener, - public views::Textfield::Controller, - public views::WidgetDelegate, +class UserController : public views::WidgetDelegate, public NewUserView::Delegate, public NotificationObserver, public UserView::Delegate { @@ -80,36 +76,30 @@ class UserController : public views::ButtonListener, bool is_user_selected() const { return is_user_selected_; } bool is_new_user() const { return is_new_user_; } bool is_guest() const { return is_guest_; } - NewUserView* new_user_view() const { return new_user_view_; } const UserManager::User& user() const { return user_; } // Enables or disables tooltip with user's email. void EnableNameTooltip(bool enable); - // Resets password text and sets the enabled state of the password. - void ClearAndEnablePassword(); - // Called when user view is activated (OnUserSelected). void ClearAndEnableFields(); - // Returns bounds of password field in screen coordinates. - // For new user it returns username coordinates. - gfx::Rect GetScreenBounds() const; + // Called when user view is activated (OnUserSelected). + void ClearAndEnablePassword(); // Get widget that contains all controls. views::WidgetGtk* controls_window() { return controls_window_; } - // ButtonListener: - virtual void ButtonPressed(views::Button* sender, const views::Event& event); + // Returns bounds of the main input field in the screen coordinates (e.g. + // these bounds could be used to choose positions for the error bubble). + gfx::Rect GetMainInputScreenBounds() const; - // Textfield::Controller: - virtual void ContentsChanged(views::Textfield* sender, - const string16& new_contents); - virtual bool HandleKeystroke(views::Textfield* sender, - const views::Textfield::Keystroke& keystroke); + // Starts/Stops throbber. + void StartThrobber(); + void StopThrobber(); // views::WidgetDelegate: virtual void IsActiveChanged(bool active); @@ -136,11 +126,8 @@ class UserController : public views::ButtonListener, // UserView::Delegate implementation: virtual void OnRemoveUser(); - // Selects user entry with specified |index|. - void SelectUser(int index); - - // Sets focus on password field. - void FocusPasswordField(); + // Selects user relative to the current user. + void SelectUserRelative(int shift); // Padding between the user windows. static const int kPadding; @@ -152,9 +139,6 @@ class UserController : public views::ButtonListener, private: FRIEND_TEST(UserControllerTest, GetNameTooltip); - // Invoked when the user wants to login. Forwards the call to the delegate. - void Login(); - // Performs common setup for login windows. void ConfigureLoginWindow(views::WidgetGtk* window, int index, @@ -176,9 +160,6 @@ class UserController : public views::ButtonListener, // itself. void SetImage(const SkBitmap& image); - // Sets the enabled state of the password field to |enable|. - void SetPasswordEnabled(bool enable); - // Returns tooltip text for user name. std::wstring GetNameTooltip() const; @@ -216,19 +197,16 @@ class UserController : public views::ButtonListener, // View that shows user image on image window. UserView* user_view_; - // View that is used for new user login. - NewUserView* new_user_view_; - - // View that is used for existing user login. - ExistingUserView* existing_user_view_; - - // View that is used for guest user login. - GuestUserView* guest_user_view_; - // Views that show display name of the user. views::Label* label_view_; views::Label* unselected_label_view_; + // Input controls which are used for username and password. + UserInput* user_input_; + + // Throbber host that can show a throbber. + ThrobberHostView* throbber_host_; + NotificationRegistrar registrar_; ScopedRunnableMethodFactory<UserController> method_factory_; diff --git a/chrome/browser/chromeos/login/user_input.h b/chrome/browser/chromeos/login/user_input.h new file mode 100644 index 0000000..565f928 --- /dev/null +++ b/chrome/browser/chromeos/login/user_input.h @@ -0,0 +1,33 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_INPUT_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_USER_INPUT_H_ + +#include "gfx/rect.h" + +namespace chromeos { + +// Interface that is used to manage the state of the user input controls. +class UserInput { + public: + virtual ~UserInput() {} + + // Enables/Disables the input controls. + virtual void EnableInputControls(bool enabled) = 0; + + // Clears and focuses the controls. + virtual void ClearAndFocusControls() = 0; + + // Clears and focuses the password field. + virtual void ClearAndFocusPassword() = 0; + + // Returns bounds of the main input field in the screen coordinates (e.g. + // these bounds could be used to choose positions for the error bubble). + virtual gfx::Rect GetMainInputScreenBounds() const = 0; +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_INPUT_H_ diff --git a/chrome/browser/chromeos/login/user_view.cc b/chrome/browser/chromeos/login/user_view.cc index 2a1b0cc..7def217 100644 --- a/chrome/browser/chromeos/login/user_view.cc +++ b/chrome/browser/chromeos/login/user_view.cc @@ -19,7 +19,6 @@ #include "views/controls/image_view.h" #include "views/controls/label.h" #include "views/controls/link.h" -#include "views/controls/throbber.h" #include "views/painter.h" namespace { @@ -243,7 +242,6 @@ UserView::UserView(Delegate* delegate, bool is_login, bool need_background) : delegate_(delegate), signout_view_(NULL), image_view_(NULL), - throbber_(CreateDefaultSmoothedThrobber()), remove_button_(NULL) { DCHECK(delegate); if (!is_login) @@ -262,16 +260,6 @@ void UserView::Init(bool need_background) { image_view_->set_background( views::Background::CreateSolidBackground(kBackgroundColor)); } - if (throbber_) { - int w = throbber_->GetPreferredSize().width(); - int h = throbber_->GetPreferredSize().height(); - throbber_->SetBounds(kUserImageSize / 2 - w / 2, - kUserImageSize / 2 - h / 2 , w, h); - // Throbber should be actually hidden while stopped so tooltip manager - // doesn't find it. - throbber_->SetVisible(false); - image_view_->AddChildView(throbber_); - } // UserView's layout never changes, so let's layout once here. image_view_->SetBounds(0, 0, kUserImageSize, kUserImageSize); @@ -307,16 +295,6 @@ void UserView::SetTooltipText(const std::wstring& text) { image_view_->SetTooltipText(text); } -void UserView::StartThrobber() { - throbber_->SetVisible(true); - throbber_->Start(); -} - -void UserView::StopThrobber() { - throbber_->Stop(); - throbber_->SetVisible(false); -} - gfx::Size UserView::GetPreferredSize() { return gfx::Size( kUserImageSize, diff --git a/chrome/browser/chromeos/login/user_view.h b/chrome/browser/chromeos/login/user_view.h index ed4b030..5d4182c 100644 --- a/chrome/browser/chromeos/login/user_view.h +++ b/chrome/browser/chromeos/login/user_view.h @@ -56,10 +56,6 @@ class UserView : public views::View, // Sets tooltip over the image. void SetTooltipText(const std::wstring& text); - // Start/Stop throbber. - void StartThrobber(); - void StopThrobber(); - // Show/Hide remove button. void SetRemoveButtonVisible(bool flag); @@ -81,8 +77,6 @@ class UserView : public views::View, SignoutView* signout_view_; PodImageView* image_view_; - views::Throbber* throbber_; - views::TextButton* remove_button_; DISALLOW_COPY_AND_ASSIGN(UserView); |