2015-01-14 22:38:51 +00:00
|
|
|
// 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"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "ui/display/display.h"
|
|
|
|
#include "ui/display/screen.h"
|
2015-03-10 22:35:53 +00:00
|
|
|
#include "ui/gfx/geometry/point.h"
|
|
|
|
#include "ui/gfx/geometry/rect.h"
|
|
|
|
#include "ui/gfx/geometry/size.h"
|
2015-01-14 22:38:51 +00:00
|
|
|
|
|
|
|
namespace mate {
|
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> Converter<gfx::Point>::ToV8(v8::Isolate* isolate,
|
2015-01-14 22:38:51 +00:00
|
|
|
const gfx::Point& val) {
|
2015-08-27 07:23:23 +00:00
|
|
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
dict.SetHidden("simple", true);
|
2015-01-14 22:38:51 +00:00
|
|
|
dict.Set("x", val.x());
|
|
|
|
dict.Set("y", val.y());
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Converter<gfx::Point>::FromV8(v8::Isolate* isolate,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> val,
|
2015-01-14 22:38:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> Converter<gfx::Size>::ToV8(v8::Isolate* isolate,
|
2016-07-04 10:19:20 +00:00
|
|
|
const gfx::Size& val) {
|
2015-08-27 07:23:23 +00:00
|
|
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
dict.SetHidden("simple", true);
|
2015-01-14 22:38:51 +00:00
|
|
|
dict.Set("width", val.width());
|
|
|
|
dict.Set("height", val.height());
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Converter<gfx::Size>::FromV8(v8::Isolate* isolate,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> val,
|
2015-01-14 22:38:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> Converter<gfx::Rect>::ToV8(v8::Isolate* isolate,
|
2015-01-14 22:38:51 +00:00
|
|
|
const gfx::Rect& val) {
|
2015-08-27 07:23:23 +00:00
|
|
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
dict.SetHidden("simple", true);
|
2015-01-14 22:38:51 +00:00
|
|
|
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,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> val,
|
2015-01-14 22:38:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-14 22:51:20 +00:00
|
|
|
template<>
|
2016-07-04 06:08:55 +00:00
|
|
|
struct Converter<display::Display::TouchSupport> {
|
2015-05-22 11:11:22 +00:00
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
2016-07-04 06:08:55 +00:00
|
|
|
const display::Display::TouchSupport& val) {
|
2015-01-14 22:51:20 +00:00
|
|
|
switch (val) {
|
2016-07-04 06:08:55 +00:00
|
|
|
case display::Display::TOUCH_SUPPORT_AVAILABLE:
|
2015-01-14 22:51:20 +00:00
|
|
|
return StringToV8(isolate, "available");
|
2016-07-04 06:08:55 +00:00
|
|
|
case display::Display::TOUCH_SUPPORT_UNAVAILABLE:
|
2015-01-14 22:51:20 +00:00
|
|
|
return StringToV8(isolate, "unavailable");
|
2015-01-15 00:37:48 +00:00
|
|
|
default:
|
|
|
|
return StringToV8(isolate, "unknown");
|
2015-01-14 22:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-04 10:19:20 +00:00
|
|
|
v8::Local<v8::Value> Converter<display::Display>::ToV8(
|
|
|
|
v8::Isolate* isolate, const display::Display& val) {
|
2015-08-27 07:23:23 +00:00
|
|
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
dict.SetHidden("simple", true);
|
2015-01-14 22:38:51 +00:00
|
|
|
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());
|
2015-01-14 22:51:20 +00:00
|
|
|
dict.Set("rotation", val.RotationAsDegree());
|
|
|
|
dict.Set("touchSupport", val.touch_support());
|
2015-01-14 22:38:51 +00:00
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mate
|