diff options
author | dpolukhin@chromium.org <dpolukhin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 10:04:07 +0000 |
---|---|---|
committer | dpolukhin@chromium.org <dpolukhin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 10:04:07 +0000 |
commit | 5b7a0cfbc0c936545c214e681df783cb7bd81222 (patch) | |
tree | 70484a2fc961ec727669ca37216f0228eb17e4a0 /chrome/browser/chromeos | |
parent | 1c75e15bd66be2551b0773cea21a5f9bd8d07bc3 (diff) | |
download | chromium_src-5b7a0cfbc0c936545c214e681df783cb7bd81222.zip chromium_src-5b7a0cfbc0c936545c214e681df783cb7bd81222.tar.gz chromium_src-5b7a0cfbc0c936545c214e681df783cb7bd81222.tar.bz2 |
OOBE progress bar
BUG=crosbug.com/4693
TEST=See progress bar during OOBE
Review URL: http://codereview.chromium.org/2883033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/login/background_view.cc | 51 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/background_view.h | 20 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/existing_user_controller.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/oobe_progress_bar.cc | 135 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/oobe_progress_bar.h | 61 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_controller.cc | 18 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_controller.h | 3 |
7 files changed, 281 insertions, 12 deletions
diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc index 3d9f954..01f0d6e 100644 --- a/chrome/browser/chromeos/login/background_view.cc +++ b/chrome/browser/chromeos/login/background_view.cc @@ -10,6 +10,7 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/login/helper.h" +#include "chrome/browser/chromeos/login/oobe_progress_bar.h" #include "chrome/browser/chromeos/status/clock_menu_button.h" #include "chrome/browser/chromeos/status/feedback_menu_button.h" #include "chrome/browser/chromeos/status/language_menu_button.h" @@ -36,6 +37,7 @@ BackgroundView::BackgroundView() : status_area_(NULL), os_version_label_(NULL), boot_times_label_(NULL), + progress_bar_(NULL), did_paint_(false) { views::Painter* painter = CreateBackgroundPainter(); set_background(views::Background::CreateBackgroundPainter(true, painter)); @@ -87,14 +89,17 @@ void BackgroundView::Paint(gfx::Canvas* canvas) { } void BackgroundView::Layout() { - int corner_padding = 5; - int kInfoLeftPadding = 60; - int kInfoBottomPadding = 40; - int kInfoBetweenLinesPadding = 4; + const int kCornerPadding = 5; + const int kInfoLeftPadding = 60; + const int kInfoBottomPadding = 10; + const int kInfoBetweenLinesPadding = 4; + const int kProgressBarBottomPadding = 20; + const int kProgressBarWidth = 750; + const int kProgressBarHeight = 70; gfx::Size status_area_size = status_area_->GetPreferredSize(); status_area_->SetBounds( - width() - status_area_size.width() - corner_padding, - corner_padding, + width() - status_area_size.width() - kCornerPadding, + kCornerPadding, status_area_size.width(), status_area_size.height()); gfx::Size version_size = os_version_label_->GetPreferredSize(); @@ -109,8 +114,15 @@ void BackgroundView::Layout() { boot_times_label_->SetBounds( kInfoLeftPadding, height() - (version_size.height() + kInfoBottomPadding), - width() - 2 * corner_padding, + width() - 2 * kCornerPadding, version_size.height()); + if (progress_bar_) { + progress_bar_->SetBounds( + (width() - kProgressBarWidth) / 2, + (height() - kProgressBarBottomPadding - kProgressBarHeight), + kProgressBarWidth, + kProgressBarHeight); + } } void BackgroundView::ChildPreferredSizeChanged(View* child) { @@ -190,6 +202,31 @@ void BackgroundView::InitInfoLabels() { } } +void BackgroundView::InitProgressBar() { + std::vector<int> steps; + steps.push_back(IDS_OOBE_SELECT_NETWORK); + steps.push_back(IDS_OOBE_EULA); + steps.push_back(IDS_OOBE_SIGNIN); + steps.push_back(IDS_OOBE_REGISTRATION); + steps.push_back(IDS_OOBE_PICTURE); + progress_bar_ = new OobeProgressBar(steps); + AddChildView(progress_bar_); +} + +void BackgroundView::SetOobeProgressBarVisible(bool visible) { + if (!progress_bar_ && visible) + InitProgressBar(); + + if (progress_bar_) + progress_bar_->SetVisible(visible); +} + +void BackgroundView::SetOobeProgress(LoginStep step) { + DCHECK(step <= PICTURE); + if (progress_bar_) + progress_bar_->SetProgress(step); +} + void BackgroundView::UpdateWindowType() { std::vector<int> params; params.push_back(did_paint_ ? 1 : 0); diff --git a/chrome/browser/chromeos/login/background_view.h b/chrome/browser/chromeos/login/background_view.h index f5c4540..5c34a6a 100644 --- a/chrome/browser/chromeos/login/background_view.h +++ b/chrome/browser/chromeos/login/background_view.h @@ -20,12 +20,21 @@ class Profile; namespace chromeos { +class OobeProgressBar; class StatusAreaView; // View used to render the background during login. BackgroundView contains // StatusAreaView. class BackgroundView : public views::View, public StatusAreaHost { public: + enum LoginStep { + SELECT_NETWORK, + EULA, + SIGNIN, + REGISTRATION, + PICTURE + }; + BackgroundView(); // Creates a window containing an instance of WizardContentsView as the root @@ -37,6 +46,12 @@ class BackgroundView : public views::View, public StatusAreaHost { // Toggles status area visibility. void SetStatusAreaVisible(bool visible); + // Toggles OOBE progress bar visibility, the bar is hidden by default. + void SetOobeProgressBarVisible(bool visible); + + // Sets current step on OOBE progress bar. + void SetOobeProgress(LoginStep step); + protected: // Overridden from views::View: virtual void Paint(gfx::Canvas* canvas); @@ -55,11 +70,13 @@ class BackgroundView : public views::View, public StatusAreaHost { virtual bool IsBrowserMode() const; virtual bool IsScreenLockerMode() const; -private: + private: // Creates and adds the status_area. void InitStatusArea(); // Creates and adds the labels for version and boot time. void InitInfoLabels(); + // Creates and add OOBE progress bar. + void InitProgressBar(); // Invokes SetWindowType for the window. This is invoked during startup and // after we've painted. @@ -74,6 +91,7 @@ private: StatusAreaView* status_area_; views::Label* os_version_label_; views::Label* boot_times_label_; + OobeProgressBar* progress_bar_; // Handles asynchronously loading the version. VersionLoader version_loader_; diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc index 5e6abeb..e8f2a75 100644 --- a/chrome/browser/chromeos/login/existing_user_controller.cc +++ b/chrome/browser/chromeos/login/existing_user_controller.cc @@ -112,6 +112,11 @@ void ExistingUserController::Init() { background_window_ = BackgroundView::CreateWindowContainingView( background_bounds_, &background_view_); + + if (!WizardController::IsOobeComplete()) { + background_view_->SetOobeProgressBarVisible(true); + background_view_->SetOobeProgress(chromeos::BackgroundView::SIGNIN); + } background_window_->Show(); } for (size_t i = 0; i < controllers_.size(); ++i) { diff --git a/chrome/browser/chromeos/login/oobe_progress_bar.cc b/chrome/browser/chromeos/login/oobe_progress_bar.cc new file mode 100644 index 0000000..0da6853 --- /dev/null +++ b/chrome/browser/chromeos/login/oobe_progress_bar.cc @@ -0,0 +1,135 @@ +// 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. + +#include "chrome/browser/chromeos/login/oobe_progress_bar.h" + +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "base/logging.h" +#include "gfx/canvas_skia.h" +#include "grit/theme_resources.h" +#include "third_party/skia/include/core/SkBitmap.h" + +namespace chromeos { + +// static +SkBitmap* OobeProgressBar::dot_current_ = NULL; +SkBitmap* OobeProgressBar::dot_empty_ = NULL; +SkBitmap* OobeProgressBar::dot_filled_ = NULL; +SkBitmap* OobeProgressBar::line_ = NULL; +SkBitmap* OobeProgressBar::line_left_ = NULL; +SkBitmap* OobeProgressBar::line_right_ = NULL; + +static const SkColor kCurrentTextColor = SkColorSetRGB(255, 255, 255); +static const SkColor kEmptyTextColor = SkColorSetRGB(112, 115, 118); +static const SkColor kFilledTextColor = SkColorSetRGB(112, 115, 118); +static const int kTextPadding = 5; + +OobeProgressBar::OobeProgressBar(const std::vector<int>& steps) + : steps_(steps), progress_(0) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + font_ = rb.GetFont(ResourceBundle::BaseFont); + InitClass(); +} + +// static +void OobeProgressBar::InitClass() { + static bool initialized = false; + if (!initialized) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + + // Load images. + dot_current_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_DOT_CURRENT); + dot_empty_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_DOT_EMPTY); + dot_filled_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_DOT_FILLED); + line_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_LINE); + line_left_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_LINE_LEFT); + line_right_ = rb.GetBitmapNamed(IDR_OOBE_PROGRESS_LINE_RIGHT); + + initialized = true; + } +} + +void OobeProgressBar::Paint(gfx::Canvas* canvas) { + gfx::Rect bounds = GetLocalBounds(false); + + int x = bounds.x(); + int y = bounds.y(); + + double step_width = static_cast<double>(bounds.width()) / steps_.size(); + + for (size_t i = 0; i < steps_.size(); ++i) { + SkBitmap* dot; + SkColor color; + SkBitmap* line_before = line_; + SkBitmap* line_after = line_; + if (i < progress_) { + dot = dot_filled_; + color = kFilledTextColor; + } else if (i == progress_) { + dot = dot_current_; + color = kCurrentTextColor; + line_before = line_left_; + line_after = line_right_; + } else { + dot = dot_empty_; + color = kEmptyTextColor; + } + + // x coordinate for next step. + int next_x = static_cast<int>((i + 1) * step_width); + + // Offset of line origin from dot origin. + int line_offset_y = (dot->height() - line_->height()) / 2; + + // Current x for painting. + int ix = x; + + int line_width = ((next_x - x) - + (line_before->width() + dot->width() + line_after->width())) / 2; + if (i > 0) { + canvas->TileImageInt(*line_, ix, y + line_offset_y, + line_width, line_->height()); + } + ix += line_width; + if (i > 0) { + canvas->DrawBitmapInt(*line_before, ix, y + line_offset_y); + } + ix += line_before->width(); + + canvas->DrawBitmapInt(*dot, ix, y); + ix += dot->width(); + + if (i != steps_.size() - 1) + canvas->DrawBitmapInt(*line_after, ix, y + line_offset_y); + ix += line_after->width(); + + if (i != steps_.size() - 1) { + canvas->TileImageInt(*line_, ix, y + line_offset_y, + next_x - ix, line_->height()); + } + + std::wstring str = l10n_util::GetString(steps_[i]); + canvas->DrawStringInt(str, font_, color, + x + kTextPadding, y + dot->height() + kTextPadding, + (next_x - x - 2 * kTextPadding), + (bounds.height() - dot->height() - 2 * kTextPadding), + gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER | + gfx::Canvas::TEXT_VALIGN_TOP); + + x = next_x; + } +} + +void OobeProgressBar::LocaleChanged() { + SchedulePaint(); +} + +void OobeProgressBar::SetProgress(size_t progress) { + DCHECK(progress < steps_.size()); + progress_ = progress; + SchedulePaint(); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/login/oobe_progress_bar.h b/chrome/browser/chromeos/login/oobe_progress_bar.h new file mode 100644 index 0000000..b655841 --- /dev/null +++ b/chrome/browser/chromeos/login/oobe_progress_bar.h @@ -0,0 +1,61 @@ +// 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_OOBE_PROGRESS_BAR_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_OOBE_PROGRESS_BAR_H_ + +#include <vector> + +#include "base/logging.h" +#include "gfx/font.h" +#include "views/view.h" + +class SkBitmap; + +namespace chromeos { + +// Special purpose progress bar with labeled steps that is used to show user's +// progress in OOBE process. +class OobeProgressBar : public views::View { + public: + // Construct progress bar with given labels as steps. + // |steps| is a vector of string IDs from resources. + explicit OobeProgressBar(const std::vector<int>& steps); + + // Overridden from View: + virtual void Paint(gfx::Canvas* canvas); + + // Set and get the progress bar progress in range [0, steps_.size() - 1]. + void SetProgress(size_t progress); + int GetProgress() const { return progress_; } + + // Add progress to current. + void AddProgress(size_t tick) { SetProgress(progress_ + tick); } + + protected: + // Overridden from View: + virtual void LocaleChanged(); + + private: + static void InitClass(); + + // Graphics. + static SkBitmap* dot_current_; + static SkBitmap* dot_empty_; + static SkBitmap* dot_filled_; + static SkBitmap* line_; + static SkBitmap* line_left_; + static SkBitmap* line_right_; + + gfx::Font font_; + + std::vector<int> steps_; + size_t progress_; + + DISALLOW_COPY_AND_ASSIGN(OobeProgressBar); +}; + +} // chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_OOBE_PROGRESS_BAR_H_ diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index 21388be..8e676fe 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -237,8 +237,7 @@ void WizardController::Init(const std::string& first_screen_name, NULL); window->SetContentsView(contents_); - PrefService* prefs = g_browser_process->local_state(); - bool oobe_complete = prefs->GetBoolean(kOobeComplete); + bool oobe_complete = IsOobeComplete(); if (!oobe_complete || first_screen_name == kOutOfBoxScreenName) { is_out_of_box_ = true; @@ -261,6 +260,7 @@ void WizardController::ShowBackground(const gfx::Rect& bounds) { background_widget_ = chromeos::BackgroundView::CreateWindowContainingView(bounds, &background_view_); + background_view_->SetOobeProgressBarVisible(true); background_widget_->Show(); } @@ -317,10 +317,12 @@ chromeos::RegistrationScreen* WizardController::GetRegistrationScreen() { void WizardController::ShowNetworkScreen() { SetStatusAreaVisible(false); SetCurrentScreen(GetNetworkScreen()); + background_view_->SetOobeProgress(chromeos::BackgroundView::SELECT_NETWORK); } void WizardController::ShowLoginScreen() { SetStatusAreaVisible(true); + background_view_->SetOobeProgress(chromeos::BackgroundView::SIGNIN); // When run under automation test show plain login screen. if (!is_test_mode_ && @@ -353,21 +355,26 @@ void WizardController::ShowAccountScreen() { void WizardController::ShowUpdateScreen() { SetStatusAreaVisible(true); SetCurrentScreen(GetUpdateScreen()); + // There is no special step for update. + background_view_->SetOobeProgress(chromeos::BackgroundView::SELECT_NETWORK); } void WizardController::ShowUserImageScreen() { SetStatusAreaVisible(true); SetCurrentScreen(GetUserImageScreen()); + background_view_->SetOobeProgress(chromeos::BackgroundView::PICTURE); } void WizardController::ShowEulaScreen() { SetStatusAreaVisible(false); SetCurrentScreen(GetEulaScreen()); + background_view_->SetOobeProgress(chromeos::BackgroundView::EULA); } void WizardController::ShowRegistrationScreen() { SetStatusAreaVisible(true); SetCurrentScreen(GetRegistrationScreen()); + background_view_->SetOobeProgress(chromeos::BackgroundView::REGISTRATION); } void WizardController::SetStatusAreaVisible(bool visible) { @@ -632,6 +639,10 @@ chromeos::ScreenObserver* WizardController::GetObserver(WizardScreen* screen) { return observer_ ? observer_ : this; } +bool WizardController::IsOobeComplete() { + return g_browser_process->local_state()->GetBoolean(kOobeComplete); +} + namespace browser { // Declared in browser_dialogs.h so that others don't need to depend on our .h. @@ -657,8 +668,7 @@ void ShowLoginWizard(const std::string& first_screen_name, gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(size)); // Check whether we need to execute OOBE process. - bool oobe_complete = g_browser_process->local_state()-> - GetBoolean(kOobeComplete); + bool oobe_complete = WizardController::IsOobeComplete(); if (first_screen_name.empty() && oobe_complete && diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h index d5c2b4f..7366fa3 100644 --- a/chrome/browser/chromeos/login/wizard_controller.h +++ b/chrome/browser/chromeos/login/wizard_controller.h @@ -52,6 +52,9 @@ class WizardController : public chromeos::ScreenObserver, return default_controller_; } + // Returns OOBE completion status. + static bool IsOobeComplete(); + // Shows the first screen defined by |first_screen_name| or by default // if the parameter is empty. |screen_bounds| are used to calculate position // of the wizard screen. |