fix logic
[personal-kdelibs.git] / khtml / ecma / kjs_html.h
blob0e6bc91501d406523dc14d1031795dc2cd7dde41
1 // -*- c-basic-offset: 2 -*-
2 /*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999 Harri Porten (porten@kde.org)
5 * Copyright (C) 2003 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef _KJS_HTML_H_
23 #define _KJS_HTML_H_
25 #include "html/html_documentimpl.h"
26 #include "html/html_baseimpl.h"
27 #include "html/html_miscimpl.h"
28 #include "html/html_formimpl.h"
29 #include "misc/loader_client.h"
31 #include "ecma/kjs_binding.h"
32 #include "ecma/kjs_dom.h"
33 #include "xml/dom_nodeimpl.h" // for NodeImpl::Id
35 namespace KJS {
36 class HTMLElement;
38 class HTMLDocument : public DOMDocument {
39 public:
40 HTMLDocument(ExecState *exec, DOM::HTMLDocumentImpl* d);
41 JSValue* getValueProperty(ExecState *exec, int token);
42 virtual bool getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot);
43 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue* value, int attr = None);
44 void putValueProperty(ExecState *exec, int token, JSValue* value, int /*attr*/);
46 virtual const ClassInfo* classInfo() const { return &info; }
47 static const ClassInfo info;
48 enum { Referrer, Domain, URL, Body, Location, Cookie,
49 Images, Applets, Links, Forms, Layers, Anchors, Scripts, All, Clear, Open, Close,
50 Write, WriteLn, GetElementsByName, GetSelection, CaptureEvents, ReleaseEvents,
51 BgColor, FgColor, AlinkColor, LinkColor, VlinkColor, LastModified,
52 Height, Width, Dir, Frames, CompatMode, DesignMode };
53 DOM::HTMLDocumentImpl* impl() const { return static_cast<DOM::HTMLDocumentImpl*>( m_impl.get() ); }
54 private:
55 static JSValue *nameGetter(ExecState *exec, JSObject*, const Identifier& name, const PropertySlot& slot);
56 static JSValue *frameNameGetter(ExecState *exec, JSObject*, const Identifier& name, const PropertySlot& slot);
57 static JSValue *objectNameGetter(ExecState *exec, JSObject*, const Identifier& name, const PropertySlot& slot);
58 static JSValue *layerNameGetter(ExecState *exec, JSObject*, const Identifier& name, const PropertySlot& slot);
61 DEFINE_PSEUDO_CONSTRUCTOR(HTMLDocumentPseudoCtor)
63 class HTMLElement : public DOMElement {
64 public:
65 HTMLElement(ExecState *exec, DOM::HTMLElementImpl* e);
66 virtual bool getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot);
67 JSValue* getValueProperty(ExecState *exec, int token) const;
68 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue* value, int attr = None);
69 void putValueProperty(ExecState *exec, int token, JSValue* value, int);
70 virtual UString toString(ExecState *exec) const;
71 virtual void pushEventHandlerScope(ExecState *exec, ScopeChain &scope) const;
72 virtual const ClassInfo* classInfo() const;
73 static const ClassInfo info;
75 static const ClassInfo html_info, head_info, link_info, title_info,
76 meta_info, base_info, isIndex_info, style_info, body_info, form_info,
77 select_info, optGroup_info, option_info, input_info, textArea_info,
78 button_info, label_info, fieldSet_info, legend_info, ul_info, ol_info,
79 dl_info, dir_info, menu_info, li_info, div_info, p_info, heading_info,
80 blockQuote_info, q_info, pre_info, br_info, baseFont_info, font_info,
81 hr_info, mod_info, a_info, canvas_info, img_info, object_info, param_info,
82 applet_info, map_info, area_info, script_info, table_info,
83 caption_info, col_info, tablesection_info, tr_info,
84 tablecell_info, frameSet_info, frame_info, iFrame_info, marquee_info, layer_info;
86 enum { HtmlVersion, HeadProfile, LinkHref, LinkRel, LinkMedia,
87 LinkCharset, LinkDisabled, LinkHrefLang, LinkRev, LinkTarget, LinkType,
88 LinkSheet, TitleText, MetaName, MetaHttpEquiv, MetaContent, MetaScheme,
89 BaseHref, BaseTarget, IsIndexForm, IsIndexPrompt, StyleDisabled,
90 StyleSheet, StyleType, StyleMedia, BodyBackground, BodyVLink, BodyText,
91 BodyLink, BodyALink, BodyBgColor, BodyOnLoad, BodyFocus,
92 FormAction, FormEncType, FormElements, FormLength, FormAcceptCharset,
93 FormReset, FormTarget, FormName, FormMethod, FormSubmit, SelectAdd,
94 SelectTabIndex, SelectValue, SelectSelectedIndex, SelectLength,
95 SelectRemove, SelectForm, SelectType, SelectOptions,
96 SelectDisabled, SelectMultiple, SelectName, SelectSize,
97 OptGroupDisabled, OptGroupLabel, OptionIndex, OptionSelected,
98 OptionForm, OptionText, OptionDefaultSelected, OptionDisabled,
99 OptionLabel, OptionValue, InputReadOnly, InputAccept,
100 InputSize, InputDefaultValue, InputTabIndex, InputValue, InputType,
101 InputMaxLength, InputDefaultChecked, InputDisabled,
102 InputChecked, InputIndeterminate, InputForm, InputAccessKey, InputAlign, InputAlt,
103 InputName, InputSrc, InputUseMap, InputSelect, InputClick,
104 InputSelectionStart, InputSelectionEnd, InputSetSelectionRange,
105 TextAreaAccessKey, TextAreaName, TextAreaDefaultValue, TextAreaSelect,
106 TextAreaCols, TextAreaDisabled, TextAreaForm, TextAreaType,
107 TextAreaTabIndex, TextAreaReadOnly, TextAreaRows, TextAreaValue,
108 TextAreaSelectionStart, TextAreaSelectionEnd, TextAreaSetSelectionRange,
109 TextAreaTextLength, ButtonClick, ButtonForm, ButtonTabIndex, ButtonName,
110 ButtonDisabled, ButtonAccessKey, ButtonType, ButtonValue, LabelHtmlFor,
111 LabelForm, LabelAccessKey, FieldSetForm, LegendForm, LegendAccessKey,
112 LegendAlign, UListType, UListCompact, OListStart, OListCompact,
113 OListType, DListCompact, DirectoryCompact, MenuCompact, LIType,
114 LIValue, DivAlign, ParagraphAlign, HeadingAlign, BlockQuoteCite,
115 QuoteCite, PreWidth, BRClear, BaseFontColor, BaseFontSize,
116 BaseFontFace, FontColor, FontSize, FontFace, HRWidth, HRNoShade,
117 HRAlign, HRSize, ModCite, ModDateTime, AnchorShape, AnchorRel,
118 AnchorAccessKey, AnchorCoords, AnchorHref, AnchorProtocol, AnchorHost,
119 AnchorCharset, AnchorHrefLang, AnchorHostname, AnchorType,
120 AnchorPort, AnchorPathName, AnchorHash, AnchorSearch, AnchorName,
121 AnchorRev, AnchorTabIndex, AnchorTarget, AnchorText, AnchorClick,
122 ImageName, ImageAlign, ImageHspace, ImageVspace, ImageUseMap, ImageAlt,
123 ImageLowSrc, ImageWidth, ImageIsMap, ImageBorder, ImageHeight,
124 ImageLongDesc, ImageSrc, ImageX, ImageY, ImageComplete, ObjectHspace, ObjectHeight, ObjectAlign,
125 ObjectBorder, ObjectCode, ObjectType, ObjectVspace, ObjectArchive,
126 ObjectDeclare, ObjectForm, ObjectCodeBase, ObjectCodeType, ObjectData,
127 ObjectName, ObjectStandby, ObjectTabIndex, ObjectUseMap, ObjectWidth, ObjectContentDocument,
128 ParamName, ParamType, ParamValueType, ParamValue, AppletArchive,
129 AppletAlt, AppletCode, AppletWidth, AppletAlign, AppletCodeBase,
130 AppletName, AppletHeight, AppletHspace, AppletObject, AppletVspace,
131 MapAreas, MapName, AreaHash, AreaHref, AreaTarget, AreaPort, AreaShape,
132 AreaCoords, AreaAlt, AreaAccessKey, AreaNoHref, AreaHost, AreaProtocol,
133 AreaHostName, AreaPathName, AreaSearch, AreaTabIndex, ScriptEvent,
134 ScriptType, ScriptHtmlFor, ScriptText, ScriptSrc, ScriptCharset,
135 ScriptDefer, TableSummary, TableTBodies, TableTHead, TableCellPadding,
136 TableDeleteCaption, TableCreateCaption, TableCaption, TableWidth,
137 TableCreateTFoot, TableAlign, TableTFoot, TableDeleteRow,
138 TableCellSpacing, TableRows, TableBgColor, TableBorder, TableFrame,
139 TableRules, TableCreateTHead, TableDeleteTHead, TableDeleteTFoot,
140 TableInsertRow, TableCaptionAlign, TableColCh, TableColChOff,
141 TableColAlign, TableColSpan, TableColVAlign, TableColWidth,
142 TableSectionCh, TableSectionDeleteRow, TableSectionChOff,
143 TableSectionRows, TableSectionAlign, TableSectionVAlign,
144 TableSectionInsertRow, TableRowSectionRowIndex, TableRowRowIndex,
145 TableRowChOff, TableRowCells, TableRowVAlign, TableRowCh,
146 TableRowAlign, TableRowBgColor, TableRowDeleteCell, TableRowInsertCell,
147 TableCellColSpan, TableCellNoWrap, TableCellAbbr, TableCellHeight,
148 TableCellWidth, TableCellCellIndex, TableCellChOff, TableCellBgColor,
149 TableCellCh, TableCellVAlign, TableCellRowSpan, TableCellHeaders,
150 TableCellAlign, TableCellAxis, TableCellScope, FrameSetCols,
151 FrameSetRows, FrameSrc, FrameLocation, FrameFrameBorder, FrameScrolling,
152 FrameMarginWidth, FrameLongDesc, FrameMarginHeight, FrameName,
153 FrameContentDocument, FrameContentWindow,
154 FrameNoResize, FrameWidth, FrameHeight, IFrameLongDesc, IFrameAlign,
155 IFrameFrameBorder, IFrameSrc, IFrameName, IFrameHeight,
156 IFrameMarginHeight, IFrameMarginWidth, IFrameScrolling, IFrameWidth,
157 IFrameContentDocument, IFrameContentWindow,
158 MarqueeStart, MarqueeStop,
159 CanvasGetContext, CanvasWidth, CanvasHeight, CanvasToDataURL,
160 LayerTop, LayerLeft, LayerVisibility, LayerBgColor, LayerClip, LayerDocument, LayerLayers,
161 ElementInnerHTML, ElementTitle, ElementId, ElementDir, ElementLang,
162 ElementClassName, ElementInnerText, ElementDocument,
163 ElementChildren, ElementContentEditable, ElementIsContentEditable,
164 ElementAll, ElementScrollIntoView };
166 DOM::HTMLElementImpl* impl() const { return static_cast<DOM::HTMLElementImpl*>(m_impl.get()); }
167 JSValue* indexGetter(ExecState *exec, unsigned index);
168 private:
169 static JSValue *formNameGetter(ExecState *exec, JSObject*, const Identifier& name, const PropertySlot& slot);
171 QString getURLArg(unsigned id) const;
173 static KParts::LiveConnectExtension *getLiveConnectExtension(const DOM::HTMLElementImpl &element);
175 /* Many of properties in the DOM bindings can be implemented by merely returning
176 an attribute as the right type, and setting it in similar manner; or perhaps
177 returning a collection of appropriate type*/
178 enum BoundPropType {
179 T_String, //String, to be return by String()
180 T_StrOrNl, //String, to be return by getStringOrNull()
181 T_Bool, //Boolean, return true if property is not null
182 T_Int,
183 T_URL,
184 T_TabIdx, //Magic tab-index handling
185 T_Res, //Reserved, ignore sets, return empty string
186 T_Coll, //Collection, type is in attrID
187 T_ReadOnly = 0x80 //Property should be handled only on read.
190 enum {
191 NotApplicable = 0xFFFFFFFu
194 struct BoundPropInfo {
195 unsigned elId; //Applicable element type
196 int token; //Token
197 BoundPropType type;
198 unsigned attrId; //Attribute to get
201 JSValue* handleBoundRead (ExecState* exec, int token) const;
202 bool handleBoundWrite(ExecState* exec, int token, JSValue* value);
204 static const BoundPropInfo bpTable[];
206 static QHash<int, const BoundPropInfo*>* s_boundPropInfo;
207 static QHash<int, const BoundPropInfo*>* boundPropInfo();
210 class HTMLCollection : public DOMObject {
211 public:
212 HTMLCollection(ExecState *exec, DOM::HTMLCollectionImpl* c);
213 HTMLCollection(KJS::JSObject *proto, DOM::HTMLCollectionImpl* c);
214 ~HTMLCollection();
215 JSValue* getValueProperty(ExecState *exec, int token);
216 virtual bool getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot);
218 virtual JSValue* callAsFunction(ExecState *exec, JSObject* thisObj, const List& args);
219 virtual bool implementsCall() const { return true; }
220 virtual bool isFunctionType() const { return false; }
221 virtual bool masqueradeAsUndefined() const;
222 virtual bool toBoolean(ExecState *) const;
223 virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&);
224 enum { Item, NamedItem, Tags };
225 JSValue* getNamedItems(ExecState *exec, const Identifier &propertyName) const;
226 virtual const ClassInfo* classInfo() const { return &info; }
227 static const ClassInfo info;
228 DOM::HTMLCollectionImpl* impl() const { return m_impl.get(); }
229 virtual void hide() { hidden = true; }
230 JSValue* indexGetter(ExecState *exec, unsigned index);
231 protected:
232 SharedPtr<DOM::HTMLCollectionImpl> m_impl;
233 bool hidden;
234 private:
235 static JSValue *lengthGetter(ExecState *exec, JSObject*, const Identifier& name, const PropertySlot& slot);
236 static JSValue *nameGetter(ExecState *exec, JSObject*, const Identifier& name, const PropertySlot& slot);
239 class HTMLSelectCollection : public HTMLCollection {
240 public:
241 enum { Add };
242 HTMLSelectCollection(ExecState *exec, DOM::HTMLCollectionImpl* c, DOM::HTMLSelectElementImpl* e);
243 virtual bool getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot);
244 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue* value, int attr = None);
246 virtual const ClassInfo* classInfo() const { return &info; }
247 static const ClassInfo info;
249 DOM::HTMLSelectElementImpl* toElement() const { return element.get(); }
250 private:
251 SharedPtr<DOM::HTMLSelectElementImpl> element;
252 static JSValue *selectedIndexGetter(ExecState *exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot);
253 static JSValue *selectedValueGetter(ExecState *exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot);
256 ////////////////////// Option Object ////////////////////////
258 class OptionConstructorImp : public JSObject {
259 public:
260 OptionConstructorImp(ExecState *exec, DOM::DocumentImpl* d);
261 virtual bool implementsConstruct() const;
262 virtual JSObject* construct(ExecState *exec, const List &args);
263 private:
264 SharedPtr<DOM::DocumentImpl> doc;
267 ////////////////////// Image Object ////////////////////////
269 class ImageConstructorImp : public JSObject {
270 public:
271 ImageConstructorImp(ExecState *exec, DOM::DocumentImpl* d);
272 virtual bool implementsConstruct() const;
273 virtual JSObject* construct(ExecState *exec, const List &args);
274 private:
275 SharedPtr<DOM::DocumentImpl> doc;
279 JSValue* getHTMLCollection(ExecState *exec, DOM::HTMLCollectionImpl* c, bool hide=false);
280 JSValue* getSelectHTMLCollection(ExecState *exec, DOM::HTMLCollectionImpl* c, DOM::HTMLSelectElementImpl* e);
282 //All the pseudo constructors..
283 DEFINE_PSEUDO_CONSTRUCTOR(HTMLElementPseudoCtor)
284 DEFINE_PSEUDO_CONSTRUCTOR(HTMLHtmlElementPseudoCtor)
285 DEFINE_PSEUDO_CONSTRUCTOR(HTMLHeadElementPseudoCtor)
286 DEFINE_PSEUDO_CONSTRUCTOR(HTMLLinkElementPseudoCtor)
287 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTitleElementPseudoCtor)
288 DEFINE_PSEUDO_CONSTRUCTOR(HTMLMetaElementPseudoCtor)
289 DEFINE_PSEUDO_CONSTRUCTOR(HTMLBaseElementPseudoCtor)
290 DEFINE_PSEUDO_CONSTRUCTOR(HTMLIsIndexElementPseudoCtor)
291 DEFINE_PSEUDO_CONSTRUCTOR(HTMLStyleElementPseudoCtor)
292 DEFINE_PSEUDO_CONSTRUCTOR(HTMLBodyElementPseudoCtor)
293 DEFINE_PSEUDO_CONSTRUCTOR(HTMLFormElementPseudoCtor)
294 DEFINE_PSEUDO_CONSTRUCTOR(HTMLSelectElementPseudoCtor)
295 DEFINE_PSEUDO_CONSTRUCTOR(HTMLOptGroupElementPseudoCtor)
296 DEFINE_PSEUDO_CONSTRUCTOR(HTMLOptionElementPseudoCtor)
297 DEFINE_PSEUDO_CONSTRUCTOR(HTMLInputElementPseudoCtor)
298 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTextAreaElementPseudoCtor)
299 DEFINE_PSEUDO_CONSTRUCTOR(HTMLButtonElementPseudoCtor)
300 DEFINE_PSEUDO_CONSTRUCTOR(HTMLLabelElementPseudoCtor)
301 DEFINE_PSEUDO_CONSTRUCTOR(HTMLFieldSetElementPseudoCtor)
302 DEFINE_PSEUDO_CONSTRUCTOR(HTMLLegendElementPseudoCtor)
303 DEFINE_PSEUDO_CONSTRUCTOR(HTMLUListElementPseudoCtor)
304 DEFINE_PSEUDO_CONSTRUCTOR(HTMLOListElementPseudoCtor)
305 DEFINE_PSEUDO_CONSTRUCTOR(HTMLDListElementPseudoCtor)
306 DEFINE_PSEUDO_CONSTRUCTOR(HTMLDirectoryElementPseudoCtor)
307 DEFINE_PSEUDO_CONSTRUCTOR(HTMLMenuElementPseudoCtor)
308 DEFINE_PSEUDO_CONSTRUCTOR(HTMLLIElementPseudoCtor)
309 DEFINE_PSEUDO_CONSTRUCTOR(HTMLDivElementPseudoCtor)
310 DEFINE_PSEUDO_CONSTRUCTOR(HTMLParagraphElementPseudoCtor)
311 DEFINE_PSEUDO_CONSTRUCTOR(HTMLHeadingElementPseudoCtor)
312 DEFINE_PSEUDO_CONSTRUCTOR(HTMLBlockQuoteElementPseudoCtor)
313 DEFINE_PSEUDO_CONSTRUCTOR(HTMLQuoteElementPseudoCtor)
314 DEFINE_PSEUDO_CONSTRUCTOR(HTMLPreElementPseudoCtor)
315 DEFINE_PSEUDO_CONSTRUCTOR(HTMLBRElementPseudoCtor)
316 DEFINE_PSEUDO_CONSTRUCTOR(HTMLBaseFontElementPseudoCtor)
317 DEFINE_PSEUDO_CONSTRUCTOR(HTMLFontElementPseudoCtor)
318 DEFINE_PSEUDO_CONSTRUCTOR(HTMLHRElementPseudoCtor)
319 DEFINE_PSEUDO_CONSTRUCTOR(HTMLModElementPseudoCtor)
320 DEFINE_PSEUDO_CONSTRUCTOR(HTMLAnchorElementPseudoCtor)
321 DEFINE_PSEUDO_CONSTRUCTOR(HTMLImageElementPseudoCtor)
322 DEFINE_PSEUDO_CONSTRUCTOR(HTMLObjectElementPseudoCtor)
323 DEFINE_PSEUDO_CONSTRUCTOR(HTMLParamElementPseudoCtor)
324 DEFINE_PSEUDO_CONSTRUCTOR(HTMLAppletElementPseudoCtor)
325 DEFINE_PSEUDO_CONSTRUCTOR(HTMLMapElementPseudoCtor)
326 DEFINE_PSEUDO_CONSTRUCTOR(HTMLAreaElementPseudoCtor)
327 DEFINE_PSEUDO_CONSTRUCTOR(HTMLScriptElementPseudoCtor)
328 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTableElementPseudoCtor)
329 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTableCaptionElementPseudoCtor)
330 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTableColElementPseudoCtor)
331 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTableSectionElementPseudoCtor)
332 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTableRowElementPseudoCtor)
333 DEFINE_PSEUDO_CONSTRUCTOR(HTMLTableCellElementPseudoCtor)
334 DEFINE_PSEUDO_CONSTRUCTOR(HTMLFrameSetElementPseudoCtor)
335 DEFINE_PSEUDO_CONSTRUCTOR(HTMLLayerElementPseudoCtor)
336 DEFINE_PSEUDO_CONSTRUCTOR(HTMLFrameElementPseudoCtor)
337 DEFINE_PSEUDO_CONSTRUCTOR(HTMLIFrameElementPseudoCtor)
338 DEFINE_PSEUDO_CONSTRUCTOR(HTMLCollectionPseudoCtor)
339 DEFINE_PSEUDO_CONSTRUCTOR(HTMLMarqueeElementPseudoCtor)
340 DEFINE_PSEUDO_CONSTRUCTOR(HTMLCanvasElementPseudoCtor)
341 } // namespace
343 #endif