- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / first_run / first_run_controller.cc
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.
4
5 #include "chrome/browser/chromeos/first_run/first_run_controller.h"
6
7 #include "ash/launcher/launcher.h"
8 #include "ash/shell.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"
15
16 namespace {
17
18 gfx::Rect GetScreenBounds() {
19   return ash::Shell::GetScreen()->GetPrimaryDisplay().bounds();
20 }
21
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;
28   params.parent =
29       ash::Shell::GetContainer(
30           ash::Shell::GetPrimaryRootWindow(),
31           ash::internal::kShellWindowId_OverlayContainer);
32   views::Widget* window = new views::Widget;
33   window->Init(params);
34   return window;
35 }
36
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());
44 }
45
46 }  // anonymous namespace
47
48 namespace chromeos {
49
50 FirstRunController::FirstRunController()
51     : window_(NULL),
52       actor_(NULL) {
53 }
54
55 FirstRunController::~FirstRunController() {
56   if (window_)
57     Stop();
58 }
59
60 void FirstRunController::Start() {
61   if (window_)
62     return;
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())
70     OnActorInitialized();
71 }
72
73 void FirstRunController::Stop() {
74   window_->Close();
75   window_ = NULL;
76   if (actor_)
77     actor_->set_delegate(NULL);
78   actor_ = NULL;
79 }
80
81 void FirstRunController::OnActorInitialized() {
82   window_->Show();
83   gfx::Rect launcher_bounds = GetLauncherBounds();
84   actor_->AddBackgroundHole(launcher_bounds.x(),
85                             launcher_bounds.y(),
86                             launcher_bounds.width(),
87                             launcher_bounds.height());
88   actor_->ShowStep("first-step",
89                    FirstRunActor::StepPosition()
90                        .SetLeft(0)
91                        .SetBottom(
92                            GetScreenBounds().height() - launcher_bounds.y()));
93 }
94
95 void FirstRunController::OnNextButtonClicked(const std::string& step_name) {
96   CHECK(step_name == "first-step");
97   Stop();
98   base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
99 }
100
101 void FirstRunController::OnActorDestroyed() {
102   actor_ = NULL;
103 }
104
105 }  // namespace chromeos
106