Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_cocoa.mm

Issue 1650483002: Refactor: Untangle Mac's ExclusiveAccessContext from BrowserWindow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self nits, More robust interface, fix other random stuff Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 10 matching lines...) Expand all
41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 40 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
42 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" 41 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
43 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" 42 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h"
44 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h" 43 #import "chrome/browser/ui/cocoa/profiles/avatar_menu_bubble_controller.h"
45 #include "chrome/browser/ui/cocoa/restart_browser.h" 44 #include "chrome/browser/ui/cocoa/restart_browser.h"
46 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" 45 #include "chrome/browser/ui/cocoa/status_bubble_mac.h"
47 #include "chrome/browser/ui/cocoa/task_manager_mac.h" 46 #include "chrome/browser/ui/cocoa/task_manager_mac.h"
48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 47 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
49 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" 48 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h"
50 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h" 49 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h"
51 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
52 #include "chrome/browser/ui/search/search_model.h" 50 #include "chrome/browser/ui/search/search_model.h"
53 #include "chrome/browser/ui/tabs/tab_strip_model.h" 51 #include "chrome/browser/ui/tabs/tab_strip_model.h"
54 #include "chrome/browser/web_applications/web_app.h" 52 #include "chrome/browser/web_applications/web_app.h"
55 #include "chrome/common/chrome_switches.h" 53 #include "chrome/common/chrome_switches.h"
56 #include "chrome/common/pref_names.h" 54 #include "chrome/common/pref_names.h"
57 #include "chrome/grit/generated_resources.h" 55 #include "chrome/grit/generated_resources.h"
58 #include "components/bookmarks/common/bookmark_pref_names.h" 56 #include "components/bookmarks/common/bookmark_pref_names.h"
59 #include "components/translate/core/browser/language_state.h" 57 #include "components/translate/core/browser/language_state.h"
60 #include "content/public/browser/native_web_keyboard_event.h" 58 #include "content/public/browser/native_web_keyboard_event.h"
61 #include "content/public/browser/notification_details.h" 59 #include "content/public/browser/notification_details.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 [window() orderFront:controller_]; 199 [window() orderFront:controller_];
202 } 200 }
203 201
204 void BrowserWindowCocoa::Hide() { 202 void BrowserWindowCocoa::Hide() {
205 [window() orderOut:controller_]; 203 [window() orderOut:controller_];
206 } 204 }
207 205
208 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { 206 void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
209 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; 207 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds];
210 208
211 ExitFullscreen(); 209 [controller_ exitAnyFullscreen];
spqchan 2016/02/01 19:55:04 It's probably safer to just use [controller_ exclu
tapted 2016/02/02 11:57:06 Yah, good idea. Done.
tapted 2016/02/02 21:58:43 (note with this change I also needed to move the i
212 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, 210 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0,
213 real_bounds.width(), 211 real_bounds.width(),
214 real_bounds.height()); 212 real_bounds.height());
215 // Flip coordinates based on the primary screen. 213 // Flip coordinates based on the primary screen.
216 NSScreen* screen = [[NSScreen screens] firstObject]; 214 NSScreen* screen = [[NSScreen screens] firstObject];
217 cocoa_bounds.origin.y = 215 cocoa_bounds.origin.y =
218 NSHeight([screen frame]) - real_bounds.height() - real_bounds.y(); 216 NSHeight([screen frame]) - real_bounds.height() - real_bounds.y();
219 217
220 [window() setFrame:cocoa_bounds display:YES]; 218 [window() setFrame:cocoa_bounds display:YES];
221 } 219 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 [window() miniaturize:controller_]; 401 [window() miniaturize:controller_];
404 } 402 }
405 403
406 void BrowserWindowCocoa::Restore() { 404 void BrowserWindowCocoa::Restore() {
407 if (IsMaximized()) 405 if (IsMaximized())
408 [window() zoom:controller_]; // Toggles zoom mode. 406 [window() zoom:controller_]; // Toggles zoom mode.
409 else if (IsMinimized()) 407 else if (IsMinimized())
410 [window() deminiaturize:controller_]; 408 [window() deminiaturize:controller_];
411 } 409 }
412 410
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 { 411 bool BrowserWindowCocoa::ShouldHideUIForFullscreen() const {
443 // On Mac, fullscreen mode has most normal things (in a slide-down panel). 412 // On Mac, fullscreen mode has most normal things (in a slide-down panel).
444 return false; 413 return false;
445 } 414 }
446 415
447 bool BrowserWindowCocoa::IsFullscreen() const { 416 bool BrowserWindowCocoa::IsFullscreen() const {
448 return [controller_ isInAnyFullscreenMode]; 417 return [controller_ isInAnyFullscreenMode];
449 } 418 }
450 419
451 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { 420 bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
452 return false; 421 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 } 422 }
474 423
475 void BrowserWindowCocoa::ConfirmAddSearchProvider( 424 void BrowserWindowCocoa::ConfirmAddSearchProvider(
476 TemplateURL* template_url, 425 TemplateURL* template_url,
477 Profile* profile) { 426 Profile* profile) {
478 // The controller will release itself when the window closes. 427 // The controller will release itself when the window closes.
479 EditSearchEngineCocoaController* editor = 428 EditSearchEngineCocoaController* editor =
480 [[EditSearchEngineCocoaController alloc] initWithProfile:profile 429 [[EditSearchEngineCocoaController alloc] initWithProfile:profile
481 delegate:NULL 430 delegate:NULL
482 templateURL:template_url]; 431 templateURL:template_url];
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 return 40; 822 return 40;
874 } 823 }
875 824
876 void BrowserWindowCocoa::ExecuteExtensionCommand( 825 void BrowserWindowCocoa::ExecuteExtensionCommand(
877 const extensions::Extension* extension, 826 const extensions::Extension* extension,
878 const extensions::Command& command) { 827 const extensions::Command& command) {
879 [cocoa_controller() executeExtensionCommand:extension->id() command:command]; 828 [cocoa_controller() executeExtensionCommand:extension->id() command:command];
880 } 829 }
881 830
882 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() { 831 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() {
883 return this; 832 return [controller_ exclusiveAccessContext];
884 } 833 }
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698