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/mac_util.h" | 11 #include "base/mac/mac_util.h" |
11 #import "base/mac/scoped_nsobject.h" | 12 #import "base/mac/scoped_nsobject.h" |
12 #import "base/mac/sdk_forward_declarations.h" | 13 #import "base/mac/sdk_forward_declarations.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/fullscreen.h" | 18 #include "chrome/browser/fullscreen.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 RecordFullscreenHistogram(APPKIT_FULLSCREEN_MECHANISM, [self window]); | 676 RecordFullscreenHistogram(APPKIT_FULLSCREEN_MECHANISM, [self window]); |
676 | 677 |
677 if (notification) // For System Fullscreen when non-nil. | 678 if (notification) // For System Fullscreen when non-nil. |
678 [self registerForContentViewResizeNotifications]; | 679 [self registerForContentViewResizeNotifications]; |
679 | 680 |
680 NSWindow* window = [self window]; | 681 NSWindow* window = [self window]; |
681 savedRegularWindowFrame_ = [window frame]; | 682 savedRegularWindowFrame_ = [window frame]; |
682 BOOL mode = enteringPresentationMode_ || | 683 BOOL mode = enteringPresentationMode_ || |
683 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); | 684 browser_->fullscreen_controller()->IsWindowFullscreenForTabOrPending(); |
684 enteringAppKitFullscreen_ = YES; | 685 enteringAppKitFullscreen_ = YES; |
686 enteringAppKitFullscreenOnPrimaryScreen_ = | |
687 [[[self window] screen] isEqual:[[NSScreen screens] objectAtIndex:0]]; | |
685 | 688 |
686 fullscreen_mac::SlidingStyle style = | 689 fullscreen_mac::SlidingStyle style = |
687 mode ? fullscreen_mac::OMNIBOX_TABS_HIDDEN | 690 mode ? fullscreen_mac::OMNIBOX_TABS_HIDDEN |
688 : fullscreen_mac::OMNIBOX_TABS_PRESENT; | 691 : fullscreen_mac::OMNIBOX_TABS_PRESENT; |
689 | 692 |
690 [self adjustUIForSlidingFullscreenStyle:style]; | 693 [self adjustUIForSlidingFullscreenStyle:style]; |
691 } | 694 } |
692 | 695 |
693 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 696 - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
694 // In Yosemite, some combination of the titlebar and toolbar always show in | 697 // In Yosemite, some combination of the titlebar and toolbar always show in |
695 // full-screen mode. We do not want either to show. Search for the window that | 698 // full-screen mode. We do not want either to show. Search for the window that |
696 // contains the views, and hide it. There is no need to ever unhide the view. | 699 // contains the views, and hide it. There is no need to ever unhide the view. |
697 // http://crbug.com/380235 | 700 // http://crbug.com/380235 |
698 if (base::mac::IsOSYosemiteOrLater()) { | 701 if (base::mac::IsOSYosemiteOrLater()) { |
699 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { | 702 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { |
700 if ([window | 703 if ([window |
701 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { | 704 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { |
702 [[window contentView] setHidden:YES]; | 705 [[window contentView] setHidden:YES]; |
703 } | 706 } |
704 } | 707 } |
705 } | 708 } |
706 | 709 |
710 if ([self shouldUseMavericksAppKitFullscreenHack]) { | |
711 // Apply a hack to fix the size of the window. This is the last run of the | |
712 // MessageLoop where the hack will not work, so dispatch the hack to the | |
713 // top of the MessageLoop. | |
714 base::Callback<void(void)> callback = base::BindBlock(^{ | |
715 if (![self isInAppKitFullscreen]) | |
716 return; | |
717 | |
718 // The window's frame should be exactly 22 points too short. | |
719 CGFloat kExpectedHeightDifference = 22; | |
720 NSRect currentFrame = [[self window] frame]; | |
721 NSRect expectedFrame = [[[self window] screen] frame]; | |
722 if (!NSEqualPoints(currentFrame.origin, expectedFrame.origin)) | |
723 return; | |
724 if (currentFrame.size.width != expectedFrame.size.width) | |
725 return; | |
726 CGFloat heightDelta = | |
727 expectedFrame.size.height - currentFrame.size.height; | |
728 if (fabs(heightDelta - kExpectedHeightDifference) > 0.01) | |
729 return; | |
730 | |
731 [[self window] setFrame:expectedFrame display:YES]; | |
732 }); | |
733 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | |
734 } | |
735 | |
707 if (notification) // For System Fullscreen when non-nil. | 736 if (notification) // For System Fullscreen when non-nil. |
708 [self deregisterForContentViewResizeNotifications]; | 737 [self deregisterForContentViewResizeNotifications]; |
709 enteringAppKitFullscreen_ = NO; | 738 enteringAppKitFullscreen_ = NO; |
710 enteringImmersiveFullscreen_ = NO; | 739 enteringImmersiveFullscreen_ = NO; |
711 enteringPresentationMode_ = NO; | 740 enteringPresentationMode_ = NO; |
712 | 741 |
713 [self showFullscreenExitBubbleIfNecessary]; | 742 [self showFullscreenExitBubbleIfNecessary]; |
714 browser_->WindowFullscreenStateChanged(); | 743 browser_->WindowFullscreenStateChanged(); |
715 [[[self window] cr_windowView] setWantsLayer:windowViewWantsLayer_]; | 744 [[[self window] cr_windowView] setWantsLayer:windowViewWantsLayer_]; |
716 } | 745 } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1042 [self updateLayerOrdering:[avatarButtonController_ view]]; | 1071 [self updateLayerOrdering:[avatarButtonController_ view]]; |
1043 | 1072 |
1044 [CATransaction commit]; | 1073 [CATransaction commit]; |
1045 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; | 1074 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; |
1046 } | 1075 } |
1047 } else { | 1076 } else { |
1048 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; | 1077 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; |
1049 } | 1078 } |
1050 } | 1079 } |
1051 | 1080 |
1081 - (BOOL)shouldUseMavericksAppKitFullscreenHack { | |
1082 if (!base::mac::IsOSMavericks()) | |
Robert Sesek
2014/10/17 19:13:16
This issue is resolved on Yosemite?
erikchen
2014/10/17 21:02:33
Yes. The bug only affects Mavericks.
| |
1083 return NO; | |
1084 if (![NSScreen respondsToSelector:@selector(screensHaveSeparateSpaces)] || | |
1085 ![NSScreen screensHaveSeparateSpaces]) | |
Robert Sesek
2014/10/17 19:13:16
nit: any time the condition is multiple lines, the
erikchen
2014/10/17 21:02:32
Done.
One day, in a universe far-far away, clang
| |
1086 return NO; | |
1087 if (!enteringAppKitFullscreen_) | |
1088 return NO; | |
1089 if (enteringAppKitFullscreenOnPrimaryScreen_) | |
1090 return NO; | |
1091 | |
1092 return YES; | |
1093 } | |
1094 | |
1052 @end // @implementation BrowserWindowController(Private) | 1095 @end // @implementation BrowserWindowController(Private) |
OLD | NEW |