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 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/mac/bind_objc_block.h" | 10 #include "base/mac/bind_objc_block.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 | 209 |
| 210 // It doesn't make sense to provide a Y higher than the height of the window. | 210 // It doesn't make sense to provide a Y higher than the height of the window. |
| 211 CGFloat windowHeight = NSHeight([window frame]); | 211 CGFloat windowHeight = NSHeight([window frame]); |
| 212 defaultSheetY = std::min(defaultSheetY, windowHeight); | 212 defaultSheetY = std::min(defaultSheetY, windowHeight); |
| 213 | 213 |
| 214 defaultSheetLocation.origin.y = defaultSheetY; | 214 defaultSheetLocation.origin.y = defaultSheetY; |
| 215 return defaultSheetLocation; | 215 return defaultSheetLocation; |
| 216 } | 216 } |
| 217 | 217 |
| 218 - (void)layoutSubviews { | 218 - (void)layoutSubviews { |
| 219 if (blockLayoutSubviews_) | |
| 220 return; | |
| 221 | |
| 219 // Suppress title drawing if necessary. | 222 // Suppress title drawing if necessary. |
| 220 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) | 223 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) |
| 221 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; | 224 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; |
| 222 | 225 |
| 223 [bookmarkBarController_ updateHiddenState]; | 226 [bookmarkBarController_ updateHiddenState]; |
| 224 [self updateSubviewZOrder]; | 227 [self updateSubviewZOrder]; |
| 225 | 228 |
| 226 base::scoped_nsobject<BrowserWindowLayout> layout( | 229 base::scoped_nsobject<BrowserWindowLayout> layout( |
| 227 [[BrowserWindowLayout alloc] init]); | 230 [[BrowserWindowLayout alloc] init]); |
| 228 [self updateLayoutParameters:layout]; | 231 [self updateLayoutParameters:layout]; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 if (notification) // For System Fullscreen when non-nil. | 680 if (notification) // For System Fullscreen when non-nil. |
| 678 [self registerForContentViewResizeNotifications]; | 681 [self registerForContentViewResizeNotifications]; |
| 679 | 682 |
| 680 NSWindow* window = [self window]; | 683 NSWindow* window = [self window]; |
| 681 savedRegularWindowFrame_ = [window frame]; | 684 savedRegularWindowFrame_ = [window frame]; |
| 682 | 685 |
| 683 enteringAppKitFullscreen_ = YES; | 686 enteringAppKitFullscreen_ = YES; |
| 684 enteringAppKitFullscreenOnPrimaryScreen_ = | 687 enteringAppKitFullscreenOnPrimaryScreen_ = |
| 685 [[[self window] screen] isEqual:[[NSScreen screens] objectAtIndex:0]]; | 688 [[[self window] screen] isEqual:[[NSScreen screens] objectAtIndex:0]]; |
| 686 | 689 |
| 687 fullscreen_mac::SlidingStyle style; | 690 // If we are using custom fullscreen animations, the layout will resize |
| 688 if (browser_->exclusive_access_manager() | 691 // in startCustomAnimationToEnterFullScreenWithDuration. In order to prevent |
| 689 ->fullscreen_controller() | 692 // multiple resizing messages from being sent to the renderer, we should call |
| 690 ->IsWindowFullscreenForTabOrPending()) { | 693 // adjustUIForEnteringFullscreen after the layout gets resized. |
| 691 style = fullscreen_mac::OMNIBOX_TABS_NONE; | 694 if ([self shouldUseCustomAppKitFullscreenTransition:YES]) |
| 692 } else if (enteringPresentationMode_) { | 695 blockLayoutSubviews_ = YES; |
| 693 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN; | 696 else |
| 694 } else { | 697 [self adjustUIForEnteringFullscreen]; |
| 695 style = fullscreen_mac::OMNIBOX_TABS_PRESENT; | |
| 696 } | |
| 697 | |
| 698 [self adjustUIForSlidingFullscreenStyle:style]; | |
| 699 } | 698 } |
| 700 | 699 |
| 701 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 700 - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
| 701 blockLayoutSubviews_ = NO; | |
| 702 fullscreenTransition_.reset(); | 702 fullscreenTransition_.reset(); |
| 703 | 703 |
| 704 // In Yosemite, some combination of the titlebar and toolbar always show in | 704 // In Yosemite, some combination of the titlebar and toolbar always show in |
| 705 // full-screen mode. We do not want either to show. Search for the window that | 705 // full-screen mode. We do not want either to show. Search for the window that |
| 706 // contains the views, and hide it. There is no need to ever unhide the view. | 706 // contains the views, and hide it. There is no need to ever unhide the view. |
| 707 // http://crbug.com/380235 | 707 // http://crbug.com/380235 |
| 708 if (base::mac::IsOSYosemiteOrLater()) { | 708 if (base::mac::IsOSYosemiteOrLater()) { |
| 709 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { | 709 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { |
| 710 if ([window | 710 if ([window |
| 711 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { | 711 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 | 748 |
| 749 [self showFullscreenExitBubbleIfNecessary]; | 749 [self showFullscreenExitBubbleIfNecessary]; |
| 750 browser_->WindowFullscreenStateChanged(); | 750 browser_->WindowFullscreenStateChanged(); |
| 751 } | 751 } |
| 752 | 752 |
| 753 - (void)windowWillExitFullScreen:(NSNotification*)notification { | 753 - (void)windowWillExitFullScreen:(NSNotification*)notification { |
| 754 if (notification) // For System Fullscreen when non-nil. | 754 if (notification) // For System Fullscreen when non-nil. |
| 755 [self registerForContentViewResizeNotifications]; | 755 [self registerForContentViewResizeNotifications]; |
| 756 exitingAppKitFullscreen_ = YES; | 756 exitingAppKitFullscreen_ = YES; |
| 757 | 757 |
| 758 [self destroyFullscreenExitBubbleIfNecessary]; | 758 // Like windowWillEnterFullScreen, if we use custom animations, |
| 759 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 759 // adjustUIForExitingFullscreen should be called after the layout resizes in |
| 760 // startCustomAnimationToExitFullScreenWithDuration. | |
| 761 if ([self shouldUseCustomAppKitFullscreenTransition:NO]) | |
| 762 blockLayoutSubviews_ = YES; | |
| 763 else | |
| 764 [self adjustUIForExitingFullscreen]; | |
| 760 } | 765 } |
| 761 | 766 |
| 762 - (void)windowDidExitFullScreen:(NSNotification*)notification { | 767 - (void)windowDidExitFullScreen:(NSNotification*)notification { |
| 763 DCHECK(exitingAppKitFullscreen_); | 768 DCHECK(exitingAppKitFullscreen_); |
| 764 | 769 |
| 765 if (notification) // For System Fullscreen when non-nil. | 770 if (notification) // For System Fullscreen when non-nil. |
| 766 [self deregisterForContentViewResizeNotifications]; | 771 [self deregisterForContentViewResizeNotifications]; |
| 767 | 772 |
| 768 // Since the content view was forcefully resized during the transition, we | |
| 769 // want to ensure that the subviews are layout correctly after it ended. | |
| 770 [self layoutSubviews]; | |
| 771 browser_->WindowFullscreenStateChanged(); | 773 browser_->WindowFullscreenStateChanged(); |
| 772 | 774 |
| 773 exitingAppKitFullscreen_ = NO; | 775 exitingAppKitFullscreen_ = NO; |
| 774 fullscreenTransition_.reset(); | 776 fullscreenTransition_.reset(); |
| 777 | |
| 778 blockLayoutSubviews_ = NO; | |
| 775 } | 779 } |
| 776 | 780 |
| 777 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { | 781 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { |
| 778 [self deregisterForContentViewResizeNotifications]; | 782 [self deregisterForContentViewResizeNotifications]; |
| 779 enteringAppKitFullscreen_ = NO; | 783 enteringAppKitFullscreen_ = NO; |
| 780 fullscreenTransition_.reset(); | 784 fullscreenTransition_.reset(); |
| 785 blockLayoutSubviews_ = NO; | |
| 781 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 786 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; |
| 782 } | 787 } |
| 783 | 788 |
| 784 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { | 789 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { |
| 785 [self deregisterForContentViewResizeNotifications]; | 790 [self deregisterForContentViewResizeNotifications]; |
| 786 exitingAppKitFullscreen_ = NO; | 791 exitingAppKitFullscreen_ = NO; |
| 787 fullscreenTransition_.reset(); | 792 fullscreenTransition_.reset(); |
| 793 blockLayoutSubviews_ = NO; | |
| 788 // Force a relayout to try and get the window back into a reasonable state. | 794 // Force a relayout to try and get the window back into a reasonable state. |
| 789 [self layoutSubviews]; | 795 [self layoutSubviews]; |
| 790 } | 796 } |
| 791 | 797 |
| 798 - (void)adjustUIForExitingFullscreen { | |
| 799 [self destroyFullscreenExitBubbleIfNecessary]; | |
| 800 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | |
| 801 } | |
| 802 | |
| 803 - (void)adjustUIForEnteringFullscreen { | |
| 804 fullscreen_mac::SlidingStyle style; | |
| 805 if (browser_->exclusive_access_manager() | |
| 806 ->fullscreen_controller() | |
| 807 ->IsWindowFullscreenForTabOrPending()) { | |
| 808 style = fullscreen_mac::OMNIBOX_TABS_NONE; | |
| 809 } else if (enteringPresentationMode_) { | |
| 810 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN; | |
| 811 } else { | |
| 812 style = fullscreen_mac::OMNIBOX_TABS_PRESENT; | |
| 813 } | |
| 814 | |
| 815 [self adjustUIForSlidingFullscreenStyle:style]; | |
| 816 } | |
| 817 | |
| 792 - (void)enableBarVisibilityUpdates { | 818 - (void)enableBarVisibilityUpdates { |
| 793 // Early escape if there's nothing to do. | 819 // Early escape if there's nothing to do. |
| 794 if (barVisibilityUpdatesEnabled_) | 820 if (barVisibilityUpdatesEnabled_) |
| 795 return; | 821 return; |
| 796 | 822 |
| 797 barVisibilityUpdatesEnabled_ = YES; | 823 barVisibilityUpdatesEnabled_ = YES; |
| 798 | 824 |
| 799 if ([barVisibilityLocks_ count]) | 825 if ([barVisibilityLocks_ count]) |
| 800 [presentationModeController_ ensureOverlayShownWithAnimation:NO delay:NO]; | 826 [presentationModeController_ ensureOverlayShownWithAnimation:NO delay:NO]; |
| 801 else | 827 else |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 return NO; | 1102 return NO; |
| 1077 | 1103 |
| 1078 return YES; | 1104 return YES; |
| 1079 } | 1105 } |
| 1080 | 1106 |
| 1081 - (BOOL)shouldUseCustomAppKitFullscreenTransition:(BOOL)enterFullScreen { | 1107 - (BOOL)shouldUseCustomAppKitFullscreenTransition:(BOOL)enterFullScreen { |
| 1082 // We are temporary disabling exit fullscreen animation because it only | 1108 // We are temporary disabling exit fullscreen animation because it only |
| 1083 // works on OSX 10.10. | 1109 // works on OSX 10.10. |
| 1084 // TODO(spqchan): Fix exit fullscreen animation so that it works on all | 1110 // TODO(spqchan): Fix exit fullscreen animation so that it works on all |
| 1085 // OSX versions. | 1111 // OSX versions. |
| 1086 if (!enterFullScreen) | 1112 // if (!enterFullScreen) |
|
erikchen
2015/10/07 21:51:03
Huh? What are you trying to do here? If you want t
spqchan
2015/10/07 22:54:01
This change was accidentally added to this CL when
| |
| 1087 return NO; | 1113 return NO; |
| 1088 | 1114 // |
| 1089 if (base::mac::IsOSMountainLionOrEarlier()) | 1115 if (base::mac::IsOSMountainLionOrEarlier()) |
| 1090 return NO; | 1116 return NO; |
| 1091 | 1117 |
| 1092 NSView* root = [[self.window contentView] superview]; | 1118 NSView* root = [[self.window contentView] superview]; |
| 1093 if (!root.layer) | 1119 if (!root.layer) |
| 1094 return NO; | 1120 return NO; |
| 1095 | 1121 |
| 1096 // AppKit on OSX 10.9 has a bug for applications linked against OSX 10.8 SDK | 1122 // AppKit on OSX 10.9 has a bug for applications linked against OSX 10.8 SDK |
| 1097 // and earlier. Under specific circumstances, it prevents the custom AppKit | 1123 // and earlier. Under specific circumstances, it prevents the custom AppKit |
| 1098 // transition from working well. See http://crbug.com/396980 for more | 1124 // transition from working well. See http://crbug.com/396980 for more |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1130 initExitWithWindow:framedBrowserWindow | 1156 initExitWithWindow:framedBrowserWindow |
| 1131 frame:savedRegularWindowFrame_]); | 1157 frame:savedRegularWindowFrame_]); |
| 1132 | 1158 |
| 1133 return [fullscreenTransition_ customWindowsForFullScreenTransition]; | 1159 return [fullscreenTransition_ customWindowsForFullScreenTransition]; |
| 1134 } | 1160 } |
| 1135 | 1161 |
| 1136 - (void)window:(NSWindow*)window | 1162 - (void)window:(NSWindow*)window |
| 1137 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { | 1163 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { |
| 1138 DCHECK([window isEqual:self.window]); | 1164 DCHECK([window isEqual:self.window]); |
| 1139 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; | 1165 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; |
| 1166 | |
| 1167 blockLayoutSubviews_ = NO; | |
| 1168 [self adjustUIForEnteringFullscreen]; | |
| 1169 blockLayoutSubviews_ = YES; | |
| 1140 } | 1170 } |
| 1141 | 1171 |
| 1142 - (void)window:(NSWindow*)window | 1172 - (void)window:(NSWindow*)window |
| 1143 startCustomAnimationToExitFullScreenWithDuration:(NSTimeInterval)duration { | 1173 startCustomAnimationToExitFullScreenWithDuration:(NSTimeInterval)duration { |
| 1144 DCHECK([window isEqual:self.window]); | 1174 DCHECK([window isEqual:self.window]); |
| 1145 | 1175 |
| 1146 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; | 1176 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; |
| 1177 | |
| 1178 blockLayoutSubviews_ = NO; | |
|
erikchen
2015/10/07 21:51:03
This code assumes that blockLayoutSubviews_ is YES
spqchan
2015/10/07 22:54:01
Done.
| |
| 1179 [self adjustUIForExitingFullscreen]; | |
| 1180 blockLayoutSubviews_ = YES; | |
| 1147 } | 1181 } |
| 1148 | 1182 |
| 1149 - (BOOL)shouldConstrainFrameRect { | 1183 - (BOOL)shouldConstrainFrameRect { |
| 1150 if ([fullscreenTransition_ shouldWindowBeUnconstrained]) | 1184 if ([fullscreenTransition_ shouldWindowBeUnconstrained]) |
| 1151 return NO; | 1185 return NO; |
| 1152 | 1186 |
| 1153 return [super shouldConstrainFrameRect]; | 1187 return [super shouldConstrainFrameRect]; |
| 1154 } | 1188 } |
| 1155 | 1189 |
| 1156 - (WebContents*)webContents { | 1190 - (WebContents*)webContents { |
| 1157 return browser_->tab_strip_model()->GetActiveWebContents(); | 1191 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 1158 } | 1192 } |
| 1159 | 1193 |
| 1160 - (PermissionBubbleManager*)permissionBubbleManager { | 1194 - (PermissionBubbleManager*)permissionBubbleManager { |
| 1161 if (WebContents* contents = [self webContents]) | 1195 if (WebContents* contents = [self webContents]) |
| 1162 return PermissionBubbleManager::FromWebContents(contents); | 1196 return PermissionBubbleManager::FromWebContents(contents); |
| 1163 return nil; | 1197 return nil; |
| 1164 } | 1198 } |
| 1165 | 1199 |
| 1166 @end // @implementation BrowserWindowController(Private) | 1200 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |