1 | /* |
2 | * This file is part of the WebKit open source project. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "config.h" |
21 | #include "WebKitDOMHTMLCanvasElement.h" |
22 | |
23 | #include <WebCore/CSSImportRule.h> |
24 | #include "DOMObjectCache.h" |
25 | #include <WebCore/DOMException.h> |
26 | #include <WebCore/Document.h> |
27 | #include "GObjectEventListener.h" |
28 | #include <WebCore/JSExecState.h> |
29 | #include "WebKitDOMEventPrivate.h" |
30 | #include "WebKitDOMEventTarget.h" |
31 | #include "WebKitDOMHTMLCanvasElementPrivate.h" |
32 | #include "WebKitDOMNodePrivate.h" |
33 | #include "WebKitDOMPrivate.h" |
34 | #include "ConvertToUTF8String.h" |
35 | #include <wtf/GetPtr.h> |
36 | #include <wtf/RefPtr.h> |
37 | |
38 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
39 | |
40 | namespace WebKit { |
41 | |
42 | WebKitDOMHTMLCanvasElement* kit(WebCore::HTMLCanvasElement* obj) |
43 | { |
44 | return WEBKIT_DOM_HTML_CANVAS_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
45 | } |
46 | |
47 | WebCore::HTMLCanvasElement* core(WebKitDOMHTMLCanvasElement* request) |
48 | { |
49 | return request ? static_cast<WebCore::HTMLCanvasElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
50 | } |
51 | |
52 | WebKitDOMHTMLCanvasElement* wrapHTMLCanvasElement(WebCore::HTMLCanvasElement* coreObject) |
53 | { |
54 | ASSERT(coreObject); |
55 | return WEBKIT_DOM_HTML_CANVAS_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_CANVAS_ELEMENT, "core-object" , coreObject, nullptr)); |
56 | } |
57 | |
58 | } // namespace WebKit |
59 | |
60 | static gboolean webkit_dom_html_canvas_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error) |
61 | { |
62 | WebCore::Event* coreEvent = WebKit::core(event); |
63 | if (!coreEvent) |
64 | return false; |
65 | WebCore::HTMLCanvasElement* coreTarget = static_cast<WebCore::HTMLCanvasElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
66 | |
67 | auto result = coreTarget->dispatchEventForBindings(*coreEvent); |
68 | if (result.hasException()) { |
69 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
70 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
71 | return false; |
72 | } |
73 | return result.releaseReturnValue(); |
74 | } |
75 | |
76 | static gboolean webkit_dom_html_canvas_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
77 | { |
78 | WebCore::HTMLCanvasElement* coreTarget = static_cast<WebCore::HTMLCanvasElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
79 | return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
80 | } |
81 | |
82 | static gboolean webkit_dom_html_canvas_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
83 | { |
84 | WebCore::HTMLCanvasElement* coreTarget = static_cast<WebCore::HTMLCanvasElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
85 | return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
86 | } |
87 | |
88 | static void webkit_dom_html_canvas_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
89 | { |
90 | iface->dispatch_event = webkit_dom_html_canvas_element_dispatch_event; |
91 | iface->add_event_listener = webkit_dom_html_canvas_element_add_event_listener; |
92 | iface->remove_event_listener = webkit_dom_html_canvas_element_remove_event_listener; |
93 | } |
94 | |
95 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLCanvasElement, webkit_dom_html_canvas_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_canvas_element_dom_event_target_init)) |
96 | |
97 | enum { |
98 | DOM_HTML_CANVAS_ELEMENT_PROP_0, |
99 | DOM_HTML_CANVAS_ELEMENT_PROP_WIDTH, |
100 | DOM_HTML_CANVAS_ELEMENT_PROP_HEIGHT, |
101 | }; |
102 | |
103 | static void webkit_dom_html_canvas_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
104 | { |
105 | WebKitDOMHTMLCanvasElement* self = WEBKIT_DOM_HTML_CANVAS_ELEMENT(object); |
106 | |
107 | switch (propertyId) { |
108 | case DOM_HTML_CANVAS_ELEMENT_PROP_WIDTH: |
109 | webkit_dom_html_canvas_element_set_width(self, g_value_get_long(value)); |
110 | break; |
111 | case DOM_HTML_CANVAS_ELEMENT_PROP_HEIGHT: |
112 | webkit_dom_html_canvas_element_set_height(self, g_value_get_long(value)); |
113 | break; |
114 | default: |
115 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
116 | break; |
117 | } |
118 | } |
119 | |
120 | static void webkit_dom_html_canvas_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
121 | { |
122 | WebKitDOMHTMLCanvasElement* self = WEBKIT_DOM_HTML_CANVAS_ELEMENT(object); |
123 | |
124 | switch (propertyId) { |
125 | case DOM_HTML_CANVAS_ELEMENT_PROP_WIDTH: |
126 | g_value_set_long(value, webkit_dom_html_canvas_element_get_width(self)); |
127 | break; |
128 | case DOM_HTML_CANVAS_ELEMENT_PROP_HEIGHT: |
129 | g_value_set_long(value, webkit_dom_html_canvas_element_get_height(self)); |
130 | break; |
131 | default: |
132 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
133 | break; |
134 | } |
135 | } |
136 | |
137 | static void webkit_dom_html_canvas_element_class_init(WebKitDOMHTMLCanvasElementClass* requestClass) |
138 | { |
139 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
140 | gobjectClass->set_property = webkit_dom_html_canvas_element_set_property; |
141 | gobjectClass->get_property = webkit_dom_html_canvas_element_get_property; |
142 | |
143 | g_object_class_install_property( |
144 | gobjectClass, |
145 | DOM_HTML_CANVAS_ELEMENT_PROP_WIDTH, |
146 | g_param_spec_long( |
147 | "width" , |
148 | "HTMLCanvasElement:width" , |
149 | "read-write glong HTMLCanvasElement:width" , |
150 | G_MINLONG, G_MAXLONG, 0, |
151 | WEBKIT_PARAM_READWRITE)); |
152 | |
153 | g_object_class_install_property( |
154 | gobjectClass, |
155 | DOM_HTML_CANVAS_ELEMENT_PROP_HEIGHT, |
156 | g_param_spec_long( |
157 | "height" , |
158 | "HTMLCanvasElement:height" , |
159 | "read-write glong HTMLCanvasElement:height" , |
160 | G_MINLONG, G_MAXLONG, 0, |
161 | WEBKIT_PARAM_READWRITE)); |
162 | |
163 | } |
164 | |
165 | static void webkit_dom_html_canvas_element_init(WebKitDOMHTMLCanvasElement* request) |
166 | { |
167 | UNUSED_PARAM(request); |
168 | } |
169 | |
170 | glong webkit_dom_html_canvas_element_get_width(WebKitDOMHTMLCanvasElement* self) |
171 | { |
172 | WebCore::JSMainThreadNullState state; |
173 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_CANVAS_ELEMENT(self), 0); |
174 | WebCore::HTMLCanvasElement* item = WebKit::core(self); |
175 | glong result = item->width(); |
176 | return result; |
177 | } |
178 | |
179 | void webkit_dom_html_canvas_element_set_width(WebKitDOMHTMLCanvasElement* self, glong value) |
180 | { |
181 | WebCore::JSMainThreadNullState state; |
182 | g_return_if_fail(WEBKIT_DOM_IS_HTML_CANVAS_ELEMENT(self)); |
183 | WebCore::HTMLCanvasElement* item = WebKit::core(self); |
184 | item->setWidth(value); |
185 | } |
186 | |
187 | glong webkit_dom_html_canvas_element_get_height(WebKitDOMHTMLCanvasElement* self) |
188 | { |
189 | WebCore::JSMainThreadNullState state; |
190 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_CANVAS_ELEMENT(self), 0); |
191 | WebCore::HTMLCanvasElement* item = WebKit::core(self); |
192 | glong result = item->height(); |
193 | return result; |
194 | } |
195 | |
196 | void webkit_dom_html_canvas_element_set_height(WebKitDOMHTMLCanvasElement* self, glong value) |
197 | { |
198 | WebCore::JSMainThreadNullState state; |
199 | g_return_if_fail(WEBKIT_DOM_IS_HTML_CANVAS_ELEMENT(self)); |
200 | WebCore::HTMLCanvasElement* item = WebKit::core(self); |
201 | item->setHeight(value); |
202 | } |
203 | |
204 | G_GNUC_END_IGNORE_DEPRECATIONS; |
205 | |