mac: Add win.setParentWindow(parent) API
authorCheng Zhao <zcbenz@gmail.com>
Fri, 17 Jun 2016 06:28:43 +0000 (15:28 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 20 Jun 2016 02:16:41 +0000 (11:16 +0900)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index 0d72a74f7d5a427fc4367a1eecbcc4e196ea5133..90d4a086091d5b774b213e3ebc624f7fb8a1f32a 100644 (file)
@@ -650,6 +650,10 @@ void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
   window_->SetAspectRatio(aspect_ratio, extra_size);
 }
 
+void Window::SetParentWindow(NativeWindow* parent) {
+  window_->SetParentWindow(parent);
+}
+
 v8::Local<v8::Value> Window::GetNativeWindowHandle() {
   gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
   return ToBuffer(
@@ -697,6 +701,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("setFullScreen", &Window::SetFullScreen)
       .SetMethod("isFullScreen", &Window::IsFullscreen)
       .SetMethod("setAspectRatio", &Window::SetAspectRatio)
+      .SetMethod("setParentWindow", &Window::SetParentWindow)
       .SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle)
       .SetMethod("getBounds", &Window::GetBounds)
       .SetMethod("setBounds", &Window::SetBounds)
index 9d3f7ef2402e4925b75b26797363c6827bd62d9c..fb78b6deb55d93b065d2733d9838feb3d87b7d8e 100644 (file)
@@ -159,6 +159,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetMenuBarVisibility(bool visible);
   bool IsMenuBarVisible();
   void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
+  void SetParentWindow(NativeWindow* parent);
   v8::Local<v8::Value> GetNativeWindowHandle();
 
 #if defined(OS_WIN)
index a644682e3458d19620e8ceccdf6ee6a6a3f8c731..8dd3dc5f334b97639aea986dc991b306141da29e 100644 (file)
@@ -158,6 +158,7 @@ class NativeWindow : public base::SupportsUserData,
   virtual void SetFocusable(bool focusable);
   virtual void SetMenu(ui::MenuModel* menu);
   virtual bool HasModalDialog();
+  virtual void SetParentWindow(NativeWindow* parent) = 0;
   virtual gfx::NativeWindow GetNativeWindow() = 0;
   virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
 
index 899043fd6acba7ef91b4bd01e5340fc5e48ca4c1..2e0b769d2adc7e8077c41c8a3eaaa2c3eb55fa18 100644 (file)
@@ -78,6 +78,7 @@ class NativeWindowMac : public NativeWindow {
   bool IsDocumentEdited() override;
   void SetIgnoreMouseEvents(bool ignore) override;
   bool HasModalDialog() override;
+  void SetParentWindow(NativeWindow* parent) override;
   gfx::NativeWindow GetNativeWindow() override;
   gfx::AcceleratedWidget GetAcceleratedWidget() override;
   void SetProgressBar(double progress) override;
index e15ff0c6cee69f75ded66fc1c738c8cf92bff4d8..b7e71f749ec0693fab3bdcf7b2e8087a02c81bfa 100644 (file)
@@ -911,6 +911,16 @@ bool NativeWindowMac::HasModalDialog() {
   return [window_ attachedSheet] != nil;
 }
 
+void NativeWindowMac::SetParentWindow(NativeWindow* parent) {
+  // Remove current parent window.
+  if ([window_ parentWindow])
+    [[window_ parentWindow] removeChildWindow:window_];
+
+  // Set new current window.
+  if (parent)
+    [parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove];
+}
+
 gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
   return window_;
 }
index 021ceba005e2b0966c9d68390d8e8d029bb08da2..ca93bb08a46fb1f676af2d6b766c4c3c99a03cf1 100644 (file)
@@ -772,6 +772,9 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
   Layout();
 }
 
+void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
+}
+
 gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
   return window_->GetNativeWindow();
 }
index 53774203742c306b7d1a69a3c34efe1369e41a52..2c63270815e66e9e2da47ed2d54aa6a965c75a20 100644 (file)
@@ -94,6 +94,7 @@ class NativeWindowViews : public NativeWindow,
   void SetIgnoreMouseEvents(bool ignore) override;
   void SetFocusable(bool focusable) override;
   void SetMenu(ui::MenuModel* menu_model) override;
+  void SetParentWindow(NativeWindow* parent) override;
   gfx::NativeWindow GetNativeWindow() override;
   void SetOverlayIcon(const gfx::Image& overlay,
                       const std::string& description) override;