Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/fullscreen.h" | |
| 6 | |
| 7 #import <Carbon/Carbon.h> | |
| 8 #import <Cocoa/Cocoa.h> | |
| 9 | |
| 10 #import "base/logging.h" | |
| 11 | |
| 12 @interface FullScreenMonitor : NSObject { | |
| 13 @private | |
| 14 BOOL fullScreen_; | |
| 15 EventHandlerRef eventHandler_; | |
| 16 } | |
| 17 | |
| 18 - (BOOL)isFullScreen; | |
| 19 - (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.
| |
| 20 | |
| 21 @end | |
| 22 | |
| 23 static OSStatus handleAppEvent(EventHandlerCallRef myHandler, | |
| 24 EventRef event, | |
| 25 void* userData) { | |
| 26 DCHECK(userData); | |
| 27 | |
| 28 FullScreenMonitor* fullScreenMonitor = | |
| 29 reinterpret_cast<FullScreenMonitor*>(userData); | |
| 30 | |
| 31 UInt32 mode = 0; | |
| 32 OSStatus status = GetEventParameter(event, | |
| 33 kEventParamSystemUIMode, | |
| 34 typeUInt32, | |
| 35 NULL, | |
| 36 sizeof(UInt32), | |
| 37 NULL, | |
| 38 &mode); | |
| 39 if (status != noErr) | |
| 40 return status; | |
| 41 BOOL isFullScreenMode = mode == kUIModeAllHidden; | |
| 42 [fullScreenMonitor setFullScreen:isFullScreenMode]; | |
| 43 return noErr; | |
| 44 } | |
| 45 | |
| 46 @implementation FullScreenMonitor | |
| 47 | |
| 48 - (id)init { | |
| 49 if ((self = [super init])) { | |
| 50 // Check if the user is in presentation mode initially. | |
| 51 SystemUIMode currentMode; | |
| 52 GetSystemUIMode(¤tMode, NULL); | |
| 53 fullScreen_ = currentMode == kUIModeAllHidden; | |
| 54 | |
| 55 // Register a Carbon event to receive the notification about the login | |
| 56 // session's UI mode change. | |
| 57 EventTypeSpec events[] = | |
| 58 {{ kEventClassApplication, kEventAppSystemUIModeChanged }}; | |
| 59 OSStatus status = InstallApplicationEventHandler( | |
| 60 NewEventHandlerUPP(handleAppEvent), | |
| 61 GetEventTypeCount(events), | |
| 62 events, | |
| 63 self, | |
| 64 &eventHandler_); | |
| 65 DCHECK(status == noErr); | |
| 66 (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.
| |
| 67 } | |
| 68 return self; | |
| 69 } | |
| 70 | |
| 71 - (void)dealloc { | |
| 72 if (eventHandler_) | |
| 73 RemoveEventHandler(eventHandler_); | |
| 74 [super dealloc]; | |
| 75 } | |
| 76 | |
| 77 - (BOOL)isFullScreen { | |
| 78 return fullScreen_; | |
| 79 } | |
| 80 | |
| 81 - (void)setFullScreen:(BOOL)newFullScreen { | |
| 82 fullScreen_ = newFullScreen; | |
| 83 } | |
| 84 | |
| 85 @end | |
| 86 | |
| 87 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
| |
| 88 | |
| 89 void InitFullScreenMonitor() { | |
| 90 if (!g_fullScreenMonitor) | |
| 91 g_fullScreenMonitor = [[FullScreenMonitor alloc] init]; | |
| 92 } | |
| 93 | |
| 94 void StopFullScreenMonitor() { | |
| 95 [g_fullScreenMonitor release]; | |
| 96 g_fullScreenMonitor = nil; | |
| 97 } | |
| 98 | |
| 99 bool IsFullScreenMode() { | |
| 100 // Check if the main display has been captured (game in particular). | |
| 101 if (CGDisplayIsCaptured(CGMainDisplayID())) | |
| 102 return true; | |
| 103 | |
| 104 return [g_fullScreenMonitor isFullScreen]; | |
| 105 } | |
| OLD | NEW |