Add support to convert gfx::Rect and gfx::Size to v8 value.
This commit is contained in:
parent
7253a35455
commit
e09a2ff811
1 changed files with 25 additions and 0 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "content/public/renderer/v8_value_converter.h"
|
||||
#include "ui/gfx/point.h"
|
||||
#include "ui/gfx/rect.h"
|
||||
#include "ui/gfx/size.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
// Convert V8 value to arbitrary supported types.
|
||||
|
@ -122,6 +123,14 @@ inline v8::Handle<v8::Value> ToV8Value(bool b) {
|
|||
return v8::Boolean::New(b);
|
||||
}
|
||||
|
||||
inline v8::Handle<v8::Value> ToV8Value(float f) {
|
||||
return v8::Number::New(f);
|
||||
}
|
||||
|
||||
inline v8::Handle<v8::Value> ToV8Value(double f) {
|
||||
return v8::Number::New(f);
|
||||
}
|
||||
|
||||
inline v8::Handle<v8::Value> ToV8Value(const char* s) {
|
||||
return v8::String::New(s);
|
||||
}
|
||||
|
@ -162,6 +171,22 @@ inline v8::Handle<v8::Value> ToV8Value(const gfx::Point& point) {
|
|||
return obj;
|
||||
}
|
||||
|
||||
inline v8::Handle<v8::Value> ToV8Value(const gfx::Rect& rect) {
|
||||
v8::Handle<v8::Object> obj = v8::Object::New();
|
||||
obj->Set(ToV8Value("x"), ToV8Value(rect.x()));
|
||||
obj->Set(ToV8Value("y"), ToV8Value(rect.y()));
|
||||
obj->Set(ToV8Value("width"), ToV8Value(rect.width()));
|
||||
obj->Set(ToV8Value("height"), ToV8Value(rect.height()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline v8::Handle<v8::Value> ToV8Value(const gfx::Size& size) {
|
||||
v8::Handle<v8::Object> obj = v8::Object::New();
|
||||
obj->Set(ToV8Value("width"), ToV8Value(size.width()));
|
||||
obj->Set(ToV8Value("height"), ToV8Value(size.height()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Check if a V8 Value is of specified type.
|
||||
template<class T> inline
|
||||
bool V8ValueCanBeConvertedTo(v8::Handle<v8::Value> value) {
|
||||
|
|
Loading…
Reference in a new issue