Add win.getParentWindow() API
authorCheng Zhao <zcbenz@gmail.com>
Fri, 17 Jun 2016 07:09:43 +0000 (16:09 +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

index 90d4a08..3e47003 100644 (file)
@@ -650,8 +650,23 @@ void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
   window_->SetAspectRatio(aspect_ratio, extra_size);
 }
 
-void Window::SetParentWindow(NativeWindow* parent) {
-  window_->SetParentWindow(parent);
+void Window::SetParentWindow(mate::Arguments* args) {
+  v8::Local<v8::Value> value;
+  NativeWindow* parent;
+  if (args->GetNext(&value) &&
+      mate::ConvertFromV8(isolate(), value, &parent)) {
+    parent_window_.Reset(isolate(), value);
+    window_->SetParentWindow(parent);
+  } else {
+    args->ThrowError("Must pass BrowserWindow instance or null");
+  }
+}
+
+v8::Local<v8::Value> Window::GetParentWindow() {
+  if (parent_window_.IsEmpty())
+    return v8::Null(isolate());
+  else
+    return v8::Local<v8::Value>::New(isolate(), parent_window_);
 }
 
 v8::Local<v8::Value> Window::GetNativeWindowHandle() {
@@ -702,6 +717,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("isFullScreen", &Window::IsFullscreen)
       .SetMethod("setAspectRatio", &Window::SetAspectRatio)
       .SetMethod("setParentWindow", &Window::SetParentWindow)
+      .SetMethod("getParentWindow", &Window::GetParentWindow)
       .SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle)
       .SetMethod("getBounds", &Window::GetBounds)
       .SetMethod("setBounds", &Window::SetBounds)
index fb78b6d..0078548 100644 (file)
@@ -159,7 +159,8 @@ class Window : public mate::TrackableObject<Window>,
   void SetMenuBarVisibility(bool visible);
   bool IsMenuBarVisible();
   void SetAspectRatio(double aspect_ratio, mate::Arguments* args);
-  void SetParentWindow(NativeWindow* parent);
+  void SetParentWindow(mate::Arguments* args);
+  v8::Local<v8::Value> GetParentWindow();
   v8::Local<v8::Value> GetNativeWindowHandle();
 
 #if defined(OS_WIN)
@@ -189,6 +190,7 @@ class Window : public mate::TrackableObject<Window>,
 
   v8::Global<v8::Value> web_contents_;
   v8::Global<v8::Value> menu_;
+  v8::Global<v8::Value> parent_window_;
 
   api::WebContents* api_web_contents_;