]> khamidou — GitHub mirrors - electron.git/commitdiff
Add initial screen module.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jan 2014 12:00:25 +0000 (20:00 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 7 Jan 2014 12:00:25 +0000 (20:00 +0800)
atom.gyp
common/api/atom_api_screen.cc [new file with mode: 0644]
common/api/atom_api_screen.h [new file with mode: 0644]
common/api/atom_extensions.h
common/api/lib/screen.coffee [new file with mode: 0644]
spec/api-screen-spec.coffee [new file with mode: 0644]

index c1d0b8ebbd825b528e1568a3f10786dfe5076010..f9b4a011f3d24424651bafcf7321b121f565c9c4 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -28,6 +28,7 @@
       'common/api/lib/clipboard.coffee',
       'common/api/lib/crash-reporter.coffee',
       'common/api/lib/id-weak-map.coffee',
+      'common/api/lib/screen.coffee',
       'common/api/lib/shell.coffee',
       'renderer/lib/init.coffee',
       'renderer/api/lib/ipc.coffee',
       'common/api/atom_api_event_emitter.h',
       'common/api/atom_api_id_weak_map.cc',
       'common/api/atom_api_id_weak_map.h',
+      'common/api/atom_api_screen.cc',
+      'common/api/atom_api_screen.h',
       'common/api/atom_api_shell.cc',
       'common/api/atom_api_shell.h',
       'common/api/atom_api_v8_util.cc',
diff --git a/common/api/atom_api_screen.cc b/common/api/atom_api_screen.cc
new file mode 100644 (file)
index 0000000..995a584
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "common/api/atom_api_screen.h"
+
+#include "common/v8/native_type_conversions.h"
+#include "ui/gfx/screen.h"
+
+#include "common/v8/node_common.h"
+
+#define UNWRAP_SCREEN_AND_CHECK \
+  Screen* self = ObjectWrap::Unwrap<Screen>(args.This()); \
+  if (self == NULL) \
+    return node::ThrowError("Screen is already destroyed")
+
+namespace atom {
+
+namespace api {
+
+Screen::Screen(v8::Handle<v8::Object> wrapper)
+    : EventEmitter(wrapper),
+      screen_(gfx::Screen::GetNativeScreen()) {
+}
+
+Screen::~Screen() {
+}
+
+// static
+void Screen::New(const v8::FunctionCallbackInfo<v8::Value>& args) {
+  v8::HandleScope scope(args.GetIsolate());
+
+  if (!args.IsConstructCall())
+    return node::ThrowError("Require constructor call");
+
+  new Screen(args.This());
+}
+
+// static
+void Screen::GetCursorScreenPoint(
+    const v8::FunctionCallbackInfo<v8::Value>& args) {
+  UNWRAP_SCREEN_AND_CHECK;
+  args.GetReturnValue().Set(ToV8Value(self->screen_->GetCursorScreenPoint()));
+}
+
+// static
+void Screen::Initialize(v8::Handle<v8::Object> target) {
+  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
+
+  v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(New);
+  t->InstanceTemplate()->SetInternalFieldCount(1);
+  t->SetClassName(v8::String::NewSymbol("Screen"));
+
+  NODE_SET_PROTOTYPE_METHOD(t, "getCursorScreenPoint", GetCursorScreenPoint);
+
+  target->Set(v8::String::NewSymbol("Screen"), t->GetFunction());
+}
+
+}  // namespace api
+
+}  // namespace atom
+
+NODE_MODULE(atom_common_screen, atom::api::Screen::Initialize)
diff --git a/common/api/atom_api_screen.h b/common/api/atom_api_screen.h
new file mode 100644 (file)
index 0000000..7b1ad3b
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_COMMON_API_ATOM_API_SCREEN_H_
+#define ATOM_COMMON_API_ATOM_API_SCREEN_H_
+
+#include "common/api/atom_api_event_emitter.h"
+
+namespace gfx {
+class Screen;
+}
+
+namespace atom {
+
+namespace api {
+
+class Screen : public EventEmitter {
+ public:
+  virtual ~Screen();
+
+  static void Initialize(v8::Handle<v8::Object> target);
+
+ protected:
+  explicit Screen(v8::Handle<v8::Object> wrapper);
+
+ private:
+  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
+
+  static void GetCursorScreenPoint(
+      const v8::FunctionCallbackInfo<v8::Value>& args);
+
+  gfx::Screen* screen_;
+
+  DISALLOW_COPY_AND_ASSIGN(Screen);
+};
+
+}  // namespace api
+
+}  // namespace atom
+
+#endif  // ATOM_COMMON_API_ATOM_API_SCREEN_H_
index c373d49a3f98b5c9a6cf53d74baff052677d942c..5bba348c0ed45b54ba621d1189a79351bfea2dd0 100644 (file)
@@ -27,6 +27,7 @@ NODE_EXT_LIST_ITEM(atom_renderer_ipc)
 NODE_EXT_LIST_ITEM(atom_common_clipboard)
 NODE_EXT_LIST_ITEM(atom_common_crash_reporter)
 NODE_EXT_LIST_ITEM(atom_common_id_weak_map)
+NODE_EXT_LIST_ITEM(atom_common_screen)
 NODE_EXT_LIST_ITEM(atom_common_shell)
 NODE_EXT_LIST_ITEM(atom_common_v8_util)
 
diff --git a/common/api/lib/screen.coffee b/common/api/lib/screen.coffee
new file mode 100644 (file)
index 0000000..fa859f1
--- /dev/null
@@ -0,0 +1,3 @@
+{Screen} = process.atomBinding 'screen'
+
+module.exports = new Screen
diff --git a/spec/api-screen-spec.coffee b/spec/api-screen-spec.coffee
new file mode 100644 (file)
index 0000000..a3803fb
--- /dev/null
@@ -0,0 +1,9 @@
+assert = require 'assert'
+screen = require 'screen'
+
+describe 'screen module', ->
+  describe 'screen.getCursorScreenPoint()', ->
+    it 'returns a point object', ->
+      point = screen.getCursorScreenPoint()
+      assert typeof(point.x), 'number'
+      assert typeof(point.y), 'number'