📄 kjs_css.cpp
字号:
deleteMedium DOMMediaList::DeleteMedium DontDelete|Function 1 appendMedium DOMMediaList::AppendMedium DontDelete|Function 1@end*/DEFINE_PROTOTYPE("DOMMediaList", DOMMediaListProto)IMPLEMENT_PROTOFUNC(DOMMediaListProtoFunc)IMPLEMENT_PROTOTYPE(DOMMediaListProto, DOMMediaListProtoFunc)DOMMediaList::DOMMediaList(ExecState *exec, DOM::MediaList ml) : DOMObject(DOMMediaListProto::self(exec)), mediaList(ml) { }DOMMediaList::~DOMMediaList(){ ScriptInterpreter::forgetDOMObject(mediaList.handle());}Value DOMMediaList::tryGet(ExecState *exec, const Identifier &p) const{ if (p == "mediaText") return getStringOrNull(mediaList.mediaText()); else if (p == lengthPropertyName) return Number(mediaList.length()); bool ok; long unsigned int u = p.toULong(&ok); if (ok) return getStringOrNull(mediaList.item(u)); return DOMObject::tryGet(exec, p);}void DOMMediaList::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr){ if (propertyName == "mediaText") mediaList.setMediaText(value.toString(exec).string()); else DOMObject::tryPut(exec, propertyName, value, attr);}Value KJS::getDOMMediaList(ExecState *exec, DOM::MediaList ml){ return cacheDOMObject<DOM::MediaList, KJS::DOMMediaList>(exec, ml);}Value KJS::DOMMediaListProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ if (!thisObj.inherits(&KJS::DOMMediaList::info)) { Object err = Error::create(exec,TypeError); exec->setException(err); return err; } DOM::MediaList mediaList = static_cast<DOMMediaList *>(thisObj.imp())->toMediaList(); switch (id) { case DOMMediaList::Item: return getStringOrNull(mediaList.item(args[0].toInt32(exec))); case DOMMediaList::DeleteMedium: mediaList.deleteMedium(args[0].toString(exec).string()); return Undefined(); case DOMMediaList::AppendMedium: mediaList.appendMedium(args[0].toString(exec).string()); return Undefined(); default: return Undefined(); }}// -------------------------------------------------------------------------const ClassInfo DOMCSSStyleSheet::info = { "CSSStyleSheet", 0, &DOMCSSStyleSheetTable, 0 };/*@begin DOMCSSStyleSheetTable 5 ownerRule DOMCSSStyleSheet::OwnerRule DontDelete|ReadOnly cssRules DOMCSSStyleSheet::CssRules DontDelete|ReadOnly# MSIE extension rules DOMCSSStyleSheet::Rules DontDelete|ReadOnly@end@begin DOMCSSStyleSheetProtoTable 6 insertRule DOMCSSStyleSheet::InsertRule DontDelete|Function 2 deleteRule DOMCSSStyleSheet::DeleteRule DontDelete|Function 1# MSIE extension addRule DOMCSSStyleSheet::AddRule DontDelete|Function 2@end*/DEFINE_PROTOTYPE("DOMCSSStyleSheet",DOMCSSStyleSheetProto)IMPLEMENT_PROTOFUNC(DOMCSSStyleSheetProtoFunc)IMPLEMENT_PROTOTYPE(DOMCSSStyleSheetProto,DOMCSSStyleSheetProtoFunc) // warning, use _WITH_PARENT if DOMStyleSheet gets a protoDOMCSSStyleSheet::DOMCSSStyleSheet(ExecState *exec, DOM::CSSStyleSheet ss) : DOMStyleSheet(DOMCSSStyleSheetProto::self(exec),ss) { }DOMCSSStyleSheet::~DOMCSSStyleSheet(){}Value DOMCSSStyleSheet::tryGet(ExecState *exec, const Identifier &p) const{ DOM::CSSStyleSheet cssStyleSheet = static_cast<DOM::CSSStyleSheet>(styleSheet); if (p == "ownerRule") return getDOMCSSRule(exec,cssStyleSheet.ownerRule()); else if (p == "cssRules" || p == "rules" /* MSIE extension */) return getDOMCSSRuleList(exec,cssStyleSheet.cssRules()); return DOMStyleSheet::tryGet(exec,p);}Value DOMCSSStyleSheetProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ if (!thisObj.inherits(&KJS::DOMCSSStyleSheet::info)) { Object err = Error::create(exec,TypeError); exec->setException(err); return err; } DOM::CSSStyleSheet styleSheet = static_cast<DOMCSSStyleSheet *>(thisObj.imp())->toCSSStyleSheet(); Value result; switch (id) { case DOMCSSStyleSheet::InsertRule: return Number(styleSheet.insertRule(args[0].toString(exec).string(),(long unsigned int)args[1].toInt32(exec))); break; case DOMCSSStyleSheet::DeleteRule: styleSheet.deleteRule(args[0].toInt32(exec)); return Undefined(); case DOMCSSStyleSheet::AddRule: { long index = args.size() >= 3 ? args[2].toInt32(exec) : -1; styleSheet.addRule(args[0].toString(exec).string(), args[1].toString(exec).string(), index); // As per Microsoft documentation, always return -1. return Number(-1); } } return Undefined();}// -------------------------------------------------------------------------const ClassInfo DOMCSSRuleList::info = { "CSSRuleList", 0, &DOMCSSRuleListTable, 0 };/*@begin DOMCSSRuleListTable 3 length DOMCSSRuleList::Length DontDelete|ReadOnly item DOMCSSRuleList::Item DontDelete|Function 1@end*/IMPLEMENT_PROTOFUNC(DOMCSSRuleListFunc) // not really a proto, but doesn't matterDOMCSSRuleList::~DOMCSSRuleList(){ ScriptInterpreter::forgetDOMObject(cssRuleList.handle());}Value DOMCSSRuleList::tryGet(ExecState *exec, const Identifier &p) const{ Value result; if (p == lengthPropertyName) return Number(cssRuleList.length()); else if (p == "item") return lookupOrCreateFunction<DOMCSSRuleListFunc>(exec,p,this,DOMCSSRuleList::Item,1,DontDelete|Function); bool ok; long unsigned int u = p.toULong(&ok); if (ok) return getDOMCSSRule(exec,DOM::CSSRuleList(cssRuleList).item(u)); return DOMObject::tryGet(exec,p);}Value DOMCSSRuleListFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ if (!thisObj.inherits(&KJS::DOMCSSRuleList::info)) { Object err = Error::create(exec,TypeError); exec->setException(err); return err; } DOM::CSSRuleList cssRuleList = static_cast<DOMCSSRuleList *>(thisObj.imp())->toCSSRuleList(); switch (id) { case DOMCSSRuleList::Item: return getDOMCSSRule(exec,cssRuleList.item(args[0].toInt32(exec))); default: return Undefined(); }}Value KJS::getDOMCSSRuleList(ExecState *exec, DOM::CSSRuleList rl){ return cacheDOMObject<DOM::CSSRuleList, KJS::DOMCSSRuleList>(exec, rl);}// -------------------------------------------------------------------------IMPLEMENT_PROTOFUNC(DOMCSSRuleFunc) // Not a proto, but doesn't matterDOMCSSRule::~DOMCSSRule(){ ScriptInterpreter::forgetDOMObject(cssRule.handle());}const ClassInfo DOMCSSRule::info = { "CSSRule", 0, &DOMCSSRuleTable, 0 };const ClassInfo DOMCSSRule::style_info = { "CSSStyleRule", &DOMCSSRule::info, &DOMCSSStyleRuleTable, 0 };const ClassInfo DOMCSSRule::media_info = { "CSSMediaRule", &DOMCSSRule::info, &DOMCSSMediaRuleTable, 0 };const ClassInfo DOMCSSRule::fontface_info = { "CSSFontFaceRule", &DOMCSSRule::info, &DOMCSSFontFaceRuleTable, 0 };const ClassInfo DOMCSSRule::page_info = { "CSSPageRule", &DOMCSSRule::info, &DOMCSSPageRuleTable, 0 };const ClassInfo DOMCSSRule::import_info = { "CSSImportRule", &DOMCSSRule::info, &DOMCSSImportRuleTable, 0 };const ClassInfo DOMCSSRule::charset_info = { "CSSCharsetRule", &DOMCSSRule::info, &DOMCSSCharsetRuleTable, 0 };const ClassInfo* DOMCSSRule::classInfo() const{ switch (cssRule.type()) { case DOM::CSSRule::STYLE_RULE: return &style_info; case DOM::CSSRule::MEDIA_RULE: return &media_info; case DOM::CSSRule::FONT_FACE_RULE: return &fontface_info; case DOM::CSSRule::PAGE_RULE: return &page_info; case DOM::CSSRule::IMPORT_RULE: return &import_info; case DOM::CSSRule::CHARSET_RULE: return &charset_info; case DOM::CSSRule::UNKNOWN_RULE: default: return &info; }}/*@begin DOMCSSRuleTable 4 type DOMCSSRule::Type DontDelete|ReadOnly cssText DOMCSSRule::CssText DontDelete|ReadOnly parentStyleSheet DOMCSSRule::ParentStyleSheet DontDelete|ReadOnly parentRule DOMCSSRule::ParentRule DontDelete|ReadOnly@end@begin DOMCSSStyleRuleTable 2 selectorText DOMCSSRule::Style_SelectorText DontDelete style DOMCSSRule::Style_Style DontDelete|ReadOnly@end@begin DOMCSSMediaRuleTable 4 media DOMCSSRule::Media_Media DontDelete|ReadOnly cssRules DOMCSSRule::Media_CssRules DontDelete|ReadOnly insertRule DOMCSSRule::Media_InsertRule DontDelete|Function 2 deleteRule DOMCSSRule::Media_DeleteRule DontDelete|Function 1@end@begin DOMCSSFontFaceRuleTable 1 style DOMCSSRule::FontFace_Style DontDelete|ReadOnly@end@begin DOMCSSPageRuleTable 2 selectorText DOMCSSRule::Page_SelectorText DontDelete style DOMCSSRule::Page_Style DontDelete|ReadOnly@end@begin DOMCSSImportRuleTable 3 href DOMCSSRule::Import_Href DontDelete|ReadOnly media DOMCSSRule::Import_Media DontDelete|ReadOnly styleSheet DOMCSSRule::Import_StyleSheet DontDelete|ReadOnly@end@begin DOMCSSCharsetRuleTable 1 encoding DOMCSSRule::Charset_Encoding DontDelete@end*/Value DOMCSSRule::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE kdDebug(6070) << "DOMCSSRule::tryGet " << propertyName.qstring() << endl;#endif const HashTable* table = classInfo()->propHashTable; // get the right hashtable const HashEntry* entry = Lookup::findEntry(table, propertyName); if (entry) { if (entry->attr & Function) return lookupOrCreateFunction<DOMCSSRuleFunc>(exec, propertyName, this, entry->value, entry->params, entry->attr); return getValueProperty(exec, entry->value); } // Base CSSRule stuff or parent class forward, as usual return DOMObjectLookupGet<DOMCSSRuleFunc, DOMCSSRule, DOMObject>(exec, propertyName, &DOMCSSRuleTable, this);}Value DOMCSSRule::getValueProperty(ExecState *exec, int token) const{ switch (token) { case Type: return Number(cssRule.type()); case CssText: return getStringOrNull(cssRule.cssText()); case ParentStyleSheet: return getDOMStyleSheet(exec,cssRule.parentStyleSheet()); case ParentRule: return getDOMCSSRule(exec,cssRule.parentRule()); // for DOM::CSSRule::STYLE_RULE: case Style_SelectorText: return getStringOrNull(static_cast<DOM::CSSStyleRule>(cssRule).selectorText()); case Style_Style: return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSStyleRule>(cssRule).style()); // for DOM::CSSRule::MEDIA_RULE: case Media_Media: return getDOMMediaList(exec,static_cast<DOM::CSSMediaRule>(cssRule).media()); case Media_CssRules: return getDOMCSSRuleList(exec,static_cast<DOM::CSSMediaRule>(cssRule).cssRules()); // for DOM::CSSRule::FONT_FACE_RULE: case FontFace_Style: return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSFontFaceRule>(cssRule).style()); // for DOM::CSSRule::PAGE_RULE: case Page_SelectorText: return getStringOrNull(static_cast<DOM::CSSPageRule>(cssRule).selectorText()); case Page_Style: return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSPageRule>(cssRule).style()); // for DOM::CSSRule::IMPORT_RULE: case Import_Href: return getStringOrNull(static_cast<DOM::CSSImportRule>(cssRule).href()); case Import_Media: return getDOMMediaList(exec,static_cast<DOM::CSSImportRule>(cssRule).media()); case Import_StyleSheet: return getDOMStyleSheet(exec,static_cast<DOM::CSSImportRule>(cssRule).styleSheet()); // for DOM::CSSRule::CHARSET_RULE: case Charset_Encoding: return getStringOrNull(static_cast<DOM::CSSCharsetRule>(cssRule).encoding()); default: kdWarning() << "DOMCSSRule::getValueProperty unhandled token " << token << endl; } return Undefined();}void DOMCSSRule::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr){ const HashTable* table = classInfo()->propHashTable; // get the right hashtable const HashEntry* entry = Lookup::findEntry(table, propertyName); if (entry) { if (entry->attr & Function) // function: put as override property { ObjectImp::put(exec, propertyName, value, attr); return; } else if ((entry->attr & ReadOnly) == 0) // let DOMObjectLookupPut print the warning if not { putValue(exec, entry->value, value, attr); return; } } DOMObjectLookupPut<DOMCSSRule, DOMObject>(exec, propertyName, value, attr, &DOMCSSRuleTable, this);}void DOMCSSRule::putValue(ExecState *exec, int token, const Value& value, int){ switch (token) { // for DOM::CSSRule::STYLE_RULE: case Style_SelectorText: static_cast<DOM::CSSStyleRule>(cssRule).setSelectorText(value.toString(exec).string()); return; // for DOM::CSSRule::PAGE_RULE: case Page_SelectorText: static_cast<DOM::CSSPageRule>(cssRule).setSelectorText(value.toString(exec).string()); return; // for DOM::CSSRule::CHARSET_RULE: case Charset_Encoding: static_cast<DOM::CSSCharsetRule>(cssRule).setEncoding(value.toString(exec).string()); return; default: kdWarning() << "DOMCSSRule::putValue unhandled token " << token << endl; }}Value DOMCSSRuleFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){ if (!thisObj.inherits(&KJS::DOMCSSRule::info)) { Object err = Error::create(exec,TypeError); exec->setException(err); return err; } DOM::CSSRule cssRule = static_cast<DOMCSSRule *>(thisObj.imp())->toCSSRule(); if (cssRule.type() == DOM::CSSRule::MEDIA_RULE) { DOM::CSSMediaRule rule = static_cast<DOM::CSSMediaRule>(cssRule); if (id == DOMCSSRule::Media_InsertRule) return Number(rule.insertRule(args[0].toString(exec).string(),args[1].toInt32(exec))); else if (id == DOMCSSRule::Media_DeleteRule) rule.deleteRule(args[0].toInt32(exec)); } return Undefined();}Value KJS::getDOMCSSRule(ExecState *exec, DOM::CSSRule r){ return cacheDOMObject<DOM::CSSRule, KJS::DOMCSSRule>(exec, r);}// -------------------------------------------------------------------------DOM::CSSRule KJS::toCSSRule(const Value& val){ Object obj = Object::dynamicCast(val); if (obj.isNull() || !obj.inherits(&DOMCSSRule::info)) return DOM::CSSRule(); const DOMCSSRule *dobj = static_cast<const DOMCSSRule*>(obj.imp()); return dobj->toCSSRule();}// -------------------------------------------------------------------------const ClassInfo CSSRuleConstructor::info = { "CSSRuleConstructor", 0, &CSSRuleConstructorTable, 0 };/*@begin CSSRuleConstructorTable 7 UNKNOWN_RULE CSSRuleConstructor::UNKNOWN_RULE DontDelete|ReadOnly STYLE_RULE CSSRuleConstructor::STYLE_RULE DontDelete|ReadOnly CHARSET_RULE CSSRuleConstructor::CHARSET_RULE DontDelete|ReadOnly IMPORT_RULE CSSRuleConstructor::IMPORT_RULE DontDelete|ReadOnly
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -