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
26 #include <dom/dom_node.h>
27 #include <dom/dom_doc.h>
28 #include <kjs/object.h>
29 #include "css/css_base.h"
30 #include "css/css_ruleimpl.h"
31 #include "css/css_stylesheetimpl.h"
32 #include "css/css_valueimpl.h"
33 #include "kjs_binding.h"
37 class DOMCSSStyleDeclaration
: public DOMObject
{
39 DOMCSSStyleDeclaration(ExecState
*exec
, DOM::CSSStyleDeclarationImpl
* s
);
40 virtual ~DOMCSSStyleDeclaration();
41 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
42 virtual void put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
= None
);
43 JSValue
*getValueProperty(ExecState
*exec
, int token
);
45 virtual const ClassInfo
*classInfo() const { return &info
; }
46 static const ClassInfo info
;
47 enum { CssText
, Length
, ParentRule
,
48 GetPropertyValue
, GetPropertyCSSValue
, RemoveProperty
, GetPropertyPriority
,
51 DOM::CSSStyleDeclarationImpl
*impl() const { return m_impl
.get(); }
53 JSValue
*indexGetter(ExecState
* exec
, unsigned index
);
55 SharedPtr
<DOM::CSSStyleDeclarationImpl
> m_impl
;
58 DEFINE_PSEUDO_CONSTRUCTOR(CSSStyleDeclarationPseudoCtor
)
59 JSValue
* getDOMCSSStyleDeclaration(ExecState
*exec
, DOM::CSSStyleDeclarationImpl
* n
);
61 class DOMStyleSheet
: public DOMObject
{
63 // Build a DOMStyleSheet
64 DOMStyleSheet(ExecState
*, DOM::StyleSheetImpl
* ss
);
65 virtual ~DOMStyleSheet();
67 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
68 JSValue
* getValueProperty(ExecState
*exec
, int token
) const;
69 virtual void put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
* value
, int attr
= None
);
70 virtual bool toBoolean(ExecState
*) const { return true; }
71 virtual const ClassInfo
* classInfo() const { return &info
; }
72 static const ClassInfo info
;
73 enum { Type
, Disabled
, OwnerNode
, ParentStyleSheet
, Href
, Title
, Media
};
75 SharedPtr
<DOM::StyleSheetImpl
> m_impl
;
78 JSValue
* getDOMStyleSheet(ExecState
*exec
, DOM::StyleSheetImpl
* ss
);
80 class DOMStyleSheetList
: public DOMObject
{
82 DOMStyleSheetList(ExecState
*, DOM::StyleSheetListImpl
* ssl
, DOM::DocumentImpl
* doc
);
83 virtual ~DOMStyleSheetList();
85 JSValue
*getValueProperty(ExecState
*exec
, int token
) const;
86 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
87 virtual JSValue
* callAsFunction(ExecState
*exec
, JSObject
* thisObj
, const List
&args
);
88 virtual bool implementsCall() const { return true; }
89 virtual bool isFunctionType() const { return false; }
90 // no put - all read-only
91 virtual const ClassInfo
* classInfo() const { return &info
; }
92 virtual bool toBoolean(ExecState
* ) const { return true; }
93 static const ClassInfo info
;
95 DOM::StyleSheetListImpl
* impl() const { return m_impl
.get(); }
96 enum { Item
, Length
};
97 JSValue
*indexGetter(ExecState
* exec
, unsigned index
);
99 static JSValue
*nameGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
101 SharedPtr
<DOM::StyleSheetListImpl
> m_impl
;
102 SharedPtr
<DOM::DocumentImpl
> m_doc
;
105 // The document is only used for get-stylesheet-by-name (make optional if necessary)
106 JSValue
* getDOMStyleSheetList(ExecState
*exec
, DOM::StyleSheetListImpl
* ss
, DOM::DocumentImpl
* doc
);
108 class DOMMediaList
: public DOMObject
{
110 DOMMediaList(ExecState
*, DOM::MediaListImpl
* ml
);
111 virtual ~DOMMediaList();
113 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
114 JSValue
* getValueProperty(ExecState
*exec
, int token
) const;
115 virtual void put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
* value
, int attr
= None
);
116 virtual const ClassInfo
* classInfo() const { return &info
; }
117 virtual bool toBoolean(ExecState
* ) const { return true; }
118 static const ClassInfo info
;
119 enum { MediaText
, Length
,
120 Item
, DeleteMedium
, AppendMedium
};
121 DOM::MediaListImpl
* impl() const { return m_impl
.get(); }
122 JSValue
*indexGetter(ExecState
* exec
, unsigned index
);
124 SharedPtr
<DOM::MediaListImpl
> m_impl
;
127 JSValue
* getDOMMediaList(ExecState
*exec
, DOM::MediaListImpl
* ss
);
129 class DOMCSSStyleSheet
: public DOMStyleSheet
{
131 DOMCSSStyleSheet(ExecState
*exec
, DOM::CSSStyleSheetImpl
* ss
);
132 virtual ~DOMCSSStyleSheet();
133 JSValue
* getValueProperty(ExecState
*exec
, int token
);
134 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
135 // no put - all read-only
136 virtual const ClassInfo
* classInfo() const { return &info
; }
137 static const ClassInfo info
;
138 enum { OwnerRule
, CssRules
, Rules
,
139 InsertRule
, DeleteRule
, AddRule
, RemoveRule
};
140 DOM::CSSStyleSheetImpl
* impl() const { return static_cast<DOM::CSSStyleSheetImpl
*>(m_impl
.get()); }
143 class DOMCSSRuleList
: public DOMObject
{
145 DOMCSSRuleList(ExecState
*, DOM::CSSRuleListImpl
* rl
);
146 virtual ~DOMCSSRuleList();
147 JSValue
*getValueProperty(ExecState
*exec
, int token
) const;
148 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
149 // no put - all read-only
150 virtual const ClassInfo
* classInfo() const { return &info
; }
151 static const ClassInfo info
;
152 enum { Item
, Length
};
153 DOM::CSSRuleListImpl
* impl() const { return m_impl
.get(); }
154 JSValue
*indexGetter(ExecState
* exec
, unsigned index
);
156 SharedPtr
<DOM::CSSRuleListImpl
> m_impl
;
160 JSValue
* getDOMCSSRuleList(ExecState
*exec
, DOM::CSSRuleListImpl
* rl
);
162 class DOMCSSRule
: public DOMObject
{
164 DOMCSSRule(ExecState
*, DOM::CSSRuleImpl
* r
);
165 virtual ~DOMCSSRule();
166 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
167 JSValue
* getValueProperty(ExecState
*exec
, int token
) const;
168 virtual void put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
* value
, int attr
= None
);
169 void putValueProperty(ExecState
*exec
, int token
, JSValue
* value
, int attr
);
170 virtual const ClassInfo
* classInfo() const;
171 static const ClassInfo info
;
172 static const ClassInfo style_info
, media_info
, fontface_info
, page_info
, import_info
, charset_info
;
173 enum { ParentStyleSheet
, Type
, CssText
, ParentRule
,
174 Style_SelectorText
, Style_Style
,
175 Media_Media
, Media_InsertRule
, Media_DeleteRule
, Media_CssRules
,
176 FontFace_Style
, Page_SelectorText
, Page_Style
,
177 Import_Href
, Import_Media
, Import_StyleSheet
, Charset_Encoding
};
178 DOM::CSSRuleImpl
* impl() const { return m_impl
.get(); }
179 JSValue
*indexGetter(ExecState
* exec
, unsigned index
);
181 SharedPtr
<DOM::CSSRuleImpl
> m_impl
;
184 JSValue
* getDOMCSSRule(ExecState
*exec
, DOM::CSSRuleImpl
* r
);
186 // Constructor for CSSRule - currently only used for some global values
187 class CSSRuleConstructor
: public DOMObject
{
189 CSSRuleConstructor(ExecState
*);
190 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
191 JSValue
* getValueProperty(ExecState
*exec
, int token
) const;
192 // no put - all read-only
193 virtual const ClassInfo
* classInfo() const { return &info
; }
194 static const ClassInfo info
;
195 enum { UNKNOWN_RULE
, STYLE_RULE
, CHARSET_RULE
, IMPORT_RULE
, MEDIA_RULE
, FONT_FACE_RULE
, PAGE_RULE
};
198 JSValue
* getCSSRuleConstructor(ExecState
*exec
);
200 class DOMCSSValue
: public DOMObject
{
202 DOMCSSValue(ExecState
*, DOM::CSSValueImpl
* v
);
203 virtual ~DOMCSSValue();
204 JSValue
* getValueProperty(ExecState
*exec
, int token
) const;
205 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
206 virtual void put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
* value
, int attr
= None
);
207 virtual const ClassInfo
* classInfo() const { return &info
; }
208 static const ClassInfo info
;
209 enum { CssText
, CssValueType
};
211 SharedPtr
<DOM::CSSValueImpl
> m_impl
;
214 JSValue
* getDOMCSSValue(ExecState
*exec
, DOM::CSSValueImpl
* v
);
216 // Constructor for CSSValue - currently only used for some global values
217 class CSSValueConstructor
: public DOMObject
{
219 CSSValueConstructor(ExecState
*exec
);
220 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
221 JSValue
* getValueProperty(ExecState
*exec
, int token
) const;
222 // no put - all read-only
223 virtual const ClassInfo
* classInfo() const { return &info
; }
224 static const ClassInfo info
;
225 enum { CSS_VALUE_LIST
, CSS_PRIMITIVE_VALUE
, CSS_CUSTOM
, CSS_INHERIT
};
228 JSValue
* getCSSValueConstructor(ExecState
*exec
);
230 class DOMCSSPrimitiveValue
: public DOMCSSValue
{
232 DOMCSSPrimitiveValue(ExecState
*exec
, DOM::CSSPrimitiveValueImpl
* v
);
233 JSValue
*getValueProperty(ExecState
*exec
, int token
);
234 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
235 // no put - all read-only
236 virtual const ClassInfo
* classInfo() const { return &info
; }
237 static const ClassInfo info
;
238 DOM::CSSPrimitiveValueImpl
* impl() const { return static_cast<DOM::CSSPrimitiveValueImpl
*>(m_impl
.get()); }
239 enum { PrimitiveType
, SetFloatValue
, GetFloatValue
, SetStringValue
, GetStringValue
,
240 GetCounterValue
, GetRectValue
, GetRGBColorValue
};
243 // Constructor for CSSPrimitiveValue - currently only used for some global values
244 class CSSPrimitiveValueConstructor
: public CSSValueConstructor
{
246 CSSPrimitiveValueConstructor(ExecState
*exec
) : CSSValueConstructor(exec
) { }
247 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
248 JSValue
* getValueProperty(ExecState
*exec
, int token
) const;
249 // no put - all read-only
250 virtual const ClassInfo
* classInfo() const { return &info
; }
251 static const ClassInfo info
;
254 JSValue
* getCSSPrimitiveValueConstructor(ExecState
*exec
);
256 class DOMCSSValueList
: public DOMCSSValue
{
258 DOMCSSValueList(ExecState
*exec
, DOM::CSSValueListImpl
* v
);
259 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
260 // no put - all read-only
261 virtual const ClassInfo
* classInfo() const { return &info
; }
262 static const ClassInfo info
;
263 enum { Item
, Length
};
264 DOM::CSSValueListImpl
* impl() const { return static_cast<DOM::CSSValueListImpl
*>(m_impl
.get()); }
265 JSValue
*indexGetter(ExecState
* exec
, unsigned index
);
268 class DOMRGBColor
: public DOMObject
{
270 DOMRGBColor(ExecState
* exec
, QRgb color
);
271 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
272 JSValue
*getValueProperty(ExecState
*exec
, int token
) const;
273 // no put - all read-only
274 virtual const ClassInfo
* classInfo() const { return &info
; }
275 static const ClassInfo info
;
276 enum { Red
, Green
, Blue
};
281 JSValue
*getDOMRGBColor(ExecState
*exec
, unsigned color
);
283 class DOMRect
: public DOMObject
{
285 DOMRect(ExecState
*, DOM::RectImpl
*r
);
287 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
288 JSValue
*getValueProperty(ExecState
*exec
, int token
) const;
289 // no put - all read-only
290 virtual const ClassInfo
* classInfo() const { return &info
; }
291 static const ClassInfo info
;
292 enum { Top
, Right
, Bottom
, Left
};
294 SharedPtr
<DOM::RectImpl
> m_impl
;
297 JSValue
*getDOMRect(ExecState
*exec
, DOM::RectImpl
*r
);
299 class DOMCounter
: public DOMObject
{
301 DOMCounter(ExecState
*, DOM::CounterImpl
*c
);
303 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
304 JSValue
*getValueProperty(ExecState
*exec
, int token
) const;
305 // no put - all read-only
306 virtual const ClassInfo
* classInfo() const { return &info
; }
307 static const ClassInfo info
;
308 enum { identifier
, listStyle
, separator
};
310 SharedPtr
<DOM::CounterImpl
> m_impl
;
313 JSValue
*getDOMCounter(ExecState
*exec
, DOM::CounterImpl
*c
);