| 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" |
| 11 #include "base/mac/bind_objc_block.h" | 11 #include "base/mac/bind_objc_block.h" |
| 12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
| 14 #import "base/mac/scoped_nsobject.h" | 14 #import "base/mac/scoped_nsobject.h" |
| 15 #import "base/mac/sdk_forward_declarations.h" | 15 #import "base/mac/sdk_forward_declarations.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/prefs/scoped_user_pref_update.h" | 18 #include "base/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/fullscreen.h" | 20 #include "chrome/browser/fullscreen.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 22 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 23 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 23 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_window_state.h" | 25 #include "chrome/browser/ui/browser_window_state.h" |
| 26 #import "chrome/browser/ui/cocoa/browser_window_fullscreen_transition.h" | 26 #import "chrome/browser/ui/cocoa/browser_window_fullscreen_transition.h" |
| 27 #import "chrome/browser/ui/cocoa/browser_window_layout.h" | 27 #import "chrome/browser/ui/cocoa/browser_window_layout.h" |
| 28 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 28 #import "chrome/browser/ui/cocoa/custom_frame_view.h" | 29 #import "chrome/browser/ui/cocoa/custom_frame_view.h" |
| 29 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 30 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
| 30 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 31 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| 31 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 32 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
| 32 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h" | 33 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h" |
| 33 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 34 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
| 34 #import "chrome/browser/ui/cocoa/fullscreen_window.h" | 35 #import "chrome/browser/ui/cocoa/fullscreen_window.h" |
| 35 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 36 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 36 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" | 37 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" |
| 37 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 38 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 if (notification) // For System Fullscreen when non-nil. | 694 if (notification) // For System Fullscreen when non-nil. |
| 694 [self registerForContentViewResizeNotifications]; | 695 [self registerForContentViewResizeNotifications]; |
| 695 | 696 |
| 696 NSWindow* window = [self window]; | 697 NSWindow* window = [self window]; |
| 697 savedRegularWindowFrame_ = [window frame]; | 698 savedRegularWindowFrame_ = [window frame]; |
| 698 | 699 |
| 699 enteringAppKitFullscreen_ = YES; | 700 enteringAppKitFullscreen_ = YES; |
| 700 enteringAppKitFullscreenOnPrimaryScreen_ = | 701 enteringAppKitFullscreenOnPrimaryScreen_ = |
| 701 [[[self window] screen] isEqual:[[NSScreen screens] firstObject]]; | 702 [[[self window] screen] isEqual:[[NSScreen screens] firstObject]]; |
| 702 | 703 |
| 704 [self setSheetHiddenForFullscreenTransition:YES]; |
| 705 |
| 703 // If we are using custom fullscreen animations, the layout will resize | 706 // If we are using custom fullscreen animations, the layout will resize |
| 704 // in startCustomAnimationToEnterFullScreenWithDuration. In order to prevent | 707 // in startCustomAnimationToEnterFullScreenWithDuration. In order to prevent |
| 705 // multiple resizing messages from being sent to the renderer, we should call | 708 // multiple resizing messages from being sent to the renderer, we should call |
| 706 // adjustUIForEnteringFullscreen after the layout gets resized. | 709 // adjustUIForEnteringFullscreen after the layout gets resized. |
| 707 if (isUsingCustomAnimation_) | 710 if (isUsingCustomAnimation_) |
| 708 blockLayoutSubviews_ = YES; | 711 blockLayoutSubviews_ = YES; |
| 709 else | 712 else |
| 710 [self adjustUIForEnteringFullscreen]; | 713 [self adjustUIForEnteringFullscreen]; |
| 711 } | 714 } |
| 712 | 715 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 CGFloat heightDelta = | 754 CGFloat heightDelta = |
| 752 expectedFrame.size.height - currentFrame.size.height; | 755 expectedFrame.size.height - currentFrame.size.height; |
| 753 if (fabs(heightDelta - kExpectedHeightDifference) > 0.01) | 756 if (fabs(heightDelta - kExpectedHeightDifference) > 0.01) |
| 754 return; | 757 return; |
| 755 | 758 |
| 756 [[self window] setFrame:expectedFrame display:YES]; | 759 [[self window] setFrame:expectedFrame display:YES]; |
| 757 }); | 760 }); |
| 758 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 761 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 759 } | 762 } |
| 760 | 763 |
| 764 [self setSheetHiddenForFullscreenTransition:NO]; |
| 765 |
| 761 if (notification) // For System Fullscreen when non-nil. | 766 if (notification) // For System Fullscreen when non-nil. |
| 762 [self deregisterForContentViewResizeNotifications]; | 767 [self deregisterForContentViewResizeNotifications]; |
| 768 |
| 763 enteringAppKitFullscreen_ = NO; | 769 enteringAppKitFullscreen_ = NO; |
| 764 enteringImmersiveFullscreen_ = NO; | 770 enteringImmersiveFullscreen_ = NO; |
| 765 enteringPresentationMode_ = NO; | 771 enteringPresentationMode_ = NO; |
| 766 isUsingCustomAnimation_ = NO; | 772 isUsingCustomAnimation_ = NO; |
| 767 | 773 |
| 768 [self showFullscreenExitBubbleIfNecessary]; | 774 [self showFullscreenExitBubbleIfNecessary]; |
| 769 [self layoutSubviews]; | |
| 770 browser_->WindowFullscreenStateChanged(); | 775 browser_->WindowFullscreenStateChanged(); |
| 771 } | 776 } |
| 772 | 777 |
| 773 - (void)windowWillExitFullScreen:(NSNotification*)notification { | 778 - (void)windowWillExitFullScreen:(NSNotification*)notification { |
| 774 if (notification) // For System Fullscreen when non-nil. | 779 if (notification) // For System Fullscreen when non-nil. |
| 775 [self registerForContentViewResizeNotifications]; | 780 [self registerForContentViewResizeNotifications]; |
| 776 exitingAppKitFullscreen_ = YES; | 781 exitingAppKitFullscreen_ = YES; |
| 777 | 782 |
| 778 // Like windowWillEnterFullScreen, if we use custom animations, | 783 // Like windowWillEnterFullScreen, if we use custom animations, |
| 779 // adjustUIForExitingFullscreen should be called after the layout resizes in | 784 // adjustUIForExitingFullscreen should be called after the layout resizes in |
| 780 // startCustomAnimationToExitFullScreenWithDuration. | 785 // startCustomAnimationToExitFullScreenWithDuration. |
| 781 if (isUsingCustomAnimation_) | 786 if (isUsingCustomAnimation_) { |
| 782 blockLayoutSubviews_ = YES; | 787 blockLayoutSubviews_ = YES; |
| 783 else | 788 [self setSheetHiddenForFullscreenTransition:YES]; |
| 789 |
| 790 // In OSX 10.11, when the NSFullScreenWindowMask is added or removed, |
| 791 // the window's frame and layer changes slightly which causes a janky |
| 792 // movement. As a result, we should disable the content view's autoresize |
| 793 // at the beginning of the animation and set it back to its original value |
| 794 // at the end of the animation. |
| 795 [self.chromeContentView setAutoresizesSubviews:NO]; |
| 796 } else { |
| 784 [self adjustUIForExitingFullscreen]; | 797 [self adjustUIForExitingFullscreen]; |
| 798 } |
| 785 } | 799 } |
| 786 | 800 |
| 787 - (void)windowDidExitFullScreen:(NSNotification*)notification { | 801 - (void)windowDidExitFullScreen:(NSNotification*)notification { |
| 788 DCHECK(exitingAppKitFullscreen_); | 802 DCHECK(exitingAppKitFullscreen_); |
| 789 | 803 |
| 790 if (notification) // For System Fullscreen when non-nil. | 804 if (notification) // For System Fullscreen when non-nil. |
| 791 [self deregisterForContentViewResizeNotifications]; | 805 [self deregisterForContentViewResizeNotifications]; |
| 792 | 806 |
| 793 browser_->WindowFullscreenStateChanged(); | 807 browser_->WindowFullscreenStateChanged(); |
| 808 [self.chromeContentView setAutoresizesSubviews:YES]; |
| 809 |
| 810 [self setSheetHiddenForFullscreenTransition:NO]; |
| 794 | 811 |
| 795 exitingAppKitFullscreen_ = NO; | 812 exitingAppKitFullscreen_ = NO; |
| 796 isUsingCustomAnimation_ = NO; | 813 isUsingCustomAnimation_ = NO; |
| 797 fullscreenTransition_.reset(); | 814 fullscreenTransition_.reset(); |
| 798 | 815 |
| 799 blockLayoutSubviews_ = NO; | 816 blockLayoutSubviews_ = NO; |
| 800 } | 817 } |
| 801 | 818 |
| 802 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { | 819 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { |
| 803 [self deregisterForContentViewResizeNotifications]; | 820 [self deregisterForContentViewResizeNotifications]; |
| 804 enteringAppKitFullscreen_ = NO; | 821 enteringAppKitFullscreen_ = NO; |
| 805 fullscreenTransition_.reset(); | 822 fullscreenTransition_.reset(); |
| 806 blockLayoutSubviews_ = NO; | 823 blockLayoutSubviews_ = NO; |
| 807 isUsingCustomAnimation_ = NO; | 824 isUsingCustomAnimation_ = NO; |
| 808 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 825 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; |
| 809 } | 826 } |
| 810 | 827 |
| 811 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { | 828 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { |
| 812 [self deregisterForContentViewResizeNotifications]; | 829 [self deregisterForContentViewResizeNotifications]; |
| 813 exitingAppKitFullscreen_ = NO; | 830 exitingAppKitFullscreen_ = NO; |
| 814 fullscreenTransition_.reset(); | 831 fullscreenTransition_.reset(); |
| 815 isUsingCustomAnimation_ = NO; | 832 isUsingCustomAnimation_ = NO; |
| 816 blockLayoutSubviews_ = NO; | 833 blockLayoutSubviews_ = NO; |
| 834 |
| 817 // Force a relayout to try and get the window back into a reasonable state. | 835 // Force a relayout to try and get the window back into a reasonable state. |
| 836 [self.chromeContentView setAutoresizesSubviews:YES]; |
| 818 [self layoutSubviews]; | 837 [self layoutSubviews]; |
| 819 } | 838 } |
| 820 | 839 |
| 840 - (void)setSheetHiddenForFullscreenTransition:(BOOL)shoudHide { |
| 841 if (!isUsingCustomAnimation_) |
| 842 return; |
| 843 |
| 844 ConstrainedWindowSheetController* sheetController = |
| 845 [ConstrainedWindowSheetController |
| 846 controllerForParentWindow:[self window]]; |
| 847 if (shoudHide) |
| 848 [sheetController hideSheetForFullscreenTransition]; |
| 849 else |
| 850 [sheetController unhideSheetForFullscreenTransition]; |
| 851 } |
| 852 |
| 821 - (void)adjustUIForExitingFullscreen { | 853 - (void)adjustUIForExitingFullscreen { |
| 822 [self destroyFullscreenExitBubbleIfNecessary]; | 854 [self destroyFullscreenExitBubbleIfNecessary]; |
| 823 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 855 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; |
| 824 } | 856 } |
| 825 | 857 |
| 826 - (void)adjustUIForEnteringFullscreen { | 858 - (void)adjustUIForEnteringFullscreen { |
| 827 fullscreen_mac::SlidingStyle style; | 859 fullscreen_mac::SlidingStyle style; |
| 828 if (browser_->exclusive_access_manager() | 860 if (browser_->exclusive_access_manager() |
| 829 ->fullscreen_controller() | 861 ->fullscreen_controller() |
| 830 ->IsWindowFullscreenForTabOrPending()) { | 862 ->IsWindowFullscreenForTabOrPending()) { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 if (![self shouldUseCustomAppKitFullscreenTransition:YES]) | 1191 if (![self shouldUseCustomAppKitFullscreenTransition:YES]) |
| 1160 return nil; | 1192 return nil; |
| 1161 | 1193 |
| 1162 FramedBrowserWindow* framedBrowserWindow = | 1194 FramedBrowserWindow* framedBrowserWindow = |
| 1163 base::mac::ObjCCast<FramedBrowserWindow>([self window]); | 1195 base::mac::ObjCCast<FramedBrowserWindow>([self window]); |
| 1164 fullscreenTransition_.reset([[BrowserWindowFullscreenTransition alloc] | 1196 fullscreenTransition_.reset([[BrowserWindowFullscreenTransition alloc] |
| 1165 initEnterWithWindow:framedBrowserWindow]); | 1197 initEnterWithWindow:framedBrowserWindow]); |
| 1166 | 1198 |
| 1167 NSArray* customWindows = | 1199 NSArray* customWindows = |
| 1168 [fullscreenTransition_ customWindowsForFullScreenTransition]; | 1200 [fullscreenTransition_ customWindowsForFullScreenTransition]; |
| 1169 isUsingCustomAnimation_ = !customWindows; | 1201 isUsingCustomAnimation_ = customWindows != nil; |
| 1170 return customWindows; | 1202 return customWindows; |
| 1171 } | 1203 } |
| 1172 | 1204 |
| 1173 - (NSArray*)customWindowsToExitFullScreenForWindow:(NSWindow*)window { | 1205 - (NSArray*)customWindowsToExitFullScreenForWindow:(NSWindow*)window { |
| 1174 DCHECK([window isEqual:self.window]); | 1206 DCHECK([window isEqual:self.window]); |
| 1175 | 1207 |
| 1176 if (![self shouldUseCustomAppKitFullscreenTransition:NO]) | 1208 if (![self shouldUseCustomAppKitFullscreenTransition:NO]) |
| 1177 return nil; | 1209 return nil; |
| 1178 | 1210 |
| 1179 FramedBrowserWindow* framedBrowserWindow = | 1211 FramedBrowserWindow* framedBrowserWindow = |
| 1180 base::mac::ObjCCast<FramedBrowserWindow>([self window]); | 1212 base::mac::ObjCCast<FramedBrowserWindow>([self window]); |
| 1181 fullscreenTransition_.reset([[BrowserWindowFullscreenTransition alloc] | 1213 fullscreenTransition_.reset([[BrowserWindowFullscreenTransition alloc] |
| 1182 initExitWithWindow:framedBrowserWindow | 1214 initExitWithWindow:framedBrowserWindow |
| 1183 frame:savedRegularWindowFrame_ | 1215 frame:savedRegularWindowFrame_ |
| 1184 tabStripBackgroundView:[self tabStripBackgroundView]]); | 1216 tabStripBackgroundView:[self tabStripBackgroundView]]); |
| 1185 | 1217 |
| 1186 NSArray* customWindows = | 1218 NSArray* customWindows = |
| 1187 [fullscreenTransition_ customWindowsForFullScreenTransition]; | 1219 [fullscreenTransition_ customWindowsForFullScreenTransition]; |
| 1188 isUsingCustomAnimation_ = !customWindows; | 1220 isUsingCustomAnimation_ = customWindows != nil; |
| 1189 return customWindows; | 1221 return customWindows; |
| 1190 } | 1222 } |
| 1191 | 1223 |
| 1192 - (void)window:(NSWindow*)window | 1224 - (void)window:(NSWindow*)window |
| 1193 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { | 1225 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { |
| 1194 DCHECK([window isEqual:self.window]); | 1226 DCHECK([window isEqual:self.window]); |
| 1195 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; | 1227 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; |
| 1196 | 1228 |
| 1197 base::AutoReset<BOOL> autoReset(&blockLayoutSubviews_, NO); | 1229 base::AutoReset<BOOL> autoReset(&blockLayoutSubviews_, NO); |
| 1198 [self adjustUIForEnteringFullscreen]; | 1230 [self adjustUIForEnteringFullscreen]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1219 return browser_->tab_strip_model()->GetActiveWebContents(); | 1251 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 1220 } | 1252 } |
| 1221 | 1253 |
| 1222 - (PermissionBubbleManager*)permissionBubbleManager { | 1254 - (PermissionBubbleManager*)permissionBubbleManager { |
| 1223 if (WebContents* contents = [self webContents]) | 1255 if (WebContents* contents = [self webContents]) |
| 1224 return PermissionBubbleManager::FromWebContents(contents); | 1256 return PermissionBubbleManager::FromWebContents(contents); |
| 1225 return nil; | 1257 return nil; |
| 1226 } | 1258 } |
| 1227 | 1259 |
| 1228 @end // @implementation BrowserWindowController(Private) | 1260 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |