File indexing completed on 2023-10-03 03:17:39
0001 /* 0002 * This file is part of the KDE libraries 0003 * Copyright (C) 2000 Harri Porten (porten@kde.org) 0004 * Copyright (C) 2001 Peter Kelly (pmk@post.com) 0005 * Copyright (C) 2003 Apple Computer, Inc. 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Library General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Library General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Library General Public 0018 * License along with this library; if not, write to the Free Software 0019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0020 */ 0021 0022 #ifndef _KJS_CSS_H_ 0023 #define _KJS_CSS_H_ 0024 0025 #include <dom/dom_node.h> 0026 #include <dom/dom_doc.h> 0027 #include <kjs/object.h> 0028 #include "css/css_base.h" 0029 #include "css/css_ruleimpl.h" 0030 #include "css/css_stylesheetimpl.h" 0031 #include "css/css_valueimpl.h" 0032 #include "kjs_binding.h" 0033 0034 namespace KJS 0035 { 0036 0037 class DOMCSSStyleDeclaration : public DOMObject 0038 { 0039 public: 0040 DOMCSSStyleDeclaration(ExecState *exec, DOM::CSSStyleDeclarationImpl *s); 0041 virtual ~DOMCSSStyleDeclaration(); 0042 using KJS::JSObject::getOwnPropertySlot; 0043 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0044 void getOwnPropertyNames(ExecState *, PropertyNameArray &, PropertyMap::PropertyMode mode) override; 0045 using KJS::JSObject::put; 0046 void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override; 0047 JSValue *getValueProperty(ExecState *exec, int token); 0048 0049 const ClassInfo *classInfo() const override 0050 { 0051 return &info; 0052 } 0053 static const ClassInfo info; 0054 enum { CssText, Length, ParentRule, 0055 GetPropertyValue, GetPropertyCSSValue, RemoveProperty, GetPropertyPriority, 0056 SetProperty, Item 0057 }; 0058 0059 DOM::CSSStyleDeclarationImpl *impl() const 0060 { 0061 return m_impl.get(); 0062 } 0063 0064 JSValue *indexGetter(ExecState *exec, unsigned index); 0065 private: 0066 SharedPtr<DOM::CSSStyleDeclarationImpl> m_impl; 0067 }; 0068 0069 DEFINE_PSEUDO_CONSTRUCTOR(CSSStyleDeclarationPseudoCtor) 0070 JSValue *getDOMCSSStyleDeclaration(ExecState *exec, DOM::CSSStyleDeclarationImpl *n); 0071 0072 class DOMStyleSheet : public DOMObject 0073 { 0074 public: 0075 // Build a DOMStyleSheet 0076 DOMStyleSheet(ExecState *, DOM::StyleSheetImpl *ss); 0077 virtual ~DOMStyleSheet(); 0078 0079 using KJS::JSObject::getOwnPropertySlot; 0080 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0081 JSValue *getValueProperty(ExecState *exec, int token) const; 0082 using KJS::JSObject::put; 0083 void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override; 0084 bool toBoolean(ExecState *) const override 0085 { 0086 return true; 0087 } 0088 const ClassInfo *classInfo() const override 0089 { 0090 return &info; 0091 } 0092 static const ClassInfo info; 0093 enum { Type, Disabled, OwnerNode, ParentStyleSheet, Href, Title, Media }; 0094 protected: 0095 SharedPtr<DOM::StyleSheetImpl> m_impl; 0096 }; 0097 DEFINE_PSEUDO_CONSTRUCTOR(DOMStyleSheetPseudoCtor) 0098 0099 JSValue *getDOMStyleSheet(ExecState *exec, DOM::StyleSheetImpl *ss); 0100 0101 class DOMStyleSheetList : public DOMObject 0102 { 0103 public: 0104 DOMStyleSheetList(ExecState *, DOM::StyleSheetListImpl *ssl, DOM::DocumentImpl *doc); 0105 virtual ~DOMStyleSheetList(); 0106 0107 JSValue *getValueProperty(ExecState *exec, int token) const; 0108 using KJS::JSObject::getOwnPropertySlot; 0109 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0110 JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override; 0111 bool implementsCall() const override 0112 { 0113 return true; 0114 } 0115 bool isFunctionType() const override 0116 { 0117 return false; 0118 } 0119 // no put - all read-only 0120 const ClassInfo *classInfo() const override 0121 { 0122 return &info; 0123 } 0124 bool toBoolean(ExecState *) const override 0125 { 0126 return true; 0127 } 0128 static const ClassInfo info; 0129 0130 DOM::StyleSheetListImpl *impl() const 0131 { 0132 return m_impl.get(); 0133 } 0134 enum { Item, Length }; 0135 JSValue *indexGetter(ExecState *exec, unsigned index); 0136 private: 0137 static JSValue *nameGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot &); 0138 0139 SharedPtr<DOM::StyleSheetListImpl> m_impl; 0140 SharedPtr<DOM::DocumentImpl> m_doc; 0141 }; 0142 0143 // The document is only used for get-stylesheet-by-name (make optional if necessary) 0144 JSValue *getDOMStyleSheetList(ExecState *exec, DOM::StyleSheetListImpl *ss, DOM::DocumentImpl *doc); 0145 0146 class DOMMediaList : public DOMObject 0147 { 0148 public: 0149 DOMMediaList(ExecState *, DOM::MediaListImpl *ml); 0150 virtual ~DOMMediaList(); 0151 0152 using KJS::JSObject::getOwnPropertySlot; 0153 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0154 JSValue *getValueProperty(ExecState *exec, int token) const; 0155 using KJS::JSObject::put; 0156 void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override; 0157 const ClassInfo *classInfo() const override 0158 { 0159 return &info; 0160 } 0161 bool toBoolean(ExecState *) const override 0162 { 0163 return true; 0164 } 0165 static const ClassInfo info; 0166 enum { MediaText, Length, 0167 Item, DeleteMedium, AppendMedium 0168 }; 0169 DOM::MediaListImpl *impl() const 0170 { 0171 return m_impl.get(); 0172 } 0173 JSValue *indexGetter(ExecState *exec, unsigned index); 0174 private: 0175 SharedPtr<DOM::MediaListImpl> m_impl; 0176 }; 0177 0178 JSValue *getDOMMediaList(ExecState *exec, DOM::MediaListImpl *ss); 0179 0180 class DOMCSSStyleSheet : public DOMStyleSheet 0181 { 0182 public: 0183 DOMCSSStyleSheet(ExecState *exec, DOM::CSSStyleSheetImpl *ss); 0184 virtual ~DOMCSSStyleSheet(); 0185 JSValue *getValueProperty(ExecState *exec, int token); 0186 using KJS::JSObject::getOwnPropertySlot; 0187 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0188 // no put - all read-only 0189 const ClassInfo *classInfo() const override 0190 { 0191 return &info; 0192 } 0193 static const ClassInfo info; 0194 enum { OwnerRule, CssRules, Rules, 0195 InsertRule, DeleteRule, AddRule, RemoveRule 0196 }; 0197 DOM::CSSStyleSheetImpl *impl() const 0198 { 0199 return static_cast<DOM::CSSStyleSheetImpl *>(m_impl.get()); 0200 } 0201 }; 0202 0203 class DOMCSSRuleList : public DOMObject 0204 { 0205 public: 0206 DOMCSSRuleList(ExecState *, DOM::CSSRuleListImpl *rl); 0207 virtual ~DOMCSSRuleList(); 0208 JSValue *getValueProperty(ExecState *exec, int token) const; 0209 using KJS::JSObject::getOwnPropertySlot; 0210 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0211 // no put - all read-only 0212 const ClassInfo *classInfo() const override 0213 { 0214 return &info; 0215 } 0216 static const ClassInfo info; 0217 enum { Item, Length }; 0218 DOM::CSSRuleListImpl *impl() const 0219 { 0220 return m_impl.get(); 0221 } 0222 JSValue *indexGetter(ExecState *exec, unsigned index); 0223 protected: 0224 SharedPtr<DOM::CSSRuleListImpl> m_impl; 0225 private: 0226 }; 0227 0228 JSValue *getDOMCSSRuleList(ExecState *exec, DOM::CSSRuleListImpl *rl); 0229 0230 class DOMCSSRule : public DOMObject 0231 { 0232 public: 0233 DOMCSSRule(ExecState *, DOM::CSSRuleImpl *r); 0234 virtual ~DOMCSSRule(); 0235 using KJS::JSObject::getOwnPropertySlot; 0236 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0237 JSValue *getValueProperty(ExecState *exec, int token) const; 0238 using KJS::JSObject::put; 0239 void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override; 0240 void putValueProperty(ExecState *exec, int token, JSValue *value, int attr); 0241 const ClassInfo *classInfo() const override; 0242 static const ClassInfo info; 0243 static const ClassInfo style_info, media_info, fontface_info, page_info, import_info, charset_info, namespace_info; 0244 enum { ParentStyleSheet, Type, CssText, ParentRule, 0245 Style_SelectorText, Style_Style, 0246 Media_Media, Media_InsertRule, Media_DeleteRule, Media_CssRules, 0247 FontFace_Style, Page_SelectorText, Page_Style, 0248 Import_Href, Import_Media, Import_StyleSheet, Charset_Encoding, 0249 Namespace_NamespaceURI, Namespace_Prefix 0250 }; 0251 DOM::CSSRuleImpl *impl() const 0252 { 0253 return m_impl.get(); 0254 } 0255 JSValue *indexGetter(ExecState *exec, unsigned index); 0256 protected: 0257 SharedPtr<DOM::CSSRuleImpl> m_impl; 0258 }; 0259 0260 JSValue *getDOMCSSRule(ExecState *exec, DOM::CSSRuleImpl *r); 0261 0262 // Constructor for CSSRule - currently only used for some global values 0263 class CSSRuleConstructor : public DOMObject 0264 { 0265 public: 0266 CSSRuleConstructor(ExecState *); 0267 using KJS::JSObject::getOwnPropertySlot; 0268 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0269 JSValue *getValueProperty(ExecState *exec, int token) const; 0270 // no put - all read-only 0271 const ClassInfo *classInfo() const override 0272 { 0273 return &info; 0274 } 0275 static const ClassInfo info; 0276 enum { UNKNOWN_RULE, STYLE_RULE, CHARSET_RULE, IMPORT_RULE, MEDIA_RULE, FONT_FACE_RULE, PAGE_RULE }; 0277 }; 0278 0279 JSValue *getCSSRuleConstructor(ExecState *exec); 0280 0281 class DOMCSSValue : public DOMObject 0282 { 0283 public: 0284 DOMCSSValue(ExecState *, DOM::CSSValueImpl *v); 0285 virtual ~DOMCSSValue(); 0286 JSValue *getValueProperty(ExecState *exec, int token) const; 0287 using KJS::JSObject::getOwnPropertySlot; 0288 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0289 using KJS::JSObject::put; 0290 void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override; 0291 const ClassInfo *classInfo() const override 0292 { 0293 return &info; 0294 } 0295 static const ClassInfo info; 0296 enum { CssText, CssValueType }; 0297 protected: 0298 SharedPtr<DOM::CSSValueImpl> m_impl; 0299 }; 0300 0301 JSValue *getDOMCSSValue(ExecState *exec, DOM::CSSValueImpl *v); 0302 0303 // Constructor for CSSValue - currently only used for some global values 0304 class CSSValueConstructor : public DOMObject 0305 { 0306 public: 0307 CSSValueConstructor(ExecState *exec); 0308 using KJS::JSObject::getOwnPropertySlot; 0309 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0310 JSValue *getValueProperty(ExecState *exec, int token) const; 0311 // no put - all read-only 0312 const ClassInfo *classInfo() const override 0313 { 0314 return &info; 0315 } 0316 static const ClassInfo info; 0317 enum { CSS_VALUE_LIST, CSS_PRIMITIVE_VALUE, CSS_CUSTOM, CSS_INHERIT }; 0318 }; 0319 0320 JSValue *getCSSValueConstructor(ExecState *exec); 0321 0322 class DOMCSSPrimitiveValue : public DOMCSSValue 0323 { 0324 public: 0325 DOMCSSPrimitiveValue(ExecState *exec, DOM::CSSPrimitiveValueImpl *v); 0326 JSValue *getValueProperty(ExecState *exec, int token); 0327 using KJS::JSObject::getOwnPropertySlot; 0328 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0329 // no put - all read-only 0330 const ClassInfo *classInfo() const override 0331 { 0332 return &info; 0333 } 0334 static const ClassInfo info; 0335 DOM::CSSPrimitiveValueImpl *impl() const 0336 { 0337 return static_cast<DOM::CSSPrimitiveValueImpl *>(m_impl.get()); 0338 } 0339 enum { PrimitiveType, SetFloatValue, GetFloatValue, SetStringValue, GetStringValue, 0340 GetCounterValue, GetRectValue, GetRGBColorValue 0341 }; 0342 }; 0343 0344 // Constructor for CSSPrimitiveValue - currently only used for some global values 0345 class CSSPrimitiveValueConstructor : public CSSValueConstructor 0346 { 0347 public: 0348 CSSPrimitiveValueConstructor(ExecState *exec) : CSSValueConstructor(exec) { } 0349 using KJS::JSObject::getOwnPropertySlot; 0350 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0351 JSValue *getValueProperty(ExecState *exec, int token) const; 0352 // no put - all read-only 0353 const ClassInfo *classInfo() const override 0354 { 0355 return &info; 0356 } 0357 static const ClassInfo info; 0358 }; 0359 0360 JSValue *getCSSPrimitiveValueConstructor(ExecState *exec); 0361 0362 class DOMCSSValueList : public DOMCSSValue 0363 { 0364 public: 0365 DOMCSSValueList(ExecState *exec, DOM::CSSValueListImpl *v); 0366 using KJS::JSObject::getOwnPropertySlot; 0367 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0368 // no put - all read-only 0369 const ClassInfo *classInfo() const override 0370 { 0371 return &info; 0372 } 0373 static const ClassInfo info; 0374 enum { Item, Length }; 0375 DOM::CSSValueListImpl *impl() const 0376 { 0377 return static_cast<DOM::CSSValueListImpl *>(m_impl.get()); 0378 } 0379 JSValue *indexGetter(ExecState *exec, unsigned index); 0380 }; 0381 0382 class DOMRGBColor : public DOMObject 0383 { 0384 public: 0385 DOMRGBColor(ExecState *exec, QRgb color); 0386 using KJS::JSObject::getOwnPropertySlot; 0387 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0388 JSValue *getValueProperty(ExecState *exec, int token) const; 0389 // no put - all read-only 0390 const ClassInfo *classInfo() const override 0391 { 0392 return &info; 0393 } 0394 static const ClassInfo info; 0395 enum { Red, Green, Blue }; 0396 private: 0397 QRgb m_color; 0398 }; 0399 0400 JSValue *getDOMRGBColor(ExecState *exec, unsigned color); 0401 0402 class DOMRect : public DOMObject 0403 { 0404 public: 0405 DOMRect(ExecState *, DOM::RectImpl *r); 0406 ~DOMRect(); 0407 using KJS::JSObject::getOwnPropertySlot; 0408 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0409 JSValue *getValueProperty(ExecState *exec, int token) const; 0410 // no put - all read-only 0411 const ClassInfo *classInfo() const override 0412 { 0413 return &info; 0414 } 0415 static const ClassInfo info; 0416 enum { Top, Right, Bottom, Left }; 0417 private: 0418 SharedPtr<DOM::RectImpl> m_impl; 0419 }; 0420 0421 JSValue *getDOMRect(ExecState *exec, DOM::RectImpl *r); 0422 0423 class DOMCounter : public DOMObject 0424 { 0425 public: 0426 DOMCounter(ExecState *, DOM::CounterImpl *c); 0427 ~DOMCounter(); 0428 using KJS::JSObject::getOwnPropertySlot; 0429 bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override; 0430 JSValue *getValueProperty(ExecState *exec, int token) const; 0431 // no put - all read-only 0432 const ClassInfo *classInfo() const override 0433 { 0434 return &info; 0435 } 0436 static const ClassInfo info; 0437 enum { identifier, listStyle, separator }; 0438 protected: 0439 SharedPtr<DOM::CounterImpl> m_impl; 0440 }; 0441 0442 JSValue *getDOMCounter(ExecState *exec, DOM::CounterImpl *c); 0443 } // namespace 0444 0445 #endif