Skip to content

Commit 5de1b20

Browse files
committed
Merge pull request electron#2900 from atom/titlebar-drag
Make draggable region work for window with hidden titlebar
2 parents 94e5018 + 7884a23 commit 5de1b20

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

atom/browser/native_window.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ NativeWindow::NativeWindow(
6868
const mate::Dictionary& options)
6969
: content::WebContentsObserver(inspectable_web_contents->GetWebContents()),
7070
has_frame_(true),
71+
force_using_draggable_region_(false),
7172
transparent_(false),
7273
enable_larger_than_screen_(false),
7374
is_closed_(false),
@@ -473,7 +474,7 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
473474
void NativeWindow::UpdateDraggableRegions(
474475
const std::vector<DraggableRegion>& regions) {
475476
// Draggable region is not supported for non-frameless window.
476-
if (has_frame_)
477+
if (has_frame_ && !force_using_draggable_region_)
477478
return;
478479
draggable_region_ = DraggableRegionsToSkRegion(regions);
479480
}

atom/browser/native_window.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ class NativeWindow : public content::WebContentsObserver,
219219
bool enable_larger_than_screen() const { return enable_larger_than_screen_; }
220220
gfx::ImageSkia icon() const { return icon_; }
221221

222+
bool force_using_draggable_region() const {
223+
return force_using_draggable_region_;
224+
}
225+
void set_force_using_draggable_region(bool force) {
226+
force_using_draggable_region_ = true;
227+
}
228+
222229
void set_has_dialog_attached(bool has_dialog_attached) {
223230
has_dialog_attached_ = has_dialog_attached;
224231
}
@@ -257,6 +264,9 @@ class NativeWindow : public content::WebContentsObserver,
257264
// Whether window has standard frame.
258265
bool has_frame_;
259266

267+
// Force the window to be aware of draggable regions.
268+
bool force_using_draggable_region_;
269+
260270
// Whether window is transparent.
261271
bool transparent_;
262272

atom/browser/native_window_mac.mm

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -351,21 +351,19 @@ - (void)drawRect:(NSRect)dirtyRect {
351351
bool useStandardWindow = true;
352352
options.Get(switches::kStandardWindow, &useStandardWindow);
353353

354+
// New title bar styles are available in Yosemite or newer
355+
std::string titleBarStyle;
356+
if (base::mac::IsOSYosemiteOrLater())
357+
options.Get(switches::kTitleBarStyle, &titleBarStyle);
358+
354359
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
355360
NSMiniaturizableWindowMask | NSResizableWindowMask;
356361
if (!useStandardWindow || transparent() || !has_frame()) {
357362
styleMask |= NSTexturedBackgroundWindowMask;
358363
}
359-
360-
std::string titleBarStyle = "default";
361-
options.Get(switches::kTitleBarStyle, &titleBarStyle);
362-
363-
if (base::mac::IsOSYosemiteOrLater()) {
364-
// New title bar styles are available in Yosemite or newer
365-
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
366-
styleMask |= NSFullSizeContentViewWindowMask;
367-
styleMask |= NSUnifiedTitleAndToolbarWindowMask;
368-
}
364+
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
365+
styleMask |= NSFullSizeContentViewWindowMask;
366+
styleMask |= NSUnifiedTitleAndToolbarWindowMask;
369367
}
370368

371369
window_.reset([[AtomNSWindow alloc]
@@ -393,18 +391,18 @@ - (void)drawRect:(NSRect)dirtyRect {
393391
// We will manage window's lifetime ourselves.
394392
[window_ setReleasedWhenClosed:NO];
395393

396-
// Configure title bar look on Yosemite or newer
397-
if (base::mac::IsOSYosemiteOrLater()) {
398-
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
399-
[window_ setTitlebarAppearsTransparent:YES];
400-
[window_ setTitleVisibility:NSWindowTitleHidden];
401-
if (titleBarStyle == "hidden-inset") {
402-
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"];
403-
toolbar.showsBaselineSeparator = NO;
404-
[window_ setToolbar:toolbar];
405-
[toolbar release];
406-
}
394+
// Hide the title bar.
395+
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
396+
[window_ setTitlebarAppearsTransparent:YES];
397+
[window_ setTitleVisibility:NSWindowTitleHidden];
398+
if (titleBarStyle == "hidden-inset") {
399+
base::scoped_nsobject<NSToolbar> toolbar(
400+
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
401+
[toolbar setShowsBaselineSeparator:NO];
402+
[window_ setToolbar:toolbar];
407403
}
404+
// We should be aware of draggable regions when using hidden titlebar.
405+
set_force_using_draggable_region(true);
408406
}
409407

410408
// On OS X the initial window size doesn't include window frame.
@@ -436,6 +434,11 @@ - (void)drawRect:(NSRect)dirtyRect {
436434
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
437435

438436
InstallView();
437+
438+
// Install the DraggableRegionView if it is forced to use draggable regions
439+
// for normal window.
440+
if (has_frame() && force_using_draggable_region())
441+
InstallDraggableRegionView();
439442
}
440443

441444
NativeWindowMac::~NativeWindowMac() {

0 commit comments

Comments
 (0)