V8CanvasRenderingContext2DCustom.cpp [plain text]
#include "config.h"
#include "CanvasRenderingContext2D.h"
#include "CanvasGradient.h"
#include "CanvasPattern.h"
#include "CanvasStyle.h"
#include "V8Binding.h"
#include "V8CanvasGradient.h"
#include "V8CanvasPattern.h"
#include "V8CustomBinding.h"
#include "V8Proxy.h"
namespace WebCore {
static v8::Handle<v8::Value> toV8(CanvasStyle* style)
{
if (style->canvasGradient())
return V8Proxy::ToV8Object(V8ClassIndex::CANVASGRADIENT, style->canvasGradient());
if (style->canvasPattern())
return V8Proxy::ToV8Object(V8ClassIndex::CANVASPATTERN, style->canvasPattern());
return v8String(style->color());
}
static PassRefPtr<CanvasStyle> toCanvasStyle(v8::Handle<v8::Value> value)
{
if (value->IsString())
return CanvasStyle::create(toWebCoreString(value));
if (V8CanvasGradient::HasInstance(value))
return CanvasStyle::create(V8Proxy::DOMWrapperToNative<CanvasGradient>(value));
if (V8CanvasPattern::HasInstance(value))
return CanvasStyle::create(V8Proxy::DOMWrapperToNative<CanvasPattern>(value));
return 0;
}
ACCESSOR_GETTER(CanvasRenderingContext2DStrokeStyle)
{
CanvasRenderingContext2D* impl = V8Proxy::DOMWrapperToNative<CanvasRenderingContext2D>(info.Holder());
return toV8(impl->strokeStyle());
}
ACCESSOR_SETTER(CanvasRenderingContext2DStrokeStyle)
{
CanvasRenderingContext2D* impl = V8Proxy::DOMWrapperToNative<CanvasRenderingContext2D>(info.Holder());
impl->setStrokeStyle(toCanvasStyle(value));
}
ACCESSOR_GETTER(CanvasRenderingContext2DFillStyle)
{
CanvasRenderingContext2D* impl = V8Proxy::DOMWrapperToNative<CanvasRenderingContext2D>(info.Holder());
return toV8(impl->fillStyle());
}
ACCESSOR_SETTER(CanvasRenderingContext2DFillStyle)
{
CanvasRenderingContext2D* impl = V8Proxy::DOMWrapperToNative<CanvasRenderingContext2D>(info.Holder());
impl->setFillStyle(toCanvasStyle(value));
}
}