OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 19 matching lines...) Expand all Loading... |
30 */ | 30 */ |
31 | 31 |
32 #include "config.h" | 32 #include "config.h" |
33 #include "V8HTMLCanvasElement.h" | 33 #include "V8HTMLCanvasElement.h" |
34 | 34 |
35 #include "V8CanvasRenderingContext2D.h" | 35 #include "V8CanvasRenderingContext2D.h" |
36 #include "V8Node.h" | 36 #include "V8Node.h" |
37 #include "V8WebGLRenderingContext.h" | 37 #include "V8WebGLRenderingContext.h" |
38 #include "bindings/v8/V8Binding.h" | 38 #include "bindings/v8/V8Binding.h" |
39 #include "core/html/HTMLCanvasElement.h" | 39 #include "core/html/HTMLCanvasElement.h" |
40 #include "core/html/canvas/CanvasContextAttributes.h" | 40 #include "core/html/canvas/Canvas2DContextAttributes.h" |
41 #include "core/html/canvas/CanvasRenderingContext.h" | 41 #include "core/html/canvas/CanvasRenderingContext.h" |
42 #include "core/html/canvas/WebGLContextAttributes.h" | 42 #include "core/html/canvas/WebGLContextAttributes.h" |
43 #include "core/inspector/InspectorCanvasInstrumentation.h" | 43 #include "core/inspector/InspectorCanvasInstrumentation.h" |
44 #include "wtf/MathExtras.h" | 44 #include "wtf/MathExtras.h" |
45 #include "wtf/text/WTFString.h" | 45 #include "wtf/text/WTFString.h" |
46 | 46 |
47 namespace WebCore { | 47 namespace WebCore { |
48 | 48 |
49 v8::Handle<v8::Value> V8HTMLCanvasElement::getContextMethodCustom(const v8::Argu
ments& args) | 49 v8::Handle<v8::Value> V8HTMLCanvasElement::getContextMethodCustom(const v8::Argu
ments& args) |
50 { | 50 { |
51 v8::Handle<v8::Object> holder = args.Holder(); | 51 v8::Handle<v8::Object> holder = args.Holder(); |
52 HTMLCanvasElement* imp = V8HTMLCanvasElement::toNative(holder); | 52 HTMLCanvasElement* imp = V8HTMLCanvasElement::toNative(holder); |
53 String contextId = toWebCoreString(args[0]); | 53 String contextId = toWebCoreString(args[0]); |
54 RefPtr<CanvasContextAttributes> attrs; | 54 RefPtr<CanvasContextAttributes> attrs; |
55 if (contextId == "webgl" || contextId == "experimental-webgl" || contextId =
= "webkit-3d") { | 55 if (contextId == "webgl" || contextId == "experimental-webgl" || contextId =
= "webkit-3d") { |
56 attrs = WebGLContextAttributes::create(); | 56 RefPtr<WebGLContextAttributes> webGLAttrs = WebGLContextAttributes::crea
te(); |
57 WebGLContextAttributes* webGLAttrs = static_cast<WebGLContextAttributes*
>(attrs.get()); | |
58 if (args.Length() > 1 && args[1]->IsObject()) { | 57 if (args.Length() > 1 && args[1]->IsObject()) { |
59 v8::Handle<v8::Object> jsAttrs = args[1]->ToObject(); | 58 v8::Handle<v8::Object> jsAttrs = args[1]->ToObject(); |
60 v8::Handle<v8::String> alpha = v8::String::NewSymbol("alpha"); | 59 v8::Handle<v8::String> alpha = v8::String::NewSymbol("alpha"); |
61 if (jsAttrs->Has(alpha)) | 60 if (jsAttrs->Has(alpha)) |
62 webGLAttrs->setAlpha(jsAttrs->Get(alpha)->BooleanValue()); | 61 webGLAttrs->setAlpha(jsAttrs->Get(alpha)->BooleanValue()); |
63 v8::Handle<v8::String> depth = v8::String::NewSymbol("depth"); | 62 v8::Handle<v8::String> depth = v8::String::NewSymbol("depth"); |
64 if (jsAttrs->Has(depth)) | 63 if (jsAttrs->Has(depth)) |
65 webGLAttrs->setDepth(jsAttrs->Get(depth)->BooleanValue()); | 64 webGLAttrs->setDepth(jsAttrs->Get(depth)->BooleanValue()); |
66 v8::Handle<v8::String> stencil = v8::String::NewSymbol("stencil"); | 65 v8::Handle<v8::String> stencil = v8::String::NewSymbol("stencil"); |
67 if (jsAttrs->Has(stencil)) | 66 if (jsAttrs->Has(stencil)) |
68 webGLAttrs->setStencil(jsAttrs->Get(stencil)->BooleanValue()); | 67 webGLAttrs->setStencil(jsAttrs->Get(stencil)->BooleanValue()); |
69 v8::Handle<v8::String> antialias = v8::String::NewSymbol("antialias"
); | 68 v8::Handle<v8::String> antialias = v8::String::NewSymbol("antialias"
); |
70 if (jsAttrs->Has(antialias)) | 69 if (jsAttrs->Has(antialias)) |
71 webGLAttrs->setAntialias(jsAttrs->Get(antialias)->BooleanValue()
); | 70 webGLAttrs->setAntialias(jsAttrs->Get(antialias)->BooleanValue()
); |
72 v8::Handle<v8::String> premultipliedAlpha = v8::String::NewSymbol("p
remultipliedAlpha"); | 71 v8::Handle<v8::String> premultipliedAlpha = v8::String::NewSymbol("p
remultipliedAlpha"); |
73 if (jsAttrs->Has(premultipliedAlpha)) | 72 if (jsAttrs->Has(premultipliedAlpha)) |
74 webGLAttrs->setPremultipliedAlpha(jsAttrs->Get(premultipliedAlph
a)->BooleanValue()); | 73 webGLAttrs->setPremultipliedAlpha(jsAttrs->Get(premultipliedAlph
a)->BooleanValue()); |
75 v8::Handle<v8::String> preserveDrawingBuffer = v8::String::NewSymbol
("preserveDrawingBuffer"); | 74 v8::Handle<v8::String> preserveDrawingBuffer = v8::String::NewSymbol
("preserveDrawingBuffer"); |
76 if (jsAttrs->Has(preserveDrawingBuffer)) | 75 if (jsAttrs->Has(preserveDrawingBuffer)) |
77 webGLAttrs->setPreserveDrawingBuffer(jsAttrs->Get(preserveDrawin
gBuffer)->BooleanValue()); | 76 webGLAttrs->setPreserveDrawingBuffer(jsAttrs->Get(preserveDrawin
gBuffer)->BooleanValue()); |
78 } | 77 } |
| 78 attrs = webGLAttrs; |
| 79 } else { |
| 80 RefPtr<Canvas2DContextAttributes> canvas2DAttrs = Canvas2DContextAttribu
tes::create(); |
| 81 if (args.Length() > 1 && args[1]->IsObject()) { |
| 82 v8::Handle<v8::Object> jsAttrs = args[1]->ToObject(); |
| 83 v8::Handle<v8::String> alpha = v8::String::NewSymbol("alpha"); |
| 84 if (jsAttrs->Has(alpha)) |
| 85 canvas2DAttrs->setAlpha(jsAttrs->Get(alpha)->BooleanValue()); |
| 86 } |
| 87 attrs = canvas2DAttrs; |
79 } | 88 } |
80 CanvasRenderingContext* result = imp->getContext(contextId, attrs.get()); | 89 CanvasRenderingContext* result = imp->getContext(contextId, attrs.get()); |
81 if (!result) | 90 if (!result) |
82 return v8Null(args.GetIsolate()); | 91 return v8Null(args.GetIsolate()); |
83 else if (result->is2d()) { | 92 else if (result->is2d()) { |
84 v8::Handle<v8::Value> v8Result = toV8Fast(static_cast<CanvasRenderingCon
text2D*>(result), args, imp); | 93 v8::Handle<v8::Value> v8Result = toV8Fast(static_cast<CanvasRenderingCon
text2D*>(result), args, imp); |
85 if (InspectorInstrumentation::canvasAgentEnabled(imp->document())) { | 94 if (InspectorInstrumentation::canvasAgentEnabled(imp->document())) { |
86 ScriptState* scriptState = ScriptState::forContext(v8::Context::GetC
urrent()); | 95 ScriptState* scriptState = ScriptState::forContext(v8::Context::GetC
urrent()); |
87 ScriptObject context(scriptState, v8::Handle<v8::Object>::Cast(v8Res
ult)); | 96 ScriptObject context(scriptState, v8::Handle<v8::Object>::Cast(v8Res
ult)); |
88 ScriptObject wrapped = InspectorInstrumentation::wrapCanvas2DRenderi
ngContextForInstrumentation(imp->document(), context); | 97 ScriptObject wrapped = InspectorInstrumentation::wrapCanvas2DRenderi
ngContextForInstrumentation(imp->document(), context); |
(...skipping 30 matching lines...) Expand all Loading... |
119 quality = args[1]->NumberValue(); | 128 quality = args[1]->NumberValue(); |
120 qualityPtr = &quality; | 129 qualityPtr = &quality; |
121 } | 130 } |
122 | 131 |
123 String result = canvas->toDataURL(type, qualityPtr, ec); | 132 String result = canvas->toDataURL(type, qualityPtr, ec); |
124 setDOMException(ec, args.GetIsolate()); | 133 setDOMException(ec, args.GetIsolate()); |
125 return v8StringOrUndefined(result, args.GetIsolate()); | 134 return v8StringOrUndefined(result, args.GetIsolate()); |
126 } | 135 } |
127 | 136 |
128 } // namespace WebCore | 137 } // namespace WebCore |
OLD | NEW |