1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | "use strict";
|
8 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
9 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
10 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
11 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
12 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
13 | };
|
14 | var __metadata = (this && this.__metadata) || function (k, v) {
|
15 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
16 | };
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | var context_1 = require("../context/context");
|
19 | var linkedList_1 = require("./linkedList");
|
20 | var gridOptionsWrapper_1 = require("../gridOptionsWrapper");
|
21 | var eventKeys_1 = require("../eventKeys");
|
22 | var eventService_1 = require("../eventService");
|
23 | var AnimationFrameService = (function () {
|
24 | function AnimationFrameService() {
|
25 | this.p1Tasks = new linkedList_1.LinkedList();
|
26 | this.p2Tasks = new linkedList_1.LinkedList();
|
27 | this.ticking = false;
|
28 | }
|
29 | AnimationFrameService.prototype.registerGridComp = function (gridPanel) {
|
30 | this.gridPanel = gridPanel;
|
31 | };
|
32 | AnimationFrameService.prototype.init = function () {
|
33 | this.useAnimationFrame = !this.gridOptionsWrapper.isSuppressAnimationFrame();
|
34 | };
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | AnimationFrameService.prototype.verifyAnimationFrameOn = function (methodName) {
|
40 | if (this.useAnimationFrame === false) {
|
41 | console.warn("ag-Grid: AnimationFrameService." + methodName + " called but animation frames are off");
|
42 | }
|
43 | };
|
44 | AnimationFrameService.prototype.addP1Task = function (task) {
|
45 | this.verifyAnimationFrameOn('addP1Task');
|
46 | this.p1Tasks.add(task);
|
47 | this.schedule();
|
48 | };
|
49 | AnimationFrameService.prototype.addP2Task = function (task) {
|
50 | this.verifyAnimationFrameOn('addP2Task');
|
51 | this.p2Tasks.add(task);
|
52 | this.schedule();
|
53 | };
|
54 | AnimationFrameService.prototype.executeFrame = function (millis) {
|
55 | this.verifyAnimationFrameOn('executeFrame');
|
56 | var frameStart = new Date().getTime();
|
57 | var duration = (new Date().getTime()) - frameStart;
|
58 | var gridPanelNeedsAFrame = true;
|
59 |
|
60 | var noMaxMillis = millis <= 0;
|
61 | while (noMaxMillis || duration < millis) {
|
62 | if (gridPanelNeedsAFrame) {
|
63 | gridPanelNeedsAFrame = this.gridPanel.executeFrame();
|
64 | }
|
65 | else if (!this.p1Tasks.isEmpty()) {
|
66 | var task = this.p1Tasks.remove();
|
67 | task();
|
68 | }
|
69 | else if (!this.p2Tasks.isEmpty()) {
|
70 | var task = this.p2Tasks.remove();
|
71 | task();
|
72 | }
|
73 | else {
|
74 | break;
|
75 | }
|
76 | duration = (new Date().getTime()) - frameStart;
|
77 | }
|
78 | if (gridPanelNeedsAFrame || !this.p1Tasks.isEmpty() || !this.p2Tasks.isEmpty()) {
|
79 | this.requestFrame();
|
80 | }
|
81 | else {
|
82 | this.stopTicking();
|
83 | }
|
84 | };
|
85 | AnimationFrameService.prototype.stopTicking = function () {
|
86 | this.ticking = false;
|
87 | var event = {
|
88 | type: eventKeys_1.Events.EVENT_ANIMATION_QUEUE_EMPTY,
|
89 | columnApi: this.gridOptionsWrapper.getColumnApi(),
|
90 | api: this.gridOptionsWrapper.getApi()
|
91 | };
|
92 | this.eventService.dispatchEvent(event);
|
93 | };
|
94 | AnimationFrameService.prototype.flushAllFrames = function () {
|
95 | if (!this.useAnimationFrame) {
|
96 | return;
|
97 | }
|
98 | this.executeFrame(-1);
|
99 | };
|
100 | AnimationFrameService.prototype.schedule = function () {
|
101 | if (!this.useAnimationFrame) {
|
102 | return;
|
103 | }
|
104 | if (!this.ticking) {
|
105 | this.ticking = true;
|
106 | this.requestFrame();
|
107 | }
|
108 | };
|
109 | AnimationFrameService.prototype.requestFrame = function () {
|
110 |
|
111 |
|
112 | var callback = this.executeFrame.bind(this, 60);
|
113 | if (window.requestAnimationFrame) {
|
114 | window.requestAnimationFrame(callback);
|
115 | }
|
116 | else if (window.webkitRequestAnimationFrame) {
|
117 | window.webkitRequestAnimationFrame(callback);
|
118 | }
|
119 | else {
|
120 | setTimeout(callback, 0);
|
121 | }
|
122 | };
|
123 | AnimationFrameService.prototype.isQueueEmpty = function () {
|
124 | return this.ticking;
|
125 | };
|
126 | __decorate([
|
127 | context_1.Autowired('gridOptionsWrapper'),
|
128 | __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
|
129 | ], AnimationFrameService.prototype, "gridOptionsWrapper", void 0);
|
130 | __decorate([
|
131 | context_1.Autowired('eventService'),
|
132 | __metadata("design:type", eventService_1.EventService)
|
133 | ], AnimationFrameService.prototype, "eventService", void 0);
|
134 | __decorate([
|
135 | context_1.PostConstruct,
|
136 | __metadata("design:type", Function),
|
137 | __metadata("design:paramtypes", []),
|
138 | __metadata("design:returntype", void 0)
|
139 | ], AnimationFrameService.prototype, "init", null);
|
140 | AnimationFrameService = __decorate([
|
141 | context_1.Bean('animationFrameService')
|
142 | ], AnimationFrameService);
|
143 | return AnimationFrameService;
|
144 | }());
|
145 | exports.AnimationFrameService = AnimationFrameService;
|