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 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_MAC_H_ 6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_MAC_H_ 7 8 #import <Cocoa/Cocoa.h> 9 10 #include "apps/app_shim/app_shim_handler_mac.h" 11 #include "base/mac/scoped_nsobject.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "chrome/browser/ui/app_list/app_list_service_impl.h" 14 15 class AppListControllerDelegateImpl; 16 17 @class AppListAnimationController; 18 @class AppListWindowController; 19 template <typename T> struct DefaultSingletonTraits; 20 21 namespace gfx { 22 class Display; 23 class Point; 24 } 25 26 // AppListServiceMac manages global resources needed for the app list to 27 // operate, and controls when the app list is opened and closed. 28 class AppListServiceMac : public AppListServiceImpl, 29 public apps::AppShimHandler { 30 public: 31 virtual ~AppListServiceMac(); 32 33 static AppListServiceMac* GetInstance(); 34 35 // Finds the position for a window to anchor it to the dock. This chooses the 36 // most appropriate position for the window based on whether the dock exists, 37 // the position of the dock (calculated by the difference between the display 38 // bounds and display work area), whether the mouse cursor is visible and its 39 // position. Sets |target_origin| to the coordinates for the window to appear 40 // at, and |start_origin| to the coordinates the window should begin animating 41 // from. Coordinates are for the bottom-left coordinate of the window, in 42 // AppKit space (Y positive is up). 43 static void FindAnchorPoint(const gfx::Size& window_size, 44 const gfx::Display& display, 45 int primary_display_height, 46 bool cursor_is_visible, 47 const gfx::Point& cursor, 48 NSPoint* target_origin, 49 NSPoint* start_origin); 50 51 void ShowWindowNearDock(); 52 void WindowAnimationDidEnd(); 53 54 // AppListService overrides: 55 virtual void Init(Profile* initial_profile) OVERRIDE; 56 virtual void CreateForProfile(Profile* requested_profile) OVERRIDE; 57 virtual void ShowForProfile(Profile* requested_profile) OVERRIDE; 58 virtual void DismissAppList() OVERRIDE; 59 virtual bool IsAppListVisible() const OVERRIDE; 60 virtual void EnableAppList(Profile* initial_profile, 61 AppListEnableSource enable_source) OVERRIDE; 62 virtual gfx::NativeWindow GetAppListWindow() OVERRIDE; 63 virtual AppListControllerDelegate* GetControllerDelegate() OVERRIDE; 64 virtual Profile* GetCurrentAppListProfile() OVERRIDE; 65 virtual void CreateShortcut() OVERRIDE; 66 67 // AppShimHandler overrides: 68 virtual void OnShimLaunch(apps::AppShimHandler::Host* host, 69 apps::AppShimLaunchType launch_type, 70 const std::vector<base::FilePath>& files) OVERRIDE; 71 virtual void OnShimClose(apps::AppShimHandler::Host* host) OVERRIDE; 72 virtual void OnShimFocus(apps::AppShimHandler::Host* host, 73 apps::AppShimFocusType focus_type, 74 const std::vector<base::FilePath>& files) OVERRIDE; 75 virtual void OnShimSetHidden(apps::AppShimHandler::Host* host, 76 bool hidden) OVERRIDE; 77 virtual void OnShimQuit(apps::AppShimHandler::Host* host) OVERRIDE; 78 79 private: 80 friend struct DefaultSingletonTraits<AppListServiceMac>; 81 82 AppListServiceMac(); 83 84 base::scoped_nsobject<AppListWindowController> window_controller_; 85 base::scoped_nsobject<AppListAnimationController> animation_controller_; 86 base::scoped_nsobject<NSRunningApplication> previously_active_application_; 87 NSPoint last_start_origin_; 88 Profile* profile_; 89 scoped_ptr<AppListControllerDelegateImpl> controller_delegate_; 90 91 DISALLOW_COPY_AND_ASSIGN(AppListServiceMac); 92 }; 93 94 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SERVICE_MAC_H_ 95