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..6f72d3171f8eaaa55b311bee5372a97ba0d31b2d |
--- /dev/null |
+++ b/chrome/browser/ui/cocoa/app_list/app_list_controller_cocoa.mm |
@@ -0,0 +1,118 @@ |
+// 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/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.h" |
+ |
+namespace { |
+ |
+class AppListControllerDelegateCocoa : public AppListControllerDelegate { |
+ 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() : current_window_(NULL) {} |
sail
2013/01/08 07:25:27
for Objective-C classes you should use nil instead
tapted
2013/01/09 04:29:49
Good advice! Done (scoped_nsobject below).
|
+ ~AppListController() {} |
+ |
+ void CreateAppList(); |
+ void ShowAppList(); |
+ void DismissAppList(); |
+ private: |
+ NSWindow* current_window_; |
sail
2013/01/08 07:25:27
should be scoped_nsobject
tapted
2013/01/09 04:29:49
Done.
|
+ 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_ = [[AppListView alloc] initAsBubble]; |
sail
2013/01/08 07:25:27
Should also call setReleasedWhenClosed:NO
This all
tapted
2013/01/09 04:29:49
Done (in 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:NSApp]; |
sail
2013/01/08 07:25:27
you can just use nil instead of NSApp
tapted
2013/01/09 04:29:49
Done.
|
+} |
+ |
+void AppListController::DismissAppList() { |
+ if (!current_window_) |
+ return; |
+ |
+ timer_.Stop(); |
+ [current_window_ close]; |
xiyuan
2013/01/08 17:09:37
Reset |current_window_| to nil after closing?
tapted
2013/01/09 04:29:49
I think with setReleasedWhenClosed:NO it can stick
|
+} |
+ |
+void CreateAppList() { |
+ 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 |