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

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

Issue 1276383004: Implemented fullscreen exit animation with AppKit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed format issues Created 5 years, 4 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
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 #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"
11 #include "base/mac/foundation_util.h" 11 #include "base/mac/foundation_util.h"
12 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
13 #import "base/mac/scoped_nsobject.h" 13 #import "base/mac/scoped_nsobject.h"
14 #import "base/mac/sdk_forward_declarations.h" 14 #import "base/mac/sdk_forward_declarations.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/prefs/scoped_user_pref_update.h" 17 #include "base/prefs/scoped_user_pref_update.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/fullscreen.h" 19 #include "chrome/browser/fullscreen.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 21 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
22 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 22 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_window_state.h" 24 #include "chrome/browser/ui/browser_window_state.h"
25 #import "chrome/browser/ui/cocoa/browser_window_enter_fullscreen_transition.h" 25 #import "chrome/browser/ui/cocoa/browser_window_fullscreen_transition.h"
26 #import "chrome/browser/ui/cocoa/browser_window_layout.h" 26 #import "chrome/browser/ui/cocoa/browser_window_layout.h"
27 #import "chrome/browser/ui/cocoa/custom_frame_view.h" 27 #import "chrome/browser/ui/cocoa/custom_frame_view.h"
28 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" 28 #import "chrome/browser/ui/cocoa/dev_tools_controller.h"
29 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 29 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
30 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 30 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
31 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h" 31 #import "chrome/browser/ui/cocoa/floating_bar_backing_view.h"
32 #import "chrome/browser/ui/cocoa/framed_browser_window.h" 32 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
33 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 33 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
34 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 34 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
35 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 35 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
36 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" 36 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
37 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" 37 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
38 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" 38 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h"
39 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" 39 #import "chrome/browser/ui/cocoa/status_bubble_mac.h"
40 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" 40 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
41 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 42 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
42 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 43 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
43 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" 44 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h"
44 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 45 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" 46 #include "chrome/browser/ui/tabs/tab_strip_model.h"
46 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 47 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
47 #include "chrome/common/chrome_switches.h" 48 #include "chrome/common/chrome_switches.h"
48 #include "content/public/browser/render_widget_host_view.h" 49 #include "content/public/browser/render_widget_host_view.h"
49 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
50 #import "ui/base/cocoa/focus_tracker.h" 51 #import "ui/base/cocoa/focus_tracker.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {
219 // Suppress title drawing if necessary. 220 // Suppress title drawing if necessary.
220 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)]) 221 if ([self.window respondsToSelector:@selector(setShouldHideTitle:)])
221 [(id)self.window setShouldHideTitle:![self hasTitleBar]]; 222 [(id)self.window setShouldHideTitle:![self hasTitleBar]];
222 223
223 [bookmarkBarController_ updateHiddenState]; 224 [bookmarkBarController_ updateHiddenState];
225
224 [self updateSubviewZOrder]; 226 [self updateSubviewZOrder];
225 227
226 base::scoped_nsobject<BrowserWindowLayout> layout( 228 base::scoped_nsobject<BrowserWindowLayout> layout(
227 [[BrowserWindowLayout alloc] init]); 229 [[BrowserWindowLayout alloc] init]);
228 [self updateLayoutParameters:layout]; 230 [self updateLayoutParameters:layout];
229 [self applyLayout:layout]; 231 [self applyLayout:layout];
230 232
231 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]]; 233 [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]];
232 234
233 // Will update the location of the permission bubble when showing/hiding the 235 // Will update the location of the permission bubble when showing/hiding the
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 684
683 - (void)windowWillEnterFullScreen:(NSNotification*)notification { 685 - (void)windowWillEnterFullScreen:(NSNotification*)notification {
684 RecordFullscreenWindowLocation([self window]); 686 RecordFullscreenWindowLocation([self window]);
685 RecordFullscreenStyle(enteringPresentationMode_ ? PRESENTATION_MODE 687 RecordFullscreenStyle(enteringPresentationMode_ ? PRESENTATION_MODE
686 : CANONICAL_FULLSCREEN); 688 : CANONICAL_FULLSCREEN);
687 689
688 if (notification) // For System Fullscreen when non-nil. 690 if (notification) // For System Fullscreen when non-nil.
689 [self registerForContentViewResizeNotifications]; 691 [self registerForContentViewResizeNotifications];
690 692
691 NSWindow* window = [self window]; 693 NSWindow* window = [self window];
692 savedRegularWindowFrame_ = [window frame]; 694 savedRegularWindowFrame_ = [window frame];
693 BOOL mode = enteringPresentationMode_ || 695 BOOL mode = enteringPresentationMode_ ||
694 browser_->exclusive_access_manager() 696 browser_->exclusive_access_manager()
695 ->fullscreen_controller() 697 ->fullscreen_controller()
696 ->IsWindowFullscreenForTabOrPending(); 698 ->IsWindowFullscreenForTabOrPending();
697 enteringAppKitFullscreen_ = YES; 699 enteringAppKitFullscreen_ = YES;
698 enteringAppKitFullscreenOnPrimaryScreen_ = 700 enteringAppKitFullscreenOnPrimaryScreen_ =
699 [[[self window] screen] isEqual:[[NSScreen screens] objectAtIndex:0]]; 701 [[[self window] screen] isEqual:[[NSScreen screens] objectAtIndex:0]];
700 702
701 fullscreen_mac::SlidingStyle style = 703 fullscreen_mac::SlidingStyle style =
702 mode ? fullscreen_mac::OMNIBOX_TABS_HIDDEN 704 mode ? fullscreen_mac::OMNIBOX_TABS_HIDDEN
703 : fullscreen_mac::OMNIBOX_TABS_PRESENT; 705 : fullscreen_mac::OMNIBOX_TABS_PRESENT;
704 706
705 [self adjustUIForSlidingFullscreenStyle:style]; 707 [self adjustUIForSlidingFullscreenStyle:style];
706 } 708 }
707 709
708 - (void)windowDidEnterFullScreen:(NSNotification*)notification { 710 - (void)windowDidEnterFullScreen:(NSNotification*)notification {
709 enterFullscreenTransition_.reset();
erikchen 2015/08/10 18:06:24 did you mean to replace with fullscreenTransition_
spqchan1 2015/08/11 21:43:47 Done
710
711 // In Yosemite, some combination of the titlebar and toolbar always show in 711 // In Yosemite, some combination of the titlebar and toolbar always show in
712 // full-screen mode. We do not want either to show. Search for the window that 712 // full-screen mode. We do not want either to show. Search for the window that
713 // contains the views, and hide it. There is no need to ever unhide the view. 713 // contains the views, and hide it. There is no need to ever unhide the view.
714 // http://crbug.com/380235 714 // http://crbug.com/380235
715 if (base::mac::IsOSYosemiteOrLater()) { 715 if (base::mac::IsOSYosemiteOrLater()) {
716 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { 716 for (NSWindow* window in [[NSApplication sharedApplication] windows]) {
717 if ([window 717 if ([window
718 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { 718 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) {
719 [[window contentView] setHidden:YES]; 719 [[window contentView] setHidden:YES];
720 } 720 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 enteringPresentationMode_ = NO; 754 enteringPresentationMode_ = NO;
755 755
756 [self showFullscreenExitBubbleIfNecessary]; 756 [self showFullscreenExitBubbleIfNecessary];
757 browser_->WindowFullscreenStateChanged(); 757 browser_->WindowFullscreenStateChanged();
758 [[[self window] contentView] setWantsLayer:windowViewWantsLayer_]; 758 [[[self window] contentView] setWantsLayer:windowViewWantsLayer_];
759 } 759 }
760 760
761 - (void)windowWillExitFullScreen:(NSNotification*)notification { 761 - (void)windowWillExitFullScreen:(NSNotification*)notification {
762 if (notification) // For System Fullscreen when non-nil. 762 if (notification) // For System Fullscreen when non-nil.
763 [self registerForContentViewResizeNotifications]; 763 [self registerForContentViewResizeNotifications];
764 exitingAppKitFullscreen_ = YES;
765
764 [self destroyFullscreenExitBubbleIfNecessary]; 766 [self destroyFullscreenExitBubbleIfNecessary];
765 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; 767 [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
766 } 768 }
767 769
768 - (void)windowDidExitFullScreen:(NSNotification*)notification { 770 - (void)windowDidExitFullScreen:(NSNotification*)notification {
771 fullscreenTransition_.reset();
769 if (notification) // For System Fullscreen when non-nil. 772 if (notification) // For System Fullscreen when non-nil.
770 [self deregisterForContentViewResizeNotifications]; 773 [self deregisterForContentViewResizeNotifications];
774
775 FramedBrowserWindow* framedWindow = (FramedBrowserWindow*)[self window];
776 [framedWindow setFrameAndStyleLock:NO];
777
778 if (exitingAppKitFullscreen_) {
erikchen 2015/08/10 18:06:24 Is it possible for this to be false? If not, you s
spqchan1 2015/08/11 21:43:47 Done.
779 [self layoutSubviews];
780 }
781 exitingAppKitFullscreen_ = NO;
782
771 browser_->WindowFullscreenStateChanged(); 783 browser_->WindowFullscreenStateChanged();
772 } 784 }
773 785
774 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { 786 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window {
775 [self deregisterForContentViewResizeNotifications]; 787 [self deregisterForContentViewResizeNotifications];
776 enteringAppKitFullscreen_ = NO; 788 enteringAppKitFullscreen_ = NO;
789 FramedBrowserWindow* framedWindow = (FramedBrowserWindow*)[self window];
erikchen 2015/08/10 18:06:24 We don't use C style casts. See other examples in
spqchan1 2015/08/11 21:43:47 Done.
790 [framedWindow setFrameAndStyleLock:NO];
777 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; 791 [self adjustUIForExitingFullscreenAndStopOmniboxSliding];
792
778 } 793 }
779 794
780 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { 795 - (void)windowDidFailToExitFullScreen:(NSWindow*)window {
781 [self deregisterForContentViewResizeNotifications]; 796 [self deregisterForContentViewResizeNotifications];
782 797 exitingAppKitFullscreen_ = NO;
783 // Force a relayout to try and get the window back into a reasonable state. 798 // Force a relayout to try and get the window back into a reasonable state.
784 [self layoutSubviews]; 799 [self layoutSubviews];
785 } 800 }
786 801
787 - (void)enableBarVisibilityUpdates { 802 - (void)enableBarVisibilityUpdates {
788 // Early escape if there's nothing to do. 803 // Early escape if there's nothing to do.
789 if (barVisibilityUpdatesEnabled_) 804 if (barVisibilityUpdatesEnabled_)
790 return; 805 return;
791 806
792 barVisibilityUpdatesEnabled_ = YES; 807 barVisibilityUpdatesEnabled_ = YES;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 // We need to return where the button should be positioned. 884 // We need to return where the button should be positioned.
870 NSView* rootView = [[[self window] contentView] superview]; 885 NSView* rootView = [[[self window] contentView] superview];
871 if ([rootView respondsToSelector:@selector(_fullScreenButtonOrigin)]) 886 if ([rootView respondsToSelector:@selector(_fullScreenButtonOrigin)])
872 buttonFrame.origin = [rootView _fullScreenButtonOrigin]; 887 buttonFrame.origin = [rootView _fullScreenButtonOrigin];
873 888
874 return buttonFrame; 889 return buttonFrame;
875 } 890 }
876 891
877 - (void)updateLayoutParameters:(BrowserWindowLayout*)layout { 892 - (void)updateLayoutParameters:(BrowserWindowLayout*)layout {
878 [layout setContentViewSize:[[[self window] contentView] bounds].size]; 893 [layout setContentViewSize:[[[self window] contentView] bounds].size];
879 [layout setWindowSize:[[self window] frame].size]; 894
895 NSSize windowSize = (exitingAppKitFullscreen_) ?
896 [[[self window] contentView] bounds].size : [[self window] frame].size;
erikchen 2015/08/10 18:06:24 Can you explain this logic? Also, can you move the
spqchan1 2015/08/12 21:07:36 Done, moved logic into "getDesiredWindowLayoutSize
897 [layout setWindowSize:windowSize];
880 898
881 [layout setInAnyFullscreen:[self isInAnyFullscreenMode]]; 899 [layout setInAnyFullscreen:[self isInAnyFullscreenMode]];
882 [layout setFullscreenSlidingStyle: 900 [layout setFullscreenSlidingStyle:
883 presentationModeController_.get().slidingStyle]; 901 presentationModeController_.get().slidingStyle];
884 [layout setFullscreenMenubarOffset: 902 [layout setFullscreenMenubarOffset:
885 [presentationModeController_ menubarOffset]]; 903 [presentationModeController_ menubarOffset]];
886 [layout setFullscreenToolbarFraction: 904 [layout setFullscreenToolbarFraction:
887 [presentationModeController_ toolbarFraction]]; 905 [presentationModeController_ toolbarFraction]];
888 906
889 [layout setHasTabStrip:[self hasTabStrip]]; 907 [layout setHasTabStrip:[self hasTabStrip]];
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 1105
1088 return YES; 1106 return YES;
1089 } 1107 }
1090 1108
1091 - (NSArray*)customWindowsToEnterFullScreenForWindow:(NSWindow*)window { 1109 - (NSArray*)customWindowsToEnterFullScreenForWindow:(NSWindow*)window {
1092 DCHECK([window isEqual:self.window]); 1110 DCHECK([window isEqual:self.window]);
1093 1111
1094 if (![self shouldUseCustomAppKitFullscreenTransition]) 1112 if (![self shouldUseCustomAppKitFullscreenTransition])
1095 return nil; 1113 return nil;
1096 1114
1097 enterFullscreenTransition_.reset( 1115 FramedBrowserWindow* framedBrowserWindow =
1098 [[BrowserWindowEnterFullscreenTransition alloc] 1116 base::mac::ObjCCast<FramedBrowserWindow>([self window]);
1099 initWithWindow:self.window]); 1117 fullscreenTransition_.reset(
1100 return [enterFullscreenTransition_ customWindowsToEnterFullScreen]; 1118 [[BrowserWindowFullscreenTransition alloc]
1119 initWithWindow:framedBrowserWindow]);
1120 return [fullscreenTransition_ customWindowsToEnterFullScreenTransition];
1101 } 1121 }
1102 1122
1123 - (NSArray*)customWindowsToExitFullScreenForWindow:(NSWindow*)window {
1124 DCHECK([window isEqual:self.window]);
1125
1126 if (![self shouldUseCustomAppKitFullscreenTransition]) {
erikchen 2015/08/10 18:06:24 nit: The Chrome style is typically to only use {}
spqchan1 2015/08/11 21:43:47 Done.
1127 return nil;
1128 }
1129
1130 return [fullscreenTransition_ customWindowsToExitFullScreenTransition];
1131 }
1132
1133
1103 - (void)window:(NSWindow*)window 1134 - (void)window:(NSWindow*)window
1104 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { 1135 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration {
1105 DCHECK([window isEqual:self.window]); 1136 DCHECK([window isEqual:self.window]);
1106 [enterFullscreenTransition_ 1137 [fullscreenTransition_
1107 startCustomAnimationToEnterFullScreenWithDuration:duration]; 1138 startCustomEnterFullScreenAnimationWithDuration:duration];
1108 } 1139 }
1109 1140
1141 - (void)window:(NSWindow*)window
1142 startCustomAnimationToExitFullScreenWithDuration:(NSTimeInterval)duration {
1143 DCHECK([window isEqual:self.window]);
1144
1145 [fullscreenTransition_
1146 startCustomExitFullScreenAnimationWithDuration:duration];
1147 }
1148
1149
1110 - (BOOL)shouldConstrainFrameRect { 1150 - (BOOL)shouldConstrainFrameRect {
1111 if ([enterFullscreenTransition_ shouldWindowBeUnconstrained]) 1151 if ([fullscreenTransition_ shouldWindowBeUnconstrained])
1112 return NO; 1152 return NO;
1113 1153
1114 return [super shouldConstrainFrameRect]; 1154 return [super shouldConstrainFrameRect];
1115 } 1155 }
1116 1156
1117 - (WebContents*)webContents { 1157 - (WebContents*)webContents {
1118 return browser_->tab_strip_model()->GetActiveWebContents(); 1158 return browser_->tab_strip_model()->GetActiveWebContents();
1119 } 1159 }
1120 1160
1121 - (PermissionBubbleManager*)permissionBubbleManager { 1161 - (PermissionBubbleManager*)permissionBubbleManager {
1122 if (WebContents* contents = [self webContents]) 1162 if (WebContents* contents = [self webContents])
1123 return PermissionBubbleManager::FromWebContents(contents); 1163 return PermissionBubbleManager::FromWebContents(contents);
1124 return nil; 1164 return nil;
1125 } 1165 }
1126 1166
1127 @end // @implementation BrowserWindowController(Private) 1167 @end // @implementation BrowserWindowController(Private)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698