OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/app_list/app_list_service_mac.h" | 5 #import "chrome/browser/ui/app_list/app_list_service_mac.h" |
6 | 6 |
7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "apps/app_launcher.h" | 10 #include "apps/app_launcher.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "chrome/browser/web_applications/web_app.h" | 30 #include "chrome/browser/web_applications/web_app.h" |
31 #include "chrome/browser/web_applications/web_app_mac.h" | 31 #include "chrome/browser/web_applications/web_app_mac.h" |
32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/chrome_version_info.h" | 33 #include "chrome/common/chrome_version_info.h" |
34 #include "chrome/common/mac/app_mode_common.h" | 34 #include "chrome/common/mac/app_mode_common.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "grit/chrome_unscaled_resources.h" | 36 #include "grit/chrome_unscaled_resources.h" |
37 #include "grit/google_chrome_strings.h" | 37 #include "grit/google_chrome_strings.h" |
38 #import "ui/app_list/cocoa/app_list_view_controller.h" | 38 #import "ui/app_list/cocoa/app_list_view_controller.h" |
39 #import "ui/app_list/cocoa/app_list_window_controller.h" | 39 #import "ui/app_list/cocoa/app_list_window_controller.h" |
40 #include "ui/app_list/search_box_model.h" | |
40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
42 #include "ui/gfx/display.h" | 43 #include "ui/gfx/display.h" |
43 #include "ui/gfx/screen.h" | 44 #include "ui/gfx/screen.h" |
44 | 45 |
45 namespace gfx { | 46 namespace gfx { |
46 class ImageSkia; | 47 class ImageSkia; |
47 } | 48 } |
48 | 49 |
49 // Controller for animations that show or hide the app list. | 50 // Controller for animations that show or hide the app list. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 virtual bool CanDoCreateShortcutsFlow(bool is_platform_app) OVERRIDE; | 91 virtual bool CanDoCreateShortcutsFlow(bool is_platform_app) OVERRIDE; |
91 virtual void CreateNewWindow(Profile* profile, bool incognito) OVERRIDE; | 92 virtual void CreateNewWindow(Profile* profile, bool incognito) OVERRIDE; |
92 virtual void DoCreateShortcutsFlow(Profile* profile, | 93 virtual void DoCreateShortcutsFlow(Profile* profile, |
93 const std::string& extension_id) OVERRIDE; | 94 const std::string& extension_id) OVERRIDE; |
94 virtual void ActivateApp(Profile* profile, | 95 virtual void ActivateApp(Profile* profile, |
95 const extensions::Extension* extension, | 96 const extensions::Extension* extension, |
96 int event_flags) OVERRIDE; | 97 int event_flags) OVERRIDE; |
97 virtual void LaunchApp(Profile* profile, | 98 virtual void LaunchApp(Profile* profile, |
98 const extensions::Extension* extension, | 99 const extensions::Extension* extension, |
99 int event_flags) OVERRIDE; | 100 int event_flags) OVERRIDE; |
101 virtual void ShowForProfileByPath( | |
102 const base::FilePath& profile_path) OVERRIDE; | |
100 | 103 |
101 DISALLOW_COPY_AND_ASSIGN(AppListControllerDelegateCocoa); | 104 DISALLOW_COPY_AND_ASSIGN(AppListControllerDelegateCocoa); |
102 }; | 105 }; |
103 | 106 |
104 ShellIntegration::ShortcutInfo GetAppListShortcutInfo( | 107 ShellIntegration::ShortcutInfo GetAppListShortcutInfo( |
105 const base::FilePath& profile_path) { | 108 const base::FilePath& profile_path) { |
106 ShellIntegration::ShortcutInfo shortcut_info; | 109 ShellIntegration::ShortcutInfo shortcut_info; |
107 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 110 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
108 if (channel == chrome::VersionInfo::CHANNEL_CANARY) { | 111 if (channel == chrome::VersionInfo::CHANNEL_CANARY) { |
109 shortcut_info.title = | 112 shortcut_info.title = |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 Profile* profile, const extensions::Extension* extension, int event_flags) { | 264 Profile* profile, const extensions::Extension* extension, int event_flags) { |
262 LaunchApp(profile, extension, event_flags); | 265 LaunchApp(profile, extension, event_flags); |
263 } | 266 } |
264 | 267 |
265 void AppListControllerDelegateCocoa::LaunchApp( | 268 void AppListControllerDelegateCocoa::LaunchApp( |
266 Profile* profile, const extensions::Extension* extension, int event_flags) { | 269 Profile* profile, const extensions::Extension* extension, int event_flags) { |
267 chrome::OpenApplication(chrome::AppLaunchParams( | 270 chrome::OpenApplication(chrome::AppLaunchParams( |
268 profile, extension, NEW_FOREGROUND_TAB)); | 271 profile, extension, NEW_FOREGROUND_TAB)); |
269 } | 272 } |
270 | 273 |
274 void AppListControllerDelegateCocoa::ShowForProfileByPath( | |
275 const base::FilePath& profile_path) { | |
276 AppListService* service = AppListServiceMac::GetInstance(); | |
277 service->SetProfilePath(profile_path); | |
278 service->Show(); | |
279 } | |
280 | |
271 enum DockLocation { | 281 enum DockLocation { |
272 DockLocationOtherDisplay, | 282 DockLocationOtherDisplay, |
273 DockLocationBottom, | 283 DockLocationBottom, |
274 DockLocationLeft, | 284 DockLocationLeft, |
275 DockLocationRight, | 285 DockLocationRight, |
276 }; | 286 }; |
277 | 287 |
278 DockLocation DockLocationInDisplay(const gfx::Display& display) { | 288 DockLocation DockLocationInDisplay(const gfx::Display& display) { |
279 // Assume the dock occupies part of the work area either on the left, right or | 289 // Assume the dock occupies part of the work area either on the left, right or |
280 // bottom of the display. Note in the autohide case, it is always 4 pixels. | 290 // bottom of the display. Note in the autohide case, it is always 4 pixels. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 | 442 |
433 init_called = true; | 443 init_called = true; |
434 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, | 444 apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, |
435 AppListServiceMac::GetInstance()); | 445 AppListServiceMac::GetInstance()); |
436 } | 446 } |
437 | 447 |
438 void AppListServiceMac::CreateForProfile(Profile* requested_profile) { | 448 void AppListServiceMac::CreateForProfile(Profile* requested_profile) { |
439 if (profile() == requested_profile) | 449 if (profile() == requested_profile) |
440 return; | 450 return; |
441 | 451 |
442 // The Objective C objects might be released at some unknown point in the | 452 // The Objective C objects might be released at some unknown point in the |
tapted
2013/09/13 23:12:17
I think here, just do
if (window_controller_) {
calamity
2013/09/16 19:45:26
Done.
| |
443 // future, so explicitly clear references to C++ objects. | 453 // future, so explicitly clear references to C++ objects. |
444 [[window_controller_ appListViewController] | 454 [[window_controller_ appListViewController] |
445 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()]; | 455 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()]; |
446 | 456 |
447 SetProfile(requested_profile); | 457 SetProfile(requested_profile); |
448 scoped_ptr<app_list::AppListViewDelegate> delegate( | 458 scoped_ptr<app_list::AppListViewDelegate> delegate( |
449 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile())); | 459 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile())); |
450 window_controller_.reset([[AppListWindowController alloc] init]); | 460 window_controller_.reset([[AppListWindowController alloc] init]); |
451 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; | 461 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; |
452 } | 462 } |
453 | 463 |
454 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { | 464 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { |
455 if (requested_profile->IsManaged()) | 465 if (requested_profile->IsManaged()) |
456 return; | 466 return; |
457 | 467 |
458 InvalidatePendingProfileLoads(); | 468 InvalidatePendingProfileLoads(); |
459 | 469 |
460 if (IsAppListVisible() && (requested_profile == profile())) { | 470 if (IsAppListVisible() && (requested_profile == profile())) { |
461 ShowWindowNearDock(); | 471 ShowWindowNearDock(); |
462 return; | 472 return; |
463 } | 473 } |
464 | 474 |
465 SetProfilePath(requested_profile->GetPath()); | 475 SetProfilePath(requested_profile->GetPath()); |
476 if (!window_controller_) { | |
477 DismissAppList(); | |
tapted
2013/09/13 23:12:17
this will always be a no-op with the condition abo
calamity
2013/09/16 19:45:26
Removed.
| |
478 CreateForProfile(requested_profile); | |
479 } else if (requested_profile != profile()) { | |
480 // Clear the search box text when switching profiles. | |
481 [[window_controller_ appListViewController] searchBoxModel] | |
482 ->SetText(base::string16()); | |
466 | 483 |
467 DismissAppList(); | 484 SetProfile(requested_profile); |
468 CreateForProfile(requested_profile); | 485 scoped_ptr<app_list::AppListViewDelegate> delegate( |
469 ShowWindowNearDock(); | 486 new AppListViewDelegate(new AppListControllerDelegateCocoa(), |
487 requested_profile)); | |
488 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; | |
489 } | |
490 if (!IsAppListVisible()) | |
tapted
2013/09/13 23:12:17
I think this check can just go at the start of Sho
calamity
2013/09/16 19:45:26
Done.
| |
491 ShowWindowNearDock(); | |
470 } | 492 } |
471 | 493 |
472 void AppListServiceMac::DismissAppList() { | 494 void AppListServiceMac::DismissAppList() { |
473 if (!IsAppListVisible()) | 495 if (!IsAppListVisible()) |
474 return; | 496 return; |
475 | 497 |
476 // If the app list is currently the main window, it will activate the next | 498 // If the app list is currently the main window, it will activate the next |
477 // Chrome window when dismissed. But if a different application was active | 499 // Chrome window when dismissed. But if a different application was active |
478 // when the app list was shown, activate that instead. | 500 // when the app list was shown, activate that instead. |
479 base::scoped_nsobject<NSRunningApplication> prior_app; | 501 base::scoped_nsobject<NSRunningApplication> prior_app; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 [animation_ startAnimation]; | 626 [animation_ startAnimation]; |
605 } | 627 } |
606 | 628 |
607 - (void)animationDidEnd:(NSAnimation*)animation { | 629 - (void)animationDidEnd:(NSAnimation*)animation { |
608 [window_ close]; | 630 [window_ close]; |
609 window_.reset(); | 631 window_.reset(); |
610 animation_.reset(); | 632 animation_.reset(); |
611 } | 633 } |
612 | 634 |
613 @end | 635 @end |
OLD | NEW |