Chromium Code Reviews| 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 #import "base/auto_reset.h" | 9 #import "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 } | 440 } |
| 441 [sourceWindow orderOut:self]; | 441 [sourceWindow orderOut:self]; |
| 442 } | 442 } |
| 443 | 443 |
| 444 - (void)updatePermissionBubbleAnchor { | 444 - (void)updatePermissionBubbleAnchor { |
| 445 PermissionRequestManager* manager = [self permissionRequestManager]; | 445 PermissionRequestManager* manager = [self permissionRequestManager]; |
| 446 if (manager) | 446 if (manager) |
| 447 manager->UpdateAnchorPosition(); | 447 manager->UpdateAnchorPosition(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 - (void)adjustUIForExitingFullscreenAndStopOmniboxSliding { | |
| 451 [fullscreenToolbarController_ exitFullscreenMode]; | |
| 452 fullscreenToolbarController_.reset(); | |
| 453 | |
| 454 // Force the bookmark bar z-order to update. | |
| 455 [[bookmarkBarController_ view] removeFromSuperview]; | |
| 456 [self layoutSubviews]; | |
| 457 } | |
| 458 | |
| 459 - (void)adjustUIForSlidingFullscreenStyle:(FullscreenSlidingStyle)style { | |
| 460 // The UI should only be adjusted in fullscreen mode. | |
| 461 if (![self isInAnyFullscreenMode]) | |
| 462 return; | |
| 463 | |
| 464 if (!fullscreenToolbarController_) { | |
| 465 fullscreenToolbarController_.reset( | |
| 466 [self newFullscreenToolbarControllerWithStyle:style]); | |
| 467 [fullscreenToolbarController_ enterFullscreenMode]; | |
| 468 } else { | |
| 469 fullscreenToolbarController_.get().slidingStyle = style; | |
| 470 } | |
| 471 | |
| 472 if (!floatingBarBackingView_.get() && | |
| 473 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) { | |
| 474 floatingBarBackingView_.reset( | |
| 475 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]); | |
| 476 [floatingBarBackingView_ | |
| 477 setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; | |
| 478 } | |
| 479 | |
| 480 // Force the bookmark bar z-order to update. | |
| 481 [[bookmarkBarController_ view] removeFromSuperview]; | |
| 482 [self layoutSubviews]; | |
| 483 } | |
| 484 | |
| 485 - (FullscreenToolbarController*)newFullscreenToolbarControllerWithStyle: | |
| 486 (FullscreenSlidingStyle)style { | |
| 487 return [[FullscreenToolbarController alloc] initWithBrowserController:self | |
| 488 style:style]; | |
| 489 } | |
| 490 | |
| 491 - (void)enterImmersiveFullscreen { | 450 - (void)enterImmersiveFullscreen { |
| 492 RecordFullscreenWindowLocation([self window]); | 451 RecordFullscreenWindowLocation([self window]); |
| 493 RecordFullscreenStyle(IMMERSIVE_FULLSCREEN); | 452 RecordFullscreenStyle(IMMERSIVE_FULLSCREEN); |
| 494 | 453 |
| 495 // Set to NO by |-windowDidEnterFullScreen:|. | 454 // Set to NO by |-windowDidEnterFullScreen:|. |
| 496 enteringImmersiveFullscreen_ = YES; | 455 enteringImmersiveFullscreen_ = YES; |
| 497 | 456 |
| 498 // Fade to black. | 457 // Fade to black. |
| 499 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; | 458 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; |
| 500 Boolean didFadeOut = NO; | 459 Boolean didFadeOut = NO; |
| 501 CGDisplayFadeReservationToken token; | 460 CGDisplayFadeReservationToken token; |
| 502 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) | 461 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) |
| 503 == kCGErrorSuccess) { | 462 == kCGErrorSuccess) { |
| 504 didFadeOut = YES; | 463 didFadeOut = YES; |
| 505 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, | 464 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, |
| 506 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); | 465 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); |
| 507 } | 466 } |
| 508 | 467 |
| 509 // Create the fullscreen window. | 468 // Create the fullscreen window. |
| 510 fullscreenWindow_.reset([[self createFullscreenWindow] retain]); | 469 fullscreenWindow_.reset([[self createFullscreenWindow] retain]); |
| 511 savedRegularWindow_ = [[self window] retain]; | 470 savedRegularWindow_ = [[self window] retain]; |
| 512 savedRegularWindowFrame_ = [savedRegularWindow_ frame]; | 471 savedRegularWindowFrame_ = [savedRegularWindow_ frame]; |
| 513 | 472 |
| 514 [self moveViewsForImmersiveFullscreen:YES | 473 [self moveViewsForImmersiveFullscreen:YES |
| 515 regularWindow:[self window] | 474 regularWindow:[self window] |
| 516 fullscreenWindow:fullscreenWindow_.get()]; | 475 fullscreenWindow:fullscreenWindow_.get()]; |
| 517 | 476 [self adjustUIForEnteringFullscreen]; |
| 518 FullscreenSlidingStyle style = FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN; | |
| 519 [self adjustUIForSlidingFullscreenStyle:style]; | |
| 520 | 477 |
| 521 [fullscreenWindow_ display]; | 478 [fullscreenWindow_ display]; |
| 522 | 479 |
| 523 // AppKit is helpful and prevents NSWindows from having the same height as | 480 // AppKit is helpful and prevents NSWindows from having the same height as |
| 524 // the screen while the menu bar is showing. This only applies to windows on | 481 // the screen while the menu bar is showing. This only applies to windows on |
| 525 // a secondary screen, in a separate space. Calling [NSWindow | 482 // a secondary screen, in a separate space. Calling [NSWindow |
| 526 // setFrame:display:] with the screen's height will always reduce the | 483 // setFrame:display:] with the screen's height will always reduce the |
| 527 // height by the height of the MenuBar. Calling the method with any other | 484 // height by the height of the MenuBar. Calling the method with any other |
| 528 // height works fine. The relevant method in the 10.10 AppKit SDK is called: | 485 // height works fine. The relevant method in the 10.10 AppKit SDK is called: |
| 529 // _canAdjustSizeForScreensHaveSeparateSpacesIfFillingSecondaryScreen | 486 // _canAdjustSizeForScreensHaveSeparateSpacesIfFillingSecondaryScreen |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 [bubbleWindow orderFront:nil]; | 737 [bubbleWindow orderFront:nil]; |
| 781 } | 738 } |
| 782 | 739 |
| 783 // Ensure that the window is layout properly. | 740 // Ensure that the window is layout properly. |
| 784 [self layoutSubviews]; | 741 [self layoutSubviews]; |
| 785 } | 742 } |
| 786 | 743 |
| 787 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { | 744 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { |
| 788 [self deregisterForContentViewResizeNotifications]; | 745 [self deregisterForContentViewResizeNotifications]; |
| 789 [self resetCustomAppKitFullscreenVariables]; | 746 [self resetCustomAppKitFullscreenVariables]; |
| 790 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 747 [self adjustUIForExitingFullscreen]; |
| 791 fullscreenLowPowerCoordinator_.reset(); | 748 fullscreenLowPowerCoordinator_.reset(); |
| 792 } | 749 } |
| 793 | 750 |
| 794 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { | 751 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { |
| 795 [self deregisterForContentViewResizeNotifications]; | 752 [self deregisterForContentViewResizeNotifications]; |
| 796 [self resetCustomAppKitFullscreenVariables]; | 753 [self resetCustomAppKitFullscreenVariables]; |
| 797 | 754 |
| 798 // Force a relayout to try and get the window back into a reasonable state. | 755 // Force a relayout to try and get the window back into a reasonable state. |
| 799 [self layoutSubviews]; | 756 [self layoutSubviews]; |
| 800 } | 757 } |
| 801 | 758 |
| 802 - (void)setSheetHiddenForFullscreenTransition:(BOOL)shoudHide { | 759 - (void)setSheetHiddenForFullscreenTransition:(BOOL)shoudHide { |
| 803 if (!isUsingCustomAnimation_) | 760 if (!isUsingCustomAnimation_) |
| 804 return; | 761 return; |
| 805 | 762 |
| 806 ConstrainedWindowSheetController* sheetController = | 763 ConstrainedWindowSheetController* sheetController = |
| 807 [ConstrainedWindowSheetController | 764 [ConstrainedWindowSheetController |
| 808 controllerForParentWindow:[self window]]; | 765 controllerForParentWindow:[self window]]; |
| 809 if (shoudHide) | 766 if (shoudHide) |
| 810 [sheetController hideSheetForFullscreenTransition]; | 767 [sheetController hideSheetForFullscreenTransition]; |
| 811 else | 768 else |
| 812 [sheetController unhideSheetForFullscreenTransition]; | 769 [sheetController unhideSheetForFullscreenTransition]; |
| 813 } | 770 } |
| 814 | 771 |
| 815 - (void)adjustUIForExitingFullscreen { | 772 - (void)adjustUIForExitingFullscreen { |
| 816 exclusiveAccessController_->Destroy(); | 773 exclusiveAccessController_->Destroy(); |
| 817 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 774 [fullscreenToolbarController_ exitFullscreenMode]; |
| 775 | |
| 776 // Force the bookmark bar z-order to update. | |
| 777 [[bookmarkBarController_ view] removeFromSuperview]; | |
| 778 [self layoutSubviews]; | |
| 818 } | 779 } |
| 819 | 780 |
| 820 - (void)adjustUIForEnteringFullscreen { | 781 - (void)adjustUIForEnteringFullscreen { |
| 821 FullscreenSlidingStyle style = FullscreenSlidingStyle::OMNIBOX_TABS_PRESENT; | 782 if (![self isInAnyFullscreenMode]) |
|
erikchen
2016/11/02 00:25:36
Should this be a DCHECK? How can this get called i
spqchan
2016/11/02 20:00:27
That's true, this was pulled from |adjustUIForSlid
| |
| 822 if ([self isFullscreenForTabContentOrExtension]) | 783 return; |
| 823 style = FullscreenSlidingStyle::OMNIBOX_TABS_NONE; | |
| 824 else if (!shouldShowFullscreenToolbar_) | |
| 825 style = FullscreenSlidingStyle::OMNIBOX_TABS_HIDDEN; | |
| 826 | 784 |
| 827 [self adjustUIForSlidingFullscreenStyle:style]; | 785 [fullscreenToolbarController_ enterFullscreenMode]; |
| 786 | |
| 787 if (!floatingBarBackingView_.get() && | |
| 788 ([self hasTabStrip] || [self hasToolbar] || [self hasLocationBar])) { | |
| 789 floatingBarBackingView_.reset( | |
| 790 [[FloatingBarBackingView alloc] initWithFrame:NSZeroRect]); | |
| 791 [floatingBarBackingView_ | |
| 792 setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; | |
| 793 } | |
| 794 | |
| 795 // Force the bookmark bar z-order to update. | |
| 796 [[bookmarkBarController_ view] removeFromSuperview]; | |
| 797 [self layoutSubviews]; | |
| 828 } | 798 } |
| 829 | 799 |
| 830 - (CGFloat)toolbarDividerOpacity { | 800 - (CGFloat)toolbarDividerOpacity { |
| 831 return [bookmarkBarController_ toolbarDividerOpacity]; | 801 return [bookmarkBarController_ toolbarDividerOpacity]; |
| 832 } | 802 } |
| 833 | 803 |
| 834 - (void)updateInfoBarTipVisibility { | 804 - (void)updateInfoBarTipVisibility { |
| 835 // If there's no toolbar then hide the infobar tip. | 805 // If there's no toolbar then hide the infobar tip. |
| 836 [infoBarContainerController_ | 806 [infoBarContainerController_ |
| 837 setShouldSuppressTopInfoBarTip:![self hasToolbar]]; | 807 setShouldSuppressTopInfoBarTip:![self hasToolbar]]; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 887 - (void)updateLayoutParameters:(BrowserWindowLayout*)layout { | 857 - (void)updateLayoutParameters:(BrowserWindowLayout*)layout { |
| 888 [layout setContentViewSize:[[[self window] contentView] bounds].size]; | 858 [layout setContentViewSize:[[[self window] contentView] bounds].size]; |
| 889 | 859 |
| 890 NSSize windowSize = (fullscreenTransition_.get()) | 860 NSSize windowSize = (fullscreenTransition_.get()) |
| 891 ? [fullscreenTransition_ desiredWindowLayoutSize] | 861 ? [fullscreenTransition_ desiredWindowLayoutSize] |
| 892 : [[self window] frame].size; | 862 : [[self window] frame].size; |
| 893 | 863 |
| 894 [layout setWindowSize:windowSize]; | 864 [layout setWindowSize:windowSize]; |
| 895 | 865 |
| 896 [layout setInAnyFullscreen:[self isInAnyFullscreenMode]]; | 866 [layout setInAnyFullscreen:[self isInAnyFullscreenMode]]; |
| 897 [layout setSlidingStyle:fullscreenToolbarController_.get().slidingStyle]; | 867 [layout setFullscreenToolbarStyle:fullscreenToolbarController_.get() |
| 868 .toolbarStyle]; | |
| 898 [layout | 869 [layout |
| 899 setFullscreenMenubarOffset:[fullscreenToolbarController_ menubarOffset]]; | 870 setFullscreenMenubarOffset:[fullscreenToolbarController_ menubarOffset]]; |
| 900 [layout setFullscreenToolbarFraction:[fullscreenToolbarController_ | 871 [layout setFullscreenToolbarFraction:[fullscreenToolbarController_ |
| 901 toolbarFraction]]; | 872 toolbarFraction]]; |
| 902 | 873 |
| 903 [layout setHasTabStrip:[self hasTabStrip]]; | 874 [layout setHasTabStrip:[self hasTabStrip]]; |
| 904 [layout setFullscreenButtonFrame:[self fullscreenButtonFrame]]; | 875 [layout setFullscreenButtonFrame:[self fullscreenButtonFrame]]; |
| 905 | 876 |
| 906 if ([self shouldShowAvatar]) { | 877 if ([self shouldShowAvatar]) { |
| 907 NSView* avatar = [avatarButtonController_ view]; | 878 NSView* avatar = [avatarButtonController_ view]; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1188 - (WebContents*)webContents { | 1159 - (WebContents*)webContents { |
| 1189 return browser_->tab_strip_model()->GetActiveWebContents(); | 1160 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 1190 } | 1161 } |
| 1191 | 1162 |
| 1192 - (PermissionRequestManager*)permissionRequestManager { | 1163 - (PermissionRequestManager*)permissionRequestManager { |
| 1193 if (WebContents* contents = [self webContents]) | 1164 if (WebContents* contents = [self webContents]) |
| 1194 return PermissionRequestManager::FromWebContents(contents); | 1165 return PermissionRequestManager::FromWebContents(contents); |
| 1195 return nil; | 1166 return nil; |
| 1196 } | 1167 } |
| 1197 | 1168 |
| 1198 - (BOOL)isFullscreenForTabContentOrExtension { | |
| 1199 FullscreenController* controller = | |
| 1200 browser_->exclusive_access_manager()->fullscreen_controller(); | |
| 1201 return controller->IsWindowFullscreenForTabOrPending() || | |
| 1202 controller->IsExtensionFullscreenOrPending(); | |
| 1203 } | |
| 1204 | |
| 1205 - (FullscreenToolbarVisibilityLockController*) | 1169 - (FullscreenToolbarVisibilityLockController*) |
| 1206 fullscreenToolbarVisibilityLockController { | 1170 fullscreenToolbarVisibilityLockController { |
| 1207 return [fullscreenToolbarController_ visibilityLockController]; | 1171 return [fullscreenToolbarController_ visibilityLockController]; |
| 1208 } | 1172 } |
| 1209 | 1173 |
| 1210 - (void)windowWillBeginSheet:(NSNotification*)notification { | 1174 - (void)windowWillBeginSheet:(NSNotification*)notification { |
| 1211 if (fullscreenLowPowerCoordinator_) | 1175 if (fullscreenLowPowerCoordinator_) |
| 1212 fullscreenLowPowerCoordinator_->SetHasActiveSheet(true); | 1176 fullscreenLowPowerCoordinator_->SetHasActiveSheet(true); |
| 1213 } | 1177 } |
| 1214 | 1178 |
| 1215 - (void)windowDidEndSheet:(NSNotification*)notification { | 1179 - (void)windowDidEndSheet:(NSNotification*)notification { |
| 1216 if (fullscreenLowPowerCoordinator_) | 1180 if (fullscreenLowPowerCoordinator_) |
| 1217 fullscreenLowPowerCoordinator_->SetHasActiveSheet(false); | 1181 fullscreenLowPowerCoordinator_->SetHasActiveSheet(false); |
| 1218 } | 1182 } |
| 1219 | 1183 |
| 1220 - (void)childWindowsDidChange { | 1184 - (void)childWindowsDidChange { |
| 1221 if (fullscreenLowPowerCoordinator_) | 1185 if (fullscreenLowPowerCoordinator_) |
| 1222 fullscreenLowPowerCoordinator_->ChildWindowsChanged(); | 1186 fullscreenLowPowerCoordinator_->ChildWindowsChanged(); |
| 1223 } | 1187 } |
| 1224 | 1188 |
| 1225 @end // @implementation BrowserWindowController(Private) | 1189 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |