patch for 'cssFloat'
David Hyatt
hyatt at apple.com
Wed Oct 1 15:00:33 CEST 2003
Here is the test I added for this bug fix:
<body>
<div id="foo"
style="width:100px;height:100px;background-color:green"></div>
<script>
var f = document.getElementById('foo');
f.style.cssFloat = 'left';
with (f.style) {
cssFloat = 'right';
}
</script>
</body>
You should end up with a right-floated 100x100 green square.
On Oct 1, 2003, at 1:34 PM, David Hyatt wrote:
> hasProperty and tryGet didn't do the right thing for 'cssFloat' in the
> Safari tree. Because hasProperty is called when you try to set using
> a with clause, e.g.,
>
> with (elt.style) {
> cssFloat = 'right';
> }
>
> the DHTML menus on aa.com mispositioned their arrow images (this also
> affects tivocommunity.com, bfcu.com, and anyone else who uses
> webreference's HierMenus DHTML framework).
>
> I also added support for mapping "-khtml-" properties so that they
> could be set/retrieved from JS. If you guys are still using "-konq-",
> watch out for that code and do what you think is best.
>
> dave
>
> Index: khtml/ecma/kjs_css.cpp
> ===================================================================
> RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/ecma/kjs_css.cpp,v
> retrieving revision 1.12
> diff -u -p -r1.12 khtml/ecma/kjs_css.cpp
> --- khtml/ecma/kjs_css.cpp 2003/05/23 00:04:31 1.12
> +++ khtml/ecma/kjs_css.cpp 2003/10/01 20:26:37
> @@ -31,18 +31,37 @@
> using namespace KJS;
> #include <kdebug.h>
>
> -static QString jsNameToProp( const Identifier &p )
> +static QString cssPropertyName(const Identifier &p, bool
> *hadPixelOrPosPrefix = 0)
> {
> QString prop = p.qstring();
> +
> int i = prop.length();
> - while( --i ) {
> + while (--i) {
> char c = prop[i].latin1();
> - if ( c < 'A' || c > 'Z' )
> - continue;
> - prop.insert( i, '-' );
> + if (c >= 'A' && c <= 'Z')
> + prop.insert(i, '-');
> }
> +
> + prop = prop.lower();
>
> - return prop.lower();
> + if (hadPixelOrPosPrefix)
> + *hadPixelOrPosPrefix = false;
> +
> + if (prop.startsWith("css-")) {
> + prop = prop.mid(4);
> + } else if (prop.startsWith("pixel-")) {
> + prop = prop.mid(6);
> + if (hadPixelOrPosPrefix)
> + *hadPixelOrPosPrefix = true;
> + } else if (prop.startsWith("pos-")) {
> + prop = prop.mid(4);
> + if (hadPixelOrPosPrefix)
> + *hadPixelOrPosPrefix = true;
> + } else if (prop.startsWith("khtml-")) {
> + prop.insert(0, '-');
> + }
> +
> + return prop;
> }
>
> /*
> @@ -77,9 +96,11 @@ DOMCSSStyleDeclaration::~DOMCSSStyleDecl
>
> bool DOMCSSStyleDeclaration::hasProperty(ExecState *exec, const
> Identifier &p) const
> {
> - DOM::DOMString cssprop = jsNameToProp(p);
> - // strip pos- / pixel- prefix here?
> - if (DOM::getPropertyID(cssprop.string().ascii(), cssprop.length()))
> + if (p == "cssText")
> + return true;
> +
> + QString prop = cssPropertyName(p);
> + if (DOM::getPropertyID(prop.ascii(), prop.length()))
> return true;
>
> return ObjectImp::hasProperty(exec, p);
> @@ -114,26 +135,21 @@ Value DOMCSSStyleDeclaration::tryGet(Exe
> return
> getStringOrNull(DOM::CSSStyleDeclaration(styleDecl).item(u));
>
> #ifdef KJS_VERBOSE
> - kdDebug(6070) << "DOMCSSStyleDeclaration: converting to css
> property name: " << jsNameToProp(propertyName) << endl;
> + kdDebug(6070) << "DOMCSSStyleDeclaration: converting to css
> property name: " << cssPropertyName(propertyName) << endl;
> #endif
> DOM::CSSStyleDeclaration styleDecl2 = styleDecl;
> - DOM::DOMString p = jsNameToProp(propertyName);
> - bool asNumber = false;
> +
> + // Set up pixelOrPos boolean to handle the fact that
> // pixelTop returns "CSS Top" as number value in unit pixels
> // posTop returns "CSS top" as number value in unit pixels _if_ its
> a
> // positioned element. if it is not a positioned element, return 0
> // from MSIE documentation ### IMPLEMENT THAT (Dirk)
> - {
> - QString prop = p.string();
> - if(prop.startsWith( "pixel-") || prop.startsWith( "pos-" ) ) {
> - p = prop.mid(prop.find( '-' )+1);
> - asNumber = true;
> - }
> - }
> + bool pixelOrPos;
> + DOM::DOMString p = cssPropertyName(propertyName, &pixelOrPos);
>
> DOM::CSSValue v = styleDecl2.getPropertyCSSValue(p);
> if (!v.isNull()) {
> - if (asNumber && v.cssValueType() ==
> DOM::CSSValue::CSS_PRIMITIVE_VALUE)
> + if (pixelOrPos && v.cssValueType() ==
> DOM::CSSValue::CSS_PRIMITIVE_VALUE)
> return
> Number(static_cast<DOM::CSSPrimitiveValue>(v).getFloatValue(DOM::
> CSSPrimitiveValue::CSS_PX));
>
> return getStringOrNull(v.cssText());
> @@ -148,10 +164,8 @@ Value DOMCSSStyleDeclaration::tryGet(Exe
> }
>
>
> -void DOMCSSStyleDeclaration::tryPut(ExecState *exec, const Identifier
> &pName, const Value& value, int )
> +void DOMCSSStyleDeclaration::tryPut(ExecState *exec, const Identifier
> &propertyName, const Value& value, int )
> {
> - Identifier propertyName = pName;
> -
> #ifdef KJS_VERBOSE
> kdDebug(6070) << "DOMCSSStyleDeclaration::tryPut " <<
> propertyName.qstring() << endl;
> #endif
> @@ -159,16 +173,11 @@ void DOMCSSStyleDeclaration::tryPut(Exec
> styleDecl.setCssText(value.toString(exec).string());
> }
> else {
> - QString prop = jsNameToProp(propertyName);
> + bool pixelOrPos;
> + QString prop = cssPropertyName(propertyName, &pixelOrPos);
> QString propvalue = value.toString(exec).qstring();
> -
> - if(prop.left(4) == "css-")
> - prop = prop.mid(4);
> -
> - if(prop.startsWith( "pixel-") || prop.startsWith( "pos-" ) ) {
> - prop = prop.mid(prop.find( '-' )+1);
> + if (pixelOrPos)
> propvalue += "px";
> - }
> #ifdef KJS_VERBOSE
> kdDebug(6070) << "DOMCSSStyleDeclaration: prop=" << prop << "
> propvalue=" << propvalue << endl;
> #endif
>
> _______________________________________________
> Khtml-devel at mail.kde.org
> http://mail.kde.org/mailman/listinfo/khtml-devel
More information about the Khtml-devel
mailing list