Chromium Code Reviews| Index: chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| diff --git a/chrome/browser/ui/views/app_list/app_list_controller_win.cc b/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e7a421b6c3f37537304741a3f6f9e8305e103ef6 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/app_list/app_list_controller_win.cc |
| @@ -0,0 +1,121 @@ |
| +// Copyright (c) 2012 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/lazy_instance.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/app_list/app_list_controller.h" |
| +#include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
| +#include "chrome/browser/ui/extensions/application_launch.h" |
| +#include "grit/theme_resources.h" |
| +#include "ui/app_list/app_list_view.h" |
| +#include "ui/app_list/icon_cache.h" |
| +#include "ui/app_list/pagination_model.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/base/win/shell.h" |
| +#include "ui/views/bubble/bubble_border.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace { |
| + |
| +class AppListControllerWin : public AppListController { |
| + public: |
| + AppListControllerWin(); |
| + virtual ~AppListControllerWin(); |
| + |
| + private: |
| + // AppListController overrides: |
| + virtual void CloseView() OVERRIDE; |
| + virtual bool IsAppPinned(const std::string& extension_id) OVERRIDE; |
| + virtual void PinApp(const std::string& extension_id) OVERRIDE; |
| + virtual void UnpinApp(const std::string& extension_id) OVERRIDE; |
| + virtual bool CanPin() OVERRIDE; |
| + virtual void ActivateApp(Profile* profile, |
| + const std::string& extension_id, |
| + int event_flags) OVERRIDE; |
| + virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppListControllerWin); |
| +}; |
| + |
| +AppListControllerWin::AppListControllerWin() {} |
| + |
| +AppListControllerWin::~AppListControllerWin() {} |
| + |
| +void AppListControllerWin::CloseView() {} |
| + |
| +bool AppListControllerWin::IsAppPinned(const std::string& extension_id) { |
| + return false; |
| +} |
| +void AppListControllerWin::PinApp(const std::string& extension_id) {} |
|
msw
2012/08/31 09:16:58
nit: add blank line above.
benwells
2012/09/04 04:47:59
Done.
|
| + |
| +void AppListControllerWin::UnpinApp(const std::string& extension_id) {} |
| + |
| +bool AppListControllerWin::CanPin() { |
| + return false; |
| +} |
| + |
| +void AppListControllerWin::ActivateApp(Profile* profile, |
| + const std::string& extension_id, |
| + int event_flags) { |
| + ExtensionService* service = profile->GetExtensionService(); |
| + DCHECK(service); |
| + const extensions::Extension* extension = service->GetInstalledExtension( |
| + extension_id); |
| + DCHECK(extension); |
| + application_launch::OpenApplication(application_launch::LaunchParams( |
| + profile, extension, extension_misc::LAUNCH_TAB, NEW_FOREGROUND_TAB)); |
| +} |
| + |
| +gfx::ImageSkia AppListControllerWin::GetWindowAppIcon() { |
| + gfx::ImageSkia* resource = ResourceBundle::GetSharedInstance(). |
| + GetImageSkiaNamed(IDR_APP_LIST); |
| + DCHECK(resource); |
|
msw
2012/08/31 09:16:58
nit: DCHECKing before a dereference is unnecessary
benwells
2012/09/04 04:47:59
Done.
|
| + return *resource; |
| +}; |
| + |
| +// The AppListResources class manages global resources needed for the app |
| +// list to operate. |
| +class AppListResources { |
| + public: |
|
xiyuan
2012/08/30 16:50:51
nit: wrong indent
benwells
2012/09/04 04:47:59
Done.
|
| + AppListResources::AppListResources() { |
| + app_list::IconCache::CreateInstance(); |
| + } |
| + |
| + app_list::PaginationModel* pagination_model() { return &pagination_model_; } |
| + |
| + private: |
|
xiyuan
2012/08/30 16:50:51
nit: wrong indent
benwells
2012/09/04 04:47:59
Done.
|
| + app_list::PaginationModel pagination_model_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppListResources); |
| +}; |
| + |
| +base::LazyInstance<AppListResources>::Leaky |
| + g_app_list_resources = LAZY_INSTANCE_INITIALIZER; |
|
msw
2012/08/31 09:16:58
nit: put "g_app_list_resources =" above, indent th
benwells
2012/09/04 04:47:59
Done.
|
| + |
| +} // namespace |
| + |
| +namespace app_list_controller { |
| + |
| +void ShowAppList() { |
| + const wchar_t kAppListAppId[] = L"ChromeAppList"; |
|
msw
2012/08/31 09:16:58
nit: I think these consts should have normal_namin
benwells
2012/09/04 04:47:59
Done.
|
| + const gfx::Point kDefaultAppListAnchor(500, 750); |
| + |
| + // The controller will be owned by the view delegate, and the delegate is |
| + // owned by the app list view. The app list view manages it's own lifetime. |
| + app_list::AppListView* view = new app_list::AppListView( |
| + new AppListViewDelegate(new AppListControllerWin())); |
| + view->InitAsBubble( |
| + GetDesktopWindow(), |
| + g_app_list_resources.Get().pagination_model(), |
| + NULL, |
| + kDefaultAppListAnchor, |
| + views::BubbleBorder::BOTTOM_LEFT); |
| + view->Show(); |
| + view->GetWidget()->GetTopLevelWidget()->UpdateWindowIcon(); |
| + ui::win::SetAppIdForWindow(kAppListAppId, |
| + view->GetWidget()->GetTopLevelWidget()->GetNativeWindow()); |
| +} |
| + |
| +} // namespace app_list_controller |