Beispiel #1
0
JSValue* jsCSSStyleDeclarationPrototypeFunctionGetPropertyCSSValue(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
    if (!thisValue->isObject(&JSCSSStyleDeclaration::s_info))
        return throwError(exec, TypeError);
    JSCSSStyleDeclaration* castedThisObj = static_cast<JSCSSStyleDeclaration*>(thisValue);
    CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(castedThisObj->impl());
    const UString& propertyName = args[0]->toString(exec);


    KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getPropertyCSSValue(propertyName)));
    return result;
}
Beispiel #2
0
JSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyCSSValue(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
{
    UNUSED_PARAM(args);
    if (!thisValue.isObject(&JSCSSStyleDeclaration::s_info))
        return throwError(exec, TypeError);
    JSCSSStyleDeclaration* castedThisObj = static_cast<JSCSSStyleDeclaration*>(asObject(thisValue));
    CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(castedThisObj->impl());
    const UString& propertyName = args.at(0).toString(exec);


    JSC::JSValue result = toJS(exec, WTF::getPtr(imp->getPropertyCSSValue(propertyName)));
    return result;
}
v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.CSSStyleDeclaration.NamedPropertyGetter");
    // First look for API defined attributes on the style declaration object.
    if (info.Holder()->HasRealNamedCallbackProperty(name))
        return notHandledByInterceptor();

    // Search the style declaration.
    CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
    CSSPropertyInfo* propInfo = cssPropertyInfo(name);

    // Do not handle non-property names.
    if (!propInfo)
        return notHandledByInterceptor();


    RefPtr<CSSValue> cssValue = imp->getPropertyCSSValue(propInfo->propID);
    if (cssValue) {
        if (propInfo->hadPixelOrPosPrefix &&
            cssValue->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
            return v8::Number::New(static_cast<CSSPrimitiveValue*>(
                cssValue.get())->getFloatValue(CSSPrimitiveValue::CSS_PX));
        }
        return v8StringOrNull(cssValue->cssText());
    }

    String result = imp->getPropertyValue(propInfo->propID);
    if (result.isNull())
        result = "";  // convert null to empty string.

    // The 'filter' attribute is made undetectable in KJS/WebKit
    // to avoid confusion with IE's filter extension.
    if (propInfo->wasFilter)
        return v8UndetectableString(result);

    return v8String(result);
}
JSValue* JSCSSStyleDeclarationPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSCSSStyleDeclaration::info))
      return throwError(exec, TypeError);

    CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(static_cast<JSCSSStyleDeclaration*>(thisObj)->impl());

    switch (id) {
    case JSCSSStyleDeclaration::GetPropertyValueFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->getPropertyValue(propertyName));
        return result;
    }
    case JSCSSStyleDeclaration::GetPropertyCSSValueFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getPropertyCSSValue(propertyName)));
        return result;
    }
    case JSCSSStyleDeclaration::RemovePropertyFuncNum: {
        ExceptionCode ec = 0;
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->removeProperty(propertyName, ec));
        setDOMException(exec, ec);
        return result;
    }
    case JSCSSStyleDeclaration::GetPropertyPriorityFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->getPropertyPriority(propertyName));
        return result;
    }
    case JSCSSStyleDeclaration::SetPropertyFuncNum: {
        ExceptionCode ec = 0;
        String propertyName = args[0]->toString(exec);
        String value = valueToStringWithNullCheck(exec, args[1]);
        String priority = args[2]->toString(exec);

        imp->setProperty(propertyName, value, priority, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSCSSStyleDeclaration::ItemFuncNum: {
        bool indexOk;
        unsigned index = args[0]->toInt32(exec, indexOk);
        if (!indexOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }


        KJS::JSValue* result = jsStringOrNull(imp->item(index));
        return result;
    }
    case JSCSSStyleDeclaration::GetPropertyShorthandFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsStringOrNull(imp->getPropertyShorthand(propertyName));
        return result;
    }
    case JSCSSStyleDeclaration::IsPropertyImplicitFuncNum: {
        String propertyName = args[0]->toString(exec);


        KJS::JSValue* result = jsBoolean(imp->isPropertyImplicit(propertyName));
        return result;
    }
    }
    return 0;
}