1 /* 2 * Copyright (C) 2009 Google Inc. 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 31 #include <config.h> 32 33 #if ENABLE(SVG) 34 #include "AffineTransform.h" 35 36 #include "SVGException.h" 37 #include "V8Binding.h" 38 #include "V8Proxy.h" 39 #include "V8SVGMatrix.h" 40 #include "V8SVGPODTypeWrapper.h" 41 42 namespace WebCore { 43 44 v8::Handle<v8::Value> V8SVGMatrix::multiplyCallback(const v8::Arguments& args) 45 { 46 INC_STATS("DOM.SVGMatrix.multiply()"); 47 if (args.Length() < 1) 48 return throwError("Not enough arguments"); 49 50 if (!V8SVGMatrix::HasInstance(args[0])) 51 return throwError("secondMatrix argument was not a SVGMatrix"); 52 53 AffineTransform m1 = *V8SVGPODTypeWrapper<AffineTransform>::toNative(args.Holder()); 54 AffineTransform m2 = *V8SVGPODTypeWrapper<AffineTransform>::toNative(v8::Handle<v8::Object>::Cast(args[0])); 55 56 RefPtr<V8SVGStaticPODTypeWrapper<AffineTransform> > wrapper = V8SVGStaticPODTypeWrapper<AffineTransform>::create(m1.multLeft(m2)); 57 return toV8(wrapper.get()); 58 } 59 60 v8::Handle<v8::Value> V8SVGMatrix::inverseCallback(const v8::Arguments& args) 61 { 62 INC_STATS("DOM.SVGMatrix.inverse()"); 63 AffineTransform matrix = *V8SVGPODTypeWrapper<AffineTransform>::toNative(args.Holder()); 64 ExceptionCode ec = 0; 65 AffineTransform result = matrix.inverse(); 66 67 if (!matrix.isInvertible()) 68 ec = SVGException::SVG_MATRIX_NOT_INVERTABLE; 69 70 if (ec != 0) { 71 V8Proxy::setDOMException(ec); 72 return v8::Handle<v8::Value>(); 73 } 74 75 RefPtr<V8SVGStaticPODTypeWrapper<AffineTransform> > wrapper = V8SVGStaticPODTypeWrapper<AffineTransform>::create(result); 76 return toV8(wrapper.get()); 77 } 78 79 v8::Handle<v8::Value> V8SVGMatrix::rotateFromVectorCallback(const v8::Arguments& args) 80 { 81 INC_STATS("DOM.SVGMatrix.rotateFromVector()"); 82 AffineTransform matrix = *V8SVGPODTypeWrapper<AffineTransform>::toNative(args.Holder()); 83 ExceptionCode ec = 0; 84 float x = toFloat(args[0]); 85 float y = toFloat(args[1]); 86 AffineTransform result = matrix; 87 result.rotateFromVector(x, y); 88 if (x == 0.0 || y == 0.0) 89 ec = SVGException::SVG_INVALID_VALUE_ERR; 90 91 if (ec != 0) { 92 V8Proxy::setDOMException(ec); 93 return v8::Handle<v8::Value>(); 94 } 95 96 RefPtr<V8SVGStaticPODTypeWrapper<AffineTransform> > wrapper = V8SVGStaticPODTypeWrapper<AffineTransform>::create(result); 97 return toV8(wrapper.get()); 98 } 99 100 } // namespace WebCore 101 102 #endif 103