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