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; |
| 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. We do this by |
| 51 // checking if the menu bar is visible. |
| 52 NSArray* screens = [NSScreen screens]; |
| 53 if ([screens count] > 0) { |
| 54 NSScreen* screen = [screens objectAtIndex:0]; |
| 55 NSRect fullBounds = [screen frame]; |
| 56 NSRect workBounds = [screen visibleFrame]; |
| 57 if (NSMaxY(fullBounds) == NSMaxY(workBounds)) |
| 58 fullScreen_ = YES; |
| 59 } |
| 60 |
| 61 // Register a Carbon event to receive the notification about the login |
| 62 // session's UI mode change. |
| 63 EventTypeSpec events[] = |
| 64 {{ kEventClassApplication, kEventAppSystemUIModeChanged }}; |
| 65 OSStatus status = InstallApplicationEventHandler( |
| 66 NewEventHandlerUPP(handleAppEvent), |
| 67 GetEventTypeCount(events), |
| 68 events, |
| 69 self, |
| 70 &eventHandler_); |
| 71 DCHECK(status == noErr); |
| 72 (void) status; // Work around unused variable warning. |
| 73 } |
| 74 return self; |
| 75 } |
| 76 |
| 77 - (void)dealloc { |
| 78 if (eventHandler_) |
| 79 RemoveEventHandler(eventHandler_); |
| 80 [super dealloc]; |
| 81 } |
| 82 |
| 83 - (BOOL)isFullScreen { |
| 84 return fullScreen_; |
| 85 } |
| 86 |
| 87 - (void)setFullScreen:(BOOL)newFullScreen { |
| 88 fullScreen_ = newFullScreen; |
| 89 } |
| 90 |
| 91 @end |
| 92 |
| 93 FullScreenMonitor* g_fullScreenMonitor = nil; |
| 94 |
| 95 void InitFullScreenMonitor() { |
| 96 if (!g_fullScreenMonitor) |
| 97 g_fullScreenMonitor = [[FullScreenMonitor alloc] init]; |
| 98 } |
| 99 |
| 100 void StopFullScreenMonitor() { |
| 101 [g_fullScreenMonitor release]; |
| 102 g_fullScreenMonitor = nil; |
| 103 } |
| 104 |
| 105 bool IsFullScreenMode() { |
| 106 // Check if the main display has been captured (game in particular). |
| 107 if (CGDisplayIsCaptured(CGMainDisplayID())) |
| 108 return true; |
| 109 |
| 110 return [g_fullScreenMonitor isFullScreen]; |
| 111 } |
OLD | NEW |