LCOV - code coverage report
Current view: top level - modules/core/overrides - Gtk.js (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 96.9 % 96 93
Test Date: 2024-04-20 17:42:51 Functions: 90.9 % 11 10
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 85.7 % 56 48

             Branch data     Line data    Source code
       1                 :          16 : // application/javascript;version=1.8
       2                 :             : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
       3                 :             : // SPDX-FileCopyrightText: 2013 Giovanni Campagna
       4                 :             : 
       5                 :           9 : const Legacy = imports._legacy;
       6                 :           9 : const {Gio, GjsPrivate, GLib, GObject} = imports.gi;
       7                 :           9 : const {_createBuilderConnectFunc, _createClosure, _registerType} = imports._common;
       8                 :           9 : const Gi = imports._gi;
       9                 :             : 
      10                 :           9 : let Gtk;
      11                 :           9 : let BuilderScope;
      12                 :             : 
      13                 :           9 : function _init() {
      14                 :           9 :     Gtk = this;
      15                 :             : 
      16                 :           9 :     Gtk.children = GObject.__gtkChildren__;
      17                 :           9 :     Gtk.cssName = GObject.__gtkCssName__;
      18                 :           9 :     Gtk.internalChildren = GObject.__gtkInternalChildren__;
      19                 :           9 :     Gtk.template = GObject.__gtkTemplate__;
      20                 :             : 
      21                 :           9 :     let {GtkWidgetClass} = Legacy.defineGtkLegacyObjects(GObject, Gtk);
      22                 :           9 :     Gtk.Widget.prototype.__metaclass__ = GtkWidgetClass;
      23                 :             : 
      24 [ +  + ][ +  + ]:           9 :     if (Gtk.Container && Gtk.Container.prototype.child_set_property) {
      25                 :           8 :         Gtk.Container.prototype.child_set_property = function (child, property, value) {
      26                 :           1 :             GjsPrivate.gtk_container_child_set_property(this, child, property, value);
      27                 :             :         };
      28                 :             :     }
      29                 :             : 
      30         [ +  + ]:           9 :     if (Gtk.CustomSorter) {
      31                 :           1 :         Gtk.CustomSorter.new = GjsPrivate.gtk_custom_sorter_new;
      32                 :           1 :         Gtk.CustomSorter.prototype.set_sort_func = function (sortFunc) {
      33                 :           2 :             GjsPrivate.gtk_custom_sorter_set_sort_func(this, sortFunc);
      34                 :             :         };
      35                 :             :     }
      36                 :             : 
      37                 :         140 :     Gtk.Widget.prototype._init = function (params) {
      38                 :         131 :         const klass = this.constructor;
      39         [ +  - ]:         131 :         const wrapper = GObject.Object.prototype._init.call(this, params) ?? this;
      40                 :             : 
      41         [ +  + ]:         131 :         if (klass[Gtk.template]) {
      42         [ +  + ]:          45 :             let children = klass[Gtk.children] ?? [];
      43         [ +  + ]:         129 :             for (let child of children) {
      44                 :          84 :                 wrapper[child.replace(/-/g, '_')] =
      45                 :          84 :                     wrapper.get_template_child(klass, child);
      46                 :             :             }
      47                 :             : 
      48         [ +  + ]:          45 :             let internalChildren = klass[Gtk.internalChildren] ?? [];
      49         [ +  + ]:          87 :             for (let child of internalChildren) {
      50                 :          42 :                 wrapper[`_${child.replace(/-/g, '_')}`] =
      51                 :          42 :                     wrapper.get_template_child(klass, child);
      52                 :             :             }
      53                 :             :         }
      54                 :             : 
      55                 :         131 :         return wrapper;
      56                 :         131 :     };
      57                 :             : 
      58                 :           9 :     Gtk.Widget._classInit = function (klass) {
      59                 :          16 :         return GObject.Object._classInit(klass);
      60                 :             :     };
      61                 :             : 
      62                 :          18 :     Object.defineProperty(Gtk.Widget, _registerType, {
      63                 :           9 :         value: _registerWidgetType,
      64                 :           9 :         writable: false,
      65                 :           9 :         configurable: false,
      66                 :           9 :         enumerable: false,
      67                 :             :     });
      68                 :             : 
      69         [ +  + ]:           9 :     if (Gtk.Widget.prototype.get_first_child) {
      70                 :           1 :         Gtk.Widget.prototype[Symbol.iterator] = function* () {
      71         [ #  # ]:           0 :             for (let c = this.get_first_child(); c; c = c.get_next_sibling())
      72                 :           0 :                 yield c;
      73                 :           0 :         };
      74                 :             :     }
      75                 :             : 
      76         [ +  + ]:           9 :     if (Gtk.BuilderScope) {
      77                 :           2 :         BuilderScope = GObject.registerClass({
      78                 :           1 :             Implements: [Gtk.BuilderScope],
      79         [ -  + ]:           8 :         }, class extends GObject.Object {
      80                 :          44 :             vfunc_create_closure(builder, handlerName, flags, connectObject) {
      81                 :          43 :                 const swapped = flags & Gtk.BuilderClosureFlags.SWAPPED;
      82                 :          43 :                 const thisArg = builder.get_current_object();
      83                 :          85 :                 return Gi.associateClosure(
      84         [ +  + ]:          43 :                     connectObject ?? thisArg,
      85                 :          43 :                     _createClosure(builder, thisArg, handlerName, swapped, connectObject)
      86                 :             :                 );
      87                 :          42 :             }
      88                 :             :         });
      89                 :             :     }
      90                 :             : }
      91                 :             : 
      92                 :          16 : function _registerWidgetType(klass) {
      93                 :          16 :     const template = klass[Gtk.template];
      94                 :          16 :     const cssName = klass[Gtk.cssName];
      95                 :          16 :     const children = klass[Gtk.children];
      96                 :          16 :     const internalChildren = klass[Gtk.internalChildren];
      97                 :             : 
      98         [ +  + ]:          16 :     if (template) {
      99                 :          13 :         klass.prototype._instance_init = function () {
     100                 :          38 :             this.init_template();
     101                 :             :         };
     102                 :             :     }
     103                 :             : 
     104                 :          16 :     GObject.Object[_registerType](klass);
     105                 :             : 
     106         [ +  + ]:          16 :     if (cssName)
     107                 :           4 :         Gtk.Widget.set_css_name.call(klass, cssName);
     108                 :             : 
     109         [ +  + ]:          16 :     if (template) {
     110         [ +  + ]:          13 :         if (typeof template === 'string') {
     111                 :           7 :             try {
     112                 :           7 :                 const uri = GLib.Uri.parse(template, GLib.UriFlags.NONE);
     113                 :           5 :                 const scheme = uri.get_scheme();
     114                 :             : 
     115         [ +  + ]:           5 :                 if (scheme === 'resource') {
     116                 :           2 :                     Gtk.Widget.set_template_from_resource.call(klass, uri.get_path());
     117         [ +  + ]:           3 :                 } else if (scheme === 'file') {
     118                 :           2 :                     const file = Gio.File.new_for_uri(template);
     119 [ +  - ][ +  - ]:           2 :                     const [, contents] = file.load_contents(null);
         [ +  - ][ +  - ]
     120                 :           2 :                     Gtk.Widget.set_template.call(klass, contents);
     121                 :             :                 } else {
     122                 :           1 :                     throw new TypeError(`Invalid template URI: ${template}`);
     123                 :             :                 }
     124                 :           3 :             } catch (err) {
     125         [ +  + ]:           3 :                 if (!(err instanceof GLib.UriError))
     126                 :           1 :                     throw err;
     127                 :             : 
     128                 :           2 :                 const contents = new TextEncoder().encode(template);
     129                 :           2 :                 Gtk.Widget.set_template.call(klass, contents);
     130                 :             :             }
     131                 :             :         } else {
     132                 :           6 :             Gtk.Widget.set_template.call(klass, template);
     133                 :             :         }
     134                 :             : 
     135         [ +  + ]:          12 :         if (BuilderScope)
     136                 :           7 :             Gtk.Widget.set_template_scope.call(klass, new BuilderScope());
     137                 :             :         else
     138                 :           5 :             Gtk.Widget.set_connect_func.call(klass, _createBuilderConnectFunc(klass));
     139                 :             :     }
     140                 :             : 
     141         [ +  + ]:          15 :     if (children) {
     142                 :          10 :         children.forEach(child =>
     143                 :          20 :             Gtk.Widget.bind_template_child_full.call(klass, child, false, 0));
     144                 :             :     }
     145                 :             : 
     146         [ +  + ]:          15 :     if (internalChildren) {
     147                 :          10 :         internalChildren.forEach(child =>
     148                 :          10 :             Gtk.Widget.bind_template_child_full.call(klass, child, true, 0));
     149                 :             :     }
     150                 :             : }
        

Generated by: LCOV version 2.0-1