#include "kjs_css.h"
#include "kjs_css.lut.h"
#include <dom/html_head.h> // for HTMLStyleElement
#include <css/css_base.h>
#include "kjs_dom.h"
using namespace KJS;
#include <kdebug.h>
static QString cssPropertyName(const Identifier &p, bool *hadPixelOrPosPrefix = 0)
{
QString prop = p.qstring();
int i = prop.length();
while (--i) {
char c = prop[i].latin1();
if (c >= 'A' && c <= 'Z')
prop.insert(i, '-');
}
prop = prop.lower();
if (hadPixelOrPosPrefix)
*hadPixelOrPosPrefix = false;
if (prop.startsWith("css-")) {
prop = prop.mid(4);
} else if (prop.startsWith("pixel-")) {
prop = prop.mid(6);
if (hadPixelOrPosPrefix)
*hadPixelOrPosPrefix = true;
} else if (prop.startsWith("pos-")) {
prop = prop.mid(4);
if (hadPixelOrPosPrefix)
*hadPixelOrPosPrefix = true;
} else if (prop.startsWith("khtml-") || prop.startsWith("apple-")) {
prop.insert(0, '-');
}
return prop;
}
DEFINE_PROTOTYPE("DOMCSSStyleDeclaration", DOMCSSStyleDeclarationProto)
IMPLEMENT_PROTOFUNC(DOMCSSStyleDeclarationProtoFunc)
IMPLEMENT_PROTOTYPE(DOMCSSStyleDeclarationProto, DOMCSSStyleDeclarationProtoFunc)
const ClassInfo DOMCSSStyleDeclaration::info = { "CSSStyleDeclaration", 0, &DOMCSSStyleDeclarationTable, 0 };
DOMCSSStyleDeclaration::DOMCSSStyleDeclaration(ExecState *exec, DOM::CSSStyleDeclaration s)
: styleDecl(s)
{
setPrototype(DOMCSSStyleDeclarationProto::self(exec));
}
DOMCSSStyleDeclaration::~DOMCSSStyleDeclaration()
{
ScriptInterpreter::forgetDOMObject(styleDecl.handle());
}
bool DOMCSSStyleDeclaration::hasOwnProperty(ExecState *exec, const Identifier &p) const
{
if (p == "cssText")
return true;
QString prop = cssPropertyName(p);
if (DOM::getPropertyID(prop.ascii(), prop.length()))
return true;
return ObjectImp::hasOwnProperty(exec, p);
}
Value DOMCSSStyleDeclaration::tryGet(ExecState *exec, const Identifier &propertyName) const
{
#ifdef KJS_VERBOSE
kdDebug(6070) << "DOMCSSStyleDeclaration::tryGet " << propertyName.qstring() << endl;
#endif
const HashEntry* entry = Lookup::findEntry(&DOMCSSStyleDeclarationTable, propertyName);
if (entry)
switch (entry->value) {
case CssText:
return getStringOrNull(styleDecl.cssText());
case Length:
return Number(styleDecl.length());
case ParentRule:
return getDOMCSSRule(exec,styleDecl.parentRule());
default:
break;
}
Object proto = Object::dynamicCast(prototype());
if (!proto.isNull() && proto.hasProperty(exec,propertyName))
return proto.get(exec,propertyName);
bool ok;
long unsigned int u = propertyName.toULong(&ok);
if (ok)
return getStringOrNull(DOM::CSSStyleDeclaration(styleDecl).item(u));
#ifdef KJS_VERBOSE
kdDebug(6070) << "DOMCSSStyleDeclaration: converting to css property name: " << cssPropertyName(propertyName) << endl;
#endif
DOM::CSSStyleDeclaration styleDecl2 = styleDecl;
bool pixelOrPos;
DOM::DOMString p = cssPropertyName(propertyName, &pixelOrPos);
DOM::CSSValue v = styleDecl2.getPropertyCSSValue(p);
if (!v.isNull()) {
if (pixelOrPos && v.cssValueType() == DOM::CSSValue::CSS_PRIMITIVE_VALUE)
return Number(static_cast<DOM::CSSPrimitiveValue>(v).getFloatValue(DOM::CSSPrimitiveValue::CSS_PX));
return getStringOrNull(v.cssText());
}
QCString prop = p.string().latin1();
if (DOM::getPropertyID(prop.data(), prop.length()))
return getStringOrNull(DOM::DOMString(""));
return DOMObject::tryGet(exec, propertyName);
}
void DOMCSSStyleDeclaration::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr )
{
#ifdef KJS_VERBOSE
kdDebug(6070) << "DOMCSSStyleDeclaration::tryPut " << propertyName.qstring() << endl;
#endif
if (propertyName == "cssText") {
styleDecl.setCssText(value.toString(exec).string());
} else {
bool pixelOrPos;
QString prop = cssPropertyName(propertyName, &pixelOrPos);
if (prop.isAllASCII() && DOM::getPropertyID(prop.ascii(), prop.length())) {
QString propvalue = value.toString(exec).qstring();
if (pixelOrPos)
propvalue += "px";
#ifdef KJS_VERBOSE
kdDebug(6070) << "DOMCSSStyleDeclaration: prop=" << prop << " propvalue=" << propvalue << endl;
#endif
styleDecl.removeProperty(prop);
if(!propvalue.isEmpty())
styleDecl.setProperty(prop,DOM::DOMString(propvalue),""); } else {
DOMObject::tryPut(exec, propertyName, value, attr);
}
}
}
Value DOMCSSStyleDeclarationProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
if (!thisObj.inherits(&KJS::DOMCSSStyleDeclaration::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
DOM::CSSStyleDeclaration styleDecl = static_cast<DOMCSSStyleDeclaration *>(thisObj.imp())->toStyleDecl();
String str = args[0].toString(exec);
DOM::DOMString s = str.value().string();
switch (id) {
case DOMCSSStyleDeclaration::GetPropertyValue:
return getStringOrNull(styleDecl.getPropertyValue(s));
case DOMCSSStyleDeclaration::GetPropertyCSSValue:
return getDOMCSSValue(exec,styleDecl.getPropertyCSSValue(s));
case DOMCSSStyleDeclaration::RemoveProperty:
return getStringOrNull(styleDecl.removeProperty(s));
case DOMCSSStyleDeclaration::GetPropertyPriority:
return getStringOrNull(styleDecl.getPropertyPriority(s));
case DOMCSSStyleDeclaration::SetProperty:
styleDecl.setProperty(args[0].toString(exec).string(),
args[1].toString(exec).string(),
args[2].toString(exec).string());
return Undefined();
case DOMCSSStyleDeclaration::Item:
return getStringOrNull(styleDecl.item(args[0].toInt32(exec)));
default:
return Undefined();
}
}
Value KJS::getDOMCSSStyleDeclaration(ExecState *exec, DOM::CSSStyleDeclaration s)
{
return Value(cacheDOMObject<DOM::CSSStyleDeclaration, KJS::DOMCSSStyleDeclaration>(exec, s));
}
const ClassInfo DOMStyleSheet::info = { "StyleSheet", 0, &DOMStyleSheetTable, 0 };
DOMStyleSheet::~DOMStyleSheet()
{
ScriptInterpreter::forgetDOMObject(styleSheet.handle());
}
Value DOMStyleSheet::tryGet(ExecState *exec, const Identifier &propertyName) const
{
return DOMObjectLookupGetValue<DOMStyleSheet,DOMObject>(exec,propertyName,&DOMStyleSheetTable,this);
}
Value DOMStyleSheet::getValueProperty(ExecState *exec, int token) const
{
switch (token) {
case Type:
return getStringOrNull(styleSheet.type());
case Disabled:
return Boolean(styleSheet.disabled());
case OwnerNode:
return getDOMNode(exec,styleSheet.ownerNode());
case ParentStyleSheet:
return getDOMStyleSheet(exec,styleSheet.parentStyleSheet());
case Href:
return getStringOrNull(styleSheet.href());
case Title:
return getStringOrNull(styleSheet.title());
case Media:
return getDOMMediaList(exec, styleSheet.media());
}
return Value();
}
void DOMStyleSheet::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
{
if (propertyName == "disabled") {
styleSheet.setDisabled(value.toBoolean(exec));
}
else
DOMObject::tryPut(exec, propertyName, value, attr);
}
Value KJS::getDOMStyleSheet(ExecState *exec, DOM::StyleSheet ss)
{
DOMObject *ret;
if (ss.isNull())
return Null();
ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter());
if ((ret = interp->getDOMObject(ss.handle())))
return Value(ret);
else {
if (ss.isCSSStyleSheet()) {
DOM::CSSStyleSheet cs;
cs = ss;
ret = new DOMCSSStyleSheet(exec,cs);
}
else
ret = new DOMStyleSheet(exec,ss);
interp->putDOMObject(ss.handle(),ret);
return Value(ret);
}
}
const ClassInfo DOMStyleSheetList::info = { "StyleSheetList", 0, &DOMStyleSheetListTable, 0 };
IMPLEMENT_PROTOFUNC(DOMStyleSheetListFunc)
DOMStyleSheetList::~DOMStyleSheetList()
{
ScriptInterpreter::forgetDOMObject(styleSheetList.handle());
}
Value DOMStyleSheetList::tryGet(ExecState *exec, const Identifier &p) const
{
#ifdef KJS_VERBOSE
kdDebug(6070) << "DOMStyleSheetList::tryGet " << p.qstring() << endl;
#endif
if (p == lengthPropertyName)
return Number(styleSheetList.length());
else if (p == "item")
return lookupOrCreateFunction<DOMStyleSheetListFunc>(exec,p,this,DOMStyleSheetList::Item,1,DontDelete|Function);
bool ok;
long unsigned int u = p.toULong(&ok);
if (ok)
return getDOMStyleSheet(exec, DOM::StyleSheetList(styleSheetList).item(u));
#if 0
DOM::NameNodeListImpl namedList( m_doc.documentElement().handle(), p.string() );
int len = namedList.length();
if ( len ) {
QValueList<DOM::Node> styleSheets;
for ( int i = 0 ; i < len ; ++i ) {
DOM::HTMLStyleElement elem = DOM::Node(namedList.item(i));
if (!elem.isNull())
styleSheets.append(elem.sheet());
}
if ( styleSheets.count() == 1 ) return getDOMStyleSheet(exec, styleSheets[0]);
else if ( styleSheets.count() > 1 ) {
return new DOMNamedItemsCollection(exec,styleSheets);
}
}
#endif
DOM::DOMString pstr = p.string();
DOM::HTMLStyleElement styleElem = m_doc.getElementById( pstr );
if (!styleElem.isNull())
return getDOMStyleSheet(exec, styleElem.sheet());
return DOMObject::tryGet(exec, p);
}
Value KJS::getDOMStyleSheetList(ExecState *exec, DOM::StyleSheetList ssl, DOM::Document doc)
{
DOMObject *ret;
if (ssl.isNull())
return Null();
ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter());
if ((ret = interp->getDOMObject(ssl.handle())))
return Value(ret);
else {
ret = new DOMStyleSheetList(exec, ssl, doc);
interp->putDOMObject(ssl.handle(),ret);
return Value(ret);
}
}
Value DOMStyleSheetListFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
if (!thisObj.inherits(&KJS::DOMStyleSheetList::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
DOM::StyleSheetList styleSheetList = static_cast<DOMStyleSheetList *>(thisObj.imp())->toStyleSheetList();
if (id == DOMStyleSheetList::Item)
return getDOMStyleSheet(exec, styleSheetList.item(args[0].toInt32(exec)));
return Undefined();
}
const ClassInfo DOMMediaList::info = { "MediaList", 0, &DOMMediaListTable, 0 };
DEFINE_PROTOTYPE("DOMMediaList", DOMMediaListProto)
IMPLEMENT_PROTOFUNC(DOMMediaListProtoFunc)
IMPLEMENT_PROTOTYPE(DOMMediaListProto, DOMMediaListProtoFunc)
DOMMediaList::DOMMediaList(ExecState *exec, DOM::MediaList ml)
: mediaList(ml)
{
setPrototype(DOMMediaListProto::self(exec));
}
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 };
DEFINE_PROTOTYPE("DOMCSSStyleSheet",DOMCSSStyleSheetProto)
IMPLEMENT_PROTOFUNC(DOMCSSStyleSheetProtoFunc)
IMPLEMENT_PROTOTYPE(DOMCSSStyleSheetProto,DOMCSSStyleSheetProtoFunc)
DOMCSSStyleSheet::DOMCSSStyleSheet(ExecState *exec, DOM::CSSStyleSheet ss)
: DOMStyleSheet(ss)
{
setPrototype(DOMCSSStyleSheetProto::self(exec));
}
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" )
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);
return Number(-1);
}
}
return Undefined();
}
const ClassInfo DOMCSSRuleList::info = { "CSSRuleList", 0, &DOMCSSRuleListTable, 0 };
IMPLEMENT_PROTOFUNC(DOMCSSRuleListFunc)
DOMCSSRuleList::~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)
DOMCSSRule::~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;
}
}
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; 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);
}
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());
case Style_SelectorText:
return getStringOrNull(static_cast<DOM::CSSStyleRule>(cssRule).selectorText());
case Style_Style:
return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSStyleRule>(cssRule).style());
case Media_Media:
return getDOMMediaList(exec,static_cast<DOM::CSSMediaRule>(cssRule).media());
case Media_CssRules:
return getDOMCSSRuleList(exec,static_cast<DOM::CSSMediaRule>(cssRule).cssRules());
case FontFace_Style:
return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSFontFaceRule>(cssRule).style());
case Page_SelectorText:
return getStringOrNull(static_cast<DOM::CSSPageRule>(cssRule).selectorText());
case Page_Style:
return getDOMCSSStyleDeclaration(exec,static_cast<DOM::CSSPageRule>(cssRule).style());
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());
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; const HashEntry* entry = Lookup::findEntry(table, propertyName);
if (entry) {
if (entry->attr & Function) {
ObjectImp::put(exec, propertyName, value, attr);
return;
}
else if ((entry->attr & ReadOnly) == 0) {
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) {
case Style_SelectorText:
static_cast<DOM::CSSStyleRule>(cssRule).setSelectorText(value.toString(exec).string());
return;
case Page_SelectorText:
static_cast<DOM::CSSPageRule>(cssRule).setSelectorText(value.toString(exec).string());
return;
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 };
Value CSSRuleConstructor::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<CSSRuleConstructor,DOMObject>(exec,p,&CSSRuleConstructorTable,this);
}
Value CSSRuleConstructor::getValueProperty(ExecState *, int token) const
{
switch (token) {
case UNKNOWN_RULE:
return Number(DOM::CSSRule::UNKNOWN_RULE);
case STYLE_RULE:
return Number(DOM::CSSRule::STYLE_RULE);
case CHARSET_RULE:
return Number(DOM::CSSRule::CHARSET_RULE);
case IMPORT_RULE:
return Number(DOM::CSSRule::IMPORT_RULE);
case MEDIA_RULE:
return Number(DOM::CSSRule::MEDIA_RULE);
case FONT_FACE_RULE:
return Number(DOM::CSSRule::FONT_FACE_RULE);
case PAGE_RULE:
return Number(DOM::CSSRule::PAGE_RULE);
}
return Value();
}
namespace KJS {
Value getCSSRuleConstructor(ExecState *exec)
{
return cacheGlobalObject<CSSRuleConstructor>( exec, "[[cssRule.constructor]]" );
}
}
const ClassInfo DOMCSSValue::info = { "CSSValue", 0, &DOMCSSValueTable, 0 };
DOMCSSValue::~DOMCSSValue()
{
ScriptInterpreter::forgetDOMObject(cssValue.handle());
}
Value DOMCSSValue::tryGet(ExecState *exec, const Identifier &p) const
{
if (p == "cssText")
return getStringOrNull(cssValue.cssText());
else if (p == "cssValueType");
return Number(cssValue.cssValueType());
return DOMObject::tryGet(exec,p);
}
void DOMCSSValue::tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr)
{
if (propertyName == "cssText")
cssValue.setCssText(value.toString(exec).string());
else
DOMObject::tryPut(exec, propertyName, value, attr);
}
Value KJS::getDOMCSSValue(ExecState *exec, DOM::CSSValue v)
{
DOMObject *ret;
if (v.isNull())
return Null();
ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter());
if ((ret = interp->getDOMObject(v.handle())))
return Value(ret);
else {
if (v.isCSSValueList())
ret = new DOMCSSValueList(exec,v);
else if (v.isCSSPrimitiveValue())
ret = new DOMCSSPrimitiveValue(exec,v);
else
ret = new DOMCSSValue(exec,v);
interp->putDOMObject(v.handle(),ret);
return Value(ret);
}
}
const ClassInfo CSSValueConstructor::info = { "CSSValueConstructor", 0, &CSSValueConstructorTable, 0 };
Value CSSValueConstructor::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<CSSValueConstructor,DOMObject>(exec,p,&CSSValueConstructorTable,this);
}
Value CSSValueConstructor::getValueProperty(ExecState *, int token) const
{
switch (token) {
case CSS_INHERIT:
return Number(DOM::CSSValue::CSS_INHERIT);
case CSS_PRIMITIVE_VALUE:
return Number(DOM::CSSValue::CSS_PRIMITIVE_VALUE);
case CSS_VALUE_LIST:
return Number(DOM::CSSValue::CSS_VALUE_LIST);
case CSS_CUSTOM:
return Number(DOM::CSSValue::CSS_CUSTOM);
}
return Value();
}
Value getCSSValueConstructor(ExecState *exec)
{
return cacheGlobalObject<CSSValueConstructor>( exec, "[[cssValue.constructor]]" );
}
const ClassInfo DOMCSSPrimitiveValue::info = { "CSSPrimitiveValue", 0, &DOMCSSPrimitiveValueTable, 0 };
DEFINE_PROTOTYPE("DOMCSSPrimitiveValue",DOMCSSPrimitiveValueProto)
IMPLEMENT_PROTOFUNC(DOMCSSPrimitiveValueProtoFunc)
IMPLEMENT_PROTOTYPE(DOMCSSPrimitiveValueProto,DOMCSSPrimitiveValueProtoFunc)
DOMCSSPrimitiveValue::DOMCSSPrimitiveValue(ExecState *exec, DOM::CSSPrimitiveValue v)
: DOMCSSValue(v)
{
setPrototype(DOMCSSPrimitiveValueProto::self(exec));
}
Value DOMCSSPrimitiveValue::tryGet(ExecState *exec, const Identifier &p) const
{
if (p=="primitiveType")
return Number(static_cast<DOM::CSSPrimitiveValue>(cssValue).primitiveType());
return DOMObject::tryGet(exec,p);
}
Value DOMCSSPrimitiveValueProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
if (!thisObj.inherits(&KJS::DOMCSSPrimitiveValue::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
DOM::CSSPrimitiveValue val = static_cast<DOMCSSPrimitiveValue *>(thisObj.imp())->toCSSPrimitiveValue();
switch (id) {
case DOMCSSPrimitiveValue::SetFloatValue:
val.setFloatValue(args[0].toInt32(exec),args[1].toNumber(exec));
return Undefined();
case DOMCSSPrimitiveValue::GetFloatValue:
return Number(val.getFloatValue(args[0].toInt32(exec)));
case DOMCSSPrimitiveValue::SetStringValue:
val.setStringValue(args[0].toInt32(exec),args[1].toString(exec).string());
return Undefined();
case DOMCSSPrimitiveValue::GetStringValue:
return getStringOrNull(val.getStringValue());
case DOMCSSPrimitiveValue::GetCounterValue:
return getDOMCounter(exec,val.getCounterValue());
case DOMCSSPrimitiveValue::GetRectValue:
return getDOMRect(exec,val.getRectValue());
case DOMCSSPrimitiveValue::GetRGBColorValue:
return getDOMRGBColor(exec,val.getRGBColorValue());
default:
return Undefined();
}
}
const ClassInfo CSSPrimitiveValueConstructor::info = { "CSSPrimitiveValueConstructor", 0, &CSSPrimitiveValueConstructorTable, 0 };
Value CSSPrimitiveValueConstructor::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<CSSPrimitiveValueConstructor,CSSValueConstructor>(exec,p,&CSSPrimitiveValueConstructorTable,this);
}
Value CSSPrimitiveValueConstructor::getValueProperty(ExecState *, int token) const
{
return Number(token);
}
Value getCSSPrimitiveValueConstructor(ExecState *exec)
{
return cacheGlobalObject<CSSPrimitiveValueConstructor>( exec, "[[cssPrimitiveValue.constructor]]" );
}
const ClassInfo DOMCSSValueList::info = { "CSSValueList", 0, &DOMCSSValueListTable, 0 };
IMPLEMENT_PROTOFUNC(DOMCSSValueListFunc)
DOMCSSValueList::DOMCSSValueList(ExecState *exec, DOM::CSSValueList v)
: DOMCSSValue(exec, v)
{
}
Value DOMCSSValueList::tryGet(ExecState *exec, const Identifier &p) const
{
Value result;
DOM::CSSValueList valueList = static_cast<DOM::CSSValueList>(cssValue);
if (p == lengthPropertyName)
return Number(valueList.length());
else if (p == "item")
return lookupOrCreateFunction<DOMCSSValueListFunc>(exec,p,this,DOMCSSValueList::Item,1,DontDelete|Function);
bool ok;
long unsigned int u = p.toULong(&ok);
if (ok)
return getDOMCSSValue(exec,valueList.item(u));
return DOMCSSValue::tryGet(exec,p);
}
Value DOMCSSValueListFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
{
if (!thisObj.inherits(&KJS::DOMCSSValue::info)) {
Object err = Error::create(exec,TypeError);
exec->setException(err);
return err;
}
DOM::CSSValueList valueList = static_cast<DOMCSSValueList *>(thisObj.imp())->toValueList();
switch (id) {
case DOMCSSValueList::Item:
return getDOMCSSValue(exec,valueList.item(args[0].toInt32(exec)));
default:
return Undefined();
}
}
const ClassInfo DOMRGBColor::info = { "RGBColor", 0, &DOMRGBColorTable, 0 };
DOMRGBColor::~DOMRGBColor()
{
}
Value DOMRGBColor::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<DOMRGBColor,DOMObject>(exec, p,
&DOMRGBColorTable,
this);
}
Value DOMRGBColor::getValueProperty(ExecState *exec, int token) const
{
switch (token) {
case Red:
return getDOMCSSValue(exec, rgbColor.red());
case Green:
return getDOMCSSValue(exec, rgbColor.green());
case Blue:
return getDOMCSSValue(exec, rgbColor.blue());
default:
return Value();
}
}
Value KJS::getDOMRGBColor(ExecState *, DOM::RGBColor c)
{
return Value(new DOMRGBColor(c));
}
const ClassInfo DOMRect::info = { "Rect", 0, &DOMRectTable, 0 };
DOMRect::~DOMRect()
{
ScriptInterpreter::forgetDOMObject(rect.handle());
}
Value DOMRect::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<DOMRect,DOMObject>(exec, p,
&DOMRectTable, this);
}
Value DOMRect::getValueProperty(ExecState *exec, int token) const
{
switch (token) {
case Top:
return getDOMCSSValue(exec, rect.top());
case Right:
return getDOMCSSValue(exec, rect.right());
case Bottom:
return getDOMCSSValue(exec, rect.bottom());
case Left:
return getDOMCSSValue(exec, rect.left());
default:
return Value();
}
}
Value KJS::getDOMRect(ExecState *exec, DOM::Rect r)
{
return cacheDOMObject<DOM::Rect, KJS::DOMRect>(exec, r);
}
const ClassInfo DOMCounter::info = { "Counter", 0, &DOMCounterTable, 0 };
DOMCounter::~DOMCounter()
{
ScriptInterpreter::forgetDOMObject(counter.handle());
}
Value DOMCounter::tryGet(ExecState *exec, const Identifier &p) const
{
return DOMObjectLookupGetValue<DOMCounter,DOMObject>(exec, p,
&DOMCounterTable, this);
}
Value DOMCounter::getValueProperty(ExecState *, int token) const
{
switch (token) {
case identifier:
return getStringOrNull(counter.identifier());
case listStyle:
return getStringOrNull(counter.listStyle());
case separator:
return getStringOrNull(counter.separator());
default:
return Value();
}
}
Value KJS::getDOMCounter(ExecState *exec, DOM::Counter c)
{
return cacheDOMObject<DOM::Counter, KJS::DOMCounter>(exec, c);
}