| 1 | /* |
| 2 | * Copyright (C) 2013 Igalia S.L. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "WebKitDOMHTMLPrivate.h" |
| 28 | |
| 29 | #include <WebCore/HTMLAnchorElement.h> |
| 30 | #include <WebCore/HTMLAppletElement.h> |
| 31 | #include <WebCore/HTMLAreaElement.h> |
| 32 | #include <WebCore/HTMLAudioElement.h> |
| 33 | #include <WebCore/HTMLBRElement.h> |
| 34 | #include <WebCore/HTMLBaseElement.h> |
| 35 | #include <WebCore/HTMLBodyElement.h> |
| 36 | #include <WebCore/HTMLButtonElement.h> |
| 37 | #include <WebCore/HTMLCanvasElement.h> |
| 38 | #include <WebCore/HTMLDListElement.h> |
| 39 | #include <WebCore/HTMLDirectoryElement.h> |
| 40 | #include <WebCore/HTMLDivElement.h> |
| 41 | #include <WebCore/HTMLElement.h> |
| 42 | #include <WebCore/HTMLEmbedElement.h> |
| 43 | #include <WebCore/HTMLFieldSetElement.h> |
| 44 | #include <WebCore/HTMLFontElement.h> |
| 45 | #include <WebCore/HTMLFormElement.h> |
| 46 | #include <WebCore/HTMLFrameElement.h> |
| 47 | #include <WebCore/HTMLFrameSetElement.h> |
| 48 | #include <WebCore/HTMLHRElement.h> |
| 49 | #include <WebCore/HTMLHeadElement.h> |
| 50 | #include <WebCore/HTMLHeadingElement.h> |
| 51 | #include <WebCore/HTMLHtmlElement.h> |
| 52 | #include <WebCore/HTMLIFrameElement.h> |
| 53 | #include <WebCore/HTMLImageElement.h> |
| 54 | #include <WebCore/HTMLInputElement.h> |
| 55 | #include <WebCore/HTMLKeygenElement.h> |
| 56 | #include <WebCore/HTMLLIElement.h> |
| 57 | #include <WebCore/HTMLLabelElement.h> |
| 58 | #include <WebCore/HTMLLegendElement.h> |
| 59 | #include <WebCore/HTMLLinkElement.h> |
| 60 | #include <WebCore/HTMLMapElement.h> |
| 61 | #include <WebCore/HTMLMarqueeElement.h> |
| 62 | #include <WebCore/HTMLMenuElement.h> |
| 63 | #include <WebCore/HTMLMetaElement.h> |
| 64 | #include <WebCore/HTMLModElement.h> |
| 65 | #include <WebCore/HTMLNames.h> |
| 66 | #include <WebCore/HTMLOListElement.h> |
| 67 | #include <WebCore/HTMLObjectElement.h> |
| 68 | #include <WebCore/HTMLOptGroupElement.h> |
| 69 | #include <WebCore/HTMLOptionElement.h> |
| 70 | #include <WebCore/HTMLParagraphElement.h> |
| 71 | #include <WebCore/HTMLParamElement.h> |
| 72 | #include <WebCore/HTMLPreElement.h> |
| 73 | #include <WebCore/HTMLQuoteElement.h> |
| 74 | #include <WebCore/HTMLScriptElement.h> |
| 75 | #include <WebCore/HTMLSelectElement.h> |
| 76 | #include <WebCore/HTMLStyleElement.h> |
| 77 | #include <WebCore/HTMLTableCaptionElement.h> |
| 78 | #include <WebCore/HTMLTableCellElement.h> |
| 79 | #include <WebCore/HTMLTableColElement.h> |
| 80 | #include <WebCore/HTMLTableElement.h> |
| 81 | #include <WebCore/HTMLTableRowElement.h> |
| 82 | #include <WebCore/HTMLTableSectionElement.h> |
| 83 | #include <WebCore/HTMLTextAreaElement.h> |
| 84 | #include <WebCore/HTMLTitleElement.h> |
| 85 | #include <WebCore/HTMLUListElement.h> |
| 86 | #include <WebCore/HTMLVideoElement.h> |
| 87 | #include "WebKitDOMHTMLAnchorElementPrivate.h" |
| 88 | #include "WebKitDOMHTMLAppletElementPrivate.h" |
| 89 | #include "WebKitDOMHTMLAreaElementPrivate.h" |
| 90 | #include "WebKitDOMHTMLBRElementPrivate.h" |
| 91 | #include "WebKitDOMHTMLBaseElementPrivate.h" |
| 92 | #include "WebKitDOMHTMLBodyElementPrivate.h" |
| 93 | #include "WebKitDOMHTMLButtonElementPrivate.h" |
| 94 | #include "WebKitDOMHTMLCanvasElementPrivate.h" |
| 95 | #include "WebKitDOMHTMLDListElementPrivate.h" |
| 96 | #include "WebKitDOMHTMLDirectoryElementPrivate.h" |
| 97 | #include "WebKitDOMHTMLDivElementPrivate.h" |
| 98 | #include "WebKitDOMHTMLElementPrivate.h" |
| 99 | #include "WebKitDOMHTMLEmbedElementPrivate.h" |
| 100 | #include "WebKitDOMHTMLFieldSetElementPrivate.h" |
| 101 | #include "WebKitDOMHTMLFontElementPrivate.h" |
| 102 | #include "WebKitDOMHTMLFormElementPrivate.h" |
| 103 | #include "WebKitDOMHTMLFrameElementPrivate.h" |
| 104 | #include "WebKitDOMHTMLFrameSetElementPrivate.h" |
| 105 | #include "WebKitDOMHTMLHRElementPrivate.h" |
| 106 | #include "WebKitDOMHTMLHeadElementPrivate.h" |
| 107 | #include "WebKitDOMHTMLHeadingElementPrivate.h" |
| 108 | #include "WebKitDOMHTMLHtmlElementPrivate.h" |
| 109 | #include "WebKitDOMHTMLIFrameElementPrivate.h" |
| 110 | #include "WebKitDOMHTMLImageElementPrivate.h" |
| 111 | #include "WebKitDOMHTMLInputElementPrivate.h" |
| 112 | #include "WebKitDOMHTMLLIElementPrivate.h" |
| 113 | #include "WebKitDOMHTMLLabelElementPrivate.h" |
| 114 | #include "WebKitDOMHTMLLegendElementPrivate.h" |
| 115 | #include "WebKitDOMHTMLLinkElementPrivate.h" |
| 116 | #include "WebKitDOMHTMLMapElementPrivate.h" |
| 117 | #include "WebKitDOMHTMLMarqueeElementPrivate.h" |
| 118 | #include "WebKitDOMHTMLMenuElementPrivate.h" |
| 119 | #include "WebKitDOMHTMLMetaElementPrivate.h" |
| 120 | #include "WebKitDOMHTMLModElementPrivate.h" |
| 121 | #include "WebKitDOMHTMLOListElementPrivate.h" |
| 122 | #include "WebKitDOMHTMLObjectElementPrivate.h" |
| 123 | #include "WebKitDOMHTMLOptGroupElementPrivate.h" |
| 124 | #include "WebKitDOMHTMLOptionElementPrivate.h" |
| 125 | #include "WebKitDOMHTMLParagraphElementPrivate.h" |
| 126 | #include "WebKitDOMHTMLParamElementPrivate.h" |
| 127 | #include "WebKitDOMHTMLPreElementPrivate.h" |
| 128 | #include "WebKitDOMHTMLQuoteElementPrivate.h" |
| 129 | #include "WebKitDOMHTMLScriptElementPrivate.h" |
| 130 | #include "WebKitDOMHTMLSelectElementPrivate.h" |
| 131 | #include "WebKitDOMHTMLStyleElementPrivate.h" |
| 132 | #include "WebKitDOMHTMLTableCaptionElementPrivate.h" |
| 133 | #include "WebKitDOMHTMLTableCellElementPrivate.h" |
| 134 | #include "WebKitDOMHTMLTableColElementPrivate.h" |
| 135 | #include "WebKitDOMHTMLTableElementPrivate.h" |
| 136 | #include "WebKitDOMHTMLTableRowElementPrivate.h" |
| 137 | #include "WebKitDOMHTMLTableSectionElementPrivate.h" |
| 138 | #include "WebKitDOMHTMLTextAreaElementPrivate.h" |
| 139 | #include "WebKitDOMHTMLTitleElementPrivate.h" |
| 140 | #include "WebKitDOMHTMLUListElementPrivate.h" |
| 141 | |
| 142 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 143 | |
| 144 | namespace WebKit { |
| 145 | |
| 146 | using namespace WebCore; |
| 147 | using namespace WebCore::HTMLNames; |
| 148 | |
| 149 | // macro(TagName, ElementName) |
| 150 | |
| 151 | #define FOR_EACH_HTML_TAG(macro) \ |
| 152 | macro(a, Anchor) \ |
| 153 | macro(applet, Applet) \ |
| 154 | macro(area, Area) \ |
| 155 | macro(base, Base) \ |
| 156 | macro(blockquote, Quote) \ |
| 157 | macro(body, Body) \ |
| 158 | macro(br, BR) \ |
| 159 | macro(button, Button) \ |
| 160 | macro(canvas, Canvas) \ |
| 161 | macro(caption, TableCaption) \ |
| 162 | macro(col, TableCol) \ |
| 163 | macro(del, Mod) \ |
| 164 | macro(dir, Directory) \ |
| 165 | macro(div, Div) \ |
| 166 | macro(dl, DList) \ |
| 167 | macro(embed, Embed) \ |
| 168 | macro(fieldset, FieldSet) \ |
| 169 | macro(font, Font) \ |
| 170 | macro(form, Form) \ |
| 171 | macro(frame, Frame) \ |
| 172 | macro(frameset, FrameSet) \ |
| 173 | macro(h1, Heading) \ |
| 174 | macro(head, Head) \ |
| 175 | macro(hr, HR) \ |
| 176 | macro(html, Html) \ |
| 177 | macro(iframe, IFrame) \ |
| 178 | macro(img, Image) \ |
| 179 | macro(input, Input) \ |
| 180 | macro(label, Label) \ |
| 181 | macro(legend, Legend) \ |
| 182 | macro(li, LI) \ |
| 183 | macro(link, Link) \ |
| 184 | macro(map, Map) \ |
| 185 | macro(marquee, Marquee) \ |
| 186 | macro(menu, Menu) \ |
| 187 | macro(meta, Meta) \ |
| 188 | macro(object, Object) \ |
| 189 | macro(ol, OList) \ |
| 190 | macro(optgroup, OptGroup) \ |
| 191 | macro(option, Option) \ |
| 192 | macro(p, Paragraph) \ |
| 193 | macro(param, Param) \ |
| 194 | macro(pre, Pre) \ |
| 195 | macro(q, Quote) \ |
| 196 | macro(script, Script) \ |
| 197 | macro(select, Select) \ |
| 198 | macro(style, Style) \ |
| 199 | macro(table, Table) \ |
| 200 | macro(tbody, TableSection) \ |
| 201 | macro(td, TableCell) \ |
| 202 | macro(textarea, TextArea) \ |
| 203 | macro(title, Title) \ |
| 204 | macro(tr, TableRow) \ |
| 205 | macro(ul, UList) \ |
| 206 | macro(colgroup, TableCol) \ |
| 207 | macro(h2, Heading) \ |
| 208 | macro(h3, Heading) \ |
| 209 | macro(h4, Heading) \ |
| 210 | macro(h5, Heading) \ |
| 211 | macro(h6, Heading) \ |
| 212 | macro(image, Image) \ |
| 213 | macro(ins, Mod) \ |
| 214 | macro(listing, Pre) \ |
| 215 | macro(tfoot, TableSection) \ |
| 216 | macro(th, TableCell) \ |
| 217 | macro(thead, TableSection) \ |
| 218 | macro(xmp, Pre) |
| 219 | |
| 220 | #define DEFINE_HTML_WRAPPER(TagName, ElementName) \ |
| 221 | static WebKitDOMHTMLElement* TagName##Wrapper(HTMLElement* element) \ |
| 222 | { \ |
| 223 | return WEBKIT_DOM_HTML_ELEMENT(wrapHTML##ElementName##Element(static_cast<HTML##ElementName##Element*>(element))); \ |
| 224 | } |
| 225 | FOR_EACH_HTML_TAG(DEFINE_HTML_WRAPPER) |
| 226 | #undef DEFINE_HTML_WRAPPER |
| 227 | |
| 228 | typedef WebKitDOMHTMLElement* (*HTMLElementWrapFunction)(HTMLElement*); |
| 229 | |
| 230 | WebKitDOMHTMLElement* wrap(HTMLElement* element) |
| 231 | { |
| 232 | static HashMap<const QualifiedName::QualifiedNameImpl*, HTMLElementWrapFunction> map; |
| 233 | if (map.isEmpty()) { |
| 234 | #define ADD_HTML_WRAPPER(TagName, ElementName) map.set(TagName##Tag->impl(), TagName##Wrapper); |
| 235 | FOR_EACH_HTML_TAG(ADD_HTML_WRAPPER) |
| 236 | #undef ADD_HTML_WRAPPER |
| 237 | } |
| 238 | |
| 239 | if (HTMLElementWrapFunction wrapFunction = map.get(element->tagQName().impl())) |
| 240 | return wrapFunction(element); |
| 241 | |
| 242 | return wrapHTMLElement(element); |
| 243 | } |
| 244 | |
| 245 | } |
| 246 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 247 | |