1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2003 Apple Computer, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "kjs_css.lut.h"
25 #include "kjs_binding.h"
27 #include "html/html_headimpl.h" // for HTMLStyleElementImpl
29 #include "dom/css_value.h"
30 #include "dom/css_rule.h"
32 #include "css/css_base.h"
33 #include "css/css_ruleimpl.h"
34 #include "css/css_renderstyledeclarationimpl.h"
35 #include "css/css_stylesheetimpl.h"
36 #include "css/css_valueimpl.h"
38 #include "misc/htmltags.h"
42 using DOM::CSSCharsetRuleImpl
;
43 using DOM::CSSFontFaceRuleImpl
;
44 using DOM::CSSImportRuleImpl
;
45 using DOM::CSSMediaRuleImpl
;
46 using DOM::CSSPageRuleImpl
;
47 using DOM::CSSPrimitiveValue
;
48 using DOM::CSSPrimitiveValueImpl
;
50 using DOM::CSSRuleImpl
;
51 using DOM::CSSRuleListImpl
;
52 using DOM::CSSStyleDeclarationImpl
;
53 using DOM::CSSStyleRuleImpl
;
54 using DOM::CSSStyleSheetImpl
;
56 using DOM::CSSValueImpl
;
57 using DOM::CSSValueListImpl
;
58 using DOM::CounterImpl
;
59 using DOM::DocumentImpl
;
61 using DOM::ElementImpl
;
62 using DOM::HTMLStyleElementImpl
;
63 using DOM::MediaListImpl
;
65 using DOM::StyleSheetImpl
;
66 using DOM::StyleSheetListImpl
;
69 #include <QtCore/QList>
73 static QString
cssPropertyName( const Identifier
&p
, bool* hadPixelPrefix
)
75 // The point here is to provide compatibility with IE
76 // syntax for accessing properties, which camel-cases them
77 // and can add prefixes to produce things like pixelFoo
78 QString prop
= p
.qstring();
79 for (int i
= prop
.length() - 1; i
>= 0; --i
) {
80 char c
= prop
[i
].toLatin1();
81 if ( c
>= 'A' && c
<= 'Z' )
82 prop
.insert( i
, '-' );
85 prop
= prop
.toLower();
86 *hadPixelPrefix
= false;
88 if (prop
.startsWith(QLatin1String("css-"))) {
90 } else if (prop
.startsWith(QLatin1String("pixel-"))) {
92 *hadPixelPrefix
= true;
93 } else if (prop
.startsWith(QLatin1String("pos-"))) {
95 *hadPixelPrefix
= true;
101 static int cssPropertyId( const QString
& p
) {
102 return DOM::getPropertyID(p
.toLatin1().constData(), p
.length());
105 static int cssPropertyId( const DOM::DOMString
& name
) {
106 return cssPropertyId(name
.string());
109 static bool isCSSPropertyName(const Identifier
&JSPropertyName
)
112 QString p
= cssPropertyName(JSPropertyName
, &dummy
);
113 return cssPropertyId(p
) != 0;
118 @begin DOMCSSStyleDeclarationProtoTable 7
119 getPropertyValue DOMCSSStyleDeclaration::GetPropertyValue DontDelete|Function 1
120 getPropertyCSSValue DOMCSSStyleDeclaration::GetPropertyCSSValue DontDelete|Function 1
121 removeProperty DOMCSSStyleDeclaration::RemoveProperty DontDelete|Function 1
122 getPropertyPriority DOMCSSStyleDeclaration::GetPropertyPriority DontDelete|Function 1
123 setProperty DOMCSSStyleDeclaration::SetProperty DontDelete|Function 3
124 item DOMCSSStyleDeclaration::Item DontDelete|Function 1
125 # IE names for it (#36063)
126 getAttribute DOMCSSStyleDeclaration::GetPropertyValue DontDelete|Function 1
127 removeAttribute DOMCSSStyleDeclaration::RemoveProperty DontDelete|Function 1
128 setAttribute DOMCSSStyleDeclaration::SetProperty DontDelete|Function 3
130 @begin DOMCSSStyleDeclarationTable 3
131 cssText DOMCSSStyleDeclaration::CssText DontDelete
132 length DOMCSSStyleDeclaration::Length DontDelete|ReadOnly
133 parentRule DOMCSSStyleDeclaration::ParentRule DontDelete|ReadOnly
136 KJS_DEFINE_PROTOTYPE(DOMCSSStyleDeclarationProto
)
137 KJS_IMPLEMENT_PROTOFUNC(DOMCSSStyleDeclarationProtoFunc
)
138 KJS_IMPLEMENT_PROTOTYPE("DOMCSSStyleDeclaration", DOMCSSStyleDeclarationProto
, DOMCSSStyleDeclarationProtoFunc
)
140 IMPLEMENT_PSEUDO_CONSTRUCTOR(CSSStyleDeclarationPseudoCtor
, "DOMCSSStyleDeclaration",DOMCSSStyleDeclarationProto
)
142 const ClassInfo
DOMCSSStyleDeclaration::info
= { "CSSStyleDeclaration", 0, &DOMCSSStyleDeclarationTable
, 0 };
144 DOMCSSStyleDeclaration::DOMCSSStyleDeclaration(ExecState
*exec
, DOM::CSSStyleDeclarationImpl
* s
)
145 : DOMObject(), m_impl(s
)
147 setPrototype(DOMCSSStyleDeclarationProto::self(exec
));
150 DOMCSSStyleDeclaration::~DOMCSSStyleDeclaration()
152 ScriptInterpreter::forgetDOMObject(m_impl
.get());
155 JSValue
* DOMCSSStyleDeclaration::getValueProperty(ExecState
*exec
, int token
)
160 return jsString(m_impl
->cssText());
162 return jsNumber(m_impl
->length());
164 return getDOMCSSRule(exec
, m_impl
->parentRule());
168 return jsUndefined();
171 JSValue
*DOMCSSStyleDeclaration::indexGetter(ExecState
* , unsigned index
)
173 return jsString(m_impl
->item(index
));
176 bool DOMCSSStyleDeclaration::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
179 kDebug(6070) << "DOMCSSStyleDeclaration::getOwnPropertySlot " << propertyName
.qstring();
182 if (getStaticOwnValueSlot(&DOMCSSStyleDeclarationTable
, this, propertyName
, slot
))
185 //Check whether it's an index
186 if (getIndexSlot(this, propertyName
, slot
))
189 if (isCSSPropertyName(propertyName
)) {
190 // Set up pixelOrPos boolean to handle the fact that
191 // pixelTop returns "CSS Top" as number value in unit pixels
192 // posTop returns "CSS top" as number value in unit pixels _if_ its a
193 // positioned element. if it is not a positioned element, return 0
194 // from MSIE documentation ### IMPLEMENT THAT (Dirk)
196 DOMString p
= cssPropertyName(propertyName
, &asNumber
);
199 CSSValueImpl
*v
= m_impl
->getPropertyCSSValue(p
);
200 if (v
&& v
->cssValueType() == DOM::CSSValue::CSS_PRIMITIVE_VALUE
)
201 //### FIXME: should this not set exception when type is wrong, or convert?
202 return getImmediateValueSlot(this,
203 jsNumber(static_cast<CSSPrimitiveValueImpl
*>(v
)->floatValue(DOM::CSSPrimitiveValue::CSS_PX
)), slot
);
206 DOM::DOMString str
= m_impl
->getPropertyValue(p
);
208 // We want to return at least an empty string here --- see #152791
209 return getImmediateValueSlot(this, jsString(str
), slot
);
212 return DOMObject::getOwnPropertySlot(exec
, propertyName
, slot
);
216 void DOMCSSStyleDeclaration::put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
)
219 kDebug(6070) << "DOMCSSStyleDeclaration::put " << propertyName
.qstring();
221 DOMExceptionTranslator
exception(exec
);
222 CSSStyleDeclarationImpl
&styleDecl
= *m_impl
;
224 if (propertyName
== "cssText") {
225 styleDecl
.setCssText(value
->toString(exec
).domString());
229 QString prop
= cssPropertyName(propertyName
, &pxSuffix
);
230 QString propvalue
= value
->toString(exec
).qstring();
233 propvalue
+= QLatin1String("px");
235 kDebug(6070) << "DOMCSSStyleDeclaration: prop=" << prop
<< " propvalue=" << propvalue
;
237 // Look whether the property is known. In that case add it as a CSS property.
238 if (int pId
= cssPropertyId(prop
)) {
239 if (propvalue
.isEmpty())
240 styleDecl
.removeProperty(pId
);
242 int important
= propvalue
.indexOf("!important", 0, Qt::CaseInsensitive
);
243 if (important
== -1) {
244 styleDecl
.setProperty(pId
, DOM::DOMString(propvalue
), false /*important*/, exception
);
246 styleDecl
.setProperty(pId
, DOM::DOMString(propvalue
.left(important
- 1)), true /*important*/, exception
);
250 // otherwise add it as a JS property
251 DOMObject::put( exec
, propertyName
, value
, attr
);
255 JSValue
*DOMCSSStyleDeclarationProtoFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
257 KJS_CHECK_THIS( KJS::DOMCSSStyleDeclaration
, thisObj
);
258 CSSStyleDeclarationImpl
& styleDecl
= *static_cast<DOMCSSStyleDeclaration
*>(thisObj
)->impl();
260 DOM::DOMString s
= args
[0]->toString(exec
).domString();
263 case DOMCSSStyleDeclaration::GetPropertyValue
:
264 return jsString(styleDecl
.getPropertyValue(s
));
265 case DOMCSSStyleDeclaration::GetPropertyCSSValue
:
266 return getDOMCSSValue(exec
,styleDecl
.getPropertyCSSValue(s
));
267 case DOMCSSStyleDeclaration::RemoveProperty
:
268 return jsString(styleDecl
.removeProperty(s
));
269 case DOMCSSStyleDeclaration::GetPropertyPriority
:
270 return jsString(styleDecl
.getPropertyPriority(s
));
271 case DOMCSSStyleDeclaration::SetProperty
:
272 styleDecl
.setProperty(args
[0]->toString(exec
).domString(),
273 args
[1]->toString(exec
).domString(),
274 args
[2]->toString(exec
).domString());
275 return jsUndefined();
276 case DOMCSSStyleDeclaration::Item
:
277 return jsString(styleDecl
.item(args
[0]->toInteger(exec
)));
279 return jsUndefined();
283 JSValue
*getDOMCSSStyleDeclaration(ExecState
*exec
, CSSStyleDeclarationImpl
*s
)
285 return cacheDOMObject
<CSSStyleDeclarationImpl
, DOMCSSStyleDeclaration
>(exec
, s
);
288 // -------------------------------------------------------------------------
290 const ClassInfo
DOMStyleSheet::info
= { "StyleSheet", 0, &DOMStyleSheetTable
, 0 };
292 @begin DOMStyleSheetTable 7
293 type DOMStyleSheet::Type DontDelete|ReadOnly
294 disabled DOMStyleSheet::Disabled DontDelete
295 ownerNode DOMStyleSheet::OwnerNode DontDelete|ReadOnly
296 parentStyleSheet DOMStyleSheet::ParentStyleSheet DontDelete|ReadOnly
297 href DOMStyleSheet::Href DontDelete|ReadOnly
298 title DOMStyleSheet::Title DontDelete|ReadOnly
299 media DOMStyleSheet::Media DontDelete|ReadOnly
303 DOMStyleSheet::DOMStyleSheet(ExecState
* exec
, DOM::StyleSheetImpl
* ss
)
306 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
309 DOMStyleSheet::~DOMStyleSheet()
311 ScriptInterpreter::forgetDOMObject(m_impl
.get());
314 bool DOMStyleSheet::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
316 return getStaticValueSlot
<DOMStyleSheet
, DOMObject
>(exec
, &DOMStyleSheetTable
, this, propertyName
, slot
);
319 JSValue
*DOMStyleSheet::getValueProperty(ExecState
*exec
, int token
) const
321 StyleSheetImpl
&styleSheet
= *m_impl
;
324 return jsString(styleSheet
.type());
326 return jsBoolean(styleSheet
.disabled());
328 return getDOMNode(exec
,styleSheet
.ownerNode());
329 case ParentStyleSheet
:
330 return getDOMStyleSheet(exec
,styleSheet
.parentStyleSheet());
332 return getStringOrNull(styleSheet
.href());
334 return jsString(styleSheet
.title());
336 return getDOMMediaList(exec
, styleSheet
.media());
341 void DOMStyleSheet::put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
)
343 StyleSheetImpl
&styleSheet
= *m_impl
;
344 if (propertyName
== "disabled") {
345 styleSheet
.setDisabled(value
->toBoolean(exec
));
348 DOMObject::put(exec
, propertyName
, value
, attr
);
351 JSValue
*getDOMStyleSheet(ExecState
*exec
, DOM::StyleSheetImpl
* ss
)
357 ScriptInterpreter
* interp
= static_cast<ScriptInterpreter
*>(exec
->dynamicInterpreter());
358 if ((ret
= interp
->getDOMObject(ss
)))
361 if (ss
->isCSSStyleSheet()) {
362 CSSStyleSheetImpl
* cs
= static_cast<CSSStyleSheetImpl
*>(ss
);
363 ret
= new DOMCSSStyleSheet(exec
,cs
);
366 ret
= new DOMStyleSheet(exec
,ss
);
367 interp
->putDOMObject(ss
,ret
);
372 // -------------------------------------------------------------------------
374 const ClassInfo
DOMStyleSheetList::info
= { "StyleSheetList", 0, &DOMStyleSheetListTable
, 0 };
377 @begin DOMStyleSheetListTable 2
378 length DOMStyleSheetList::Length DontDelete|ReadOnly
379 item DOMStyleSheetList::Item DontDelete|Function 1
382 KJS_IMPLEMENT_PROTOFUNC(DOMStyleSheetListFunc
) // not really a proto, but doesn't matter
384 DOMStyleSheetList::DOMStyleSheetList(ExecState
*exec
, DOM::StyleSheetListImpl
* ssl
, DOM::DocumentImpl
* doc
)
385 : m_impl(ssl
), m_doc(doc
)
387 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
390 DOMStyleSheetList::~DOMStyleSheetList()
392 ScriptInterpreter::forgetDOMObject(m_impl
.get());
395 JSValue
*DOMStyleSheetList::getValueProperty(ExecState
*, int token
) const
399 return jsNumber(m_impl
->length());
402 return jsUndefined();
406 JSValue
*DOMStyleSheetList::indexGetter(ExecState
*exec
, unsigned index
)
408 return getDOMStyleSheet(exec
, m_impl
->item(index
));
411 JSValue
*DOMStyleSheetList::nameGetter(ExecState
*exec
, JSObject
*, const Identifier
& propertyName
, const PropertySlot
& slot
)
413 DOMStyleSheetList
*thisObj
= static_cast<DOMStyleSheetList
*>(slot
.slotBase());
414 ElementImpl
*element
= thisObj
->m_doc
->getElementById(propertyName
.domString());
415 assert(element
->id() == ID_STYLE
); //Should be from existence check
416 return getDOMStyleSheet(exec
, static_cast<HTMLStyleElementImpl
*>(element
)->sheet());
419 bool DOMStyleSheetList::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
422 kDebug(6070) << "DOMStyleSheetList::getOwnPropertySlot " << propertyName
.qstring();
424 if (getStaticOwnPropertySlot
<DOMStyleSheetListFunc
, DOMStyleSheetList
>(&DOMStyleSheetListTable
, this, propertyName
, slot
))
427 StyleSheetListImpl
&styleSheetList
= *m_impl
;
429 // Retrieve stylesheet by index
430 if (getIndexSlot(this, styleSheetList
, propertyName
, slot
))
433 // IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag
434 // (this is consistent with all the other collections)
435 // ### Bad implementation because returns a single element (are IDs always unique?)
436 // and doesn't look for name attribute (see implementation above).
437 // But unicity of stylesheet ids is good practice anyway ;)
438 ElementImpl
*element
= m_doc
->getElementById(propertyName
.domString());
439 if (element
&& element
->id() == ID_STYLE
) {
440 slot
.setCustom(this, nameGetter
);
444 return DOMObject::getOwnPropertySlot(exec
, propertyName
, slot
);
447 JSValue
*DOMStyleSheetList::callAsFunction(ExecState
*exec
, JSObject
* /*thisObj*/, const List
&args
)
449 if (args
.size() == 1) {
450 // support for styleSheets(<index>) and styleSheets(<name>)
451 return get( exec
, Identifier(args
[0]->toString(exec
)) );
453 return jsUndefined();
456 JSValue
*getDOMStyleSheetList(ExecState
*exec
, DOM::StyleSheetListImpl
* ssl
, DOM::DocumentImpl
* doc
)
458 // Can't use the cacheDOMObject macro because of the doc argument
462 ScriptInterpreter
* interp
= static_cast<ScriptInterpreter
*>(exec
->dynamicInterpreter());
463 if ((ret
= interp
->getDOMObject(ssl
)))
466 ret
= new DOMStyleSheetList(exec
, ssl
, doc
);
467 interp
->putDOMObject(ssl
,ret
);
472 JSValue
*DOMStyleSheetListFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
474 KJS_CHECK_THIS( KJS::DOMStyleSheetList
, thisObj
);
475 DOM::StyleSheetListImpl
* styleSheetList
= static_cast<DOMStyleSheetList
*>(thisObj
)->impl();
476 if (id
== DOMStyleSheetList::Item
)
477 return getDOMStyleSheet(exec
, styleSheetList
->item(args
[0]->toInteger(exec
)));
478 return jsUndefined();
481 // -------------------------------------------------------------------------
483 const ClassInfo
DOMMediaList::info
= { "MediaList", 0, &DOMMediaListTable
, 0 };
486 @begin DOMMediaListTable 2
487 mediaText DOMMediaList::MediaText DontDelete|ReadOnly
488 length DOMMediaList::Length DontDelete|ReadOnly
490 @begin DOMMediaListProtoTable 3
491 item DOMMediaList::Item DontDelete|Function 1
492 deleteMedium DOMMediaList::DeleteMedium DontDelete|Function 1
493 appendMedium DOMMediaList::AppendMedium DontDelete|Function 1
496 KJS_DEFINE_PROTOTYPE(DOMMediaListProto
)
497 KJS_IMPLEMENT_PROTOFUNC(DOMMediaListProtoFunc
)
498 KJS_IMPLEMENT_PROTOTYPE("DOMMediaList", DOMMediaListProto
, DOMMediaListProtoFunc
)
500 DOMMediaList::DOMMediaList(ExecState
*exec
, DOM::MediaListImpl
* ml
)
503 setPrototype(DOMMediaListProto::self(exec
));
506 DOMMediaList::~DOMMediaList()
508 ScriptInterpreter::forgetDOMObject(m_impl
.get());
511 JSValue
* DOMMediaList::getValueProperty(ExecState
*, int token
) const
513 const MediaListImpl
& mediaList
= *m_impl
;
517 return jsString(mediaList
.mediaText());
519 return jsNumber(mediaList
.length());
522 return jsUndefined();
526 JSValue
*DOMMediaList::indexGetter(ExecState
*, unsigned index
)
528 return jsString(m_impl
->item(index
));
531 bool DOMMediaList::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
533 if (getStaticOwnValueSlot(&DOMMediaListTable
, this, propertyName
, slot
))
536 if (getIndexSlot(this, *m_impl
, propertyName
, slot
))
539 return DOMObject::getOwnPropertySlot(exec
, propertyName
, slot
);
542 void DOMMediaList::put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
)
544 if (propertyName
== "mediaText") {
545 DOMExceptionTranslator
exception(exec
);
546 m_impl
->setMediaText(value
->toString(exec
).domString(), exception
);
548 DOMObject::put(exec
, propertyName
, value
, attr
);
551 JSValue
*getDOMMediaList(ExecState
*exec
, DOM::MediaListImpl
* ml
)
553 return cacheDOMObject
<DOM::MediaListImpl
, KJS::DOMMediaList
>(exec
, ml
);
556 JSValue
*DOMMediaListProtoFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
558 KJS_CHECK_THIS( KJS::DOMMediaList
, thisObj
);
559 DOM::MediaListImpl
& mediaList
= *static_cast<DOMMediaList
*>(thisObj
)->impl();
560 DOMExceptionTranslator
exception(exec
);
562 case DOMMediaList::Item
:
563 return jsString(mediaList
.item(args
[0]->toInteger(exec
)));
564 case DOMMediaList::DeleteMedium
:
565 mediaList
.deleteMedium(args
[0]->toString(exec
).domString(), exception
);
566 return jsUndefined();
567 case DOMMediaList::AppendMedium
:
568 mediaList
.appendMedium(args
[0]->toString(exec
).domString(), exception
);
569 return jsUndefined();
571 return jsUndefined();
575 // -------------------------------------------------------------------------
577 const ClassInfo
DOMCSSStyleSheet::info
= { "CSSStyleSheet", 0, &DOMCSSStyleSheetTable
, 0 };
580 @begin DOMCSSStyleSheetTable 2
581 ownerRule DOMCSSStyleSheet::OwnerRule DontDelete|ReadOnly
582 cssRules DOMCSSStyleSheet::CssRules DontDelete|ReadOnly
584 rules DOMCSSStyleSheet::Rules DontDelete|ReadOnly
586 @begin DOMCSSStyleSheetProtoTable 2
587 insertRule DOMCSSStyleSheet::InsertRule DontDelete|Function 2
588 deleteRule DOMCSSStyleSheet::DeleteRule DontDelete|Function 1
590 addRule DOMCSSStyleSheet::AddRule DontDelete|Function 3
591 removeRule DOMCSSStyleSheet::RemoveRule DontDelete|Function 1
594 KJS_DEFINE_PROTOTYPE(DOMCSSStyleSheetProto
)
595 KJS_IMPLEMENT_PROTOFUNC(DOMCSSStyleSheetProtoFunc
)
596 KJS_IMPLEMENT_PROTOTYPE("DOMCSSStyleSheet",DOMCSSStyleSheetProto
,DOMCSSStyleSheetProtoFunc
) // warning, use _WITH_PARENT if DOMStyleSheet gets a proto
598 DOMCSSStyleSheet::DOMCSSStyleSheet(ExecState
*exec
, DOM::CSSStyleSheetImpl
* ss
): DOMStyleSheet(exec
, ss
)
600 setPrototype(DOMCSSStyleSheetProto::self(exec
));
603 DOMCSSStyleSheet::~DOMCSSStyleSheet()
606 JSValue
* DOMCSSStyleSheet::getValueProperty(ExecState
*exec
, int token
)
608 CSSStyleSheetImpl
& cssStyleSheet
= *impl();
609 // MSIE does not list the charset rules in its proprietary extension
610 bool omitCharsetRules
= true;
613 return getDOMCSSRule(exec
,cssStyleSheet
.ownerRule());
615 omitCharsetRules
= false;
618 return getDOMCSSRuleList(exec
, cssStyleSheet
.cssRules(omitCharsetRules
));
622 return jsUndefined();
627 bool DOMCSSStyleSheet::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
629 return getStaticValueSlot
<DOMCSSStyleSheet
, DOMStyleSheet
>(exec
, &DOMCSSStyleSheetTable
, this, propertyName
, slot
);
632 JSValue
*DOMCSSStyleSheetProtoFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
634 KJS_CHECK_THIS( KJS::DOMCSSStyleSheet
, thisObj
);
635 DOM::CSSStyleSheetImpl
& styleSheet
= *static_cast<DOMCSSStyleSheet
*>(thisObj
)->impl();
636 DOMExceptionTranslator
exception(exec
);
639 case DOMCSSStyleSheet::InsertRule
:
640 return jsNumber(styleSheet
.insertRule(args
[0]->toString(exec
).domString(),(long unsigned int)args
[1]->toInteger(exec
), exception
));
641 case DOMCSSStyleSheet::DeleteRule
:
642 styleSheet
.deleteRule(args
[0]->toInteger(exec
), exception
);
643 return jsUndefined();
645 case DOMCSSStyleSheet::AddRule
: {
646 //Unpassed/-1 means append. Since insertRule is picky (throws exceptions)
647 //we adjust it to the desired length
648 unsigned long index
= args
[2]->toInteger(exec
);
649 unsigned long length
= styleSheet
.length();
650 if (args
[2]->type() == UndefinedType
) index
= length
;
651 if (index
> length
) index
= length
;
652 DOM::DOMString str
= args
[0]->toString(exec
).domString() + " { " + args
[1]->toString(exec
).domString() + " } ";
653 return jsNumber(styleSheet
.insertRule(str
, index
, exception
));
655 case DOMCSSStyleSheet::RemoveRule
: {
656 int index
= args
.size() > 0 ? args
[0]->toInteger(exec
) : 0 /*first one*/;
657 styleSheet
.deleteRule(index
, exception
);
658 return jsUndefined();
661 return jsUndefined();
665 // -------------------------------------------------------------------------
667 const ClassInfo
DOMCSSRuleList::info
= { "CSSRuleList", 0, &DOMCSSRuleListTable
, 0 };
669 @begin DOMCSSRuleListTable 3
670 length DOMCSSRuleList::Length DontDelete|ReadOnly
671 item DOMCSSRuleList::Item DontDelete|Function 1
674 KJS_IMPLEMENT_PROTOFUNC(DOMCSSRuleListFunc
) // not really a proto, but doesn't matter
676 DOMCSSRuleList::DOMCSSRuleList(ExecState
* exec
, DOM::CSSRuleListImpl
* rl
)
679 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
682 DOMCSSRuleList::~DOMCSSRuleList()
684 ScriptInterpreter::forgetDOMObject(m_impl
.get());
687 JSValue
*DOMCSSRuleList::getValueProperty(ExecState
*, int token
) const
691 return jsNumber(m_impl
->length());
694 return jsUndefined();
698 JSValue
*DOMCSSRuleList::indexGetter(ExecState
* exec
, unsigned index
)
700 return getDOMCSSRule(exec
, m_impl
->item(index
));
703 bool DOMCSSRuleList::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
705 if (getStaticOwnPropertySlot
<DOMCSSRuleListFunc
, DOMCSSRuleList
>(&DOMCSSRuleListTable
, this, propertyName
, slot
))
708 //Check whether it's an index
709 CSSRuleListImpl
&cssRuleList
= *m_impl
;
711 if (getIndexSlot(this, *m_impl
, propertyName
, slot
))
714 return DOMObject::getOwnPropertySlot(exec
, propertyName
, slot
);
717 JSValue
*DOMCSSRuleListFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
719 KJS_CHECK_THIS( KJS::DOMCSSRuleList
, thisObj
);
720 DOM::CSSRuleListImpl
& cssRuleList
= *static_cast<DOMCSSRuleList
*>(thisObj
)->impl();
722 case DOMCSSRuleList::Item
:
723 return getDOMCSSRule(exec
,cssRuleList
.item(args
[0]->toInteger(exec
)));
725 return jsUndefined();
729 JSValue
*getDOMCSSRuleList(ExecState
*exec
, DOM::CSSRuleListImpl
* rl
)
731 return cacheDOMObject
<DOM::CSSRuleListImpl
, KJS::DOMCSSRuleList
>(exec
, rl
);
734 // -------------------------------------------------------------------------
736 KJS_IMPLEMENT_PROTOFUNC(DOMCSSRuleFunc
) // Not a proto, but doesn't matter
738 DOMCSSRule::DOMCSSRule(ExecState
* exec
, DOM::CSSRuleImpl
* r
)
741 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
744 DOMCSSRule::~DOMCSSRule()
746 ScriptInterpreter::forgetDOMObject(m_impl
.get());
749 const ClassInfo
DOMCSSRule::info
= { "CSSRule", 0, &DOMCSSRuleTable
, 0 };
750 const ClassInfo
DOMCSSRule::style_info
= { "CSSStyleRule", &DOMCSSRule::info
, &DOMCSSStyleRuleTable
, 0 };
751 const ClassInfo
DOMCSSRule::media_info
= { "CSSMediaRule", &DOMCSSRule::info
, &DOMCSSMediaRuleTable
, 0 };
752 const ClassInfo
DOMCSSRule::fontface_info
= { "CSSFontFaceRule", &DOMCSSRule::info
, &DOMCSSFontFaceRuleTable
, 0 };
753 const ClassInfo
DOMCSSRule::page_info
= { "CSSPageRule", &DOMCSSRule::info
, &DOMCSSPageRuleTable
, 0 };
754 const ClassInfo
DOMCSSRule::import_info
= { "CSSImportRule", &DOMCSSRule::info
, &DOMCSSImportRuleTable
, 0 };
755 const ClassInfo
DOMCSSRule::charset_info
= { "CSSCharsetRule", &DOMCSSRule::info
, &DOMCSSCharsetRuleTable
, 0 };
757 const ClassInfo
* DOMCSSRule::classInfo() const
759 switch (m_impl
->type()) {
760 case DOM::CSSRule::STYLE_RULE
:
762 case DOM::CSSRule::MEDIA_RULE
:
764 case DOM::CSSRule::FONT_FACE_RULE
:
765 return &fontface_info
;
766 case DOM::CSSRule::PAGE_RULE
:
768 case DOM::CSSRule::IMPORT_RULE
:
770 case DOM::CSSRule::CHARSET_RULE
:
771 return &charset_info
;
772 case DOM::CSSRule::UNKNOWN_RULE
:
778 @begin DOMCSSRuleTable 4
779 type DOMCSSRule::Type DontDelete|ReadOnly
780 cssText DOMCSSRule::CssText DontDelete|ReadOnly
781 parentStyleSheet DOMCSSRule::ParentStyleSheet DontDelete|ReadOnly
782 parentRule DOMCSSRule::ParentRule DontDelete|ReadOnly
784 @begin DOMCSSStyleRuleTable 2
785 selectorText DOMCSSRule::Style_SelectorText DontDelete
786 style DOMCSSRule::Style_Style DontDelete|ReadOnly
788 @begin DOMCSSMediaRuleTable 4
789 media DOMCSSRule::Media_Media DontDelete|ReadOnly
790 cssRules DOMCSSRule::Media_CssRules DontDelete|ReadOnly
791 insertRule DOMCSSRule::Media_InsertRule DontDelete|Function 2
792 deleteRule DOMCSSRule::Media_DeleteRule DontDelete|Function 1
794 @begin DOMCSSFontFaceRuleTable 1
795 style DOMCSSRule::FontFace_Style DontDelete|ReadOnly
797 @begin DOMCSSPageRuleTable 2
798 selectorText DOMCSSRule::Page_SelectorText DontDelete
799 style DOMCSSRule::Page_Style DontDelete|ReadOnly
801 @begin DOMCSSImportRuleTable 3
802 href DOMCSSRule::Import_Href DontDelete|ReadOnly
803 media DOMCSSRule::Import_Media DontDelete|ReadOnly
804 styleSheet DOMCSSRule::Import_StyleSheet DontDelete|ReadOnly
806 @begin DOMCSSCharsetRuleTable 1
807 encoding DOMCSSRule::Charset_Encoding DontDelete
810 bool DOMCSSRule::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
813 kDebug(6070) << "DOMCSSRule::tryGet " << propertyName
.qstring();
815 //First do the rule-type-specific stuff
816 const HashTable
* table
= classInfo()->propHashTable
; // get the right hashtable
817 if (getStaticOwnPropertySlot
<DOMCSSRuleFunc
, DOMCSSRule
>(table
, this, propertyName
, slot
))
820 //Now do generic stuff
821 return getStaticPropertySlot
<DOMCSSRuleFunc
, DOMCSSRule
, DOMObject
>(exec
, &DOMCSSRuleTable
, this, propertyName
, slot
);
824 JSValue
*DOMCSSRule::getValueProperty(ExecState
*exec
, int token
) const
826 CSSRuleImpl
&cssRule
= *m_impl
;
829 return jsNumber(cssRule
.type());
831 return jsString(cssRule
.cssText());
832 case ParentStyleSheet
:
833 return getDOMStyleSheet(exec
,cssRule
.parentStyleSheet());
835 return getDOMCSSRule(exec
,cssRule
.parentRule());
837 // for DOM::CSSRule::STYLE_RULE:
838 case Style_SelectorText
:
839 return jsString(static_cast<CSSStyleRuleImpl
*>(m_impl
.get())->selectorText());
841 return getDOMCSSStyleDeclaration(exec
, static_cast<CSSStyleRuleImpl
*>(m_impl
.get())->style());
843 // for DOM::CSSRule::MEDIA_RULE:
845 return getDOMMediaList(exec
, static_cast<CSSMediaRuleImpl
*>(m_impl
.get())->media());
847 return getDOMCSSRuleList(exec
, static_cast<CSSMediaRuleImpl
*>(m_impl
.get())->cssRules());
849 // for DOM::CSSRule::FONT_FACE_RULE:
851 return getDOMCSSStyleDeclaration(exec
, static_cast<CSSFontFaceRuleImpl
*>(m_impl
.get())->style());
853 // for DOM::CSSRule::PAGE_RULE:
854 case Page_SelectorText
:
855 return jsString(static_cast<CSSPageRuleImpl
*>(m_impl
.get())->selectorText());
857 return getDOMCSSStyleDeclaration(exec
, static_cast<CSSPageRuleImpl
*>(m_impl
.get())->style());
859 // for DOM::CSSRule::IMPORT_RULE:
861 return jsString(static_cast<CSSImportRuleImpl
*>(m_impl
.get())->href());
863 return getDOMMediaList(exec
, static_cast<CSSImportRuleImpl
*>(m_impl
.get())->media());
864 case Import_StyleSheet
:
865 return getDOMStyleSheet(exec
, static_cast<CSSImportRuleImpl
*>(m_impl
.get())->styleSheet());
867 // for DOM::CSSRule::CHARSET_RULE:
868 case Charset_Encoding
:
869 return jsString(static_cast<CSSCharsetRuleImpl
*>(m_impl
.get())->encoding());
874 return jsUndefined();
877 void DOMCSSRule::put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
)
879 const HashTable
* table
= classInfo()->propHashTable
; // get the right hashtable
880 const HashEntry
* entry
= Lookup::findEntry(table
, propertyName
);
882 if (entry
->attr
& Function
) // function: put as override property
884 JSObject::put(exec
, propertyName
, value
, attr
);
887 else if ((entry
->attr
& ReadOnly
) == 0) // let lookupPut print the warning if not
889 putValueProperty(exec
, entry
->value
, value
, attr
);
893 lookupPut
<DOMCSSRule
, DOMObject
>(exec
, propertyName
, value
, attr
, &DOMCSSRuleTable
, this);
896 void DOMCSSRule::putValueProperty(ExecState
*exec
, int token
, JSValue
*value
, int)
899 // for DOM::CSSRule::STYLE_RULE:
900 case Style_SelectorText
:
901 static_cast<CSSStyleRuleImpl
*>(m_impl
.get())->setSelectorText(value
->toString(exec
).domString());
904 // for DOM::CSSRule::PAGE_RULE:
905 case Page_SelectorText
:
906 static_cast<CSSPageRuleImpl
*>(m_impl
.get())->setSelectorText(value
->toString(exec
).domString());
909 // for DOM::CSSRule::CHARSET_RULE:
910 case Charset_Encoding
:
911 static_cast<CSSCharsetRuleImpl
*>(m_impl
.get())->setEncoding(value
->toString(exec
).domString());
915 kDebug(6070) << "DOMCSSRule::putValueProperty unhandled token " << token
;
919 JSValue
*DOMCSSRuleFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
921 KJS_CHECK_THIS( KJS::DOMCSSRule
, thisObj
);
922 DOM::CSSRuleImpl
& cssRule
= *static_cast<DOMCSSRule
*>(thisObj
)->impl();
924 if (cssRule
.type() == DOM::CSSRule::MEDIA_RULE
) {
925 DOM::CSSMediaRuleImpl
& rule
= static_cast<DOM::CSSMediaRuleImpl
&>(cssRule
);
926 if (id
== DOMCSSRule::Media_InsertRule
)
927 return jsNumber(rule
.insertRule(args
[0]->toString(exec
).domString(),args
[1]->toInteger(exec
)));
928 else if (id
== DOMCSSRule::Media_DeleteRule
)
929 rule
.deleteRule(args
[0]->toInteger(exec
));
932 return jsUndefined();
935 JSValue
*getDOMCSSRule(ExecState
*exec
, DOM::CSSRuleImpl
* r
)
937 return cacheDOMObject
<DOM::CSSRuleImpl
, KJS::DOMCSSRule
>(exec
, r
);
940 // -------------------------------------------------------------------------
942 const ClassInfo
CSSRuleConstructor::info
= { "CSSRuleConstructor", 0, &CSSRuleConstructorTable
, 0 };
944 @begin CSSRuleConstructorTable 7
945 UNKNOWN_RULE CSSRuleConstructor::UNKNOWN_RULE DontDelete|ReadOnly
946 STYLE_RULE CSSRuleConstructor::STYLE_RULE DontDelete|ReadOnly
947 CHARSET_RULE CSSRuleConstructor::CHARSET_RULE DontDelete|ReadOnly
948 IMPORT_RULE CSSRuleConstructor::IMPORT_RULE DontDelete|ReadOnly
949 MEDIA_RULE CSSRuleConstructor::MEDIA_RULE DontDelete|ReadOnly
950 FONT_FACE_RULE CSSRuleConstructor::FONT_FACE_RULE DontDelete|ReadOnly
951 PAGE_RULE CSSRuleConstructor::PAGE_RULE DontDelete|ReadOnly
955 CSSRuleConstructor::CSSRuleConstructor(ExecState
*exec
)
957 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
960 bool CSSRuleConstructor::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
962 return getStaticValueSlot
<CSSRuleConstructor
, DOMObject
>(exec
, &CSSRuleConstructorTable
, this, propertyName
, slot
);
965 JSValue
*CSSRuleConstructor::getValueProperty(ExecState
*, int token
) const
969 return jsNumber(DOM::CSSRule::UNKNOWN_RULE
);
971 return jsNumber(DOM::CSSRule::STYLE_RULE
);
973 return jsNumber(DOM::CSSRule::CHARSET_RULE
);
975 return jsNumber(DOM::CSSRule::IMPORT_RULE
);
977 return jsNumber(DOM::CSSRule::MEDIA_RULE
);
979 return jsNumber(DOM::CSSRule::FONT_FACE_RULE
);
981 return jsNumber(DOM::CSSRule::PAGE_RULE
);
986 JSValue
*getCSSRuleConstructor(ExecState
*exec
)
988 return cacheGlobalObject
<CSSRuleConstructor
>( exec
, "[[cssRule.constructor]]" );
991 // -------------------------------------------------------------------------
993 const ClassInfo
DOMCSSValue::info
= { "CSSValue", 0, &DOMCSSValueTable
, 0 };
996 @begin DOMCSSValueTable 2
997 cssText DOMCSSValue::CssText DontDelete|ReadOnly
998 cssValueType DOMCSSValue::CssValueType DontDelete|ReadOnly
1002 DOMCSSValue::DOMCSSValue(ExecState
* exec
, DOM::CSSValueImpl
* val
)
1005 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
1008 DOMCSSValue::~DOMCSSValue()
1010 ScriptInterpreter::forgetDOMObject(m_impl
.get());
1013 JSValue
*DOMCSSValue::getValueProperty(ExecState
*, int token
) const
1015 CSSValueImpl
&cssValue
= *m_impl
;
1018 return jsString(cssValue
.cssText());
1020 return jsNumber(cssValue
.cssValueType());
1023 return jsUndefined();
1027 bool DOMCSSValue::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
1029 return getStaticValueSlot
<DOMCSSValue
, DOMObject
>(exec
, &DOMCSSValueTable
, this, propertyName
, slot
);
1032 void DOMCSSValue::put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
)
1034 CSSValueImpl
&cssValue
= *m_impl
;
1035 if (propertyName
== "cssText") {
1036 cssValue
.setCssText(value
->toString(exec
).domString());
1038 DOMObject::put(exec
, propertyName
, value
, attr
);
1041 JSValue
*getDOMCSSValue(ExecState
*exec
, DOM::CSSValueImpl
* v
)
1046 ScriptInterpreter
* interp
= static_cast<ScriptInterpreter
*>(exec
->dynamicInterpreter());
1047 if ((ret
= interp
->getDOMObject(v
)))
1050 if (v
->isValueList())
1051 ret
= new DOMCSSValueList(exec
, static_cast<CSSValueListImpl
*>(v
));
1052 else if (v
->isPrimitiveValue())
1053 ret
= new DOMCSSPrimitiveValue(exec
, static_cast<CSSPrimitiveValueImpl
*>(v
));
1055 ret
= new DOMCSSValue(exec
,v
);
1056 interp
->putDOMObject(v
,ret
);
1061 // -------------------------------------------------------------------------
1063 const ClassInfo
CSSValueConstructor::info
= { "CSSValueConstructor", 0, &CSSValueConstructorTable
, 0 };
1065 @begin CSSValueConstructorTable 5
1066 CSS_INHERIT CSSValueConstructor::CSS_INHERIT DontDelete|ReadOnly
1067 CSS_PRIMITIVE_VALUE CSSValueConstructor::CSS_PRIMITIVE_VALUE DontDelete|ReadOnly
1068 CSS_VALUE_LIST CSSValueConstructor::CSS_VALUE_LIST DontDelete|ReadOnly
1069 CSS_CUSTOM CSSValueConstructor::CSS_CUSTOM DontDelete|ReadOnly
1073 CSSValueConstructor::CSSValueConstructor(ExecState
*exec
)
1075 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
1078 bool CSSValueConstructor::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
1080 return getStaticValueSlot
<CSSValueConstructor
, DOMObject
>(exec
, &CSSValueConstructorTable
, this, propertyName
, slot
);
1083 JSValue
*CSSValueConstructor::getValueProperty(ExecState
*, int token
) const
1087 return jsNumber(DOM::CSSValue::CSS_INHERIT
);
1088 case CSS_PRIMITIVE_VALUE
:
1089 return jsNumber(DOM::CSSValue::CSS_PRIMITIVE_VALUE
);
1090 case CSS_VALUE_LIST
:
1091 return jsNumber(DOM::CSSValue::CSS_VALUE_LIST
);
1093 return jsNumber(DOM::CSSValue::CSS_CUSTOM
);
1098 JSValue
*getCSSValueConstructor(ExecState
*exec
)
1100 return cacheGlobalObject
<CSSValueConstructor
>( exec
, "[[cssValue.constructor]]" );
1103 // -------------------------------------------------------------------------
1105 const ClassInfo
DOMCSSPrimitiveValue::info
= { "CSSPrimitiveValue", 0, &DOMCSSPrimitiveValueTable
, 0 };
1107 @begin DOMCSSPrimitiveValueTable 1
1108 primitiveType DOMCSSPrimitiveValue::PrimitiveType DontDelete|ReadOnly
1110 @begin DOMCSSPrimitiveValueProtoTable 3
1111 setFloatValue DOMCSSPrimitiveValue::SetFloatValue DontDelete|Function 2
1112 getFloatValue DOMCSSPrimitiveValue::GetFloatValue DontDelete|Function 1
1113 setStringValue DOMCSSPrimitiveValue::SetStringValue DontDelete|Function 2
1114 getStringValue DOMCSSPrimitiveValue::GetStringValue DontDelete|Function 0
1115 getCounterValue DOMCSSPrimitiveValue::GetCounterValue DontDelete|Function 0
1116 getRectValue DOMCSSPrimitiveValue::GetRectValue DontDelete|Function 0
1117 getRGBColorValue DOMCSSPrimitiveValue::GetRGBColorValue DontDelete|Function 0
1120 KJS_DEFINE_PROTOTYPE(DOMCSSPrimitiveValueProto
)
1121 KJS_IMPLEMENT_PROTOFUNC(DOMCSSPrimitiveValueProtoFunc
)
1122 KJS_IMPLEMENT_PROTOTYPE("DOMCSSPrimitiveValue",DOMCSSPrimitiveValueProto
,DOMCSSPrimitiveValueProtoFunc
)
1124 DOMCSSPrimitiveValue::DOMCSSPrimitiveValue(ExecState
*exec
, DOM::CSSPrimitiveValueImpl
* v
)
1125 : DOMCSSValue(exec
, v
) {
1126 setPrototype(DOMCSSPrimitiveValueProto::self(exec
));
1129 JSValue
*DOMCSSPrimitiveValue::getValueProperty(ExecState
*, int token
)
1131 assert(token
== PrimitiveType
);
1132 return jsNumber(static_cast<CSSPrimitiveValueImpl
*>(impl())->primitiveType());
1135 bool DOMCSSPrimitiveValue::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
1137 return getStaticValueSlot
<DOMCSSPrimitiveValue
, DOMCSSValue
>(exec
, &DOMCSSPrimitiveValueTable
, this, propertyName
, slot
);
1140 JSValue
*DOMCSSPrimitiveValueProtoFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
1142 KJS_CHECK_THIS( KJS::DOMCSSPrimitiveValue
, thisObj
);
1143 CSSPrimitiveValueImpl
&val
= *static_cast<CSSPrimitiveValueImpl
*>(static_cast<DOMCSSPrimitiveValue
*>(thisObj
)->impl());
1144 DOMExceptionTranslator
exception(exec
);
1146 case DOMCSSPrimitiveValue::SetFloatValue
:
1147 val
.setFloatValue(args
[0]->toInteger(exec
),args
[1]->toNumber(exec
), exception
);
1148 return jsUndefined();
1149 case DOMCSSPrimitiveValue::GetFloatValue
:
1150 //### FIXME: exception?
1151 return jsNumber(val
.floatValue(args
[0]->toInteger(exec
)));
1152 case DOMCSSPrimitiveValue::SetStringValue
:
1153 val
.setStringValue(args
[0]->toInteger(exec
),args
[1]->toString(exec
).domString(), exception
);
1154 return jsUndefined();
1155 case DOMCSSPrimitiveValue::GetStringValue
:
1156 return jsString(DOM::DOMString(val
.getStringValue()));
1157 case DOMCSSPrimitiveValue::GetCounterValue
:
1158 return getDOMCounter(exec
,val
.getCounterValue());
1159 case DOMCSSPrimitiveValue::GetRectValue
:
1160 return getDOMRect(exec
,val
.getRectValue());
1161 case DOMCSSPrimitiveValue::GetRGBColorValue
:
1162 return getDOMRGBColor(exec
,val
.getRGBColorValue());
1164 return jsUndefined();
1168 // -------------------------------------------------------------------------
1170 const ClassInfo
CSSPrimitiveValueConstructor::info
= { "CSSPrimitiveValueConstructor", 0, &CSSPrimitiveValueConstructorTable
, 0 };
1173 @begin CSSPrimitiveValueConstructorTable 27
1174 CSS_UNKNOWN DOM::CSSPrimitiveValue::CSS_UNKNOWN DontDelete|ReadOnly
1175 CSS_NUMBER DOM::CSSPrimitiveValue::CSS_NUMBER DontDelete|ReadOnly
1176 CSS_PERCENTAGE DOM::CSSPrimitiveValue::CSS_PERCENTAGE DontDelete|ReadOnly
1177 CSS_EMS DOM::CSSPrimitiveValue::CSS_EMS DontDelete|ReadOnly
1178 CSS_EXS DOM::CSSPrimitiveValue::CSS_EXS DontDelete|ReadOnly
1179 CSS_PX DOM::CSSPrimitiveValue::CSS_PX DontDelete|ReadOnly
1180 CSS_CM DOM::CSSPrimitiveValue::CSS_CM DontDelete|ReadOnly
1181 CSS_MM DOM::CSSPrimitiveValue::CSS_MM DontDelete|ReadOnly
1182 CSS_IN DOM::CSSPrimitiveValue::CSS_IN DontDelete|ReadOnly
1183 CSS_PT DOM::CSSPrimitiveValue::CSS_PT DontDelete|ReadOnly
1184 CSS_PC DOM::CSSPrimitiveValue::CSS_PC DontDelete|ReadOnly
1185 CSS_DEG DOM::CSSPrimitiveValue::CSS_DEG DontDelete|ReadOnly
1186 CSS_RAD DOM::CSSPrimitiveValue::CSS_RAD DontDelete|ReadOnly
1187 CSS_GRAD DOM::CSSPrimitiveValue::CSS_GRAD DontDelete|ReadOnly
1188 CSS_MS DOM::CSSPrimitiveValue::CSS_MS DontDelete|ReadOnly
1189 CSS_S DOM::CSSPrimitiveValue::CSS_S DontDelete|ReadOnly
1190 CSS_HZ DOM::CSSPrimitiveValue::CSS_HZ DontDelete|ReadOnly
1191 CSS_KHZ DOM::CSSPrimitiveValue::CSS_KHZ DontDelete|ReadOnly
1192 CSS_DIMENSION DOM::CSSPrimitiveValue::CSS_DIMENSION DontDelete|ReadOnly
1193 CSS_STRING DOM::CSSPrimitiveValue::CSS_STRING DontDelete|ReadOnly
1194 CSS_URI DOM::CSSPrimitiveValue::CSS_URI DontDelete|ReadOnly
1195 CSS_IDENT DOM::CSSPrimitiveValue::CSS_IDENT DontDelete|ReadOnly
1196 CSS_ATTR DOM::CSSPrimitiveValue::CSS_ATTR DontDelete|ReadOnly
1197 CSS_COUNTER DOM::CSSPrimitiveValue::CSS_COUNTER DontDelete|ReadOnly
1198 CSS_RECT DOM::CSSPrimitiveValue::CSS_RECT DontDelete|ReadOnly
1199 CSS_RGBCOLOR DOM::CSSPrimitiveValue::CSS_RGBCOLOR DontDelete|ReadOnly
1203 bool CSSPrimitiveValueConstructor::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
) {
1204 return getStaticValueSlot
<CSSPrimitiveValueConstructor
, DOMObject
>(exec
, &CSSPrimitiveValueConstructorTable
, this, propertyName
, slot
);
1207 JSValue
*CSSPrimitiveValueConstructor::getValueProperty(ExecState
*, int token
) const
1209 // We use the token as the value to return directly
1210 return jsNumber(token
);
1213 JSValue
*getCSSPrimitiveValueConstructor(ExecState
*exec
)
1215 return cacheGlobalObject
<CSSPrimitiveValueConstructor
>( exec
, "[[cssPrimitiveValue.constructor]]" );
1218 // -------------------------------------------------------------------------
1220 const ClassInfo
DOMCSSValueList::info
= { "CSSValueList", 0, &DOMCSSValueListTable
, 0 };
1223 @begin DOMCSSValueListTable 3
1224 length DOMCSSValueList::Length DontDelete|ReadOnly
1225 item DOMCSSValueList::Item DontDelete|Function 1
1228 KJS_IMPLEMENT_PROTOFUNC(DOMCSSValueListFunc
) // not really a proto, but doesn't matter
1230 DOMCSSValueList::DOMCSSValueList(ExecState
*exec
, DOM::CSSValueListImpl
* v
)
1231 : DOMCSSValue(exec
, v
) { }
1234 JSValue
*DOMCSSValueList::indexGetter(ExecState
*exec
, unsigned index
)
1236 return getDOMCSSValue(exec
, impl()->item(index
));
1239 bool DOMCSSValueList::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
1241 if (getStaticOwnPropertySlot
<DOMCSSValueListFunc
, DOMCSSValueList
>(
1242 &DOMCSSValueListTable
, this, propertyName
, slot
))
1245 CSSValueListImpl
&valueList
= *static_cast<CSSValueListImpl
*>(impl());
1246 if (getIndexSlot(this, valueList
, propertyName
, slot
))
1249 return DOMCSSValue::getOwnPropertySlot(exec
, propertyName
, slot
);
1252 JSValue
*DOMCSSValueListFunc::callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
)
1254 KJS_CHECK_THIS( KJS::DOMCSSValueList
, thisObj
);
1255 CSSValueListImpl
&valueList
= *static_cast<CSSValueListImpl
*>(static_cast<DOMCSSValueList
*>(thisObj
)->impl());
1257 case DOMCSSValueList::Item
:
1258 return getDOMCSSValue(exec
,valueList
.item(args
[0]->toInteger(exec
)));
1260 return jsUndefined();
1264 // -------------------------------------------------------------------------
1266 const ClassInfo
DOMRGBColor::info
= { "RGBColor", 0, &DOMRGBColorTable
, 0 };
1269 @begin DOMRGBColorTable 3
1270 red DOMRGBColor::Red DontDelete|ReadOnly
1271 green DOMRGBColor::Green DontDelete|ReadOnly
1272 blue DOMRGBColor::Blue DontDelete|ReadOnly
1276 DOMRGBColor::DOMRGBColor(ExecState
* exec
, QRgb c
)
1279 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
1282 bool DOMRGBColor::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
) {
1283 return getStaticValueSlot
<DOMRGBColor
, DOMObject
>(exec
, &DOMRGBColorTable
, this, propertyName
, slot
);
1286 JSValue
*DOMRGBColor::getValueProperty(ExecState
*exec
, int token
) const
1291 color
= qRed(m_color
); break;
1293 color
= qGreen(m_color
); break;
1295 color
= qBlue(m_color
); break;
1298 return jsUndefined();
1301 return new DOMCSSPrimitiveValue(exec
, new CSSPrimitiveValueImpl(color
, CSSPrimitiveValue::CSS_NUMBER
));
1304 JSValue
*getDOMRGBColor(ExecState
*exec
, unsigned color
)
1306 // ### implement equals for RGBColor since they're not refcounted objects
1307 return new DOMRGBColor(exec
, color
);
1310 // -------------------------------------------------------------------------
1312 const ClassInfo
DOMRect::info
= { "Rect", 0, &DOMRectTable
, 0 };
1314 @begin DOMRectTable 4
1315 top DOMRect::Top DontDelete|ReadOnly
1316 right DOMRect::Right DontDelete|ReadOnly
1317 bottom DOMRect::Bottom DontDelete|ReadOnly
1318 left DOMRect::Left DontDelete|ReadOnly
1322 DOMRect::DOMRect(ExecState
*exec
, DOM::RectImpl
* r
)
1325 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
1330 ScriptInterpreter::forgetDOMObject(m_impl
.get());
1333 bool DOMRect::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
1335 return getStaticValueSlot
<DOMRect
, DOMObject
>(exec
, &DOMRectTable
, this, propertyName
, slot
);
1338 JSValue
*DOMRect::getValueProperty(ExecState
*exec
, int token
) const
1340 DOM::RectImpl
& rect
= *m_impl
;
1343 return getDOMCSSValue(exec
, rect
.top());
1345 return getDOMCSSValue(exec
, rect
.right());
1347 return getDOMCSSValue(exec
, rect
.bottom());
1349 return getDOMCSSValue(exec
, rect
.left());
1355 JSValue
*getDOMRect(ExecState
*exec
, DOM::RectImpl
* r
)
1357 return cacheDOMObject
<DOM::RectImpl
, KJS::DOMRect
>(exec
, r
);
1360 // -------------------------------------------------------------------------
1362 const ClassInfo
DOMCounter::info
= { "Counter", 0, &DOMCounterTable
, 0 };
1364 @begin DOMCounterTable 3
1365 identifier DOMCounter::identifier DontDelete|ReadOnly
1366 listStyle DOMCounter::listStyle DontDelete|ReadOnly
1367 separator DOMCounter::separator DontDelete|ReadOnly
1370 DOMCounter::DOMCounter(ExecState
*exec
, DOM::CounterImpl
* c
)
1373 setPrototype(exec
->lexicalInterpreter()->builtinObjectPrototype());
1376 DOMCounter::~DOMCounter()
1378 ScriptInterpreter::forgetDOMObject(m_impl
.get());
1381 bool DOMCounter::getOwnPropertySlot(ExecState
*exec
, const Identifier
& propertyName
, PropertySlot
& slot
)
1383 return getStaticValueSlot
<DOMCounter
, DOMObject
>(exec
, &DOMCounterTable
, this, propertyName
, slot
);
1386 JSValue
*DOMCounter::getValueProperty(ExecState
*, int token
) const
1388 CounterImpl
&counter
= *m_impl
;
1391 return jsString(counter
.identifier());
1393 return jsString(khtml::stringForListStyleType((khtml::EListStyleType
)counter
.listStyle()));
1395 return jsString(counter
.separator());
1401 JSValue
*getDOMCounter(ExecState
*exec
, DOM::CounterImpl
* c
)
1403 return cacheDOMObject
<DOM::CounterImpl
, KJS::DOMCounter
>(exec
, c
);