This repository has been archived by the owner on Sep 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.go
6355 lines (5314 loc) · 226 KB
/
dom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2014 Alex Diaconu.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
// Package webkitdomgtk provides WebKit2DOMGTK+ bindings for Go.
package webkitdomgtk
// #cgo pkg-config: webkit2gtk-3.0
//
// #include <stdint.h>
// #include <stdlib.h>
// #include <string.h>
//
// #include <webkitdom/webkitdom.h>
// #include "dom.go.h"
import "C"
import (
"runtime"
"errors"
"unsafe"
"github.com/conformal/gotk3/glib"
)
func init() {
tm := []glib.TypeMarshaler{
// Objects/Interfaces
{glib.Type(C.webkit_dom_node_get_type()), marshalNode},
{glib.Type(C.webkit_dom_object_get_type()), marshalObject},
{glib.Type(C.webkit_dom_node_list_get_type()), marshalNodeList},
{glib.Type(C.webkit_dom_document_get_type()), marshalDocument},
{glib.Type(C.webkit_dom_attr_get_type()), marshalAttr},
{glib.Type(C.webkit_dom_document_get_type()), marshalDocument},
{glib.Type(C.webkit_dom_element_get_type()), marshalElement},
{glib.Type(C.webkit_dom_html_element_get_type()), marshalHTMLElement},
{glib.Type(C.webkit_dom_html_collection_get_type()), marshalHTMLCollection},
{glib.Type(C.webkit_dom_style_sheet_get_type()), marshalStyleSheet},
{glib.Type(C.webkit_dom_style_sheet_list_get_type()), marshal},
{glib.Type(C.webkit_dom_character_data_get_type()), marshalCharacterData},
{glib.Type(C.webkit_dom_processing_instruction_get_type()), marshalProcessingInstruction},
{glib.Type(C.webkit_dom_text_get_type()), marshalText},
{glib.Type(C.webkit_dom_file_list_get_type()), marshalFileList},
{glib.Type(C.webkit_dom_file_get_type()), marshalFile},
{glib.Type(C.webkit_dom_blob_get_type()), marshalBlob},
{glib.Type(C.webkit_dom_media_list_get_type()), marshalMediaList},
{glib.Type(C.webkit_dom_css_style_sheet_get_type()), marshalCSSStyleSheet},
{glib.Type(C.webkit_dom_css_rule_get_type()), marshalCSSRule},
{glib.Type(C.webkit_dom_css_rule_list_get_type()), marshalCSSRuleList},
{glib.Type(C.webkit_dom_css_style_declaration_get_type()), marshalCSSStyleDeclaration},
{glib.Type(C.webkit_dom_css_value_get_type()), marshalCSSValue},
{glib.Type(C.webkit_dom_event_get_type()), marshalEvent},
{glib.Type(C.webkit_dom_xpath_expression_get_type()), marshalXPathExpression},
{glib.Type(C.webkit_dom_xpath_result_get_type()), marshalXPathResult},
{glib.Type(C.webkit_dom_window_get_type()), marshalWindow},
{glib.Type(C.webkit_dom_html_anchor_element_get_type()), marshalHTMLAnchorElement},
{glib.Type(C.webkit_dom_html_applet_element_get_type()), marshalHTMLAppletElement},
{glib.Type(C.webkit_dom_html_area_element_get_type()), marshalHTMLAreaElement},
{glib.Type(C.webkit_dom_html_br_element_get_type()), marshalHTMLBRElement},
{glib.Type(C.webkit_dom_html_base_element_get_type()), marshalHTMLBaseElement},
{glib.Type(C.webkit_dom_html_title_element_get_type()), marshalHTMLTitleElement},
{glib.Type(C.webkit_dom_html_text_area_element_get_type()), marshalHTMLTextAreaElement},
{glib.Type(C.webkit_dom_html_head_element_get_type()), marshalHTMLHeadElement},
{glib.Type(C.webkit_dom_html_link_element_get_type()), marshalHTMLLinkElement},
{glib.Type(C.webkit_dom_html_body_element_get_type()), marshalHTMLBodyElement},
{glib.Type(C.webkit_dom_html_button_element_get_type()), marshalHTMLButtonElement},
{glib.Type(C.webkit_dom_html_div_element_get_type()), marshalHTMLDivElement},
{glib.Type(C.webkit_dom_html_document_get_type()), marshalHTMLDocument},
{glib.Type(C.webkit_dom_html_frame_element_get_type()), marshalHTMLFrameElement},
{glib.Type(C.webkit_dom_html_frame_set_element_get_type()), marshalHTMLFrameSetElement},
{glib.Type(C.webkit_dom_html_embed_element_get_type()), marshalHTMLEmbedElement},
{glib.Type(C.webkit_dom_html_field_set_element_get_type()), marshalHTMLFieldSetElement},
{glib.Type(C.webkit_dom_html_input_element_get_type()), marshalHTMLInputElement},
{glib.Type(C.webkit_dom_html_label_element_get_type()), marshalHTMLLabelElement},
{glib.Type(C.webkit_dom_html_image_element_get_type()), marshalHTMLImageElement},
{glib.Type(C.webkit_dom_html_form_element_get_type()), marshalHTMLFormElement},
{glib.Type(C.webkit_dom_html_meta_element_get_type()), marshalHTMLMetaElement},
{glib.Type(C.webkit_dom_html_object_element_get_type()), marshalHTMLObjectElement},
{glib.Type(C.webkit_dom_html_opt_group_element_get_type()), marshalHTMLOptGroupElement},
{glib.Type(C.webkit_dom_html_option_element_get_type()), marshalHTMLOptionElement},
{glib.Type(C.webkit_dom_html_options_collection_get_type()), marshalHTMLOptionsCollection},
{glib.Type(C.webkit_dom_html_script_element_get_type()), marshalHTMLScriptElement},
{glib.Type(C.webkit_dom_html_select_element_get_type()), marshalHTMLSelectElement},
}
glib.RegisterGValueMarshalers(tm)
}
type Object struct {
*glib.Object
}
func marshalObject(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapObject(obj), nil
}
func wrapObject(obj *glib.Object) *Object {
return &Object{obj}
}
func (o *Object) native() *C.WebKitDOMObject {
if o == nil || o.GObject == nil {
return nil
}
p := unsafe.Pointer(o.GObject)
return C.toWebKitDOMObject(p)
}
func newObject(p unsafe.Pointer) *Object {
return wrapObject(newGlibObject(p))
}
type Node struct {
Object
}
func marshalNode(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapNode(obj), nil
}
func wrapNode(obj *glib.Object) *Node {
return &Node{Object{obj}}
}
func (n *Node) native() *C.WebKitDOMNode {
if n == nil || n.GObject == nil {
return nil
}
p := unsafe.Pointer(n.GObject)
return C.toWebKitDOMNode(p)
}
func newNode(p unsafe.Pointer) *Node {
return wrapNode(newGlibObject(p))
}
// ReplaceChild wraps webkit_dom_node_replace_child().
func (n *Node) ReplaceChild(newChild, oldChild *Node) (*Node, error) {
var err *C.GError = nil
C.webkit_dom_node_replace_child(n.native(), newChild.native(), oldChild.native(), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return oldChild, nil
}
// RemoveChild wraps webkit_dom_node_remove_child().
func (n *Node) RemoveChild(oldChild *Node) (*Node, error) {
var err *C.GError = nil
C.webkit_dom_node_remove_child(n.native(), oldChild.native(), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return oldChild, nil
}
// AppendChild wraps webkit_dom_node_append_child().
//
// http://webkitgtk.org/reference/webkitdomgtk/2.4.6/WebKitDOMNode.html#webkit-dom-node-append-child
// http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-184E7107
func (n *Node) AppendChild(newChild *Node) (*Node, error) {
var err *C.GError = nil
C.webkit_dom_node_append_child(n.native(), newChild.native(), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newChild, nil
}
// HasChildNodes wraps webkit_dom_node_has_child_nodes().
func (n *Node) HasChildNodes() bool {
return gobool(C.webkit_dom_node_has_child_nodes(n.native()))
}
func newGlibObject(p unsafe.Pointer) *glib.Object {
obj := &glib.Object{GObject: glib.ToGObject(p)}
obj.RefSink()
runtime.SetFinalizer(obj, (*glib.Object).Unref)
return obj
}
// GLib <-> Go boolean conversion
func gboolean(b bool) C.gboolean {
if b {
return C.gboolean(1)
}
return C.gboolean(0)
}
func gobool(b C.gboolean) bool {
return b != 0
}
// Clone wraps webkit_dom_node_clone_node().
func (n *Node) Clone(deep bool) *Node {
c := C.webkit_dom_node_clone_node(n.native(), gboolean(deep))
if c == nil {
return nil
}
return newNode(unsafe.Pointer(c))
}
// Normalize wraps webkit_dom_node_normalize().
func (n *Node) Normalize() {
C.webkit_dom_node_normalize(n.native())
}
// IsSupported wraps webkit_dom_node_is_supported().
func (n *Node) IsSupported(feature, version string) bool {
f := C.CString(feature)
defer C.free(unsafe.Pointer(f))
v := C.CString(version)
defer C.free(unsafe.Pointer(v))
b := C.webkit_dom_node_is_supported(n.native(), (*C.gchar)(f), (*C.gchar)(v))
return gobool(b)
}
// TODO: IsSameNode
// IsEqual wraps webkit_dom_node_is_equal_node().
func (n *Node) IsEqual(other *Node) bool {
b := C.webkit_dom_node_is_equal_node(n.native(), other.native())
return gobool(b)
}
// LookupPrefix wraps webkit_dom_node_lookup_prefix().)
func (n *Node) LookupPrefix(namespaceURI string) string {
uri := C.CString(namespaceURI)
defer C.free(unsafe.Pointer(uri))
s := C.webkit_dom_node_lookup_prefix(n.native(), (*C.gchar)(uri))
return C.GoString((*C.char)(s))
}
// LookupNamespaceURI wraps webkit_dom_node_lookup_namespace_uri().)
func (n *Node) LookupNamespaceURI(prefix string) string {
p := C.CString(prefix)
defer C.free(unsafe.Pointer(p))
s := C.webkit_dom_node_lookup_namespace_uri(n.native(), (*C.gchar)(p))
return C.GoString((*C.char)(s))
}
// IsDefaultNamespace wraps webkit_dom_node_is_default_namespace().
func (n *Node) IsDefaultNamespace(namespaceURI string) bool {
uri := C.CString(namespaceURI)
defer C.free(unsafe.Pointer(uri))
b := C.webkit_dom_node_is_default_namespace(n.native(), (*C.gchar)(uri))
return gobool(b)
}
// CompareDocumentPosition wraps webkit_dom_node_compare_document_position().
func (n *Node) CompareDocumentPosition(other *Node) DocumentPosition {
dp := C.webkit_dom_node_compare_document_position(n.native(), other.native())
return DocumentPosition(dp)
}
// Contains wraps webkit_dom_node_contains().
func (n *Node) Contains(other *Node) bool {
b := C.webkit_dom_node_contains(n.native(), other.native())
return gobool(b)
}
// Name wraps webkit_dom_node_get_node_name().
func (n *Node) Name() string {
s := C.webkit_dom_node_get_node_name(n.native())
return C.GoString((*C.char)(s))
}
// Value wraps webkit_dom_node_get_node_value().
func (n *Node) Value() string {
s := C.webkit_dom_node_get_node_value(n.native())
return C.GoString((*C.char)(s))
}
// SetValue wraps webkit_dom_node_set_node_value().
//
// http://webkitgtk.org/reference/webkitdomgtk/2.4.6/WebKitDOMNode.html#webkit-dom-node-set-node-value
func (n *Node) SetValue(value string) error {
v := C.CString(value)
defer C.free(unsafe.Pointer(v))
var err *C.GError = nil
C.webkit_dom_node_set_node_value(n.native(), (*C.gchar)(v), &err)
if err != nil {
defer C.g_error_free(err)
return errors.New(C.GoString((*C.char)(err.message)))
}
return nil
}
// Type wraps webkit_dom_node_get_node_type().
func (n *Node) Type() Type {
t := C.webkit_dom_node_get_node_type(n.native())
return Type(t)
}
// ParentNode wraps webkit_dom_node_get_parent_node().
func (n *Node) ParentNode() *Node {
pn := C.webkit_dom_node_get_parent_node(n.native())
if pn == nil {
return nil
}
return newNode(unsafe.Pointer(pn))
}
// ChildNodes wraps webkit_dom_node_get_child_nodes().
func (n *Node) ChildNodes() *NodeList {
cl := C.webkit_dom_node_get_child_nodes(n.native())
return newNodeList(unsafe.Pointer(cl))
}
// FirstChild wraps webkit_dom_node_get_first_child().
func (n *Node) FirstChild() *Node {
f := C.webkit_dom_node_get_first_child(n.native())
if f == nil {
return nil
}
return newNode(unsafe.Pointer(f))
}
// LastChild wraps webkit_dom_node_get_last_child().
func (n *Node) LastChild() *Node {
l := C.webkit_dom_node_get_first_child(n.native())
if l == nil {
return nil
}
return newNode(unsafe.Pointer(l))
}
// PreviousSibling wraps webkit_dom_node_get_previous_sibling().
func (n *Node) PreviousSibling() *Node {
ps := C.webkit_dom_node_get_previous_sibling(n.native())
if ps == nil {
return nil
}
return newNode(unsafe.Pointer(ps))
}
// NextSibling wraps webkit_dom_node_get_next_sibling().
func (n *Node) NextSibling() *Node {
ns := C.webkit_dom_node_get_next_sibling(n.native())
if ns == nil {
return nil
}
return newNode(unsafe.Pointer(ns))
}
// NamespaceURI wraps webkit_dom_node_get_namespace_uri().
func (n *Node) NamespaceURI() string {
uri := C.webkit_dom_node_get_namespace_uri(n.native())
if uri == nil {
return ""
}
return C.GoString((*C.char)(uri))
}
// Prefix wraps webkit_dom_node_get_prefix().
func (n *Node) Prefix() string {
p := C.webkit_dom_node_get_prefix(n.native())
if p == nil {
return ""
}
return C.GoString((*C.char)(p))
}
// SetPrefix wraps webkit_dom_node_set_prefix().
func (n *Node) SetPrefix(value string) error {
p := C.CString(value)
defer C.free(unsafe.Pointer(p))
var err *C.GError = nil
C.webkit_dom_node_set_prefix(n.native(), (*C.gchar)(p), &err)
if err != nil {
defer C.g_error_free(err)
return errors.New(C.GoString((*C.char)(err.message)))
}
return nil
}
// LocalName wraps webkit_dom_node_get_local_name().
func (n *Node) LocalName() string {
ln := C.webkit_dom_node_get_local_name(n.native())
if ln == nil {
return ""
}
return C.GoString((*C.char)(ln))
}
// BaseURI wraps webkit_dom_node_get_base_uri().
func (n *Node) BaseURI() string {
uri := C.webkit_dom_node_get_base_uri(n.native())
if uri == nil {
return ""
}
return C.GoString((*C.char)(uri))
}
// TextContent wraps webkit_dom_node_get_text_content().
func (n *Node) TextContent() string {
t := C.webkit_dom_node_get_text_content(n.native())
if t == nil {
return ""
}
return C.GoString((*C.char)(t))
}
// SetTextContent wraps webkit_dom_node_set_text_content().
func (n *Node) SetTextContent(content string) error {
c := C.CString(content)
defer C.free(unsafe.Pointer(c))
var err *C.GError = nil
C.webkit_dom_node_set_text_content(n.native(), (*C.gchar)(c), &err)
if err != nil {
defer C.g_error_free(err)
return errors.New(C.GoString((*C.char)(err.message)))
}
return nil
}
func (n *Node) ParentElement() *Element {
e := C.webkit_dom_node_get_parent_element(n.native())
return newElement(unsafe.Pointer(e))
}
/*
* NodeList
*/
type NodeList struct {
Object
}
func marshalNodeList(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapNodeList(obj), nil
}
func newNodeList(p unsafe.Pointer) *NodeList {
return wrapNodeList(newGlibObject(p))
}
func wrapNodeList(obj *glib.Object) *NodeList {
return &NodeList{Object{obj}}
}
func (l *NodeList) native() *C.WebKitDOMNodeList {
if l == nil || l.GObject == nil {
return nil
}
p := unsafe.Pointer(l.GObject)
return C.toWebKitDOMNodeList(p)
}
// Len wraps webkit_dom_node_list_get_length().
func (l *NodeList) Len() int {
return int(C.webkit_dom_node_list_get_length(l.native()))
}
// Item wraps webkit_dom_node_list_item().
func (l *NodeList) Item(index int) *Node {
n := C.webkit_dom_node_list_item(l.native(), (C.gulong)(index))
return newNode(unsafe.Pointer(n))
}
type NodeMap struct {
Object
}
func newNodeMap(p unsafe.Pointer) *NodeMap {
return wrapNodeMap(obj)
}
func marshalNodeMap(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapNodeMap(obj), nil
}
func wrapNodeMap(obj *glib.Object) *NodeMap {
return &NodeMap{Object{obj}}
}
func (m *NodeMap) native() *C.WebKitDOMNamedNodeMap {
if m == nil || m.GObject == nil {
return nil
}
p := unsafe.Pointer(m.GObject)
return C.toWebKitDOMNamedNodeMap(p)
}
func (m *NodeMap) toWebKitDOMNamedNodeMap() *C.WebKitDOMNamedNodeMap {
return m.native();
}
func (m *NodeMap) Node(name string) *Node {
s := C.CString(name)
defer C.free(unsafe.Pointer(s))
n := C.webkit_dom_named_node_map_get_named_item(m.native(), (*C.gchar)(s))
return newNode(unsafe.Pointer(n))
}
func (m *NodeMap) Set(node *Node) *Node {
n := C.webkit_dom_named_node_map_set_named_item(m.native(), node.native(), nil)
if n != nil {
return newNode(unsafe.Pointer(n))
}
return nil
}
func (m *nodeMap) Len() int {
return int(C.webkit_dom_named_node_map_get_length(m.native()))
}
func (m *nodeMap) At(index int) *Node {
n := C.webkit_dom_named_node_map_item(m.native(), (C.gulong)(index))
if n != nil {
return newNode(unsafe.Pointer(n))
}
return nil
}
/*
* NodeIterator
*/
type NodeIterator struct {
Object
}
func marshalNodeIterator(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapNodeIterator(obj), nil
}
func wrapNodeIterator(obj *glib.Object) *NodeIterator {
return &NodeIterator{Object{obj}}
}
func (n *NodeIterator) native() *C.WebKitDOMNodeIterator {
if n == nil || n.GObject == nil {
return nil
}
p := unsafe.Pointer(n.GObject)
return C.toWebKitDOMNodeIterator(p)
}
func newNodeIterator(p unsafe.Pointer) *NodeIterator {
return wrapNodeIterator(newGlibObject(p))
}
func (i *NodeIterator) NextNode() (*Node, error) {
var err *C.GError
n := C.webkit_dom_node_iterator_next_node(i.native(), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newNode(unsafe.Pointer(n)), nil
}
func (i *NodeIterator) PreviousNode() (*Node, error) {
var err *C.GError
n := C.webkit_dom_node_iterator_next_node(i.native(), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newNode(unsafe.Pointer(n)), nil
}
func (i *NodeIterator) Detach() {
C.webkit_dom_node_iterator_detach(i.native())
}
func (i *NodeIterator) Root() *Node {
n := C.webkit_dom_node_iterator_get_root(i.native())
return newNode(unsafe.Pointer(n))
}
func (i *NodeIterator) WhatToShow() uint {
return uint(C.webkit_dom_node_iterator_get_what_to_show(i.native()))
}
func (i *NodeIterator) Filter() *NodeFilter {
f := C.webkit_dom_node_iterator_get_filter(i.native())
return newNodeFilter(unsafe.Pointer(f))
}
func (i *NodeIterator) ExpandEntityReferences() bool {
return gobool(C.webkit_dom_node_iterator_get_expand_entity_references(i.native()))
}
func (i *NodeIterator) ReferenceNode() *Node {
n := C.webkit_dom_node_iterator_get_reference_node(i.native())
return newNode(unsafe.Pointer(n))
}
func (i *NodeIterator) PointerBeforeReferenceNode() bool {
return gobool(C.webkit_dom_node_iterator_get_pointer_before_reference_node(i.native()))
}
/*
* NodeFilter
*/
type NodeFilter struct {
// TODO
}
/*
* Document
*/
type Document struct {
Node
}
func marshalDocument(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}
return wrapDocument(obj), nil
}
func wrapDocument(obj *glib.Object) *Document {
return &Document{Node{Object{obj}}}
}
func (d *Document) native() *C.WebKitDOMDocument {
if d == nil || d.GObject == nil {
return nil
}
p := unsafe.Pointer(d.GObject)
return C.toWebKitDOMDocument(p)
}
func newDocument(p unsafe.Pointer) *Document {
return wrapDocument(newGlibObject(p))
}
func (d *Document) CreateElement(tag string) error {
t := C.CString(tag)
defer C.free(unsafe.Pointer(t))
var err *C.GError
e := C.webkit_dom_document_create_element(d.native(), (*C.gchar)(t), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newElement(unsafe.Pointer(e)), nil
}
func (d *Document) CreateTextNode(data string) *Text {
d := C.CString(data)
defer C.free(unsafe.Pointer(d))
t := C.webkit_dom_document_create_text_node(d.native(), (*C.gchar)(d))
return newText(unsafe.Pointer(t))
}
// func (d *Document) CreateComment(data string) *Comment {
// cd := C.CString(data)
// defer C.free(unsafe.Pointer(cd))
// c := C.webkit_dom_document_create_comment(d.native(), (*C.gchar)(cd))
// return newComment(unsafe.Pointer(c))
// }
// func (d *Document) CreateCDataSection(data string) (*CDataSection, error) {
// cd := C.CString(data)
// defer C.free(unsafe.Pointer(cd))
// var err *C.GError
// cds := C.webkit_dom_document_create_cdata_section(d.native(), (*C.gchar)(cd), &err)
// if err != nil {
// defer C.g_error_free(err)
// return nil, errors.New(C.GoString((*C.char)(err.message)))
// }
// return newCDataSection(unsafe.Pointer(cds)), nil
// }
//
func (d *Document) CreateProcessingInstruction(target, data string) (*ProcessingInstruction, error) {
t := C.CString(target)
defer C.free(unsafe.Pointer(t))
pid := C.CString(data)
defer C.free(unsafe.Pointer(pid))
var err *C.GError
pi := C.webkit_dom_document_create_processing_instruction(d.native(), (*C.gchar)(pid), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newProcessingInstruction(unsafe.Pointer(pi)), nil
}
func (d *Document) CreateAttribute(name string) (*Attr, error) {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
var err *C.GError
a := C.webkit_dom_document_create_attribute(d.native(), (*C.gchar)(n), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newAttr(unsafe.Pointer(a))
}
func (d *Document) CreateEntityReference(name string) error {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
er := C.webkit_dom_document_create_entity_reference(d.native(), (*C.gchar)(n), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newEntityReference(unsafe.Pointer(er)), nil
}
func (d *Document) ElementsByTagName(tag string) *NodeList {
t := C.CString(tag)
defer C.free(unsafe.Pointer(t))
l := C.webkit_dom_document_get_elements_by_tag_name(d.native(), (*C.gchar)(t))
return newNodeList(unsafe.Pointer(l))
}
func (d *Document) ImportNode(node *Node, deep bool) (*Node, error) {
var err *C.GError
in := C.webkit_dom_document_import_node(d.native(), node.native(), gboolean(deep), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
// This should be a clone of the node we take as a parameter to this function.
return newNode(unsafe.Pointer(in)), nil
}
// webkit_dom_document_create_element_ns
// webkit_dom_document_create_attribute_ns
// webkit_dom_document_get_elements_by_tag_name_ns
func (d *Document) ElementByID(id string) *Element {
i := C.CString(id)
defer C.free(unsafe.Pointer(i))
e := C.webkit_dom_document_get_element_by_id(d.native(), (*C.gchar)(i))
return newElement(unsafe.Pointer(e))
}
func (d *Document) AdoptNode(source *Node) (*Node, error) {
var err *C.GError
C.webkit_dom_document_adopt_node(d.native(), source.native(), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
// Apparently, this doesn't create a copy of the source node, so we can return that here.
return source, nil
}
func (d *Document) CreateEvent(event string) (*Event, error) {
es := C.CString(event)
defer C.free(unsafe.Pointer(es))
var err *C.GError
e := C.webkit_dom_document_create_event(d.native(), (*C.gchar)(es), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newEvent(e), nil
}
func (d *Document) ElementsByName(name string) *NodeList {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
nl := C.webkit_dom_document_get_elements_by_name(d.native(), (*C.gchar)(n))
return newNodeList(unsafe.Pointer(nl))
}
func (d *Document) ElementFromPoint(x, y int) *Element {
e := C.webkit_dom_document_element_from_point(d.native(), C.glong(x), C.glong(y))
return newElement(unsafe.Pointer(e))
}
func (d *Document) CreateCSSStyleDeclaration() *CSSStyleDeclaration {
csd := C.webkit_dom_document_create_css_style_declaration(d.native())
return newCSSStyleDeclaration(unsafe.Pointer(csd))
}
func (d *Document) ElementsByClassName(tag string) *NodeList {
t := C.CString(tag)
defer C.free(unsafe.Pointer(t))
nl := C.webkit_dom_document_get_elements_by_class_name(d.native(), (*C.gchar)(t))
return newNodeList(unsafe.Pointer(nl))
}
func (d *Document) HasFocus() bool {
return gobool(C.webkit_dom_document_has_focus(d.native()))
}
func (d *Document) QuerySelector(selectors string) (*Element, error) {
s := C.CString(selectors)
defer C.free(unsafe.Pointer(s))
var err *C.GError
e := C.webkit_dom_document_query_selector(d.native(), (*C.gchar)(s), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newElement(unsafe.Pointer(e)), nil
}
func (d *Document) QuerySelectorAll(selectors string) (*NodeList, error) {
s := C.CString(selectors)
defer C.free(unsafe.Pointer(s))
nl := C.webkit_dom_document_query_selector_all(d.native(), (*C.gchar)(s), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return newNodeList(unsafe.Pointer(nl)), nil
}
// TODO
// webkit_dom_document_get_doctype ()
// webkit_dom_document_get_implementation ()
func (d *Document) DocumentElement() *Element {
e := C.webkit_dom_document_get_document_element(d.native())
return newElement(unsafe.Pointer(e))
}
func (d *Document) URI() string {
u := C.webkit_dom_document_get_document_uri(d.native())
return C.GoString((*C.char)(u))
}
func (d *Document) SetURI(value string) {
v := C.CString(value)
defer C.free(unsafe.Pointer(v))
C.webkit_dom_document_set_document_uri(d.native(), (*C.gchar)(v))
}
// TODO
// WebKitDOMDOMWindow * webkit_dom_document_get_default_view ()
func (d *Document) StyleSheets() *StyleSheetList {
ssl := C.webkit_dom_document_get_style_sheets(d.native())
return newStyleSheetList(unsafe.Pointer(ssl))
}
func (d *Document) Title() string {
t := C.webkit_dom_document_get_title(d.native())
return C.GoString((*C.char)(t))
}
func (d *Document) SetTitle(value string) {
v := C.CString(value)
defer C.free(unsafe.Pointer(v))
C.webkit_dom_document_set_title(d.native(), (*C.gchar)(v))
}
func (d *Document) Referrer() string {
r := C.webkit_dom_document_get_referrer(d.native())
return C.GoString((*C.char)(r))
}
func (d *Document) Domain() string {
domain := C.webkit_dom_document_get_domain(d.native())
return C.GoString((*C.char)(domain))
}
func (d *Document) URL() string {
u := C.webkit_dom_document_get_url()
return C.GoString((*C.char)(u))
}
func (d *Document) Cookie() (string, error) {
var err *C.GError
c := C.webkit_dom_document_get_cookie(d.native(), &err)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New(C.GoString((*C.char)(err.message)))
}
return C.GoString((*C.char)(c)), nil
}
func (d *Document) SetCookie(value string) error {
v := C.CString(value)
defer C.free(unsafe.Pointer(v))
C.webkit_dom_document_set_cookie(d.native(), (*C.gchar)(v), &err)
if err != nil {
defer C.g_error_free(err)
return errors.New(C.GoString((*C.char)(err.message)))
}
return nil
}
func (d *Document) Body() *HTMLElement {
b := C.webkit_dom_document_get_body(d.native())
return newHTMLElement(unsafe.Pointer(b))
}
func (d *Document) SetBody(value string) error {
v := C.CString(value)
defer C.free(unsafe.Pointer(v))
var err *C.GError
C.webkit_dom_document_set_body(d.native(), (*C.gchar)(v), &err)
if err != nil {
defer C.g_error_free(err)
return errors.New(C.GoString((*C.char)(err.message)))
}
return nil
}
func (d *Document) Head() *HTMLHeadElement {
h := C.webkit_dom_document_get_head(d.native())
return newHTMLHeadElement(unsafe.Pointer(he))
}
func (d *Document) Images() *HTMLCollection {
is := C.webkit_dom_document_get_images(d.native())
return newHTMLCollection(unsafe.Pointer(is))
}
func (d *Document) Applets() *HTMLCollection {
as := C.webkit_dom_document_get_applets(d.native())
return newHTMLCollection(unsafe.Pointer(as))
}
func (d *Document) Links() *HTMLCollection {
ls := C.webkit_dom_document_get_links(d.native())
return newHTMLCollection(unsafe.Pointer(ls))
}
func (d *Document) Forms() *HTMLCollection {
fs := C.webkit_dom_document_get_forms(d.native())
return newHTMLCollection(unsafe.Pointer(fs))
}
func (d *Document) Anchors() *HTMLCollection {
as := C.webkit_dom_document_get_anchors(d.native())
return newHTMLCollection(unsafe.Pointer(as))
}
func (d *Document) LastModified() string {
lm := C.webkit_dom_document_get_last_modified(d.native())
return C.GoString((*C.char)(lm))
}
func (d *Document) Charset() string {
cs := C.webkit_dom_document_get_charset(d.native())
return C.GoString((*C.char)(cs))
}
func (d *Document) SetCharset(value string) {
v := C.CString(value)
defer C.free(unsafe.Pointer(v))
C.webkit_dom_document_set_charset(d.native(), (*C.gchar)(v))
}
func (d *Document) DefaultCharset() string {
dcs := C.webkit_dom_document_get_default_charset(d.native())
return C.GoString((*C.char)(dcs))
}
func (d *Document) ReadyState() string {
rs := C.webkit_dom_document_get_ready_state(d.native())
return C.GoString((*C.char)(rs))
}
func (d *Document) PreferredStyleSheet() string {
pss := C.webkit_dom_document_get_preferred_stylesheet_set(d.native())
return C.GoString((*C.char)(pss))
}
func (d *Document) SelectedStyleSheet() string {
s := C.webkit_dom_document_get_selected_stylesheet_set(d.native())
return C.GoString((*C.char)(s))
}
func (d *Document) SetSelectedStyleSheet(value string) {
v := C.CString(value)
defer C.free(unsafe.Pointer(v))
C.webkit_dom_document_set_selected_stylesheet_set(d.native(), (*C.gchar)(v))
}
func (d *Document) ActiveElement() *Element {
e := C.webkit_dom_document_get_active_element(d.native())
return newElement(unsafe.Pointer(e))
}
/*
* Attr
*/
type Attr struct {
Node
}
func marshalAttr(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := &glib.Object{GObject: glib.ToGObject(unsafe.Pointer(c))}