• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ash/first_run/first_run_helper_impl.h"
6 
7 #include "ash/launcher/launcher.h"
8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h"
10 #include "ash/system/tray/system_tray.h"
11 #include "base/logging.h"
12 #include "ui/app_list/views/app_list_view.h"
13 #include "ui/aura/window.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h"
17 
18 namespace ash {
19 
20 namespace {
21 
CreateFirstRunWindow()22 views::Widget* CreateFirstRunWindow() {
23   views::Widget::InitParams params(
24       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
25   params.bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds();
26   params.show_state = ui::SHOW_STATE_FULLSCREEN;
27   params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
28   params.parent =
29       Shell::GetContainer(Shell::GetPrimaryRootWindow(),
30                           ash::internal::kShellWindowId_OverlayContainer);
31   views::Widget* window = new views::Widget;
32   window->Init(params);
33   return window;
34 }
35 
36 }  // anonymous namespace
37 
FirstRunHelperImpl()38 FirstRunHelperImpl::FirstRunHelperImpl()
39     : widget_(CreateFirstRunWindow()) {
40   Shell::GetInstance()->overlay_filter()->Activate(this);
41 }
42 
~FirstRunHelperImpl()43 FirstRunHelperImpl::~FirstRunHelperImpl() {
44   Shell::GetInstance()->overlay_filter()->Deactivate();
45   if (IsTrayBubbleOpened())
46     CloseTrayBubble();
47   widget_->Close();
48 }
49 
GetOverlayWidget()50 views::Widget* FirstRunHelperImpl::GetOverlayWidget() {
51   return widget_;
52 }
53 
OpenAppList()54 void FirstRunHelperImpl::OpenAppList() {
55   if (Shell::GetInstance()->GetAppListTargetVisibility())
56     return;
57   Shell::GetInstance()->ToggleAppList(NULL);
58 }
59 
CloseAppList()60 void FirstRunHelperImpl::CloseAppList() {
61   if (!Shell::GetInstance()->GetAppListTargetVisibility())
62     return;
63   Shell::GetInstance()->ToggleAppList(NULL);
64 }
65 
GetLauncherBounds()66 gfx::Rect FirstRunHelperImpl::GetLauncherBounds() {
67   ash::Launcher* launcher = ash::Launcher::ForPrimaryDisplay();
68   return launcher->GetVisibleItemsBoundsInScreen();
69 }
70 
GetAppListButtonBounds()71 gfx::Rect FirstRunHelperImpl::GetAppListButtonBounds() {
72   ash::Launcher* launcher = ash::Launcher::ForPrimaryDisplay();
73   views::View* app_button = launcher->GetAppListButtonView();
74   return app_button->GetBoundsInScreen();
75 }
76 
GetAppListBounds()77 gfx::Rect FirstRunHelperImpl::GetAppListBounds() {
78   app_list::AppListView* view = Shell::GetInstance()->GetAppListView();
79   return view->GetBoundsInScreen();
80 }
81 
Cancel()82 void FirstRunHelperImpl::Cancel() {
83   FOR_EACH_OBSERVER(Observer, observers(), OnCancelled());
84 }
85 
IsCancelingKeyEvent(ui::KeyEvent * event)86 bool FirstRunHelperImpl::IsCancelingKeyEvent(ui::KeyEvent* event) {
87   return event->key_code() == ui::VKEY_ESCAPE;
88 }
89 
GetWindow()90 aura::Window* FirstRunHelperImpl::GetWindow() {
91   return widget_->GetNativeWindow();
92 }
93 
OpenTrayBubble()94 void FirstRunHelperImpl::OpenTrayBubble() {
95   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
96   tray->ShowPersistentDefaultView();
97 }
98 
CloseTrayBubble()99 void FirstRunHelperImpl::CloseTrayBubble() {
100   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
101   DCHECK(tray->HasSystemBubble()) << "Tray bubble is closed already.";
102   tray->CloseSystemBubble();
103 }
104 
IsTrayBubbleOpened()105 bool FirstRunHelperImpl::IsTrayBubbleOpened() {
106   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
107   return tray->HasSystemBubble();
108 }
109 
GetTrayBubbleBounds()110 gfx::Rect FirstRunHelperImpl::GetTrayBubbleBounds() {
111   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
112   views::View* bubble = tray->GetSystemBubble()->bubble_view();
113   return bubble->GetBoundsInScreen();
114 }
115 
GetHelpButtonBounds()116 gfx::Rect FirstRunHelperImpl::GetHelpButtonBounds() {
117   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
118   views::View* help_button = tray->GetHelpButtonView();
119   return help_button->GetBoundsInScreen();
120 }
121 
122 }  // namespace ash
123 
124