/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { Base, runOn, delegateCombine, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs, enumGetBox, Point_$type, Boolean_$type } from "./type";
import { IScrollerView_$type } from "./IScrollerView";
import { CanvasGestureDOMEventProxy } from "./CanvasGestureDOMEventProxy";
import { Brush } from "./Brush";
import { DOMExecutionContext } from "./DOMExecutionContext";
import { DoubleAnimator } from "./DoubleAnimator";
import { Rect } from "./Rect";
import { ScrollbarStyle_$type } from "./ScrollbarStyle";
import { truncate, isNaN_ } from "./number";
import { List$1 } from "./List$1";
import { EasingFunctions } from "./EasingFunctions";
import { ScrollerScrollingEventArgs } from "./ScrollerScrollingEventArgs";
/**
 * @hidden
 */
var ScrollerView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ScrollerView, _super);
    function ScrollerView(a) {
        var _this = _super.call(this) || this;
        _this.c = null;
        _this.ab = null;
        _this.af = null;
        _this.b = null;
        _this.aa = null;
        _this.a = null;
        _this.ae = null;
        _this.ac = null;
        _this.ad = null;
        _this.ag = null;
        _this.e = false;
        _this.d = null;
        _this.i = false;
        _this.h = false;
        _this.w = 0;
        _this.t = 0;
        _this.x = -1;
        _this.u = -1;
        _this.g = false;
        _this.f = false;
        _this.v = 0;
        _this.s = 0;
        _this.c = a;
        return _this;
    }
    ScrollerView.prototype.getDefaultScrollbarBrush = function () {
        return ((function () {
            var $ret = new Brush();
            $ret.fill = "#666666";
            return $ret;
        })());
    };
    ScrollerView.prototype.provideContainer = function (a) {
        var _this = this;
        if (a == null) {
            if (this.ab != null) {
                this.ab = null;
            }
            if (this.a != null) {
                this.a.an = null;
                this.a.au();
            }
            return;
        }
        this.ab = a;
        this.c.executionContext = new DOMExecutionContext(this.ab);
        var b = Math.round(this.ab.rootWrapper.width());
        var c = Math.round(this.ab.rootWrapper.height());
        this.ae = this.ab.rootWrapper;
        this.ae.setStyleProperty("position", "relative");
        this.af = this.ab.createElement("div");
        this.af.setStyleProperty("position", "relative");
        this.af.setStyleProperty("width", "100%");
        this.af.setStyleProperty("height", "100%");
        this.af.setStyleProperty("overflow", "hidden");
        this.ae.append(this.af);
        this.ad = this.ab.createElement("div");
        this.ad.setStyleProperty("position", "absolute");
        this.ad.setStyleProperty("height", this.c.scrollbarSpan + "px");
        this.ad.setStyleProperty("width", this.c.minScrollbarSize + "px");
        this.ad.setStyleProperty("background-color", this.c.scrollbarBrush._fill);
        this.ad.setStyleProperty("display", "none");
        this.ad.setStyleProperty("border-radius", "5px");
        this.ad.setStyleProperty("z-index", "10000");
        this.ad.setStyleProperty("bottom", "0px");
        this.ae.append(this.ad);
        this.ag = this.ab.createElement("div");
        this.ag.setStyleProperty("position", "absolute");
        this.ag.setStyleProperty("width", this.c.scrollbarSpan + "px");
        this.ag.setStyleProperty("height", this.c.minScrollbarSize + "px");
        this.ag.setStyleProperty("background-color", this.c.scrollbarBrush._fill);
        this.ag.setStyleProperty("display", "none");
        this.ag.setStyleProperty("border-radius", "5px");
        this.ag.setStyleProperty("z-index", "10000");
        this.ag.setStyleProperty("right", "0px");
        this.ae.append(this.ag);
        this.updateScrollbarStatus(false);
        this.aa = this.af.getNativeElement();
        this.a = new CanvasGestureDOMEventProxy(this.ab.rootWrapper, this.ab, true);
        this.ab.rootWrapper.setProperty("tabIndex", 1000);
        this.ab.rootWrapper.setRawStyleProperty("outline", "none");
        this.a.c7 = true;
        this.a.bu = true;
        var d = this.a;
        d.onMouseWheel = delegateCombine(d.onMouseWheel, runOn(this, this.l));
        var e = this.a;
        e.onMouseWheelHorizontal = delegateCombine(e.onMouseWheelHorizontal, runOn(this, this.m));
        var f = this.a;
        f.onMouseLeave = delegateCombine(f.onMouseLeave, runOn(this, this.an));
        var g = this.a;
        g.onDragStarted = delegateCombine(g.onDragStarted, runOn(this, this.am));
        var h = this.a;
        h.onDragDelta = delegateCombine(h.onDragDelta, runOn(this, this.al));
        var i = this.a;
        i.onDragCompleted = delegateCombine(i.onDragCompleted, runOn(this, this.ak));
        var j = this.a;
        j.onFlingStarted = delegateCombine(j.onFlingStarted, runOn(this, this.j));
        var k = this.a;
        k.onContactStarted = delegateCombine(k.onContactStarted, runOn(this, this.aj));
        var l = this.a;
        l.onContactMoved = delegateCombine(l.onContactMoved, runOn(this, this.ai));
        var m = this.a;
        m.onContactCompleted = delegateCombine(m.onContactCompleted, runOn(this, this.ah));
        this.a.ab = true;
        this.a.ap = runOn(this, this.r);
        var n = this.a;
        n.onKeyDown = delegateCombine(n.onKeyDown, runOn(this, this.k));
        this.a.aq = function (o) {
            var e_ = o.originalEvent;
            var p = (e_.type);
            if (p == "pointerdown" && !_this.a.bq(o)) {
                return false;
            }
            return true;
        };
        this.c.di(b, c);
        this.c.horizontalAnimation.u(this.ab);
        this.c.verticalAnimation.u(this.ab);
        this.attachNativeScroll();
    };
    ScrollerView.prototype.k = function (a) {
        return this.c.ao(a, (this.a.bh & 4) != 0, (this.a.bh & 2) != 0);
    };
    ScrollerView.prototype.r = function (a, b, c) {
        if (this.f || this.g) {
            return true;
        }
        if (c || b) {
            return true;
        }
        if (this.n(a, b)) {
            this.c.c3();
            return true;
        }
        else if (this.c.isHorizontalActive) {
            this.c.c7();
        }
        if (this.o(a, b)) {
            this.c.c4();
            return true;
        }
        else if (this.c.isVerticalActive) {
            this.c.c8();
        }
        return false;
    };
    ScrollerView.prototype.ah = function (a, b) {
        this.f = false;
        this.g = false;
        this.c.isDraggingVBar = false;
        this.c.isDraggingHBar = false;
    };
    ScrollerView.prototype.ai = function (a, b) {
        if (this.g) {
            var c = a.y - this.v;
            this.v = a.y;
            this.c.dh(c);
        }
        else if (this.f) {
            var d = a.x - this.s;
            this.s = a.x;
            this.c.df(d);
        }
    };
    ScrollerView.prototype.aj = function (a, b) {
        this.e = false;
        this.cancelInertia();
        var c = this.q(a, b);
        var d = this.p(a, b);
        if (c) {
            this.c.isDraggingVBar = true;
            this.g = true;
            this.v = a.y;
            this.focus();
        }
        else if (d) {
            this.c.isDraggingHBar = true;
            this.f = true;
            this.s = a.x;
            this.focus();
        }
    };
    ScrollerView.prototype.p = function (a, b) {
        if (!this.h) {
            return false;
        }
        if (a.y >= this.c.viewportHeight - this.c.scrollbarSpan && a.y <= this.c.viewportHeight && a.x >= this.u - this.t / 2 && a.x <= this.u + this.t / 2) {
            return true;
        }
        return false;
    };
    ScrollerView.prototype.q = function (a, b) {
        if (!this.i) {
            return false;
        }
        if (a.x >= this.c.viewportWidth - this.c.scrollbarSpan && a.x <= this.c.viewportWidth && a.y >= this.x - this.w / 2 && a.y <= this.x + this.w / 2) {
            return true;
        }
        return false;
    };
    ScrollerView.prototype.n = function (a, b) {
        if (!this.h) {
            return false;
        }
        return a.y >= this.c.viewportHeight - this.c.scrollbarSpan - 40 && a.y <= this.c.viewportHeight;
    };
    ScrollerView.prototype.o = function (a, b) {
        if (!this.i) {
            return false;
        }
        return a.x >= this.c.viewportWidth - this.c.scrollbarSpan - 40 && a.x <= this.c.viewportWidth;
    };
    ScrollerView.prototype.j = function (a, b, c) {
        this.e = true;
        return true;
    };
    ScrollerView.prototype.onViewportHeightChanged = function (a) {
        this.a.bk = new Rect(0, 0, 0, this.c.viewportWidth, this.c.viewportHeight);
    };
    ScrollerView.prototype.onViewportWidthChanged = function (a) {
        this.a.bk = new Rect(0, 0, 0, this.c.viewportWidth, this.c.viewportHeight);
    };
    ScrollerView.prototype.onContentHeightChanged = function (a) {
        if (this.ac != null) {
            this.ac.setStyleProperty("height", a + "px");
        }
    };
    ScrollerView.prototype.onContentWidthChanged = function (a) {
        if (this.ac != null) {
            this.ac.setStyleProperty("width", a + "px");
        }
    };
    ScrollerView.prototype.cancelInertia = function () {
    };
    ScrollerView.prototype.ak = function (a) {
        if (this.f || this.g) {
            return;
        }
        this.e = false;
        this.c.dc(a);
    };
    ScrollerView.prototype.al = function (a) {
        if (this.f || this.g) {
            return;
        }
        this.c.dd(a);
    };
    ScrollerView.prototype.updateScrollTop = function (a) {
        this.aa.scrollTop = truncate(a);
    };
    ScrollerView.prototype.am = function (a) {
        if (this.f || this.g) {
            return;
        }
        this.e = false;
        this.c.de(a);
    };
    ScrollerView.prototype.getInitialScrollLeft = function () {
        return this.aa.scrollLeft;
    };
    ScrollerView.prototype.getInitialScrollTop = function () {
        return this.aa.scrollTop;
    };
    ScrollerView.prototype.l = function (a, b) {
        this.e = false;
        this.cancelInertia();
        return this.c.aq(a, 0, b);
    };
    ScrollerView.prototype.m = function (a, b) {
        this.e = false;
        this.cancelInertia();
        return this.c.aq(a, b, 0);
    };
    ScrollerView.prototype.an = function (a) {
        if (this.c.horizontalScrollbarStatus > 0) {
            this.c.c7();
        }
        if (this.c.verticalScrollbarStatus > 0) {
            this.c.c8();
        }
    };
    ScrollerView.prototype.updateScrollLeft = function (a) {
        this.aa.scrollLeft = truncate(a);
    };
    ScrollerView.prototype.provideContent = function (a) {
        this.ac = a;
        this.af.append(this.ac);
    };
    ScrollerView.prototype.requestWork = function (a) {
        if (this.ab == null) {
            return;
        }
        if (this.d == null) {
            this.d = this.ab.getRequestAnimationFrame();
        }
        if (this.e) {
            a();
        }
        else {
            this.d(function () { return a(); });
        }
    };
    ScrollerView.prototype.hideVScrollbar = function () {
        if (this.i) {
            this.i = false;
            this.ag.setStyleProperty("display", "none");
        }
    };
    ScrollerView.prototype.hideHScrollbar = function () {
        if (this.h) {
            this.h = false;
            this.ad.setStyleProperty("display", "none");
        }
    };
    ScrollerView.prototype.updateVScrollbar = function (a, b) {
        var c = false;
        if (!this.i) {
            c = true;
            this.i = true;
            this.ag.setStyleProperty("display", "block");
        }
        if (a != this.x || c) {
            this.x = a;
            if (this.i) {
                this.ag.setRawYPosition(a - b / 2);
            }
        }
        if (b != this.w || c) {
            this.w = b;
            if (this.i) {
                this.ag.setRawSize(this.z(), b);
            }
        }
    };
    ScrollerView.prototype.updateHScrollbar = function (a, b) {
        var c = false;
        if (!this.h) {
            c = true;
            this.h = true;
            this.ad.setStyleProperty("display", "block");
        }
        if (a != this.u || c) {
            this.u = a;
            if (this.h) {
                this.ad.setRawXPosition(a - b / 2);
            }
        }
        if (b != this.t || c) {
            this.t = b;
            if (this.h) {
                this.ad.setRawSize(b, this.y());
            }
        }
    };
    ScrollerView.prototype.updateScrollbarStatus = function (a) {
        if (this.ad != null && this.ag != null) {
            switch (this.c.scrollbarStyle) {
                case 0:
                    if (a) {
                        this.ad.setStyleProperty("opacity", "1");
                        this.ag.setStyleProperty("opacity", "1");
                        this.ad.setRawSize(this.t, this.y());
                        this.ag.setRawSize(this.z(), this.w);
                    }
                    break;
                case 1:
                    if (a) {
                        this.ad.setRawSize(this.t, this.y());
                        this.ag.setRawSize(this.z(), this.w);
                    }
                    this.ad.setStyleProperty("opacity", this.c.horizontalScrollbarStatus.toString());
                    this.ag.setStyleProperty("opacity", this.c.verticalScrollbarStatus.toString());
                    break;
                case 2:
                    if (a) {
                        this.ad.setStyleProperty("opacity", "1");
                        this.ag.setStyleProperty("opacity", "1");
                    }
                    this.ad.setRawSize(this.t, this.y());
                    this.ag.setRawSize(this.z(), this.w);
                    break;
            }
        }
    };
    ScrollerView.prototype.y = function () {
        if (this.c.scrollbarStyle == 2) {
            return this.c.horizontalScrollbarStatus * (this.c.scrollbarSpan - 2) + 2;
        }
        return this.c.scrollbarSpan;
    };
    ScrollerView.prototype.z = function () {
        if (this.c.scrollbarStyle == 2) {
            return this.c.verticalScrollbarStatus * (this.c.scrollbarSpan - 2) + 2;
        }
        return this.c.scrollbarSpan;
    };
    ScrollerView.prototype.focus = function () {
        this.ab.rootWrapper.focus(true);
    };
    ScrollerView.prototype.onDetachedFromUI = function () {
        if (this.a != null) {
            this.a.bg(this.ab.rootWrapper, "");
        }
    };
    ScrollerView.prototype.onAttachedToUI = function () {
        if (this.a != null) {
            this.a.as(this.ab.rootWrapper, "");
        }
    };
    ScrollerView.prototype.attachNativeScroll = function () {
        var a = this.af.getNativeElement();
        a.addEventListener("scroll", runOn(this, this.onNativeScroll));
    };
    ScrollerView.prototype.detachNativeScroll = function () {
        var a = this.af.getNativeElement();
        a.removeEventListener("scroll", runOn(this, this.onNativeScroll));
    };
    ScrollerView.prototype.onNativeScroll = function (a) {
    };
    ScrollerView.$t = markType(ScrollerView, 'ScrollerView', Base.$, [IScrollerView_$type]);
    return ScrollerView;
}(Base));
export { ScrollerView };
/**
 * @hidden
 */
