# khtml Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kjs_css.cpp

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 2000 Harri Porten (porten@kde.org)
    00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    00006  *
    00007  *  This library is free software; you can redistribute it and/or
    00008  *  modify it under the terms of the GNU Library General Public
    00009  *  License as published by the Free Software Foundation; either
    00010  *  version 2 of the License, or (at your option) any later version.
    00011  *
    00012  *  This library is distributed in the hope that it will be useful,
    00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015  *  Library General Public License for more details.
    00016  *
    00017  *  You should have received a copy of the GNU Library General Public
    00018  *  License along with this library; if not, write to the Free Software
    00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00020  */
    00021
    00022 #include "kjs_css.h"
    00023 #include "kjs_css.lut.h"
    00024
    00025 #include <dom/html_head.h> // for HTMLStyleElement
    00026
    00027 #include <css/cssparser.h>
    00028 #include "kjs_dom.h"
    00029
    00030 using namespace KJS;
    00031 #include <kdebug.h>
    00032
    00033 static QString jsNameToProp( const UString &p )
    00034 {
    00035     QString prop = p.qstring();
    00036     int i = prop.length();
    00037     while( --i ) {
    00038         char c = prop[i].latin1();
    00039         if ( c < 'A' || c > 'Z' )
    00040             continue;
    00041         prop.insert( i, '-' );
    00042     }
    00043
    00044     return prop.lower();
    00045 }
    00046
    00047 /*
    00048 @begin DOMCSSStyleDeclarationProtoTable 7
    00049   getPropertyValue      DOMCSSStyleDeclaration::GetPropertyValue        DontDelete|Function 1
    00050   getPropertyCSSValue   DOMCSSStyleDeclaration::GetPropertyCSSValue     DontDelete|Function 1
    00051   removeProperty        DOMCSSStyleDeclaration::RemoveProperty          DontDelete|Function 1
    00052   getPropertyPriority   DOMCSSStyleDeclaration::GetPropertyPriority     DontDelete|Function 1
    00053   setProperty           DOMCSSStyleDeclaration::SetProperty             DontDelete|Function 3
    00054   item                  DOMCSSStyleDeclaration::Item                    DontDelete|Function 1
    00055 # IE names for it (#36063)
    00056   getAttribute          DOMCSSStyleDeclaration::GetPropertyValue        DontDelete|Function 1
    00057   removeAttribute       DOMCSSStyleDeclaration::RemoveProperty          DontDelete|Function 1
    00058   setAttribute          DOMCSSStyleDeclaration::SetProperty             DontDelete|Function 3
    00059 @end
    00060 @begin DOMCSSStyleDeclarationTable 3
    00061   cssText               DOMCSSStyleDeclaration::CssText         DontDelete
    00062   length                DOMCSSStyleDeclaration::Length          DontDelete|ReadOnly
    00063   parentRule            DOMCSSStyleDeclaration::ParentRule      DontDelete|ReadOnly
    00064 @end
    00065 */
    00066 DEFINE_PROTOTYPE("DOMCSSStyleDeclaration", DOMCSSStyleDeclarationProto)
    00067 IMPLEMENT_PROTOFUNC_DOM(DOMCSSStyleDeclarationProtoFunc)
    00068 IMPLEMENT_PROTOTYPE(DOMCSSStyleDeclarationProto, DOMCSSStyleDeclarationProtoFunc)
    00069
    00070 const ClassInfo DOMCSSStyleDeclaration::info = { "CSSStyleDeclaration", 0, &DOMCSSStyleDeclarationTable, 0 };
    00071
    00072 DOMCSSStyleDeclaration::DOMCSSStyleDeclaration(ExecState *exec, const DOM::CSSStyleDeclaration& s)
    00073   : DOMObject(DOMCSSStyleDeclarationProto::self(exec)), styleDecl(s)
    00074 { }
    00075
    00076 DOMCSSStyleDeclaration::~DOMCSSStyleDeclaration()
    00077 {
    00078   ScriptInterpreter::forgetDOMObject(styleDecl.handle());
    00079 }
    00080
    00081 bool DOMCSSStyleDeclaration::hasProperty(ExecState *exec, const UString &p) const
    00082 {
    00083   DOM::DOMString cssprop = jsNameToProp(p);
    00084   // strip pos- / pixel- prefix here?
    00085   if (DOM::getPropertyID(cssprop.string().ascii(), cssprop.length()))
    00086       return true;
    00087
    00088   return ObjectImp::hasProperty(exec, p);
    00089 }
    00090
    00091 Value DOMCSSStyleDeclaration::tryGet(ExecState *exec, const UString &propertyName) const
    00092 {
    00093 #ifdef KJS_VERBOSE
    00094   kdDebug(6070) << "DOMCSSStyleDeclaration::tryGet " << propertyName.qstring() << endl;
    00095 #endif
    00096   const HashEntry* entry = Lookup::findEntry(&DOMCSSStyleDeclarationTable, propertyName);
    00097   if (entry)
    00098     switch (entry->value) {
    00099     case CssText:
    00100       return getString(styleDecl.cssText());
    00101     case Length:
    00102       return Number(styleDecl.length());
    00103     case ParentRule:
    00104       return getDOMCSSRule(exec,styleDecl.parentRule());
    00105     default:
    00106       break;
    00107     }
    00108
    00109   // Look in the prototype (for functions) before assuming it's a name
    00110   Object proto = Object::dynamicCast(prototype());
    00111   if (!proto.isNull() && proto.hasProperty(exec,propertyName))
    00112     return proto.get(exec,propertyName);
    00113
    00114   bool ok;
    00115   long unsigned int u = propertyName.toULong(&ok);
    00116   if (ok)
    00117     return getString(DOM::CSSStyleDeclaration(styleDecl).item(u));
    00118
    00119 #ifdef KJS_VERBOSE
    00120   kdDebug(6070) << "DOMCSSStyleDeclaration: converting to css property name: " << jsNameToProp(propertyName) << endl;
    00121 #endif
    00122   DOM::DOMString p = jsNameToProp(propertyName);
    00123   bool asNumber = false;
    00124   // pixelTop returns "CSS Top" as number value in unit pixels
    00125   // posTop returns "CSS top" as number value in unit pixels _if_ its a
    00126   // positioned element. if it is not a positioned element, return 0
    00127   // from MSIE documentation ### IMPLEMENT THAT (Dirk)
    00128   {
    00129     QString prop = p.string();
    00130     if(prop.startsWith( "pixel-") || prop.startsWith( "pos-" ) ) {
    00131       p = prop.mid(prop.find( '-' )+1);
    00132       asNumber = true;
    00133     }
    00134   }
    00135
    00136   if (asNumber) {
    00137     DOM::CSSValue v = styleDecl.getPropertyCSSValue(p);
    00138     if ( !v.isNull() && v.cssValueType() == DOM::CSSValue::CSS_PRIMITIVE_VALUE)
    00139       return Number(static_cast<DOM::CSSPrimitiveValue>(v).getFloatValue(DOM::CSSPrimitiveValue::CSS_PX));
    00140   }
    00141
    00142   DOM::DOMString str = const_cast<DOM::CSSStyleDeclaration &>( styleDecl ).getPropertyValue(p);
    00143   if (!str.isNull())
    00144     return String(str);
    00145
    00146   // see if we know this css property, return empty then
    00147   QCString prop = p.string().latin1();
    00148   if (DOM::getPropertyID(prop.data(), prop.length()))
    00149       return getString(DOM::DOMString(""));
    00150
    00151   return DOMObject::tryGet(exec, propertyName);
    00152 }
    00153
    00154
    00155 void DOMCSSStyleDeclaration::tryPut(ExecState *exec, const UString &pName, const Value& value, int attr )
    00156 {
    00157   UString propertyName = pName;
    00158
    00159 #ifdef KJS_VERBOSE
    00160   kdDebug(6070) << "DOMCSSStyleDeclaration::tryPut " << propertyName.qstring() << endl;
    00161 #endif
    00162   if (propertyName == "cssText") {
    00163     styleDecl.setCssText(value.toString(exec).string());
    00164   }
    00165   else {
    00166     QString prop = jsNameToProp(propertyName);
    00167     QString propvalue = value.toString(exec).qstring();
    00168
    00169     if(prop.left(4) == "css-")
    00170       prop = prop.mid(4);
    00171
    00172     if(prop.startsWith( "pixel-") || prop.startsWith( "pos-" ) ) {
    00173       prop = prop.mid(prop.find( '-' )+1);
    00174       propvalue += "px";
    00175     }
    00176 #ifdef KJS_VERBOSE
    00177     kdDebug(6070) << "DOMCSSStyleDeclaration: prop=" << prop << " propvalue=" << propvalue << endl;
    00178 #endif
    00179     styleDecl.removeProperty(prop);
    00180     if(!propvalue.isEmpty())
    00181     {
    00182       // Look whether the property is known. In that case add it as a CSS property.
    00183       QCString cprop = prop.latin1();
    00184       if (DOM::getPropertyID(cprop.data(), cprop.length()))
    00185         styleDecl.setProperty(prop,DOM::DOMString(propvalue),""); // ### is "" ok for priority?
    00186       else
    00187       {
    00188         // otherwise add it as a JS property
    00189         DOMObject::tryPut( exec, pName, value, attr );
    00190       }
    00191     }
    00192   }
    00193 }
    00194
    00195 Value DOMCSSStyleDeclarationProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00196 {
    00197   KJS_CHECK_THIS( KJS::DOMCSSStyleDeclaration, thisObj );
    00198   DOM::CSSStyleDeclaration styleDecl = static_cast<DOMCSSStyleDeclaration *>(thisObj.imp())->toStyleDecl();
    00199   String str = args[0].toString(exec);
    00200   DOM::DOMString s = str.value().string();
    00201
    00202   switch (id) {
    00203     case DOMCSSStyleDeclaration::GetPropertyValue:
    00204       return getString(styleDecl.getPropertyValue(s));
    00205     case DOMCSSStyleDeclaration::GetPropertyCSSValue:
    00206       return getDOMCSSValue(exec,styleDecl.getPropertyCSSValue(s));
    00207     case DOMCSSStyleDeclaration::RemoveProperty:
    00208       return getString(styleDecl.removeProperty(s));
    00209     case DOMCSSStyleDeclaration::GetPropertyPriority:
    00210       return getString(styleDecl.getPropertyPriority(s));
    00211     case DOMCSSStyleDeclaration::SetProperty:
    00212       styleDecl.setProperty(args[0].toString(exec).string(),
    00213                             args[1].toString(exec).string(),
    00214                             args[2].toString(exec).string());
    00215       return Undefined();
    00216     case DOMCSSStyleDeclaration::Item:
    00217       return getString(styleDecl.item(args[0].toInteger(exec)));
    00218     default:
    00219       return Undefined();
    00220   }
    00221 }
    00222
    00223 Value KJS::getDOMCSSStyleDeclaration(ExecState *exec, const DOM::CSSStyleDeclaration& s)
    00224 {
    00225   return cacheDOMObject<DOM::CSSStyleDeclaration, KJS::DOMCSSStyleDeclaration>(exec, s);
    00226 }
    00227
    00228 // -------------------------------------------------------------------------
    00229
    00230 const ClassInfo DOMStyleSheet::info = { "StyleSheet", 0, &DOMStyleSheetTable, 0 };
    00231 /*
    00232 @begin DOMStyleSheetTable 7
    00233   type          DOMStyleSheet::Type             DontDelete|ReadOnly
    00234   disabled      DOMStyleSheet::Disabled         DontDelete
    00235   ownerNode     DOMStyleSheet::OwnerNode        DontDelete|ReadOnly
    00236   parentStyleSheet DOMStyleSheet::ParentStyleSheet      DontDelete|ReadOnly
    00237   href          DOMStyleSheet::Href             DontDelete|ReadOnly
    00238   title         DOMStyleSheet::Title            DontDelete|ReadOnly
    00239   media         DOMStyleSheet::Media            DontDelete|ReadOnly
    00240 @end
    00241 */
    00242
    00243 DOMStyleSheet::DOMStyleSheet(ExecState* exec, const DOM::StyleSheet& ss)
    00244   : DOMObject(exec->interpreter()->builtinObjectPrototype()), styleSheet(ss)
    00245 {
    00246 }
    00247
    00248 DOMStyleSheet::~DOMStyleSheet()
    00249 {
    00250   ScriptInterpreter::forgetDOMObject(styleSheet.handle());
    00251 }
    00252
    00253 Value DOMStyleSheet::tryGet(ExecState *exec, const UString &propertyName) const
    00254 {
    00255   return DOMObjectLookupGetValue<DOMStyleSheet,DOMObject>(exec,propertyName,&DOMStyleSheetTable,this);
    00256 }
    00257
    00258 Value DOMStyleSheet::getValueProperty(ExecState *exec, int token) const
    00259 {
    00260   switch (token) {
    00261   case Type:
    00262     return getString(styleSheet.type());
    00263   case Disabled:
    00264     return Boolean(styleSheet.disabled());
    00265   case OwnerNode:
    00266     return getDOMNode(exec,styleSheet.ownerNode());
    00267   case ParentStyleSheet:
    00268     return getDOMStyleSheet(exec,styleSheet.parentStyleSheet());
    00269   case Href:
    00270     return getString(styleSheet.href());
    00271   case Title:
    00272     return getString(styleSheet.title());
    00273   case Media:
    00274     return getDOMMediaList(exec, styleSheet.media());
    00275   }
    00276   return Value();
    00277 }
    00278
    00279 void DOMStyleSheet::tryPut(ExecState *exec, const UString &propertyName, const Value& value, int attr)
    00280 {
    00281   if (propertyName == "disabled") {
    00282     styleSheet.setDisabled(value.toBoolean(exec));
    00283   }
    00284   else
    00285     DOMObject::tryPut(exec, propertyName, value, attr);
    00286 }
    00287
    00288 Value KJS::getDOMStyleSheet(ExecState *exec, const DOM::StyleSheet& ss)
    00289 {
    00290   DOMObject *ret;
    00291   if (ss.isNull())
    00292     return Null();
    00293   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
    00294   if ((ret = interp->getDOMObject(ss.handle())))
    00295     return Value(ret);
    00296   else {
    00297     if (ss.isCSSStyleSheet()) {
    00298       DOM::CSSStyleSheet cs;
    00299       cs = ss;
    00300       ret = new DOMCSSStyleSheet(exec,cs);
    00301     }
    00302     else
    00303       ret = new DOMStyleSheet(exec,ss);
    00304     interp->putDOMObject(ss.handle(),ret);
    00305     return Value(ret);
    00306   }
    00307 }
    00308
    00309 // -------------------------------------------------------------------------
    00310
    00311 const ClassInfo DOMStyleSheetList::info = { "StyleSheetList", 0, &DOMStyleSheetListTable, 0 };
    00312
    00313 /*
    00314 @begin DOMStyleSheetListTable 2
    00315   length        DOMStyleSheetList::Length       DontDelete|ReadOnly
    00316   item          DOMStyleSheetList::Item         DontDelete|Function 1
    00317 @end
    00318 */
    00319 IMPLEMENT_PROTOFUNC_DOM(DOMStyleSheetListFunc) // not really a proto, but doesn't matter
    00320
    00321 DOMStyleSheetList::DOMStyleSheetList(ExecState *exec, const DOM::StyleSheetList& ssl, const DOM::Document& doc)
    00322   : DOMObject(exec->interpreter()->builtinObjectPrototype()), styleSheetList(ssl), m_doc(doc)
    00323 {
    00324 }
    00325
    00326 DOMStyleSheetList::~DOMStyleSheetList()
    00327 {
    00328   ScriptInterpreter::forgetDOMObject(styleSheetList.handle());
    00329 }
    00330
    00331 Value DOMStyleSheetList::tryGet(ExecState *exec, const UString &p) const
    00332 {
    00333 #ifdef KJS_VERBOSE
    00334   kdDebug(6070) << "DOMStyleSheetList::tryGet " << p.qstring() << endl;
    00335 #endif
    00336   if (p == "length")
    00337     return Number(styleSheetList.length());
    00338   else if (p == "item")
    00339     return lookupOrCreateFunction<DOMStyleSheetListFunc>(exec,p,this,DOMStyleSheetList::Item,1,DontDelete|Function);
    00340
    00341   // Retrieve stylesheet by index
    00342   bool ok;
    00343   long unsigned int u = p.toULong(&ok);
    00344   if (ok)
    00345     return getDOMStyleSheet(exec, DOM::StyleSheetList(styleSheetList).item(u));
    00346
    00347   // IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag
    00348   // (this is consistent with all the other collections)
    00349 #if 0
    00350   // Bad implementation because DOM::StyleSheet doesn't inherit DOM::Node
    00351   // so we can't use DOMNamedNodesCollection.....
    00352   // We could duplicate it for stylesheets though - worth it ?
    00353   // Other problem of this implementation: it doesn't look for the ID attribute!
    00354   DOM::NameNodeListImpl namedList( m_doc.documentElement().handle(), p.string() );
    00355   int len = namedList.length();
    00356   if ( len ) {
    00357     QValueList<DOM::Node> styleSheets;
    00358     for ( int i = 0 ; i < len ; ++i ) {
    00359       DOM::HTMLStyleElement elem = DOM::Node(namedList.item(i));
    00360       if (!elem.isNull())
    00361         styleSheets.append(elem.sheet());
    00362     }
    00363     if ( styleSheets.count() == 1 ) // single result
    00364       return getDOMStyleSheet(exec, styleSheets[0]);
    00365     else if ( styleSheets.count() > 1 ) {
    00366       return new DOMNamedItemsCollection(exec,styleSheets);
    00367     }
    00368   }
    00369 #endif
    00370   // ### Bad implementation because returns a single element (are IDs always unique?)
    00371   // and doesn't look for name attribute (see implementation above).
    00372   // But unicity of stylesheet ids is good practice anyway ;)
    00373   DOM::DOMString pstr = p.string();
    00374   DOM::HTMLStyleElement styleElem = m_doc.getElementById( pstr );
    00375   if (!styleElem.isNull())
    00376     return getDOMStyleSheet(exec, styleElem.sheet());
    00377
    00378   return DOMObject::tryGet(exec, p);
    00379 }
    00380
    00381 Value KJS::DOMStyleSheetList::call(ExecState *exec, Object &thisObj, const List &args)
    00382 {
    00383   // This code duplication is necessary, DOMStyleSheetList isn't a DOMFunction
    00384   Value val;
    00385   try {
    00386     val = tryCall(exec, thisObj, args);
    00387   }
    00388   // pity there's no way to distinguish between these in JS code
    00389   catch (...) {
    00390     Object err = Error::create(exec, GeneralError, "Exception from DOMStyleSheetList");
    00391     exec->setException(err);
    00392   }
    00393   return val;
    00394 }
    00395
    00396 Value DOMStyleSheetList::tryCall(ExecState *exec, Object & /*thisObj*/, const List &args)
    00397 {
    00398   if (args.size() == 1) {
    00399     // support for styleSheets(<index>) and styleSheets(<name>)
    00400     return tryGet( exec, args[0].toString(exec) );
    00401   }
    00402   return Undefined();
    00403 }
    00404
    00405 Value KJS::getDOMStyleSheetList(ExecState *exec, const DOM::StyleSheetList& ssl, const DOM::Document& doc)
    00406 {
    00407   // Can't use the cacheDOMObject macro because of the doc argument
    00408   DOMObject *ret;
    00409   if (ssl.isNull())
    00410     return Null();
    00411   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
    00412   if ((ret = interp->getDOMObject(ssl.handle())))
    00413     return Value(ret);
    00414   else {
    00415     ret = new DOMStyleSheetList(exec, ssl, doc);
    00416     interp->putDOMObject(ssl.handle(),ret);
    00417     return Value(ret);
    00418   }
    00419 }
    00420
    00421 Value DOMStyleSheetListFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00422 {
    00423   KJS_CHECK_THIS( KJS::DOMStyleSheetList, thisObj );
    00424   DOM::StyleSheetList styleSheetList = static_cast<DOMStyleSheetList *>(thisObj.imp())->toStyleSheetList();
    00425   if (id == DOMStyleSheetList::Item)
    00426     return getDOMStyleSheet(exec, styleSheetList.item(args[0].toInteger(exec)));
    00427   return Undefined();
    00428 }
    00429
    00430 // -------------------------------------------------------------------------
    00431
    00432 const ClassInfo DOMMediaList::info = { "MediaList", 0, &DOMMediaListTable, 0 };
    00433
    00434 /*
    00435 @begin DOMMediaListTable 2
    00436   mediaText     DOMMediaList::MediaText         DontDelete|ReadOnly
    00437   length        DOMMediaList::Length            DontDelete|ReadOnly
    00438 @end
    00439 @begin DOMMediaListProtoTable 3
    00440   item          DOMMediaList::Item              DontDelete|Function 1
    00441   deleteMedium  DOMMediaList::DeleteMedium      DontDelete|Function 1
    00442   appendMedium  DOMMediaList::AppendMedium      DontDelete|Function 1
    00443 @end
    00444 */
    00445 DEFINE_PROTOTYPE("DOMMediaList", DOMMediaListProto)
    00446 IMPLEMENT_PROTOFUNC_DOM(DOMMediaListProtoFunc)
    00447 IMPLEMENT_PROTOTYPE(DOMMediaListProto, DOMMediaListProtoFunc)
    00448
    00449 DOMMediaList::DOMMediaList(ExecState *exec, const DOM::MediaList& ml)
    00450   : DOMObject(DOMMediaListProto::self(exec)), mediaList(ml) { }
    00451
    00452 DOMMediaList::~DOMMediaList()
    00453 {
    00454   ScriptInterpreter::forgetDOMObject(mediaList.handle());
    00455 }
    00456
    00457 Value DOMMediaList::tryGet(ExecState *exec, const UString &p) const
    00458 {
    00459   if (p == "mediaText")
    00460     return getString(mediaList.mediaText());
    00461   else if (p == "length")
    00462     return Number(mediaList.length());
    00463
    00464   bool ok;
    00465   long unsigned int u = p.toULong(&ok);
    00466   if (ok)
    00467     return getString(mediaList.item(u));
    00468
    00469   return DOMObject::tryGet(exec, p);
    00470 }
    00471
    00472 void DOMMediaList::tryPut(ExecState *exec, const UString &propertyName, const Value& value, int attr)
    00473 {
    00474   if (propertyName == "mediaText")
    00475     mediaList.setMediaText(value.toString(exec).string());
    00476   else
    00477     DOMObject::tryPut(exec, propertyName, value, attr);
    00478 }
    00479
    00480 Value KJS::getDOMMediaList(ExecState *exec, const DOM::MediaList& ml)
    00481 {
    00482   return cacheDOMObject<DOM::MediaList, KJS::DOMMediaList>(exec, ml);
    00483 }
    00484
    00485 Value KJS::DOMMediaListProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00486 {
    00487   KJS_CHECK_THIS( KJS::DOMMediaList, thisObj );
    00488   DOM::MediaList mediaList = static_cast<DOMMediaList *>(thisObj.imp())->toMediaList();
    00489   switch (id) {
    00490     case DOMMediaList::Item:
    00491       return getString(mediaList.item(args[0].toInteger(exec)));
    00492     case DOMMediaList::DeleteMedium:
    00493       mediaList.deleteMedium(args[0].toString(exec).string());
    00494       return Undefined();
    00495     case DOMMediaList::AppendMedium:
    00496       mediaList.appendMedium(args[0].toString(exec).string());
    00497       return Undefined();
    00498     default:
    00499       return Undefined();
    00500   }
    00501 }
    00502
    00503 // -------------------------------------------------------------------------
    00504
    00505 const ClassInfo DOMCSSStyleSheet::info = { "CSSStyleSheet", 0, &DOMCSSStyleSheetTable, 0 };
    00506
    00507 /*
    00508 @begin DOMCSSStyleSheetTable 2
    00509   ownerRule     DOMCSSStyleSheet::OwnerRule     DontDelete|ReadOnly
    00510   cssRules      DOMCSSStyleSheet::CssRules      DontDelete|ReadOnly
    00511 # MSIE extension
    00512   rules         DOMCSSStyleSheet::Rules         DontDelete|ReadOnly
    00513 @end
    00514 @begin DOMCSSStyleSheetProtoTable 2
    00515   insertRule    DOMCSSStyleSheet::InsertRule    DontDelete|Function 2
    00516   deleteRule    DOMCSSStyleSheet::DeleteRule    DontDelete|Function 1
    00517 # IE extensions
    00518   addRule       DOMCSSStyleSheet::AddRule       DontDelete|Function 3
    00519   removeRule    DOMCSSStyleSheet::RemoveRule    DontDelete|Function 1
    00520 @end
    00521 */
    00522 DEFINE_PROTOTYPE("DOMCSSStyleSheet",DOMCSSStyleSheetProto)
    00523 IMPLEMENT_PROTOFUNC_DOM(DOMCSSStyleSheetProtoFunc)
    00524 IMPLEMENT_PROTOTYPE(DOMCSSStyleSheetProto,DOMCSSStyleSheetProtoFunc) // warning, use _WITH_PARENT if DOMStyleSheet gets a proto
    00525
    00526 DOMCSSStyleSheet::DOMCSSStyleSheet(ExecState *exec, const DOM::CSSStyleSheet& ss)
    00527   : DOMStyleSheet(DOMCSSStyleSheetProto::self(exec),ss) { }
    00528
    00529 DOMCSSStyleSheet::~DOMCSSStyleSheet()
    00530 {
    00531 }
    00532
    00533 Value DOMCSSStyleSheet::tryGet(ExecState *exec, const UString &p) const
    00534 {
    00535   DOM::CSSStyleSheet cssStyleSheet = static_cast<DOM::CSSStyleSheet>(styleSheet);
    00536   if (p == "ownerRule")
    00537     return getDOMCSSRule(exec,cssStyleSheet.ownerRule());
    00538   else if (p == "cssRules" || p == "rules" /* MSIE extension */)
    00539     return getDOMCSSRuleList(exec,cssStyleSheet.cssRules());
    00540   return DOMStyleSheet::tryGet(exec,p);
    00541 }
    00542
    00543 Value DOMCSSStyleSheetProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00544 {
    00545   KJS_CHECK_THIS( KJS::DOMCSSStyleSheet, thisObj );
    00546   DOM::CSSStyleSheet styleSheet = static_cast<DOMCSSStyleSheet *>(thisObj.imp())->toCSSStyleSheet();
    00547
    00548   switch (id) {
    00549     case DOMCSSStyleSheet::InsertRule:
    00550       return Number(styleSheet.insertRule(args[0].toString(exec).string(),(long unsigned int)args[1].toInteger(exec)));
    00551     case DOMCSSStyleSheet::DeleteRule:
    00552       styleSheet.deleteRule(args[0].toInteger(exec));
    00553       return Undefined();
    00554     // IE extensions
    00555     case DOMCSSStyleSheet::AddRule: {
    00556       DOM::DOMString str = args[0].toString(exec).string() + " { " + args[1].toString(exec).string() + " } ";
    00557       return Number(styleSheet.insertRule(str,(long unsigned int)args[2].toInteger(exec)));
    00558     }
    00559     case DOMCSSStyleSheet::RemoveRule: {
    00560       int index = args.size() > 0 ? args[0].toInteger(exec) : 0 /*first one*/;
    00561       styleSheet.deleteRule(index);
    00562       return Undefined();
    00563     }
    00564     default:
    00565       return Undefined();
    00566   }
    00567 }
    00568
    00569 // -------------------------------------------------------------------------
    00570
    00571 const ClassInfo DOMCSSRuleList::info = { "CSSRuleList", 0, &DOMCSSRuleListTable, 0 };
    00572 /*
    00573 @begin DOMCSSRuleListTable 3
    00574   length                DOMCSSRuleList::Length          DontDelete|ReadOnly
    00575   item                  DOMCSSRuleList::Item            DontDelete|Function 1
    00576 @end
    00577 */
    00578 IMPLEMENT_PROTOFUNC_DOM(DOMCSSRuleListFunc) // not really a proto, but doesn't matter
    00579
    00580 DOMCSSRuleList::DOMCSSRuleList(ExecState* exec, const DOM::CSSRuleList& rl)
    00581   : DOMObject(exec->interpreter()->builtinObjectPrototype()), cssRuleList(rl)
    00582 {
    00583 }
    00584
    00585 DOMCSSRuleList::~DOMCSSRuleList()
    00586 {
    00587   ScriptInterpreter::forgetDOMObject(cssRuleList.handle());
    00588 }
    00589
    00590 Value DOMCSSRuleList::tryGet(ExecState *exec, const UString &p) const
    00591 {
    00592   Value result;
    00593   if (p == "length")
    00594     return Number(cssRuleList.length());
    00595   else if (p == "item")
    00596     return lookupOrCreateFunction<DOMCSSRuleListFunc>(exec,p,this,DOMCSSRuleList::Item,1,DontDelete|Function);
    00597
    00598   bool ok;
    00599   long unsigned int u = p.toULong(&ok);
    00600   if (ok)
    00601     return getDOMCSSRule(exec,DOM::CSSRuleList(cssRuleList).item(u));
    00602
    00603   return DOMObject::tryGet(exec,p);
    00604 }
    00605
    00606 Value DOMCSSRuleListFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00607 {
    00608   KJS_CHECK_THIS( KJS::DOMCSSRuleList, thisObj );
    00609   DOM::CSSRuleList cssRuleList = static_cast<DOMCSSRuleList *>(thisObj.imp())->toCSSRuleList();
    00610   switch (id) {
    00611     case DOMCSSRuleList::Item:
    00612       return getDOMCSSRule(exec,cssRuleList.item(args[0].toInteger(exec)));
    00613     default:
    00614       return Undefined();
    00615   }
    00616 }
    00617
    00618 Value KJS::getDOMCSSRuleList(ExecState *exec, const DOM::CSSRuleList& rl)
    00619 {
    00620   return cacheDOMObject<DOM::CSSRuleList, KJS::DOMCSSRuleList>(exec, rl);
    00621 }
    00622
    00623 // -------------------------------------------------------------------------
    00624
    00625 IMPLEMENT_PROTOFUNC_DOM(DOMCSSRuleFunc) // Not a proto, but doesn't matter
    00626
    00627 DOMCSSRule::DOMCSSRule(ExecState* exec, const DOM::CSSRule& r)
    00628   : DOMObject(exec->interpreter()->builtinObjectPrototype()), cssRule(r)
    00629 {
    00630 }
    00631
    00632 DOMCSSRule::~DOMCSSRule()
    00633 {
    00634   ScriptInterpreter::forgetDOMObject(cssRule.handle());
    00635 }
    00636
    00637 const ClassInfo DOMCSSRule::info = { "CSSRule", 0, &DOMCSSRuleTable, 0 };
    00638 const ClassInfo DOMCSSRule::style_info = { "CSSStyleRule", &DOMCSSRule::info, &DOMCSSStyleRuleTable, 0 };
    00639 const ClassInfo DOMCSSRule::media_info = { "CSSMediaRule", &DOMCSSRule::info, &DOMCSSMediaRuleTable, 0 };
    00640 const ClassInfo DOMCSSRule::fontface_info = { "CSSFontFaceRule", &DOMCSSRule::info, &DOMCSSFontFaceRuleTable, 0 };
    00641 const ClassInfo DOMCSSRule::page_info = { "CSSPageRule", &DOMCSSRule::info, &DOMCSSPageRuleTable, 0 };
    00642 const ClassInfo DOMCSSRule::import_info = { "CSSImportRule", &DOMCSSRule::info, &DOMCSSImportRuleTable, 0 };
    00643 const ClassInfo DOMCSSRule::charset_info = { "CSSCharsetRule", &DOMCSSRule::info, &DOMCSSCharsetRuleTable, 0 };
    00644
    00645 const ClassInfo* DOMCSSRule::classInfo() const
    00646 {
    00647   switch (cssRule.type()) {
    00648   case DOM::CSSRule::STYLE_RULE:
    00649     return &style_info;
    00650   case DOM::CSSRule::MEDIA_RULE:
    00651     return &media_info;
    00652   case DOM::CSSRule::FONT_FACE_RULE:
    00653     return &fontface_info;
    00654   case DOM::CSSRule::PAGE_RULE:
    00655     return &page_info;
    00656   case DOM::CSSRule::IMPORT_RULE:
    00657     return &import_info;
    00658   case DOM::CSSRule::CHARSET_RULE:
    00659     return &charset_info;
    00660   case DOM::CSSRule::UNKNOWN_RULE:
    00661   default:
    00662     return &info;
    00663   }
    00664 }
    00665 /*
    00666 @begin DOMCSSRuleTable 4
    00667   type                  DOMCSSRule::Type        DontDelete|ReadOnly
    00668   cssText               DOMCSSRule::CssText     DontDelete|ReadOnly
    00669   parentStyleSheet      DOMCSSRule::ParentStyleSheet    DontDelete|ReadOnly
    00670   parentRule            DOMCSSRule::ParentRule  DontDelete|ReadOnly
    00671 @end
    00672 @begin DOMCSSStyleRuleTable 2
    00673   selectorText          DOMCSSRule::Style_SelectorText  DontDelete
    00674   style                 DOMCSSRule::Style_Style         DontDelete|ReadOnly
    00675 @end
    00676 @begin DOMCSSMediaRuleTable 4
    00677   media                 DOMCSSRule::Media_Media         DontDelete|ReadOnly
    00678   cssRules              DOMCSSRule::Media_CssRules      DontDelete|ReadOnly
    00679   insertRule            DOMCSSRule::Media_InsertRule    DontDelete|Function 2
    00680   deleteRule            DOMCSSRule::Media_DeleteRule    DontDelete|Function 1
    00681 @end
    00682 @begin DOMCSSFontFaceRuleTable 1
    00683   style                 DOMCSSRule::FontFace_Style      DontDelete|ReadOnly
    00684 @end
    00685 @begin DOMCSSPageRuleTable 2
    00686   selectorText          DOMCSSRule::Page_SelectorText   DontDelete
    00687   style                 DOMCSSRule::Page_Style          DontDelete|ReadOnly
    00688 @end
    00689 @begin DOMCSSImportRuleTable 3
    00690   href                  DOMCSSRule::Import_Href         DontDelete|ReadOnly
    00691   media                 DOMCSSRule::Import_Media        DontDelete|ReadOnly
    00692   styleSheet            DOMCSSRule::Import_StyleSheet   DontDelete|ReadOnly
    00693 @end
    00694 @begin DOMCSSCharsetRuleTable 1
    00695   encoding              DOMCSSRule::Charset_Encoding    DontDelete
    00696 @end
    00697 */
    00698 Value DOMCSSRule::tryGet(ExecState *exec, const UString &propertyName) const
    00699 {
    00700 #ifdef KJS_VERBOSE
    00701   kdDebug(6070) << "DOMCSSRule::tryGet " << propertyName.qstring() << endl;
    00702 #endif
    00703   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
    00704   const HashEntry* entry = Lookup::findEntry(table, propertyName);
    00705   if (entry) {
    00706     if (entry->attr & Function)
    00707       return lookupOrCreateFunction<DOMCSSRuleFunc>(exec, propertyName, this, entry->value, entry->params, entry->attr);
    00708     return getValueProperty(exec, entry->value);
    00709   }
    00710
    00711   // Base CSSRule stuff or parent class forward, as usual
    00712   return DOMObjectLookupGet<DOMCSSRuleFunc, DOMCSSRule, DOMObject>(exec, propertyName, &DOMCSSRuleTable, this);
    00713 }
    00714
    00715 Value DOMCSSRule::getValueProperty(ExecState *exec, int token) const
    00716 {
    00717   switch (token) {
    00718   case Type:
    00719     return Number(cssRule.type());
    00720   case CssText:
    00721     return getString(cssRule.cssText());
    00722   case ParentStyleSheet:
    00723     return getDOMStyleSheet(exec,cssRule.parentStyleSheet());
    00724   case ParentRule:
    00725     return getDOMCSSRule(exec,cssRule.parentRule());
    00726
    00727   // for DOM::CSSRule::STYLE_RULE:
    00728   case Style_SelectorText:
    00729     return getString(static_cast<DOM::CSSStyleRule>(cssRule).selectorText());
    00730   case Style_Style:
    00731     return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSStyleRule>(cssRule).style());
    00732
    00733   // for DOM::CSSRule::MEDIA_RULE:
    00734   case Media_Media:
    00735     return getDOMMediaList(exec,static_cast<DOM::CSSMediaRule>(cssRule).media());
    00736   case Media_CssRules:
    00737     return getDOMCSSRuleList(exec,static_cast<DOM::CSSMediaRule>(cssRule).cssRules());
    00738
    00739   // for DOM::CSSRule::FONT_FACE_RULE:
    00740   case FontFace_Style:
    00741     return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSFontFaceRule>(cssRule).style());
    00742
    00743   // for DOM::CSSRule::PAGE_RULE:
    00744   case Page_SelectorText:
    00745     return getString(static_cast<DOM::CSSPageRule>(cssRule).selectorText());
    00746   case Page_Style:
    00747     return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSPageRule>(cssRule).style());
    00748
    00749   // for DOM::CSSRule::IMPORT_RULE:
    00750   case Import_Href:
    00751     return getString(static_cast<DOM::CSSImportRule>(cssRule).href());
    00752   case Import_Media:
    00753     return getDOMMediaList(exec,static_cast<DOM::CSSImportRule>(cssRule).media());
    00754   case Import_StyleSheet:
    00755     return getDOMStyleSheet(exec,static_cast<DOM::CSSImportRule>(cssRule).styleSheet());
    00756
    00757   // for DOM::CSSRule::CHARSET_RULE:
    00758   case Charset_Encoding:
    00759     return getString(static_cast<DOM::CSSCharsetRule>(cssRule).encoding());
    00760
    00761   default:
    00762     kdWarning() << "DOMCSSRule::getValueProperty unhandled token " << token << endl;
    00763   }
    00764   return Undefined();
    00765 }
    00766
    00767 void DOMCSSRule::tryPut(ExecState *exec, const UString &propertyName, const Value& value, int attr)
    00768 {
    00769   const HashTable* table = classInfo()->propHashTable; // get the right hashtable
    00770   const HashEntry* entry = Lookup::findEntry(table, propertyName);
    00771   if (entry) {
    00772     if (entry->attr & Function) // function: put as override property
    00773     {
    00774       ObjectImp::put(exec, propertyName, value, attr);
    00775       return;
    00776     }
    00777     else if ((entry->attr & ReadOnly) == 0) // let DOMObjectLookupPut print the warning if not
    00778     {
    00779       putValueProperty(exec, entry->value, value, attr);
    00780       return;
    00781     }
    00782   }
    00783   DOMObjectLookupPut<DOMCSSRule, DOMObject>(exec, propertyName, value, attr, &DOMCSSRuleTable, this);
    00784 }
    00785
    00786 void DOMCSSRule::putValueProperty(ExecState *exec, int token, const Value& value, int)
    00787 {
    00788   switch (token) {
    00789   // for DOM::CSSRule::STYLE_RULE:
    00790   case Style_SelectorText:
    00791     static_cast<DOM::CSSStyleRule>(cssRule).setSelectorText(value.toString(exec).string());
    00792     return;
    00793
    00794   // for DOM::CSSRule::PAGE_RULE:
    00795   case Page_SelectorText:
    00796     static_cast<DOM::CSSPageRule>(cssRule).setSelectorText(value.toString(exec).string());
    00797     return;
    00798
    00799   // for DOM::CSSRule::CHARSET_RULE:
    00800   case Charset_Encoding:
    00801     static_cast<DOM::CSSCharsetRule>(cssRule).setEncoding(value.toString(exec).string());
    00802     return;
    00803
    00804   default:
    00805     kdWarning() << "DOMCSSRule::putValueProperty unhandled token " << token << endl;
    00806   }
    00807 }
    00808
    00809 Value DOMCSSRuleFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00810 {
    00811   KJS_CHECK_THIS( KJS::DOMCSSRule, thisObj );
    00812   DOM::CSSRule cssRule = static_cast<DOMCSSRule *>(thisObj.imp())->toCSSRule();
    00813
    00814   if (cssRule.type() == DOM::CSSRule::MEDIA_RULE) {
    00815     DOM::CSSMediaRule rule = static_cast<DOM::CSSMediaRule>(cssRule);
    00816     if (id == DOMCSSRule::Media_InsertRule)
    00817       return Number(rule.insertRule(args[0].toString(exec).string(),args[1].toInteger(exec)));
    00818     else if (id == DOMCSSRule::Media_DeleteRule)
    00819       rule.deleteRule(args[0].toInteger(exec));
    00820   }
    00821
    00822   return Undefined();
    00823 }
    00824
    00825 Value KJS::getDOMCSSRule(ExecState *exec, const DOM::CSSRule& r)
    00826 {
    00827   return cacheDOMObject<DOM::CSSRule, KJS::DOMCSSRule>(exec, r);
    00828 }
    00829
    00830 // -------------------------------------------------------------------------
    00831
    00832
    00833 DOM::CSSRule KJS::toCSSRule(const Value& val)
    00834 {
    00835   Object obj = Object::dynamicCast(val);
    00836   if (obj.isNull() || !obj.inherits(&DOMCSSRule::info))
    00837     return DOM::CSSRule();
    00838
    00839   const DOMCSSRule *dobj = static_cast<const DOMCSSRule*>(obj.imp());
    00840   return dobj->toCSSRule();
    00841 }
    00842
    00843 // -------------------------------------------------------------------------
    00844
    00845 const ClassInfo CSSRuleConstructor::info = { "CSSRuleConstructor", 0, &CSSRuleConstructorTable, 0 };
    00846 /*
    00847 @begin CSSRuleConstructorTable 7
    00848   UNKNOWN_RULE  CSSRuleConstructor::UNKNOWN_RULE        DontDelete|ReadOnly
    00849   STYLE_RULE    CSSRuleConstructor::STYLE_RULE          DontDelete|ReadOnly
    00850   CHARSET_RULE  CSSRuleConstructor::CHARSET_RULE        DontDelete|ReadOnly
    00851   IMPORT_RULE   CSSRuleConstructor::IMPORT_RULE         DontDelete|ReadOnly
    00852   MEDIA_RULE    CSSRuleConstructor::MEDIA_RULE          DontDelete|ReadOnly
    00853   FONT_FACE_RULE CSSRuleConstructor::FONT_FACE_RULE     DontDelete|ReadOnly
    00854   PAGE_RULE     CSSRuleConstructor::PAGE_RULE           DontDelete|ReadOnly
    00855 @end
    00856 */
    00857
    00858 CSSRuleConstructor::CSSRuleConstructor(ExecState *exec)
    00859   : DOMObject(exec->interpreter()->builtinObjectPrototype())
    00860 {
    00861 }
    00862
    00863 Value CSSRuleConstructor::tryGet(ExecState *exec, const UString &p) const
    00864 {
    00865   return DOMObjectLookupGetValue<CSSRuleConstructor,DOMObject>(exec,p,&CSSRuleConstructorTable,this);
    00866 }
    00867
    00868 Value CSSRuleConstructor::getValueProperty(ExecState *, int token) const
    00869 {
    00870   switch (token) {
    00871   case UNKNOWN_RULE:
    00872     return Number(DOM::CSSRule::UNKNOWN_RULE);
    00873   case STYLE_RULE:
    00874     return Number(DOM::CSSRule::STYLE_RULE);
    00875   case CHARSET_RULE:
    00876     return Number(DOM::CSSRule::CHARSET_RULE);
    00877   case IMPORT_RULE:
    00878     return Number(DOM::CSSRule::IMPORT_RULE);
    00879   case MEDIA_RULE:
    00880     return Number(DOM::CSSRule::MEDIA_RULE);
    00881   case FONT_FACE_RULE:
    00882     return Number(DOM::CSSRule::FONT_FACE_RULE);
    00883   case PAGE_RULE:
    00884     return Number(DOM::CSSRule::PAGE_RULE);
    00885   }
    00886   return Value();
    00887 }
    00888
    00889 Value KJS::getCSSRuleConstructor(ExecState *exec)
    00890 {
    00891   return cacheGlobalObject<CSSRuleConstructor>( exec, "[[cssRule.constructor]]" );
    00892 }
    00893
    00894 // -------------------------------------------------------------------------
    00895
    00896 const ClassInfo DOMCSSValue::info = { "CSSValue", 0, &DOMCSSValueTable, 0 };
    00897
    00898 /*
    00899 @begin DOMCSSValueTable 2
    00900   cssText       DOMCSSValue::CssText            DontDelete|ReadOnly
    00901   cssValueType  DOMCSSValue::CssValueType       DontDelete|ReadOnly
    00902 @end
    00903 */
    00904
    00905 DOMCSSValue::DOMCSSValue(ExecState* exec, const DOM::CSSValue& val)
    00906   : DOMObject(exec->interpreter()->builtinObjectPrototype()), cssValue(val)
    00907 {
    00908 }
    00909
    00910 DOMCSSValue::~DOMCSSValue()
    00911 {
    00912   ScriptInterpreter::forgetDOMObject(cssValue.handle());
    00913 }
    00914
    00915 Value DOMCSSValue::tryGet(ExecState *exec, const UString &p) const
    00916 {
    00917   if (p == "cssText")
    00918     return getString(cssValue.cssText());
    00919   else if (p == "cssValueType")
    00920     return Number(cssValue.cssValueType());
    00921   return DOMObject::tryGet(exec,p);
    00922 }
    00923
    00924 void DOMCSSValue::tryPut(ExecState *exec, const UString &propertyName, const Value& value, int attr)
    00925 {
    00926   if (propertyName == "cssText")
    00927     cssValue.setCssText(value.toString(exec).string());
    00928   else
    00929     DOMObject::tryPut(exec, propertyName, value, attr);
    00930 }
    00931
    00932 Value KJS::getDOMCSSValue(ExecState *exec, const DOM::CSSValue& v)
    00933 {
    00934   DOMObject *ret;
    00935   if (v.isNull())
    00936     return Null();
    00937   ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
    00938   if ((ret = interp->getDOMObject(v.handle())))
    00939     return Value(ret);
    00940   else {
    00941     if (v.isCSSValueList())
    00942       ret = new DOMCSSValueList(exec,v);
    00943     else if (v.isCSSPrimitiveValue())
    00944       ret = new DOMCSSPrimitiveValue(exec,v);
    00945     else
    00946       ret = new DOMCSSValue(exec,v);
    00947     interp->putDOMObject(v.handle(),ret);
    00948     return Value(ret);
    00949   }
    00950 }
    00951
    00952 // -------------------------------------------------------------------------
    00953
    00954 const ClassInfo CSSValueConstructor::info = { "CSSValueConstructor", 0, &CSSValueConstructorTable, 0 };
    00955 /*
    00956 @begin CSSValueConstructorTable 5
    00957   CSS_INHERIT           CSSValueConstructor::CSS_INHERIT                DontDelete|ReadOnly
    00958   CSS_PRIMITIVE_VALUE   CSSValueConstructor::CSS_PRIMITIVE_VALUE        DontDelete|ReadOnly
    00959   CSS_VALUE_LIST        CSSValueConstructor::CSS_VALUE_LIST             DontDelete|ReadOnly
    00960   CSS_CUSTOM            CSSValueConstructor::CSS_CUSTOM                 DontDelete|ReadOnly
    00961 @end
    00962 */
    00963
    00964 CSSValueConstructor::CSSValueConstructor(ExecState *exec)
    00965   : DOMObject(exec->interpreter()->builtinObjectPrototype())
    00966 {
    00967 }
    00968
    00969 Value CSSValueConstructor::tryGet(ExecState *exec, const UString &p) const
    00970 {
    00971   return DOMObjectLookupGetValue<CSSValueConstructor,DOMObject>(exec,p,&CSSValueConstructorTable,this);
    00972 }
    00973
    00974 Value CSSValueConstructor::getValueProperty(ExecState *, int token) const
    00975 {
    00976   switch (token) {
    00977   case CSS_INHERIT:
    00978     return Number(DOM::CSSValue::CSS_INHERIT);
    00979   case CSS_PRIMITIVE_VALUE:
    00980     return Number(DOM::CSSValue::CSS_PRIMITIVE_VALUE);
    00981   case CSS_VALUE_LIST:
    00982     return Number(DOM::CSSValue::CSS_VALUE_LIST);
    00983   case CSS_CUSTOM:
    00984     return Number(DOM::CSSValue::CSS_CUSTOM);
    00985   }
    00986   return Value();
    00987 }
    00988
    00989 Value KJS::getCSSValueConstructor(ExecState *exec)
    00990 {
    00991   return cacheGlobalObject<CSSValueConstructor>( exec, "[[cssValue.constructor]]" );
    00992 }
    00993
    00994 // -------------------------------------------------------------------------
    00995
    00996 const ClassInfo DOMCSSPrimitiveValue::info = { "CSSPrimitiveValue", 0, &DOMCSSPrimitiveValueTable, 0 };
    00997 /*
    00998 @begin DOMCSSPrimitiveValueTable 1
    00999   primitiveType         DOMCSSPrimitiveValue::PrimitiveType     DontDelete|ReadOnly
    01000 @end
    01001 @begin DOMCSSPrimitiveValueProtoTable 3
    01002   setFloatValue         DOMCSSPrimitiveValue::SetFloatValue     DontDelete|Function 2
    01003   getFloatValue         DOMCSSPrimitiveValue::GetFloatValue     DontDelete|Function 1
    01004   setStringValue        DOMCSSPrimitiveValue::SetStringValue    DontDelete|Function 2
    01005   getStringValue        DOMCSSPrimitiveValue::GetStringValue    DontDelete|Function 0
    01006   getCounterValue       DOMCSSPrimitiveValue::GetCounterValue   DontDelete|Function 0
    01007   getRectValue          DOMCSSPrimitiveValue::GetRectValue      DontDelete|Function 0
    01008   getRGBColorValue      DOMCSSPrimitiveValue::GetRGBColorValue  DontDelete|Function 0
    01009 @end
    01010 */
    01011 DEFINE_PROTOTYPE("DOMCSSPrimitiveValue",DOMCSSPrimitiveValueProto)
    01012 IMPLEMENT_PROTOFUNC_DOM(DOMCSSPrimitiveValueProtoFunc)
    01013 IMPLEMENT_PROTOTYPE(DOMCSSPrimitiveValueProto,DOMCSSPrimitiveValueProtoFunc)
    01014
    01015 DOMCSSPrimitiveValue::DOMCSSPrimitiveValue(ExecState *exec, const DOM::CSSPrimitiveValue& v)
    01016   : DOMCSSValue(DOMCSSPrimitiveValueProto::self(exec), v) { }
    01017
    01018 Value DOMCSSPrimitiveValue::tryGet(ExecState *exec, const UString &p) const
    01019 {
    01020   if (p=="primitiveType")
    01021     return Number(static_cast<DOM::CSSPrimitiveValue>(cssValue).primitiveType());
    01022   return DOMObject::tryGet(exec,p);
    01023 }
    01024
    01025 Value DOMCSSPrimitiveValueProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    01026 {
    01027   KJS_CHECK_THIS( KJS::DOMCSSPrimitiveValue, thisObj );
    01028   DOM::CSSPrimitiveValue val = static_cast<DOMCSSPrimitiveValue *>(thisObj.imp())->toCSSPrimitiveValue();
    01029   switch (id) {
    01030     case DOMCSSPrimitiveValue::SetFloatValue:
    01031       val.setFloatValue(args[0].toInteger(exec),args[1].toNumber(exec));
    01032       return Undefined();
    01033     case DOMCSSPrimitiveValue::GetFloatValue:
    01034       return Number(val.getFloatValue(args[0].toInteger(exec)));
    01035     case DOMCSSPrimitiveValue::SetStringValue:
    01036       val.setStringValue(args[0].toInteger(exec),args[1].toString(exec).string());
    01037       return Undefined();
    01038     case DOMCSSPrimitiveValue::GetStringValue:
    01039       return getString(val.getStringValue());
    01040     case DOMCSSPrimitiveValue::GetCounterValue:
    01041       return getDOMCounter(exec,val.getCounterValue());
    01042     case DOMCSSPrimitiveValue::GetRectValue:
    01043       return getDOMRect(exec,val.getRectValue());
    01044     case DOMCSSPrimitiveValue::GetRGBColorValue:
    01045       return getDOMRGBColor(exec,val.getRGBColorValue());
    01046     default:
    01047       return Undefined();
    01048   }
    01049 }
    01050
    01051 // -------------------------------------------------------------------------
    01052
    01053 const ClassInfo CSSPrimitiveValueConstructor::info = { "CSSPrimitiveValueConstructor", 0, &CSSPrimitiveValueConstructorTable, 0 };
    01054
    01055 /*
    01056 @begin CSSPrimitiveValueConstructorTable 27
    01057   CSS_UNKNOWN           DOM::CSSPrimitiveValue::CSS_UNKNOWN     DontDelete|ReadOnly
    01058   CSS_NUMBER            DOM::CSSPrimitiveValue::CSS_NUMBER      DontDelete|ReadOnly
    01059   CSS_PERCENTAGE        DOM::CSSPrimitiveValue::CSS_PERCENTAGE  DontDelete|ReadOnly
    01060   CSS_EMS               DOM::CSSPrimitiveValue::CSS_EMS         DontDelete|ReadOnly
    01061   CSS_EXS               DOM::CSSPrimitiveValue::CSS_EXS         DontDelete|ReadOnly
    01062   CSS_PX                DOM::CSSPrimitiveValue::CSS_PX          DontDelete|ReadOnly
    01063   CSS_CM                DOM::CSSPrimitiveValue::CSS_CM          DontDelete|ReadOnly
    01064   CSS_MM                DOM::CSSPrimitiveValue::CSS_MM          DontDelete|ReadOnly
    01065   CSS_IN                DOM::CSSPrimitiveValue::CSS_IN          DontDelete|ReadOnly
    01066   CSS_PT                DOM::CSSPrimitiveValue::CSS_PT          DontDelete|ReadOnly
    01067   CSS_PC                DOM::CSSPrimitiveValue::CSS_PC          DontDelete|ReadOnly
    01068   CSS_DEG               DOM::CSSPrimitiveValue::CSS_DEG         DontDelete|ReadOnly
    01069   CSS_RAD               DOM::CSSPrimitiveValue::CSS_RAD         DontDelete|ReadOnly
    01070   CSS_GRAD              DOM::CSSPrimitiveValue::CSS_GRAD        DontDelete|ReadOnly
    01071   CSS_MS                DOM::CSSPrimitiveValue::CSS_MS          DontDelete|ReadOnly
    01072   CSS_S                 DOM::CSSPrimitiveValue::CSS_S           DontDelete|ReadOnly
    01073   CSS_HZ                DOM::CSSPrimitiveValue::CSS_HZ          DontDelete|ReadOnly
    01074   CSS_KHZ               DOM::CSSPrimitiveValue::CSS_KHZ         DontDelete|ReadOnly
    01075   CSS_DIMENSION         DOM::CSSPrimitiveValue::CSS_DIMENSION   DontDelete|ReadOnly
    01076   CSS_STRING            DOM::CSSPrimitiveValue::CSS_STRING      DontDelete|ReadOnly
    01077   CSS_URI               DOM::CSSPrimitiveValue::CSS_URI         DontDelete|ReadOnly
    01078   CSS_IDENT             DOM::CSSPrimitiveValue::CSS_IDENT       DontDelete|ReadOnly
    01079   CSS_ATTR              DOM::CSSPrimitiveValue::CSS_ATTR        DontDelete|ReadOnly
    01080   CSS_COUNTER           DOM::CSSPrimitiveValue::CSS_COUNTER     DontDelete|ReadOnly
    01081   CSS_RECT              DOM::CSSPrimitiveValue::CSS_RECT        DontDelete|ReadOnly
    01082   CSS_RGBCOLOR          DOM::CSSPrimitiveValue::CSS_RGBCOLOR    DontDelete|ReadOnly
    01083 @end
    01084 */
    01085
    01086 Value CSSPrimitiveValueConstructor::tryGet(ExecState *exec, const UString &p) const
    01087 {
    01088   return DOMObjectLookupGetValue<CSSPrimitiveValueConstructor,CSSValueConstructor>(exec,p,&CSSPrimitiveValueConstructorTable,this);
    01089 }
    01090
    01091 Value CSSPrimitiveValueConstructor::getValueProperty(ExecState *, int token) const
    01092 {
    01093   // We use the token as the value to return directly
    01094   return Number(token);
    01095 }
    01096
    01097 Value KJS::getCSSPrimitiveValueConstructor(ExecState *exec)
    01098 {
    01099   return cacheGlobalObject<CSSPrimitiveValueConstructor>( exec, "[[cssPrimitiveValue.constructor]]" );
    01100 }
    01101
    01102 // -------------------------------------------------------------------------
    01103
    01104 const ClassInfo DOMCSSValueList::info = { "CSSValueList", 0, &DOMCSSValueListTable, 0 };
    01105
    01106 /*
    01107 @begin DOMCSSValueListTable 3
    01108   length                DOMCSSValueList::Length         DontDelete|ReadOnly
    01109   item                  DOMCSSValueList::Item           DontDelete|Function 1
    01110 @end
    01111 */
    01112 IMPLEMENT_PROTOFUNC_DOM(DOMCSSValueListFunc) // not really a proto, but doesn't matter
    01113
    01114 DOMCSSValueList::DOMCSSValueList(ExecState *exec, const DOM::CSSValueList& v)
    01115   : DOMCSSValue(exec, v) { }
    01116
    01117 Value DOMCSSValueList::tryGet(ExecState *exec, const UString &p) const
    01118 {
    01119   Value result;
    01120   DOM::CSSValueList valueList = static_cast<DOM::CSSValueList>(cssValue);
    01121
    01122   if (p == "length")
    01123     return Number(valueList.length());
    01124   else if (p == "item")
    01125     return lookupOrCreateFunction<DOMCSSValueListFunc>(exec,p,this,DOMCSSValueList::Item,1,DontDelete|Function);
    01126
    01127   bool ok;
    01128   long unsigned int u = p.toULong(&ok);
    01129   if (ok)
    01130     return getDOMCSSValue(exec,valueList.item(u));
    01131
    01132   return DOMCSSValue::tryGet(exec,p);
    01133 }
    01134
    01135 Value DOMCSSValueListFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    01136 {
    01137   KJS_CHECK_THIS( KJS::DOMCSSValueList, thisObj );
    01138   DOM::CSSValueList valueList = static_cast<DOMCSSValueList *>(thisObj.imp())->toValueList();
    01139   switch (id) {
    01140     case DOMCSSValueList::Item:
    01141       return getDOMCSSValue(exec,valueList.item(args[0].toInteger(exec)));
    01142     default:
    01143       return Undefined();
    01144   }
    01145 }
    01146
    01147 // -------------------------------------------------------------------------
    01148
    01149 const ClassInfo DOMRGBColor::info = { "RGBColor", 0, &DOMRGBColorTable, 0 };
    01150
    01151 /*
    01152 @begin DOMRGBColorTable 3
    01153   red   DOMRGBColor::Red        DontDelete|ReadOnly
    01154   green DOMRGBColor::Green      DontDelete|ReadOnly
    01155   blue  DOMRGBColor::Blue       DontDelete|ReadOnly
    01156 @end
    01157 */
    01158
    01159 DOMRGBColor::DOMRGBColor(ExecState* exec, const DOM::RGBColor& c)
    01160   : DOMObject(exec->interpreter()->builtinObjectPrototype()), rgbColor(c)
    01161 {
    01162 }
    01163
    01164 DOMRGBColor::~DOMRGBColor()
    01165 {
    01166   //rgbColors.remove(rgbColor.handle());
    01167 }
    01168
    01169 Value DOMRGBColor::tryGet(ExecState *exec, const UString &p) const
    01170 {
    01171   return DOMObjectLookupGetValue<DOMRGBColor,DOMObject>(exec, p,
    01172                                                        &DOMRGBColorTable,
    01173                                                        this);
    01174 }
    01175
    01176 Value DOMRGBColor::getValueProperty(ExecState *exec, int token) const
    01177 {
    01178   switch (token) {
    01179   case Red:
    01180     return getDOMCSSValue(exec, rgbColor.red());
    01181   case Green:
    01182     return getDOMCSSValue(exec, rgbColor.green());
    01183   case Blue:
    01184     return getDOMCSSValue(exec, rgbColor.blue());
    01185   default:
    01186     return Value();
    01187   }
    01188 }
    01189
    01190 Value KJS::getDOMRGBColor(ExecState *exec, const DOM::RGBColor& c)
    01191 {
    01192   // ### implement equals for RGBColor since they're not refcounted objects
    01193   return Value(new DOMRGBColor(exec, c));
    01194 }
    01195
    01196 // -------------------------------------------------------------------------
    01197
    01198 const ClassInfo DOMRect::info = { "Rect", 0, &DOMRectTable, 0 };
    01199 /*
    01200 @begin DOMRectTable 4
    01201   top   DOMRect::Top    DontDelete|ReadOnly
    01202   right DOMRect::Right  DontDelete|ReadOnly
    01203   bottom DOMRect::Bottom DontDelete|ReadOnly
    01204   left  DOMRect::Left   DontDelete|ReadOnly
    01205 @end
    01206 */
    01207
    01208 DOMRect::DOMRect(ExecState *exec, const DOM::Rect& r)
    01209   : DOMObject(exec->interpreter()->builtinObjectPrototype()), rect(r)
    01210 {
    01211 }
    01212
    01213 DOMRect::~DOMRect()
    01214 {
    01215   ScriptInterpreter::forgetDOMObject(rect.handle());
    01216 }
    01217
    01218 Value DOMRect::tryGet(ExecState *exec, const UString &p) const
    01219 {
    01220   return DOMObjectLookupGetValue<DOMRect,DOMObject>(exec, p,
    01221                                                     &DOMRectTable, this);
    01222 }
    01223
    01224 Value DOMRect::getValueProperty(ExecState *exec, int token) const
    01225 {
    01226   switch (token) {
    01227   case Top:
    01228     return getDOMCSSValue(exec, rect.top());
    01229   case Right:
    01230     return getDOMCSSValue(exec, rect.right());
    01231   case Bottom:
    01232     return getDOMCSSValue(exec, rect.bottom());
    01233   case Left:
    01234     return getDOMCSSValue(exec, rect.left());
    01235   default:
    01236     return Value();
    01237   }
    01238 }
    01239
    01240 Value KJS::getDOMRect(ExecState *exec, const DOM::Rect& r)
    01241 {
    01242   return cacheDOMObject<DOM::Rect, KJS::DOMRect>(exec, r);
    01243 }
    01244
    01245 // -------------------------------------------------------------------------
    01246
    01247 const ClassInfo DOMCounter::info = { "Counter", 0, &DOMCounterTable, 0 };
    01248 /*
    01249 @begin DOMCounterTable 3
    01250   identifier    DOMCounter::_Identifier DontDelete|ReadOnly
    01251   listStyle     DOMCounter::ListStyle   DontDelete|ReadOnly
    01252   separator     DOMCounter::Separator   DontDelete|ReadOnly
    01253 @end
    01254 */
    01255 DOMCounter::DOMCounter(ExecState *exec, const DOM::Counter& c)
    01256   : DOMObject(exec->interpreter()->builtinObjectPrototype()), counter(c)
    01257 {
    01258 }
    01259
    01260 DOMCounter::~DOMCounter()
    01261 {
    01262   ScriptInterpreter::forgetDOMObject(counter.handle());
    01263 }
    01264
    01265 Value DOMCounter::tryGet(ExecState *exec, const UString &p) const
    01266 {
    01267   return DOMObjectLookupGetValue<DOMCounter,DOMObject>(exec, p,
    01268                                                        &DOMCounterTable, this);
    01269 }
    01270
    01271 Value DOMCounter::getValueProperty(ExecState *, int token) const
    01272 {
    01273   switch (token) {
    01274   case _Identifier:
    01275     return getString(counter.identifier());
    01276   case ListStyle:
    01277     return getString(counter.listStyle());
    01278   case Separator:
    01279     return getString(counter.separator());
    01280   default:
    01281     return Value();
    01282   }
    01283 }
    01284
    01285 Value KJS::getDOMCounter(ExecState *exec, const DOM::Counter& c)
    01286 {
    01287   return cacheDOMObject<DOM::Counter, KJS::DOMCounter>(exec, c);
    01288 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:12 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001