From: Cheng Zhao Date: Fri, 22 Nov 2013 06:22:28 +0000 (+0800) Subject: Enable converting V8 value to gfx::Rect. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0548530e70df6c02dc37f20a2bac6560b83a432;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Enable converting V8 value to gfx::Rect. --- diff --git a/common/v8_conversions.h b/common/v8_conversions.h index bd5f72a6a..b56061119 100644 --- a/common/v8_conversions.h +++ b/common/v8_conversions.h @@ -11,6 +11,7 @@ #include "base/files/file_path.h" #include "base/string16.h" #include "browser/api/atom_api_window.h" +#include "ui/gfx/rect.h" #include "v8/include/v8.h" // Convert V8 value to arbitrary supported types. @@ -38,6 +39,20 @@ struct FromV8Value { return base::FilePath::FromUTF8Unsafe(FromV8Value(value_)); } + operator gfx::Rect() { + v8::Handle rect = value_->ToObject(); + v8::Handle x = rect->Get(v8::String::New("x")); + v8::Handle y = rect->Get(v8::String::New("y")); + v8::Handle width = rect->Get(v8::String::New("width")); + v8::Handle height = rect->Get(v8::String::New("height")); + if (!x->IsNumber() || !y->IsNumber() || + !width->IsNumber() || !height->IsNumber()) + return gfx::Rect(); + else + return gfx::Rect(x->IntegerValue(), y->IntegerValue(), + width->IntegerValue(), height->IntegerValue()); + } + operator std::vector() { std::vector array; v8::Handle v8_array = v8::Handle::Cast(value_); @@ -58,11 +73,9 @@ struct FromV8Value { } operator v8::Persistent() { - return value_->IsFunction() ? - v8::Persistent::New( - node::node_isolate, - v8::Handle::Cast(value_)) : - v8::Persistent(); + return v8::Persistent::New( + node::node_isolate, + v8::Handle::Cast(value_)); } v8::Handle value_; @@ -137,6 +150,11 @@ bool V8ValueCanBeConvertedTo(v8::Handle value) { return V8ValueCanBeConvertedTo(value); } +template<> inline +bool V8ValueCanBeConvertedTo(v8::Handle value) { + return value->IsObject(); +} + template<> inline bool V8ValueCanBeConvertedTo>( v8::Handle value) {