Implement titleBarStyle without using NSFullSizeContentViewWindowMask

This commit is contained in:
Cheng Zhao 2016-05-17 15:48:14 +09:00
parent ecbb088ea6
commit f53aabaef5
4 changed files with 19 additions and 25 deletions

View file

@ -49,7 +49,6 @@ NativeWindow::NativeWindow(
const mate::Dictionary& options) const mate::Dictionary& options)
: content::WebContentsObserver(inspectable_web_contents->GetWebContents()), : content::WebContentsObserver(inspectable_web_contents->GetWebContents()),
has_frame_(true), has_frame_(true),
force_using_draggable_region_(false),
transparent_(false), transparent_(false),
enable_larger_than_screen_(false), enable_larger_than_screen_(false),
is_closed_(false), is_closed_(false),
@ -573,7 +572,7 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
void NativeWindow::UpdateDraggableRegions( void NativeWindow::UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) { const std::vector<DraggableRegion>& regions) {
// Draggable region is not supported for non-frameless window. // Draggable region is not supported for non-frameless window.
if (has_frame_ && !force_using_draggable_region_) if (has_frame_)
return; return;
draggable_region_ = DraggableRegionsToSkRegion(regions); draggable_region_ = DraggableRegionsToSkRegion(regions);
} }

View file

@ -246,18 +246,13 @@ class NativeWindow : public base::SupportsUserData,
} }
bool has_frame() const { return has_frame_; } bool has_frame() const { return has_frame_; }
void set_has_frame(bool has_frame) { has_frame_ = has_frame; }
bool transparent() const { return transparent_; } bool transparent() const { return transparent_; }
SkRegion* draggable_region() const { return draggable_region_.get(); } SkRegion* draggable_region() const { return draggable_region_.get(); }
bool enable_larger_than_screen() const { return enable_larger_than_screen_; } bool enable_larger_than_screen() const { return enable_larger_than_screen_; }
gfx::ImageSkia icon() const { return icon_; } gfx::ImageSkia icon() const { return icon_; }
bool force_using_draggable_region() const {
return force_using_draggable_region_;
}
void set_force_using_draggable_region(bool force) {
force_using_draggable_region_ = true;
}
void set_has_dialog_attached(bool has_dialog_attached) { void set_has_dialog_attached(bool has_dialog_attached) {
has_dialog_attached_ = has_dialog_attached; has_dialog_attached_ = has_dialog_attached;
} }
@ -299,9 +294,6 @@ class NativeWindow : public base::SupportsUserData,
// Whether window has standard frame. // Whether window has standard frame.
bool has_frame_; bool has_frame_;
// Force the window to be aware of draggable regions.
bool force_using_draggable_region_;
// Whether window is transparent. // Whether window is transparent.
bool transparent_; bool transparent_;

View file

@ -142,6 +142,10 @@ class NativeWindowMac : public NativeWindow {
// The presentation options before entering kiosk mode. // The presentation options before entering kiosk mode.
NSApplicationPresentationOptions kiosk_options_; NSApplicationPresentationOptions kiosk_options_;
// Force showing the buttons for frameless window.
bool force_show_buttons_;
// Whether to hide the native toolbar under fullscreen mode.
bool should_hide_native_toolbar_in_fullscreen_; bool should_hide_native_toolbar_in_fullscreen_;
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac); DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);

View file

@ -391,6 +391,7 @@ NativeWindowMac::NativeWindowMac(
: NativeWindow(web_contents, options), : NativeWindow(web_contents, options),
is_kiosk_(false), is_kiosk_(false),
attention_request_id_(0), attention_request_id_(0),
force_show_buttons_(false),
should_hide_native_toolbar_in_fullscreen_(false) { should_hide_native_toolbar_in_fullscreen_(false) {
int width = 800, height = 600; int width = 800, height = 600;
options.Get(options::kWidth, &width); options.Get(options::kWidth, &width);
@ -438,22 +439,17 @@ NativeWindowMac::NativeWindowMac(
if (closable) { if (closable) {
styleMask |= NSClosableWindowMask; styleMask |= NSClosableWindowMask;
} }
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
// The window without titlebar is treated the same with frameless window.
set_has_frame(false);
force_show_buttons_ = true;
}
if (!useStandardWindow || transparent() || !has_frame()) { if (!useStandardWindow || transparent() || !has_frame()) {
styleMask |= NSTexturedBackgroundWindowMask; styleMask |= NSTexturedBackgroundWindowMask;
} }
if (resizable) { if (resizable) {
styleMask |= NSResizableWindowMask; styleMask |= NSResizableWindowMask;
} }
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
styleMask |= NSFullSizeContentViewWindowMask;
styleMask |= NSUnifiedTitleAndToolbarWindowMask;
}
// We capture this because we need to access the option later when
// entering/exiting fullscreen and since the options dict is only passed to
// the constructor but not stored, lets store this option this way.
if (titleBarStyle == "hidden-inset") {
should_hide_native_toolbar_in_fullscreen_ = true;
}
window_.reset([[AtomNSWindow alloc] window_.reset([[AtomNSWindow alloc]
initWithContentRect:cocoa_bounds initWithContentRect:cocoa_bounds
@ -498,9 +494,8 @@ NativeWindowMac::NativeWindowMac(
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
[toolbar setShowsBaselineSeparator:NO]; [toolbar setShowsBaselineSeparator:NO];
[window_ setToolbar:toolbar]; [window_ setToolbar:toolbar];
should_hide_native_toolbar_in_fullscreen_ = true;
} }
// We should be aware of draggable regions when using hidden titlebar.
set_force_using_draggable_region(true);
} }
// On OS X the initial window size doesn't include window frame. // On OS X the initial window size doesn't include window frame.
@ -1013,6 +1008,10 @@ void NativeWindowMac::InstallView() {
[view setFrame:[content_view_ bounds]]; [view setFrame:[content_view_ bounds]];
[content_view_ addSubview:view]; [content_view_ addSubview:view];
if (force_show_buttons_)
return;
// Hide the window buttons.
[[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES]; [[window_ standardWindowButton:NSWindowZoomButton] setHidden:YES];
[[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; [[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window_ standardWindowButton:NSWindowCloseButton] setHidden:YES]; [[window_ standardWindowButton:NSWindowCloseButton] setHidden:YES];
@ -1031,7 +1030,7 @@ void NativeWindowMac::UninstallView() {
void NativeWindowMac::UpdateDraggableRegionViews( void NativeWindowMac::UpdateDraggableRegionViews(
const std::vector<DraggableRegion>& regions) { const std::vector<DraggableRegion>& regions) {
if (has_frame() && !force_using_draggable_region()) if (has_frame())
return; return;
// All ControlRegionViews should be added as children of the WebContentsView, // All ControlRegionViews should be added as children of the WebContentsView,