Chromium Code Reviews| 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 { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 69 v8::Handle<v8::String> antialias = v8::String::NewSymbol("antialias" ); | 69 v8::Handle<v8::String> antialias = v8::String::NewSymbol("antialias" ); |
| 70 if (jsAttrs->Has(antialias)) | 70 if (jsAttrs->Has(antialias)) |
| 71 webGLAttrs->setAntialias(jsAttrs->Get(antialias)->BooleanValue() ); | 71 webGLAttrs->setAntialias(jsAttrs->Get(antialias)->BooleanValue() ); |
| 72 v8::Handle<v8::String> premultipliedAlpha = v8::String::NewSymbol("p remultipliedAlpha"); | 72 v8::Handle<v8::String> premultipliedAlpha = v8::String::NewSymbol("p remultipliedAlpha"); |
| 73 if (jsAttrs->Has(premultipliedAlpha)) | 73 if (jsAttrs->Has(premultipliedAlpha)) |
| 74 webGLAttrs->setPremultipliedAlpha(jsAttrs->Get(premultipliedAlph a)->BooleanValue()); | 74 webGLAttrs->setPremultipliedAlpha(jsAttrs->Get(premultipliedAlph a)->BooleanValue()); |
| 75 v8::Handle<v8::String> preserveDrawingBuffer = v8::String::NewSymbol ("preserveDrawingBuffer"); | 75 v8::Handle<v8::String> preserveDrawingBuffer = v8::String::NewSymbol ("preserveDrawingBuffer"); |
| 76 if (jsAttrs->Has(preserveDrawingBuffer)) | 76 if (jsAttrs->Has(preserveDrawingBuffer)) |
| 77 webGLAttrs->setPreserveDrawingBuffer(jsAttrs->Get(preserveDrawin gBuffer)->BooleanValue()); | 77 webGLAttrs->setPreserveDrawingBuffer(jsAttrs->Get(preserveDrawin gBuffer)->BooleanValue()); |
| 78 } | 78 } |
| 79 } else { | |
| 80 attrs = Canvas2DContextAttributes::create(); | |
| 81 Canvas2DContextAttributes* canvas2DAttrs = static_cast<Canvas2DContextAt tributes*>(attrs.get()); | |
|
jamesr
2013/04/26 00:41:31
do you have to downcast? can you just keep a more
Stephen White
2013/04/26 15:51:03
Good point. I was blindly following the pattern of
| |
| 82 if (args.Length() > 1 && args[1]->IsObject()) { | |
| 83 v8::Handle<v8::Object> jsAttrs = args[1]->ToObject(); | |
| 84 v8::Handle<v8::String> alpha = v8::String::NewSymbol("alpha"); | |
| 85 if (jsAttrs->Has(alpha)) | |
| 86 canvas2DAttrs->setAlpha(jsAttrs->Get(alpha)->BooleanValue()); | |
|
jamesr
2013/04/26 00:41:31
this seems to imply that the default value for 'al
Stephen White
2013/04/26 15:51:03
I think this should work: Canvas2DContextAttribute
| |
| 87 } | |
| 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 |