Chromium Code Reviews| Index: chrome/browser/ui/cocoa/app_list/app_list_controller_cocoa.mm |
| diff --git a/chrome/browser/ui/cocoa/app_list/app_list_controller_cocoa.mm b/chrome/browser/ui/cocoa/app_list/app_list_controller_cocoa.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..266a72b9b59cf2aa53ae903a50711c7e69330ffe |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/app_list/app_list_controller_cocoa.mm |
| @@ -0,0 +1,119 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/bind.h" |
| +#include "base/lazy_instance.h" |
| +#include "base/memory/scoped_nsobject.h" |
| +#include "base/message_loop.h" |
| +#include "base/time.h" |
| +#include "base/timer.h" |
| +#include "chrome/browser/ui/app_list/app_list_controller.h" |
| +#include "ui/app_list/cocoa/app_list_view_window.h" |
| + |
| +namespace { |
| + |
| +class AppListControllerDelegateCocoa : public AppListControllerDelegate { |
|
sail
2013/01/09 22:09:53
is this class used anywhere?
tapted
2013/01/10 00:07:36
No, not yet (I have this stub plumbed through in a
|
| + public: |
| + AppListControllerDelegateCocoa(); |
| + virtual ~AppListControllerDelegateCocoa(); |
| + |
| + private: |
| + // AppListControllerDelegate overrides: |
| + virtual void DismissView() OVERRIDE; |
| + virtual bool CanShowCreateShortcutsDialog() OVERRIDE; |
| + virtual void ActivateApp(Profile* profile, |
| + const std::string& extension_id, |
| + int event_flags) OVERRIDE; |
| + virtual void LaunchApp(Profile* profile, |
| + const std::string& extension_id, |
| + int event_flags) OVERRIDE; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppListControllerDelegateCocoa); |
| +}; |
| + |
| +// The AppListController class manages global resources needed for the app |
| +// list to operate, and controls when the app list is opened and closed. |
| +class AppListController { |
| + public: |
| + AppListController() {} |
| + ~AppListController() {} |
| + |
| + void CreateAppList(); |
| + void ShowAppList(); |
| + void DismissAppList(); |
| + private: |
| + scoped_nsobject<AppListViewWindow> current_window_; |
| + base::OneShotTimer<AppListController> timer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppListController); |
| +}; |
| + |
| +base::LazyInstance<AppListController>::Leaky g_app_list_controller = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +AppListControllerDelegateCocoa::AppListControllerDelegateCocoa() {} |
| + |
| +AppListControllerDelegateCocoa::~AppListControllerDelegateCocoa() {} |
| + |
| +void AppListControllerDelegateCocoa::DismissView() { |
| + g_app_list_controller.Get().DismissAppList(); |
| +} |
| + |
| +bool AppListControllerDelegateCocoa::CanShowCreateShortcutsDialog() { |
| + return false; |
| +} |
| + |
| +void AppListControllerDelegateCocoa::ActivateApp( |
| + Profile* profile, const std::string& extension_id, int event_flags) { |
| + // TODO(tapted): Refactor this from Win into shared. |
| +} |
| + |
| +void AppListControllerDelegateCocoa::LaunchApp( |
| + Profile* profile, const std::string& extension_id, int event_flags) { |
| + // TODO(tapted): Refactor this from Win into shared. |
| +} |
| + |
| +void AppListController::CreateAppList() { |
| + current_window_.reset([[AppListViewWindow alloc] initAsBubble]); |
| +} |
| + |
| +void AppListController::ShowAppList() { |
| + const int kLifetimeIntervalMS = 1000; |
| + |
| + if (!current_window_) |
| + CreateAppList(); |
| + |
| + timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kLifetimeIntervalMS), this, |
| + &AppListController::DismissAppList); |
| + [current_window_ makeKeyAndOrderFront:nil]; |
| +} |
| + |
| +void AppListController::DismissAppList() { |
| + if (!current_window_) |
| + return; |
| + |
| + timer_.Stop(); |
| + [current_window_ close]; |
| +} |
| + |
| +void CreateAppList() { |
|
sail
2013/01/09 22:09:53
is this function used anywhere?
tapted
2013/01/10 00:07:36
Not yet - I'll delete it. And good point - this ma
|
| + g_app_list_controller.Get().CreateAppList(); |
| +} |
| + |
| +} // namespace |
| + |
| + |
| +namespace app_list_controller { |
| + |
| +void InitAppList() { |
| + // TODO(tapted): AppList warmup code coes here. |
| +} |
| + |
| +void ShowAppList() { |
| + // Create the App list. |
| + g_app_list_controller.Get().ShowAppList(); |
| +} |
| + |
| +} // namespace app_list_controller |