Chromium Code Reviews| Index: chrome/browser/fullscreen_mac.mm |
| =================================================================== |
| --- chrome/browser/fullscreen_mac.mm (revision 0) |
| +++ chrome/browser/fullscreen_mac.mm (revision 0) |
| @@ -0,0 +1,105 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "chrome/browser/fullscreen.h" |
| + |
| +#import <Carbon/Carbon.h> |
| +#import <Cocoa/Cocoa.h> |
| + |
| +#import "base/logging.h" |
| + |
| +@interface FullScreenMonitor : NSObject { |
| + @private |
| + BOOL fullScreen_; |
| + EventHandlerRef eventHandler_; |
| +} |
| + |
| +- (BOOL)isFullScreen; |
| +- (void)setFullScreen:(BOOL)newFullScreen; |
|
dmac
2011/01/25 05:04:37
You could also do this with properties
@property
jianli
2011/01/25 19:30:16
Done.
|
| + |
| +@end |
| + |
| +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; |
| +} |
| + |
| +@implementation FullScreenMonitor |
| + |
| +- (id)init { |
| + if ((self = [super init])) { |
| + // Check if the user is in presentation mode initially. |
| + SystemUIMode currentMode; |
| + GetSystemUIMode(¤tMode, NULL); |
| + fullScreen_ = currentMode == kUIModeAllHidden; |
| + |
| + // Register a Carbon event to receive the notification about the login |
| + // session's UI mode change. |
| + EventTypeSpec events[] = |
| + {{ kEventClassApplication, kEventAppSystemUIModeChanged }}; |
| + OSStatus status = InstallApplicationEventHandler( |
| + NewEventHandlerUPP(handleAppEvent), |
| + GetEventTypeCount(events), |
| + events, |
| + self, |
| + &eventHandler_); |
| + DCHECK(status == noErr); |
| + (void) status; // Work around unused variable warning. |
|
dmac
2011/01/25 05:04:37
possibly a better option here would be
if (status)
jianli
2011/01/25 19:30:16
Done.
|
| + } |
| + return self; |
| +} |
| + |
| +- (void)dealloc { |
| + if (eventHandler_) |
| + RemoveEventHandler(eventHandler_); |
| + [super dealloc]; |
| +} |
| + |
| +- (BOOL)isFullScreen { |
| + return fullScreen_; |
| +} |
| + |
| +- (void)setFullScreen:(BOOL)newFullScreen { |
| + fullScreen_ = newFullScreen; |
| +} |
| + |
| +@end |
| + |
| +FullScreenMonitor* g_fullScreenMonitor = nil; |
|
dmac
2011/01/25 05:04:37
should this be static? or in an anonymous namespac
jianli
2011/01/25 19:30:16
I forgot to put static back when I moved the code
|
| + |
| +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())) |
| + return true; |
| + |
| + return [g_fullScreenMonitor isFullScreen]; |
| +} |
| Property changes on: chrome\browser\fullscreen_mac.mm |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |