summaryrefslogtreecommitdiffstats
path: root/chrome/browser/fullscreen_mac.mm
blob: f4e73c06ab6a14877146fcb0715e103f341f9bb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "chrome/browser/fullscreen.h"

#import <Cocoa/Cocoa.h>

#import "base/logging.h"
#import "third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h"

// Replicate specific 10.7 SDK declarations for building with prior SDKs.
#if !defined(MAC_OS_X_VERSION_10_7) || \
    MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7

enum {
  NSApplicationPresentationFullScreen = 1 << 10
};

#endif  // MAC_OS_X_VERSION_10_7

namespace {

BOOL AreOptionsFullScreen(NSApplicationPresentationOptions options) {
  // If both dock and menu bar are hidden, that is the equivalent of the Carbon
  // SystemUIMode (or Info.plist's LSUIPresentationMode) kUIModeAllHidden.
  if (((options & NSApplicationPresentationHideDock) ||
       (options & NSApplicationPresentationAutoHideDock)) &&
      ((options & NSApplicationPresentationHideMenuBar) ||
       (options & NSApplicationPresentationAutoHideMenuBar))) {
    return YES;
  }

  if (options & NSApplicationPresentationFullScreen)
    return YES;

  return NO;
}

}  // namespace

@interface FullScreenMonitor : NSObject {
 @private
  BOOL fullScreen_;
}

@property (nonatomic, getter=isFullScreen) BOOL fullScreen;

@end

@implementation FullScreenMonitor

@synthesize fullScreen = fullScreen_;

- (id)init {
  if ((self = [super init])) {
    [NSApp gtm_addObserver:self
                forKeyPath:@"currentSystemPresentationOptions"
                  selector:@selector(observeNotification:)
                  userInfo:nil
                   options:NSKeyValueObservingOptionNew |
                           NSKeyValueObservingOptionInitial];
  }
  return self;
}

- (void)dealloc {
  [NSApp gtm_removeObserver:self
                 forKeyPath:@"currentSystemPresentationOptions"
                   selector:@selector(observeNotification:)];
  [super dealloc];
}

- (void)observeNotification:(GTMKeyValueChangeNotification*)notification {
  NSDictionary* change = [notification change];
  NSApplicationPresentationOptions options =
      [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
  [self setFullScreen:AreOptionsFullScreen(options)];
}

@end

static FullScreenMonitor* g_fullScreenMonitor = nil;

void InitFullScreenMonitor() {
  if (!g_fullScreenMonitor)
    g_fullScreenMonitor = [[FullScreenMonitor alloc] init];
}

void StopFullScreenMonitor() {
  [g_fullScreenMonitor release];
  g_fullScreenMonitor = nil;
}

bool IsFullScreenMode() {
  // Check if the main display has been captured (by games in particular).
  if (CGDisplayIsCaptured(CGMainDisplayID()))
    return true;

  return [g_fullScreenMonitor isFullScreen];
}