views: Initial implementation of win.setParentWindow(parent)
authorCheng Zhao <zcbenz@gmail.com>
Sun, 19 Jun 2016 02:19:32 +0000 (11:19 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 20 Jun 2016 02:16:41 +0000 (11:16 +0900)
But it doesn't work, aparrently Chromium doesn't support changing
parent window dynamically on desktop.

atom/browser/native_window_views.cc

index b27f08a..a1081da 100644 (file)
@@ -29,6 +29,7 @@
 #include "ui/views/window/client_view.h"
 #include "ui/views/widget/native_widget_private.h"
 #include "ui/views/widget/widget.h"
+#include "ui/wm/core/window_util.h"
 #include "ui/wm/core/shadow_types.h"
 
 #if defined(USE_X11)
@@ -783,6 +784,21 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
 }
 
 void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
+  // Should work, but does not, it seems that the views toolkit doesn't support
+  // reparenting on desktop.
+#if defined(DEBUG)
+  if (parent) {
+    ::SetParent(GetAcceleratedWidget(), parent->GetAcceleratedWidget());
+    views::Widget::ReparentNativeView(GetNativeWindow(),
+                                      parent->GetNativeWindow());
+    wm::AddTransientChild(parent->GetNativeWindow(), GetNativeWindow());
+  } else {
+    if (!GetNativeWindow()->parent())
+      return;
+    views::Widget::ReparentNativeView(GetNativeWindow(), nullptr);
+    wm::RemoveTransientChild(GetNativeWindow()->parent(), GetNativeWindow());
+  }
+#endif
 }
 
 gfx::NativeWindow NativeWindowViews::GetNativeWindow() {