]> khamidou — GitHub mirrors - electron.git/commitdiff
Don't put gfx_converter's implementaion in header file
authorCheng Zhao <zcbenz@gmail.com>
Wed, 14 Jan 2015 22:38:51 +0000 (14:38 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 16 Jan 2015 19:01:38 +0000 (11:01 -0800)
atom.gyp
atom/common/api/atom_api_screen.cc
atom/common/native_mate_converters/gfx_converter.cc [new file with mode: 0644]
atom/common/native_mate_converters/gfx_converter.h

index 7aa21a9d584560b060622f3c26b0dc92f7780d20..21563b6359c32c946561cbefa833a9100173f888 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'atom/common/native_mate_converters/accelerator_converter.cc',
       'atom/common/native_mate_converters/accelerator_converter.h',
       'atom/common/native_mate_converters/file_path_converter.h',
+      'atom/common/native_mate_converters/gfx_converter.cc',
       'atom/common/native_mate_converters/gfx_converter.h',
       'atom/common/native_mate_converters/gurl_converter.h',
       'atom/common/native_mate_converters/image_converter.cc',
index 77d6110e796da9ed3b71460e9d08f24b6f00d072..2e3fd3b5007451945cb288dcccdcb4d48a603a27 100644 (file)
@@ -3,6 +3,10 @@
 // found in the LICENSE file.
 
 #include "atom/common/native_mate_converters/gfx_converter.h"
+#include "base/bind.h"
+#include "native_mate/dictionary.h"
+#include "ui/gfx/screen.h"
+
 #include "atom/common/node_includes.h"
 
 namespace {
diff --git a/atom/common/native_mate_converters/gfx_converter.cc b/atom/common/native_mate_converters/gfx_converter.cc
new file mode 100644 (file)
index 0000000..3d74bdb
--- /dev/null
@@ -0,0 +1,93 @@
+// Copyright (c) 2015 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/common/native_mate_converters/gfx_converter.h"
+
+#include "native_mate/dictionary.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/screen.h"
+#include "ui/gfx/size.h"
+
+namespace mate {
+
+v8::Handle<v8::Value> Converter<gfx::Point>::ToV8(v8::Isolate* isolate,
+                                                  const gfx::Point& val) {
+  mate::Dictionary dict(isolate, v8::Object::New(isolate));
+  dict.Set("x", val.x());
+  dict.Set("y", val.y());
+  return dict.GetHandle();
+}
+
+bool Converter<gfx::Point>::FromV8(v8::Isolate* isolate,
+                                   v8::Handle<v8::Value> val,
+                                   gfx::Point* out) {
+  mate::Dictionary dict;
+  if (!ConvertFromV8(isolate, val, &dict))
+    return false;
+  int x, y;
+  if (!dict.Get("x", &x) || !dict.Get("y", &y))
+    return false;
+  *out = gfx::Point(x, y);
+  return true;
+}
+
+v8::Handle<v8::Value> Converter<gfx::Size>::ToV8(v8::Isolate* isolate,
+                                                  const gfx::Size& val) {
+  mate::Dictionary dict(isolate, v8::Object::New(isolate));
+  dict.Set("width", val.width());
+  dict.Set("height", val.height());
+  return dict.GetHandle();
+}
+
+bool Converter<gfx::Size>::FromV8(v8::Isolate* isolate,
+                                  v8::Handle<v8::Value> val,
+                                  gfx::Size* out) {
+  mate::Dictionary dict;
+  if (!ConvertFromV8(isolate, val, &dict))
+    return false;
+  int width, height;
+  if (!dict.Get("width", &width) || !dict.Get("height", &height))
+    return false;
+  *out = gfx::Size(width, height);
+  return true;
+}
+
+v8::Handle<v8::Value> Converter<gfx::Rect>::ToV8(v8::Isolate* isolate,
+                                                 const gfx::Rect& val) {
+  mate::Dictionary dict(isolate, v8::Object::New(isolate));
+  dict.Set("x", val.x());
+  dict.Set("y", val.y());
+  dict.Set("width", val.width());
+  dict.Set("height", val.height());
+  return dict.GetHandle();
+}
+
+bool Converter<gfx::Rect>::FromV8(v8::Isolate* isolate,
+                                  v8::Handle<v8::Value> val,
+                                  gfx::Rect* out) {
+  mate::Dictionary dict;
+  if (!ConvertFromV8(isolate, val, &dict))
+    return false;
+  int x, y, width, height;
+  if (!dict.Get("x", &x) || !dict.Get("y", &y) ||
+      !dict.Get("width", &width) || !dict.Get("height", &height))
+    return false;
+  *out = gfx::Rect(x, y, width, height);
+  return true;
+}
+
+v8::Handle<v8::Value> Converter<gfx::Display>::ToV8(v8::Isolate* isolate,
+                                                    const gfx::Display& val) {
+  mate::Dictionary dict(isolate, v8::Object::New(isolate));
+  dict.Set("id", val.id());
+  dict.Set("bounds", val.bounds());
+  dict.Set("workArea", val.work_area());
+  dict.Set("size", val.size());
+  dict.Set("workAreaSize", val.work_area_size());
+  dict.Set("scaleFactor", val.device_scale_factor());
+  return dict.GetHandle();
+}
+
+}  // namespace mate
index 2cd9bf6bb0e1bf5c883f56a6ade422c38ab70db7..35fd5039a72f157dbd22a72ca374ff78b22ee371 100644 (file)
@@ -5,95 +5,51 @@
 #ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_GFX_CONVERTER_H_
 #define ATOM_COMMON_NATIVE_MATE_CONVERTERS_GFX_CONVERTER_H_
 
-#include "native_mate/dictionary.h"
-#include "ui/gfx/point.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/screen.h"
-#include "ui/gfx/size.h"
+#include "native_mate/converter.h"
+
+namespace gfx {
+class Point;
+class Size;
+class Rect;
+class Display;
+}
 
 namespace mate {
 
 template<>
 struct Converter<gfx::Point> {
   static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
-                                    const gfx::Point& val) {
-    mate::Dictionary dict(isolate, v8::Object::New(isolate));
-    dict.Set("x", val.x());
-    dict.Set("y", val.y());
-    return dict.GetHandle();
-  }
-  static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
-                     gfx::Point* out) {
-    mate::Dictionary dict;
-    if (!ConvertFromV8(isolate, val, &dict))
-      return false;
-    int x, y;
-    if (!dict.Get("x", &x) || !dict.Get("y", &y))
-      return false;
-    *out = gfx::Point(x, y);
-    return true;
-  }
+                                    const gfx::Point& val);
+  static bool FromV8(v8::Isolate* isolate,
+                     v8::Handle<v8::Value> val,
+                     gfx::Point* out);
 };
 
 template<>
 struct Converter<gfx::Size> {
   static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
-                                    const gfx::Size& val) {
-    mate::Dictionary dict(isolate, v8::Object::New(isolate));
-    dict.Set("width", val.width());
-    dict.Set("height", val.height());
-    return dict.GetHandle();
-  }
-  static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
-                     gfx::Size* out) {
-    mate::Dictionary dict;
-    if (!ConvertFromV8(isolate, val, &dict))
-      return false;
-    int width, height;
-    if (!dict.Get("width", &width) || !dict.Get("height", &height))
-      return false;
-    *out = gfx::Size(width, height);
-    return true;
-  }
+                                    const gfx::Size& val);
+  static bool FromV8(v8::Isolate* isolate,
+                     v8::Handle<v8::Value> val,
+                     gfx::Size* out);
 };
 
 template<>
 struct Converter<gfx::Rect> {
   static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
-                                    const gfx::Rect& val) {
-    mate::Dictionary dict(isolate, v8::Object::New(isolate));
-    dict.Set("x", val.x());
-    dict.Set("y", val.y());
-    dict.Set("width", val.width());
-    dict.Set("height", val.height());
-    return dict.GetHandle();
-  }
-  static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
-                     gfx::Rect* out) {
-    mate::Dictionary dict;
-    if (!ConvertFromV8(isolate, val, &dict))
-      return false;
-    int x, y, width, height;
-    if (!dict.Get("x", &x) || !dict.Get("y", &y) ||
-        !dict.Get("width", &width) || !dict.Get("height", &height))
-      return false;
-    *out = gfx::Rect(x, y, width, height);
-    return true;
-  }
+                                    const gfx::Rect& val);
+  static bool FromV8(v8::Isolate* isolate,
+                     v8::Handle<v8::Value> val,
+                     gfx::Rect* out);
 };
 
 template<>
 struct Converter<gfx::Display> {
   static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
-                                    const gfx::Display& display) {
-    mate::Dictionary dict(isolate, v8::Object::New(isolate));
-    dict.Set("bounds", display.bounds());
-    dict.Set("workArea", display.work_area());
-    dict.Set("size", display.size());
-    dict.Set("workAreaSize", display.work_area_size());
-    dict.Set("scaleFactor", display.device_scale_factor());
-    return dict.GetHandle();
-  }
+                                    const gfx::Display& val);
+  static bool FromV8(v8::Isolate* isolate,
+                     v8::Handle<v8::Value> val,
+                     gfx::Display* out);
 };
 
 }  // namespace mate