Merge pull request #10254 from zachflower/feature/simple-fullscreen-mode

Feature/simple fullscreen mode
This commit is contained in:
Cheng Zhao 2017-09-14 09:39:50 +09:00 committed by GitHub
commit a19a229a59
10 changed files with 141 additions and 1 deletions

View file

@ -730,6 +730,13 @@ enum {
[super performClose:sender];
}
- (void)toggleFullScreen:(id)sender {
if (shell_->simple_fullscreen())
shell_->SetSimpleFullScreen(!shell_->IsSimpleFullScreen());
else
[super toggleFullScreen:sender];
}
- (void)performMiniaturize:(id)sender {
if (shell_->title_bar_style() == atom::NativeWindowMac::CUSTOM_BUTTONS_ON_HOVER)
[self miniaturize:self];
@ -829,7 +836,9 @@ NativeWindowMac::NativeWindowMac(
zoom_to_page_width_(false),
fullscreen_window_title_(false),
attention_request_id_(0),
title_bar_style_(NORMAL) {
title_bar_style_(NORMAL),
always_simple_fullscreen_(false),
is_simple_fullscreen_(false) {
int width = 800, height = 600;
options.Get(options::kWidth, &width);
options.Get(options::kHeight, &height);
@ -975,6 +984,8 @@ NativeWindowMac::NativeWindowMac(
options.Get(options::kFullscreenWindowTitle, &fullscreen_window_title_);
options.Get(options::kSimpleFullScreen, &always_simple_fullscreen_);
// Enable the NSView to accept first mouse event.
bool acceptsFirstMouse = false;
options.Get(options::kAcceptFirstMouse, &acceptsFirstMouse);
@ -1361,6 +1372,80 @@ void NativeWindowMac::FlashFrame(bool flash) {
void NativeWindowMac::SetSkipTaskbar(bool skip) {
}
void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
NSWindow* window = GetNativeWindow();
if (simple_fullscreen && !is_simple_fullscreen_) {
is_simple_fullscreen_ = true;
// Take note of the current window size
original_frame_ = [window frame];
simple_fullscreen_options_ = [NSApp currentSystemPresentationOptions];
simple_fullscreen_mask_ = [window styleMask];
// We can simulate the pre-Lion fullscreen by auto-hiding the dock and menu bar
NSApplicationPresentationOptions options =
NSApplicationPresentationAutoHideDock +
NSApplicationPresentationAutoHideMenuBar;
[NSApp setPresentationOptions:options];
was_maximizable_ = IsMaximizable();
was_movable_ = IsMovable();
NSRect fullscreenFrame = [window.screen frame];
if ( !fullscreen_window_title() ) {
// Hide the titlebar
SetStyleMask(false, NSTitledWindowMask);
// Resize the window to accomodate the _entire_ screen size
fullscreenFrame.size.height -= [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
} else {
// No need to hide the title, but we should still hide the window buttons
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
}
[window setFrame:fullscreenFrame display: YES animate: YES];
// Fullscreen windows can't be resized, minimized, maximized, or moved
SetMinimizable(false);
SetResizable(false);
SetMaximizable(false);
SetMovable(false);
} else if (!simple_fullscreen && is_simple_fullscreen_) {
is_simple_fullscreen_ = false;
if ( !fullscreen_window_title() ) {
// Restore the titlebar
SetStyleMask(true, NSTitledWindowMask);
} else {
// Show the window buttons
[[window standardWindowButton:NSWindowZoomButton] setHidden:NO];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:NO];
[[window standardWindowButton:NSWindowCloseButton] setHidden:NO];
}
[window setFrame:original_frame_ display: YES animate: YES];
[NSApp setPresentationOptions:simple_fullscreen_options_];
// Restore original style mask
ScopedDisableResize disable_resize;
[window_ setStyleMask:simple_fullscreen_mask_];
// Restore window manipulation abilities
SetMaximizable(was_maximizable_);
SetMovable(was_movable_);
}
}
bool NativeWindowMac::IsSimpleFullScreen() {
return is_simple_fullscreen_;
}
void NativeWindowMac::SetKiosk(bool kiosk) {
if (kiosk && !is_kiosk_) {
kiosk_options_ = [NSApp currentSystemPresentationOptions];