15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2009 Google Inc. All rights reserved.
302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met:
702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission.
1702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch *
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
3002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
317757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch#include "config.h"
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "V8SVGLength.h"
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
347757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch#include "bindings/v8/ExceptionState.h"
3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "bindings/v8/V8Binding.h"
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/ExceptionCode.h"
3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/svg/SVGLengthContext.h"
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/svg/properties/SVGPropertyTearOff.h"
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)void V8SVGLength::valueAttrGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder());
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGLength& imp = wrapper->propertyReference();
467757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    ExceptionState es(info.GetIsolate());
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGLengthContext lengthContext(wrapper->contextElement());
487757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    float value = imp.value(lengthContext, es);
497757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    if (es.throwIfNeeded())
505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        return;
515267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    v8SetReturnValue(info, value);
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)void V8SVGLength::valueAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(info.Holder());
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (wrapper->isReadOnly()) {
58e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        setDOMException(NoModificationAllowedError, info.GetIsolate());
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!isUndefinedOrNull(value) && !value->IsNumber() && !value->IsBoolean()) {
637757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch        throwTypeError(info.GetIsolate());
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGLength& imp = wrapper->propertyReference();
687757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    ExceptionState es(info.GetIsolate());
695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGLengthContext lengthContext(wrapper->contextElement());
707757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    imp.setValue(static_cast<float>(value->NumberValue()), lengthContext, es);
717757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    if (es.throwIfNeeded())
727757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch        return;
737757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    wrapper->commitChange();
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
765267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)void V8SVGLength::convertToSpecifiedUnitsMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGPropertyTearOff<SVGLength>* wrapper = V8SVGLength::toNative(args.Holder());
795267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    if (wrapper->isReadOnly()) {
80e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch        setDOMException(NoModificationAllowedError, args.GetIsolate());
815267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        return;
825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    }
835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    if (args.Length() < 1) {
855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        throwNotEnoughArgumentsError(args.GetIsolate());
865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        return;
875267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    }
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGLength& imp = wrapper->propertyReference();
907757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    ExceptionState es(args.GetIsolate());
915267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    V8TRYCATCH_VOID(int, unitType, toUInt32(args[0]));
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    SVGLengthContext lengthContext(wrapper->contextElement());
937757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    imp.convertToSpecifiedUnits(unitType, lengthContext, es);
947757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch    if (es.throwIfNeeded())
955267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)        return;
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    wrapper->commitChange();
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore
100