2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "bindings/core/v8/V8CanvasRenderingContext2D.h"
34 #include "bindings/core/v8/V8Binding.h"
35 #include "bindings/core/v8/V8CanvasGradient.h"
36 #include "bindings/core/v8/V8CanvasPattern.h"
37 #include "bindings/core/v8/V8HTMLCanvasElement.h"
38 #include "bindings/core/v8/V8HTMLImageElement.h"
39 #include "bindings/core/v8/V8HTMLVideoElement.h"
40 #include "bindings/core/v8/V8ImageData.h"
41 #include "core/html/canvas/CanvasGradient.h"
42 #include "core/html/canvas/CanvasPattern.h"
43 #include "core/html/canvas/CanvasRenderingContext2D.h"
44 #include "core/html/canvas/CanvasStyle.h"
45 #include "platform/geometry/FloatRect.h"
49 static v8::Handle<v8::Value> toV8Object(CanvasStyle* style, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
51 if (style->canvasGradient())
52 return toV8(style->canvasGradient(), creationContext, isolate);
54 if (style->canvasPattern())
55 return toV8(style->canvasPattern(), creationContext, isolate);
57 return v8String(isolate, style->color());
60 static PassRefPtrWillBeRawPtr<CanvasStyle> toCanvasStyle(v8::Handle<v8::Value> value, v8::Isolate* isolate)
62 RefPtrWillBeRawPtr<CanvasStyle> canvasStyle = CanvasStyle::createFromGradient(V8CanvasGradient::toImplWithTypeCheck(isolate, value));
65 return CanvasStyle::createFromPattern(V8CanvasPattern::toImplWithTypeCheck(isolate, value));
68 void V8CanvasRenderingContext2D::strokeStyleAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
70 CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toImpl(info.Holder());
71 v8SetReturnValue(info, toV8Object(impl->strokeStyle(), info.Holder(), info.GetIsolate()));
74 void V8CanvasRenderingContext2D::strokeStyleAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
76 CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toImpl(info.Holder());
77 if (RefPtrWillBeRawPtr<CanvasStyle> canvasStyle = toCanvasStyle(value, info.GetIsolate())) {
78 impl->setStrokeStyle(canvasStyle);
80 TOSTRING_VOID(V8StringResource<>, colorString, value);
81 impl->setStrokeColor(colorString);
85 void V8CanvasRenderingContext2D::fillStyleAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
87 CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toImpl(info.Holder());
88 v8SetReturnValue(info, toV8Object(impl->fillStyle(), info.Holder(), info.GetIsolate()));
91 void V8CanvasRenderingContext2D::fillStyleAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
93 CanvasRenderingContext2D* impl = V8CanvasRenderingContext2D::toImpl(info.Holder());
94 if (RefPtrWillBeRawPtr<CanvasStyle> canvasStyle = toCanvasStyle(value, info.GetIsolate())) {
95 impl->setFillStyle(canvasStyle);
97 TOSTRING_VOID(V8StringResource<>, colorString, value);
98 impl->setFillColor(colorString);