| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/download/download_shelf.h" | 17 #include "chrome/browser/download/download_shelf.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" |
| 20 #include "chrome/browser/fullscreen.h" | |
| 21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/shell_integration.h" | 21 #include "chrome/browser/shell_integration.h" |
| 23 #include "chrome/browser/signin/chrome_signin_helper.h" | 22 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 24 #include "chrome/browser/translate/chrome_translate_client.h" | 23 #include "chrome/browser/translate/chrome_translate_client.h" |
| 25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_command_controller.h" | 25 #include "chrome/browser/ui/browser_command_controller.h" |
| 27 #include "chrome/browser/ui/browser_commands_mac.h" | 26 #include "chrome/browser/ui/browser_commands_mac.h" |
| 28 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 29 #include "chrome/browser/ui/browser_window_state.h" | 28 #include "chrome/browser/ui/browser_window_state.h" |
| 30 #import "chrome/browser/ui/cocoa/autofill/save_card_bubble_view_bridge.h" | 29 #import "chrome/browser/ui/cocoa/autofill/save_card_bubble_view_bridge.h" |
| 31 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" | 30 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" |
| 31 #import "chrome/browser/ui/cocoa/browser/exclusive_access_controller_views.h" |
| 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 33 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 33 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 34 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 34 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 35 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 35 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 36 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 36 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
| 37 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 37 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
| 38 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 38 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| 39 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 39 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 40 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 40 #include "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 42 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" | 42 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
| 43 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" | 43 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" |
| 44 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" | 44 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" |
| 45 #include "chrome/browser/ui/cocoa/restart_browser.h" | 45 #include "chrome/browser/ui/cocoa/restart_browser.h" |
| 46 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" | 46 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 47 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 47 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
| 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 49 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" | 49 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" |
| 50 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro
ller.h" | 50 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro
ller.h" |
| 51 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 51 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 52 #include "chrome/browser/ui/search/search_model.h" | 52 #include "chrome/browser/ui/search/search_model.h" |
| 53 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 53 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 54 #include "chrome/browser/web_applications/web_app.h" | 54 #include "chrome/browser/web_applications/web_app.h" |
| 55 #include "chrome/common/chrome_switches.h" | 55 #include "chrome/common/chrome_switches.h" |
| 56 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
| 57 #include "chrome/grit/generated_resources.h" | 57 #include "chrome/grit/generated_resources.h" |
| 58 #include "components/bookmarks/common/bookmark_pref_names.h" | 58 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 59 #include "components/translate/core/browser/language_state.h" | 59 #include "components/translate/core/browser/language_state.h" |
| 60 #include "content/public/browser/native_web_keyboard_event.h" | 60 #include "content/public/browser/native_web_keyboard_event.h" |
| 61 #include "content/public/browser/notification_details.h" | 61 #include "content/public/browser/notification_details.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 [window() orderFront:controller_]; | 201 [window() orderFront:controller_]; |
| 202 } | 202 } |
| 203 | 203 |
| 204 void BrowserWindowCocoa::Hide() { | 204 void BrowserWindowCocoa::Hide() { |
| 205 [window() orderOut:controller_]; | 205 [window() orderOut:controller_]; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { | 208 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
| 209 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; | 209 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; |
| 210 | 210 |
| 211 ExitFullscreen(); | 211 [controller_ exclusiveAccessContext]->ExitFullscreen(); |
| 212 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, | 212 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, |
| 213 real_bounds.width(), | 213 real_bounds.width(), |
| 214 real_bounds.height()); | 214 real_bounds.height()); |
| 215 // Flip coordinates based on the primary screen. | 215 // Flip coordinates based on the primary screen. |
| 216 NSScreen* screen = [[NSScreen screens] firstObject]; | 216 NSScreen* screen = [[NSScreen screens] firstObject]; |
| 217 cocoa_bounds.origin.y = | 217 cocoa_bounds.origin.y = |
| 218 NSHeight([screen frame]) - real_bounds.height() - real_bounds.y(); | 218 NSHeight([screen frame]) - real_bounds.height() - real_bounds.y(); |
| 219 | 219 |
| 220 [window() setFrame:cocoa_bounds display:YES]; | 220 [window() setFrame:cocoa_bounds display:YES]; |
| 221 } | 221 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 [window() miniaturize:controller_]; | 403 [window() miniaturize:controller_]; |
| 404 } | 404 } |
| 405 | 405 |
| 406 void BrowserWindowCocoa::Restore() { | 406 void BrowserWindowCocoa::Restore() { |
| 407 if (IsMaximized()) | 407 if (IsMaximized()) |
| 408 [window() zoom:controller_]; // Toggles zoom mode. | 408 [window() zoom:controller_]; // Toggles zoom mode. |
| 409 else if (IsMinimized()) | 409 else if (IsMinimized()) |
| 410 [window() deminiaturize:controller_]; | 410 [window() deminiaturize:controller_]; |
| 411 } | 411 } |
| 412 | 412 |
| 413 // See browser_window_controller.h for a detailed explanation of the logic in | |
| 414 // this method. | |
| 415 void BrowserWindowCocoa::EnterFullscreen(const GURL& url, | |
| 416 ExclusiveAccessBubbleType bubble_type, | |
| 417 bool with_toolbar) { | |
| 418 if (browser_->exclusive_access_manager() | |
| 419 ->fullscreen_controller() | |
| 420 ->IsWindowFullscreenForTabOrPending()) | |
| 421 [controller_ enterWebContentFullscreenForURL:url bubbleType:bubble_type]; | |
| 422 else if (!url.is_empty()) | |
| 423 [controller_ enterExtensionFullscreenForURL:url bubbleType:bubble_type]; | |
| 424 else | |
| 425 [controller_ enterBrowserFullscreenWithToolbar:with_toolbar]; | |
| 426 } | |
| 427 | |
| 428 void BrowserWindowCocoa::ExitFullscreen() { | |
| 429 [controller_ exitAnyFullscreen]; | |
| 430 } | |
| 431 | |
| 432 void BrowserWindowCocoa::UpdateExclusiveAccessExitBubbleContent( | |
| 433 const GURL& url, | |
| 434 ExclusiveAccessBubbleType bubble_type) { | |
| 435 [controller_ updateFullscreenExitBubbleURL:url bubbleType:bubble_type]; | |
| 436 } | |
| 437 | |
| 438 void BrowserWindowCocoa::OnExclusiveAccessUserInput() { | |
| 439 // TODO(mgiuca): Route this signal to the exclusive access bubble on Mac. | |
| 440 } | |
| 441 | |
| 442 bool BrowserWindowCocoa::ShouldHideUIForFullscreen() const { | 413 bool BrowserWindowCocoa::ShouldHideUIForFullscreen() const { |
| 443 // On Mac, fullscreen mode has most normal things (in a slide-down panel). | 414 // On Mac, fullscreen mode has most normal things (in a slide-down panel). |
| 444 return false; | 415 return false; |
| 445 } | 416 } |
| 446 | 417 |
| 447 bool BrowserWindowCocoa::IsFullscreen() const { | 418 bool BrowserWindowCocoa::IsFullscreen() const { |
| 448 return [controller_ isInAnyFullscreenMode]; | 419 return [controller_ isInAnyFullscreenMode]; |
| 449 } | 420 } |
| 450 | 421 |
| 451 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { | 422 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { |
| 452 return false; | 423 return false; // Currently only called from toolkit-views website_settings. |
| 453 } | |
| 454 | |
| 455 bool BrowserWindowCocoa::SupportsFullscreenWithToolbar() const { | |
| 456 return chrome::mac::SupportsSystemFullscreen(); | |
| 457 } | |
| 458 | |
| 459 void BrowserWindowCocoa::UpdateFullscreenWithToolbar(bool with_toolbar) { | |
| 460 [controller_ updateFullscreenWithToolbar:with_toolbar]; | |
| 461 } | |
| 462 | |
| 463 void BrowserWindowCocoa::ToggleFullscreenToolbar() { | |
| 464 [controller_ toggleFullscreenToolbar]; | |
| 465 } | |
| 466 | |
| 467 bool BrowserWindowCocoa::IsFullscreenWithToolbar() const { | |
| 468 return IsFullscreen() && ![controller_ inPresentationMode]; | |
| 469 } | |
| 470 | |
| 471 bool BrowserWindowCocoa::ShouldHideFullscreenToolbar() const { | |
| 472 return [controller_ shouldHideFullscreenToolbar]; | |
| 473 } | 424 } |
| 474 | 425 |
| 475 void BrowserWindowCocoa::ConfirmAddSearchProvider( | 426 void BrowserWindowCocoa::ConfirmAddSearchProvider( |
| 476 TemplateURL* template_url, | 427 TemplateURL* template_url, |
| 477 Profile* profile) { | 428 Profile* profile) { |
| 478 // The controller will release itself when the window closes. | 429 // The controller will release itself when the window closes. |
| 479 EditSearchEngineCocoaController* editor = | 430 EditSearchEngineCocoaController* editor = |
| 480 [[EditSearchEngineCocoaController alloc] initWithProfile:profile | 431 [[EditSearchEngineCocoaController alloc] initWithProfile:profile |
| 481 delegate:NULL | 432 delegate:NULL |
| 482 templateURL:template_url]; | 433 templateURL:template_url]; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 return 40; | 824 return 40; |
| 874 } | 825 } |
| 875 | 826 |
| 876 void BrowserWindowCocoa::ExecuteExtensionCommand( | 827 void BrowserWindowCocoa::ExecuteExtensionCommand( |
| 877 const extensions::Extension* extension, | 828 const extensions::Extension* extension, |
| 878 const extensions::Command& command) { | 829 const extensions::Command& command) { |
| 879 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; | 830 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; |
| 880 } | 831 } |
| 881 | 832 |
| 882 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() { | 833 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() { |
| 883 return this; | 834 return [controller_ exclusiveAccessContext]; |
| 884 } | 835 } |
| 885 | |
| 886 Profile* BrowserWindowCocoa::GetProfile() { | |
| 887 return browser_->profile(); | |
| 888 } | |
| 889 | |
| 890 WebContents* BrowserWindowCocoa::GetActiveWebContents() { | |
| 891 return browser_->tab_strip_model()->GetActiveWebContents(); | |
| 892 } | |
| 893 | |
| 894 void BrowserWindowCocoa::UnhideDownloadShelf() { | |
| 895 GetDownloadShelf()->Unhide(); | |
| 896 } | |
| 897 | |
| 898 void BrowserWindowCocoa::HideDownloadShelf() { | |
| 899 GetDownloadShelf()->Hide(); | |
| 900 StatusBubble* statusBubble = GetStatusBubble(); | |
| 901 if (statusBubble) | |
| 902 statusBubble->Hide(); | |
| 903 } | |
| OLD | NEW |