<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl">
    <binding id="wheeltabs">
        <implementation>
            <field name="_eventListeners">[];</field>
            <field name="initialized">false;</field>
            <constructor><![CDATA[
                if (!window.gBrowser)
                    window.addEventListener("load", this, false);
                else
                    this.init();
            ]]></constructor>
            <destructor><![CDATA[
                if (!this.initialized)
                    return;
                this._eventListeners.forEach((args) => args[0].removeEventListener(args[1], args[2], args[3]));
                this.initialized = false;
            ]]></destructor>
            <method name="init">
                <body><![CDATA[
                    if (this.initialized || !("tabContainer" in gBrowser))
                        return;
                    this.initialized = true;
                    var tabContain = gBrowser.tabContainer;
                    this._addEventListener(tabContain, "wheel", function(event) {
                        if (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey)
                            return;
                        event.stopPropagation();
                        event.preventDefault();
                        this.advanceSelectedTab(event.deltaY < 0 ? 1 : -1, true);
                    }, true);
                ]]></body>
            </method>
            <method name="handleEvent">
                <parameter name="event"/>
                <body><![CDATA[
                    window.removeEventListener("load", this, false);
                    this.init();
                ]]></body>
            </method>
            <method name="_addEventListener">
                <body><![CDATA[
                    arguments[0].addEventListener(arguments[1], arguments[2], arguments[3]);
                    this._eventListeners.push(arguments);
                ]]></body>
            </method>
        </implementation>
    </binding>
</bindings>
