OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/fullscreen.h" | 5 #import "chrome/browser/fullscreen.h" |
6 | 6 |
7 #import <Carbon/Carbon.h> | |
8 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
9 | 8 |
10 #import "base/logging.h" | 9 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
10 #if !defined(MAC_OS_X_VERSION_10_7) || \ | |
11 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | |
11 | 12 |
12 @interface FullScreenMonitor : NSObject { | 13 enum { |
13 @private | 14 NSApplicationPresentationFullScreen = 1 << 10 |
14 BOOL fullScreen_; | 15 }; |
15 EventHandlerRef eventHandler_; | |
16 } | |
17 | 16 |
18 @property (nonatomic, getter=isFullScreen) BOOL fullScreen; | 17 #endif // MAC_OS_X_VERSION_10_7 |
19 | |
20 @end | |
21 | |
22 static OSStatus handleAppEvent(EventHandlerCallRef myHandler, | |
23 EventRef event, | |
24 void* userData) { | |
25 DCHECK(userData); | |
26 | |
27 FullScreenMonitor* fullScreenMonitor = | |
28 reinterpret_cast<FullScreenMonitor*>(userData); | |
29 | |
30 UInt32 mode = 0; | |
31 OSStatus status = GetEventParameter(event, | |
32 kEventParamSystemUIMode, | |
33 typeUInt32, | |
34 NULL, | |
35 sizeof(UInt32), | |
36 NULL, | |
37 &mode); | |
38 if (status != noErr) | |
39 return status; | |
40 BOOL isFullScreenMode = mode == kUIModeAllHidden; | |
41 [fullScreenMonitor setFullScreen:isFullScreenMode]; | |
42 return noErr; | |
43 } | |
44 | |
45 @implementation FullScreenMonitor | |
46 | |
47 @synthesize fullScreen = fullScreen_; | |
48 | |
49 - (id)init { | |
50 if ((self = [super init])) { | |
51 // Check if the user is in presentation mode initially. | |
52 SystemUIMode currentMode; | |
53 GetSystemUIMode(¤tMode, NULL); | |
54 fullScreen_ = currentMode == kUIModeAllHidden; | |
55 | |
56 // Register a Carbon event to receive the notification about the login | |
57 // session's UI mode change. | |
58 EventTypeSpec events[] = | |
59 {{ kEventClassApplication, kEventAppSystemUIModeChanged }}; | |
60 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
| |
61 NewEventHandlerUPP(handleAppEvent), | |
62 GetEventTypeCount(events), | |
63 events, | |
64 self, | |
65 &eventHandler_); | |
66 if (status) { | |
67 [self release]; | |
68 self = nil; | |
69 } | |
70 } | |
71 return self; | |
72 } | |
73 | |
74 - (void)dealloc { | |
75 if (eventHandler_) | |
76 RemoveEventHandler(eventHandler_); | |
77 [super dealloc]; | |
78 } | |
79 | |
80 @end | |
81 | |
82 static FullScreenMonitor* g_fullScreenMonitor = nil; | |
83 | |
84 void InitFullScreenMonitor() { | |
85 if (!g_fullScreenMonitor) | |
86 g_fullScreenMonitor = [[FullScreenMonitor alloc] init]; | |
87 } | |
88 | |
89 void StopFullScreenMonitor() { | |
90 [g_fullScreenMonitor release]; | |
91 g_fullScreenMonitor = nil; | |
92 } | |
93 | 18 |
94 bool IsFullScreenMode() { | 19 bool IsFullScreenMode() { |
95 // Check if the main display has been captured (game in particular). | 20 // Check if the main display has been captured (by games in particular). |
96 if (CGDisplayIsCaptured(CGMainDisplayID())) | 21 if (CGDisplayIsCaptured(CGMainDisplayID())) |
97 return true; | 22 return true; |
98 | 23 |
99 return [g_fullScreenMonitor isFullScreen]; | 24 NSApplicationPresentationOptions options = |
25 [NSApp currentSystemPresentationOptions]; | |
26 | |
27 // If both dock and menu bar are hidden, that is the equivalent of the Carbon | |
28 // SystemUIMode (or Info.plist's LSUIPresentationMode) kUIModeAllHidden. | |
29 if (((options & NSApplicationPresentationHideDock) || | |
30 (options & NSApplicationPresentationAutoHideDock)) && | |
31 ((options & NSApplicationPresentationHideMenuBar) || | |
32 (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.
| |
33 return true; | |
34 } | |
35 | |
36 if (options & NSApplicationPresentationFullScreen) | |
37 return true; | |
38 | |
39 return false; | |
100 } | 40 } |
OLD | NEW |