summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authoravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 07:22:54 +0000
committeravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 07:22:54 +0000
commitc6f882173c881372f71cbe400ee4b6c4535afaaf (patch)
tree57e6b6af97dc950b1e3c048b9401a5e7cc632ca6 /chrome/browser/chromeos
parent860c85d54df2b9b5008dbadacb534657e9876c3b (diff)
downloadchromium_src-c6f882173c881372f71cbe400ee4b6c4535afaaf.zip
chromium_src-c6f882173c881372f71cbe400ee4b6c4535afaaf.tar.gz
chromium_src-c6f882173c881372f71cbe400ee4b6c4535afaaf.tar.bz2
Added initial implementation of account creation view.
BUG=35157 TEST=Run chrome with --login-manager=create_accout and verify that screen works as intended. Review URL: http://codereview.chromium.org/600003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38588 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/login/account_creation_view.cc231
-rw-r--r--chrome/browser/chromeos/login/account_creation_view.h94
-rw-r--r--chrome/browser/chromeos/login/login_manager_view.h9
-rw-r--r--chrome/browser/chromeos/login/login_wizard_view.cc35
-rw-r--r--chrome/browser/chromeos/login/login_wizard_view.h11
5 files changed, 357 insertions, 23 deletions
diff --git a/chrome/browser/chromeos/login/account_creation_view.cc b/chrome/browser/chromeos/login/account_creation_view.cc
new file mode 100644
index 0000000..1d9665b
--- /dev/null
+++ b/chrome/browser/chromeos/login/account_creation_view.cc
@@ -0,0 +1,231 @@
+// Copyright (c) 2009 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.
+
+#include "chrome/browser/chromeos/login/account_creation_view.h"
+
+#include <algorithm>
+
+#include "app/gfx/canvas.h"
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/keyboard_codes.h"
+#include "chrome/browser/chromeos/login/rounded_rect_painter.h"
+#include "chrome/browser/chromeos/login/screen_observer.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "views/controls/button/native_button.h"
+#include "views/controls/label.h"
+#include "views/grid_layout.h"
+#include "views/widget/widget.h"
+#include "views/window/non_client_view.h"
+#include "views/window/window.h"
+#include "views/window/window_gtk.h"
+
+using views::Background;
+using views::Label;
+using views::Textfield;
+using views::View;
+using views::Widget;
+
+namespace {
+
+const int kCornerRadius = 12;
+const int kHorizontalPad = 10;
+const int kVerticalInset = 50;
+const int kHorizontalInset = 40;
+const int kTextfieldWidthInChars = 20;
+const SkColor kErrorColor = 0xFF8F384F;
+const SkColor kBackground = SK_ColorWHITE;
+const SkColor kLabelColor = 0xFF808080;
+
+} // namespace
+
+///////////////////////////////////////////////////////////////////////////////
+// AccountCreationView, public:
+AccountCreationView::AccountCreationView(chromeos::ScreenObserver* observer)
+ : observer_(observer) {
+}
+
+AccountCreationView::~AccountCreationView() {
+}
+
+void AccountCreationView::Init() {
+ // Use rounded rect background.
+ views::Painter* painter = new chromeos::RoundedRectPainter(
+ 0, kBackground, // no padding
+ true, SK_ColorBLACK, // black shadow
+ kCornerRadius, // corner radius
+ kBackground, kBackground); // backgound without gradient
+ set_background(
+ views::Background::CreateBackgroundPainter(true, painter));
+
+ InitControls();
+ InitLayout();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// AccountCreationView, views::View overrides:
+gfx::Size AccountCreationView::GetPreferredSize() {
+ return gfx::Size(width(), height());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// AccountCreationView, views::WindowDelegate overrides:
+views::View* AccountCreationView::GetContentsView() {
+ return this;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// AccountCreationView, views::ButtonListener overrides:
+void AccountCreationView::ButtonPressed(
+ views::Button* sender, const views::Event& event) {
+ // TODO(avayvod): Back button.
+ CreateAccount();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// AccountCreationView, views::Textfield::Controller overrides:
+bool AccountCreationView::HandleKeystroke(views::Textfield* s,
+ const views::Textfield::Keystroke& keystroke) {
+ if (keystroke.GetKeyboardCode() == base::VKEY_RETURN) {
+ CreateAccount();
+ // Return true so that processing ends
+ return true;
+ }
+ // Return false so that processing does not end
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// AccountCreationView, private:
+void AccountCreationView::CreateAccount() {
+ // TODO(avayvod): Implement account creation.
+}
+
+void AccountCreationView::InitLabel(const gfx::Font& label_font,
+ const std::wstring& label_text,
+ views::Label** label) {
+ scoped_ptr<views::Label> new_label(new views::Label());
+ new_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ new_label->SetFont(label_font);
+ new_label->SetText(label_text);
+ new_label->SetColor(kLabelColor);
+ AddChildView(new_label.get());
+ *label = new_label.release();
+}
+
+void AccountCreationView::InitTextfield(const gfx::Font& field_font,
+ views::Textfield::StyleFlags style,
+ views::Textfield** field) {
+ scoped_ptr<views::Textfield> new_field(new views::Textfield(style));
+ new_field->SetFont(field_font);
+ new_field->set_default_width_in_chars(kTextfieldWidthInChars);
+ AddChildView(new_field.get());
+ new_field->SetController(this);
+ *field = new_field.release();
+}
+
+void AccountCreationView::InitControls() {
+ // Set up fonts.
+ gfx::Font title_font =
+ gfx::Font::CreateFont(L"Droid Sans", 10).DeriveFont(0, gfx::Font::BOLD);
+ gfx::Font label_font = gfx::Font::CreateFont(L"Droid Sans", 8);
+ gfx::Font button_font = label_font;
+ gfx::Font field_font = label_font;
+
+ InitLabel(title_font,
+ l10n_util::GetString(IDS_ACCOUNT_CREATION_TITLE),
+ &title_label_);
+
+ InitLabel(label_font,
+ l10n_util::GetString(IDS_ACCOUNT_CREATION_FIRSTNAME),
+ &firstname_label_);
+ InitTextfield(field_font, views::Textfield::STYLE_DEFAULT,
+ &firstname_field_);
+ InitLabel(label_font,
+ l10n_util::GetString(IDS_ACCOUNT_CREATION_LASTNAME),
+ &lastname_label_);
+ InitTextfield(field_font, views::Textfield::STYLE_DEFAULT, &lastname_field_);
+ InitLabel(label_font,
+ l10n_util::GetString(IDS_ACCOUNT_CREATION_EMAIL),
+ &username_label_);
+ InitTextfield(field_font, views::Textfield::STYLE_DEFAULT, &username_field_);
+ InitLabel(label_font,
+ l10n_util::GetString(IDS_ACCOUNT_CREATION_PASSWORD),
+ &password_label_);
+ InitTextfield(field_font, views::Textfield::STYLE_PASSWORD,
+ &password_field_);
+ InitLabel(label_font,
+ l10n_util::GetString(IDS_ACCOUNT_CREATION_REENTER_PASSWORD),
+ &reenter_password_label_);
+ InitTextfield(field_font, views::Textfield::STYLE_PASSWORD,
+ &reenter_password_field_);
+
+ create_account_button_ = new views::NativeButton(this, std::wstring());
+ create_account_button_->set_font(button_font);
+ create_account_button_->SetLabel(
+ l10n_util::GetString(IDS_ACCOUNT_CREATION_BUTTON));
+ AddChildView(create_account_button_);
+}
+
+void AccountCreationView::InitLayout() {
+ // Create layout for all the views.
+ views::GridLayout* layout = new views::GridLayout(this);
+ SetLayoutManager(layout);
+
+ views::ColumnSet* columns = layout->AddColumnSet(0);
+ // Column for labels.
+ columns->AddColumn(views::GridLayout::LEADING,
+ views::GridLayout::CENTER,
+ 0,
+ views::GridLayout::USE_PREF, 0, 0);
+ columns->AddPaddingColumn(0, kHorizontalPad);
+ // Column for text fields.
+ columns->AddColumn(views::GridLayout::LEADING,
+ views::GridLayout::CENTER,
+ 0,
+ views::GridLayout::USE_PREF, 0, 0);
+ columns->AddPaddingColumn(0, kHorizontalPad);
+ // Column for field status.
+ columns->AddColumn(views::GridLayout::LEADING,
+ views::GridLayout::CENTER,
+ 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->SetInsets(kHorizontalInset,
+ kVerticalInset,
+ kHorizontalInset,
+ kVerticalInset);
+
+ BuildLayout(layout);
+}
+
+void AccountCreationView::BuildLayout(views::GridLayout* layout) {
+ layout->StartRow(1, 0);
+ layout->AddView(firstname_label_);
+ layout->AddView(firstname_field_);
+
+ layout->StartRow(1, 0);
+ layout->AddView(lastname_label_);
+ layout->AddView(lastname_field_);
+
+ layout->StartRow(1, 0);
+ layout->AddView(username_label_);
+ layout->AddView(username_field_);
+
+ layout->StartRow(1, 0);
+ layout->AddView(password_label_);
+ layout->AddView(password_field_);
+
+ layout->StartRow(1, 0);
+ layout->AddView(reenter_password_label_);
+ layout->AddView(reenter_password_field_);
+
+ layout->StartRow(10, 0);
+ // Skip columns for label, field and two padding columns in between.
+ layout->SkipColumns(4);
+ layout->AddView(create_account_button_, 1, 1,
+ views::GridLayout::TRAILING,
+ views::GridLayout::TRAILING);
+}
+
diff --git a/chrome/browser/chromeos/login/account_creation_view.h b/chrome/browser/chromeos/login/account_creation_view.h
new file mode 100644
index 0000000..a7378bc
--- /dev/null
+++ b/chrome/browser/chromeos/login/account_creation_view.h
@@ -0,0 +1,94 @@
+// 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_ACCOUNT_CREATION_VIEW_H_
+#define CHROME_BROWSER_CHROMEOS_LOGIN_ACCOUNT_CREATION_VIEW_H_
+
+#include <string>
+#include "views/accelerator.h"
+#include "views/controls/button/button.h"
+#include "views/controls/textfield/textfield.h"
+#include "views/view.h"
+#include "views/widget/widget_gtk.h"
+#include "views/window/window_delegate.h"
+
+namespace views {
+class GridLayout;
+class Label;
+class NativeButton;
+} // namespace views
+
+namespace chromeos {
+class ScreenObserver;
+} // namespace chromeos
+
+class AccountCreationView : public views::View,
+ public views::WindowDelegate,
+ public views::Textfield::Controller,
+ public views::ButtonListener {
+ public:
+ explicit AccountCreationView(chromeos::ScreenObserver* observer);
+ virtual ~AccountCreationView();
+
+ // Initialize the controls on the dialog.
+ void Init();
+
+ // Overridden from views::View:
+ virtual gfx::Size GetPreferredSize();
+
+ // Overridden from views::WindowDelegate:
+ virtual views::View* GetContentsView();
+
+ // Overridden from views::Textfield::Controller:
+ virtual bool HandleKeystroke(views::Textfield* sender,
+ const views::Textfield::Keystroke& keystroke);
+ virtual void ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) {}
+
+ // Overriden from views::ButtonListener.
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+
+ private:
+ // Tries to create an account with user input.
+ void CreateAccount();
+
+ // Initializers for labels and textfields.
+ void InitLabel(const gfx::Font& label_font,
+ const std::wstring& label_text,
+ views::Label** label);
+ void InitTextfield(const gfx::Font& field_font,
+ views::Textfield::StyleFlags style,
+ views::Textfield** field);
+
+ // Initializes all controls on the screen.
+ void InitControls();
+
+ // Initializes the layout manager.
+ void InitLayout();
+
+ // Adds controls to layout manager.
+ void BuildLayout(views::GridLayout* layout);
+
+ // Controls on the view.
+ views::Textfield* firstname_field_;
+ views::Textfield* lastname_field_;
+ views::Textfield* username_field_;
+ views::Textfield* password_field_;
+ views::Textfield* reenter_password_field_;
+ views::Label* title_label_;
+ views::Label* firstname_label_;
+ views::Label* lastname_label_;
+ views::Label* username_label_;
+ views::Label* password_label_;
+ views::Label* reenter_password_label_;
+ views::NativeButton* create_account_button_;
+
+ // Notifications receiver.
+ chromeos::ScreenObserver* observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(AccountCreationView);
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_ACCOUNT_CREATION_VIEW_H_
+
diff --git a/chrome/browser/chromeos/login/login_manager_view.h b/chrome/browser/chromeos/login/login_manager_view.h
index 7d02ed7..55b9f1f 100644
--- a/chrome/browser/chromeos/login/login_manager_view.h
+++ b/chrome/browser/chromeos/login/login_manager_view.h
@@ -45,14 +45,12 @@ class LoginManagerView : public views::View,
// Not thread-safe, by virtue of using SetupSession().
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke& keystroke);
+ virtual void ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) {}
// Overriden from views::ButtonListener.
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
- // This method is called whenever the text in the field changes.
- virtual void ContentsChanged(views::Textfield* sender,
- const string16& new_contents) {}
-
private:
// Given a |username| and |password|, this method attempts to authenticate to
// the Google accounts servers.
@@ -60,9 +58,6 @@ class LoginManagerView : public views::View,
bool Authenticate(const std::string& username,
const std::string& password);
- // Asynchronously launches the Chrome OS window manager.
- bool RunWindowManager(const std::string& username);
-
// This is not threadsafe; as authentication is supposed to happen on the main
// thread before any other threads are started, so this should be ok.
// That said, the only reason we're not threadsafe right now is that we're
diff --git a/chrome/browser/chromeos/login/login_wizard_view.cc b/chrome/browser/chromeos/login/login_wizard_view.cc
index f2f44f5..de9a57e 100644
--- a/chrome/browser/chromeos/login/login_wizard_view.cc
+++ b/chrome/browser/chromeos/login/login_wizard_view.cc
@@ -18,6 +18,7 @@
#include "base/logging.h"
#include "base/process_util.h"
#include "chrome/browser/chromeos/cros/login_library.h"
+#include "chrome/browser/chromeos/login/account_creation_view.h"
#include "chrome/browser/chromeos/login/login_manager_view.h"
#include "chrome/browser/chromeos/login/rounded_rect_painter.h"
#include "chrome/browser/chromeos/status/clock_menu_button.h"
@@ -38,8 +39,8 @@ using views::Widget;
namespace {
-const int kLoginWidth = 700;
-const int kLoginHeight = 350;
+const int kScreenWidth = 700;
+const int kScreenHeight = 350;
const SkColor kBackgroundTopColor = SkColorSetRGB(82, 139, 224);
const SkColor kBackgroundBottomColor = SkColorSetRGB(50, 102, 204);
const int kCornerRadius = 12;
@@ -48,6 +49,7 @@ const SkColor kBackgroundPaddingColor = SK_ColorBLACK;
// Names of screens to start login wizard with.
const char kLoginManager[] = "login";
+const char kAccountCreation[] = "create_account";
} // namespace
@@ -138,7 +140,8 @@ void ShowLoginWizard(const std::string& start_screen_name) {
LoginWizardView::LoginWizardView()
: status_area_(NULL),
current_(NULL),
- login_manager_(NULL) {
+ login_manager_(NULL),
+ account_creation_(NULL) {
}
LoginWizardView::~LoginWizardView() {
@@ -162,11 +165,14 @@ void LoginWizardView::Init(const std::string& start_view_name) {
InitStatusArea();
// Create and initialize all views, hidden.
- InitLoginManager();
+ CreateAndInitScreen(&login_manager_);
+ CreateAndInitScreen(&account_creation_);
// Select the view to start with and show it.
if (start_view_name == kLoginManager) {
current_ = login_manager_;
+ } else if (start_view_name == kAccountCreation) {
+ current_ = account_creation_;
} else {
// Default to login manager.
current_ = login_manager_;
@@ -188,7 +194,6 @@ void LoginWizardView::InitStatusArea() {
status_area_ = new chromeos::StatusAreaView(this);
status_area_->Init();
gfx::Size status_area_size = status_area_->GetPreferredSize();
- // TODO(avayvod): Check this on RTL interface.
status_area_->SetBounds(
dimensions_.width() - status_area_size.width() -
kCornerRadius - kBackgroundPadding,
@@ -198,15 +203,17 @@ void LoginWizardView::InitStatusArea() {
AddChildView(status_area_);
}
-void LoginWizardView::InitLoginManager() {
- login_manager_ = new LoginManagerView(this);
- login_manager_->Init();
- login_manager_->SetBounds((dimensions_.width() - kLoginWidth) / 2,
- (dimensions_.height() - kLoginHeight) / 2,
- kLoginWidth,
- kLoginHeight);
- login_manager_->SetVisible(false);
- AddChildView(login_manager_);
+template <class T>
+void LoginWizardView::CreateAndInitScreen(T** screen) {
+ T* new_screen = new T(this);
+ new_screen->Init();
+ new_screen->SetBounds((dimensions_.width() - kScreenWidth) / 2,
+ (dimensions_.height() - kScreenHeight) / 2,
+ kScreenWidth,
+ kScreenHeight);
+ new_screen->SetVisible(false);
+ AddChildView(new_screen);
+ *screen = new_screen;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/chromeos/login/login_wizard_view.h b/chrome/browser/chromeos/login/login_wizard_view.h
index 13974a13..1b0655a 100644
--- a/chrome/browser/chromeos/login/login_wizard_view.h
+++ b/chrome/browser/chromeos/login/login_wizard_view.h
@@ -14,6 +14,7 @@
#include "views/window/window_delegate.h"
class LoginManagerView;
+class AccountCreationView;
namespace chromeos {
class StatusAreaView;
@@ -50,9 +51,12 @@ class LoginWizardView : public views::View,
virtual void OpenButtonOptions(const views::View* button_view) const;
virtual bool IsButtonVisible(const views::View* button_view) const;
- // Initializers for all child views.
+ // Initializer for status area.
void InitStatusArea();
- void InitLoginManager();
+
+ // Initializer for all login screens.
+ template <class T>
+ void CreateAndInitScreen(T** screen);
// Wizard view dimensions.
gfx::Size dimensions_;
@@ -66,6 +70,9 @@ class LoginWizardView : public views::View,
// Login manager view.
LoginManagerView* login_manager_;
+ // Account creation view.
+ AccountCreationView* account_creation_;
+
DISALLOW_COPY_AND_ASSIGN(LoginWizardView);
};