• 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/shelf/shelf.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 = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
29                                       ash::kShellWindowId_OverlayContainer);
30   views::Widget* window = new views::Widget;
31   window->Init(params);
32   return window;
33 }
34 
35 }  // anonymous namespace
36 
FirstRunHelperImpl()37 FirstRunHelperImpl::FirstRunHelperImpl()
38     : widget_(CreateFirstRunWindow()) {
39   Shell::GetInstance()->overlay_filter()->Activate(this);
40 }
41 
~FirstRunHelperImpl()42 FirstRunHelperImpl::~FirstRunHelperImpl() {
43   Shell::GetInstance()->overlay_filter()->Deactivate();
44   if (IsTrayBubbleOpened())
45     CloseTrayBubble();
46   widget_->Close();
47 }
48 
GetOverlayWidget()49 views::Widget* FirstRunHelperImpl::GetOverlayWidget() {
50   return widget_;
51 }
52 
OpenAppList()53 void FirstRunHelperImpl::OpenAppList() {
54   if (Shell::GetInstance()->GetAppListTargetVisibility())
55     return;
56   Shell::GetInstance()->ToggleAppList(NULL);
57 }
58 
CloseAppList()59 void FirstRunHelperImpl::CloseAppList() {
60   if (!Shell::GetInstance()->GetAppListTargetVisibility())
61     return;
62   Shell::GetInstance()->ToggleAppList(NULL);
63 }
64 
GetLauncherBounds()65 gfx::Rect FirstRunHelperImpl::GetLauncherBounds() {
66   Shelf* shelf = Shelf::ForPrimaryDisplay();
67   return shelf->GetVisibleItemsBoundsInScreen();
68 }
69 
GetAppListButtonBounds()70 gfx::Rect FirstRunHelperImpl::GetAppListButtonBounds() {
71   Shelf* shelf = Shelf::ForPrimaryDisplay();
72   views::View* app_button = shelf->GetAppListButtonView();
73   return app_button->GetBoundsInScreen();
74 }
75 
GetAppListBounds()76 gfx::Rect FirstRunHelperImpl::GetAppListBounds() {
77   app_list::AppListView* view = Shell::GetInstance()->GetAppListView();
78   return view->GetBoundsInScreen();
79 }
80 
Cancel()81 void FirstRunHelperImpl::Cancel() {
82   FOR_EACH_OBSERVER(Observer, observers(), OnCancelled());
83 }
84 
IsCancelingKeyEvent(ui::KeyEvent * event)85 bool FirstRunHelperImpl::IsCancelingKeyEvent(ui::KeyEvent* event) {
86   return event->key_code() == ui::VKEY_ESCAPE;
87 }
88 
GetWindow()89 aura::Window* FirstRunHelperImpl::GetWindow() {
90   return widget_->GetNativeWindow();
91 }
92 
OpenTrayBubble()93 void FirstRunHelperImpl::OpenTrayBubble() {
94   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
95   tray->ShowPersistentDefaultView();
96 }
97 
CloseTrayBubble()98 void FirstRunHelperImpl::CloseTrayBubble() {
99   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
100   DCHECK(tray->HasSystemBubble()) << "Tray bubble is closed already.";
101   tray->CloseSystemBubble();
102 }
103 
IsTrayBubbleOpened()104 bool FirstRunHelperImpl::IsTrayBubbleOpened() {
105   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
106   return tray->HasSystemBubble();
107 }
108 
GetTrayBubbleBounds()109 gfx::Rect FirstRunHelperImpl::GetTrayBubbleBounds() {
110   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
111   views::View* bubble = tray->GetSystemBubble()->bubble_view();
112   return bubble->GetBoundsInScreen();
113 }
114 
GetHelpButtonBounds()115 gfx::Rect FirstRunHelperImpl::GetHelpButtonBounds() {
116   SystemTray* tray = Shell::GetInstance()->GetPrimarySystemTray();
117   views::View* help_button = tray->GetHelpButtonView();
118   return help_button->GetBoundsInScreen();
119 }
120 
121 }  // namespace ash
122