diff options
author | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 22:37:09 +0000 |
---|---|---|
committer | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 22:37:09 +0000 |
commit | 2f25166d30d865f92e1c68e2489070d924f8da7d (patch) | |
tree | 51dca137f993a8f62b468d70356a3794fdb94008 /webkit/port | |
parent | 4abb93959ea4d1ffafa6681ee4c543f9a5d5691b (diff) | |
download | chromium_src-2f25166d30d865f92e1c68e2489070d924f8da7d.zip chromium_src-2f25166d30d865f92e1c68e2489070d924f8da7d.tar.gz chromium_src-2f25166d30d865f92e1c68e2489070d924f8da7d.tar.bz2 |
Use upstreamed v8 bindings for CanvasRenderingContext2D
BUG=12262
Review URL: http://codereview.chromium.org/113599
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port')
-rw-r--r-- | webkit/port/bindings/v8/v8_custom.cpp | 416 |
1 files changed, 0 insertions, 416 deletions
diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp index 9eafb38..bed5542 100644 --- a/webkit/port/bindings/v8/v8_custom.cpp +++ b/webkit/port/bindings/v8/v8_custom.cpp @@ -143,422 +143,6 @@ ACCESSOR_GETTER(DocumentImplementation) { return wrapper; } -// CanvasRenderingContext2D ---------------------------------------------------- - -// Helper macro for converting v8 values into floats (expected by many of the -// canvas functions). -#define TO_FLOAT(a) static_cast<float>((a)->NumberValue()) - -// TODO: SetStrokeColor and SetFillColor are similar except function names, -// consolidate them into one. -CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetStrokeColor) { - INC_STATS("DOM.CanvasRenderingContext2D.setStrokeColor()"); - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - switch (args.Length()) { - case 1: - if (args[0]->IsString()) { - context->setStrokeColor(ToWebCoreString(args[0])); - } else { - context->setStrokeColor(TO_FLOAT(args[0])); - } - break; - case 2: - if (args[0]->IsString()) { - context->setStrokeColor(ToWebCoreString(args[0]), - TO_FLOAT(args[1])); - } else { - context->setStrokeColor(TO_FLOAT(args[0]), - TO_FLOAT(args[1])); - } - break; - case 4: - context->setStrokeColor(TO_FLOAT(args[0]), - TO_FLOAT(args[1]), - TO_FLOAT(args[2]), - TO_FLOAT(args[3])); - break; - case 5: - context->setStrokeColor(TO_FLOAT(args[0]), - TO_FLOAT(args[1]), - TO_FLOAT(args[2]), - TO_FLOAT(args[3]), - TO_FLOAT(args[4])); - break; - default: - V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, - "setStrokeColor: Invalid number of arguments"); - break; - } - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetFillColor) { - INC_STATS("DOM.CanvasRenderingContext2D.setFillColor()"); - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - switch (args.Length()) { - case 1: - if (args[0]->IsString()) { - context->setFillColor(ToWebCoreString(args[0])); - } else { - context->setFillColor(TO_FLOAT(args[0])); - } - break; - case 2: - if (args[0]->IsString()) { - context->setFillColor(ToWebCoreString(args[0]), TO_FLOAT(args[1])); - } else { - context->setFillColor(TO_FLOAT(args[0]), TO_FLOAT(args[1])); - } - break; - case 4: - context->setFillColor(TO_FLOAT(args[0]), - TO_FLOAT(args[1]), - TO_FLOAT(args[2]), - TO_FLOAT(args[3])); - break; - case 5: - context->setFillColor(TO_FLOAT(args[0]), - TO_FLOAT(args[1]), - TO_FLOAT(args[2]), - TO_FLOAT(args[3]), - TO_FLOAT(args[4])); - break; - default: - V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, - "setFillColor: Invalid number of arguments"); - break; - } - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DStrokeRect) { - INC_STATS("DOM.CanvasRenderingContext2D.strokeRect()"); - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - if (args.Length() == 5) { - context->strokeRect(TO_FLOAT(args[0]), - TO_FLOAT(args[1]), - TO_FLOAT(args[2]), - TO_FLOAT(args[3]), - TO_FLOAT(args[4])); - } else if (args.Length() == 4) { - context->strokeRect(TO_FLOAT(args[0]), - TO_FLOAT(args[1]), - TO_FLOAT(args[2]), - TO_FLOAT(args[3])); - } else { - V8Proxy::SetDOMException(INDEX_SIZE_ERR); - return v8::Handle<v8::Value>(); - } - - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DSetShadow) { - INC_STATS("DOM.CanvasRenderingContext2D.setShadow()"); - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - - switch (args.Length()) { - case 3: - context->setShadow(TO_FLOAT(args[0]), TO_FLOAT(args[1]), - TO_FLOAT(args[2])); - break; - case 4: - if (args[3]->IsString()) - context->setShadow(TO_FLOAT(args[0]), TO_FLOAT(args[1]), - TO_FLOAT(args[2]), ToWebCoreString(args[3])); - else - context->setShadow(TO_FLOAT(args[0]), TO_FLOAT(args[1]), - TO_FLOAT(args[2]), TO_FLOAT(args[3])); - break; - case 5: - if (args[3]->IsString()) - context->setShadow(TO_FLOAT(args[0]), TO_FLOAT(args[1]), - TO_FLOAT(args[2]), ToWebCoreString(args[3]), - TO_FLOAT(args[4])); - else - context->setShadow(TO_FLOAT(args[0]), TO_FLOAT(args[1]), - TO_FLOAT(args[2]), TO_FLOAT(args[3]), - TO_FLOAT(args[4])); - break; - case 7: - context->setShadow(TO_FLOAT(args[0]), TO_FLOAT(args[1]), - TO_FLOAT(args[2]), TO_FLOAT(args[3]), - TO_FLOAT(args[4]), TO_FLOAT(args[5]), - TO_FLOAT(args[6])); - break; - case 8: - context->setShadow(TO_FLOAT(args[0]), TO_FLOAT(args[1]), - TO_FLOAT(args[2]), TO_FLOAT(args[3]), - TO_FLOAT(args[4]), TO_FLOAT(args[5]), - TO_FLOAT(args[6]), TO_FLOAT(args[7])); - break; - default: - V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, - "setShadow: Invalid number of arguments"); - break; - } - - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DDrawImage) { - INC_STATS("DOM.CanvasRenderingContext2D.drawImage()"); - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - - v8::Handle<v8::Value> arg = args[0]; - - if (V8HTMLImageElement::HasInstance(arg)) { - ExceptionCode ec = 0; - HTMLImageElement* image_element = - V8Proxy::DOMWrapperToNode<HTMLImageElement>(arg); - switch (args.Length()) { - case 3: - context->drawImage(image_element, TO_FLOAT(args[1]), TO_FLOAT(args[2])); - break; - case 5: - context->drawImage(image_element, TO_FLOAT(args[1]), TO_FLOAT(args[2]), - TO_FLOAT(args[3]), TO_FLOAT(args[4]), ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - break; - case 9: - context->drawImage(image_element, - FloatRect(TO_FLOAT(args[1]), TO_FLOAT(args[2]), - TO_FLOAT(args[3]), TO_FLOAT(args[4])), - FloatRect(TO_FLOAT(args[5]), TO_FLOAT(args[6]), - TO_FLOAT(args[7]), TO_FLOAT(args[8])), - ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - break; - default: - V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, - "drawImage: Invalid number of arguments"); - return v8::Undefined(); - } - return v8::Undefined(); - } - - // HTMLCanvasElement - if (V8HTMLCanvasElement::HasInstance(arg)) { - ExceptionCode ec = 0; - HTMLCanvasElement* canvas_element = - V8Proxy::DOMWrapperToNode<HTMLCanvasElement>(arg); - switch (args.Length()) { - case 3: - context->drawImage(canvas_element, TO_FLOAT(args[1]), TO_FLOAT(args[2])); - break; - case 5: - context->drawImage(canvas_element, TO_FLOAT(args[1]), TO_FLOAT(args[2]), - TO_FLOAT(args[3]), TO_FLOAT(args[4]), ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - break; - case 9: - context->drawImage(canvas_element, - FloatRect(TO_FLOAT(args[1]), TO_FLOAT(args[2]), - TO_FLOAT(args[3]), TO_FLOAT(args[4])), - FloatRect(TO_FLOAT(args[5]), TO_FLOAT(args[6]), - TO_FLOAT(args[7]), TO_FLOAT(args[8])), - ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - break; - default: - V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, - "drawImage: Invalid number of arguments"); - return v8::Undefined(); - } - return v8::Undefined(); - } - - V8Proxy::SetDOMException(TYPE_MISMATCH_ERR); - return v8::Handle<v8::Value>(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DDrawImageFromRect) { - INC_STATS("DOM.CanvasRenderingContext2D.drawImageFromRect()"); - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - - v8::Handle<v8::Value> arg = args[0]; - - if (V8HTMLImageElement::HasInstance(arg)) { - HTMLImageElement* image_element = - V8Proxy::DOMWrapperToNode<HTMLImageElement>(arg); - context->drawImageFromRect(image_element, - TO_FLOAT(args[1]), TO_FLOAT(args[2]), - TO_FLOAT(args[3]), TO_FLOAT(args[4]), - TO_FLOAT(args[5]), TO_FLOAT(args[6]), - TO_FLOAT(args[7]), TO_FLOAT(args[8]), - ToWebCoreString(args[9])); - } else { - V8Proxy::ThrowError(V8Proxy::TYPE_ERROR, - "drawImageFromRect: Invalid type of arguments"); - } - - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DCreatePattern) { - INC_STATS("DOM.CanvasRenderingContext2D.createPattern()"); - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - - v8::Handle<v8::Value> arg = args[0]; - - if (V8HTMLImageElement::HasInstance(arg)) { - HTMLImageElement* image_element = - V8Proxy::DOMWrapperToNode<HTMLImageElement>(arg); - ExceptionCode ec = 0; - RefPtr<CanvasPattern> pattern = - context->createPattern(image_element, valueToStringWithNullCheck(args[1]), ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - return V8Proxy::ToV8Object(V8ClassIndex::CANVASPATTERN, pattern.get()); - } - - if (V8HTMLCanvasElement::HasInstance(arg)) { - HTMLCanvasElement* canvas_element = - V8Proxy::DOMWrapperToNode<HTMLCanvasElement>(arg); - ExceptionCode ec = 0; - RefPtr<CanvasPattern> pattern = - context->createPattern(canvas_element, valueToStringWithNullCheck(args[1]), ec); - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - return V8Proxy::ToV8Object(V8ClassIndex::CANVASPATTERN, pattern.get()); - } - - V8Proxy::SetDOMException(TYPE_MISMATCH_ERR); - return v8::Handle<v8::Value>(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DFillText) { - INC_STATS("DOM.CanvasRenderingContext2D.fillText()"); - - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - - // Two forms: - // * fillText(text, x, y) - // * fillText(text, x, y, maxWidth) - if (args.Length() < 3 || args.Length() > 4) { - V8Proxy::SetDOMException(SYNTAX_ERR); - return v8::Handle<v8::Value>(); - } - - String text = ToWebCoreString(args[0]); - float x = TO_FLOAT(args[1]); - float y = TO_FLOAT(args[2]); - - if (args.Length() == 4) { - float maxWidth = TO_FLOAT(args[3]); - context->fillText(text, x, y, maxWidth); - } else { - context->fillText(text, x, y); - } - - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DStrokeText) { - INC_STATS("DOM.CanvasRenderingContext2D.strokeText()"); - - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - - // Two forms: - // * strokeText(text, x, y) - // * strokeText(text, x, y, maxWidth) - if (args.Length() < 3 || args.Length() > 4) { - V8Proxy::SetDOMException(SYNTAX_ERR); - return v8::Handle<v8::Value>(); - } - - String text = ToWebCoreString(args[0]); - float x = TO_FLOAT(args[1]); - float y = TO_FLOAT(args[2]); - - if (args.Length() == 4) { - float maxWidth = TO_FLOAT(args[3]); - context->strokeText(text, x, y, maxWidth); - } else { - context->strokeText(text, x, y); - } - - return v8::Undefined(); -} - -CALLBACK_FUNC_DECL(CanvasRenderingContext2DPutImageData) { - INC_STATS("DOM.CanvasRenderingContext2D.putImageData()"); - - // Two froms: - // * putImageData(ImageData, x, y) - // * putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight) - if (args.Length() != 3 && args.Length() != 7) { - V8Proxy::SetDOMException(SYNTAX_ERR); - return v8::Handle<v8::Value>(); - } - - CanvasRenderingContext2D* context = - V8Proxy::ToNativeObject<CanvasRenderingContext2D>( - V8ClassIndex::CANVASRENDERINGCONTEXT2D, args.Holder()); - - ImageData* imageData = 0; - - // Need to check that the argument is of the correct type, since - // ToNativeObject() expects it to be correct. If the argument was incorrect - // we leave it null, and putImageData() will throw the correct exception - // (TYPE_MISMATCH_ERR). - if (V8Proxy::IsWrapperOfType(args[0], V8ClassIndex::IMAGEDATA)) { - imageData = V8Proxy::ToNativeObject<ImageData>( - V8ClassIndex::IMAGEDATA, args[0]); - } - - ExceptionCode ec = 0; - - if (args.Length() == 7) { - context->putImageData(imageData, - TO_FLOAT(args[1]), TO_FLOAT(args[2]), TO_FLOAT(args[3]), - TO_FLOAT(args[4]), TO_FLOAT(args[5]), TO_FLOAT(args[6]), ec); - } else { - context->putImageData(imageData, TO_FLOAT(args[1]), TO_FLOAT(args[2]), ec); - } - - if (ec != 0) { - V8Proxy::SetDOMException(ec); - return v8::Handle<v8::Value>(); - } - - return v8::Undefined(); -} - // TODO(mbelshe): This should move into V8DOMWindowCustom.cpp // Can't move it right now because it depends on V8ScheduledAction, // which is private to this file (v8_custom.cpp). |