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 SetProfile(requested_profile); |
443 // future, so explicitly clear references to C++ objects. | |
444 [[window_controller_ appListViewController] | |
445 setDelegate:scoped_ptr<app_list::AppListViewDelegate>()]; | |
446 | 453 |
447 SetProfile(requested_profile); | 454 if (window_controller_) { |
455 // Clear the search box. | |
456 [[window_controller_ appListViewController] searchBoxModel] | |
457 ->SetText(base::string16()); | |
458 } else { | |
459 window_controller_.reset([[AppListWindowController alloc] init]); | |
460 } | |
461 | |
448 scoped_ptr<app_list::AppListViewDelegate> delegate( | 462 scoped_ptr<app_list::AppListViewDelegate> delegate( |
449 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile())); | 463 new AppListViewDelegate(new AppListControllerDelegateCocoa(), profile())); |
450 window_controller_.reset([[AppListWindowController alloc] init]); | |
451 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; | 464 [[window_controller_ appListViewController] setDelegate:delegate.Pass()]; |
452 } | 465 } |
453 | 466 |
454 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { | 467 void AppListServiceMac::ShowForProfile(Profile* requested_profile) { |
455 if (requested_profile->IsManaged()) | 468 if (requested_profile->IsManaged()) |
456 return; | 469 return; |
457 | 470 |
458 InvalidatePendingProfileLoads(); | 471 InvalidatePendingProfileLoads(); |
459 | 472 |
460 if (IsAppListVisible() && (requested_profile == profile())) { | 473 if (requested_profile == profile()) { |
461 ShowWindowNearDock(); | 474 ShowWindowNearDock(); |
462 return; | 475 return; |
463 } | 476 } |
464 | 477 |
465 SetProfilePath(requested_profile->GetPath()); | 478 SetProfilePath(requested_profile->GetPath()); |
466 | |
467 DismissAppList(); | |
468 CreateForProfile(requested_profile); | 479 CreateForProfile(requested_profile); |
469 ShowWindowNearDock(); | 480 ShowWindowNearDock(); |
470 } | 481 } |
471 | 482 |
472 void AppListServiceMac::DismissAppList() { | 483 void AppListServiceMac::DismissAppList() { |
473 if (!IsAppListVisible()) | 484 if (!IsAppListVisible()) |
474 return; | 485 return; |
475 | 486 |
476 // If the app list is currently the main window, it will activate the next | 487 // 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 | 488 // Chrome window when dismissed. But if a different application was active |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 | 538 |
528 void AppListServiceMac::OnShimFocus(apps::AppShimHandler::Host* host, | 539 void AppListServiceMac::OnShimFocus(apps::AppShimHandler::Host* host, |
529 apps::AppShimFocusType focus_type) {} | 540 apps::AppShimFocusType focus_type) {} |
530 | 541 |
531 void AppListServiceMac::OnShimSetHidden(apps::AppShimHandler::Host* host, | 542 void AppListServiceMac::OnShimSetHidden(apps::AppShimHandler::Host* host, |
532 bool hidden) {} | 543 bool hidden) {} |
533 | 544 |
534 void AppListServiceMac::OnShimQuit(apps::AppShimHandler::Host* host) {} | 545 void AppListServiceMac::OnShimQuit(apps::AppShimHandler::Host* host) {} |
535 | 546 |
536 void AppListServiceMac::ShowWindowNearDock() { | 547 void AppListServiceMac::ShowWindowNearDock() { |
548 if (IsAppListVisible()) | |
549 return; | |
tapted
2013/09/16 20:46:44
nit: blank line after early return
calamity
2013/09/17 00:09:26
Done.
| |
537 NSWindow* window = GetAppListWindow(); | 550 NSWindow* window = GetAppListWindow(); |
538 DCHECK(window); | 551 DCHECK(window); |
539 NSPoint target_origin; | 552 NSPoint target_origin; |
540 GetAppListWindowOrigins(window, &target_origin, &last_start_origin_); | 553 GetAppListWindowOrigins(window, &target_origin, &last_start_origin_); |
541 [window setFrameOrigin:last_start_origin_]; | 554 [window setFrameOrigin:last_start_origin_]; |
542 | 555 |
543 // Before activating, see if an application other than Chrome is currently the | 556 // Before activating, see if an application other than Chrome is currently the |
544 // active application, so that it can be reactivated when dismissing. | 557 // active application, so that it can be reactivated when dismissing. |
545 previously_active_application_.reset([ActiveApplicationNotChrome() retain]); | 558 previously_active_application_.reset([ActiveApplicationNotChrome() retain]); |
546 | 559 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 [animation_ startAnimation]; | 617 [animation_ startAnimation]; |
605 } | 618 } |
606 | 619 |
607 - (void)animationDidEnd:(NSAnimation*)animation { | 620 - (void)animationDidEnd:(NSAnimation*)animation { |
608 [window_ close]; | 621 [window_ close]; |
609 window_.reset(); | 622 window_.reset(); |
610 animation_.reset(); | 623 animation_.reset(); |
611 } | 624 } |
612 | 625 |
613 @end | 626 @end |
OLD | NEW |