2
* Copyright (C) 2007 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#include "JSCSSStyleDeclaration.h"
29
#include "AtomicString.h"
30
#include "CSSPrimitiveValue.h"
31
#include "CSSStyleDeclaration.h"
33
#include "DeprecatedString.h"
34
#include "PlatformString.h"
35
#include <kjs/string_object.h>
41
static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0)
43
DeprecatedString prop = propertyName;
45
int i = prop.length();
47
::UChar c = prop[i].unicode();
48
if (c >= 'A' && c <= 'Z')
54
if (hadPixelOrPosPrefix)
55
*hadPixelOrPosPrefix = false;
57
if (prop.startsWith("css-"))
59
else if (prop.startsWith("pixel-")) {
61
if (hadPixelOrPosPrefix)
62
*hadPixelOrPosPrefix = true;
63
} else if (prop.startsWith("pos-")) {
65
if (hadPixelOrPosPrefix)
66
*hadPixelOrPosPrefix = true;
67
} else if (prop.startsWith("khtml-") || prop.startsWith("apple-") || prop.startsWith("webkit-"))
73
static bool isCSSPropertyName(const Identifier& propertyName)
75
return CSSStyleDeclaration::isPropertyName(cssPropertyName(propertyName));
78
bool JSCSSStyleDeclaration::canGetItemsForName(ExecState*, CSSStyleDeclaration*, const Identifier& propertyName)
80
return isCSSPropertyName(propertyName);
83
JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
85
JSCSSStyleDeclaration* thisObj = static_cast<JSCSSStyleDeclaration*>(slot.slotBase());
87
// Set up pixelOrPos boolean to handle the fact that
88
// pixelTop returns "CSS Top" as number value in unit pixels
89
// posTop returns "CSS top" as number value in unit pixels _if_ its a
90
// positioned element. if it is not a positioned element, return 0
91
// from MSIE documentation FIXME: IMPLEMENT THAT (Dirk)
93
String prop = cssPropertyName(propertyName, &pixelOrPos);
94
RefPtr<CSSValue> v = thisObj->impl()->getPropertyCSSValue(prop);
96
if (pixelOrPos && v->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE)
97
return jsNumber(static_pointer_cast<CSSPrimitiveValue>(v)->getFloatValue(CSSPrimitiveValue::CSS_PX));
98
return jsStringOrNull(v->cssText());
101
// If the property is a shorthand property (such as "padding"),
102
// it can only be accessed using getPropertyValue.
104
// Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute.
105
if (propertyName == "filter")
106
return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalInterpreter()->builtinStringPrototype(), thisObj->impl()->getPropertyValue(prop));
108
return jsString(thisObj->impl()->getPropertyValue(prop));
112
bool JSCSSStyleDeclaration::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value, int /*attr*/)
114
if (!isCSSPropertyName(propertyName))
117
DOMExceptionTranslator exception(exec);
119
String prop = cssPropertyName(propertyName, &pixelOrPos);
120
String propValue = valueToStringWithNullCheck(exec, value);
123
impl()->setProperty(prop, propValue, exception);
127
} // namespace WebCore