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 "WebKitDOMRange.h" |
22 | |
23 | #include <WebCore/CSSImportRule.h> |
24 | #include "DOMObjectCache.h" |
25 | #include <WebCore/DOMException.h> |
26 | #include <WebCore/Document.h> |
27 | #include <WebCore/JSExecState.h> |
28 | #include "WebKitDOMDocumentFragmentPrivate.h" |
29 | #include "WebKitDOMNodePrivate.h" |
30 | #include "WebKitDOMPrivate.h" |
31 | #include "WebKitDOMRangePrivate.h" |
32 | #include "ConvertToUTF8String.h" |
33 | #include "WebKitDOMRangeUnstable.h" |
34 | #include <wtf/GetPtr.h> |
35 | #include <wtf/RefPtr.h> |
36 | |
37 | #define WEBKIT_DOM_RANGE_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_RANGE, WebKitDOMRangePrivate) |
38 | |
39 | typedef struct _WebKitDOMRangePrivate { |
40 | RefPtr<WebCore::Range> coreObject; |
41 | } WebKitDOMRangePrivate; |
42 | |
43 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
44 | |
45 | namespace WebKit { |
46 | |
47 | WebKitDOMRange* kit(WebCore::Range* obj) |
48 | { |
49 | if (!obj) |
50 | return 0; |
51 | |
52 | if (gpointer ret = DOMObjectCache::get(obj)) |
53 | return WEBKIT_DOM_RANGE(ret); |
54 | |
55 | return wrapRange(obj); |
56 | } |
57 | |
58 | WebCore::Range* core(WebKitDOMRange* request) |
59 | { |
60 | return request ? static_cast<WebCore::Range*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
61 | } |
62 | |
63 | WebKitDOMRange* wrapRange(WebCore::Range* coreObject) |
64 | { |
65 | ASSERT(coreObject); |
66 | return WEBKIT_DOM_RANGE(g_object_new(WEBKIT_DOM_TYPE_RANGE, "core-object" , coreObject, nullptr)); |
67 | } |
68 | |
69 | } // namespace WebKit |
70 | |
71 | G_DEFINE_TYPE(WebKitDOMRange, webkit_dom_range, WEBKIT_DOM_TYPE_OBJECT) |
72 | |
73 | enum { |
74 | DOM_RANGE_PROP_0, |
75 | DOM_RANGE_PROP_START_CONTAINER, |
76 | DOM_RANGE_PROP_START_OFFSET, |
77 | DOM_RANGE_PROP_END_CONTAINER, |
78 | DOM_RANGE_PROP_END_OFFSET, |
79 | DOM_RANGE_PROP_COLLAPSED, |
80 | DOM_RANGE_PROP_COMMON_ANCESTOR_CONTAINER, |
81 | DOM_RANGE_PROP_TEXT, |
82 | }; |
83 | |
84 | static void webkit_dom_range_finalize(GObject* object) |
85 | { |
86 | WebKitDOMRangePrivate* priv = WEBKIT_DOM_RANGE_GET_PRIVATE(object); |
87 | |
88 | WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
89 | |
90 | priv->~WebKitDOMRangePrivate(); |
91 | G_OBJECT_CLASS(webkit_dom_range_parent_class)->finalize(object); |
92 | } |
93 | |
94 | static void webkit_dom_range_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
95 | { |
96 | WebKitDOMRange* self = WEBKIT_DOM_RANGE(object); |
97 | |
98 | switch (propertyId) { |
99 | case DOM_RANGE_PROP_START_CONTAINER: |
100 | g_value_set_object(value, webkit_dom_range_get_start_container(self, nullptr)); |
101 | break; |
102 | case DOM_RANGE_PROP_START_OFFSET: |
103 | g_value_set_long(value, webkit_dom_range_get_start_offset(self, nullptr)); |
104 | break; |
105 | case DOM_RANGE_PROP_END_CONTAINER: |
106 | g_value_set_object(value, webkit_dom_range_get_end_container(self, nullptr)); |
107 | break; |
108 | case DOM_RANGE_PROP_END_OFFSET: |
109 | g_value_set_long(value, webkit_dom_range_get_end_offset(self, nullptr)); |
110 | break; |
111 | case DOM_RANGE_PROP_COLLAPSED: |
112 | g_value_set_boolean(value, webkit_dom_range_get_collapsed(self, nullptr)); |
113 | break; |
114 | case DOM_RANGE_PROP_COMMON_ANCESTOR_CONTAINER: |
115 | g_value_set_object(value, webkit_dom_range_get_common_ancestor_container(self, nullptr)); |
116 | break; |
117 | case DOM_RANGE_PROP_TEXT: |
118 | g_value_take_string(value, webkit_dom_range_get_text(self)); |
119 | break; |
120 | default: |
121 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
122 | break; |
123 | } |
124 | } |
125 | |
126 | static GObject* webkit_dom_range_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties) |
127 | { |
128 | GObject* object = G_OBJECT_CLASS(webkit_dom_range_parent_class)->constructor(type, constructPropertiesCount, constructProperties); |
129 | |
130 | WebKitDOMRangePrivate* priv = WEBKIT_DOM_RANGE_GET_PRIVATE(object); |
131 | priv->coreObject = static_cast<WebCore::Range*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
132 | WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
133 | |
134 | return object; |
135 | } |
136 | |
137 | static void webkit_dom_range_class_init(WebKitDOMRangeClass* requestClass) |
138 | { |
139 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
140 | g_type_class_add_private(gobjectClass, sizeof(WebKitDOMRangePrivate)); |
141 | gobjectClass->constructor = webkit_dom_range_constructor; |
142 | gobjectClass->finalize = webkit_dom_range_finalize; |
143 | gobjectClass->get_property = webkit_dom_range_get_property; |
144 | |
145 | g_object_class_install_property( |
146 | gobjectClass, |
147 | DOM_RANGE_PROP_START_CONTAINER, |
148 | g_param_spec_object( |
149 | "start-container" , |
150 | "Range:start-container" , |
151 | "read-only WebKitDOMNode* Range:start-container" , |
152 | WEBKIT_DOM_TYPE_NODE, |
153 | WEBKIT_PARAM_READABLE)); |
154 | |
155 | g_object_class_install_property( |
156 | gobjectClass, |
157 | DOM_RANGE_PROP_START_OFFSET, |
158 | g_param_spec_long( |
159 | "start-offset" , |
160 | "Range:start-offset" , |
161 | "read-only glong Range:start-offset" , |
162 | G_MINLONG, G_MAXLONG, 0, |
163 | WEBKIT_PARAM_READABLE)); |
164 | |
165 | g_object_class_install_property( |
166 | gobjectClass, |
167 | DOM_RANGE_PROP_END_CONTAINER, |
168 | g_param_spec_object( |
169 | "end-container" , |
170 | "Range:end-container" , |
171 | "read-only WebKitDOMNode* Range:end-container" , |
172 | WEBKIT_DOM_TYPE_NODE, |
173 | WEBKIT_PARAM_READABLE)); |
174 | |
175 | g_object_class_install_property( |
176 | gobjectClass, |
177 | DOM_RANGE_PROP_END_OFFSET, |
178 | g_param_spec_long( |
179 | "end-offset" , |
180 | "Range:end-offset" , |
181 | "read-only glong Range:end-offset" , |
182 | G_MINLONG, G_MAXLONG, 0, |
183 | WEBKIT_PARAM_READABLE)); |
184 | |
185 | g_object_class_install_property( |
186 | gobjectClass, |
187 | DOM_RANGE_PROP_COLLAPSED, |
188 | g_param_spec_boolean( |
189 | "collapsed" , |
190 | "Range:collapsed" , |
191 | "read-only gboolean Range:collapsed" , |
192 | FALSE, |
193 | WEBKIT_PARAM_READABLE)); |
194 | |
195 | g_object_class_install_property( |
196 | gobjectClass, |
197 | DOM_RANGE_PROP_COMMON_ANCESTOR_CONTAINER, |
198 | g_param_spec_object( |
199 | "common-ancestor-container" , |
200 | "Range:common-ancestor-container" , |
201 | "read-only WebKitDOMNode* Range:common-ancestor-container" , |
202 | WEBKIT_DOM_TYPE_NODE, |
203 | WEBKIT_PARAM_READABLE)); |
204 | |
205 | g_object_class_install_property( |
206 | gobjectClass, |
207 | DOM_RANGE_PROP_TEXT, |
208 | g_param_spec_string( |
209 | "text" , |
210 | "Range:text" , |
211 | "read-only gchar* Range:text" , |
212 | "" , |
213 | WEBKIT_PARAM_READABLE)); |
214 | |
215 | } |
216 | |
217 | static void webkit_dom_range_init(WebKitDOMRange* request) |
218 | { |
219 | WebKitDOMRangePrivate* priv = WEBKIT_DOM_RANGE_GET_PRIVATE(request); |
220 | new (priv) WebKitDOMRangePrivate(); |
221 | } |
222 | |
223 | void webkit_dom_range_set_start(WebKitDOMRange* self, WebKitDOMNode* refNode, glong offset, GError** error) |
224 | { |
225 | WebCore::JSMainThreadNullState state; |
226 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
227 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
228 | g_return_if_fail(!error || !*error); |
229 | WebCore::Range* item = WebKit::core(self); |
230 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
231 | auto result = item->setStart(*convertedRefNode, offset); |
232 | if (result.hasException()) { |
233 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
234 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
235 | } |
236 | } |
237 | |
238 | void webkit_dom_range_set_end(WebKitDOMRange* self, WebKitDOMNode* refNode, glong offset, GError** error) |
239 | { |
240 | WebCore::JSMainThreadNullState state; |
241 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
242 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
243 | g_return_if_fail(!error || !*error); |
244 | WebCore::Range* item = WebKit::core(self); |
245 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
246 | auto result = item->setEnd(*convertedRefNode, offset); |
247 | if (result.hasException()) { |
248 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
249 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
250 | } |
251 | } |
252 | |
253 | void webkit_dom_range_set_start_before(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
254 | { |
255 | WebCore::JSMainThreadNullState state; |
256 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
257 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
258 | g_return_if_fail(!error || !*error); |
259 | WebCore::Range* item = WebKit::core(self); |
260 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
261 | auto result = item->setStartBefore(*convertedRefNode); |
262 | if (result.hasException()) { |
263 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
264 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
265 | } |
266 | } |
267 | |
268 | void webkit_dom_range_set_start_after(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
269 | { |
270 | WebCore::JSMainThreadNullState state; |
271 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
272 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
273 | g_return_if_fail(!error || !*error); |
274 | WebCore::Range* item = WebKit::core(self); |
275 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
276 | auto result = item->setStartAfter(*convertedRefNode); |
277 | if (result.hasException()) { |
278 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
279 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
280 | } |
281 | } |
282 | |
283 | void webkit_dom_range_set_end_before(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
284 | { |
285 | WebCore::JSMainThreadNullState state; |
286 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
287 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
288 | g_return_if_fail(!error || !*error); |
289 | WebCore::Range* item = WebKit::core(self); |
290 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
291 | auto result = item->setEndBefore(*convertedRefNode); |
292 | if (result.hasException()) { |
293 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
294 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
295 | } |
296 | } |
297 | |
298 | void webkit_dom_range_set_end_after(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
299 | { |
300 | WebCore::JSMainThreadNullState state; |
301 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
302 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
303 | g_return_if_fail(!error || !*error); |
304 | WebCore::Range* item = WebKit::core(self); |
305 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
306 | auto result = item->setEndAfter(*convertedRefNode); |
307 | if (result.hasException()) { |
308 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
309 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
310 | } |
311 | } |
312 | |
313 | void webkit_dom_range_collapse(WebKitDOMRange* self, gboolean toStart, GError** error) |
314 | { |
315 | WebCore::JSMainThreadNullState state; |
316 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
317 | UNUSED_PARAM(error); |
318 | WebCore::Range* item = WebKit::core(self); |
319 | item->collapse(toStart); |
320 | } |
321 | |
322 | void webkit_dom_range_select_node(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
323 | { |
324 | WebCore::JSMainThreadNullState state; |
325 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
326 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
327 | g_return_if_fail(!error || !*error); |
328 | WebCore::Range* item = WebKit::core(self); |
329 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
330 | auto result = item->selectNode(*convertedRefNode); |
331 | if (result.hasException()) { |
332 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
333 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
334 | } |
335 | } |
336 | |
337 | void webkit_dom_range_select_node_contents(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
338 | { |
339 | WebCore::JSMainThreadNullState state; |
340 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
341 | g_return_if_fail(WEBKIT_DOM_IS_NODE(refNode)); |
342 | g_return_if_fail(!error || !*error); |
343 | WebCore::Range* item = WebKit::core(self); |
344 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
345 | auto result = item->selectNodeContents(*convertedRefNode); |
346 | if (result.hasException()) { |
347 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
348 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
349 | } |
350 | } |
351 | |
352 | gshort webkit_dom_range_compare_boundary_points(WebKitDOMRange* self, gushort how, WebKitDOMRange* sourceRange, GError** error) |
353 | { |
354 | WebCore::JSMainThreadNullState state; |
355 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
356 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(sourceRange), 0); |
357 | g_return_val_if_fail(!error || !*error, 0); |
358 | WebCore::Range* item = WebKit::core(self); |
359 | WebCore::Range* convertedSourceRange = WebKit::core(sourceRange); |
360 | auto result = item->compareBoundaryPointsForBindings(how, *convertedSourceRange); |
361 | if (result.hasException()) { |
362 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
363 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
364 | return 0; |
365 | } |
366 | return result.releaseReturnValue(); |
367 | } |
368 | |
369 | void webkit_dom_range_delete_contents(WebKitDOMRange* self, GError** error) |
370 | { |
371 | WebCore::JSMainThreadNullState state; |
372 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
373 | g_return_if_fail(!error || !*error); |
374 | WebCore::Range* item = WebKit::core(self); |
375 | auto result = item->deleteContents(); |
376 | if (result.hasException()) { |
377 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
378 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
379 | } |
380 | } |
381 | |
382 | WebKitDOMDocumentFragment* (WebKitDOMRange* self, GError** error) |
383 | { |
384 | WebCore::JSMainThreadNullState state; |
385 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
386 | g_return_val_if_fail(!error || !*error, 0); |
387 | WebCore::Range* item = WebKit::core(self); |
388 | auto result = item->extractContents(); |
389 | if (result.hasException()) { |
390 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
391 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
392 | return nullptr; |
393 | } |
394 | return WebKit::kit(result.releaseReturnValue().ptr()); |
395 | } |
396 | |
397 | WebKitDOMDocumentFragment* webkit_dom_range_clone_contents(WebKitDOMRange* self, GError** error) |
398 | { |
399 | WebCore::JSMainThreadNullState state; |
400 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
401 | g_return_val_if_fail(!error || !*error, 0); |
402 | WebCore::Range* item = WebKit::core(self); |
403 | auto result = item->cloneContents(); |
404 | if (result.hasException()) { |
405 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
406 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
407 | return nullptr; |
408 | } |
409 | return WebKit::kit(result.releaseReturnValue().ptr()); |
410 | } |
411 | |
412 | void webkit_dom_range_insert_node(WebKitDOMRange* self, WebKitDOMNode* newNode, GError** error) |
413 | { |
414 | WebCore::JSMainThreadNullState state; |
415 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
416 | g_return_if_fail(WEBKIT_DOM_IS_NODE(newNode)); |
417 | g_return_if_fail(!error || !*error); |
418 | WebCore::Range* item = WebKit::core(self); |
419 | WebCore::Node* convertedNewNode = WebKit::core(newNode); |
420 | auto result = item->insertNode(*convertedNewNode); |
421 | if (result.hasException()) { |
422 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
423 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
424 | } |
425 | } |
426 | |
427 | void webkit_dom_range_surround_contents(WebKitDOMRange* self, WebKitDOMNode* newParent, GError** error) |
428 | { |
429 | WebCore::JSMainThreadNullState state; |
430 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
431 | g_return_if_fail(WEBKIT_DOM_IS_NODE(newParent)); |
432 | g_return_if_fail(!error || !*error); |
433 | WebCore::Range* item = WebKit::core(self); |
434 | WebCore::Node* convertedNewParent = WebKit::core(newParent); |
435 | auto result = item->surroundContents(*convertedNewParent); |
436 | if (result.hasException()) { |
437 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
438 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
439 | } |
440 | } |
441 | |
442 | WebKitDOMRange* webkit_dom_range_clone_range(WebKitDOMRange* self, GError** error) |
443 | { |
444 | WebCore::JSMainThreadNullState state; |
445 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
446 | UNUSED_PARAM(error); |
447 | WebCore::Range* item = WebKit::core(self); |
448 | RefPtr<WebCore::Range> gobjectResult = WTF::getPtr(item->cloneRange()); |
449 | return WebKit::kit(gobjectResult.get()); |
450 | } |
451 | |
452 | gchar* webkit_dom_range_to_string(WebKitDOMRange* self, GError** error) |
453 | { |
454 | WebCore::JSMainThreadNullState state; |
455 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
456 | UNUSED_PARAM(error); |
457 | WebCore::Range* item = WebKit::core(self); |
458 | gchar* result = convertToUTF8String(item->toString()); |
459 | return result; |
460 | } |
461 | |
462 | void webkit_dom_range_detach(WebKitDOMRange* self, GError** error) |
463 | { |
464 | WebCore::JSMainThreadNullState state; |
465 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
466 | UNUSED_PARAM(error); |
467 | WebCore::Range* item = WebKit::core(self); |
468 | item->detach(); |
469 | } |
470 | |
471 | WebKitDOMDocumentFragment* webkit_dom_range_create_contextual_fragment(WebKitDOMRange* self, const gchar* html, GError** error) |
472 | { |
473 | WebCore::JSMainThreadNullState state; |
474 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
475 | g_return_val_if_fail(html, 0); |
476 | g_return_val_if_fail(!error || !*error, 0); |
477 | WebCore::Range* item = WebKit::core(self); |
478 | WTF::String convertedHtml = WTF::String::fromUTF8(html); |
479 | auto result = item->createContextualFragment(convertedHtml); |
480 | if (result.hasException()) { |
481 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
482 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
483 | return nullptr; |
484 | } |
485 | return WebKit::kit(result.releaseReturnValue().ptr()); |
486 | } |
487 | |
488 | gshort webkit_dom_range_compare_node(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
489 | { |
490 | WebCore::JSMainThreadNullState state; |
491 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
492 | g_return_val_if_fail(WEBKIT_DOM_IS_NODE(refNode), 0); |
493 | g_return_val_if_fail(!error || !*error, 0); |
494 | WebCore::Range* item = WebKit::core(self); |
495 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
496 | auto result = item->compareNode(*convertedRefNode); |
497 | if (result.hasException()) { |
498 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
499 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
500 | return 0; |
501 | } |
502 | return result.releaseReturnValue(); |
503 | } |
504 | |
505 | gboolean webkit_dom_range_intersects_node(WebKitDOMRange* self, WebKitDOMNode* refNode, GError** error) |
506 | { |
507 | WebCore::JSMainThreadNullState state; |
508 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), FALSE); |
509 | g_return_val_if_fail(WEBKIT_DOM_IS_NODE(refNode), FALSE); |
510 | g_return_val_if_fail(!error || !*error, FALSE); |
511 | WebCore::Range* item = WebKit::core(self); |
512 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
513 | auto result = item->intersectsNode(*convertedRefNode); |
514 | if (result.hasException()) { |
515 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
516 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
517 | return false; |
518 | } |
519 | return result.releaseReturnValue(); |
520 | } |
521 | |
522 | gshort webkit_dom_range_compare_point(WebKitDOMRange* self, WebKitDOMNode* refNode, glong offset, GError** error) |
523 | { |
524 | WebCore::JSMainThreadNullState state; |
525 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
526 | g_return_val_if_fail(WEBKIT_DOM_IS_NODE(refNode), 0); |
527 | g_return_val_if_fail(!error || !*error, 0); |
528 | WebCore::Range* item = WebKit::core(self); |
529 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
530 | auto result = item->comparePoint(*convertedRefNode, offset); |
531 | if (result.hasException()) { |
532 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
533 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
534 | return 0; |
535 | } |
536 | return result.releaseReturnValue(); |
537 | } |
538 | |
539 | gboolean webkit_dom_range_is_point_in_range(WebKitDOMRange* self, WebKitDOMNode* refNode, glong offset, GError** error) |
540 | { |
541 | WebCore::JSMainThreadNullState state; |
542 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), FALSE); |
543 | g_return_val_if_fail(WEBKIT_DOM_IS_NODE(refNode), FALSE); |
544 | g_return_val_if_fail(!error || !*error, FALSE); |
545 | WebCore::Range* item = WebKit::core(self); |
546 | WebCore::Node* convertedRefNode = WebKit::core(refNode); |
547 | auto result = item->isPointInRange(*convertedRefNode, offset); |
548 | if (result.hasException()) { |
549 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
550 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
551 | return false; |
552 | } |
553 | return result.releaseReturnValue(); |
554 | } |
555 | |
556 | void webkit_dom_range_expand(WebKitDOMRange* self, const gchar* unit, GError** error) |
557 | { |
558 | WebCore::JSMainThreadNullState state; |
559 | g_return_if_fail(WEBKIT_DOM_IS_RANGE(self)); |
560 | g_return_if_fail(unit); |
561 | g_return_if_fail(!error || !*error); |
562 | WebCore::Range* item = WebKit::core(self); |
563 | WTF::String convertedUnit = WTF::String::fromUTF8(unit); |
564 | auto result = item->expand(convertedUnit); |
565 | if (result.hasException()) { |
566 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
567 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
568 | } |
569 | } |
570 | |
571 | WebKitDOMNode* webkit_dom_range_get_start_container(WebKitDOMRange* self, GError** error) |
572 | { |
573 | WebCore::JSMainThreadNullState state; |
574 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
575 | UNUSED_PARAM(error); |
576 | WebCore::Range* item = WebKit::core(self); |
577 | RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->startContainer()); |
578 | return WebKit::kit(gobjectResult.get()); |
579 | } |
580 | |
581 | glong webkit_dom_range_get_start_offset(WebKitDOMRange* self, GError** error) |
582 | { |
583 | WebCore::JSMainThreadNullState state; |
584 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
585 | UNUSED_PARAM(error); |
586 | WebCore::Range* item = WebKit::core(self); |
587 | glong result = item->startOffset(); |
588 | return result; |
589 | } |
590 | |
591 | WebKitDOMNode* webkit_dom_range_get_end_container(WebKitDOMRange* self, GError** error) |
592 | { |
593 | WebCore::JSMainThreadNullState state; |
594 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
595 | UNUSED_PARAM(error); |
596 | WebCore::Range* item = WebKit::core(self); |
597 | RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->endContainer()); |
598 | return WebKit::kit(gobjectResult.get()); |
599 | } |
600 | |
601 | glong webkit_dom_range_get_end_offset(WebKitDOMRange* self, GError** error) |
602 | { |
603 | WebCore::JSMainThreadNullState state; |
604 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
605 | UNUSED_PARAM(error); |
606 | WebCore::Range* item = WebKit::core(self); |
607 | glong result = item->endOffset(); |
608 | return result; |
609 | } |
610 | |
611 | gboolean webkit_dom_range_get_collapsed(WebKitDOMRange* self, GError** error) |
612 | { |
613 | WebCore::JSMainThreadNullState state; |
614 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), FALSE); |
615 | UNUSED_PARAM(error); |
616 | WebCore::Range* item = WebKit::core(self); |
617 | gboolean result = item->collapsed(); |
618 | return result; |
619 | } |
620 | |
621 | WebKitDOMNode* webkit_dom_range_get_common_ancestor_container(WebKitDOMRange* self, GError** error) |
622 | { |
623 | WebCore::JSMainThreadNullState state; |
624 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
625 | UNUSED_PARAM(error); |
626 | WebCore::Range* item = WebKit::core(self); |
627 | RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->commonAncestorContainer()); |
628 | return WebKit::kit(gobjectResult.get()); |
629 | } |
630 | |
631 | gchar* webkit_dom_range_get_text(WebKitDOMRange* self) |
632 | { |
633 | WebCore::JSMainThreadNullState state; |
634 | g_return_val_if_fail(WEBKIT_DOM_IS_RANGE(self), 0); |
635 | WebCore::Range* item = WebKit::core(self); |
636 | gchar* result = convertToUTF8String(item->text()); |
637 | return result; |
638 | } |
639 | |
640 | G_GNUC_END_IGNORE_DEPRECATIONS; |
641 | |