Skip to content

Commit

Permalink
Implemented skeleton of new first-run overlay UI.
Browse files Browse the repository at this point in the history
UI can be enabled by 'enable-first-run-ui' flag. Currently only one
example step will be shown right after login.

BUG=269286
TBR=jochen,nkostylev

Review URL: https://chromiumcodereview.appspot.com/23604021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220877 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dzhioev@chromium.org committed Sep 2, 2013
1 parent a471f65 commit 798edb2
Show file tree
Hide file tree
Showing 30 changed files with 895 additions and 1 deletion.
4 changes: 4 additions & 0 deletions chrome/browser/browser_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<structure name="IDR_DOWNLOADS_CSS" file="resources\downloads\downloads.css" flattenhtml="true" type="chrome_html" />
<structure name="IDR_DOWNLOADS_HTML" file="resources\downloads\downloads.html" flattenhtml="true" allowexternalscript="true" type="chrome_html" />
<structure name="IDR_EXTENSIONS_HTML" file="resources\extensions\extensions.html" flattenhtml="true" type="chrome_html" />
<if expr="pp_ifdef('chromeos')">
<structure name="IDR_FIRST_RUN_HTML" file="resources\chromeos\first_run\first_run.html" flattenhtml="true" type="chrome_html"/>
<structure name="IDR_FIRST_RUN_JS" file="resources\chromeos\first_run\first_run.js" flattenhtml="true" type="chrome_html" />
</if>
<structure name="IDR_HELP_CSS" file="resources\help\help.css" flattenhtml="true" type="chrome_html" />
<structure name="IDR_HELP_HTML" file="resources\help\help.html" flattenhtml="true" type="chrome_html" />
<structure name="IDR_HELP_CHANNEL_CHANGE_PAGE_CSS" file="resources\help\channel_change_page.css" flattenhtml="true" type="chrome_html" />
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/chromeos/first_run/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dzhioev@chromium.org
106 changes: 106 additions & 0 deletions chrome/browser/chromeos/first_run/first_run_controller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright 2013 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/first_run/first_run_controller.h"

#include "ash/launcher/launcher.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "chrome/browser/chromeos/first_run/first_run_view.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "ui/views/widget/widget.h"

namespace {

gfx::Rect GetScreenBounds() {
return ash::Shell::GetScreen()->GetPrimaryDisplay().bounds();
}

views::Widget* CreateFirstRunWindow() {
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.bounds = GetScreenBounds();
params.show_state = ui::SHOW_STATE_FULLSCREEN;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.parent =
ash::Shell::GetContainer(
ash::Shell::GetPrimaryRootWindow(),
ash::internal::kShellWindowId_OverlayContainer);
views::Widget* window = new views::Widget;
window->Init(params);
return window;
}

// We can't get launcher size now in normal way. This workaround uses fact that
// AppList button is the rightmost button in Launcher.
gfx::Rect GetLauncherBounds() {
ash::Launcher* launcher = ash::Launcher::ForPrimaryDisplay();
views::View* app_button = launcher->GetAppListButtonView();
gfx::Rect bounds = app_button->GetBoundsInScreen();
return gfx::Rect(0, bounds.y(), bounds.right(), bounds.height());
}

} // anonymous namespace

namespace chromeos {

FirstRunController::FirstRunController()
: window_(NULL),
actor_(NULL) {
}

FirstRunController::~FirstRunController() {
if (window_)
Stop();
}

void FirstRunController::Start() {
if (window_)
return;
window_ = CreateFirstRunWindow();
FirstRunView* view = new FirstRunView();
view->Init(ProfileManager::GetDefaultProfile());
window_->SetContentsView(view);
actor_ = view->GetActor();
actor_->set_delegate(this);
if (actor_->IsInitialized())
OnActorInitialized();
}

void FirstRunController::Stop() {
window_->Close();
window_ = NULL;
if (actor_)
actor_->set_delegate(NULL);
actor_ = NULL;
}

void FirstRunController::OnActorInitialized() {
window_->Show();
gfx::Rect launcher_bounds = GetLauncherBounds();
actor_->AddBackgroundHole(launcher_bounds.x(),
launcher_bounds.y(),
launcher_bounds.width(),
launcher_bounds.height());
actor_->ShowStep("first-step",
FirstRunActor::StepPosition()
.SetLeft(0)
.SetBottom(
GetScreenBounds().height() - launcher_bounds.y()));
}

void FirstRunController::OnNextButtonClicked(const std::string& step_name) {
CHECK(step_name == "first-step");
Stop();
base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}

void FirstRunController::OnActorDestroyed() {
actor_ = NULL;
}

} // namespace chromeos

52 changes: 52 additions & 0 deletions chrome/browser/chromeos/first_run/first_run_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2013 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_FIRST_RUN_FIRST_RUN_CONTROLLER_H_
#define CHROME_BROWSER_CHROMEOS_FIRST_RUN_FIRST_RUN_CONTROLLER_H_

#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h"

namespace views {
class Widget;
}

namespace chromeos {

// FirstRunController creates and manages first-run tutorial.
// Object manages its lifetime and deletes itself after completion of the
// tutorial.
class FirstRunController : public FirstRunActor::Delegate {
public:
FirstRunController();
virtual ~FirstRunController();

// Creates first-run UI and starts tutorial.
void Start();

// Finalizes first-run tutorial and destroys UI.
void Stop();

private:
// Overriden from FirstRunActor::Delegate.
virtual void OnActorInitialized() OVERRIDE;
virtual void OnNextButtonClicked(const std::string& step_name) OVERRIDE;
virtual void OnActorDestroyed() OVERRIDE;

// Window with UI. FirstRunController closes window after tutorial completes.
views::Widget* window_;
// The object providing interface to UI layer. It's not directly owned by
// FirstRunController.
FirstRunActor* actor_;

DISALLOW_COPY_AND_ASSIGN(FirstRunController);
};

} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_FIRST_RUN_FIRST_RUN_CONTROLLER_H_

54 changes: 54 additions & 0 deletions chrome/browser/chromeos/first_run/first_run_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2013 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/first_run/first_run_view.h"

#include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/views/controls/webview/webview.h"
#include "url/gurl.h"

namespace chromeos {

FirstRunView::FirstRunView()
: web_view_(NULL) {
}

void FirstRunView::Init(content::BrowserContext* context) {
web_view_ = new views::WebView(context);
AddChildView(web_view_);
web_view_->LoadInitialURL(GURL(chrome::kChromeUIFirstRunURL));
web_view_->RequestFocus();

web_view_->web_contents()->SetDelegate(this);

SkBitmap background;
background.setConfig(SkBitmap::kA8_Config, 1, 1);
background.allocPixels();
background.eraseARGB(0, 0, 0, 0);
web_view_->web_contents()->GetRenderViewHost()->GetView()->
SetBackground(background);
}

FirstRunActor* FirstRunView::GetActor() {
return static_cast<FirstRunUI*>(
web_view_->web_contents()->GetWebUI()->GetController())->get_actor();
}

void FirstRunView::Layout() {
web_view_->SetBoundsRect(bounds());
}

bool FirstRunView::HandleContextMenu(
const content::ContextMenuParams& params) {
// Discards context menu.
return true;
}

} // namespace chromeos

50 changes: 50 additions & 0 deletions chrome/browser/chromeos/first_run/first_run_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2013 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_FIRST_RUN_FIRST_RUN_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_FIRST_RUN_FIRST_RUN_VIEW_H_

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/views/view.h"

class Profile;

namespace content {
class BrowserContext;
}

namespace views {
class WebView;
}

namespace chromeos {

class FirstRunActor;

// WebUI view used for first run tutorial.
class FirstRunView : public views::View,
public content::WebContentsDelegate {
public:
FirstRunView();
void Init(content::BrowserContext* context);
FirstRunActor* GetActor();
private:
// Overriden from views::View.
virtual void Layout() OVERRIDE;

// Overriden from content::WebContentsDelegate.
virtual bool HandleContextMenu(
const content::ContextMenuParams& params) OVERRIDE;

views::WebView* web_view_;

DISALLOW_COPY_AND_ASSIGN(FirstRunView);
};

} // namespace chromeos

#endif // CHROME_BROWSER_CHROMEOS_FIRST_RUN_FIRST_RUN_VIEW_H_

8 changes: 8 additions & 0 deletions chrome/browser/chromeos/login/login_display_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/customization_document.h"
#include "chrome/browser/chromeos/first_run/first_run_controller.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/language_preferences.h"
Expand Down Expand Up @@ -277,6 +278,13 @@ LoginDisplayHostImpl::~LoginDisplayHostImpl() {
chrome::EndKeepAlive();

default_host_ = NULL;
// TODO(dzhioev): find better place for starting tutorial.
if (CommandLine::ForCurrentProcess()->
HasSwitch(switches::kEnableFirstRunUI)) {
// FirstRunController manages its lifetime and destructs after tutorial
// completion.
(new FirstRunController())->Start();
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/webui_login_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WebUILoginView : public views::View,
// Initializes the webui login view.
virtual void Init();

// Overridden from views::Views:
// Overridden from views::View:
virtual bool AcceleratorPressed(
const ui::Accelerator& accelerator) OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/resources/chromeos/first_run/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dzhioev@chromium.org
18 changes: 18 additions & 0 deletions chrome/browser/resources/chromeos/first_run/background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions chrome/browser/resources/chromeos/first_run/first_run.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright 2013 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.
*/

html,
body {
margin: 0;
padding: 0;
}

body {
background-color: rgba(0, 0, 0, 0);
cursor: default;
height: 100%;
width: 100%;
}

#background {
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
z-index: -1;
}

#background .fill {
fill: rgba(0, 0, 0, 0.7);
}
19 changes: 19 additions & 0 deletions chrome/browser/resources/chromeos/first_run/first_run.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title></title>
<link rel="stylesheet" href="chrome://resources/css/widgets.css">
<link rel="stylesheet" href="first_run.css">
<link rel="stylesheet" href="step.css">
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/js/cr/ui.js"></script>
<script src="chrome://first-run/first_run.js"></script>
</head>
<body>
<include src="background.svg">
<include src="first_step.html">
</body>
</html>

Loading

0 comments on commit 798edb2

Please sign in to comment.