var Scroller = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Scroller, _super);
    function Scroller() {
        var _this = _super.call(this) || this;
        _this.bh = 49;
        _this._keyboardListener = null;
        _this.a9 = NaN;
        _this.a3 = 49;
        _this.a1 = NaN;
        _this.bg = 48;
        _this.a8 = NaN;
        _this.a2 = 48;
        _this.a0 = NaN;
        _this.a6 = 0;
        _this.ba = 20;
        _this.bd = 8;
        _this.bj = 0;
        _this.dx = null;
        _this.x = false;
        _this.a5 = 0;
        _this.bl = 0;
        _this.bk = 0;
        _this.bf = 0;
        _this.be = 0;
        _this.c = null;
        _this.v = true;
        _this.aa = false;
        _this.a4 = 0;
        _this.az = 0;
        _this.e = 0;
        _this.a7 = 0;
        _this.bi = 0;
        _this.j = null;
        _this.k = null;
        _this.bu = 0;
        _this.b5 = 0;
        _this.bv = 0;
        _this.b6 = 0;
        _this._executionContext = null;
        _this._isDraggingVBar = false;
        _this._isDraggingHBar = false;
        _this.s = false;
        _this.q = false;
        _this.r = false;
        _this.dz = null;
        _this.p = false;
        _this.propertyChanged = null;
        _this.onScrolling = null;
        _this.onScrollStart = null;
        _this.onScrollStop = null;
        _this._isScrolling = false;
        _this.bb = 0;
        _this.bc = 0;
        _this.w = false;
        _this.ay = new List$1(Boolean_$type, 0);
        _this.cb = 500;
        _this.cc = 0;
        _this.cd = 0;
        _this.o = false;
        _this.z = false;
        _this.n = false;
        _this.y = false;
        _this.t = true;
        _this.u = true;
        _this.dx = _this.view.getDefaultScrollbarBrush();
        _this.j = new DoubleAnimator(0, 1, 400);
        _this.k = new DoubleAnimator(0, 1, 400);
        _this.j.b = EasingFunctions.cubicEase;
        _this.k.b = EasingFunctions.cubicEase;
        var a = _this.j;
        a.propertyChanged = delegateCombine(a.propertyChanged, runOn(_this, _this.c1));
        var b = _this.k;
        b.propertyChanged = delegateCombine(b.propertyChanged, runOn(_this, _this.c2));
        return _this;
    }
    Object.defineProperty(Scroller.prototype, "smallVerticalChange", {
        get: function () {
            return this.bh;
        },
        set: function (a) {
            var b = this.bh;
            this.bh = a;
            if (b != this.bh) {
                this.dg("SmallVerticalChange", b, this.bh);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "keyboardListener", {
        get: function () {
            return this._keyboardListener;
        },
        set: function (a) {
            this._keyboardListener = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "largeVerticalChange", {
        get: function () {
            return this.a9;
        },
        set: function (a) {
            var b = this.a9;
            this.a9 = a;
            if (b != this.a9) {
                this.dg("LargeVerticalChange", b, this.a9);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "bq", {
        get: function () {
            return this.a3;
        },
        set: function (a) {
            var b = this.a3;
            this.a3 = a;
            if (b != this.a3) {
                this.dg("ActualSmallVerticalChange", b, this.a3);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "bo", {
        get: function () {
            return this.a1;
        },
        set: function (a) {
            var b = this.a1;
            this.a1 = a;
            if (b != this.a1) {
                this.dg("ActualLargeVerticalChange", b, this.a1);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "smallHorizontalChange", {
        get: function () {
            return this.bg;
        },
        set: function (a) {
            var b = this.bg;
            this.bg = a;
            if (b != this.bg) {
                this.dg("SmallHorizontalChange", b, this.bg);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "largeHorizontalChange", {
        get: function () {
            return this.a8;
        },
        set: function (a) {
            var b = this.a8;
            this.a8 = a;
            if (b != this.a8) {
                this.dg("LargeHorizontalChange", b, this.a8);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "bp", {
        get: function () {
            return this.a2;
        },
        set: function (a) {
            var b = this.a2;
            this.a2 = a;
            if (b != this.a2) {
                this.dg("ActualSmallHorizontalChange", b, this.a2);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "bn", {
        get: function () {
            return this.a0;
        },
        set: function (a) {
            var b = this.a0;
            this.a0 = a;
            if (b != this.a0) {
                this.dg("ActualLargeHorizontalChange", b, this.a0);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "contentWidth", {
        get: function () {
            return this.a6;
        },
        set: function (a) {
            var b = this.a6;
            this.a6 = a;
            if (b != this.a6) {
                this.dg("ContentWidth", b, this.a6);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "minScrollbarSize", {
        get: function () {
            return this.ba;
        },
        set: function (a) {
            var b = this.ba;
            this.ba = a;
            if (b != this.ba) {
                this.dg("MinScrollbarSize", b, this.ba);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollbarSpan", {
        get: function () {
            return this.bd;
        },
        set: function (a) {
            var b = this.bd;
            this.bd = a;
            if (b != this.bd) {
                this.dg("ScrollbarSpan", b, this.bd);
            }
        },
        enumerable: false,
        configurable: true
    });
    Scroller.prototype.ao = function (a, b, c) {
        switch (a) {
            case 11: return this.ar(b, c);
            case 10: return this.as(b, c);
            case 17: return this.ah(b, c);
            case 15: return this.aw(b, c);
            case 14: return this.ap(b, c);
            case 16: return this.at(b, c);
            case 13: return this.am(b, c);
            case 12: return this.ai(b, c);
            case 2: return this.av(b, c);
            case 3: return this.aj(b, c);
            case 8: return this.ak();
            case 57: return this.al();
            case 9: return this.au(b, c);
            default: return this.an(a, b, c);
        }
        return false;
    };
    Scroller.prototype.au = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onSpace(a, b)) {
                return true;
            }
        }
        return false;
    };
    Scroller.prototype.al = function () {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onF2()) {
                return true;
            }
        }
        return false;
    };
    Scroller.prototype.ak = function () {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onEscape()) {
                return true;
            }
        }
        return false;
    };
    Scroller.prototype.av = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onTab(a, b)) {
                return true;
            }
        }
        return false;
    };
    Scroller.prototype.ai = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onEnd(a, b)) {
                return true;
            }
        }
        return false;
    };
    Scroller.prototype.am = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onHome(a, b)) {
                return true;
            }
        }
        return false;
    };
    Scroller.prototype.at = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onRightArrow(a, b)) {
                return true;
            }
        }
        if (this.scrollLeft + this.viewportWidth >= this.contentWidth) {
            return false;
        }
        this.dn(this.bp, 0);
        return true;
    };
    Scroller.prototype.ap = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onLeftArrow(a, b)) {
                return true;
            }
        }
        if (this.scrollLeft <= 0) {
            return false;
        }
        this.dn(this.bp * -1, 0);
        return true;
    };
    Scroller.prototype.aw = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onUpArrow(a, b)) {
                return true;
            }
        }
        if (this.scrollTop <= 0) {
            return false;
        }
        this.dn(0, this.bq * -1);
        return true;
    };
    Scroller.prototype.ah = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onDownArrow(a, b)) {
                return true;
            }
        }
        if (this.scrollTop + this.viewportHeight >= this.contentHeight) {
            return false;
        }
        this.dn(0, this.bq);
        return true;
    };
    Scroller.prototype.as = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onPageUp(a, b)) {
                return true;
            }
        }
        if (this.scrollTop < 0) {
            return false;
        }
        this.dn(0, this.bo * -1);
        return true;
    };
    Scroller.prototype.ar = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onPageDown(a, b)) {
                return true;
            }
        }
        if (this.scrollTop + this.viewportHeight >= this.contentHeight) {
            return false;
        }
        this.dn(0, this.bo);
        return true;
    };
    Scroller.prototype.aj = function (a, b) {
        if (this.keyboardListener != null) {
            if (this.keyboardListener.onEnter(a, b)) {
                return true;
            }
        }
        return false;
    };
    Scroller.prototype.an = function (a, b, c) {
        if (this.keyboardListener != null) {
            return this.keyboardListener.onKeyDown(a, b, c);
        }
        return false;
    };
    Object.defineProperty(Scroller.prototype, "verticalTrackStartInset", {
        get: function () {
            return this.bj;
        },
        set: function (a) {
            var b = this.bj;
            this.bj = a;
            if (b != this.bj) {
                this.dg("VerticalTrackStartInset", b, this.bj);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollbarBrush", {
        get: function () {
            return this.dx;
        },
        set: function (a) {
            var b = this.dx;
            this.dx = a;
            if (b != this.dx) {
                this.dg("ScrollbarBrush", b, this.dx);
            }
        },
        enumerable: false,
        configurable: true
    });
    Scroller.prototype.dg = function (a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        this.dj(a, b, c);
    };
    Object.defineProperty(Scroller.prototype, "ax", {
        get: function () {
            return this.x;
        },
        set: function (a) {
            this.x = a;
            if (!this.x) {
                this.view.updateScrollTop(this.scrollTop);
                this.view.updateScrollLeft(this.scrollLeft);
            }
        },
        enumerable: false,
        configurable: true
    });
    Scroller.prototype.dj = function (a, b, c) {
        switch (a) {
            case "ContentWidth":
                this.view.onContentWidthChanged(this.contentWidth);
                var d = c;
                var e = b;
                if (d < e && this.scrollLeft + this.viewportWidth >= d) {
                    this.dp(d - (this.scrollLeft + this.viewportWidth), 0);
                }
                this.du();
                break;
            case "ContentHeight":
                this.view.onContentHeightChanged(this.contentHeight);
                var f = c;
                var g = b;
                if (f < g && this.scrollTop > 0 && this.scrollTop + this.viewportHeight >= f) {
                    this.dp(0, f - (this.scrollTop + this.viewportHeight));
                }
                this.dw();
                break;
            case "ScrollTop":
                if (!this.ax) {
                    this.view.updateScrollTop(this.scrollTop);
                }
                break;
            case "ScrollLeft":
                if (!this.ax) {
                    this.view.updateScrollLeft(this.scrollLeft);
                }
                break;
            case "ViewportWidth":
                this.view.onViewportWidthChanged(this.viewportWidth);
                if (isNaN_(this.largeVerticalChange)) {
                    this.bn = this.viewportWidth;
                }
                if (this.contentWidth > 0 && this.scrollLeft + this.viewportWidth > this.contentWidth) {
                    this.dp(this.contentWidth - this.viewportWidth - this.scrollLeft, 0);
                }
                this.du();
                if (this.view.getInitialScrollLeft() != this.scrollLeft) {
                    this.view.updateScrollLeft(this.scrollLeft);
                }
                break;
            case "ViewportHeight":
                this.view.onViewportHeightChanged(this.viewportHeight);
                if (isNaN_(this.largeVerticalChange)) {
                    this.bo = this.viewportHeight;
                }
                this.dw();
                if (this.view.getInitialScrollTop() != this.scrollTop) {
                    this.view.updateScrollTop(this.scrollTop);
                }
                break;
            case "ScrollbarBrush":
            case "ScrollbarSpan":
            case "MinScrollbarSize":
            case "VerticalTrackStartInset":
                this.dw();
                this.du();
                break;
            case "HorizontalScrollbarStatus":
            case "VerticalOpacity":
                this.view.updateScrollbarStatus(false);
                break;
            case "ScrollbarStyle":
                this.view.updateScrollbarStatus(true);
                break;
        }
    };
    Object.defineProperty(Scroller.prototype, "contentHeight", {
        get: function () {
            return this.a5;
        },
        set: function (a) {
            var b = this.a5;
            this.a5 = a;
            if (b != this.a5) {
                this.dg("ContentHeight", b, this.a5);
            }
        },
        enumerable: false,
        configurable: true
    });
    Scroller.prototype.dh = function (a) {
        var b = Math.max(this.minScrollbarSize, this.actualVerticalScrollbarHeight);
        var c = this.verticalTrackStartInset + (b / 2);
        var d = this.viewportHeight - (b / 2);
        var e = a / (d - c);
        var f = e * (this.contentHeight - this.viewportHeight);
        this.dn(0, f);
    };
    Scroller.prototype.df = function (a) {
        var b = Math.max(this.minScrollbarSize, this.actualHorizontalScrollbarWidth);
        var c = 0 + (b / 2);
        var d = this.viewportWidth - (b / 2);
        var e = a / (d - c);
        var f = e * (this.contentWidth - this.viewportWidth);
        this.dn(f, 0);
    };
    Scroller.prototype.di = function (a, b, c) {
        if (c === void 0) {
            c = false;
        }
        var d = this.bl;
        var e = this.bk;
        this.bl = a;
        this.bk = b;
        if (c && (d != a || e != b)) {
            this.dg("ViewportWidth", d, a);
            this.dg("ViewportHeight", e, b);
        }
    };
    Object.defineProperty(Scroller.prototype, "viewportWidth", {
        get: function () {
            return this.bl;
        },
        set: function (a) {
            var b = this.bl;
            this.bl = a;
            if (b != this.bl) {
                this.dg("ViewportWidth", b, this.bl);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "viewportHeight", {
        get: function () {
            return this.bk;
        },
        set: function (a) {
            var b = this.bk;
            this.bk = a;
            if (b != this.bk) {
                this.dg("ViewportHeight", b, this.bk);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollTop", {
        get: function () {
            return this.bf;
        },
        set: function (a) {
            var b = this.bf;
            this.bf = a;
            if (b != this.bf) {
                this.dg("ScrollTop", b, this.bf);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollLeft", {
        get: function () {
            return this.be;
        },
        set: function (a) {
            var b = this.be;
            this.be = a;
            if (b != this.be) {
                this.dg("ScrollLeft", b, this.be);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "view", {
        get: function () {
            if (this.c == null) {
                this.c = new ScrollerView(this);
            }
            return this.c;
        },
        set: function (a) {
            this.c = a;
        },
        enumerable: false,
        configurable: true
    });
    Scroller.prototype.provideContainer = function (a) {
        this.view.provideContainer(a);
        this.bf = this.view.getInitialScrollTop();
        this.be = this.view.getInitialScrollLeft();
        this.du();
        this.dw();
    };
    Scroller.prototype.onDetachedFromUI = function () {
        this.view.onDetachedFromUI();
    };
    Scroller.prototype.onAttachedToUI = function () {
        this.view.onAttachedToUI();
    };
    Scroller.prototype.provideContent = function (a) {
        this.view.provideContent(a);
    };
    Scroller.prototype.aq = function (a, b, c) {
        this.r = false;
        this.q = false;
        this.s = false;
        this.view.cancelInertia();
        if (this.keyboardListener != null) {
            this.keyboardListener.onWheel();
        }
        this.dn(b, c);
        return true;
    };
    Object.defineProperty(Scroller.prototype, "lockScrollDirection", {
        get: function () {
            return this.v;
        },
        set: function (a) {
            this.v = true;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "actualVerticalScrollbarHeight", {
        get: function () {
            return this.a4;
        },
        set: function (a) {
            var b = this.a4;
            this.a4 = a;
            if (b != this.a4) {
                this.dg("ActualVerticalScrollbarHeight", b, this.a4);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "actualHorizontalScrollbarWidth", {
        get: function () {
            return this.az;
        },
        set: function (a) {
            var b = this.az;
            this.az = a;
            if (b != this.az) {
                this.dg("ActualHorizontalScrollbarWidth", b, this.az);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "scrollbarStyle", {
        get: function () {
            return this.e;
        },
        set: function (a) {
            var b = this.e;
            this.e = a;
            if (b != this.e) {
                this.dg("ScrollbarStyle", enumGetBox(ScrollbarStyle_$type, b), enumGetBox(ScrollbarStyle_$type, this.e));
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "horizontalScrollbarStatus", {
        get: function () {
            return this.a7;
        },
        set: function (a) {
            var b = this.a7;
            this.a7 = a;
            if (b != this.a7) {
                this.dg("HorizontalScrollbarStatus", b, this.a7);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "verticalScrollbarStatus", {
        get: function () {
            return this.bi;
        },
        set: function (a) {
            var b = this.bi;
            this.bi = a;
            if (b != this.bi) {
                this.dg("VerticalOpacity", b, this.bi);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "horizontalAnimation", {
        get: function () {
            return this.j;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "verticalAnimation", {
        get: function () {
            return this.k;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "executionContext", {
        get: function () {
            return this._executionContext;
        },
        set: function (a) {
            this._executionContext = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "isVerticalActive", {
        get: function () {
            return this.y;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "isHorizontalActive", {
        get: function () {
            return this.n;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "isDraggingVBar", {
        get: function () {
            return this._isDraggingVBar;
        },
        set: function (a) {
            this._isDraggingVBar = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Scroller.prototype, "isDraggingHBar", {
        get: function () {
            return this._isDraggingHBar;
        },
        set: function (a) {
            this._isDraggingHBar = a;
        },
        enumerable: false,
        configurable: true
    });
    Scroller.prototype.focus = function () {
        this.view.focus();
    };
    Scroller.prototype.de = function (a) {
        this.view.focus();
        this.s = false;
        this.q = false;
        this.r = false;
        this.p = true;
        this.dz = { $type: Point_$type, x: a.x, y: a.y };
    };
    Scroller.prototype.dd = function (a) {
        if (this.p) {
            var b = a.y - this.dz.y;
            var c = a.x - this.dz.x;
            if (this.lockScrollDirection && !this.r) {
                this.r = true;
                if (b > 0 || c > 0) {
                    if (b > c) {
                        this.s = true;
                    }
                    else {
                        this.s = true;
                    }
                }
            }
            this.dz = { $type: Point_$type, x: a.x, y: a.y };
            this.dn(-c, -b);
        }
    };
    Object.defineProperty(Scroller.prototype, "isScrolling", {
        get: function () {
            return this._isScrolling;
        },
        set: function (a) {
            this._isScrolling = a;
        },
        enumerable: false,
        configurable: true
    });
    Scroller.prototype.scrollTo = function (a, b) {
        this.view.detachNativeScroll();
        this.bb = a - this.scrollLeft;
        this.bc = b - this.scrollTop;
        this.dm();
    };
    Scroller.prototype.dn = function (a, b) {
        this.view.detachNativeScroll();
        this.bb += a;
        this.bc += b;
        this.dm();
    };
    Scroller.prototype.dp = function (a, b) {
        this.view.detachNativeScroll();
        this.bb += a;
        this.bc += b;
        this.dt();
    };
    Scroller.prototype.dm = function () {
        if (this.w) {
            return;
        }
        this.w = true;
        this.view.requestWork(runOn(this, this.dt));
    };
    Scroller.prototype.dt = function () {
        var _this = this;
        this.w = false;
        var a = this.bb;
        var b = this.bc;
        this.bb = 0;
        this.bc = 0;
        if (this.r) {
            if (this.s) {
                a = 0;
            }
            if (this.q) {
                b = 0;
            }
        }
        if (a != 0) {
            this.t = false;
            this.c3();
            this.c7();
            this.t = true;
        }
        if (b != 0) {
            this.u = false;
            this.c4();
            this.c8();
            this.u = true;
        }
        var c = Math.round(this.scrollTop + b);
        var d = Math.round(this.scrollLeft + a);
        if (c < 0) {
            c = 0;
            this.view.cancelInertia();
        }
        if (d < 0) {
            d = 0;
            this.view.cancelInertia();
        }
        if (c + this.viewportHeight > this.contentHeight) {
            c = this.contentHeight - this.viewportHeight;
            if (c < 0) {
                c = 0;
            }
            this.view.cancelInertia();
        }
        if (d + this.viewportWidth > this.contentWidth) {
            d = this.contentWidth - this.viewportWidth;
            if (d < 0) {
                d = 0;
            }
            this.view.cancelInertia();
        }
        b = c - this.scrollTop;
        a = d - this.scrollLeft;
        if (b != 0 || a != 0) {
            try {
                this.ax = true;
                this.aa = true;
                this.scrollTop = c;
                this.scrollLeft = d;
                this.dw();
                this.du();
                this.aa = false;
                if (!this.isScrolling) {
                    this.isScrolling = true;
                    if (this.onScrollStart != null) {
                        this.onScrollStart(this, ((function () {
                            var $ret = new ScrollerScrollingEventArgs();
                            $ret.deltaX = a;
                            $ret.deltaY = b;
                            return $ret;
                        })()));
                    }
                }
                if (this.onScrolling != null) {
                    this.onScrolling(this, ((function () {
                        var $ret = new ScrollerScrollingEventArgs();
                        $ret.deltaX = a;
                        $ret.deltaY = b;
                        return $ret;
                    })()));
                }
                if (this.ay.count > 0) {
                    this.ay._inner[this.ay.count - 1] = false;
                }
                this.ay.add(true);
                this.executionContext.executeDelayed(function () {
                    if (_this.ay._inner[0]) {
                        if (_this.onScrollStop != null) {
                            _this.onScrollStop(_this, ((function () {
                                var $ret = new ScrollerScrollingEventArgs();
                                $ret.deltaX = a;
                                $ret.deltaY = b;
                                return $ret;
                            })()));
                        }
                        _this.isScrolling = false;
                        _this.view.attachNativeScroll();
                    }
                    _this.ay.removeAt(0);
                }, 50);
            }
            finally {
                this.ax = false;
            }
        }
    };
    Scroller.prototype.dw = function () {
        this.dv(this.contentHeight, this.viewportHeight, this.scrollTop, true);
    };
    Scroller.prototype.du = function () {
        this.dv(this.contentWidth, this.viewportWidth, this.scrollLeft, false);
    };
    Scroller.prototype.dv = function (a, b, c, d) {
        var e = Math.round((b / a) * b);
        var f = d ? this.verticalTrackStartInset : 0;
        e = e - f;
        if (e < this.minScrollbarSize) {
            e = this.minScrollbarSize;
        }
        if (e >= (b - f)) {
            if (d) {
                this.view.hideVScrollbar();
            }
            else {
                this.view.hideHScrollbar();
            }
            return;
        }
        var g = f + (e / 2);
        var h = b - (e / 2);
        var i = c / (a - b);
        var j = Math.round(g + (h - g) * i);
        if (d) {
            this.actualVerticalScrollbarHeight = e;
            this.view.updateVScrollbar(j, e);
        }
        else {
            this.actualHorizontalScrollbarWidth = e;
            this.view.updateHScrollbar(j, e);
        }
    };
    Scroller.prototype.dc = function (a) {
        this.r = false;
        this.q = false;
        this.s = false;
        this.p = false;
    };
    Scroller.prototype.c1 = function (a, b) {
        this.horizontalScrollbarStatus = this.bu + this.j.o * (this.b5 - this.bu);
    };
    Scroller.prototype.c2 = function (a, b) {
        this.verticalScrollbarStatus = this.bv + this.k.o * (this.b6 - this.bv);
    };
    Scroller.prototype.c3 = function () {
        if (this.n) {
            return;
        }
        if (this.scrollbarStyle == 1 || this.scrollbarStyle == 2) {
            if (this.j.f()) {
                this.j.w();
            }
            this.horizontalScrollbarStatus = 1;
            if (this.o && this.t) {
                this.o = false;
            }
        }
        this.n = true;
    };
    Scroller.prototype.c4 = function () {
        if (this.y) {
            return;
        }
        if (this.scrollbarStyle == 1 || this.scrollbarStyle == 2) {
            if (this.k.f()) {
                this.k.w();
            }
            this.verticalScrollbarStatus = 1;
            if (this.z && this.u) {
                this.z = false;
            }
        }
        this.y = true;
    };
    Scroller.prototype.c7 = function () {
        if (!this.n || this.isDraggingHBar) {
            return;
        }
        if (this.scrollbarStyle == 1 || this.scrollbarStyle == 2) {
            this.dr();
        }
        this.n = false;
    };
    Scroller.prototype.c8 = function () {
        if (!this.y || this.isDraggingVBar) {
            return;
        }
        if (this.scrollbarStyle == 1 || this.scrollbarStyle == 2) {
            this.ds();
        }
        this.y = false;
    };
    Scroller.prototype.dr = function () {
        if (!this.o) {
            this.o = true;
            this.cc = this.executionContext.getCurrentRelativeTime();
            this.executionContext.executeDelayed(runOn(this, this.c5), this.cb);
        }
        else {
            this.cc = this.executionContext.getCurrentRelativeTime();
        }
    };
    Scroller.prototype.ds = function () {
        if (!this.z) {
            this.z = true;
            this.cd = this.executionContext.getCurrentRelativeTime();
            this.executionContext.executeDelayed(runOn(this, this.c6), this.cb);
        }
        else {
            this.cd = this.executionContext.getCurrentRelativeTime();
        }
    };
    Scroller.prototype.c5 = function () {
        if (!this.o) {
            return;
        }
        var a = this.executionContext.getCurrentRelativeTime();
        if (a - this.cc >= this.cb) {
            if (!this.j.f() && this.horizontalScrollbarStatus != 0) {
                this.bu = this.horizontalScrollbarStatus;
                this.b5 = 0;
                this.j.v();
            }
            this.o = false;
        }
        else {
            this.executionContext.executeDelayed(runOn(this, this.c5), (this.cb - (a - this.cc)));
        }
    };
    Scroller.prototype.c6 = function () {
        if (!this.z) {
            return;
        }
        var a = this.executionContext.getCurrentRelativeTime();
        if (a - this.cd >= this.cb) {
            if (!this.k.f() && this.verticalScrollbarStatus != 0) {
                this.bv = this.verticalScrollbarStatus;
                this.b6 = 0;
                this.k.v();
            }
            this.z = false;
        }
        else {
            this.executionContext.executeDelayed(runOn(this, this.c6), (this.cb - (a - this.cd)));
        }
    };
    Scroller.$t = markType(Scroller, 'Scroller', Base.$, [INotifyPropertyChanged_$type]);
    return Scroller;
}(Base));
export { Scroller };
