| 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/l10n_util.h" | 13 #include "app/l10n_util.h" |
| 14 #include "app/resource_bundle.h" | 14 #include "app/resource_bundle.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/keyboard_codes.h" | 17 #include "base/keyboard_codes.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "base/string_util.h" | 22 #include "base/string_util.h" |
| 23 #include "chrome/browser/chromeos/cros/cros_library.h" | 23 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 24 #include "chrome/browser/chromeos/login/helper.h" | 24 #include "chrome/browser/chromeos/login/helper.h" |
| 25 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" | 25 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
| 26 #include "chrome/browser/google_util.h" |
| 26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 27 #include "views/controls/button/native_button.h" | 28 #include "views/controls/button/native_button.h" |
| 28 #include "views/controls/label.h" | 29 #include "views/controls/label.h" |
| 29 #include "views/controls/throbber.h" | 30 #include "views/controls/throbber.h" |
| 31 #include "views/widget/widget_gtk.h" |
| 30 | 32 |
| 31 using views::Label; | 33 using views::Label; |
| 32 using views::Textfield; | 34 using views::Textfield; |
| 33 using views::View; | 35 using views::View; |
| 36 using views::WidgetGtk; |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 const int kTextfieldWidth = 286; | 40 const int kTextfieldWidth = 286; |
| 38 const int kRowPad = 7; | 41 const int kRowPad = 7; |
| 39 const int kColumnPad = 7; | 42 const int kColumnPad = 7; |
| 40 const int kLanguagesMenuWidth = 200; | 43 const int kLanguagesMenuWidth = 200; |
| 41 const int kLanguagesMenuHeight = 30; | 44 const int kLanguagesMenuHeight = 30; |
| 42 const SkColor kErrorColor = 0xFF8F384F; | 45 const SkColor kErrorColor = 0xFF8F384F; |
| 43 const char *kDefaultDomain = "@gmail.com"; | 46 const char kDefaultDomain[] = "@gmail.com"; |
| 47 |
| 48 const char kAccountRecoveryHelpUrl[] = |
| 49 "http://www.google.com/support/accounts/bin/answer.py?answer=48598"; |
| 44 | 50 |
| 45 } // namespace | 51 } // namespace |
| 46 | 52 |
| 47 namespace chromeos { | 53 namespace chromeos { |
| 48 | 54 |
| 49 NewUserView::NewUserView(Delegate* delegate, bool need_border) | 55 NewUserView::NewUserView(Delegate* delegate, bool need_border) |
| 50 : username_field_(NULL), | 56 : username_field_(NULL), |
| 51 password_field_(NULL), | 57 password_field_(NULL), |
| 52 title_label_(NULL), | 58 title_label_(NULL), |
| 53 sign_in_button_(NULL), | 59 sign_in_button_(NULL), |
| 54 create_account_link_(NULL), | 60 create_account_link_(NULL), |
| 61 cant_access_account_link_(NULL), |
| 55 browse_without_signin_link_(NULL), | 62 browse_without_signin_link_(NULL), |
| 56 languages_menubutton_(NULL), | 63 languages_menubutton_(NULL), |
| 57 throbber_(NULL), | 64 throbber_(NULL), |
| 58 accel_focus_user_(views::Accelerator(base::VKEY_U, false, false, true)), | 65 accel_focus_user_(views::Accelerator(base::VKEY_U, false, false, true)), |
| 59 accel_focus_pass_(views::Accelerator(base::VKEY_P, false, false, true)), | 66 accel_focus_pass_(views::Accelerator(base::VKEY_P, false, false, true)), |
| 60 delegate_(delegate), | 67 delegate_(delegate), |
| 61 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)), | 68 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)), |
| 62 focus_delayed_(false), | 69 focus_delayed_(false), |
| 63 login_in_process_(false), | 70 login_in_process_(false), |
| 64 need_border_(need_border) { | 71 need_border_(need_border) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 91 | 98 |
| 92 username_field_ = new views::Textfield; | 99 username_field_ = new views::Textfield; |
| 93 AddChildView(username_field_); | 100 AddChildView(username_field_); |
| 94 | 101 |
| 95 password_field_ = new views::Textfield(views::Textfield::STYLE_PASSWORD); | 102 password_field_ = new views::Textfield(views::Textfield::STYLE_PASSWORD); |
| 96 AddChildView(password_field_); | 103 AddChildView(password_field_); |
| 97 | 104 |
| 98 throbber_ = CreateDefaultSmoothedThrobber(); | 105 throbber_ = CreateDefaultSmoothedThrobber(); |
| 99 AddChildView(throbber_); | 106 AddChildView(throbber_); |
| 100 | 107 |
| 101 create_account_link_ = new views::Link(std::wstring()); | 108 InitLink(&create_account_link_); |
| 102 create_account_link_->SetController(this); | 109 InitLink(&cant_access_account_link_); |
| 103 AddChildView(create_account_link_); | 110 InitLink(&browse_without_signin_link_); |
| 104 | |
| 105 browse_without_signin_link_ = new views::Link(std::wstring()); | |
| 106 browse_without_signin_link_->SetController(this); | |
| 107 AddChildView(browse_without_signin_link_); | |
| 108 | 111 |
| 109 language_switch_model_.InitLanguageMenu(); | 112 language_switch_model_.InitLanguageMenu(); |
| 110 languages_menubutton_ = new views::MenuButton( | 113 languages_menubutton_ = new views::MenuButton( |
| 111 NULL, std::wstring(), &language_switch_model_, true); | 114 NULL, std::wstring(), &language_switch_model_, true); |
| 112 AddChildView(languages_menubutton_); | 115 AddChildView(languages_menubutton_); |
| 113 | 116 |
| 114 AddAccelerator(accel_focus_user_); | 117 AddAccelerator(accel_focus_user_); |
| 115 AddAccelerator(accel_focus_pass_); | 118 AddAccelerator(accel_focus_pass_); |
| 116 | 119 |
| 117 UpdateLocalizedStrings(); | 120 UpdateLocalizedStrings(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 RecreateNativeControls(); | 156 RecreateNativeControls(); |
| 154 | 157 |
| 155 title_label_->SetText(l10n_util::GetString(IDS_LOGIN_TITLE)); | 158 title_label_->SetText(l10n_util::GetString(IDS_LOGIN_TITLE)); |
| 156 username_field_->set_text_to_display_when_empty( | 159 username_field_->set_text_to_display_when_empty( |
| 157 l10n_util::GetStringUTF16(IDS_LOGIN_USERNAME)); | 160 l10n_util::GetStringUTF16(IDS_LOGIN_USERNAME)); |
| 158 password_field_->set_text_to_display_when_empty( | 161 password_field_->set_text_to_display_when_empty( |
| 159 l10n_util::GetStringUTF16(IDS_LOGIN_PASSWORD)); | 162 l10n_util::GetStringUTF16(IDS_LOGIN_PASSWORD)); |
| 160 sign_in_button_->SetLabel(l10n_util::GetString(IDS_LOGIN_BUTTON)); | 163 sign_in_button_->SetLabel(l10n_util::GetString(IDS_LOGIN_BUTTON)); |
| 161 create_account_link_->SetText( | 164 create_account_link_->SetText( |
| 162 l10n_util::GetString(IDS_CREATE_ACCOUNT_BUTTON)); | 165 l10n_util::GetString(IDS_CREATE_ACCOUNT_BUTTON)); |
| 166 cant_access_account_link_->SetText( |
| 167 l10n_util::GetString(IDS_CANT_ACCESS_ACCOUNT_BUTTON)); |
| 163 browse_without_signin_link_->SetText( | 168 browse_without_signin_link_->SetText( |
| 164 l10n_util::GetString(IDS_BROWSE_WITHOUT_SIGNING_IN_BUTTON)); | 169 l10n_util::GetString(IDS_BROWSE_WITHOUT_SIGNING_IN_BUTTON)); |
| 165 delegate_->ClearErrors(); | 170 delegate_->ClearErrors(); |
| 166 languages_menubutton_->SetText(language_switch_model_.GetCurrentLocaleName()); | 171 languages_menubutton_->SetText(language_switch_model_.GetCurrentLocaleName()); |
| 167 } | 172 } |
| 168 | 173 |
| 169 void NewUserView::LocaleChanged() { | 174 void NewUserView::LocaleChanged() { |
| 170 UpdateLocalizedStrings(); | 175 UpdateLocalizedStrings(); |
| 171 Layout(); | 176 Layout(); |
| 172 SchedulePaint(); | 177 SchedulePaint(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 kTextfieldWidth); | 249 kTextfieldWidth); |
| 245 x = (this->width() - width) / 2; | 250 x = (this->width() - width) / 2; |
| 246 int max_width = this->width() - x - insets.right(); | 251 int max_width = this->width() - x - insets.right(); |
| 247 title_label_->SizeToFit(max_width); | 252 title_label_->SizeToFit(max_width); |
| 248 | 253 |
| 249 height = title_label_->GetPreferredSize().height() + | 254 height = title_label_->GetPreferredSize().height() + |
| 250 username_field_->GetPreferredSize().height() + | 255 username_field_->GetPreferredSize().height() + |
| 251 password_field_->GetPreferredSize().height() + | 256 password_field_->GetPreferredSize().height() + |
| 252 sign_in_button_->GetPreferredSize().height() + | 257 sign_in_button_->GetPreferredSize().height() + |
| 253 create_account_link_->GetPreferredSize().height() + | 258 create_account_link_->GetPreferredSize().height() + |
| 259 cant_access_account_link_->GetPreferredSize().height() + |
| 254 browse_without_signin_link_->GetPreferredSize().height() + | 260 browse_without_signin_link_->GetPreferredSize().height() + |
| 255 4 * kRowPad; | 261 4 * kRowPad; |
| 256 y = (this->height() - height) / 2; | 262 y = (this->height() - height) / 2; |
| 257 | 263 |
| 258 y += (setViewBounds(title_label_, x, y, max_width, false) + kRowPad); | 264 y += (setViewBounds(title_label_, x, y, max_width, false) + kRowPad); |
| 259 y += (setViewBounds(username_field_, x, y, width, true) + kRowPad); | 265 y += (setViewBounds(username_field_, x, y, width, true) + kRowPad); |
| 260 y += (setViewBounds(password_field_, x, y, width, true) + kRowPad); | 266 y += (setViewBounds(password_field_, x, y, width, true) + kRowPad); |
| 261 int throbber_y = y; | 267 int throbber_y = y; |
| 262 y += (setViewBounds(sign_in_button_, x, y, width, false) + kRowPad); | 268 y += (setViewBounds(sign_in_button_, x, y, width, false) + kRowPad); |
| 263 setViewBounds(throbber_, | 269 setViewBounds(throbber_, |
| 264 x + width - throbber_->GetPreferredSize().width(), | 270 x + width - throbber_->GetPreferredSize().width(), |
| 265 throbber_y + (sign_in_button_->GetPreferredSize().height() - | 271 throbber_y + (sign_in_button_->GetPreferredSize().height() - |
| 266 throbber_->GetPreferredSize().height()) / 2, | 272 throbber_->GetPreferredSize().height()) / 2, |
| 267 width, | 273 width, |
| 268 false); | 274 false); |
| 269 y += setViewBounds(create_account_link_, x, y, max_width, false); | 275 y += setViewBounds(create_account_link_, x, y, max_width, false); |
| 276 y += setViewBounds(cant_access_account_link_, x, y, max_width, false); |
| 270 y += setViewBounds(browse_without_signin_link_, x, y, max_width, false); | 277 y += setViewBounds(browse_without_signin_link_, x, y, max_width, false); |
| 271 | 278 |
| 272 SchedulePaint(); | 279 SchedulePaint(); |
| 273 } | 280 } |
| 274 | 281 |
| 275 gfx::Size NewUserView::GetPreferredSize() { | 282 gfx::Size NewUserView::GetPreferredSize() { |
| 276 return gfx::Size(width(), height()); | 283 return gfx::Size(width(), height()); |
| 277 } | 284 } |
| 278 | 285 |
| 279 views::View* NewUserView::GetContentsView() { | 286 views::View* NewUserView::GetContentsView() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 views::Button* sender, const views::Event& event) { | 319 views::Button* sender, const views::Event& event) { |
| 313 DCHECK(sender == sign_in_button_); | 320 DCHECK(sender == sign_in_button_); |
| 314 Login(); | 321 Login(); |
| 315 } | 322 } |
| 316 | 323 |
| 317 void NewUserView::LinkActivated(views::Link* source, int event_flags) { | 324 void NewUserView::LinkActivated(views::Link* source, int event_flags) { |
| 318 if (source == create_account_link_) { | 325 if (source == create_account_link_) { |
| 319 delegate_->OnCreateAccount(); | 326 delegate_->OnCreateAccount(); |
| 320 } else if (source == browse_without_signin_link_) { | 327 } else if (source == browse_without_signin_link_) { |
| 321 delegate_->OnLoginOffTheRecord(); | 328 delegate_->OnLoginOffTheRecord(); |
| 329 } else if (source == cant_access_account_link_) { |
| 330 // TODO(nkostylev): Display offline help when network is not connected. |
| 331 // http://crosbug.com/3874 |
| 332 dialog_.reset(new LoginHtmlDialog( |
| 333 this, |
| 334 GetNativeWindow(), |
| 335 l10n_util::GetString(IDS_LOGIN_OOBE_HELP_DIALOG_TITLE), |
| 336 google_util::AppendGoogleLocaleParam(GURL(kAccountRecoveryHelpUrl)))); |
| 337 dialog_->Show(); |
| 322 } | 338 } |
| 323 } | 339 } |
| 324 | 340 |
| 325 void NewUserView::ClearAndEnablePassword() { | 341 void NewUserView::ClearAndEnablePassword() { |
| 326 login_in_process_ = false; | 342 login_in_process_ = false; |
| 327 EnableInputControls(true); | 343 EnableInputControls(true); |
| 328 SetPassword(std::string()); | 344 SetPassword(std::string()); |
| 329 password_field_->RequestFocus(); | 345 password_field_->RequestFocus(); |
| 330 throbber_->Stop(); | 346 throbber_->Stop(); |
| 331 } | 347 } |
| 332 | 348 |
| 333 gfx::Rect NewUserView::GetPasswordBounds() const { | 349 gfx::Rect NewUserView::GetPasswordBounds() const { |
| 334 gfx::Rect screen_bounds(password_field_->bounds()); | 350 gfx::Rect screen_bounds(password_field_->bounds()); |
| 335 gfx::Point origin(screen_bounds.origin()); | 351 gfx::Point origin(screen_bounds.origin()); |
| 336 views::View::ConvertPointToScreen(password_field_->GetParent(), &origin); | 352 views::View::ConvertPointToScreen(password_field_->GetParent(), &origin); |
| 337 screen_bounds.set_origin(origin); | 353 screen_bounds.set_origin(origin); |
| 338 return screen_bounds; | 354 return screen_bounds; |
| 339 } | 355 } |
| 340 | 356 |
| 341 void NewUserView::StopThrobber() { | 357 void NewUserView::StopThrobber() { |
| 342 throbber_->Stop(); | 358 throbber_->Stop(); |
| 343 } | 359 } |
| 344 | 360 |
| 361 gfx::NativeWindow NewUserView::GetNativeWindow() const { |
| 362 return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView()); |
| 363 } |
| 364 |
| 345 bool NewUserView::HandleKeystroke(views::Textfield* s, | 365 bool NewUserView::HandleKeystroke(views::Textfield* s, |
| 346 const views::Textfield::Keystroke& keystroke) { | 366 const views::Textfield::Keystroke& keystroke) { |
| 347 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_) | 367 if (!CrosLibrary::Get()->EnsureLoaded() || login_in_process_) |
| 348 return false; | 368 return false; |
| 349 | 369 |
| 350 if (keystroke.GetKeyboardCode() == base::VKEY_TAB) { | 370 if (keystroke.GetKeyboardCode() == base::VKEY_TAB) { |
| 351 if (username_field_->text().length() != 0) { | 371 if (username_field_->text().length() != 0) { |
| 352 std::string username = UTF16ToUTF8(username_field_->text()); | 372 std::string username = UTF16ToUTF8(username_field_->text()); |
| 353 | 373 |
| 354 if (username.find('@') == std::string::npos) { | 374 if (username.find('@') == std::string::npos) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 367 } | 387 } |
| 368 // Return false so that processing does not end | 388 // Return false so that processing does not end |
| 369 return false; | 389 return false; |
| 370 } | 390 } |
| 371 | 391 |
| 372 void NewUserView::EnableInputControls(bool enabled) { | 392 void NewUserView::EnableInputControls(bool enabled) { |
| 373 username_field_->SetEnabled(enabled); | 393 username_field_->SetEnabled(enabled); |
| 374 password_field_->SetEnabled(enabled); | 394 password_field_->SetEnabled(enabled); |
| 375 sign_in_button_->SetEnabled(enabled); | 395 sign_in_button_->SetEnabled(enabled); |
| 376 create_account_link_->SetEnabled(enabled); | 396 create_account_link_->SetEnabled(enabled); |
| 397 cant_access_account_link_->SetEnabled(enabled); |
| 377 browse_without_signin_link_->SetEnabled(enabled); | 398 browse_without_signin_link_->SetEnabled(enabled); |
| 378 } | 399 } |
| 379 | 400 |
| 401 void NewUserView::InitLink(views::Link** link) { |
| 402 *link = new views::Link(std::wstring()); |
| 403 (*link)->SetController(this); |
| 404 AddChildView(*link); |
| 405 } |
| 406 |
| 380 } // namespace chromeos | 407 } // namespace chromeos |
| OLD | NEW |