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