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

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

Issue 1387473002: Switch HTML5 Fullscreen Over to AppKit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix more things Created 5 years, 2 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
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller_private.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/mac/bind_objc_block.h" 11 #include "base/mac/bind_objc_block.h"
11 #include "base/mac/foundation_util.h" 12 #include "base/mac/foundation_util.h"
12 #include "base/mac/mac_util.h" 13 #include "base/mac/mac_util.h"
13 #import "base/mac/scoped_nsobject.h" 14 #import "base/mac/scoped_nsobject.h"
14 #import "base/mac/sdk_forward_declarations.h" 15 #import "base/mac/sdk_forward_declarations.h"
15 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
16 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
17 #include "base/prefs/scoped_user_pref_update.h" 18 #include "base/prefs/scoped_user_pref_update.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 210
210 // It doesn't make sense to provide a Y higher than the height of the window. 211 // It doesn't make sense to provide a Y higher than the height of the window.
211 CGFloat windowHeight = NSHeight([window frame]); 212 CGFloat windowHeight = NSHeight([window frame]);
212 defaultSheetY = std::min(defaultSheetY, windowHeight); 213 defaultSheetY = std::min(defaultSheetY, windowHeight);
213 214
214 defaultSheetLocation.origin.y = defaultSheetY; 215 defaultSheetLocation.origin.y = defaultSheetY;
215 return defaultSheetLocation; 216 return defaultSheetLocation;
216 } 217 }
217 218
218 - (void)layoutSubviews { 219 - (void)layoutSubviews {
220 if (blockLayoutSubviews_)
221 return;
222
219 // Suppress title drawing if necessary. 223 // Suppress title drawing if necessary.
220 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) 224 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)])
221 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; 225 [(id)self.window setShouldHideTitle:![self hasTitleBar]];
222 226
223 [bookmarkBarController_ updateHiddenState]; 227 [bookmarkBarController_ updateHiddenState];
224 [self updateSubviewZOrder]; 228 [self updateSubviewZOrder];
225 229
226 base::scoped_nsobject<BrowserWindowLayout> layout( 230 base::scoped_nsobject<BrowserWindowLayout> layout(
227 [[BrowserWindowLayout alloc] init]); 231 [[BrowserWindowLayout alloc] init]);
228 [self updateLayoutParameters:layout]; 232 [self updateLayoutParameters:layout];
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 if (notification) // For System Fullscreen when non-nil. 681 if (notification) // For System Fullscreen when non-nil.
678 [self registerForContentViewResizeNotifications]; 682 [self registerForContentViewResizeNotifications];
679 683
680 NSWindow* window = [self window]; 684 NSWindow* window = [self window];
681 savedRegularWindowFrame_ = [window frame]; 685 savedRegularWindowFrame_ = [window frame];
682 686
683 enteringAppKitFullscreen_ = YES; 687 enteringAppKitFullscreen_ = YES;
684 enteringAppKitFullscreenOnPrimaryScreen_ = 688 enteringAppKitFullscreenOnPrimaryScreen_ =
685 [[[self window] screen] isEqual:[[NSScreen screens] objectAtIndex:0]]; 689 [[[self window] screen] isEqual:[[NSScreen screens] objectAtIndex:0]];
686 690
687 fullscreen_mac::SlidingStyle style; 691 // If we are using custom fullscreen animations, the layout will resize
688 if (browser_->exclusive_access_manager() 692 // in startCustomAnimationToEnterFullScreenWithDuration. In order to prevent
689 ->fullscreen_controller() 693 // multiple resizing messages from being sent to the renderer, we should call
690 ->IsWindowFullscreenForTabOrPending()) { 694 // adjustUIForEnteringFullscreen after the layout gets resized.
691 style = fullscreen_mac::OMNIBOX_TABS_NONE; 695 if ([self shouldUseCustomAppKitFullscreenTransition:YES])
692 } else if (enteringPresentationMode_) { 696 blockLayoutSubviews_ = YES;
693 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN; 697 else
694 } else { 698 [self adjustUIForEnteringFullscreen];
695 style = fullscreen_mac::OMNIBOX_TABS_PRESENT;
696 }
697
698 [self adjustUIForSlidingFullscreenStyle:style];
699 } 699 }
700 700
701 - (void)windowDidEnterFullScreen:(NSNotification*)notification { 701 - (void)windowDidEnterFullScreen:(NSNotification*)notification {
702 blockLayoutSubviews_ = NO;
702 fullscreenTransition_.reset(); 703 fullscreenTransition_.reset();
703 704
704 // In Yosemite, some combination of the titlebar and toolbar always show in 705 // 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 706 // 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. 707 // contains the views, and hide it. There is no need to ever unhide the view.
707 // http://crbug.com/380235 708 // http://crbug.com/380235
708 if (base::mac::IsOSYosemiteOrLater()) { 709 if (base::mac::IsOSYosemiteOrLater()) {
709 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { 710 for (NSWindow* window in [[NSApplication sharedApplication] windows]) {
710 if ([window 711 if ([window
711 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { 712 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 749
749 [self showFullscreenExitBubbleIfNecessary]; 750 [self showFullscreenExitBubbleIfNecessary];
750 browser_->WindowFullscreenStateChanged(); 751 browser_->WindowFullscreenStateChanged();
751 } 752 }
752 753
753 - (void)windowWillExitFullScreen:(NSNotification*)notification { 754 - (void)windowWillExitFullScreen:(NSNotification*)notification {
754 if (notification) // For System Fullscreen when non-nil. 755 if (notification) // For System Fullscreen when non-nil.
755 [self registerForContentViewResizeNotifications]; 756 [self registerForContentViewResizeNotifications];
756 exitingAppKitFullscreen_ = YES; 757 exitingAppKitFullscreen_ = YES;
757 758
758 [self destroyFullscreenExitBubbleIfNecessary]; 759 // Like windowWillEnterFullScreen, if we use custom animations,
759 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; 760 // adjustUIForExitingFullscreen should be called after the layout resizes in
761 // startCustomAnimationToExitFullScreenWithDuration.
762 if ([self shouldUseCustomAppKitFullscreenTransition:NO])
763 blockLayoutSubviews_ = YES;
764 else
765 [self adjustUIForExitingFullscreen];
760 } 766 }
761 767
762 - (void)windowDidExitFullScreen:(NSNotification*)notification { 768 - (void)windowDidExitFullScreen:(NSNotification*)notification {
763 DCHECK(exitingAppKitFullscreen_); 769 DCHECK(exitingAppKitFullscreen_);
764 770
765 if (notification) // For System Fullscreen when non-nil. 771 if (notification) // For System Fullscreen when non-nil.
766 [self deregisterForContentViewResizeNotifications]; 772 [self deregisterForContentViewResizeNotifications];
767 773
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(); 774 browser_->WindowFullscreenStateChanged();
772 775
773 exitingAppKitFullscreen_ = NO; 776 exitingAppKitFullscreen_ = NO;
774 fullscreenTransition_.reset(); 777 fullscreenTransition_.reset();
778
779 blockLayoutSubviews_ = NO;
775 } 780 }
776 781
777 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { 782 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window {
778 [self deregisterForContentViewResizeNotifications]; 783 [self deregisterForContentViewResizeNotifications];
779 enteringAppKitFullscreen_ = NO; 784 enteringAppKitFullscreen_ = NO;
780 fullscreenTransition_.reset(); 785 fullscreenTransition_.reset();
786 blockLayoutSubviews_ = NO;
781 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; 787 [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
782 } 788 }
783 789
784 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { 790 - (void)windowDidFailToExitFullScreen:(NSWindow*)window {
785 [self deregisterForContentViewResizeNotifications]; 791 [self deregisterForContentViewResizeNotifications];
786 exitingAppKitFullscreen_ = NO; 792 exitingAppKitFullscreen_ = NO;
787 fullscreenTransition_.reset(); 793 fullscreenTransition_.reset();
794 blockLayoutSubviews_ = NO;
788 // Force a relayout to try and get the window back into a reasonable state. 795 // Force a relayout to try and get the window back into a reasonable state.
789 [self layoutSubviews]; 796 [self layoutSubviews];
790 } 797 }
791 798
799 - (void)adjustUIForExitingFullscreen {
800 [self destroyFullscreenExitBubbleIfNecessary];
801 [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
802 }
803
804 - (void)adjustUIForEnteringFullscreen {
erikchen 2015/10/07 23:17:53 Add declarations for this method and the one above
spqchan 2015/10/07 23:53:26 Done.
805 fullscreen_mac::SlidingStyle style;
806 if (browser_->exclusive_access_manager()
807 ->fullscreen_controller()
808 ->IsWindowFullscreenForTabOrPending()) {
809 style = fullscreen_mac::OMNIBOX_TABS_NONE;
810 } else if (enteringPresentationMode_) {
811 style = fullscreen_mac::OMNIBOX_TABS_HIDDEN;
812 } else {
813 style = fullscreen_mac::OMNIBOX_TABS_PRESENT;
814 }
815
816 [self adjustUIForSlidingFullscreenStyle:style];
817 }
818
792 - (void)enableBarVisibilityUpdates { 819 - (void)enableBarVisibilityUpdates {
793 // Early escape if there's nothing to do. 820 // Early escape if there's nothing to do.
794 if (barVisibilityUpdatesEnabled_) 821 if (barVisibilityUpdatesEnabled_)
795 return; 822 return;
796 823
797 barVisibilityUpdatesEnabled_ = YES; 824 barVisibilityUpdatesEnabled_ = YES;
798 825
799 if ([barVisibilityLocks_ count]) 826 if ([barVisibilityLocks_ count])
800 [presentationModeController_ ensureOverlayShownWithAnimation:NO delay:NO]; 827 [presentationModeController_ ensureOverlayShownWithAnimation:NO delay:NO];
801 else 828 else
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 initExitWithWindow:framedBrowserWindow 1157 initExitWithWindow:framedBrowserWindow
1131 frame:savedRegularWindowFrame_]); 1158 frame:savedRegularWindowFrame_]);
1132 1159
1133 return [fullscreenTransition_ customWindowsForFullScreenTransition]; 1160 return [fullscreenTransition_ customWindowsForFullScreenTransition];
1134 } 1161 }
1135 1162
1136 - (void)window:(NSWindow*)window 1163 - (void)window:(NSWindow*)window
1137 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { 1164 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration {
1138 DCHECK([window isEqual:self.window]); 1165 DCHECK([window isEqual:self.window]);
1139 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; 1166 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration];
1167
1168 base::AutoReset<BOOL> auto_reset_in_run(&blockLayoutSubviews_, NO);
1169 [self adjustUIForEnteringFullscreen];
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 base::AutoReset<BOOL> auto_reset_in_run(&blockLayoutSubviews_, NO);
1179 [self adjustUIForExitingFullscreen];
1147 } 1180 }
1148 1181
1149 - (BOOL)shouldConstrainFrameRect { 1182 - (BOOL)shouldConstrainFrameRect {
1150 if ([fullscreenTransition_ shouldWindowBeUnconstrained]) 1183 if ([fullscreenTransition_ shouldWindowBeUnconstrained])
1151 return NO; 1184 return NO;
1152 1185
1153 return [super shouldConstrainFrameRect]; 1186 return [super shouldConstrainFrameRect];
1154 } 1187 }
1155 1188
1156 - (WebContents*)webContents { 1189 - (WebContents*)webContents {
1157 return browser_->tab_strip_model()->GetActiveWebContents(); 1190 return browser_->tab_strip_model()->GetActiveWebContents();
1158 } 1191 }
1159 1192
1160 - (PermissionBubbleManager*)permissionBubbleManager { 1193 - (PermissionBubbleManager*)permissionBubbleManager {
1161 if (WebContents* contents = [self webContents]) 1194 if (WebContents* contents = [self webContents])
1162 return PermissionBubbleManager::FromWebContents(contents); 1195 return PermissionBubbleManager::FromWebContents(contents);
1163 return nil; 1196 return nil;
1164 } 1197 }
1165 1198
1166 @end // @implementation BrowserWindowController(Private) 1199 @end // @implementation BrowserWindowController(Private)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller_private.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698