1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/first_run/first_run_controller.h"
7 #include "ash/launcher/launcher.h"
9 #include "ash/shell_window_ids.h"
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
12 #include "chrome/browser/chromeos/first_run/first_run_view.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "ui/views/widget/widget.h"
18 gfx::Rect GetScreenBounds() {
19 return ash::Shell::GetScreen()->GetPrimaryDisplay().bounds();
22 views::Widget* CreateFirstRunWindow() {
23 views::Widget::InitParams params(
24 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
25 params.bounds = GetScreenBounds();
26 params.show_state = ui::SHOW_STATE_FULLSCREEN;
27 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
29 ash::Shell::GetContainer(
30 ash::Shell::GetPrimaryRootWindow(),
31 ash::internal::kShellWindowId_OverlayContainer);
32 views::Widget* window = new views::Widget;
37 // We can't get launcher size now in normal way. This workaround uses fact that
38 // AppList button is the rightmost button in Launcher.
39 gfx::Rect GetLauncherBounds() {
40 ash::Launcher* launcher = ash::Launcher::ForPrimaryDisplay();
41 views::View* app_button = launcher->GetAppListButtonView();
42 gfx::Rect bounds = app_button->GetBoundsInScreen();
43 return gfx::Rect(0, bounds.y(), bounds.right(), bounds.height());
46 } // anonymous namespace
50 FirstRunController::FirstRunController()
55 FirstRunController::~FirstRunController() {
60 void FirstRunController::Start() {
63 window_ = CreateFirstRunWindow();
64 FirstRunView* view = new FirstRunView();
65 view->Init(ProfileManager::GetDefaultProfile());
66 window_->SetContentsView(view);
67 actor_ = view->GetActor();
68 actor_->set_delegate(this);
69 if (actor_->IsInitialized())
73 void FirstRunController::Stop() {
77 actor_->set_delegate(NULL);
81 void FirstRunController::OnActorInitialized() {
83 gfx::Rect launcher_bounds = GetLauncherBounds();
84 actor_->AddBackgroundHole(launcher_bounds.x(),
86 launcher_bounds.width(),
87 launcher_bounds.height());
88 actor_->ShowStep("first-step",
89 FirstRunActor::StepPosition()
92 GetScreenBounds().height() - launcher_bounds.y()));
95 void FirstRunController::OnNextButtonClicked(const std::string& step_name) {
96 CHECK(step_name == "first-step");
98 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
101 void FirstRunController::OnActorDestroyed() {
105 } // namespace chromeos