| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011, Google Inc. | |
| 2 // All rights reserved. | |
| 3 // | |
| 4 // Redistribution and use in source and binary forms, with or without | |
| 5 // modification, are permitted provided that the following conditions are | |
| 6 // met: | |
| 7 // | |
| 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 | |
| 13 // distribution. | |
| 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. | |
| 17 // | |
| 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. | |
| 29 | |
| 30 #include "config.h" | |
| 31 #include "bindings/core/dart/DartCanvasRenderingContext2D.h" | |
| 32 | |
| 33 #include "bindings/core/dart/DartCanvasGradient.h" | |
| 34 #include "bindings/core/dart/DartCanvasPattern.h" | |
| 35 #include "bindings/core/dart/DartDOMWrapper.h" | |
| 36 #include "core/html/canvas/CanvasRenderingContext2D.h" | |
| 37 #include "core/html/canvas/CanvasStyle.h" | |
| 38 | |
| 39 namespace blink { | |
| 40 | |
| 41 namespace DartCanvasRenderingContext2DInternal { | |
| 42 | |
| 43 static void canvasStyleReturnToDartValue(Dart_NativeArguments args, CanvasStyle*
style) | |
| 44 { | |
| 45 if (style->canvasGradient()) { | |
| 46 DartCanvasGradient::returnToDart(args, style->canvasGradient()); | |
| 47 return; | |
| 48 } | |
| 49 | |
| 50 if (style->canvasPattern()) { | |
| 51 DartCanvasPattern::returnToDart(args, style->canvasPattern()); | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 DartUtilities::setDartStringReturnValue(args, style->color()); | |
| 56 } | |
| 57 | |
| 58 static PassRefPtr<CanvasStyle> toCanvasStyle(Dart_Handle value) | |
| 59 { | |
| 60 Dart_Handle exception = 0; | |
| 61 if (DartDOMWrapper::subtypeOf(value, DartCanvasGradient::dartClassId)) | |
| 62 return CanvasStyle::createFromGradient(DartCanvasGradient::toNativeWithN
ullCheck(value, exception)); | |
| 63 | |
| 64 if (DartDOMWrapper::subtypeOf(value, DartCanvasPattern::dartClassId)) | |
| 65 return CanvasStyle::createFromPattern(DartCanvasPattern::toNativeWithNul
lCheck(value, exception)); | |
| 66 | |
| 67 return nullptr; | |
| 68 } | |
| 69 | |
| 70 void strokeStyleGetter(Dart_NativeArguments args ) | |
| 71 { | |
| 72 { | |
| 73 CanvasRenderingContext2D* receiver = DartDOMWrapper::receiver<CanvasRend
eringContext2D>(args); | |
| 74 | |
| 75 canvasStyleReturnToDartValue(args, receiver->strokeStyle()); | |
| 76 return; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void strokeStyleSetter(Dart_NativeArguments args) | |
| 81 { | |
| 82 Dart_Handle exception = 0; | |
| 83 { | |
| 84 CanvasRenderingContext2D* receiver = DartDOMWrapper::receiver<CanvasRend
eringContext2D>(args); | |
| 85 | |
| 86 Dart_Handle arg = Dart_GetNativeArgument(args, 1); | |
| 87 if (Dart_IsString(arg)) { | |
| 88 DartStringAdapter color = DartUtilities::dartToString(args, 1, excep
tion); | |
| 89 if (exception) | |
| 90 goto fail; | |
| 91 | |
| 92 receiver->setStrokeColor(color); | |
| 93 return; | |
| 94 } | |
| 95 | |
| 96 receiver->setStrokeStyle(toCanvasStyle(arg)); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 fail: | |
| 101 Dart_ThrowException(exception); | |
| 102 ASSERT_NOT_REACHED(); | |
| 103 } | |
| 104 | |
| 105 void fillStyleGetter(Dart_NativeArguments args) | |
| 106 { | |
| 107 { | |
| 108 CanvasRenderingContext2D* receiver = DartDOMWrapper::receiver<CanvasRend
eringContext2D>(args); | |
| 109 | |
| 110 canvasStyleReturnToDartValue(args, receiver->fillStyle()); | |
| 111 return; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 void fillStyleSetter(Dart_NativeArguments args) | |
| 116 { | |
| 117 Dart_Handle exception = 0; | |
| 118 { | |
| 119 CanvasRenderingContext2D* receiver = DartDOMWrapper::receiver<CanvasRend
eringContext2D>(args); | |
| 120 | |
| 121 Dart_Handle arg = Dart_GetNativeArgument(args, 1); | |
| 122 if (Dart_IsString(arg)) { | |
| 123 DartStringAdapter color = DartUtilities::dartToString(arg, exception
); | |
| 124 if (exception) | |
| 125 goto fail; | |
| 126 | |
| 127 receiver->setFillColor(color); | |
| 128 return; | |
| 129 } | |
| 130 | |
| 131 receiver->setFillStyle(toCanvasStyle(arg)); | |
| 132 return; | |
| 133 } | |
| 134 | |
| 135 fail: | |
| 136 Dart_ThrowException(exception); | |
| 137 ASSERT_NOT_REACHED(); | |
| 138 } | |
| 139 | |
| 140 } // namespace DartCanvasRenderingContext2DInternal | |
| 141 | |
| 142 } // namespace blink | |
| OLD | NEW |