1 | /* |
2 | * Copyright (C) 1999-2001 Harri Porten ([email protected]) |
3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
4 | * Copyright (C) 2007 Samuel Weinig <[email protected]> |
5 | * Copyright (C) 2008 Luke Kenneth Casson Leighton <[email protected]> |
6 | * Copyright (C) 2008 Martin Soto <[email protected]> |
7 | * Copyright (C) 2009-2013 Igalia S.L. |
8 | * |
9 | * This library is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU Lesser General Public |
11 | * License as published by the Free Software Foundation; either |
12 | * version 2 of the License, or (at your option) any later version. |
13 | * |
14 | * This library is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | * Lesser General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU Lesser General Public |
20 | * License along with this library; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | */ |
23 | |
24 | #include "config.h" |
25 | #include "WebKitDOMPrivate.h" |
26 | |
27 | #include <WebCore/Blob.h> |
28 | #include <WebCore/Element.h> |
29 | #include <WebCore/Event.h> |
30 | #include <WebCore/EventTarget.h> |
31 | #include <WebCore/File.h> |
32 | #include <WebCore/HTMLElement.h> |
33 | #include <WebCore/HTMLNames.h> |
34 | #include <WebCore/KeyboardEvent.h> |
35 | #include <WebCore/MouseEvent.h> |
36 | #include <WebCore/StyleSheet.h> |
37 | #include <WebCore/UIEvent.h> |
38 | #include "WebKitDOMAttrPrivate.h" |
39 | #include "WebKitDOMBlobPrivate.h" |
40 | #include "WebKitDOMCDATASectionPrivate.h" |
41 | #include "WebKitDOMCSSStyleSheetPrivate.h" |
42 | #include "WebKitDOMCommentPrivate.h" |
43 | #include "WebKitDOMDOMWindowPrivate.h" |
44 | #include "WebKitDOMDocumentFragmentPrivate.h" |
45 | #include "WebKitDOMDocumentPrivate.h" |
46 | #include "WebKitDOMDocumentTypePrivate.h" |
47 | #include "WebKitDOMElementPrivate.h" |
48 | #include "WebKitDOMEventPrivate.h" |
49 | #include "WebKitDOMEventTargetPrivate.h" |
50 | #include "WebKitDOMFilePrivate.h" |
51 | #include "WebKitDOMHTMLCollectionPrivate.h" |
52 | #include "WebKitDOMHTMLDocumentPrivate.h" |
53 | #include "WebKitDOMHTMLOptionsCollectionPrivate.h" |
54 | #include "WebKitDOMHTMLPrivate.h" |
55 | #include "WebKitDOMKeyboardEventPrivate.h" |
56 | #include "WebKitDOMMouseEventPrivate.h" |
57 | #include "WebKitDOMNodePrivate.h" |
58 | #include "WebKitDOMProcessingInstructionPrivate.h" |
59 | #include "WebKitDOMStyleSheetPrivate.h" |
60 | #include "WebKitDOMTextPrivate.h" |
61 | #include "WebKitDOMUIEventPrivate.h" |
62 | #include "WebKitDOMWheelEventPrivate.h" |
63 | |
64 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
65 | |
66 | namespace WebKit { |
67 | |
68 | using namespace WebCore; |
69 | using namespace WebCore::HTMLNames; |
70 | |
71 | WebKitDOMNode* wrapNodeGtk(Node* node) |
72 | { |
73 | ASSERT(node); |
74 | ASSERT(node->nodeType()); |
75 | |
76 | switch (node->nodeType()) { |
77 | case Node::ELEMENT_NODE: |
78 | if (is<HTMLElement>(*node)) |
79 | return WEBKIT_DOM_NODE(wrap(downcast<HTMLElement>(node))); |
80 | return nullptr; |
81 | case Node::ATTRIBUTE_NODE: |
82 | return WEBKIT_DOM_NODE(wrapAttr(static_cast<Attr*>(node))); |
83 | case Node::TEXT_NODE: |
84 | return WEBKIT_DOM_NODE(wrapText(downcast<Text>(node))); |
85 | case Node::CDATA_SECTION_NODE: |
86 | return WEBKIT_DOM_NODE(wrapCDATASection(static_cast<CDATASection*>(node))); |
87 | case Node::PROCESSING_INSTRUCTION_NODE: |
88 | return WEBKIT_DOM_NODE(wrapProcessingInstruction(static_cast<ProcessingInstruction*>(node))); |
89 | case Node::COMMENT_NODE: |
90 | return WEBKIT_DOM_NODE(wrapComment(static_cast<Comment*>(node))); |
91 | case Node::DOCUMENT_NODE: |
92 | if (is<HTMLDocument>(*node)) |
93 | return WEBKIT_DOM_NODE(wrapHTMLDocument(downcast<HTMLDocument>(node))); |
94 | return nullptr; |
95 | case Node::DOCUMENT_TYPE_NODE: |
96 | return WEBKIT_DOM_NODE(wrapDocumentType(static_cast<DocumentType*>(node))); |
97 | case Node::DOCUMENT_FRAGMENT_NODE: |
98 | return WEBKIT_DOM_NODE(wrapDocumentFragment(static_cast<DocumentFragment*>(node))); |
99 | } |
100 | |
101 | return wrapNode(node); |
102 | } |
103 | |
104 | WebKitDOMEvent* wrap(Event* event) |
105 | { |
106 | ASSERT(event); |
107 | |
108 | if (is<UIEvent>(*event)) { |
109 | if (is<MouseEvent>(*event)) |
110 | return WEBKIT_DOM_EVENT(wrapMouseEvent(&downcast<MouseEvent>(*event))); |
111 | if (is<KeyboardEvent>(*event)) |
112 | return WEBKIT_DOM_EVENT(wrapKeyboardEvent(&downcast<KeyboardEvent>(*event))); |
113 | if (is<WheelEvent>(*event)) |
114 | return WEBKIT_DOM_EVENT(wrapWheelEvent(&downcast<WheelEvent>(*event))); |
115 | return WEBKIT_DOM_EVENT(wrapUIEvent(&downcast<UIEvent>(*event))); |
116 | } |
117 | |
118 | return wrapEvent(event); |
119 | } |
120 | |
121 | WebKitDOMStyleSheet* wrap(StyleSheet* styleSheet) |
122 | { |
123 | ASSERT(styleSheet); |
124 | |
125 | if (is<CSSStyleSheet>(*styleSheet)) |
126 | return WEBKIT_DOM_STYLE_SHEET(wrapCSSStyleSheet(downcast<CSSStyleSheet>(styleSheet))); |
127 | return wrapStyleSheet(styleSheet); |
128 | } |
129 | |
130 | WebKitDOMHTMLCollection* wrap(HTMLCollection* collection) |
131 | { |
132 | ASSERT(collection); |
133 | |
134 | if (is<HTMLOptionsCollection>(*collection)) |
135 | return WEBKIT_DOM_HTML_COLLECTION(wrapHTMLOptionsCollection(downcast<HTMLOptionsCollection>(collection))); |
136 | return wrapHTMLCollection(collection); |
137 | } |
138 | |
139 | WebKitDOMEventTarget* wrap(EventTarget* eventTarget) |
140 | { |
141 | ASSERT(eventTarget); |
142 | |
143 | if (is<Node>(*eventTarget)) |
144 | return WEBKIT_DOM_EVENT_TARGET(kit(&downcast<Node>(*eventTarget))); |
145 | if (is<DOMWindow>(*eventTarget)) |
146 | return WEBKIT_DOM_EVENT_TARGET(kit(&downcast<DOMWindow>(*eventTarget))); |
147 | return nullptr; |
148 | } |
149 | |
150 | WebKitDOMBlob* wrap(Blob* blob) |
151 | { |
152 | ASSERT(blob); |
153 | |
154 | if (blob->isFile()) |
155 | return WEBKIT_DOM_BLOB(wrapFile(static_cast<File*>(blob))); |
156 | return wrapBlob(blob); |
157 | } |
158 | |
159 | } // namespace WebKit |
160 | G_GNUC_END_IGNORE_DEPRECATIONS; |
161 | |