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