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" |
| 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 Loading... | |
| 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 | |
|
erikchen
2015/08/11 22:42:54
please don't randomly add whitespace
spqchan1
2015/08/12 19:34:41
Done.
| |
| 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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); | |
| 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 fullscreenTransition_.reset(); | |
|
erikchen
2015/08/11 22:42:54
I see that you changed s/enterFullscreenTransition
spqchan1
2015/08/12 19:34:41
Originally, fullscreenTransition was going take ca
| |
| 715 if (base::mac::IsOSYosemiteOrLater()) { | 716 if (base::mac::IsOSYosemiteOrLater()) { |
| 716 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { | 717 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { |
| 717 if ([window | 718 if ([window |
| 718 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { | 719 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { |
| 719 [[window contentView] setHidden:YES]; | 720 [[window contentView] setHidden:YES]; |
| 720 } | 721 } |
| 721 } | 722 } |
| 722 } | 723 } |
| 723 | 724 |
| 724 if ([self shouldUseMavericksAppKitFullscreenHack]) { | 725 if ([self shouldUseMavericksAppKitFullscreenHack]) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 754 enteringPresentationMode_ = NO; | 755 enteringPresentationMode_ = NO; |
| 755 | 756 |
| 756 [self showFullscreenExitBubbleIfNecessary]; | 757 [self showFullscreenExitBubbleIfNecessary]; |
| 757 browser_->WindowFullscreenStateChanged(); | 758 browser_->WindowFullscreenStateChanged(); |
| 758 [[[self window] contentView] setWantsLayer:windowViewWantsLayer_]; | 759 [[[self window] contentView] setWantsLayer:windowViewWantsLayer_]; |
| 759 } | 760 } |
| 760 | 761 |
| 761 - (void)windowWillExitFullScreen:(NSNotification*)notification { | 762 - (void)windowWillExitFullScreen:(NSNotification*)notification { |
| 762 if (notification) // For System Fullscreen when non-nil. | 763 if (notification) // For System Fullscreen when non-nil. |
| 763 [self registerForContentViewResizeNotifications]; | 764 [self registerForContentViewResizeNotifications]; |
| 765 exitingAppKitFullscreen_ = YES; | |
| 766 | |
| 764 [self destroyFullscreenExitBubbleIfNecessary]; | 767 [self destroyFullscreenExitBubbleIfNecessary]; |
| 765 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 768 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; |
| 766 } | 769 } |
| 767 | 770 |
| 768 - (void)windowDidExitFullScreen:(NSNotification*)notification { | 771 - (void)windowDidExitFullScreen:(NSNotification*)notification { |
| 772 DCHECK(exitingAppKitFullscreen_); | |
| 773 | |
| 769 if (notification) // For System Fullscreen when non-nil. | 774 if (notification) // For System Fullscreen when non-nil. |
| 770 [self deregisterForContentViewResizeNotifications]; | 775 [self deregisterForContentViewResizeNotifications]; |
| 776 | |
| 777 FramedBrowserWindow* framedBrowserWindow = | |
| 778 base::mac::ObjCCast<FramedBrowserWindow>([self window]); | |
| 779 [framedBrowserWindow setFrameAndStyleMaskLock:NO]; | |
| 780 | |
| 781 [self layoutSubviews]; | |
| 771 browser_->WindowFullscreenStateChanged(); | 782 browser_->WindowFullscreenStateChanged(); |
| 783 | |
| 784 exitingAppKitFullscreen_ = NO; | |
| 785 fullscreenTransition_.reset(); | |
| 772 } | 786 } |
| 773 | 787 |
| 774 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { | 788 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { |
| 775 [self deregisterForContentViewResizeNotifications]; | 789 [self deregisterForContentViewResizeNotifications]; |
| 776 enteringAppKitFullscreen_ = NO; | 790 enteringAppKitFullscreen_ = NO; |
| 791 fullscreenTransition_.reset(); | |
| 777 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; | 792 [self adjustUIForExitingFullscreenAndStopOmniboxSliding]; |
| 778 } | 793 } |
| 779 | 794 |
| 780 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { | 795 - (void)windowDidFailToExitFullScreen:(NSWindow*)window { |
| 781 [self deregisterForContentViewResizeNotifications]; | 796 [self deregisterForContentViewResizeNotifications]; |
| 782 | 797 exitingAppKitFullscreen_ = NO; |
| 798 fullscreenTransition_.reset(); | |
| 799 FramedBrowserWindow* framedBrowserWindow = | |
| 800 base::mac::ObjCCast<FramedBrowserWindow>([self window]); | |
| 801 [framedBrowserWindow setFrameAndStyleMaskLock:NO]; | |
| 783 // Force a relayout to try and get the window back into a reasonable state. | 802 // Force a relayout to try and get the window back into a reasonable state. |
| 784 [self layoutSubviews]; | 803 [self layoutSubviews]; |
| 785 } | 804 } |
| 786 | 805 |
| 787 - (void)enableBarVisibilityUpdates { | 806 - (void)enableBarVisibilityUpdates { |
| 788 // Early escape if there's nothing to do. | 807 // Early escape if there's nothing to do. |
| 789 if (barVisibilityUpdatesEnabled_) | 808 if (barVisibilityUpdatesEnabled_) |
| 790 return; | 809 return; |
| 791 | 810 |
| 792 barVisibilityUpdatesEnabled_ = YES; | 811 barVisibilityUpdatesEnabled_ = YES; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 // We need to return where the button should be positioned. | 888 // We need to return where the button should be positioned. |
| 870 NSView* rootView = [[[self window] contentView] superview]; | 889 NSView* rootView = [[[self window] contentView] superview]; |
| 871 if ([rootView respondsToSelector:@selector(_fullScreenButtonOrigin)]) | 890 if ([rootView respondsToSelector:@selector(_fullScreenButtonOrigin)]) |
| 872 buttonFrame.origin = [rootView _fullScreenButtonOrigin]; | 891 buttonFrame.origin = [rootView _fullScreenButtonOrigin]; |
| 873 | 892 |
| 874 return buttonFrame; | 893 return buttonFrame; |
| 875 } | 894 } |
| 876 | 895 |
| 877 - (void)updateLayoutParameters:(BrowserWindowLayout*)layout { | 896 - (void)updateLayoutParameters:(BrowserWindowLayout*)layout { |
| 878 [layout setContentViewSize:[[[self window] contentView] bounds].size]; | 897 [layout setContentViewSize:[[[self window] contentView] bounds].size]; |
| 879 [layout setWindowSize:[[self window] frame].size]; | 898 |
| 899 NSSize windowSize = (fullscreenTransition_.get()) | |
| 900 ? [fullscreenTransition_ getDesiredWindowLayoutSize] | |
| 901 : [[self window] frame].size; | |
| 902 | |
| 903 [layout setWindowSize:windowSize]; | |
| 880 | 904 |
| 881 [layout setInAnyFullscreen:[self isInAnyFullscreenMode]]; | 905 [layout setInAnyFullscreen:[self isInAnyFullscreenMode]]; |
| 882 [layout setFullscreenSlidingStyle: | 906 [layout setFullscreenSlidingStyle: |
| 883 presentationModeController_.get().slidingStyle]; | 907 presentationModeController_.get().slidingStyle]; |
| 884 [layout setFullscreenMenubarOffset: | 908 [layout setFullscreenMenubarOffset: |
| 885 [presentationModeController_ menubarOffset]]; | 909 [presentationModeController_ menubarOffset]]; |
| 886 [layout setFullscreenToolbarFraction: | 910 [layout setFullscreenToolbarFraction: |
| 887 [presentationModeController_ toolbarFraction]]; | 911 [presentationModeController_ toolbarFraction]]; |
| 888 | 912 |
| 889 [layout setHasTabStrip:[self hasTabStrip]]; | 913 [layout setHasTabStrip:[self hasTabStrip]]; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 | 1111 |
| 1088 return YES; | 1112 return YES; |
| 1089 } | 1113 } |
| 1090 | 1114 |
| 1091 - (NSArray*)customWindowsToEnterFullScreenForWindow:(NSWindow*)window { | 1115 - (NSArray*)customWindowsToEnterFullScreenForWindow:(NSWindow*)window { |
| 1092 DCHECK([window isEqual:self.window]); | 1116 DCHECK([window isEqual:self.window]); |
| 1093 | 1117 |
| 1094 if (![self shouldUseCustomAppKitFullscreenTransition]) | 1118 if (![self shouldUseCustomAppKitFullscreenTransition]) |
| 1095 return nil; | 1119 return nil; |
| 1096 | 1120 |
| 1097 enterFullscreenTransition_.reset( | 1121 FramedBrowserWindow* framedBrowserWindow = |
| 1098 [[BrowserWindowEnterFullscreenTransition alloc] | 1122 base::mac::ObjCCast<FramedBrowserWindow>([self window]); |
| 1099 initWithWindow:self.window]); | 1123 fullscreenTransition_.reset([[BrowserWindowFullscreenTransition alloc] |
| 1100 return [enterFullscreenTransition_ customWindowsToEnterFullScreen]; | 1124 initEnterWithWindow:framedBrowserWindow]); |
| 1125 return [fullscreenTransition_ customWindowsForFullScreenTransition]; | |
| 1126 } | |
| 1127 | |
| 1128 - (NSArray*)customWindowsToExitFullScreenForWindow:(NSWindow*)window { | |
| 1129 DCHECK([window isEqual:self.window]); | |
| 1130 | |
| 1131 if (![self shouldUseCustomAppKitFullscreenTransition]) | |
| 1132 return nil; | |
| 1133 | |
| 1134 FramedBrowserWindow* framedBrowserWindow = | |
| 1135 base::mac::ObjCCast<FramedBrowserWindow>([self window]); | |
| 1136 fullscreenTransition_.reset([[BrowserWindowFullscreenTransition alloc] | |
| 1137 initExitWithWindow:framedBrowserWindow | |
| 1138 frame:savedRegularWindowFrame_]); | |
| 1139 | |
| 1140 return [fullscreenTransition_ customWindowsForFullScreenTransition]; | |
| 1101 } | 1141 } |
| 1102 | 1142 |
| 1103 - (void)window:(NSWindow*)window | 1143 - (void)window:(NSWindow*)window |
| 1104 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { | 1144 startCustomAnimationToEnterFullScreenWithDuration:(NSTimeInterval)duration { |
| 1105 DCHECK([window isEqual:self.window]); | 1145 DCHECK([window isEqual:self.window]); |
| 1106 [enterFullscreenTransition_ | 1146 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; |
| 1107 startCustomAnimationToEnterFullScreenWithDuration:duration]; | 1147 } |
| 1148 | |
| 1149 - (void)window:(NSWindow*)window | |
| 1150 startCustomAnimationToExitFullScreenWithDuration:(NSTimeInterval)duration { | |
| 1151 DCHECK([window isEqual:self.window]); | |
| 1152 | |
| 1153 [fullscreenTransition_ startCustomFullScreenAnimationWithDuration:duration]; | |
| 1108 } | 1154 } |
| 1109 | 1155 |
| 1110 - (BOOL)shouldConstrainFrameRect { | 1156 - (BOOL)shouldConstrainFrameRect { |
| 1111 if ([enterFullscreenTransition_ shouldWindowBeUnconstrained]) | 1157 if ([fullscreenTransition_ shouldWindowBeUnconstrained]) |
| 1112 return NO; | 1158 return NO; |
| 1113 | 1159 |
| 1114 return [super shouldConstrainFrameRect]; | 1160 return [super shouldConstrainFrameRect]; |
| 1115 } | 1161 } |
| 1116 | 1162 |
| 1117 - (WebContents*)webContents { | 1163 - (WebContents*)webContents { |
| 1118 return browser_->tab_strip_model()->GetActiveWebContents(); | 1164 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 1119 } | 1165 } |
| 1120 | 1166 |
| 1121 - (PermissionBubbleManager*)permissionBubbleManager { | 1167 - (PermissionBubbleManager*)permissionBubbleManager { |
| 1122 if (WebContents* contents = [self webContents]) | 1168 if (WebContents* contents = [self webContents]) |
| 1123 return PermissionBubbleManager::FromWebContents(contents); | 1169 return PermissionBubbleManager::FromWebContents(contents); |
| 1124 return nil; | 1170 return nil; |
| 1125 } | 1171 } |
| 1126 | 1172 |
| 1127 @end // @implementation BrowserWindowController(Private) | 1173 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |