Merge pull request #2900 from atom/titlebar-drag
Make draggable region work for window with hidden titlebar
This commit is contained in:
commit
5de1b20935
3 changed files with 36 additions and 22 deletions
|
@ -68,6 +68,7 @@ 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),
|
||||||
|
@ -473,7 +474,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_)
|
if (has_frame_ && !force_using_draggable_region_)
|
||||||
return;
|
return;
|
||||||
draggable_region_ = DraggableRegionsToSkRegion(regions);
|
draggable_region_ = DraggableRegionsToSkRegion(regions);
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,13 @@ class NativeWindow : public content::WebContentsObserver,
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -257,6 +264,9 @@ class NativeWindow : public content::WebContentsObserver,
|
||||||
// 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_;
|
||||||
|
|
||||||
|
|
|
@ -351,22 +351,20 @@ NativeWindowMac::NativeWindowMac(
|
||||||
bool useStandardWindow = true;
|
bool useStandardWindow = true;
|
||||||
options.Get(switches::kStandardWindow, &useStandardWindow);
|
options.Get(switches::kStandardWindow, &useStandardWindow);
|
||||||
|
|
||||||
|
// New title bar styles are available in Yosemite or newer
|
||||||
|
std::string titleBarStyle;
|
||||||
|
if (base::mac::IsOSYosemiteOrLater())
|
||||||
|
options.Get(switches::kTitleBarStyle, &titleBarStyle);
|
||||||
|
|
||||||
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
|
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
|
||||||
NSMiniaturizableWindowMask | NSResizableWindowMask;
|
NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||||
if (!useStandardWindow || transparent() || !has_frame()) {
|
if (!useStandardWindow || transparent() || !has_frame()) {
|
||||||
styleMask |= NSTexturedBackgroundWindowMask;
|
styleMask |= NSTexturedBackgroundWindowMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string titleBarStyle = "default";
|
|
||||||
options.Get(switches::kTitleBarStyle, &titleBarStyle);
|
|
||||||
|
|
||||||
if (base::mac::IsOSYosemiteOrLater()) {
|
|
||||||
// New title bar styles are available in Yosemite or newer
|
|
||||||
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
|
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
|
||||||
styleMask |= NSFullSizeContentViewWindowMask;
|
styleMask |= NSFullSizeContentViewWindowMask;
|
||||||
styleMask |= NSUnifiedTitleAndToolbarWindowMask;
|
styleMask |= NSUnifiedTitleAndToolbarWindowMask;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
window_.reset([[AtomNSWindow alloc]
|
window_.reset([[AtomNSWindow alloc]
|
||||||
initWithContentRect:cocoa_bounds
|
initWithContentRect:cocoa_bounds
|
||||||
|
@ -393,18 +391,18 @@ NativeWindowMac::NativeWindowMac(
|
||||||
// We will manage window's lifetime ourselves.
|
// We will manage window's lifetime ourselves.
|
||||||
[window_ setReleasedWhenClosed:NO];
|
[window_ setReleasedWhenClosed:NO];
|
||||||
|
|
||||||
// Configure title bar look on Yosemite or newer
|
// Hide the title bar.
|
||||||
if (base::mac::IsOSYosemiteOrLater()) {
|
|
||||||
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
|
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
|
||||||
[window_ setTitlebarAppearsTransparent:YES];
|
[window_ setTitlebarAppearsTransparent:YES];
|
||||||
[window_ setTitleVisibility:NSWindowTitleHidden];
|
[window_ setTitleVisibility:NSWindowTitleHidden];
|
||||||
if (titleBarStyle == "hidden-inset") {
|
if (titleBarStyle == "hidden-inset") {
|
||||||
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"];
|
base::scoped_nsobject<NSToolbar> toolbar(
|
||||||
toolbar.showsBaselineSeparator = NO;
|
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
|
||||||
|
[toolbar setShowsBaselineSeparator:NO];
|
||||||
[window_ setToolbar:toolbar];
|
[window_ setToolbar:toolbar];
|
||||||
[toolbar release];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// 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.
|
||||||
|
@ -436,6 +434,11 @@ NativeWindowMac::NativeWindowMac(
|
||||||
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||||
|
|
||||||
InstallView();
|
InstallView();
|
||||||
|
|
||||||
|
// Install the DraggableRegionView if it is forced to use draggable regions
|
||||||
|
// for normal window.
|
||||||
|
if (has_frame() && force_using_draggable_region())
|
||||||
|
InstallDraggableRegionView();
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeWindowMac::~NativeWindowMac() {
|
NativeWindowMac::~NativeWindowMac() {
|
||||||
|
|
Loading…
Reference in a new issue