2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-01-07 12:00:25 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-01-15 00:19:22 +00:00
|
|
|
#include "atom/browser/api/atom_api_screen.h"
|
|
|
|
|
|
|
|
#include "atom/browser/browser.h"
|
2014-10-24 04:48:52 +00:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2015-01-14 22:38:51 +00:00
|
|
|
#include "base/bind.h"
|
|
|
|
#include "native_mate/dictionary.h"
|
2015-01-15 00:19:22 +00:00
|
|
|
#include "native_mate/object_template_builder.h"
|
2015-01-14 22:38:51 +00:00
|
|
|
#include "ui/gfx/screen.h"
|
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2014-01-07 12:00:25 +00:00
|
|
|
|
2015-01-15 00:19:22 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
Screen::Screen(gfx::Screen* screen) : screen_(screen) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Screen::~Screen() {
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point Screen::GetCursorScreenPoint() {
|
|
|
|
return screen_->GetCursorScreenPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Display Screen::GetPrimaryDisplay() {
|
|
|
|
return screen_->GetPrimaryDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<gfx::Display> Screen::GetAllDisplays() {
|
|
|
|
return screen_->GetAllDisplays();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Display Screen::GetDisplayNearestPoint(const gfx::Point& point) {
|
|
|
|
return screen_->GetDisplayNearestPoint(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Display Screen::GetDisplayMatching(const gfx::Rect& match_rect) {
|
|
|
|
return screen_->GetDisplayMatching(match_rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::OnDisplayAdded(const gfx::Display& new_display) {
|
|
|
|
Emit("display-added");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::OnDisplayRemoved(const gfx::Display& old_display) {
|
|
|
|
Emit("display-removed");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::OnDisplayMetricsChanged(const gfx::Display& display,
|
|
|
|
uint32_t changed_metrics) {
|
|
|
|
Emit("display-metrics-changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
mate::ObjectTemplateBuilder Screen::GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
return mate::ObjectTemplateBuilder(isolate)
|
|
|
|
.SetMethod("getCursorScreenPoint", &Screen::GetCursorScreenPoint)
|
|
|
|
.SetMethod("getPrimaryDisplay", &Screen::GetPrimaryDisplay)
|
|
|
|
.SetMethod("getAllDisplays", &Screen::GetAllDisplays)
|
|
|
|
.SetMethod("getDisplayNearestPoint", &Screen::GetDisplayNearestPoint)
|
|
|
|
.SetMethod("getDisplayMatching", &Screen::GetDisplayMatching);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
mate::Handle<Screen> Screen::Create(v8::Isolate* isolate) {
|
|
|
|
gfx::Screen* screen = gfx::Screen::GetNativeScreen();
|
|
|
|
if (!screen) {
|
|
|
|
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
|
|
|
|
isolate, "Failed to get screen information")));
|
|
|
|
return mate::Handle<Screen>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return CreateHandle(isolate, new Screen(screen));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
2014-04-15 08:25:39 +00:00
|
|
|
namespace {
|
2014-01-07 12:15:55 +00:00
|
|
|
|
2014-06-29 12:48:44 +00:00
|
|
|
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
|
|
|
v8::Handle<v8::Context> context, void* priv) {
|
|
|
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
2015-01-15 00:19:22 +00:00
|
|
|
dict.Set("screen", atom::api::Screen::Create(context->GetIsolate()));
|
2014-01-07 12:00:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 08:25:39 +00:00
|
|
|
} // namespace
|
2014-01-07 12:00:25 +00:00
|
|
|
|
2014-06-29 12:48:44 +00:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_screen, Initialize)
|