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