08c5f027646625ae53f5bf85fab9b7be4a54f8cb
[WebKit-https.git] / Source / WebCore / bindings / gobject / WebKitDOMPrivate.cpp
1 /*
2  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4  *  Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
5  *  Copyright (C) 2008 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
6  *  Copyright (C) 2008 Martin Soto <soto@freedesktop.org>
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 "Blob.h"
28 #include "DOMObjectCache.h"
29 #include "Element.h"
30 #include "Event.h"
31 #include "EventException.h"
32 #include "EventTarget.h"
33 #include "File.h"
34 #include "HTMLElement.h"
35 #include "HTMLNames.h"
36 #include "KeyboardEvent.h"
37 #include "MouseEvent.h"
38 #include "StyleSheet.h"
39 #include "UIEvent.h"
40 #include "WebKitDOMAttrPrivate.h"
41 #include "WebKitDOMBlobPrivate.h"
42 #include "WebKitDOMCDATASectionPrivate.h"
43 #include "WebKitDOMCSSStyleSheetPrivate.h"
44 #include "WebKitDOMCommentPrivate.h"
45 #include "WebKitDOMDOMWindowPrivate.h"
46 #include "WebKitDOMDocumentFragmentPrivate.h"
47 #include "WebKitDOMDocumentPrivate.h"
48 #include "WebKitDOMDocumentTypePrivate.h"
49 #include "WebKitDOMElementPrivate.h"
50 #include "WebKitDOMEntityReferencePrivate.h"
51 #include "WebKitDOMEventPrivate.h"
52 #include "WebKitDOMEventTargetPrivate.h"
53 #include "WebKitDOMFilePrivate.h"
54 #include "WebKitDOMHTMLCollectionPrivate.h"
55 #include "WebKitDOMHTMLDocumentPrivate.h"
56 #include "WebKitDOMHTMLOptionsCollectionPrivate.h"
57 #include "WebKitDOMHTMLPrivate.h"
58 #include "WebKitDOMKeyboardEventPrivate.h"
59 #include "WebKitDOMMouseEventPrivate.h"
60 #include "WebKitDOMNodePrivate.h"
61 #include "WebKitDOMProcessingInstructionPrivate.h"
62 #include "WebKitDOMStyleSheetPrivate.h"
63 #include "WebKitDOMTextPrivate.h"
64 #include "WebKitDOMUIEventPrivate.h"
65 #include "WebKitDOMWheelEventPrivate.h"
66
67 #if ENABLE(VIDEO_TRACK)
68 #include "DataCue.h"
69 #include "VTTCue.h"
70 #include "WebKitDOMDataCuePrivate.h"
71 #include "WebKitDOMTextTrackCuePrivate.h"
72 #include "WebKitDOMVTTCuePrivate.h"
73 #endif
74
75 namespace WebKit {
76
77 using namespace WebCore;
78 using namespace WebCore::HTMLNames;
79
80 WebKitDOMNode* wrap(Node* node)
81 {
82     ASSERT(node);
83     ASSERT(node->nodeType());
84
85     switch (node->nodeType()) {
86     case Node::ELEMENT_NODE:
87         if (is<HTMLElement>(node))
88             return WEBKIT_DOM_NODE(wrap(downcast<HTMLElement>(node)));
89         return WEBKIT_DOM_NODE(wrapElement(downcast<Element>(node)));
90     case Node::ATTRIBUTE_NODE:
91         return WEBKIT_DOM_NODE(wrapAttr(static_cast<Attr*>(node)));
92     case Node::TEXT_NODE:
93         return WEBKIT_DOM_NODE(wrapText(downcast<Text>(node)));
94     case Node::CDATA_SECTION_NODE:
95         return WEBKIT_DOM_NODE(wrapCDATASection(static_cast<CDATASection*>(node)));
96     case Node::ENTITY_REFERENCE_NODE:
97         return WEBKIT_DOM_NODE(wrapEntityReference(static_cast<EntityReference*>(node)));
98     case Node::PROCESSING_INSTRUCTION_NODE:
99         return WEBKIT_DOM_NODE(wrapProcessingInstruction(static_cast<ProcessingInstruction*>(node)));
100     case Node::COMMENT_NODE:
101         return WEBKIT_DOM_NODE(wrapComment(static_cast<Comment*>(node)));
102     case Node::DOCUMENT_NODE:
103         if (is<HTMLDocument>(node))
104             return WEBKIT_DOM_NODE(wrapHTMLDocument(downcast<HTMLDocument>(node)));
105         return WEBKIT_DOM_NODE(wrapDocument(downcast<Document>(node)));
106     case Node::DOCUMENT_TYPE_NODE:
107         return WEBKIT_DOM_NODE(wrapDocumentType(static_cast<DocumentType*>(node)));
108     case Node::DOCUMENT_FRAGMENT_NODE:
109         return WEBKIT_DOM_NODE(wrapDocumentFragment(static_cast<DocumentFragment*>(node)));
110     case Node::ENTITY_NODE:
111     case Node::NOTATION_NODE:
112     case Node::XPATH_NAMESPACE_NODE:
113         break;
114     }
115
116     return wrapNode(node);
117 }
118
119 WebKitDOMEvent* wrap(Event* event)
120 {
121     ASSERT(event);
122
123     if (event->isUIEvent()) {
124         if (event->isMouseEvent())
125             return WEBKIT_DOM_EVENT(wrapMouseEvent(static_cast<MouseEvent*>(event)));
126
127         if (event->isKeyboardEvent())
128             return WEBKIT_DOM_EVENT(wrapKeyboardEvent(static_cast<KeyboardEvent*>(event)));
129
130         if (event->eventInterface() == WheelEventInterfaceType)
131             return WEBKIT_DOM_EVENT(wrapWheelEvent(static_cast<WheelEvent*>(event)));
132
133         return WEBKIT_DOM_EVENT(wrapUIEvent(static_cast<UIEvent*>(event)));
134     }
135
136     return wrapEvent(event);
137 }
138
139 WebKitDOMStyleSheet* wrap(StyleSheet* styleSheet)
140 {
141     ASSERT(styleSheet);
142
143     if (styleSheet->isCSSStyleSheet())
144         return WEBKIT_DOM_STYLE_SHEET(wrapCSSStyleSheet(toCSSStyleSheet(styleSheet)));
145     return wrapStyleSheet(styleSheet);
146 }
147
148 WebKitDOMHTMLCollection* wrap(HTMLCollection* collection)
149 {
150     ASSERT(collection);
151
152     if (collection->type() == WebCore::SelectOptions)
153         return WEBKIT_DOM_HTML_COLLECTION(wrapHTMLOptionsCollection(static_cast<HTMLOptionsCollection*>(collection)));
154     return wrapHTMLCollection(collection);
155 }
156
157 WebKitDOMEventTarget* wrap(EventTarget* eventTarget)
158 {
159     ASSERT(eventTarget);
160
161     if (Node* node = eventTarget->toNode())
162         return WEBKIT_DOM_EVENT_TARGET(kit(node));
163
164     if (DOMWindow* window = eventTarget->toDOMWindow())
165         return WEBKIT_DOM_EVENT_TARGET(kit(window));
166
167     return 0;
168 }
169
170 WebKitDOMBlob* wrap(Blob* blob)
171 {
172     ASSERT(blob);
173
174     if (blob->isFile())
175         return WEBKIT_DOM_BLOB(wrapFile(static_cast<File*>(blob)));
176     return wrapBlob(blob);
177 }
178
179 #if ENABLE(VIDEO_TRACK)
180 WebKitDOMTextTrackCue* wrap(TextTrackCue* cue)
181 {
182     ASSERT(cue);
183
184     switch (cue->cueType()) {
185     case TextTrackCue::Data:
186         return WEBKIT_DOM_TEXT_TRACK_CUE(wrapDataCue(static_cast<DataCue*>(cue)));
187     case TextTrackCue::WebVTT:
188     case TextTrackCue::Generic:
189         return WEBKIT_DOM_TEXT_TRACK_CUE(wrapVTTCue(static_cast<VTTCue*>(cue)));
190     }
191     return wrapTextTrackCue(cue);
192 }
193 #endif
194
195 } // namespace WebKit