]> khamidou — GitHub mirrors - electron.git/commitdiff
osx: Make draggable region work for window with hidden titlebar
authorCheng Zhao <zcbenz@gmail.com>
Fri, 25 Sep 2015 08:38:36 +0000 (16:38 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 25 Sep 2015 08:38:36 +0000 (16:38 +0800)
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.mm

index e06633d7b7ca0afd1473d824deb5ebc048069320..c3620bba70527fb594814622f9cb4d2b93aa1176 100644 (file)
@@ -68,6 +68,7 @@ NativeWindow::NativeWindow(
     const mate::Dictionary& options)
     : content::WebContentsObserver(inspectable_web_contents->GetWebContents()),
       has_frame_(true),
+      force_using_draggable_region_(false),
       transparent_(false),
       enable_larger_than_screen_(false),
       is_closed_(false),
@@ -473,7 +474,7 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
 void NativeWindow::UpdateDraggableRegions(
     const std::vector<DraggableRegion>& regions) {
   // Draggable region is not supported for non-frameless window.
-  if (has_frame_)
+  if (has_frame_ && !force_using_draggable_region_)
     return;
   draggable_region_ = DraggableRegionsToSkRegion(regions);
 }
index e9a2b9433d13edac0d4cbaae25605cfd533fbb49..5c8d8c73b0fee8b9d2dba8bab7f6b5b4388062ff 100644 (file)
@@ -219,6 +219,13 @@ class NativeWindow : public content::WebContentsObserver,
   bool enable_larger_than_screen() const { return enable_larger_than_screen_; }
   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) {
     has_dialog_attached_ = has_dialog_attached;
   }
@@ -257,6 +264,9 @@ class NativeWindow : public content::WebContentsObserver,
   // Whether window has standard frame.
   bool has_frame_;
 
+  // Force the window to be aware of draggable regions.
+  bool force_using_draggable_region_;
+
   // Whether window is transparent.
   bool transparent_;
 
index c87e4b2dca1e2861c8bcf9d507acf5d4c3cc8e5e..f0a685e4d952ef98ebb9f5f8b9a68ef8c9407391 100644 (file)
@@ -391,7 +391,7 @@ NativeWindowMac::NativeWindowMac(
   // We will manage window's lifetime ourselves.
   [window_ setReleasedWhenClosed:NO];
 
-  // Configure title bar look on Yosemite or newer
+  // Hide the title bar.
   if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
     [window_ setTitlebarAppearsTransparent:YES];
     [window_ setTitleVisibility:NSWindowTitleHidden];
@@ -401,6 +401,8 @@ NativeWindowMac::NativeWindowMac(
       [toolbar setShowsBaselineSeparator:NO];
       [window_ setToolbar:toolbar];
     }
+    // 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.
@@ -432,6 +434,11 @@ NativeWindowMac::NativeWindowMac(
   [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
 
   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() {