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 <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #import "base/logging.h" | 9 #import "base/logging.h" |
10 #import "third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h" | |
11 | 10 |
12 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 11 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
13 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 12 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
14 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 13 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
15 | 14 |
16 enum { | 15 enum { |
17 NSApplicationPresentationFullScreen = 1 << 10 | 16 NSApplicationPresentationFullScreen = 1 << 10 |
18 }; | 17 }; |
19 | 18 |
20 #endif // MAC_OS_X_VERSION_10_7 | 19 #endif // MAC_OS_X_VERSION_10_7 |
(...skipping 26 matching lines...) Expand all Loading... |
47 @property (nonatomic, getter=isFullScreen) BOOL fullScreen; | 46 @property (nonatomic, getter=isFullScreen) BOOL fullScreen; |
48 | 47 |
49 @end | 48 @end |
50 | 49 |
51 @implementation FullScreenMonitor | 50 @implementation FullScreenMonitor |
52 | 51 |
53 @synthesize fullScreen = fullScreen_; | 52 @synthesize fullScreen = fullScreen_; |
54 | 53 |
55 - (id)init { | 54 - (id)init { |
56 if ((self = [super init])) { | 55 if ((self = [super init])) { |
57 [NSApp gtm_addObserver:self | 56 [NSApp addObserver:self |
58 forKeyPath:@"currentSystemPresentationOptions" | 57 forKeyPath:@"currentSystemPresentationOptions" |
59 selector:@selector(observeNotification:) | 58 options:NSKeyValueObservingOptionNew | |
60 userInfo:nil | 59 NSKeyValueObservingOptionInitial |
61 options:NSKeyValueObservingOptionNew | | 60 context:nil]; |
62 NSKeyValueObservingOptionInitial]; | |
63 } | 61 } |
64 return self; | 62 return self; |
65 } | 63 } |
66 | 64 |
67 - (void)dealloc { | 65 - (void)dealloc { |
68 [NSApp gtm_removeObserver:self | 66 [NSApp removeObserver:self |
69 forKeyPath:@"currentSystemPresentationOptions" | 67 forKeyPath:@"currentSystemPresentationOptions"]; |
70 selector:@selector(observeNotification:)]; | |
71 [super dealloc]; | 68 [super dealloc]; |
72 } | 69 } |
73 | 70 |
74 - (void)observeNotification:(GTMKeyValueChangeNotification*)notification { | 71 - (void)observeValueForKeyPath:(NSString*)keyPath |
75 NSDictionary* change = [notification change]; | 72 ofObject:(id)object |
| 73 change:(NSDictionary*)change |
| 74 context:(void*)context { |
76 NSApplicationPresentationOptions options = | 75 NSApplicationPresentationOptions options = |
77 [[change objectForKey:NSKeyValueChangeNewKey] integerValue]; | 76 [[change objectForKey:NSKeyValueChangeNewKey] integerValue]; |
78 [self setFullScreen:AreOptionsFullScreen(options)]; | 77 [self setFullScreen:AreOptionsFullScreen(options)]; |
79 } | 78 } |
80 | 79 |
81 @end | 80 @end |
82 | 81 |
83 static FullScreenMonitor* g_fullScreenMonitor = nil; | 82 static FullScreenMonitor* g_fullScreenMonitor = nil; |
84 | 83 |
85 void InitFullScreenMonitor() { | 84 void InitFullScreenMonitor() { |
86 if (!g_fullScreenMonitor) | 85 if (!g_fullScreenMonitor) |
87 g_fullScreenMonitor = [[FullScreenMonitor alloc] init]; | 86 g_fullScreenMonitor = [[FullScreenMonitor alloc] init]; |
88 } | 87 } |
89 | 88 |
90 void StopFullScreenMonitor() { | 89 void StopFullScreenMonitor() { |
91 [g_fullScreenMonitor release]; | 90 [g_fullScreenMonitor release]; |
92 g_fullScreenMonitor = nil; | 91 g_fullScreenMonitor = nil; |
93 } | 92 } |
94 | 93 |
95 bool IsFullScreenMode() { | 94 bool IsFullScreenMode() { |
96 // Check if the main display has been captured (by games in particular). | 95 // Check if the main display has been captured (by games in particular). |
97 if (CGDisplayIsCaptured(CGMainDisplayID())) | 96 if (CGDisplayIsCaptured(CGMainDisplayID())) |
98 return true; | 97 return true; |
99 | 98 |
100 return [g_fullScreenMonitor isFullScreen]; | 99 return [g_fullScreenMonitor isFullScreen]; |
101 } | 100 } |
OLD | NEW |