kjs_css.h

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 2000 Harri Porten (porten@kde.org)
00005  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
00006  *  Copyright (C) 2003 Apple Computer, Inc.
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Library General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2 of the License, or (at your option) any later version.
00012  *
00013  *  This library is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Library General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Library General Public
00019  *  License along with this library; if not, write to the Free Software
00020  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  */
00022 
00023 #ifndef _KJS_CSS_H_
00024 #define _KJS_CSS_H_
00025 
00026 #include <dom/dom_node.h>
00027 #include <dom/dom_doc.h>
00028 #include <kjs/object.h>
00029 #include <dom/css_value.h>
00030 #include <dom/css_stylesheet.h>
00031 #include <dom/css_rule.h>
00032 #include "kjs_binding.h"
00033 
00034 namespace KJS {
00035 
00036   class DOMCSSStyleDeclaration : public DOMObject {
00037   public:
00038     DOMCSSStyleDeclaration(ExecState *exec, const DOM::CSSStyleDeclaration& s);
00039     virtual ~DOMCSSStyleDeclaration();
00040     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00041     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00042     virtual bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
00043     virtual const ClassInfo *classInfo() const { return &info; }
00044     static const ClassInfo info;
00045     enum { CssText, Length, ParentRule,
00046            GetPropertyValue, GetPropertyCSSValue, RemoveProperty, GetPropertyPriority,
00047            SetProperty, Item };
00048     DOM::CSSStyleDeclaration toStyleDecl() const { return styleDecl; }
00049   protected:
00050     DOM::CSSStyleDeclaration styleDecl;
00051   };
00052 
00053   DEFINE_PSEUDO_CONSTRUCTOR(CSSStyleDeclarationPseudoCtor)
00054 
00055   Value getDOMCSSStyleDeclaration(ExecState *exec, const DOM::CSSStyleDeclaration& n);
00056 
00057   class DOMStyleSheet : public DOMObject {
00058   public:
00059     // Build a DOMStyleSheet
00060     DOMStyleSheet(ExecState *, const DOM::StyleSheet& ss);
00061     // Constructor for inherited classes
00062     DOMStyleSheet(const Object& proto, const DOM::StyleSheet& ss) : DOMObject(proto), styleSheet(ss) { }
00063     virtual ~DOMStyleSheet();
00064     virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
00065     Value getValueProperty(ExecState *exec, int token) const;
00066     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00067     virtual bool toBoolean(ExecState *) const { return true; }
00068     virtual const ClassInfo* classInfo() const { return &info; }
00069     static const ClassInfo info;
00070     enum { Type, Disabled, OwnerNode, ParentStyleSheet, Href, Title, Media };
00071   protected:
00072     DOM::StyleSheet styleSheet;
00073   };
00074 
00075   Value getDOMStyleSheet(ExecState *exec, const DOM::StyleSheet& ss);
00076 
00077   class DOMStyleSheetList : public DOMObject {
00078   public:
00079     DOMStyleSheetList(ExecState *, const DOM::StyleSheetList& ssl, const DOM::Document& doc);
00080     virtual ~DOMStyleSheetList();
00081     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00082     virtual Value call(ExecState *exec, Object &thisObj, const List &args);
00083     Value tryCall(ExecState *exec, Object &thisObj, const List &args);
00084     virtual bool implementsCall() const { return true; }
00085     // no put - all read-only
00086     virtual const ClassInfo* classInfo() const { return &info; }
00087     virtual bool toBoolean(ExecState* ) const { return true; }
00088     static const ClassInfo info;
00089     DOM::StyleSheetList toStyleSheetList() const { return styleSheetList; }
00090     enum { Item, Length };
00091   private:
00092     DOM::StyleSheetList styleSheetList;
00093     DOM::Document m_doc;
00094   };
00095 
00096   // The document is only used for get-stylesheet-by-name (make optional if necessary)
00097   Value getDOMStyleSheetList(ExecState *exec, const DOM::StyleSheetList& ss, const DOM::Document& doc);
00098 
00099   class DOMMediaList : public DOMObject {
00100   public:
00101     DOMMediaList(ExecState *, const DOM::MediaList& ml);
00102     virtual ~DOMMediaList();
00103     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00104     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00105     virtual const ClassInfo* classInfo() const { return &info; }
00106     virtual bool toBoolean(ExecState* ) const { return true; }
00107     static const ClassInfo info;
00108     enum { MediaText, Length,
00109            Item, DeleteMedium, AppendMedium };
00110     DOM::MediaList toMediaList() const { return mediaList; }
00111   private:
00112     DOM::MediaList mediaList;
00113   };
00114 
00115   Value getDOMMediaList(ExecState *exec, const DOM::MediaList& ss);
00116 
00117   class DOMCSSStyleSheet : public DOMStyleSheet {
00118   public:
00119     DOMCSSStyleSheet(ExecState *exec, const DOM::CSSStyleSheet& ss);
00120     virtual ~DOMCSSStyleSheet();
00121     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00122     // no put - all read-only
00123     virtual const ClassInfo* classInfo() const { return &info; }
00124     static const ClassInfo info;
00125     enum { OwnerRule, CssRules, Rules,
00126            InsertRule, DeleteRule, AddRule, RemoveRule };
00127     DOM::CSSStyleSheet toCSSStyleSheet() const { return static_cast<DOM::CSSStyleSheet>(styleSheet); }
00128   };
00129 
00130   class DOMCSSRuleList : public DOMObject {
00131   public:
00132     DOMCSSRuleList(ExecState *, const DOM::CSSRuleList& rl);
00133     virtual ~DOMCSSRuleList();
00134     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00135     // no put - all read-only
00136     virtual const ClassInfo* classInfo() const { return &info; }
00137     static const ClassInfo info;
00138     enum { Item, Length };
00139     DOM::CSSRuleList toCSSRuleList() const { return cssRuleList; }
00140   protected:
00141     DOM::CSSRuleList cssRuleList;
00142   };
00143 
00144   Value getDOMCSSRuleList(ExecState *exec, const DOM::CSSRuleList& rl);
00145 
00146   class DOMCSSRule : public DOMObject {
00147   public:
00148     DOMCSSRule(ExecState *, const DOM::CSSRule& r);
00149     virtual ~DOMCSSRule();
00150     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00151     Value getValueProperty(ExecState *exec, int token) const;
00152     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00153     void putValueProperty(ExecState *exec, int token, const Value& value, int attr);
00154     virtual const ClassInfo* classInfo() const;
00155     static const ClassInfo info;
00156     static const ClassInfo style_info, media_info, fontface_info, page_info, import_info, charset_info;
00157     enum { ParentStyleSheet, Type, CssText, ParentRule,
00158            Style_SelectorText, Style_Style,
00159            Media_Media, Media_InsertRule, Media_DeleteRule, Media_CssRules,
00160            FontFace_Style, Page_SelectorText, Page_Style,
00161            Import_Href, Import_Media, Import_StyleSheet, Charset_Encoding };
00162     DOM::CSSRule toCSSRule() const { return cssRule; }
00163   protected:
00164     DOM::CSSRule cssRule;
00165   };
00166 
00167   Value getDOMCSSRule(ExecState *exec, const DOM::CSSRule& r);
00168 
00172   DOM::CSSRule toCSSRule(const Value&);
00173 
00174   // Constructor for CSSRule - currently only used for some global values
00175   class CSSRuleConstructor : public DOMObject {
00176   public:
00177     CSSRuleConstructor(ExecState *);
00178     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00179     Value getValueProperty(ExecState *exec, int token) const;
00180     // no put - all read-only
00181     virtual const ClassInfo* classInfo() const { return &info; }
00182     static const ClassInfo info;
00183     enum { UNKNOWN_RULE, STYLE_RULE, CHARSET_RULE, IMPORT_RULE, MEDIA_RULE, FONT_FACE_RULE, PAGE_RULE };
00184   };
00185 
00186   Value getCSSRuleConstructor(ExecState *exec);
00187 
00188   class DOMCSSValue : public DOMObject {
00189   public:
00190     DOMCSSValue(ExecState *, const DOM::CSSValue& v);
00191     DOMCSSValue(const Object& proto, const DOM::CSSValue& v) : DOMObject(proto), cssValue(v) { }
00192     virtual ~DOMCSSValue();
00193     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00194     virtual void tryPut(ExecState *exec, const Identifier &propertyName, const Value& value, int attr = None);
00195     virtual const ClassInfo* classInfo() const { return &info; }
00196     static const ClassInfo info;
00197     enum { CssText, CssValueType };
00198   protected:
00199     DOM::CSSValue cssValue;
00200   };
00201 
00202   Value getDOMCSSValue(ExecState *exec, const DOM::CSSValue& v);
00203 
00204   // Constructor for CSSValue - currently only used for some global values
00205   class CSSValueConstructor : public DOMObject {
00206   public:
00207     CSSValueConstructor(ExecState *exec);
00208     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00209     Value getValueProperty(ExecState *exec, int token) const;
00210     // no put - all read-only
00211     virtual const ClassInfo* classInfo() const { return &info; }
00212     static const ClassInfo info;
00213     enum { CSS_VALUE_LIST, CSS_PRIMITIVE_VALUE, CSS_CUSTOM, CSS_INHERIT };
00214   };
00215 
00216   Value getCSSValueConstructor(ExecState *exec);
00217 
00218   class DOMCSSPrimitiveValue : public DOMCSSValue {
00219   public:
00220     DOMCSSPrimitiveValue(ExecState *exec, const DOM::CSSPrimitiveValue& v);
00221     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00222     // no put - all read-only
00223     virtual const ClassInfo* classInfo() const { return &info; }
00224     static const ClassInfo info;
00225     DOM::CSSPrimitiveValue toCSSPrimitiveValue() const { return static_cast<DOM::CSSPrimitiveValue>(cssValue); }
00226     enum { PrimitiveType, SetFloatValue, GetFloatValue, SetStringValue, GetStringValue,
00227            GetCounterValue, GetRectValue, GetRGBColorValue };
00228   };
00229 
00230   // Constructor for CSSPrimitiveValue - currently only used for some global values
00231   class CSSPrimitiveValueConstructor : public CSSValueConstructor {
00232   public:
00233     CSSPrimitiveValueConstructor(ExecState *exec) : CSSValueConstructor(exec) { }
00234     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00235     Value getValueProperty(ExecState *exec, int token) const;
00236     // no put - all read-only
00237     virtual const ClassInfo* classInfo() const { return &info; }
00238     static const ClassInfo info;
00239   };
00240 
00241   Value getCSSPrimitiveValueConstructor(ExecState *exec);
00242 
00243   class DOMCSSValueList : public DOMCSSValue {
00244   public:
00245     DOMCSSValueList(ExecState *exec, const DOM::CSSValueList& v);
00246     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00247     // no put - all read-only
00248     virtual const ClassInfo* classInfo() const { return &info; }
00249     static const ClassInfo info;
00250     enum { Item, Length };
00251     DOM::CSSValueList toValueList() const { return static_cast<DOM::CSSValueList>(cssValue); }
00252   };
00253 
00254   class DOMRGBColor : public DOMObject {
00255   public:
00256     DOMRGBColor(ExecState*, const DOM::RGBColor& c);
00257     ~DOMRGBColor();
00258     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00259     Value getValueProperty(ExecState *exec, int token) const;
00260     // no put - all read-only
00261     virtual const ClassInfo* classInfo() const { return &info; }
00262     static const ClassInfo info;
00263     enum { Red, Green, Blue };
00264   protected:
00265     DOM::RGBColor rgbColor;
00266   };
00267 
00268   Value getDOMRGBColor(ExecState *exec, const DOM::RGBColor& c);
00269 
00270   class DOMRect : public DOMObject {
00271   public:
00272     DOMRect(ExecState *, const DOM::Rect& r);
00273     ~DOMRect();
00274     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00275     Value getValueProperty(ExecState *exec, int token) const;
00276     // no put - all read-only
00277     virtual const ClassInfo* classInfo() const { return &info; }
00278     static const ClassInfo info;
00279     enum { Top, Right, Bottom, Left };
00280   protected:
00281     DOM::Rect rect;
00282   };
00283 
00284   Value getDOMRect(ExecState *exec, const DOM::Rect& r);
00285 
00286   class DOMCounter : public DOMObject {
00287   public:
00288     DOMCounter(ExecState *, const DOM::Counter& c);
00289     ~DOMCounter();
00290     virtual Value tryGet(ExecState *exec,const Identifier &propertyName) const;
00291     Value getValueProperty(ExecState *exec, int token) const;
00292     // no put - all read-only
00293     virtual const ClassInfo* classInfo() const { return &info; }
00294     static const ClassInfo info;
00295     enum { identifier, listStyle, separator };
00296   protected:
00297     DOM::Counter counter;
00298   };
00299 
00300   Value getDOMCounter(ExecState *exec, const DOM::Counter& c);
00301 
00302 } // namespace
00303 
00304 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys