001package Torello.Browser;
002
003import java.util.*;
004import javax.json.*;
005import javax.json.stream.*;
006import java.io.*;
007
008import java.lang.reflect.Method;
009import java.lang.reflect.Parameter;
010import java.util.function.Function;
011
012import Torello.Java.Additional.*;
013import Torello.Java.JSON.*;
014
015import static Torello.Java.JSON.JFlag.*;
016
017import Torello.Java.StrCmpr;
018import Torello.JavaDoc.StaticFunctional;
019import Torello.JavaDoc.JDHeaderBackgroundImg;
020import Torello.JavaDoc.Excuse;
021
022/**
023 * <SPAN CLASS=COPIEDJDK><B><CODE>[No Description Provided by Google]</CODE></B></SPAN>
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
026 */
027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
029public class LayerTree
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private LayerTree () { }
040
041    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
042    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
043    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
044    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
045
046    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
047    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
048    // offically, two empty-vectors.  One for String's, and the other for Classes.
049
050    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
051    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
052
053    static
054    {
055        for (Method m : LayerTree.class.getMethods())
056        {
057            // This doesn't work!  The parameter names are all "arg0" ... "argN"
058            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
059            //
060            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
061
062            Vector<Class<?>> parameterTypesList = new Vector<>();
063        
064            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
065
066            parameterTypes.put(
067                m.getName(),
068                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
069            );
070        }
071    }
072
073    static
074    {
075        Vector<String> v = null;
076
077        v = new Vector<String>(1);
078        parameterNames.put("compositingReasons", v);
079        Collections.addAll(v, new String[]
080        { "layerId", });
081
082        parameterNames.put("disable", EMPTY_VEC_STR);
083
084        parameterNames.put("enable", EMPTY_VEC_STR);
085
086        v = new Vector<String>(1);
087        parameterNames.put("loadSnapshot", v);
088        Collections.addAll(v, new String[]
089        { "tiles", });
090
091        v = new Vector<String>(1);
092        parameterNames.put("makeSnapshot", v);
093        Collections.addAll(v, new String[]
094        { "layerId", });
095
096        v = new Vector<String>(4);
097        parameterNames.put("profileSnapshot", v);
098        Collections.addAll(v, new String[]
099        { "snapshotId", "minRepeatCount", "minDuration", "clipRect", });
100
101        v = new Vector<String>(1);
102        parameterNames.put("releaseSnapshot", v);
103        Collections.addAll(v, new String[]
104        { "snapshotId", });
105
106        v = new Vector<String>(4);
107        parameterNames.put("replaySnapshot", v);
108        Collections.addAll(v, new String[]
109        { "snapshotId", "fromStep", "toStep", "scale", });
110
111        v = new Vector<String>(1);
112        parameterNames.put("snapshotCommandLog", v);
113        Collections.addAll(v, new String[]
114        { "snapshotId", });
115    }
116
117
118    // ********************************************************************************************
119    // ********************************************************************************************
120    // Types - Static Inner Classes
121    // ********************************************************************************************
122    // ********************************************************************************************
123
124    // public static class LayerId => String
125    
126    // public static class SnapshotId => String
127    
128    // public static class PaintProfile => Number[]
129    
130    /** Rectangle where scrolling happens on the main thread. */
131    public static class ScrollRect
132        extends BaseType
133        implements java.io.Serializable
134    {
135        /** For Object Serialization.  java.io.Serializable */
136        protected static final long serialVersionUID = 1;
137        
138        public boolean[] optionals()
139        { return new boolean[] { false, false, }; }
140        
141        /** Rectangle itself. */
142        public final DOM.Rect rect;
143        
144        /** Reason for rectangle to force scrolling on the main thread */
145        public final String type;
146        
147        /**
148         * Constructor
149         *
150         * @param rect Rectangle itself.
151         * 
152         * @param type Reason for rectangle to force scrolling on the main thread
153         * <BR />Acceptable Values: ["RepaintsOnScroll", "TouchEventHandler", "WheelEventHandler"]
154         */
155        public ScrollRect(DOM.Rect rect, String type)
156        {
157            // Exception-Check(s) to ensure that if any parameters which are not declared as
158            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
159            
160            if (rect == null) BRDPC.throwNPE("rect");
161            if (type == null) BRDPC.throwNPE("type");
162            
163            // Exception-Check(s) to ensure that if any parameters which must adhere to a
164            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
165            
166            BRDPC.checkIAE(
167                "type", type,
168                "RepaintsOnScroll", "TouchEventHandler", "WheelEventHandler"
169            );
170            
171            this.rect  = rect;
172            this.type  = type;
173        }
174        
175        /**
176         * JSON Object Constructor
177         * @param jo A Json-Object having data about an instance of {@code 'ScrollRect'}.
178         */
179        public ScrollRect (JsonObject jo)
180        {
181            this.rect  = ReadJSON.getObject(jo, "rect", DOM.Rect.class, false, true);
182            this.type  = ReadJSON.getString(jo, "type", false, true);
183        }
184        
185        
186        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
187        public boolean equals(Object other)
188        {
189            if (other == null)                       return false;
190            if (other.getClass() != this.getClass()) return false;
191        
192            ScrollRect o = (ScrollRect) other;
193        
194            return
195                    Objects.equals(this.rect, o.rect)
196                &&  Objects.equals(this.type, o.type);
197        }
198        
199        /** Generates a Hash-Code for {@code 'this'} instance */
200        public int hashCode()
201        {
202            return
203                    this.rect.hashCode()
204                +   Objects.hashCode(this.type);
205        }
206    }
207    
208    /** Sticky position constraints. */
209    public static class StickyPositionConstraint
210        extends BaseType
211        implements java.io.Serializable
212    {
213        /** For Object Serialization.  java.io.Serializable */
214        protected static final long serialVersionUID = 1;
215        
216        public boolean[] optionals()
217        { return new boolean[] { false, false, true, true, }; }
218        
219        /** Layout rectangle of the sticky element before being shifted */
220        public final DOM.Rect stickyBoxRect;
221        
222        /** Layout rectangle of the containing block of the sticky element */
223        public final DOM.Rect containingBlockRect;
224        
225        /**
226         * The nearest sticky layer that shifts the sticky box
227         * <BR />
228         * <BR /><B>OPTIONAL</B>
229         */
230        public final String nearestLayerShiftingStickyBox;
231        
232        /**
233         * The nearest sticky layer that shifts the containing block
234         * <BR />
235         * <BR /><B>OPTIONAL</B>
236         */
237        public final String nearestLayerShiftingContainingBlock;
238        
239        /**
240         * Constructor
241         *
242         * @param stickyBoxRect Layout rectangle of the sticky element before being shifted
243         * 
244         * @param containingBlockRect Layout rectangle of the containing block of the sticky element
245         * 
246         * @param nearestLayerShiftingStickyBox The nearest sticky layer that shifts the sticky box
247         * <BR /><B>OPTIONAL</B>
248         * 
249         * @param nearestLayerShiftingContainingBlock The nearest sticky layer that shifts the containing block
250         * <BR /><B>OPTIONAL</B>
251         */
252        public StickyPositionConstraint(
253                DOM.Rect stickyBoxRect, DOM.Rect containingBlockRect, 
254                String nearestLayerShiftingStickyBox, String nearestLayerShiftingContainingBlock
255            )
256        {
257            // Exception-Check(s) to ensure that if any parameters which are not declared as
258            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
259            
260            if (stickyBoxRect == null)       BRDPC.throwNPE("stickyBoxRect");
261            if (containingBlockRect == null) BRDPC.throwNPE("containingBlockRect");
262            
263            this.stickyBoxRect                        = stickyBoxRect;
264            this.containingBlockRect                  = containingBlockRect;
265            this.nearestLayerShiftingStickyBox        = nearestLayerShiftingStickyBox;
266            this.nearestLayerShiftingContainingBlock  = nearestLayerShiftingContainingBlock;
267        }
268        
269        /**
270         * JSON Object Constructor
271         * @param jo A Json-Object having data about an instance of {@code 'StickyPositionConstraint'}.
272         */
273        public StickyPositionConstraint (JsonObject jo)
274        {
275            this.stickyBoxRect                        = ReadJSON.getObject(jo, "stickyBoxRect", DOM.Rect.class, false, true);
276            this.containingBlockRect                  = ReadJSON.getObject(jo, "containingBlockRect", DOM.Rect.class, false, true);
277            this.nearestLayerShiftingStickyBox        = ReadJSON.getString(jo, "nearestLayerShiftingStickyBox", true, false);
278            this.nearestLayerShiftingContainingBlock  = ReadJSON.getString(jo, "nearestLayerShiftingContainingBlock", true, false);
279        }
280        
281        
282        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
283        public boolean equals(Object other)
284        {
285            if (other == null)                       return false;
286            if (other.getClass() != this.getClass()) return false;
287        
288            StickyPositionConstraint o = (StickyPositionConstraint) other;
289        
290            return
291                    Objects.equals(this.stickyBoxRect, o.stickyBoxRect)
292                &&  Objects.equals(this.containingBlockRect, o.containingBlockRect)
293                &&  Objects.equals(this.nearestLayerShiftingStickyBox, o.nearestLayerShiftingStickyBox)
294                &&  Objects.equals(this.nearestLayerShiftingContainingBlock, o.nearestLayerShiftingContainingBlock);
295        }
296        
297        /** Generates a Hash-Code for {@code 'this'} instance */
298        public int hashCode()
299        {
300            return
301                    this.stickyBoxRect.hashCode()
302                +   this.containingBlockRect.hashCode()
303                +   Objects.hashCode(this.nearestLayerShiftingStickyBox)
304                +   Objects.hashCode(this.nearestLayerShiftingContainingBlock);
305        }
306    }
307    
308    /** Serialized fragment of layer picture along with its offset within the layer. */
309    public static class PictureTile
310        extends BaseType
311        implements java.io.Serializable
312    {
313        /** For Object Serialization.  java.io.Serializable */
314        protected static final long serialVersionUID = 1;
315        
316        public boolean[] optionals()
317        { return new boolean[] { false, false, false, }; }
318        
319        /** Offset from owning layer left boundary */
320        public final Number x;
321        
322        /** Offset from owning layer top boundary */
323        public final Number y;
324        
325        /** Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON) */
326        public final String picture;
327        
328        /**
329         * Constructor
330         *
331         * @param x Offset from owning layer left boundary
332         * 
333         * @param y Offset from owning layer top boundary
334         * 
335         * @param picture Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON)
336         */
337        public PictureTile(Number x, Number y, String picture)
338        {
339            // Exception-Check(s) to ensure that if any parameters which are not declared as
340            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
341            
342            if (x == null)       BRDPC.throwNPE("x");
343            if (y == null)       BRDPC.throwNPE("y");
344            if (picture == null) BRDPC.throwNPE("picture");
345            
346            this.x        = x;
347            this.y        = y;
348            this.picture  = picture;
349        }
350        
351        /**
352         * JSON Object Constructor
353         * @param jo A Json-Object having data about an instance of {@code 'PictureTile'}.
354         */
355        public PictureTile (JsonObject jo)
356        {
357            this.x        = ReadNumberJSON.get(jo, "x", false, true);
358            this.y        = ReadNumberJSON.get(jo, "y", false, true);
359            this.picture  = ReadJSON.getString(jo, "picture", false, true);
360        }
361        
362        
363        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
364        public boolean equals(Object other)
365        {
366            if (other == null)                       return false;
367            if (other.getClass() != this.getClass()) return false;
368        
369            PictureTile o = (PictureTile) other;
370        
371            return
372                    Objects.equals(this.x, o.x)
373                &&  Objects.equals(this.y, o.y)
374                &&  Objects.equals(this.picture, o.picture);
375        }
376        
377        /** Generates a Hash-Code for {@code 'this'} instance */
378        public int hashCode()
379        {
380            return
381                    Objects.hashCode(this.x)
382                +   Objects.hashCode(this.y)
383                +   Objects.hashCode(this.picture);
384        }
385    }
386    
387    /** Information about a compositing layer. */
388    public static class Layer
389        extends BaseType
390        implements java.io.Serializable
391    {
392        /** For Object Serialization.  java.io.Serializable */
393        protected static final long serialVersionUID = 1;
394        
395        public boolean[] optionals()
396        { return new boolean[] { false, true, true, false, false, false, false, true, true, true, true, false, false, true, true, true, }; }
397        
398        /** The unique id for this layer. */
399        public final String layerId;
400        
401        /**
402         * The id of parent (not present for root).
403         * <BR />
404         * <BR /><B>OPTIONAL</B>
405         */
406        public final String parentLayerId;
407        
408        /**
409         * The backend id for the node associated with this layer.
410         * <BR />
411         * <BR /><B>OPTIONAL</B>
412         */
413        public final Integer backendNodeId;
414        
415        /** Offset from parent layer, X coordinate. */
416        public final Number offsetX;
417        
418        /** Offset from parent layer, Y coordinate. */
419        public final Number offsetY;
420        
421        /** Layer width. */
422        public final Number width;
423        
424        /** Layer height. */
425        public final Number height;
426        
427        /**
428         * Transformation matrix for layer, default is identity matrix
429         * <BR />
430         * <BR /><B>OPTIONAL</B>
431         */
432        public final Number[] transform;
433        
434        /**
435         * Transform anchor point X, absent if no transform specified
436         * <BR />
437         * <BR /><B>OPTIONAL</B>
438         */
439        public final Number anchorX;
440        
441        /**
442         * Transform anchor point Y, absent if no transform specified
443         * <BR />
444         * <BR /><B>OPTIONAL</B>
445         */
446        public final Number anchorY;
447        
448        /**
449         * Transform anchor point Z, absent if no transform specified
450         * <BR />
451         * <BR /><B>OPTIONAL</B>
452         */
453        public final Number anchorZ;
454        
455        /** Indicates how many time this layer has painted. */
456        public final int paintCount;
457        
458        /**
459         * Indicates whether this layer hosts any content, rather than being used for
460         * transform/scrolling purposes only.
461         */
462        public final boolean drawsContent;
463        
464        /**
465         * Set if layer is not visible.
466         * <BR />
467         * <BR /><B>OPTIONAL</B>
468         */
469        public final Boolean invisible;
470        
471        /**
472         * Rectangles scrolling on main thread only.
473         * <BR />
474         * <BR /><B>OPTIONAL</B>
475         */
476        public final LayerTree.ScrollRect[] scrollRects;
477        
478        /**
479         * Sticky position constraint information
480         * <BR />
481         * <BR /><B>OPTIONAL</B>
482         */
483        public final LayerTree.StickyPositionConstraint stickyPositionConstraint;
484        
485        /**
486         * Constructor
487         *
488         * @param layerId The unique id for this layer.
489         * 
490         * @param parentLayerId The id of parent (not present for root).
491         * <BR /><B>OPTIONAL</B>
492         * 
493         * @param backendNodeId The backend id for the node associated with this layer.
494         * <BR /><B>OPTIONAL</B>
495         * 
496         * @param offsetX Offset from parent layer, X coordinate.
497         * 
498         * @param offsetY Offset from parent layer, Y coordinate.
499         * 
500         * @param width Layer width.
501         * 
502         * @param height Layer height.
503         * 
504         * @param transform Transformation matrix for layer, default is identity matrix
505         * <BR /><B>OPTIONAL</B>
506         * 
507         * @param anchorX Transform anchor point X, absent if no transform specified
508         * <BR /><B>OPTIONAL</B>
509         * 
510         * @param anchorY Transform anchor point Y, absent if no transform specified
511         * <BR /><B>OPTIONAL</B>
512         * 
513         * @param anchorZ Transform anchor point Z, absent if no transform specified
514         * <BR /><B>OPTIONAL</B>
515         * 
516         * @param paintCount Indicates how many time this layer has painted.
517         * 
518         * @param drawsContent 
519         * Indicates whether this layer hosts any content, rather than being used for
520         * transform/scrolling purposes only.
521         * 
522         * @param invisible Set if layer is not visible.
523         * <BR /><B>OPTIONAL</B>
524         * 
525         * @param scrollRects Rectangles scrolling on main thread only.
526         * <BR /><B>OPTIONAL</B>
527         * 
528         * @param stickyPositionConstraint Sticky position constraint information
529         * <BR /><B>OPTIONAL</B>
530         */
531        public Layer(
532                String layerId, String parentLayerId, Integer backendNodeId, Number offsetX, 
533                Number offsetY, Number width, Number height, Number[] transform, Number anchorX, 
534                Number anchorY, Number anchorZ, int paintCount, boolean drawsContent, 
535                Boolean invisible, LayerTree.ScrollRect[] scrollRects, 
536                LayerTree.StickyPositionConstraint stickyPositionConstraint
537            )
538        {
539            // Exception-Check(s) to ensure that if any parameters which are not declared as
540            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
541            
542            if (layerId == null) BRDPC.throwNPE("layerId");
543            if (offsetX == null) BRDPC.throwNPE("offsetX");
544            if (offsetY == null) BRDPC.throwNPE("offsetY");
545            if (width == null)   BRDPC.throwNPE("width");
546            if (height == null)  BRDPC.throwNPE("height");
547            
548            this.layerId                   = layerId;
549            this.parentLayerId             = parentLayerId;
550            this.backendNodeId             = backendNodeId;
551            this.offsetX                   = offsetX;
552            this.offsetY                   = offsetY;
553            this.width                     = width;
554            this.height                    = height;
555            this.transform                 = transform;
556            this.anchorX                   = anchorX;
557            this.anchorY                   = anchorY;
558            this.anchorZ                   = anchorZ;
559            this.paintCount                = paintCount;
560            this.drawsContent              = drawsContent;
561            this.invisible                 = invisible;
562            this.scrollRects               = scrollRects;
563            this.stickyPositionConstraint  = stickyPositionConstraint;
564        }
565        
566        /**
567         * JSON Object Constructor
568         * @param jo A Json-Object having data about an instance of {@code 'Layer'}.
569         */
570        public Layer (JsonObject jo)
571        {
572            this.layerId                   = ReadJSON.getString(jo, "layerId", false, true);
573            this.parentLayerId             = ReadJSON.getString(jo, "parentLayerId", true, false);
574            this.backendNodeId             = ReadBoxedJSON.getInteger(jo, "backendNodeId", true);
575            this.offsetX                   = ReadNumberJSON.get(jo, "offsetX", false, true);
576            this.offsetY                   = ReadNumberJSON.get(jo, "offsetY", false, true);
577            this.width                     = ReadNumberJSON.get(jo, "width", false, true);
578            this.height                    = ReadNumberJSON.get(jo, "height", false, true);
579            this.transform = (jo.getJsonArray("transform") == null)
580                ? null
581                : ReadArrJSON.DimN.arrNumber(jo.getJsonArray("transform"), -1, 0, null, Number[].class);
582        
583            this.anchorX                   = ReadNumberJSON.get(jo, "anchorX", true, false);
584            this.anchorY                   = ReadNumberJSON.get(jo, "anchorY", true, false);
585            this.anchorZ                   = ReadNumberJSON.get(jo, "anchorZ", true, false);
586            this.paintCount                = ReadPrimJSON.getInt(jo, "paintCount");
587            this.drawsContent              = ReadPrimJSON.getBoolean(jo, "drawsContent");
588            this.invisible                 = ReadBoxedJSON.getBoolean(jo, "invisible", true);
589            this.scrollRects = (jo.getJsonArray("scrollRects") == null)
590                ? null
591                : ReadArrJSON.DimN.objArr(jo.getJsonArray("scrollRects"), null, 0, LayerTree.ScrollRect[].class);
592        
593            this.stickyPositionConstraint  = ReadJSON.getObject(jo, "stickyPositionConstraint", LayerTree.StickyPositionConstraint.class, true, false);
594        }
595        
596        
597        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
598        public boolean equals(Object other)
599        {
600            if (other == null)                       return false;
601            if (other.getClass() != this.getClass()) return false;
602        
603            Layer o = (Layer) other;
604        
605            return
606                    Objects.equals(this.layerId, o.layerId)
607                &&  Objects.equals(this.parentLayerId, o.parentLayerId)
608                &&  Objects.equals(this.backendNodeId, o.backendNodeId)
609                &&  Objects.equals(this.offsetX, o.offsetX)
610                &&  Objects.equals(this.offsetY, o.offsetY)
611                &&  Objects.equals(this.width, o.width)
612                &&  Objects.equals(this.height, o.height)
613                &&  Arrays.deepEquals(this.transform, o.transform)
614                &&  Objects.equals(this.anchorX, o.anchorX)
615                &&  Objects.equals(this.anchorY, o.anchorY)
616                &&  Objects.equals(this.anchorZ, o.anchorZ)
617                &&  (this.paintCount == o.paintCount)
618                &&  (this.drawsContent == o.drawsContent)
619                &&  Objects.equals(this.invisible, o.invisible)
620                &&  Arrays.deepEquals(this.scrollRects, o.scrollRects)
621                &&  Objects.equals(this.stickyPositionConstraint, o.stickyPositionConstraint);
622        }
623        
624        /** Generates a Hash-Code for {@code 'this'} instance */
625        public int hashCode()
626        {
627            return
628                    Objects.hashCode(this.layerId)
629                +   Objects.hashCode(this.parentLayerId)
630                +   Objects.hashCode(this.backendNodeId)
631                +   Objects.hashCode(this.offsetX)
632                +   Objects.hashCode(this.offsetY)
633                +   Objects.hashCode(this.width)
634                +   Objects.hashCode(this.height)
635                +   Arrays.deepHashCode(this.transform)
636                +   Objects.hashCode(this.anchorX)
637                +   Objects.hashCode(this.anchorY)
638                +   Objects.hashCode(this.anchorZ)
639                +   this.paintCount
640                +   (this.drawsContent ? 1 : 0)
641                +   Objects.hashCode(this.invisible)
642                +   Arrays.deepHashCode(this.scrollRects)
643                +   this.stickyPositionConstraint.hashCode();
644        }
645    }
646    
647    /** <CODE>[No Description Provided by Google]</CODE> */
648    public static class layerPainted
649        extends BrowserEvent
650        implements java.io.Serializable
651    {
652        /** For Object Serialization.  java.io.Serializable */
653        protected static final long serialVersionUID = 1;
654        
655        public boolean[] optionals()
656        { return new boolean[] { false, false, }; }
657        
658        /** The id of the painted layer. */
659        public final String layerId;
660        
661        /** Clip rectangle. */
662        public final DOM.Rect clip;
663        
664        /**
665         * Constructor
666         *
667         * @param layerId The id of the painted layer.
668         * 
669         * @param clip Clip rectangle.
670         */
671        public layerPainted(String layerId, DOM.Rect clip)
672        {
673            super("LayerTree", "layerPainted", 2);
674            
675            // Exception-Check(s) to ensure that if any parameters which are not declared as
676            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
677            
678            if (layerId == null) BRDPC.throwNPE("layerId");
679            if (clip == null)    BRDPC.throwNPE("clip");
680            
681            this.layerId  = layerId;
682            this.clip     = clip;
683        }
684        
685        /**
686         * JSON Object Constructor
687         * @param jo A Json-Object having data about an instance of {@code 'layerPainted'}.
688         */
689        public layerPainted (JsonObject jo)
690        {
691            super("LayerTree", "layerPainted", 2);
692        
693            this.layerId  = ReadJSON.getString(jo, "layerId", false, true);
694            this.clip     = ReadJSON.getObject(jo, "clip", DOM.Rect.class, false, true);
695        }
696        
697        
698        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
699        public boolean equals(Object other)
700        {
701            if (other == null)                       return false;
702            if (other.getClass() != this.getClass()) return false;
703        
704            layerPainted o = (layerPainted) other;
705        
706            return
707                    Objects.equals(this.layerId, o.layerId)
708                &&  Objects.equals(this.clip, o.clip);
709        }
710        
711        /** Generates a Hash-Code for {@code 'this'} instance */
712        public int hashCode()
713        {
714            return
715                    Objects.hashCode(this.layerId)
716                +   this.clip.hashCode();
717        }
718    }
719    
720    /** <CODE>[No Description Provided by Google]</CODE> */
721    public static class layerTreeDidChange
722        extends BrowserEvent
723        implements java.io.Serializable
724    {
725        /** For Object Serialization.  java.io.Serializable */
726        protected static final long serialVersionUID = 1;
727        
728        public boolean[] optionals()
729        { return new boolean[] { true, }; }
730        
731        /**
732         * Layer tree, absent if not in the comspositing mode.
733         * <BR />
734         * <BR /><B>OPTIONAL</B>
735         */
736        public final LayerTree.Layer[] layers;
737        
738        /**
739         * Constructor
740         *
741         * @param layers Layer tree, absent if not in the comspositing mode.
742         * <BR /><B>OPTIONAL</B>
743         */
744        public layerTreeDidChange(LayerTree.Layer[] layers)
745        {
746            super("LayerTree", "layerTreeDidChange", 1);
747            
748            this.layers  = layers;
749        }
750        
751        /**
752         * JSON Object Constructor
753         * @param jo A Json-Object having data about an instance of {@code 'layerTreeDidChange'}.
754         */
755        public layerTreeDidChange (JsonObject jo)
756        {
757            super("LayerTree", "layerTreeDidChange", 1);
758        
759            this.layers = (jo.getJsonArray("layers") == null)
760                ? null
761                : ReadArrJSON.DimN.objArr(jo.getJsonArray("layers"), null, 0, LayerTree.Layer[].class);
762        
763        }
764        
765        
766        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
767        public boolean equals(Object other)
768        {
769            if (other == null)                       return false;
770            if (other.getClass() != this.getClass()) return false;
771        
772            layerTreeDidChange o = (layerTreeDidChange) other;
773        
774            return
775                    Arrays.deepEquals(this.layers, o.layers);
776        }
777        
778        /** Generates a Hash-Code for {@code 'this'} instance */
779        public int hashCode()
780        {
781            return
782                    Arrays.deepHashCode(this.layers);
783        }
784    }
785    
786    
787    // Counter for keeping the WebSocket Request ID's distinct.
788    private static int counter = 1;
789    
790    /**
791     * Provides the reasons why the given layer was composited.
792     * 
793     * @param layerId The id of the layer for which we want to get the reasons it was composited.
794     * 
795     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
796     * {@link Ret2}&gt;</CODE>
797     *
798     * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 
799     * {@link Script#exec()}), and a {@link Promise} returned.
800     *
801     * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B>
802     * (using {@link Promise#await()}), the {@code Ret2} will subsequently
803     * be returned from that call.
804     * 
805     * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated
806     * in an instance of <B>{@link Ret2}</B>
807     *
808     * <BR /><BR /><UL CLASS=JDUL>
809     * <LI><CODE><B>Ret2.a:</B> String[] (<B>compositingReasons</B>)</CODE>
810     *     <BR />A list of strings specifying reasons for the given layer to become composited.
811     *     <BR /><BR /></LI>
812     * <LI><CODE><B>Ret2.b:</B> String[] (<B>compositingReasonIds</B>)</CODE>
813     *     <BR />A list of strings specifying reason IDs for the given layer to become composited.
814     *     </LI>
815     * </UL>
816     */
817    public static Script<String, JsonObject, Ret2<String[], String[]>> compositingReasons
818        (String layerId)
819    {
820        // Exception-Check(s) to ensure that if any parameters which are not declared as
821        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
822        
823        if (layerId == null) BRDPC.throwNPE("layerId");
824        
825        final int       webSocketID = 27000000 + counter++;
826        final boolean[] optionals   = { false, };
827        
828        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
829        String requestJSON = WriteJSON.get(
830            parameterTypes.get("compositingReasons"),
831            parameterNames.get("compositingReasons"),
832            optionals, webSocketID,
833            "LayerTree.compositingReasons",
834            layerId
835        );
836        
837        // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret2'
838        Function<JsonObject, Ret2<String[], String[]>> 
839            responseProcessor = (JsonObject jo) -> new Ret2<>(
840                (jo.getJsonArray("compositingReasons") == null)
841                    ? null
842                    : ReadArrJSON.DimN.strArr(jo.getJsonArray("compositingReasons"), null, 0, String[].class),
843                (jo.getJsonArray("compositingReasonIds") == null)
844                    ? null
845                    : ReadArrJSON.DimN.strArr(jo.getJsonArray("compositingReasonIds"), null, 0, String[].class)
846            );
847        
848        // Pass the 'defaultSender' to Script-Constructor
849        // The sender that is used can be changed before executing script.
850        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
851    }
852    
853    /**
854     * Disables compositing tree inspection.
855     * 
856     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
857     * {@link Ret0}&gt;</CODE>
858     *
859     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
860     * browser receives the invocation-request.
861     *
862     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
863     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
864     * {@code >} to ensure the Browser Function has run to completion.
865     */
866    public static Script<String, JsonObject, Ret0> disable()
867    {
868        final int          webSocketID = 27001000 + counter++;
869        final boolean[]    optionals   = new boolean[0];
870        
871        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
872        String requestJSON = WriteJSON.get(
873            parameterTypes.get("disable"),
874            parameterNames.get("disable"),
875            optionals, webSocketID,
876            "LayerTree.disable"
877        );
878        
879        // This Remote Command does not have a Return-Value.
880        return new Script<>
881            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
882    }
883    
884    /**
885     * Enables compositing tree inspection.
886     * 
887     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
888     * {@link Ret0}&gt;</CODE>
889     *
890     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
891     * browser receives the invocation-request.
892     *
893     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
894     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
895     * {@code >} to ensure the Browser Function has run to completion.
896     */
897    public static Script<String, JsonObject, Ret0> enable()
898    {
899        final int          webSocketID = 27002000 + counter++;
900        final boolean[]    optionals   = new boolean[0];
901        
902        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
903        String requestJSON = WriteJSON.get(
904            parameterTypes.get("enable"),
905            parameterNames.get("enable"),
906            optionals, webSocketID,
907            "LayerTree.enable"
908        );
909        
910        // This Remote Command does not have a Return-Value.
911        return new Script<>
912            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
913    }
914    
915    /**
916     * Returns the snapshot identifier.
917     * 
918     * @param tiles An array of tiles composing the snapshot.
919     * 
920     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
921     * String&gt;</CODE>
922     * 
923     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
924     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
925     * String&gt;</CODE> will be returned.
926     *
927     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
928     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
929      * may be retrieved.</I>
930     *
931     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
932     * <BR /><BR /><UL CLASS=JDUL>
933     * <LI><CODE>String (<B>snapshotId</B></CODE>)
934     *     <BR />The id of the snapshot.
935     * </LI>
936     * </UL> */
937    public static Script<String, JsonObject, String> loadSnapshot(LayerTree.PictureTile[] tiles)
938    {
939        // Exception-Check(s) to ensure that if any parameters which are not declared as
940        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
941        
942        if (tiles == null) BRDPC.throwNPE("tiles");
943        
944        final int       webSocketID = 27003000 + counter++;
945        final boolean[] optionals   = { false, };
946        
947        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
948        String requestJSON = WriteJSON.get(
949            parameterTypes.get("loadSnapshot"),
950            parameterNames.get("loadSnapshot"),
951            optionals, webSocketID,
952            "LayerTree.loadSnapshot",
953            (Object) tiles
954        );
955        
956        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
957        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
958            ReadJSON.getString(jo, "snapshotId", false, true);
959        
960        // Pass the 'defaultSender' to Script-Constructor
961        // The sender that is used can be changed before executing script.
962        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
963    }
964    
965    /**
966     * Returns the layer snapshot identifier.
967     * 
968     * @param layerId The id of the layer.
969     * 
970     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
971     * String&gt;</CODE>
972     * 
973     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
974     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
975     * String&gt;</CODE> will be returned.
976     *
977     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
978     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
979      * may be retrieved.</I>
980     *
981     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
982     * <BR /><BR /><UL CLASS=JDUL>
983     * <LI><CODE>String (<B>snapshotId</B></CODE>)
984     *     <BR />The id of the layer snapshot.
985     * </LI>
986     * </UL> */
987    public static Script<String, JsonObject, String> makeSnapshot(String layerId)
988    {
989        // Exception-Check(s) to ensure that if any parameters which are not declared as
990        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
991        
992        if (layerId == null) BRDPC.throwNPE("layerId");
993        
994        final int       webSocketID = 27004000 + counter++;
995        final boolean[] optionals   = { false, };
996        
997        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
998        String requestJSON = WriteJSON.get(
999            parameterTypes.get("makeSnapshot"),
1000            parameterNames.get("makeSnapshot"),
1001            optionals, webSocketID,
1002            "LayerTree.makeSnapshot",
1003            layerId
1004        );
1005        
1006        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
1007        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
1008            ReadJSON.getString(jo, "snapshotId", false, true);
1009        
1010        // Pass the 'defaultSender' to Script-Constructor
1011        // The sender that is used can be changed before executing script.
1012        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1013    }
1014    
1015    /**
1016     * <CODE>[No Description Provided by Google]</CODE>
1017     * 
1018     * @param snapshotId The id of the layer snapshot.
1019     * 
1020     * @param minRepeatCount The maximum number of times to replay the snapshot (1, if not specified).
1021     * <BR /><B>OPTIONAL</B>
1022     * 
1023     * @param minDuration The minimum duration (in seconds) to replay the snapshot.
1024     * <BR /><B>OPTIONAL</B>
1025     * 
1026     * @param clipRect The clip rectangle to apply when replaying the snapshot.
1027     * <BR /><B>OPTIONAL</B>
1028     * 
1029     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1030     * Number[][]&gt;</CODE>
1031     * 
1032     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1033     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1034     * Number[][]&gt;</CODE> will be returned.
1035     *
1036     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1037     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1038      * may be retrieved.</I>
1039     *
1040     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1041     * <BR /><BR /><UL CLASS=JDUL>
1042     * <LI><CODE>Number[][] (<B>timings</B></CODE>)
1043     *     <BR />The array of paint profiles, one per run.
1044     * </LI>
1045     * </UL> */
1046    public static Script<String, JsonObject, Number[][]> profileSnapshot
1047        (String snapshotId, Integer minRepeatCount, Number minDuration, DOM.Rect clipRect)
1048    {
1049        // Exception-Check(s) to ensure that if any parameters which are not declared as
1050        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1051        
1052        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
1053        
1054        final int       webSocketID = 27005000 + counter++;
1055        final boolean[] optionals   = { false, true, true, true, };
1056        
1057        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1058        String requestJSON = WriteJSON.get(
1059            parameterTypes.get("profileSnapshot"),
1060            parameterNames.get("profileSnapshot"),
1061            optionals, webSocketID,
1062            "LayerTree.profileSnapshot",
1063            snapshotId, minRepeatCount, minDuration, clipRect
1064        );
1065        
1066        // 'JSON Binding' ... Converts Browser Response-JSON to 'Number[][]'
1067        Function<JsonObject, Number[][]> responseProcessor = (JsonObject jo) ->
1068            (jo.getJsonArray("timings") == null)
1069                ? null
1070                : ReadArrJSON.DimN.arrNumber(jo.getJsonArray("timings"), -1, 0, null, Number[][].class);
1071        
1072        // Pass the 'defaultSender' to Script-Constructor
1073        // The sender that is used can be changed before executing script.
1074        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1075    }
1076    
1077    /**
1078     * Releases layer snapshot captured by the back-end.
1079     * 
1080     * @param snapshotId The id of the layer snapshot.
1081     * 
1082     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1083     * {@link Ret0}&gt;</CODE>
1084     *
1085     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1086     * browser receives the invocation-request.
1087     *
1088     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1089     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1090     * {@code >} to ensure the Browser Function has run to completion.
1091     */
1092    public static Script<String, JsonObject, Ret0> releaseSnapshot(String snapshotId)
1093    {
1094        // Exception-Check(s) to ensure that if any parameters which are not declared as
1095        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1096        
1097        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
1098        
1099        final int       webSocketID = 27006000 + counter++;
1100        final boolean[] optionals   = { false, };
1101        
1102        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1103        String requestJSON = WriteJSON.get(
1104            parameterTypes.get("releaseSnapshot"),
1105            parameterNames.get("releaseSnapshot"),
1106            optionals, webSocketID,
1107            "LayerTree.releaseSnapshot",
1108            snapshotId
1109        );
1110        
1111        // This Remote Command does not have a Return-Value.
1112        return new Script<>
1113            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1114    }
1115    
1116    /**
1117     * Replays the layer snapshot and returns the resulting bitmap.
1118     * 
1119     * @param snapshotId The id of the layer snapshot.
1120     * 
1121     * @param fromStep The first step to replay from (replay from the very start if not specified).
1122     * <BR /><B>OPTIONAL</B>
1123     * 
1124     * @param toStep The last step to replay to (replay till the end if not specified).
1125     * <BR /><B>OPTIONAL</B>
1126     * 
1127     * @param scale The scale to apply while replaying (defaults to 1).
1128     * <BR /><B>OPTIONAL</B>
1129     * 
1130     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1131     * String&gt;</CODE>
1132     * 
1133     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1134     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1135     * String&gt;</CODE> will be returned.
1136     *
1137     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1138     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1139      * may be retrieved.</I>
1140     *
1141     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1142     * <BR /><BR /><UL CLASS=JDUL>
1143     * <LI><CODE>String (<B>dataURL</B></CODE>)
1144     *     <BR />A data: URL for resulting image.
1145     * </LI>
1146     * </UL> */
1147    public static Script<String, JsonObject, String> replaySnapshot
1148        (String snapshotId, Integer fromStep, Integer toStep, Number scale)
1149    {
1150        // Exception-Check(s) to ensure that if any parameters which are not declared as
1151        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1152        
1153        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
1154        
1155        final int       webSocketID = 27007000 + counter++;
1156        final boolean[] optionals   = { false, true, true, true, };
1157        
1158        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1159        String requestJSON = WriteJSON.get(
1160            parameterTypes.get("replaySnapshot"),
1161            parameterNames.get("replaySnapshot"),
1162            optionals, webSocketID,
1163            "LayerTree.replaySnapshot",
1164            snapshotId, fromStep, toStep, scale
1165        );
1166        
1167        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
1168        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
1169            ReadJSON.getString(jo, "dataURL", false, true);
1170        
1171        // Pass the 'defaultSender' to Script-Constructor
1172        // The sender that is used can be changed before executing script.
1173        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1174    }
1175    
1176    /**
1177     * Replays the layer snapshot and returns canvas log.
1178     * 
1179     * @param snapshotId The id of the layer snapshot.
1180     * 
1181     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1182     * JsonArray&gt;</CODE>
1183     * 
1184     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1185     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1186     * JsonArray&gt;</CODE> will be returned.
1187     *
1188     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1189     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1190      * may be retrieved.</I>
1191     *
1192     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1193     * <BR /><BR /><UL CLASS=JDUL>
1194     * <LI><CODE>JsonArray (<B>commandLog</B></CODE>)
1195     *     <BR />The array of canvas function calls.
1196     * </LI>
1197     * </UL> */
1198    public static Script<String, JsonObject, JsonArray> snapshotCommandLog(String snapshotId)
1199    {
1200        // Exception-Check(s) to ensure that if any parameters which are not declared as
1201        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1202        
1203        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
1204        
1205        final int       webSocketID = 27008000 + counter++;
1206        final boolean[] optionals   = { false, };
1207        
1208        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1209        String requestJSON = WriteJSON.get(
1210            parameterTypes.get("snapshotCommandLog"),
1211            parameterNames.get("snapshotCommandLog"),
1212            optionals, webSocketID,
1213            "LayerTree.snapshotCommandLog",
1214            snapshotId
1215        );
1216        
1217        // 'JSON Binding' ... Converts Browser Response-JSON to 'JsonArray'
1218        Function<JsonObject, JsonArray> responseProcessor = (JsonObject jo) ->
1219            jo.getJsonArray("commandLog");
1220        
1221        // Pass the 'defaultSender' to Script-Constructor
1222        // The sender that is used can be changed before executing script.
1223        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1224    }
1225    
1226}