Chromium Code Reviews| Index: chrome/browser/fullscreen_mac.mm |
| diff --git a/chrome/browser/fullscreen_mac.mm b/chrome/browser/fullscreen_mac.mm |
| index 303f6f240779a48d8d8e7e004bebe0a158df79af..addf08250f449c3ea846cc0e35fa2cc31556c59d 100644 |
| --- a/chrome/browser/fullscreen_mac.mm |
| +++ b/chrome/browser/fullscreen_mac.mm |
| @@ -4,97 +4,37 @@ |
| #import "chrome/browser/fullscreen.h" |
| -#import <Carbon/Carbon.h> |
| #import <Cocoa/Cocoa.h> |
| -#import "base/logging.h" |
| +// Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| +#if !defined(MAC_OS_X_VERSION_10_7) || \ |
| + MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| -@interface FullScreenMonitor : NSObject { |
| - @private |
| - BOOL fullScreen_; |
| - EventHandlerRef eventHandler_; |
| -} |
| - |
| -@property (nonatomic, getter=isFullScreen) BOOL fullScreen; |
| - |
| -@end |
| +enum { |
| + NSApplicationPresentationFullScreen = 1 << 10 |
| +}; |
| -static OSStatus handleAppEvent(EventHandlerCallRef myHandler, |
| - EventRef event, |
| - void* userData) { |
| - DCHECK(userData); |
| - |
| - FullScreenMonitor* fullScreenMonitor = |
| - reinterpret_cast<FullScreenMonitor*>(userData); |
| - |
| - UInt32 mode = 0; |
| - OSStatus status = GetEventParameter(event, |
| - kEventParamSystemUIMode, |
| - typeUInt32, |
| - NULL, |
| - sizeof(UInt32), |
| - NULL, |
| - &mode); |
| - if (status != noErr) |
| - return status; |
| - BOOL isFullScreenMode = mode == kUIModeAllHidden; |
| - [fullScreenMonitor setFullScreen:isFullScreenMode]; |
| - return noErr; |
| -} |
| +#endif // MAC_OS_X_VERSION_10_7 |
| -@implementation FullScreenMonitor |
| - |
| -@synthesize fullScreen = fullScreen_; |
| +bool IsFullScreenMode() { |
| + // Check if the main display has been captured (by games in particular). |
| + if (CGDisplayIsCaptured(CGMainDisplayID())) |
| + return true; |
| -- (id)init { |
| - if ((self = [super init])) { |
| - // Check if the user is in presentation mode initially. |
| - SystemUIMode currentMode; |
| - GetSystemUIMode(¤tMode, NULL); |
| - fullScreen_ = currentMode == kUIModeAllHidden; |
| + NSApplicationPresentationOptions options = |
| + [NSApp currentSystemPresentationOptions]; |
| - // Register a Carbon event to receive the notification about the login |
| - // session's UI mode change. |
| - EventTypeSpec events[] = |
| - {{ kEventClassApplication, kEventAppSystemUIModeChanged }}; |
| - OSStatus status = InstallApplicationEventHandler( |
|
Nico
2013/01/23 21:35:21
Did this inform us about fullscreen changes from o
Avi (use Gerrit)
2013/01/23 21:48:21
Yes, and that's the point.
Cocoa has on NSApp bot
|
| - NewEventHandlerUPP(handleAppEvent), |
| - GetEventTypeCount(events), |
| - events, |
| - self, |
| - &eventHandler_); |
| - if (status) { |
| - [self release]; |
| - self = nil; |
| - } |
| + // If both dock and menu bar are hidden, that is the equivalent of the Carbon |
| + // SystemUIMode (or Info.plist's LSUIPresentationMode) kUIModeAllHidden. |
| + if (((options & NSApplicationPresentationHideDock) || |
| + (options & NSApplicationPresentationAutoHideDock)) && |
| + ((options & NSApplicationPresentationHideMenuBar) || |
| + (options & NSApplicationPresentationAutoHideMenuBar))) { |
|
Nico
2013/01/23 21:52:08
nit: This would be a tad more readable as
bool do
Avi (use Gerrit)
2013/01/23 21:55:07
agreed.
|
| + return true; |
| } |
| - return self; |
| -} |
| - |
| -- (void)dealloc { |
| - if (eventHandler_) |
| - RemoveEventHandler(eventHandler_); |
| - [super dealloc]; |
| -} |
| -@end |
| - |
| -static FullScreenMonitor* g_fullScreenMonitor = nil; |
| - |
| -void InitFullScreenMonitor() { |
| - if (!g_fullScreenMonitor) |
| - g_fullScreenMonitor = [[FullScreenMonitor alloc] init]; |
| -} |
| - |
| -void StopFullScreenMonitor() { |
| - [g_fullScreenMonitor release]; |
| - g_fullScreenMonitor = nil; |
| -} |
| - |
| -bool IsFullScreenMode() { |
| - // Check if the main display has been captured (game in particular). |
| - if (CGDisplayIsCaptured(CGMainDisplayID())) |
| + if (options & NSApplicationPresentationFullScreen) |
| return true; |
| - return [g_fullScreenMonitor isFullScreen]; |
| + return false; |
| } |