Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: Source/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

Issue 290143007: canvas.getContext with alpha:undefined should behave like alpha:true (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: test expectations Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 #include "core/html/HTMLCanvasElement.h" 40 #include "core/html/HTMLCanvasElement.h"
41 #include "core/html/canvas/Canvas2DContextAttributes.h" 41 #include "core/html/canvas/Canvas2DContextAttributes.h"
42 #include "core/html/canvas/CanvasRenderingContext.h" 42 #include "core/html/canvas/CanvasRenderingContext.h"
43 #include "core/html/canvas/WebGLContextAttributes.h" 43 #include "core/html/canvas/WebGLContextAttributes.h"
44 #include "core/inspector/InspectorCanvasInstrumentation.h" 44 #include "core/inspector/InspectorCanvasInstrumentation.h"
45 #include "wtf/MathExtras.h" 45 #include "wtf/MathExtras.h"
46 #include "wtf/text/WTFString.h" 46 #include "wtf/text/WTFString.h"
47 47
48 namespace WebCore { 48 namespace WebCore {
49 49
50 static bool determineAlpha(v8::Handle<v8::Value> alphaValue)
Justin Novosad 2014/05/20 19:28:39 We are going to need a more generic version of thi
51 {
52 // WebIDL dictionary spec says that setting a dictionary value to undefined
53 // should result in the attribute retaining its default value.
54 if (isUndefinedOrNull(alphaValue))
55 return true;
56
57 return alphaValue->BooleanValue();
58 }
59
50 void V8HTMLCanvasElement::getContextMethodCustom(const v8::FunctionCallbackInfo< v8::Value>& info) 60 void V8HTMLCanvasElement::getContextMethodCustom(const v8::FunctionCallbackInfo< v8::Value>& info)
51 { 61 {
52 v8::Handle<v8::Object> holder = info.Holder(); 62 v8::Handle<v8::Object> holder = info.Holder();
53 v8::Isolate* isolate = info.GetIsolate(); 63 v8::Isolate* isolate = info.GetIsolate();
54 HTMLCanvasElement* impl = V8HTMLCanvasElement::toNative(holder); 64 HTMLCanvasElement* impl = V8HTMLCanvasElement::toNative(holder);
55 TOSTRING_VOID(V8StringResource<>, contextIdResource, info[0]); 65 TOSTRING_VOID(V8StringResource<>, contextIdResource, info[0]);
56 String contextId = contextIdResource; 66 String contextId = contextIdResource;
57 RefPtr<CanvasContextAttributes> attributes; 67 RefPtr<CanvasContextAttributes> attributes;
58 if (contextId == "webgl" || contextId == "experimental-webgl") { 68 if (contextId == "webgl" || contextId == "experimental-webgl") {
59 RefPtr<WebGLContextAttributes> webGLAttributes = WebGLContextAttributes: :create(); 69 RefPtr<WebGLContextAttributes> webGLAttributes = WebGLContextAttributes: :create();
60 if (info.Length() > 1 && info[1]->IsObject()) { 70 if (info.Length() > 1 && info[1]->IsObject()) {
61 v8::Handle<v8::Object> jsAttributes = info[1]->ToObject(); 71 v8::Handle<v8::Object> jsAttributes = info[1]->ToObject();
62 v8::Handle<v8::String> alpha = v8AtomicString(isolate, "alpha"); 72 v8::Handle<v8::String> alpha = v8AtomicString(isolate, "alpha");
63 if (jsAttributes->Has(alpha)) 73 if (jsAttributes->Has(alpha))
64 webGLAttributes->setAlpha(jsAttributes->Get(alpha)->BooleanValue ()); 74 webGLAttributes->setAlpha(determineAlpha(jsAttributes->Get(alpha )));
Justin Novosad 2014/05/20 19:28:39 Theroriginal bug was primarily about 2D canvas. If
65 v8::Handle<v8::String> depth = v8AtomicString(isolate, "depth"); 75 v8::Handle<v8::String> depth = v8AtomicString(isolate, "depth");
66 if (jsAttributes->Has(depth)) 76 if (jsAttributes->Has(depth))
67 webGLAttributes->setDepth(jsAttributes->Get(depth)->BooleanValue ()); 77 webGLAttributes->setDepth(jsAttributes->Get(depth)->BooleanValue ());
68 v8::Handle<v8::String> stencil = v8AtomicString(isolate, "stencil"); 78 v8::Handle<v8::String> stencil = v8AtomicString(isolate, "stencil");
69 if (jsAttributes->Has(stencil)) 79 if (jsAttributes->Has(stencil))
70 webGLAttributes->setStencil(jsAttributes->Get(stencil)->BooleanV alue()); 80 webGLAttributes->setStencil(jsAttributes->Get(stencil)->BooleanV alue());
71 v8::Handle<v8::String> antialias = v8AtomicString(isolate, "antialia s"); 81 v8::Handle<v8::String> antialias = v8AtomicString(isolate, "antialia s");
72 if (jsAttributes->Has(antialias)) 82 if (jsAttributes->Has(antialias))
73 webGLAttributes->setAntialias(jsAttributes->Get(antialias)->Bool eanValue()); 83 webGLAttributes->setAntialias(jsAttributes->Get(antialias)->Bool eanValue());
74 v8::Handle<v8::String> premultipliedAlpha = v8AtomicString(isolate, "premultipliedAlpha"); 84 v8::Handle<v8::String> premultipliedAlpha = v8AtomicString(isolate, "premultipliedAlpha");
75 if (jsAttributes->Has(premultipliedAlpha)) 85 if (jsAttributes->Has(premultipliedAlpha))
76 webGLAttributes->setPremultipliedAlpha(jsAttributes->Get(premult ipliedAlpha)->BooleanValue()); 86 webGLAttributes->setPremultipliedAlpha(jsAttributes->Get(premult ipliedAlpha)->BooleanValue());
77 v8::Handle<v8::String> preserveDrawingBuffer = v8AtomicString(isolat e, "preserveDrawingBuffer"); 87 v8::Handle<v8::String> preserveDrawingBuffer = v8AtomicString(isolat e, "preserveDrawingBuffer");
78 if (jsAttributes->Has(preserveDrawingBuffer)) 88 if (jsAttributes->Has(preserveDrawingBuffer))
79 webGLAttributes->setPreserveDrawingBuffer(jsAttributes->Get(pres erveDrawingBuffer)->BooleanValue()); 89 webGLAttributes->setPreserveDrawingBuffer(jsAttributes->Get(pres erveDrawingBuffer)->BooleanValue());
80 v8::Handle<v8::String> failIfMajorPerformanceCaveat = v8AtomicString (isolate, "failIfMajorPerformanceCaveat"); 90 v8::Handle<v8::String> failIfMajorPerformanceCaveat = v8AtomicString (isolate, "failIfMajorPerformanceCaveat");
81 if (jsAttributes->Has(failIfMajorPerformanceCaveat)) 91 if (jsAttributes->Has(failIfMajorPerformanceCaveat))
82 webGLAttributes->setFailIfMajorPerformanceCaveat(jsAttributes->G et(failIfMajorPerformanceCaveat)->BooleanValue()); 92 webGLAttributes->setFailIfMajorPerformanceCaveat(jsAttributes->G et(failIfMajorPerformanceCaveat)->BooleanValue());
83 } 93 }
84 attributes = webGLAttributes; 94 attributes = webGLAttributes;
85 } else { 95 } else {
86 RefPtr<Canvas2DContextAttributes> canvas2DAttributes = Canvas2DContextAt tributes::create(); 96 RefPtr<Canvas2DContextAttributes> canvas2DAttributes = Canvas2DContextAt tributes::create();
87 if (info.Length() > 1 && info[1]->IsObject()) { 97 if (info.Length() > 1 && info[1]->IsObject()) {
88 v8::Handle<v8::Object> jsAttributes = info[1]->ToObject(); 98 v8::Handle<v8::Object> jsAttributes = info[1]->ToObject();
89 v8::Handle<v8::String> alpha = v8AtomicString(isolate, "alpha"); 99 v8::Handle<v8::String> alpha = v8AtomicString(isolate, "alpha");
90 if (jsAttributes->Has(alpha)) 100 if (jsAttributes->Has(alpha))
91 canvas2DAttributes->setAlpha(jsAttributes->Get(alpha)->BooleanVa lue()); 101 canvas2DAttributes->setAlpha(determineAlpha(jsAttributes->Get(al pha)));
92 } 102 }
93 attributes = canvas2DAttributes; 103 attributes = canvas2DAttributes;
94 } 104 }
95 CanvasRenderingContext* result = impl->getContext(contextId, attributes.get( )); 105 CanvasRenderingContext* result = impl->getContext(contextId, attributes.get( ));
96 if (!result) { 106 if (!result) {
97 v8SetReturnValueNull(info); 107 v8SetReturnValueNull(info);
98 return; 108 return;
99 } 109 }
100 if (result->is2d()) { 110 if (result->is2d()) {
101 v8::Handle<v8::Value> v8Result = toV8(toCanvasRenderingContext2D(result) , info.Holder(), info.GetIsolate()); 111 v8::Handle<v8::Value> v8Result = toV8(toCanvasRenderingContext2D(result) , info.Holder(), info.GetIsolate());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 quality = info[1]->NumberValue(); 152 quality = info[1]->NumberValue();
143 qualityPtr = &quality; 153 qualityPtr = &quality;
144 } 154 }
145 155
146 String result = canvas->toDataURL(type, qualityPtr, exceptionState); 156 String result = canvas->toDataURL(type, qualityPtr, exceptionState);
147 exceptionState.throwIfNeeded(); 157 exceptionState.throwIfNeeded();
148 v8SetReturnValueStringOrUndefined(info, result, info.GetIsolate()); 158 v8SetReturnValueStringOrUndefined(info, result, info.GetIsolate());
149 } 159 }
150 160
151 } // namespace WebCore 161 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/canvas/webgl/context-attributes-alpha-depth-stencil-antialias-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698