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 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/fullscreen.h" |
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_info_util.h" | 16 #include "chrome/browser/profiles/profile_info_util.h" |
16 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 17 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_window_state.h" | 19 #include "chrome/browser/ui/browser_window_state.h" |
19 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" | 20 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
20 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 21 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
21 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 22 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
22 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 23 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 maxY + badgeYOffset); | 312 maxY + badgeYOffset); |
312 [avatarButton setFrameOrigin:origin]; | 313 [avatarButton setFrameOrigin:origin]; |
313 [avatarButton setHidden:NO]; // Make sure it's shown. | 314 [avatarButton setHidden:NO]; // Make sure it's shown. |
314 } | 315 } |
315 | 316 |
316 // Calculate the right indentation. The default indentation built into the | 317 // Calculate the right indentation. The default indentation built into the |
317 // tabstrip leaves enough room for the fullscreen button or presentation mode | 318 // tabstrip leaves enough room for the fullscreen button or presentation mode |
318 // toggle button on Lion. On non-Lion systems, the right indent needs to be | 319 // toggle button on Lion. On non-Lion systems, the right indent needs to be |
319 // adjusted to make room for the new tab button when an avatar is present. | 320 // adjusted to make room for the new tab button when an avatar is present. |
320 CGFloat rightIndent = 0; | 321 CGFloat rightIndent = 0; |
321 if (base::mac::IsOSLionOrLater()) { | 322 if (base::mac::IsOSLionOrLater() && |
| 323 [[self window] isKindOfClass:[FramedBrowserWindow class]]) { |
322 FramedBrowserWindow* window = | 324 FramedBrowserWindow* window = |
323 static_cast<FramedBrowserWindow*>([self window]); | 325 static_cast<FramedBrowserWindow*>([self window]); |
324 DCHECK([window isKindOfClass:[FramedBrowserWindow class]]); | |
325 rightIndent += -[window fullScreenButtonOriginAdjustment].x; | 326 rightIndent += -[window fullScreenButtonOriginAdjustment].x; |
326 } else if ([self shouldShowAvatar]) { | 327 } else if ([self shouldShowAvatar]) { |
327 rightIndent += kAvatarTabStripShrink; | 328 rightIndent += kAvatarTabStripShrink; |
328 NSButton* labelButton = [avatarButtonController_ labelButtonView]; | 329 NSButton* labelButton = [avatarButtonController_ labelButtonView]; |
329 if (labelButton) | 330 if (labelButton) |
330 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset; | 331 rightIndent += NSWidth([labelButton frame]) + kAvatarRightOffset; |
331 } | 332 } |
332 [tabStripController_ setRightIndentForControls:rightIndent]; | 333 [tabStripController_ setRightIndentForControls:rightIndent]; |
333 | 334 |
334 // Go ahead and layout the tabs. | 335 // Go ahead and layout the tabs. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 NSRect bookmarkFrame = [[bookmarkBarController_ view] frame]; | 486 NSRect bookmarkFrame = [[bookmarkBarController_ view] frame]; |
486 bookmarkFrame.size.height = bookmarkFrame.size.height - deltaH; | 487 bookmarkFrame.size.height = bookmarkFrame.size.height - deltaH; |
487 [[toolbarController_ view] setFrame:toolbarFrame]; | 488 [[toolbarController_ view] setFrame:toolbarFrame]; |
488 [[bookmarkBarController_ view] setFrame:bookmarkFrame]; | 489 [[bookmarkBarController_ view] setFrame:bookmarkFrame]; |
489 [self layoutSubviews]; | 490 [self layoutSubviews]; |
490 } | 491 } |
491 | 492 |
492 // Fullscreen and presentation mode methods | 493 // Fullscreen and presentation mode methods |
493 | 494 |
494 - (BOOL)shouldShowPresentationModeToggle { | 495 - (BOOL)shouldShowPresentationModeToggle { |
495 return base::mac::IsOSLionOrLater() && [self isFullscreen]; | 496 return chrome::mac::SupportsSystemFullscreen() && [self isFullscreen]; |
496 } | 497 } |
497 | 498 |
498 - (void)moveViewsForFullscreenForSnowLeopard:(BOOL)fullscreen | 499 - (void)moveViewsForFullscreenForSnowLeopard:(BOOL)fullscreen |
499 regularWindow:(NSWindow*)regularWindow | 500 regularWindow:(NSWindow*)regularWindow |
500 fullscreenWindow:(NSWindow*)fullscreenWindow { | 501 fullscreenWindow:(NSWindow*)fullscreenWindow { |
501 // This method is only for Snow Leopard. | 502 // This method is only for systems without fullscreen support. |
502 DCHECK(base::mac::IsOSSnowLeopard()); | 503 DCHECK(!chrome::mac::SupportsSystemFullscreen()); |
503 | 504 |
504 NSWindow* sourceWindow = fullscreen ? regularWindow : fullscreenWindow; | 505 NSWindow* sourceWindow = fullscreen ? regularWindow : fullscreenWindow; |
505 NSWindow* destWindow = fullscreen ? fullscreenWindow : regularWindow; | 506 NSWindow* destWindow = fullscreen ? fullscreenWindow : regularWindow; |
506 | 507 |
507 // Close the bookmark bubble, if it's open. Use |-ok:| instead of |-cancel:| | 508 // Close the bookmark bubble, if it's open. Use |-ok:| instead of |-cancel:| |
508 // or |-close| because that matches the behavior when the bubble loses key | 509 // or |-close| because that matches the behavior when the bubble loses key |
509 // status. | 510 // status. |
510 [bookmarkBubbleController_ ok:self]; | 511 [bookmarkBubbleController_ ok:self]; |
511 | 512 |
512 // Save the current first responder so we can restore after views are moved. | 513 // Save the current first responder so we can restore after views are moved. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } else { | 607 } else { |
607 [presentationModeController_ exitPresentationMode]; | 608 [presentationModeController_ exitPresentationMode]; |
608 presentationModeController_.reset(); | 609 presentationModeController_.reset(); |
609 } | 610 } |
610 | 611 |
611 [self adjustUIForPresentationMode:presentationMode]; | 612 [self adjustUIForPresentationMode:presentationMode]; |
612 [self layoutSubviews]; | 613 [self layoutSubviews]; |
613 } | 614 } |
614 | 615 |
615 - (void)enterFullscreenForSnowLeopard { | 616 - (void)enterFullscreenForSnowLeopard { |
616 DCHECK(base::mac::IsOSSnowLeopard()); | 617 // TODO(rohitrao): This method is misnamed now, since there is a flag that |
| 618 // enables 10.6-style fullscreen on newer OSes. |
| 619 DCHECK(!chrome::mac::SupportsSystemFullscreen()); |
617 | 620 |
618 // Fade to black. | 621 // Fade to black. |
619 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; | 622 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; |
620 Boolean didFadeOut = NO; | 623 Boolean didFadeOut = NO; |
621 CGDisplayFadeReservationToken token; | 624 CGDisplayFadeReservationToken token; |
622 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) | 625 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) |
623 == kCGErrorSuccess) { | 626 == kCGErrorSuccess) { |
624 didFadeOut = YES; | 627 didFadeOut = YES; |
625 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, | 628 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, |
626 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); | 629 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); |
(...skipping 16 matching lines...) Expand all Loading... |
643 | 646 |
644 // Fade back in. | 647 // Fade back in. |
645 if (didFadeOut) { | 648 if (didFadeOut) { |
646 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, | 649 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, |
647 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); | 650 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); |
648 CGReleaseDisplayFadeReservation(token); | 651 CGReleaseDisplayFadeReservation(token); |
649 } | 652 } |
650 } | 653 } |
651 | 654 |
652 - (void)exitFullscreenForSnowLeopard { | 655 - (void)exitFullscreenForSnowLeopard { |
653 DCHECK(base::mac::IsOSSnowLeopard()); | 656 // TODO(rohitrao): This method is misnamed now, since there is a flag that |
| 657 // enables 10.6-style fullscreen on newer OSes. |
| 658 DCHECK(!chrome::mac::SupportsSystemFullscreen()); |
654 | 659 |
655 // Fade to black. | 660 // Fade to black. |
656 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; | 661 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; |
657 Boolean didFadeOut = NO; | 662 Boolean didFadeOut = NO; |
658 CGDisplayFadeReservationToken token; | 663 CGDisplayFadeReservationToken token; |
659 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) | 664 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) |
660 == kCGErrorSuccess) { | 665 == kCGErrorSuccess) { |
661 didFadeOut = YES; | 666 didFadeOut = YES; |
662 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, | 667 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, |
663 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); | 668 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 777 |
773 NSWindow* window = [self window]; | 778 NSWindow* window = [self window]; |
774 savedRegularWindowFrame_ = [window frame]; | 779 savedRegularWindowFrame_ = [window frame]; |
775 BOOL mode = enteringPresentationMode_ || | 780 BOOL mode = enteringPresentationMode_ || |
776 browser_->fullscreen_controller()->IsFullscreenForTabOrPending(); | 781 browser_->fullscreen_controller()->IsFullscreenForTabOrPending(); |
777 enteringFullscreen_ = YES; | 782 enteringFullscreen_ = YES; |
778 [self setPresentationModeInternal:mode forceDropdown:NO]; | 783 [self setPresentationModeInternal:mode forceDropdown:NO]; |
779 } | 784 } |
780 | 785 |
781 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 786 - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
782 if (base::mac::IsOSLionOrLater()) | 787 if (chrome::mac::SupportsSystemFullscreen()) |
783 [self deregisterForContentViewResizeNotifications]; | 788 [self deregisterForContentViewResizeNotifications]; |
784 enteringFullscreen_ = NO; | 789 enteringFullscreen_ = NO; |
785 enteringPresentationMode_ = NO; | 790 enteringPresentationMode_ = NO; |
786 [self showFullscreenExitBubbleIfNecessary]; | 791 [self showFullscreenExitBubbleIfNecessary]; |
787 browser_->WindowFullscreenStateChanged(); | 792 browser_->WindowFullscreenStateChanged(); |
788 } | 793 } |
789 | 794 |
790 - (void)windowWillExitFullScreen:(NSNotification*)notification { | 795 - (void)windowWillExitFullScreen:(NSNotification*)notification { |
791 if (base::mac::IsOSLionOrLater()) | 796 if (chrome::mac::SupportsSystemFullscreen()) |
792 [self registerForContentViewResizeNotifications]; | 797 [self registerForContentViewResizeNotifications]; |
793 [self destroyFullscreenExitBubbleIfNecessary]; | 798 [self destroyFullscreenExitBubbleIfNecessary]; |
794 [self setPresentationModeInternal:NO forceDropdown:NO]; | 799 [self setPresentationModeInternal:NO forceDropdown:NO]; |
795 } | 800 } |
796 | 801 |
797 - (void)windowDidExitFullScreen:(NSNotification*)notification { | 802 - (void)windowDidExitFullScreen:(NSNotification*)notification { |
798 if (base::mac::IsOSLionOrLater()) | 803 if (chrome::mac::SupportsSystemFullscreen()) |
799 [self deregisterForContentViewResizeNotifications]; | 804 [self deregisterForContentViewResizeNotifications]; |
800 browser_->WindowFullscreenStateChanged(); | 805 browser_->WindowFullscreenStateChanged(); |
801 } | 806 } |
802 | 807 |
803 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { | 808 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { |
804 [self deregisterForContentViewResizeNotifications]; | 809 [self deregisterForContentViewResizeNotifications]; |
805 enteringFullscreen_ = NO; | 810 enteringFullscreen_ = NO; |
806 [self setPresentationModeInternal:NO forceDropdown:NO]; | 811 [self setPresentationModeInternal:NO forceDropdown:NO]; |
807 | 812 |
808 // Force a relayout to try and get the window back into a reasonable state. | 813 // Force a relayout to try and get the window back into a reasonable state. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 return browser_window_controller::kCoreAnimationEnabledLazy; | 967 return browser_window_controller::kCoreAnimationEnabledLazy; |
963 } | 968 } |
964 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 969 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
965 switches::kUseCoreAnimation) == "disabled") { | 970 switches::kUseCoreAnimation) == "disabled") { |
966 return browser_window_controller::kCoreAnimationDisabled; | 971 return browser_window_controller::kCoreAnimationDisabled; |
967 } | 972 } |
968 return browser_window_controller::kCoreAnimationEnabledAlways; | 973 return browser_window_controller::kCoreAnimationEnabledAlways; |
969 } | 974 } |
970 | 975 |
971 @end // @implementation BrowserWindowController(Private) | 976 @end // @implementation BrowserWindowController(Private) |
OLD | NEW |