-
Notifications
You must be signed in to change notification settings - Fork 6
/
css.go
2219 lines (1812 loc) · 62.1 KB
/
css.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
package protocol
import (
"encoding/json"
"github.com/yijinliu/algo-lib/go/src/logging"
hc "github.com/yijinliu/headless-chromium/go"
"sync"
)
type StyleSheetId string
// Stylesheet type: "injected" for stylesheets injected via extension, "user-agent" for user-agent stylesheets, "inspector" for stylesheets created by the inspector (i.e. those holding the "via inspector" rules), "regular" for regular stylesheets.
type StyleSheetOrigin string
const StyleSheetOriginInjected StyleSheetOrigin = "injected"
const StyleSheetOriginUserAgent StyleSheetOrigin = "user-agent"
const StyleSheetOriginInspector StyleSheetOrigin = "inspector"
const StyleSheetOriginRegular StyleSheetOrigin = "regular"
// CSS rule collection for a single pseudo style.
type PseudoElementMatches struct {
PseudoType *PseudoType `json:"pseudoType"` // Pseudo element type.
Matches []*RuleMatch `json:"matches"` // Matches of CSS rules applicable to the pseudo style.
}
// Inherited CSS rule collection from ancestor node.
type InheritedStyleEntry struct {
InlineStyle *CSSStyle `json:"inlineStyle,omitempty"` // The ancestor node's inline style, if any, in the style inheritance chain.
MatchedCSSRules []*RuleMatch `json:"matchedCSSRules"` // Matches of CSS rules matching the ancestor node in the style inheritance chain.
}
// Match data for a CSS rule.
type RuleMatch struct {
Rule *CSSRule `json:"rule"` // CSS rule in the match.
MatchingSelectors []int `json:"matchingSelectors"` // Matching selector indices in the rule's selectorList selectors (0-based).
}
// Data for a simple selector (these are delimited by commas in a selector list).
type Value struct {
Text string `json:"text"` // Value text.
Range *SourceRange `json:"range,omitempty"` // Value range in the underlying resource (if available).
}
// Selector list data.
type SelectorList struct {
Selectors []*Value `json:"selectors"` // Selectors in the list.
Text string `json:"text"` // Rule selector text.
}
// CSS stylesheet metainformation.
type CSSStyleSheetHeader struct {
StyleSheetId StyleSheetId `json:"styleSheetId"` // The stylesheet identifier.
FrameId *FrameId `json:"frameId"` // Owner frame identifier.
SourceURL string `json:"sourceURL"` // Stylesheet resource URL.
SourceMapURL string `json:"sourceMapURL,omitempty"` // URL of source map associated with the stylesheet (if any).
Origin StyleSheetOrigin `json:"origin"` // Stylesheet origin.
Title string `json:"title"` // Stylesheet title.
OwnerNode *BackendNodeId `json:"ownerNode,omitempty"` // The backend id for the owner node of the stylesheet.
Disabled bool `json:"disabled"` // Denotes whether the stylesheet is disabled.
HasSourceURL bool `json:"hasSourceURL,omitempty"` // Whether the sourceURL field value comes from the sourceURL comment.
IsInline bool `json:"isInline"` // Whether this stylesheet is created for STYLE tag by parser. This flag is not set for document.written STYLE tags.
StartLine float64 `json:"startLine"` // Line offset of the stylesheet within the resource (zero based).
StartColumn float64 `json:"startColumn"` // Column offset of the stylesheet within the resource (zero based).
}
// CSS rule representation.
type CSSRule struct {
StyleSheetId StyleSheetId `json:"styleSheetId,omitempty"` // The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from.
SelectorList *SelectorList `json:"selectorList"` // Rule selector data.
Origin StyleSheetOrigin `json:"origin"` // Parent stylesheet's origin.
Style *CSSStyle `json:"style"` // Associated style declaration.
Media []*CSSMedia `json:"media,omitempty"` // Media list array (for rules involving media queries). The array enumerates media queries starting with the innermost one, going outwards.
}
// CSS rule usage information.
// @experimental
type RuleUsage struct {
StyleSheetId StyleSheetId `json:"styleSheetId"` // The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from.
Range *SourceRange `json:"range"` // Style declaration range in the enclosing stylesheet (if available).
Used bool `json:"used"` // Indicates whether the rule was actually used by some element in the page.
}
// Text range within a resource. All numbers are zero-based.
type SourceRange struct {
StartLine int `json:"startLine"` // Start line of range.
StartColumn int `json:"startColumn"` // Start column of range (inclusive).
EndLine int `json:"endLine"` // End line of range
EndColumn int `json:"endColumn"` // End column of range (exclusive).
}
type ShorthandEntry struct {
Name string `json:"name"` // Shorthand name.
Value string `json:"value"` // Shorthand value.
Important bool `json:"important,omitempty"` // Whether the property has "!important" annotation (implies false if absent).
}
type CSSComputedStyleProperty struct {
Name string `json:"name"` // Computed style property name.
Value string `json:"value"` // Computed style property value.
}
// CSS style representation.
type CSSStyle struct {
StyleSheetId StyleSheetId `json:"styleSheetId,omitempty"` // The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from.
CssProperties []*CSSProperty `json:"cssProperties"` // CSS properties in the style.
ShorthandEntries []*ShorthandEntry `json:"shorthandEntries"` // Computed values for all shorthands found in the style.
CssText string `json:"cssText,omitempty"` // Style declaration text (if available).
Range *SourceRange `json:"range,omitempty"` // Style declaration range in the enclosing stylesheet (if available).
}
// CSS property declaration data.
type CSSProperty struct {
Name string `json:"name"` // The property name.
Value string `json:"value"` // The property value.
Important bool `json:"important,omitempty"` // Whether the property has "!important" annotation (implies false if absent).
Implicit bool `json:"implicit,omitempty"` // Whether the property is implicit (implies false if absent).
Text string `json:"text,omitempty"` // The full property text as specified in the style.
ParsedOk bool `json:"parsedOk,omitempty"` // Whether the property is understood by the browser (implies true if absent).
Disabled bool `json:"disabled,omitempty"` // Whether the property is disabled by the user (present for source-based properties only).
Range *SourceRange `json:"range,omitempty"` // The entire property range in the enclosing style declaration (if available).
}
// CSS media rule descriptor.
type CSSMedia struct {
Text string `json:"text"` // Media query text.
Source string `json:"source"` // Source of the media query: "mediaRule" if specified by a @media rule, "importRule" if specified by an @import rule, "linkedSheet" if specified by a "media" attribute in a linked stylesheet's LINK tag, "inlineSheet" if specified by a "media" attribute in an inline stylesheet's STYLE tag.
SourceURL string `json:"sourceURL,omitempty"` // URL of the document containing the media query description.
Range *SourceRange `json:"range,omitempty"` // The associated rule (@media or @import) header range in the enclosing stylesheet (if available).
StyleSheetId StyleSheetId `json:"styleSheetId,omitempty"` // Identifier of the stylesheet containing this object (if exists).
MediaList []*MediaQuery `json:"mediaList,omitempty"` // Array of media queries.
}
// Media query descriptor.
// @experimental
type MediaQuery struct {
Expressions []*MediaQueryExpression `json:"expressions"` // Array of media query expressions.
Active bool `json:"active"` // Whether the media query condition is satisfied.
}
// Media query expression descriptor.
// @experimental
type MediaQueryExpression struct {
Value float64 `json:"value"` // Media query expression value.
Unit string `json:"unit"` // Media query expression units.
Feature string `json:"feature"` // Media query expression feature.
ValueRange *SourceRange `json:"valueRange,omitempty"` // The associated range of the value text in the enclosing stylesheet (if available).
ComputedLength float64 `json:"computedLength,omitempty"` // Computed length of media query expression (if applicable).
}
// Information about amount of glyphs that were rendered with given font.
// @experimental
type PlatformFontUsage struct {
FamilyName string `json:"familyName"` // Font's family name reported by platform.
IsCustomFont bool `json:"isCustomFont"` // Indicates if the font was downloaded or resolved locally.
GlyphCount float64 `json:"glyphCount"` // Amount of glyphs that were rendered with this font.
}
// CSS keyframes rule representation.
type CSSKeyframesRule struct {
AnimationName *Value `json:"animationName"` // Animation name.
Keyframes []*CSSKeyframeRule `json:"keyframes"` // List of keyframes.
}
// CSS keyframe rule representation.
type CSSKeyframeRule struct {
StyleSheetId StyleSheetId `json:"styleSheetId,omitempty"` // The css style sheet identifier (absent for user agent stylesheet and user-specified stylesheet rules) this rule came from.
Origin StyleSheetOrigin `json:"origin"` // Parent stylesheet's origin.
KeyText *Value `json:"keyText"` // Associated key text.
Style *CSSStyle `json:"style"` // Associated style declaration.
}
// A descriptor of operation to mutate style declaration text.
type StyleDeclarationEdit struct {
StyleSheetId StyleSheetId `json:"styleSheetId"` // The css style sheet identifier.
Range *SourceRange `json:"range"` // The range of the style text in the enclosing stylesheet.
Text string `json:"text"` // New style text.
}
// Details of post layout rendered text positions. The exact layout should not be regarded as stable and may change between versions.
// @experimental
type InlineTextBox struct {
BoundingBox *Rect `json:"boundingBox"` // The absolute position bounding box.
StartCharacterIndex int `json:"startCharacterIndex"` // The starting index in characters, for this post layout textbox substring.
NumCharacters int `json:"numCharacters"` // The number of characters in this post layout textbox substring.
}
// Details of an element in the DOM tree with a LayoutObject.
// @experimental
type LayoutTreeNode struct {
NodeId *NodeId `json:"nodeId"` // The id of the related DOM node matching one from DOM.GetDocument.
BoundingBox *Rect `json:"boundingBox"` // The absolute position bounding box.
LayoutText string `json:"layoutText,omitempty"` // Contents of the LayoutText if any
InlineTextNodes []*InlineTextBox `json:"inlineTextNodes,omitempty"` // The post layout inline text nodes, if any.
StyleIndex int `json:"styleIndex,omitempty"` // Index into the computedStyles array returned by getLayoutTreeAndStyles.
}
// A subset of the full ComputedStyle as defined by the request whitelist.
// @experimental
type ComputedStyle struct {
Properties []*CSSComputedStyleProperty `json:"properties"`
}
// Enables the CSS agent for the given page. Clients should not assume that the CSS agent has been enabled until the result of this command is received.
type CSSEnableCommand struct {
wg sync.WaitGroup
err error
}
func NewCSSEnableCommand() *CSSEnableCommand {
return &CSSEnableCommand{}
}
func (cmd *CSSEnableCommand) Name() string {
return "CSS.enable"
}
func (cmd *CSSEnableCommand) Params() interface{} {
return nil
}
func (cmd *CSSEnableCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func CSSEnable(conn *hc.Conn) (err error) {
cmd := NewCSSEnableCommand()
cmd.Run(conn)
return cmd.err
}
type CSSEnableCB func(err error)
// Enables the CSS agent for the given page. Clients should not assume that the CSS agent has been enabled until the result of this command is received.
type AsyncCSSEnableCommand struct {
cb CSSEnableCB
}
func NewAsyncCSSEnableCommand(cb CSSEnableCB) *AsyncCSSEnableCommand {
return &AsyncCSSEnableCommand{
cb: cb,
}
}
func (cmd *AsyncCSSEnableCommand) Name() string {
return "CSS.enable"
}
func (cmd *AsyncCSSEnableCommand) Params() interface{} {
return nil
}
func (cmd *CSSEnableCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncCSSEnableCommand) Done(data []byte, err error) {
cmd.cb(err)
}
// Disables the CSS agent for the given page.
type CSSDisableCommand struct {
wg sync.WaitGroup
err error
}
func NewCSSDisableCommand() *CSSDisableCommand {
return &CSSDisableCommand{}
}
func (cmd *CSSDisableCommand) Name() string {
return "CSS.disable"
}
func (cmd *CSSDisableCommand) Params() interface{} {
return nil
}
func (cmd *CSSDisableCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func CSSDisable(conn *hc.Conn) (err error) {
cmd := NewCSSDisableCommand()
cmd.Run(conn)
return cmd.err
}
type CSSDisableCB func(err error)
// Disables the CSS agent for the given page.
type AsyncCSSDisableCommand struct {
cb CSSDisableCB
}
func NewAsyncCSSDisableCommand(cb CSSDisableCB) *AsyncCSSDisableCommand {
return &AsyncCSSDisableCommand{
cb: cb,
}
}
func (cmd *AsyncCSSDisableCommand) Name() string {
return "CSS.disable"
}
func (cmd *AsyncCSSDisableCommand) Params() interface{} {
return nil
}
func (cmd *CSSDisableCommand) Done(data []byte, err error) {
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncCSSDisableCommand) Done(data []byte, err error) {
cmd.cb(err)
}
type GetMatchedStylesForNodeParams struct {
NodeId *NodeId `json:"nodeId"`
}
type GetMatchedStylesForNodeResult struct {
InlineStyle *CSSStyle `json:"inlineStyle"` // Inline style for the specified DOM node.
AttributesStyle *CSSStyle `json:"attributesStyle"` // Attribute-defined element style (e.g. resulting from "width=20 height=100%").
MatchedCSSRules []*RuleMatch `json:"matchedCSSRules"` // CSS rules matching this node, from all applicable stylesheets.
PseudoElements []*PseudoElementMatches `json:"pseudoElements"` // Pseudo style matches for this node.
Inherited []*InheritedStyleEntry `json:"inherited"` // A chain of inherited styles (from the immediate node parent up to the DOM tree root).
CssKeyframesRules []*CSSKeyframesRule `json:"cssKeyframesRules"` // A list of CSS keyframed animations matching this node.
}
// Returns requested styles for a DOM node identified by nodeId.
type GetMatchedStylesForNodeCommand struct {
params *GetMatchedStylesForNodeParams
result GetMatchedStylesForNodeResult
wg sync.WaitGroup
err error
}
func NewGetMatchedStylesForNodeCommand(params *GetMatchedStylesForNodeParams) *GetMatchedStylesForNodeCommand {
return &GetMatchedStylesForNodeCommand{
params: params,
}
}
func (cmd *GetMatchedStylesForNodeCommand) Name() string {
return "CSS.getMatchedStylesForNode"
}
func (cmd *GetMatchedStylesForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetMatchedStylesForNodeCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func GetMatchedStylesForNode(params *GetMatchedStylesForNodeParams, conn *hc.Conn) (result *GetMatchedStylesForNodeResult, err error) {
cmd := NewGetMatchedStylesForNodeCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type GetMatchedStylesForNodeCB func(result *GetMatchedStylesForNodeResult, err error)
// Returns requested styles for a DOM node identified by nodeId.
type AsyncGetMatchedStylesForNodeCommand struct {
params *GetMatchedStylesForNodeParams
cb GetMatchedStylesForNodeCB
}
func NewAsyncGetMatchedStylesForNodeCommand(params *GetMatchedStylesForNodeParams, cb GetMatchedStylesForNodeCB) *AsyncGetMatchedStylesForNodeCommand {
return &AsyncGetMatchedStylesForNodeCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncGetMatchedStylesForNodeCommand) Name() string {
return "CSS.getMatchedStylesForNode"
}
func (cmd *AsyncGetMatchedStylesForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetMatchedStylesForNodeCommand) Result() *GetMatchedStylesForNodeResult {
return &cmd.result
}
func (cmd *GetMatchedStylesForNodeCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncGetMatchedStylesForNodeCommand) Done(data []byte, err error) {
var result GetMatchedStylesForNodeResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type GetInlineStylesForNodeParams struct {
NodeId *NodeId `json:"nodeId"`
}
type GetInlineStylesForNodeResult struct {
InlineStyle *CSSStyle `json:"inlineStyle"` // Inline style for the specified DOM node.
AttributesStyle *CSSStyle `json:"attributesStyle"` // Attribute-defined element style (e.g. resulting from "width=20 height=100%").
}
// Returns the styles defined inline (explicitly in the "style" attribute and implicitly, using DOM attributes) for a DOM node identified by nodeId.
type GetInlineStylesForNodeCommand struct {
params *GetInlineStylesForNodeParams
result GetInlineStylesForNodeResult
wg sync.WaitGroup
err error
}
func NewGetInlineStylesForNodeCommand(params *GetInlineStylesForNodeParams) *GetInlineStylesForNodeCommand {
return &GetInlineStylesForNodeCommand{
params: params,
}
}
func (cmd *GetInlineStylesForNodeCommand) Name() string {
return "CSS.getInlineStylesForNode"
}
func (cmd *GetInlineStylesForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetInlineStylesForNodeCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func GetInlineStylesForNode(params *GetInlineStylesForNodeParams, conn *hc.Conn) (result *GetInlineStylesForNodeResult, err error) {
cmd := NewGetInlineStylesForNodeCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type GetInlineStylesForNodeCB func(result *GetInlineStylesForNodeResult, err error)
// Returns the styles defined inline (explicitly in the "style" attribute and implicitly, using DOM attributes) for a DOM node identified by nodeId.
type AsyncGetInlineStylesForNodeCommand struct {
params *GetInlineStylesForNodeParams
cb GetInlineStylesForNodeCB
}
func NewAsyncGetInlineStylesForNodeCommand(params *GetInlineStylesForNodeParams, cb GetInlineStylesForNodeCB) *AsyncGetInlineStylesForNodeCommand {
return &AsyncGetInlineStylesForNodeCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncGetInlineStylesForNodeCommand) Name() string {
return "CSS.getInlineStylesForNode"
}
func (cmd *AsyncGetInlineStylesForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetInlineStylesForNodeCommand) Result() *GetInlineStylesForNodeResult {
return &cmd.result
}
func (cmd *GetInlineStylesForNodeCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncGetInlineStylesForNodeCommand) Done(data []byte, err error) {
var result GetInlineStylesForNodeResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type GetComputedStyleForNodeParams struct {
NodeId *NodeId `json:"nodeId"`
}
type GetComputedStyleForNodeResult struct {
ComputedStyle []*CSSComputedStyleProperty `json:"computedStyle"` // Computed style for the specified DOM node.
}
// Returns the computed style for a DOM node identified by nodeId.
type GetComputedStyleForNodeCommand struct {
params *GetComputedStyleForNodeParams
result GetComputedStyleForNodeResult
wg sync.WaitGroup
err error
}
func NewGetComputedStyleForNodeCommand(params *GetComputedStyleForNodeParams) *GetComputedStyleForNodeCommand {
return &GetComputedStyleForNodeCommand{
params: params,
}
}
func (cmd *GetComputedStyleForNodeCommand) Name() string {
return "CSS.getComputedStyleForNode"
}
func (cmd *GetComputedStyleForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetComputedStyleForNodeCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func GetComputedStyleForNode(params *GetComputedStyleForNodeParams, conn *hc.Conn) (result *GetComputedStyleForNodeResult, err error) {
cmd := NewGetComputedStyleForNodeCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type GetComputedStyleForNodeCB func(result *GetComputedStyleForNodeResult, err error)
// Returns the computed style for a DOM node identified by nodeId.
type AsyncGetComputedStyleForNodeCommand struct {
params *GetComputedStyleForNodeParams
cb GetComputedStyleForNodeCB
}
func NewAsyncGetComputedStyleForNodeCommand(params *GetComputedStyleForNodeParams, cb GetComputedStyleForNodeCB) *AsyncGetComputedStyleForNodeCommand {
return &AsyncGetComputedStyleForNodeCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncGetComputedStyleForNodeCommand) Name() string {
return "CSS.getComputedStyleForNode"
}
func (cmd *AsyncGetComputedStyleForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetComputedStyleForNodeCommand) Result() *GetComputedStyleForNodeResult {
return &cmd.result
}
func (cmd *GetComputedStyleForNodeCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncGetComputedStyleForNodeCommand) Done(data []byte, err error) {
var result GetComputedStyleForNodeResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type GetPlatformFontsForNodeParams struct {
NodeId *NodeId `json:"nodeId"`
}
type GetPlatformFontsForNodeResult struct {
Fonts []*PlatformFontUsage `json:"fonts"` // Usage statistics for every employed platform font.
}
// Requests information about platform fonts which we used to render child TextNodes in the given node.
// @experimental
type GetPlatformFontsForNodeCommand struct {
params *GetPlatformFontsForNodeParams
result GetPlatformFontsForNodeResult
wg sync.WaitGroup
err error
}
func NewGetPlatformFontsForNodeCommand(params *GetPlatformFontsForNodeParams) *GetPlatformFontsForNodeCommand {
return &GetPlatformFontsForNodeCommand{
params: params,
}
}
func (cmd *GetPlatformFontsForNodeCommand) Name() string {
return "CSS.getPlatformFontsForNode"
}
func (cmd *GetPlatformFontsForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetPlatformFontsForNodeCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func GetPlatformFontsForNode(params *GetPlatformFontsForNodeParams, conn *hc.Conn) (result *GetPlatformFontsForNodeResult, err error) {
cmd := NewGetPlatformFontsForNodeCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type GetPlatformFontsForNodeCB func(result *GetPlatformFontsForNodeResult, err error)
// Requests information about platform fonts which we used to render child TextNodes in the given node.
// @experimental
type AsyncGetPlatformFontsForNodeCommand struct {
params *GetPlatformFontsForNodeParams
cb GetPlatformFontsForNodeCB
}
func NewAsyncGetPlatformFontsForNodeCommand(params *GetPlatformFontsForNodeParams, cb GetPlatformFontsForNodeCB) *AsyncGetPlatformFontsForNodeCommand {
return &AsyncGetPlatformFontsForNodeCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncGetPlatformFontsForNodeCommand) Name() string {
return "CSS.getPlatformFontsForNode"
}
func (cmd *AsyncGetPlatformFontsForNodeCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetPlatformFontsForNodeCommand) Result() *GetPlatformFontsForNodeResult {
return &cmd.result
}
func (cmd *GetPlatformFontsForNodeCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncGetPlatformFontsForNodeCommand) Done(data []byte, err error) {
var result GetPlatformFontsForNodeResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type GetStyleSheetTextParams struct {
StyleSheetId StyleSheetId `json:"styleSheetId"`
}
type GetStyleSheetTextResult struct {
Text string `json:"text"` // The stylesheet text.
}
// Returns the current textual content and the URL for a stylesheet.
type GetStyleSheetTextCommand struct {
params *GetStyleSheetTextParams
result GetStyleSheetTextResult
wg sync.WaitGroup
err error
}
func NewGetStyleSheetTextCommand(params *GetStyleSheetTextParams) *GetStyleSheetTextCommand {
return &GetStyleSheetTextCommand{
params: params,
}
}
func (cmd *GetStyleSheetTextCommand) Name() string {
return "CSS.getStyleSheetText"
}
func (cmd *GetStyleSheetTextCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetStyleSheetTextCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func GetStyleSheetText(params *GetStyleSheetTextParams, conn *hc.Conn) (result *GetStyleSheetTextResult, err error) {
cmd := NewGetStyleSheetTextCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type GetStyleSheetTextCB func(result *GetStyleSheetTextResult, err error)
// Returns the current textual content and the URL for a stylesheet.
type AsyncGetStyleSheetTextCommand struct {
params *GetStyleSheetTextParams
cb GetStyleSheetTextCB
}
func NewAsyncGetStyleSheetTextCommand(params *GetStyleSheetTextParams, cb GetStyleSheetTextCB) *AsyncGetStyleSheetTextCommand {
return &AsyncGetStyleSheetTextCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncGetStyleSheetTextCommand) Name() string {
return "CSS.getStyleSheetText"
}
func (cmd *AsyncGetStyleSheetTextCommand) Params() interface{} {
return cmd.params
}
func (cmd *GetStyleSheetTextCommand) Result() *GetStyleSheetTextResult {
return &cmd.result
}
func (cmd *GetStyleSheetTextCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncGetStyleSheetTextCommand) Done(data []byte, err error) {
var result GetStyleSheetTextResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type CollectClassNamesParams struct {
StyleSheetId StyleSheetId `json:"styleSheetId"`
}
type CollectClassNamesResult struct {
ClassNames []string `json:"classNames"` // Class name list.
}
// Returns all class names from specified stylesheet.
// @experimental
type CollectClassNamesCommand struct {
params *CollectClassNamesParams
result CollectClassNamesResult
wg sync.WaitGroup
err error
}
func NewCollectClassNamesCommand(params *CollectClassNamesParams) *CollectClassNamesCommand {
return &CollectClassNamesCommand{
params: params,
}
}
func (cmd *CollectClassNamesCommand) Name() string {
return "CSS.collectClassNames"
}
func (cmd *CollectClassNamesCommand) Params() interface{} {
return cmd.params
}
func (cmd *CollectClassNamesCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func CollectClassNames(params *CollectClassNamesParams, conn *hc.Conn) (result *CollectClassNamesResult, err error) {
cmd := NewCollectClassNamesCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type CollectClassNamesCB func(result *CollectClassNamesResult, err error)
// Returns all class names from specified stylesheet.
// @experimental
type AsyncCollectClassNamesCommand struct {
params *CollectClassNamesParams
cb CollectClassNamesCB
}
func NewAsyncCollectClassNamesCommand(params *CollectClassNamesParams, cb CollectClassNamesCB) *AsyncCollectClassNamesCommand {
return &AsyncCollectClassNamesCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncCollectClassNamesCommand) Name() string {
return "CSS.collectClassNames"
}
func (cmd *AsyncCollectClassNamesCommand) Params() interface{} {
return cmd.params
}
func (cmd *CollectClassNamesCommand) Result() *CollectClassNamesResult {
return &cmd.result
}
func (cmd *CollectClassNamesCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncCollectClassNamesCommand) Done(data []byte, err error) {
var result CollectClassNamesResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type SetStyleSheetTextParams struct {
StyleSheetId StyleSheetId `json:"styleSheetId"`
Text string `json:"text"`
}
type SetStyleSheetTextResult struct {
SourceMapURL string `json:"sourceMapURL"` // URL of source map associated with script (if any).
}
// Sets the new stylesheet text.
type SetStyleSheetTextCommand struct {
params *SetStyleSheetTextParams
result SetStyleSheetTextResult
wg sync.WaitGroup
err error
}
func NewSetStyleSheetTextCommand(params *SetStyleSheetTextParams) *SetStyleSheetTextCommand {
return &SetStyleSheetTextCommand{
params: params,
}
}
func (cmd *SetStyleSheetTextCommand) Name() string {
return "CSS.setStyleSheetText"
}
func (cmd *SetStyleSheetTextCommand) Params() interface{} {
return cmd.params
}
func (cmd *SetStyleSheetTextCommand) Run(conn *hc.Conn) error {
cmd.wg.Add(1)
conn.SendCommand(cmd)
cmd.wg.Wait()
return cmd.err
}
func SetStyleSheetText(params *SetStyleSheetTextParams, conn *hc.Conn) (result *SetStyleSheetTextResult, err error) {
cmd := NewSetStyleSheetTextCommand(params)
cmd.Run(conn)
return &cmd.result, cmd.err
}
type SetStyleSheetTextCB func(result *SetStyleSheetTextResult, err error)
// Sets the new stylesheet text.
type AsyncSetStyleSheetTextCommand struct {
params *SetStyleSheetTextParams
cb SetStyleSheetTextCB
}
func NewAsyncSetStyleSheetTextCommand(params *SetStyleSheetTextParams, cb SetStyleSheetTextCB) *AsyncSetStyleSheetTextCommand {
return &AsyncSetStyleSheetTextCommand{
params: params,
cb: cb,
}
}
func (cmd *AsyncSetStyleSheetTextCommand) Name() string {
return "CSS.setStyleSheetText"
}
func (cmd *AsyncSetStyleSheetTextCommand) Params() interface{} {
return cmd.params
}
func (cmd *SetStyleSheetTextCommand) Result() *SetStyleSheetTextResult {
return &cmd.result
}
func (cmd *SetStyleSheetTextCommand) Done(data []byte, err error) {
if err == nil {
err = json.Unmarshal(data, &cmd.result)
}
cmd.err = err
cmd.wg.Done()
}
func (cmd *AsyncSetStyleSheetTextCommand) Done(data []byte, err error) {
var result SetStyleSheetTextResult
if err == nil {
err = json.Unmarshal(data, &result)
}
if cmd.cb == nil {
logging.Vlog(-1, err)
} else if err != nil {
cmd.cb(nil, err)
} else {
cmd.cb(&result, nil)
}
}
type SetRuleSelectorParams struct {
StyleSheetId StyleSheetId `json:"styleSheetId"`
Range *SourceRange `json:"range"`
Selector string `json:"selector"`
}
type SetRuleSelectorResult struct {