|
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 "base/logging.h" | |
dmac
2011/01/21 19:34:44
base/logging should be under system imports.
jianli
2011/01/21 20:21:00
Done.
| |
8 #import <Carbon/Carbon.h> | |
9 #import <Cocoa/Cocoa.h> | |
10 | |
11 @interface FullScreenMonitor : NSObject { | |
12 @private | |
13 BOOL isFullScreen_; | |
14 EventHandlerRef eventHandler_; | |
15 } | |
16 | |
17 - (BOOL) isFullScreen; | |
dmac
2011/01/21 19:34:44
no space between ) and i (same on line below)
jianli
2011/01/21 20:21:00
Done.
| |
18 - (void) setIsFullScreen:(BOOL)newIsFullScreen; | |
dmac
2011/01/21 19:34:44
cocoa naming would be isFullScreen and setFullScre
jianli
2011/01/21 20:21:00
Done.
| |
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 (void) GetEventParameter(event, | |
32 kEventParamSystemUIMode, | |
33 typeUInt32, | |
34 /*outActualType*/ NULL, | |
dmac
2011/01/21 19:34:44
get rid of /*value*/ and do you want to check for
jianli
2011/01/21 20:21:00
Done.
| |
35 sizeof(UInt32), | |
36 /*outActualSize*/ NULL, | |
37 &mode); | |
38 BOOL isFullScreenMode = mode == kUIModeAllHidden; | |
39 [fullScreenMonitor setIsFullScreen:isFullScreenMode]; | |
40 return noErr; | |
41 } | |
42 | |
43 @implementation FullScreenMonitor | |
44 | |
45 - (id)init { | |
46 if ((self = [super init])) { | |
47 // Check if the user is in presentation mode initially. We do this by | |
dmac
2011/01/21 19:34:44
When this is initialized, do we expect Chrome to b
jianli
2011/01/21 20:21:00
No. InitFullScreenMonitor is called when Notificat
| |
48 // checking if the menu bar is visible. | |
49 NSArray* screens = [NSScreen screens]; | |
50 if ([screens count] > 0) { | |
51 NSScreen* screen = [screens objectAtIndex:0]; | |
52 NSRect fullBounds = [screen frame]; | |
53 NSRect workBounds = [screen visibleFrame]; | |
54 if (NSMaxY(fullBounds) == NSMaxY(workBounds)) | |
55 isFullScreen_ = YES; | |
56 } | |
57 | |
58 // Register a Carbon event to receive the notification about the login | |
59 // session's UI mode change. | |
60 EventTypeSpec events[] = | |
61 {{ kEventClassApplication, kEventAppSystemUIModeChanged }}; | |
62 OSStatus res = InstallApplicationEventHandler( | |
63 NewEventHandlerUPP(handleAppEvent), | |
64 GetEventTypeCount(events), | |
65 events, | |
66 self, | |
67 &eventHandler_); | |
68 DCHECK(res == noErr); | |
69 (void) res; // Work around unused variable warning. | |
70 } | |
71 return self; | |
72 } | |
73 | |
74 - (void)dealloc { | |
75 if (eventHandler_) | |
76 RemoveEventHandler(eventHandler_); | |
77 [super dealloc]; | |
78 } | |
79 | |
80 - (BOOL)isFullScreen { | |
81 return isFullScreen_; | |
82 } | |
83 | |
84 - (void)setIsFullScreen:(BOOL)newIsFullScreen { | |
85 isFullScreen_ = newIsFullScreen; | |
86 } | |
87 | |
88 @end | |
89 | |
90 FullScreenMonitor* g_fullScreenMonitor = nil; | |
91 | |
92 void InitFullScreenMonitor() { | |
93 if (!g_fullScreenMonitor) | |
94 g_fullScreenMonitor = [[FullScreenMonitor alloc] init]; | |
95 } | |
96 | |
97 void StopFullScreenMonitor() { | |
98 g_fullScreenMonitor = nil; | |
dmac
2011/01/21 19:34:44
[g_fullScreenMonitor release]; ?
jianli
2011/01/21 20:21:00
Done.
| |
99 } | |
100 | |
101 bool IsFullScreenMode() { | |
102 // Check if the main display has been captured (game in particular). | |
103 if (CGDisplayIsCaptured(CGMainDisplayID())) | |
104 return true; | |
105 | |
106 return [g_fullScreenMonitor isFullScreen]; | |
107 } | |
OLD | NEW |