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