summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-29 01:01:15 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-29 01:01:15 +0000
commitabd4d9a627747c1928927c7bad77391818ed985c (patch)
tree0343ec595fa9ff279659f9761df7164d17cbec24
parentb5528a2437b6874af7fc4a57dee3d6be940f02c2 (diff)
downloadchromium_src-abd4d9a627747c1928927c7bad77391818ed985c.zip
chromium_src-abd4d9a627747c1928927c7bad77391818ed985c.tar.gz
chromium_src-abd4d9a627747c1928927c7bad77391818ed985c.tar.bz2
Switch to Cocoa APIs for fullscreen.
BUG=none TEST=none TBR=thakis@chromium.org Review URL: https://chromiumcodereview.appspot.com/11697004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174754 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/mac/mac_util.mm34
-rw-r--r--chrome/browser/fullscreen_mac.mm95
-rw-r--r--chrome/chrome_browser.gypi3
-rw-r--r--chrome/chrome_browser_ui.gypi2
-rw-r--r--ui/base/cocoa/fullscreen_window_manager_unittest.mm18
5 files changed, 78 insertions, 74 deletions
diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm
index 4fb1a42..3263db1 100644
--- a/base/mac/mac_util.mm
+++ b/base/mac/mac_util.mm
@@ -28,17 +28,16 @@ namespace {
// The current count of outstanding requests for full screen mode from browser
// windows, plugins, etc.
-int g_full_screen_requests[kNumFullScreenModes] = { 0, 0, 0};
+int g_full_screen_requests[kNumFullScreenModes] = { 0 };
-// Sets the appropriate SystemUIMode based on the current full screen requests.
-// Since only one SystemUIMode can be active at a given time, full screen
-// requests are ordered by priority. If there are no outstanding full screen
-// requests, reverts to normal mode. If the correct SystemUIMode is already
-// set, does nothing.
+// Sets the appropriate application presentation option based on the current
+// full screen requests. Since only one presentation option can be active at a
+// given time, full screen requests are ordered by priority. If there are no
+// outstanding full screen requests, reverts to normal mode. If the correct
+// presentation option is already set, does nothing.
void SetUIMode() {
- // Get the current UI mode.
- SystemUIMode current_mode;
- GetSystemUIMode(&current_mode, NULL);
+ NSApplicationPresentationOptions current_options =
+ [NSApp presentationOptions];
// Determine which mode should be active, based on which requests are
// currently outstanding. More permissive requests take precedence. For
@@ -46,19 +45,20 @@ void SetUIMode() {
// windows request |kFullScreenModeHideDock| when the fullscreen overlay is
// down. Precedence goes to plugins in this case, so AutoHideAll wins over
// HideDock.
- SystemUIMode desired_mode = kUIModeNormal;
- SystemUIOptions desired_options = 0;
+ NSApplicationPresentationOptions desired_options =
+ NSApplicationPresentationDefault;
if (g_full_screen_requests[kFullScreenModeAutoHideAll] > 0) {
- desired_mode = kUIModeAllHidden;
- desired_options = kUIOptionAutoShowMenuBar;
+ desired_options = NSApplicationPresentationHideDock |
+ NSApplicationPresentationAutoHideMenuBar;
} else if (g_full_screen_requests[kFullScreenModeHideDock] > 0) {
- desired_mode = kUIModeContentHidden;
+ desired_options = NSApplicationPresentationHideDock;
} else if (g_full_screen_requests[kFullScreenModeHideAll] > 0) {
- desired_mode = kUIModeAllHidden;
+ desired_options = NSApplicationPresentationHideDock |
+ NSApplicationPresentationHideMenuBar;
}
- if (current_mode != desired_mode)
- SetSystemUIMode(desired_mode, desired_options);
+ if (current_options != desired_options)
+ [NSApp setPresentationOptions:desired_options];
}
// Looks into Shared File Lists corresponding to Login Items for the item
diff --git a/chrome/browser/fullscreen_mac.mm b/chrome/browser/fullscreen_mac.mm
index 303f6f2..f4e73c0 100644
--- a/chrome/browser/fullscreen_mac.mm
+++ b/chrome/browser/fullscreen_mac.mm
@@ -4,79 +4,80 @@
#import "chrome/browser/fullscreen.h"
-#import <Carbon/Carbon.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_;
- EventHandlerRef eventHandler_;
}
@property (nonatomic, getter=isFullScreen) BOOL fullScreen;
@end
-static OSStatus handleAppEvent(EventHandlerCallRef myHandler,
- EventRef event,
- void* userData) {
- DCHECK(userData);
-
- FullScreenMonitor* fullScreenMonitor =
- reinterpret_cast<FullScreenMonitor*>(userData);
-
- UInt32 mode = 0;
- OSStatus status = GetEventParameter(event,
- kEventParamSystemUIMode,
- typeUInt32,
- NULL,
- sizeof(UInt32),
- NULL,
- &mode);
- if (status != noErr)
- return status;
- BOOL isFullScreenMode = mode == kUIModeAllHidden;
- [fullScreenMonitor setFullScreen:isFullScreenMode];
- return noErr;
-}
-
@implementation FullScreenMonitor
@synthesize fullScreen = fullScreen_;
- (id)init {
if ((self = [super init])) {
- // Check if the user is in presentation mode initially.
- SystemUIMode currentMode;
- GetSystemUIMode(&currentMode, NULL);
- fullScreen_ = currentMode == kUIModeAllHidden;
-
- // Register a Carbon event to receive the notification about the login
- // session's UI mode change.
- EventTypeSpec events[] =
- {{ kEventClassApplication, kEventAppSystemUIModeChanged }};
- OSStatus status = InstallApplicationEventHandler(
- NewEventHandlerUPP(handleAppEvent),
- GetEventTypeCount(events),
- events,
- self,
- &eventHandler_);
- if (status) {
- [self release];
- self = nil;
- }
+ [NSApp gtm_addObserver:self
+ forKeyPath:@"currentSystemPresentationOptions"
+ selector:@selector(observeNotification:)
+ userInfo:nil
+ options:NSKeyValueObservingOptionNew |
+ NSKeyValueObservingOptionInitial];
}
return self;
}
- (void)dealloc {
- if (eventHandler_)
- RemoveEventHandler(eventHandler_);
+ [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;
@@ -92,7 +93,7 @@ void StopFullScreenMonitor() {
}
bool IsFullScreenMode() {
- // Check if the main display has been captured (game in particular).
+ // Check if the main display has been captured (by games in particular).
if (CGDisplayIsCaptured(CGMainDisplayID()))
return true;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index bcf30f8..ee7e5ff 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2863,11 +2863,14 @@
],
'sources': [
# Build the necessary GTM sources
+ '../third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h',
+ '../third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.m',
'../third_party/GTM/Foundation/GTMServiceManagement.h',
'../third_party/GTM/Foundation/GTMServiceManagement.c',
],
'include_dirs': [
'../third_party/GTM',
+ '../third_party/GTM/DebugUtils',
'../third_party/GTM/Foundation',
],
}],
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 3fd6935..5f43439 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -2621,8 +2621,6 @@
'../third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.m',
'../third_party/GTM/Foundation/GTMNSNumber+64Bit.h',
'../third_party/GTM/Foundation/GTMNSNumber+64Bit.m',
- '../third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.h',
- '../third_party/GTM/Foundation/GTMNSObject+KeyValueObserving.m',
# MolokoCacao additions
'../third_party/molokocacao/NSBezierPath+MCAdditions.h',
'../third_party/molokocacao/NSBezierPath+MCAdditions.m',
diff --git a/ui/base/cocoa/fullscreen_window_manager_unittest.mm b/ui/base/cocoa/fullscreen_window_manager_unittest.mm
index eee5097..710ec79 100644
--- a/ui/base/cocoa/fullscreen_window_manager_unittest.mm
+++ b/ui/base/cocoa/fullscreen_window_manager_unittest.mm
@@ -4,7 +4,6 @@
#import "ui/base/cocoa/fullscreen_window_manager.h"
-
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "ui/base/test/ui_cocoa_test_helper.h"
@@ -17,15 +16,18 @@ TEST_F(FullscreenWindowManagerTest, EnterExit) {
initWithWindow:test_window()
desiredScreen:[NSScreen mainScreen]]);
- SystemUIMode mode = kUIModeNormal;
- GetSystemUIMode(&mode, NULL);
- EXPECT_EQ(kUIModeNormal, mode);
+ NSApplicationPresentationOptions current_options =
+ [NSApp presentationOptions];
+ EXPECT_EQ(NSApplicationPresentationDefault, current_options);
[manager enterFullscreenMode];
- GetSystemUIMode(&mode, NULL);
- EXPECT_EQ(kUIModeAllHidden, mode);
+ current_options = [NSApp presentationOptions];
+ EXPECT_EQ(static_cast<NSApplicationPresentationOptions>(
+ NSApplicationPresentationHideDock |
+ NSApplicationPresentationHideMenuBar),
+ current_options);
[manager exitFullscreenMode];
- GetSystemUIMode(&mode, NULL);
- EXPECT_EQ(kUIModeNormal, mode);
+ current_options = [NSApp presentationOptions];
+ EXPECT_EQ(NSApplicationPresentationDefault, current_options);
}