Commit e401427d authored by jackhou@chromium.org's avatar jackhou@chromium.org

[Mac] Update fullscreen state when window is fullscreened natively.

This calls OnNativeWindowChanged when the window enters or exits
fullscreen. It also redundantly calls AppWindow::OSFullscreen and
AppWindow::Restore to get the AppWindow to update it's internal state.

BUG=372301

Review URL: https://codereview.chromium.org/280483004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270904 0039d316-1c4b-4281-b951-d872f2087c98
parent 66fc6a60
...@@ -338,6 +338,10 @@ class AppWindow : public content::NotificationObserver, ...@@ -338,6 +338,10 @@ class AppWindow : public content::NotificationObserver,
return app_window_contents_.get(); return app_window_contents_.get();
} }
int fullscreen_types_for_test() {
return fullscreen_types_;
}
// Set whether the window should stay above other windows which are not // Set whether the window should stay above other windows which are not
// configured to be always-on-top. // configured to be always-on-top.
void SetAlwaysOnTop(bool always_on_top); void SetAlwaysOnTop(bool always_on_top);
......
...@@ -101,6 +101,12 @@ class NativeAppWindowCocoa : public apps::NativeAppWindow, ...@@ -101,6 +101,12 @@ class NativeAppWindowCocoa : public apps::NativeAppWindow,
// Called when the window is zoomed (maximized or de-maximized). // Called when the window is zoomed (maximized or de-maximized).
void WindowWillZoom(); void WindowWillZoom();
// Called when the window enters fullscreen.
void WindowDidEnterFullscreen();
// Called when the window exits fullscreen.
void WindowDidExitFullscreen();
// Called to handle a key event. // Called to handle a key event.
bool HandledByExtensionCommand(NSEvent* event); bool HandledByExtensionCommand(NSEvent* event);
......
...@@ -160,12 +160,12 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions( ...@@ -160,12 +160,12 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
- (void)windowDidEnterFullScreen:(NSNotification*)notification { - (void)windowDidEnterFullScreen:(NSNotification*)notification {
if (appWindow_) if (appWindow_)
appWindow_->WindowDidFinishResize(); appWindow_->WindowDidEnterFullscreen();
} }
- (void)windowDidExitFullScreen:(NSNotification*)notification { - (void)windowDidExitFullScreen:(NSNotification*)notification {
if (appWindow_) if (appWindow_)
appWindow_->WindowDidFinishResize(); appWindow_->WindowDidExitFullscreen();
} }
- (void)windowDidMove:(NSNotification*)notification { - (void)windowDidMove:(NSNotification*)notification {
...@@ -820,13 +820,6 @@ void NativeAppWindowCocoa::WindowDidFinishResize() { ...@@ -820,13 +820,6 @@ void NativeAppWindowCocoa::WindowDidFinishResize() {
else if (NSEqualPoints(frame.origin, screen.origin)) else if (NSEqualPoints(frame.origin, screen.origin))
is_maximized_ = true; is_maximized_ = true;
// Update |is_fullscreen_| if needed.
is_fullscreen_ = ([window() styleMask] & NSFullScreenWindowMask) != 0;
// If not fullscreen but the window is constrained, disable the fullscreen UI
// control.
if (!is_fullscreen_ && !shows_fullscreen_controls_)
SetFullScreenCollectionBehavior(window(), false);
UpdateRestoredBounds(); UpdateRestoredBounds();
} }
...@@ -848,6 +841,21 @@ void NativeAppWindowCocoa::WindowDidDeminiaturize() { ...@@ -848,6 +841,21 @@ void NativeAppWindowCocoa::WindowDidDeminiaturize() {
app_window_->OnNativeWindowChanged(); app_window_->OnNativeWindowChanged();
} }
void NativeAppWindowCocoa::WindowDidEnterFullscreen() {
is_fullscreen_ = true;
app_window_->OSFullscreen();
app_window_->OnNativeWindowChanged();
}
void NativeAppWindowCocoa::WindowDidExitFullscreen() {
is_fullscreen_ = false;
if (!shows_fullscreen_controls_)
SetFullScreenCollectionBehavior(window(), false);
app_window_->Restore();
app_window_->OnNativeWindowChanged();
}
void NativeAppWindowCocoa::WindowWillZoom() { void NativeAppWindowCocoa::WindowWillZoom() {
// See top of file NOTE: Maximize and Zoom. // See top of file NOTE: Maximize and Zoom.
if (IsMaximized()) if (IsMaximized())
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "apps/app_window_registry.h" #include "apps/app_window_registry.h"
#include "base/mac/mac_util.h"
#include "chrome/browser/apps/app_browsertest_util.h" #include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
...@@ -112,3 +113,120 @@ IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) { ...@@ -112,3 +113,120 @@ IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, HideShowWithApp) {
EXPECT_TRUE([ns_window isVisible]); EXPECT_TRUE([ns_window isVisible]);
EXPECT_FALSE([other_ns_window isVisible]); EXPECT_FALSE([other_ns_window isVisible]);
} }
// Only test fullscreen for 10.7 and above.
// 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
@interface NSWindow (LionSDKDeclarations)
- (void)toggleFullScreen:(id)sender;
@end
enum {
NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7,
NSFullScreenWindowMask = 1 << 14
};
NSString* const NSWindowDidEnterFullScreenNotification =
@"NSWindowDidEnterFullScreenNotification";
NSString* const NSWindowDidExitFullScreenNotification =
@"NSWindowDidExitFullScreenNotification";
#endif // MAC_OS_X_VERSION_10_7
@interface ScopedNotificationWatcher : NSObject {
@private
BOOL received_;
}
- (id)initWithNotification:(NSString*)notification
andObject:(NSObject*)object;
- (void)onNotification:(NSString*)notification;
- (void)waitForNotification;
@end
@implementation ScopedNotificationWatcher
- (id)initWithNotification:(NSString*)notification
andObject:(NSObject*)object {
if ((self = [super init])) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(onNotification:)
name:notification
object:object];
}
return self;
}
- (void)onNotification:(NSString*)notification {
received_ = YES;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)waitForNotification {
while (!received_)
content::RunAllPendingInMessageLoop();
}
@end
// Test that NativeAppWindow and AppWindow fullscreen state is updated when
// the window is fullscreened natively.
IN_PROC_BROWSER_TEST_F(NativeAppWindowCocoaBrowserTest, Fullscreen) {
if (!base::mac::IsOSLionOrLater())
return;
SetUpAppWithWindows(1);
apps::AppWindow* app_window = GetFirstAppWindow();
apps::NativeAppWindow* window = app_window->GetBaseWindow();
NSWindow* ns_window = app_window->GetNativeWindow();
base::scoped_nsobject<ScopedNotificationWatcher> watcher;
EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE,
app_window->fullscreen_types_for_test());
EXPECT_FALSE(window->IsFullscreen());
EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
watcher.reset([[ScopedNotificationWatcher alloc]
initWithNotification:NSWindowDidEnterFullScreenNotification
andObject:ns_window]);
[ns_window toggleFullScreen:nil];
[watcher waitForNotification];
EXPECT_TRUE(app_window->fullscreen_types_for_test() &
apps::AppWindow::FULLSCREEN_TYPE_OS);
EXPECT_TRUE(window->IsFullscreen());
EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
watcher.reset([[ScopedNotificationWatcher alloc]
initWithNotification:NSWindowDidExitFullScreenNotification
andObject:ns_window]);
app_window->Restore();
EXPECT_FALSE(window->IsFullscreenOrPending());
[watcher waitForNotification];
EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE,
app_window->fullscreen_types_for_test());
EXPECT_FALSE(window->IsFullscreen());
EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
watcher.reset([[ScopedNotificationWatcher alloc]
initWithNotification:NSWindowDidEnterFullScreenNotification
andObject:ns_window]);
app_window->Fullscreen();
EXPECT_TRUE(window->IsFullscreenOrPending());
[watcher waitForNotification];
EXPECT_TRUE(app_window->fullscreen_types_for_test() &
apps::AppWindow::FULLSCREEN_TYPE_WINDOW_API);
EXPECT_TRUE(window->IsFullscreen());
EXPECT_TRUE([ns_window styleMask] & NSFullScreenWindowMask);
watcher.reset([[ScopedNotificationWatcher alloc]
initWithNotification:NSWindowDidExitFullScreenNotification
andObject:ns_window]);
[ns_window toggleFullScreen:nil];
[watcher waitForNotification];
EXPECT_EQ(apps::AppWindow::FULLSCREEN_TYPE_NONE,
app_window->fullscreen_types_for_test());
EXPECT_FALSE(window->IsFullscreen());
EXPECT_FALSE([ns_window styleMask] & NSFullScreenWindowMask);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment