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

This file is part of the documentation for khtml Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:33:17 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003