summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-03 19:27:28 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-03 19:27:28 +0000
commitce04f0c9b299f5afbc6a44839f302baabe498cd1 (patch)
tree83b7b5fb2b88a95930d7a2d9360b7b2427567bb7 /chrome/browser/cocoa
parentea2cad155442906261ce832585a36630c6f10d98 (diff)
downloadchromium_src-ce04f0c9b299f5afbc6a44839f302baabe498cd1.zip
chromium_src-ce04f0c9b299f5afbc6a44839f302baabe498cd1.tar.gz
chromium_src-ce04f0c9b299f5afbc6a44839f302baabe498cd1.tar.bz2
[Mac] When in fullscreen mode, ties the menubar shown state to the overlay shown state.
BUG=36610 TEST=Go fullscreen. Menubar should only be shown when the overlay is fully visible. TEST=While in fullscreen mode, fullscreen a youtube video. Menubar should be autohidden (mousing to the top of the screen should show it). Review URL: http://codereview.chromium.org/661380 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40529 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/fullscreen_controller.h21
-rw-r--r--chrome/browser/cocoa/fullscreen_controller.mm71
2 files changed, 68 insertions, 24 deletions
diff --git a/chrome/browser/cocoa/fullscreen_controller.h b/chrome/browser/cocoa/fullscreen_controller.h
index 1fda1d7..f599835 100644
--- a/chrome/browser/cocoa/fullscreen_controller.h
+++ b/chrome/browser/cocoa/fullscreen_controller.h
@@ -8,6 +8,7 @@
#import <Cocoa/Cocoa.h>
#import "base/cocoa_protocols_mac.h"
+#include "base/mac_util.h"
#include "chrome/browser/cocoa/location_bar_view_mac.h"
@class BrowserWindowController;
@@ -57,12 +58,15 @@
// completes.
NSRect trackingAreaBounds_;
- // YES if we are currently hiding the menubar. While this should generally
- // match the window's main status, it can get out of sync if we miss a
- // notification (which can happen when a fullscreen window is closed). Used
- // to make sure we properly restore the menubar when this controller is
+ // Tracks the currently requested fullscreen mode. This should be
+ // |kFullScreenModeNormal| when the window is not main or not fullscreen,
+ // |kFullScreenModeHideAll| while the overlay is hidden, and
+ // |kFullScreenModeHideDock| while the overlay is shown. This value can get
+ // out of sync with the correct state if we miss a notification (which can
+ // happen when a fullscreen window is closed). Used to track the current
+ // state and make sure we properly restore the menubar when this controller is
// destroyed.
- BOOL menubarIsHidden_;
+ mac_util::FullScreenMode currentFullscreenMode_;
}
@property(readonly, nonatomic) BOOL isFullscreen;
@@ -96,6 +100,13 @@
// Cancels any running animation and timers.
- (void)cancelAnimationAndTimers;
+// Gets the current floating bar shown fraction.
+- (CGFloat)floatingBarShownFraction;
+
+// Sets a new current floating bar shown fraction. NOTE: This function has side
+// effects, such as modifying the fullscreen mode (menubar shown state).
+- (void)changeFloatingBarShownFraction:(CGFloat)fraction;
+
@end
#endif // CHROME_BROWSER_COCOA_FULLSCREEN_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/fullscreen_controller.mm b/chrome/browser/cocoa/fullscreen_controller.mm
index 3e36777..3c67409 100644
--- a/chrome/browser/cocoa/fullscreen_controller.mm
+++ b/chrome/browser/cocoa/fullscreen_controller.mm
@@ -6,7 +6,6 @@
#include <algorithm>
-#include "base/mac_util.h"
#import "chrome/browser/cocoa/browser_window_controller.h"
#import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
@@ -29,11 +28,11 @@ const CGFloat kTabStripVerticalOffset = 14;
// Helper class to manage animations for the fullscreen dropdown bar. Calls
-// back to [BrowserWindowController setFloatingBarShownFraction] once per
-// animation step.
+// [FullscreenController changeFloatingBarShownFraction] once per animation
+// step.
@interface DropdownAnimation : NSAnimation {
@private
- BrowserWindowController* controller_;
+ FullscreenController* controller_;
CGFloat startFraction_;
CGFloat endFraction_;
}
@@ -47,7 +46,7 @@ const CGFloat kTabStripVerticalOffset = 14;
- (id)initWithFraction:(CGFloat)fromFraction
fullDuration:(CGFloat)fullDuration
animationCurve:(NSInteger)animationCurve
- controller:(BrowserWindowController*)controller;
+ controller:(FullscreenController*)controller;
@end
@@ -59,7 +58,7 @@ const CGFloat kTabStripVerticalOffset = 14;
- (id)initWithFraction:(CGFloat)toFraction
fullDuration:(CGFloat)fullDuration
animationCurve:(NSInteger)animationCurve
- controller:(BrowserWindowController*)controller {
+ controller:(FullscreenController*)controller {
// Calculate the effective duration, based on the current shown fraction.
DCHECK(controller);
CGFloat fromFraction = [controller floatingBarShownFraction];
@@ -79,7 +78,7 @@ const CGFloat kTabStripVerticalOffset = 14;
- (void)setCurrentProgress:(NSAnimationProgress)progress {
CGFloat fraction =
startFraction_ + (progress * (endFraction_ - startFraction_));
- [controller_ setFloatingBarShownFraction:fraction];
+ [controller_ changeFloatingBarShownFraction:fraction];
}
@end
@@ -90,6 +89,10 @@ const CGFloat kTabStripVerticalOffset = 14;
// Returns YES if the fullscreen window is on the primary screen.
- (BOOL)isWindowOnPrimaryScreen;
+// Returns |kFullScreenModeHideAll| when the overlay is hidden and
+// |kFullScreenModeHideDock| when the overlay is shown.
+- (mac_util::FullScreenMode)desiredFullscreenMode;
+
// Change the overlay to the given fraction, with or without animation. Only
// guaranteed to work properly with |fraction == 0| or |fraction == 1|. This
// performs the show/hide (animation) immediately. It does not touch the timers.
@@ -153,6 +156,7 @@ const CGFloat kTabStripVerticalOffset = 14;
- (id)initWithBrowserController:(BrowserWindowController*)controller {
if ((self == [super init])) {
browserController_ = controller;
+ currentFullscreenMode_ = mac_util::kFullScreenModeNormal;
}
return self;
}
@@ -167,7 +171,7 @@ const CGFloat kTabStripVerticalOffset = 14;
DCHECK(!isFullscreen_);
isFullscreen_ = YES;
contentView_ = contentView;
- [browserController_ setFloatingBarShownFraction:(showDropdown ? 1 : 0)];
+ [self changeFloatingBarShownFraction:(showDropdown ? 1 : 0)];
// Register for notifications. Self is removed as an observer in |-cleanup|.
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
@@ -275,6 +279,24 @@ const CGFloat kTabStripVerticalOffset = 14;
currentAnimation_.reset();
}
+- (CGFloat)floatingBarShownFraction {
+ return [browserController_ floatingBarShownFraction];
+}
+
+- (void)changeFloatingBarShownFraction:(CGFloat)fraction {
+ [browserController_ setFloatingBarShownFraction:fraction];
+
+ mac_util::FullScreenMode desiredMode = [self desiredFullscreenMode];
+ if (desiredMode != currentFullscreenMode_ &&
+ [[browserController_ window] isMainWindow]) {
+ if (currentFullscreenMode_ == mac_util::kFullScreenModeNormal)
+ mac_util::RequestFullScreen(desiredMode);
+ else
+ mac_util::SwitchFullScreenModes(currentFullscreenMode_, desiredMode);
+ currentFullscreenMode_ = desiredMode;
+ }
+}
+
// Used to activate the floating bar in fullscreen mode.
- (void)mouseEntered:(NSEvent*)event {
DCHECK(isFullscreen_);
@@ -350,12 +372,18 @@ const CGFloat kTabStripVerticalOffset = 14;
return (screen == primaryScreen);
}
+- (mac_util::FullScreenMode)desiredFullscreenMode {
+ if ([browserController_ floatingBarShownFraction] >= 1.0)
+ return mac_util::kFullScreenModeHideDock;
+ return mac_util::kFullScreenModeHideAll;
+}
+
- (void)changeOverlayToFraction:(CGFloat)fraction
withAnimation:(BOOL)animate {
// The non-animated case is really simple, so do it and return.
if (!animate) {
[currentAnimation_ stopAnimation];
- [browserController_ setFloatingBarShownFraction:fraction];
+ [self changeFloatingBarShownFraction:fraction];
return;
}
@@ -378,7 +406,7 @@ const CGFloat kTabStripVerticalOffset = 14;
[[DropdownAnimation alloc] initWithFraction:fraction
fullDuration:kDropdownAnimationDuration
animationCurve:NSAnimationEaseOut
- controller:browserController_]);
+ controller:self]);
DCHECK(currentAnimation_);
[currentAnimation_ setAnimationBlockingMode:NSAnimationNonblocking];
[currentAnimation_ setDelegate:self];
@@ -544,21 +572,26 @@ const CGFloat kTabStripVerticalOffset = 14;
}
- (void)showActiveWindowUI {
- if (!menubarIsHidden_) {
- // Only hide the menubar if the window is on the primary screen.
- if ([self isWindowOnPrimaryScreen]) {
- mac_util::RequestFullScreen();
- menubarIsHidden_ = YES;
- }
+ DCHECK_EQ(currentFullscreenMode_, mac_util::kFullScreenModeNormal);
+ if (currentFullscreenMode_ != mac_util::kFullScreenModeNormal)
+ return;
+
+ // Only hide the menubar if the window is on the primary screen.
+ if ([self isWindowOnPrimaryScreen]) {
+ mac_util::FullScreenMode desiredMode = [self desiredFullscreenMode];
+ mac_util::RequestFullScreen(desiredMode);
+ currentFullscreenMode_ = desiredMode;
}
+
// TODO(rohitrao): Insert the Exit Fullscreen button. http://crbug.com/35956
}
- (void)hideActiveWindowUI {
- if (menubarIsHidden_) {
- mac_util::ReleaseFullScreen();
- menubarIsHidden_ = NO;
+ if (currentFullscreenMode_ != mac_util::kFullScreenModeNormal) {
+ mac_util::ReleaseFullScreen(currentFullscreenMode_);
+ currentFullscreenMode_ = mac_util::kFullScreenModeNormal;
}
+
// TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956
}