mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 958110 - Update Shumway to version 0.7.993. r=till
This commit is contained in:
parent
6d921eb968
commit
821accba8f
@ -188,6 +188,16 @@ function isShumwayEnabledFor(actions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function fallbackToNativePlugin(window, userAction, activateCTP) {
|
||||
var obj = window.frameElement;
|
||||
var doc = obj.ownerDocument;
|
||||
var e = doc.createEvent("CustomEvent");
|
||||
e.initCustomEvent("MozPlayPlugin", true, true, activateCTP);
|
||||
obj.dispatchEvent(e);
|
||||
|
||||
ShumwayTelemetry.onFallback(userAction);
|
||||
}
|
||||
|
||||
// All the priviledged actions.
|
||||
function ChromeActions(url, window, document) {
|
||||
this.url = url;
|
||||
@ -356,13 +366,8 @@ ChromeActions.prototype = {
|
||||
});
|
||||
},
|
||||
fallback: function(automatic) {
|
||||
var obj = this.window.frameElement;
|
||||
var doc = obj.ownerDocument;
|
||||
var e = doc.createEvent("CustomEvent");
|
||||
e.initCustomEvent("MozPlayPlugin", true, true, null);
|
||||
obj.dispatchEvent(e);
|
||||
|
||||
ShumwayTelemetry.onFallback(!automatic);
|
||||
automatic = !!automatic; // cast to boolean
|
||||
fallbackToNativePlugin(this.window, !automatic, automatic);
|
||||
},
|
||||
setClipboard: function (data) {
|
||||
if (typeof data !== 'string' ||
|
||||
@ -902,7 +907,7 @@ ShumwayStreamConverterBase.prototype = {
|
||||
converter.getUrlHint(originalURI));
|
||||
|
||||
if (!isShumwayEnabledFor(actions)) {
|
||||
actions.fallback(true);
|
||||
fallbackToNativePlugin(domWindow, false, true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Binary file not shown.
@ -187,32 +187,12 @@ function cloneObject(obj) {
|
||||
clone[prop] = obj[prop];
|
||||
return clone;
|
||||
}
|
||||
function sortByDepth(a, b) {
|
||||
var levelA = a._level;
|
||||
var levelB = b._level;
|
||||
if (a._parent !== b._parent && a._index > -1 && b._index > -1) {
|
||||
while (a._level > levelB) {
|
||||
a = a._parent;
|
||||
}
|
||||
while (b._level > levelA) {
|
||||
b = b._parent;
|
||||
}
|
||||
while (a._level > 1) {
|
||||
if (a._parent === b._parent) {
|
||||
break;
|
||||
}
|
||||
a = a._parent;
|
||||
b = b._parent;
|
||||
}
|
||||
}
|
||||
if (a === b) {
|
||||
return levelA - levelB;
|
||||
}
|
||||
return a._index - b._index;
|
||||
}
|
||||
function sortNumeric(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
function sortByZindex(a, b) {
|
||||
return a._zindex - b._zindex;
|
||||
}
|
||||
function rgbaObjToStr(color) {
|
||||
return 'rgba(' + color.red + ',' + color.green + ',' + color.blue + ',' + color.alpha / 255 + ')';
|
||||
}
|
||||
@ -296,158 +276,336 @@ function randomStyle() {
|
||||
}
|
||||
return randomStyleCache[nextStyle++ % randomStyleCache.length];
|
||||
}
|
||||
var Promise = function PromiseClosure() {
|
||||
function isPromise(obj) {
|
||||
return typeof obj === 'object' && obj !== null && typeof obj.then === 'function';
|
||||
}
|
||||
function defaultOnFulfilled(value) {
|
||||
return value;
|
||||
}
|
||||
function defaultOnRejected(reason) {
|
||||
throw reason;
|
||||
}
|
||||
function propagateFulfilled(subject, value) {
|
||||
subject.subpromisesValue = value;
|
||||
var subpromises = subject.subpromises;
|
||||
if (!subpromises) {
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < subpromises.length; i++) {
|
||||
subpromises[i].fulfill(value);
|
||||
}
|
||||
delete subject.subpromises;
|
||||
}
|
||||
function propagateRejected(subject, reason) {
|
||||
subject.subpromisesReason = reason;
|
||||
var subpromises = subject.subpromises;
|
||||
if (!subpromises) {
|
||||
if (!true) {
|
||||
console.warn(reason);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < subpromises.length; i++) {
|
||||
subpromises[i].reject(reason);
|
||||
}
|
||||
delete subject.subpromises;
|
||||
}
|
||||
function performCall(callback, arg, subject) {
|
||||
try {
|
||||
var value = callback(arg);
|
||||
if (isPromise(value)) {
|
||||
value.then(function Promise_queueCall_onFulfilled(value) {
|
||||
propagateFulfilled(subject, value);
|
||||
}, function Promise_queueCall_onRejected(reason) {
|
||||
propagateRejected(subject, reason);
|
||||
(function PromiseClosure() {
|
||||
var global = Function('return this')();
|
||||
if (global.Promise) {
|
||||
if (typeof global.Promise.all !== 'function') {
|
||||
global.Promise.all = function (iterable) {
|
||||
var count = 0, results = [], resolve, reject;
|
||||
var promise = new global.Promise(function (resolve_, reject_) {
|
||||
resolve = resolve_;
|
||||
reject = reject_;
|
||||
});
|
||||
return;
|
||||
iterable.forEach(function (p, i) {
|
||||
count++;
|
||||
p.then(function (result) {
|
||||
results[i] = result;
|
||||
count--;
|
||||
if (count === 0) {
|
||||
resolve(results);
|
||||
}
|
||||
}, reject);
|
||||
});
|
||||
if (count === 0) {
|
||||
resolve(results);
|
||||
}
|
||||
propagateFulfilled(subject, value);
|
||||
} catch (ex) {
|
||||
propagateRejected(subject, ex);
|
||||
}
|
||||
return promise;
|
||||
};
|
||||
}
|
||||
var queue = [];
|
||||
function processQueue() {
|
||||
while (queue.length > 0) {
|
||||
var task = queue[0];
|
||||
if (task.directCallback) {
|
||||
task.callback.call(task.subject, task.arg);
|
||||
} else {
|
||||
performCall(task.callback, task.arg, task.subject);
|
||||
}
|
||||
queue.shift();
|
||||
}
|
||||
if (typeof global.Promise.resolve !== 'function') {
|
||||
global.Promise.resolve = function (x) {
|
||||
return new global.Promise(function (resolve) {
|
||||
resolve(x);
|
||||
});
|
||||
};
|
||||
}
|
||||
function queueCall(callback, arg, subject, directCallback) {
|
||||
if (queue.length === 0) {
|
||||
setTimeout(processQueue, 0);
|
||||
return;
|
||||
}
|
||||
function getDeferred(C) {
|
||||
if (typeof C !== 'function') {
|
||||
throw new TypeError('Invalid deferred constructor');
|
||||
}
|
||||
var resolver = createDeferredConstructionFunctions();
|
||||
var promise = new C(resolver);
|
||||
var resolve = resolver.resolve;
|
||||
if (typeof resolve !== 'function') {
|
||||
throw new TypeError('Invalid resolve construction function');
|
||||
}
|
||||
var reject = resolver.reject;
|
||||
if (typeof reject !== 'function') {
|
||||
throw new TypeError('Invalid reject construction function');
|
||||
}
|
||||
return {
|
||||
promise: promise,
|
||||
resolve: resolve,
|
||||
reject: reject
|
||||
};
|
||||
}
|
||||
function updateDeferredFromPotentialThenable(x, deferred) {
|
||||
if (typeof x !== 'object' || x === null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
var then = x.then;
|
||||
if (typeof then !== 'function') {
|
||||
return false;
|
||||
}
|
||||
queue.push({
|
||||
callback: callback,
|
||||
arg: arg,
|
||||
subject: subject,
|
||||
directCallback: directCallback
|
||||
var thenCallResult = then.call(x, deferred.resolve, deferred.reject);
|
||||
} catch (e) {
|
||||
var reject = deferred.reject;
|
||||
reject(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function isPromise(x) {
|
||||
return typeof x === 'object' && x !== null && typeof x.promiseStatus !== 'undefined';
|
||||
}
|
||||
function rejectPromise(promise, reason) {
|
||||
if (promise.promiseStatus !== 'unresolved') {
|
||||
return;
|
||||
}
|
||||
var reactions = promise.rejectReactions;
|
||||
promise.result = reason;
|
||||
promise.resolveReactions = undefined;
|
||||
promise.rejectReactions = undefined;
|
||||
promise.promiseStatus = 'has-rejection';
|
||||
triggerPromiseReactions(reactions, reason);
|
||||
}
|
||||
function resolvePromise(promise, resolution) {
|
||||
if (promise.promiseStatus !== 'unresolved') {
|
||||
return;
|
||||
}
|
||||
var reactions = promise.resolveReactions;
|
||||
promise.result = resolution;
|
||||
promise.resolveReactions = undefined;
|
||||
promise.rejectReactions = undefined;
|
||||
promise.promiseStatus = 'has-resolution';
|
||||
triggerPromiseReactions(reactions, resolution);
|
||||
}
|
||||
function triggerPromiseReactions(reactions, argument) {
|
||||
for (var i = 0; i < reactions.length; i++) {
|
||||
queueMicrotask({
|
||||
reaction: reactions[i],
|
||||
argument: argument
|
||||
});
|
||||
}
|
||||
function Promise(onFulfilled, onRejected) {
|
||||
this.state = 'pending';
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : defaultOnFulfilled;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : defaultOnRejected;
|
||||
}
|
||||
function queueMicrotask(task) {
|
||||
if (microtasksQueue.length === 0) {
|
||||
setTimeout(handleMicrotasksQueue, 0);
|
||||
}
|
||||
Promise.prototype = {
|
||||
fulfill: function Promise_resolve(value) {
|
||||
if (this.state !== 'pending') {
|
||||
return;
|
||||
microtasksQueue.push(task);
|
||||
}
|
||||
function executePromiseReaction(reaction, argument) {
|
||||
var deferred = reaction.deferred;
|
||||
var handler = reaction.handler;
|
||||
var handlerResult, updateResult;
|
||||
try {
|
||||
handlerResult = handler(argument);
|
||||
} catch (e) {
|
||||
var reject = deferred.reject;
|
||||
return reject(e);
|
||||
}
|
||||
if (handlerResult === deferred.promise) {
|
||||
var reject = deferred.reject;
|
||||
return reject(new TypeError('Self resolution'));
|
||||
}
|
||||
try {
|
||||
updateResult = updateDeferredFromPotentialThenable(handlerResult, deferred);
|
||||
if (!updateResult) {
|
||||
var resolve = deferred.resolve;
|
||||
return resolve(handlerResult);
|
||||
}
|
||||
} catch (e) {
|
||||
var reject = deferred.reject;
|
||||
return reject(e);
|
||||
}
|
||||
}
|
||||
var microtasksQueue = [];
|
||||
function handleMicrotasksQueue() {
|
||||
while (microtasksQueue.length > 0) {
|
||||
var task = microtasksQueue[0];
|
||||
try {
|
||||
executePromiseReaction(task.reaction, task.argument);
|
||||
} catch (e) {
|
||||
if (typeof Promise.onerror === 'function') {
|
||||
Promise.onerror(e);
|
||||
}
|
||||
this.state = 'fulfilled';
|
||||
this.value = value;
|
||||
queueCall(this.onFulfilled, value, this, false);
|
||||
},
|
||||
reject: function Promise_reject(reason) {
|
||||
if (this.state !== 'pending') {
|
||||
return;
|
||||
}
|
||||
microtasksQueue.shift();
|
||||
}
|
||||
}
|
||||
function throwerFunction(e) {
|
||||
throw e;
|
||||
}
|
||||
function identityFunction(x) {
|
||||
return x;
|
||||
}
|
||||
function createRejectPromiseFunction(promise) {
|
||||
return function (reason) {
|
||||
rejectPromise(promise, reason);
|
||||
};
|
||||
}
|
||||
function createResolvePromiseFunction(promise) {
|
||||
return function (resolution) {
|
||||
resolvePromise(promise, resolution);
|
||||
};
|
||||
}
|
||||
function createDeferredConstructionFunctions() {
|
||||
var fn = function (resolve, reject) {
|
||||
fn.resolve = resolve;
|
||||
fn.reject = reject;
|
||||
};
|
||||
return fn;
|
||||
}
|
||||
function createPromiseResolutionHandlerFunctions(promise, fulfillmentHandler, rejectionHandler) {
|
||||
return function (x) {
|
||||
if (x === promise) {
|
||||
return rejectionHandler(new TypeError('Self resolution'));
|
||||
}
|
||||
var cstr = promise.promiseConstructor;
|
||||
if (isPromise(x)) {
|
||||
var xConstructor = x.promiseConstructor;
|
||||
if (xConstructor === cstr) {
|
||||
return x.then(fulfillmentHandler, rejectionHandler);
|
||||
}
|
||||
this.state = 'rejected';
|
||||
this.reason = reason;
|
||||
queueCall(this.onRejected, reason, this, false);
|
||||
},
|
||||
then: function Promise_then(onFulfilled, onRejected) {
|
||||
var promise = new Promise(onFulfilled, onRejected);
|
||||
if ('subpromisesValue' in this) {
|
||||
queueCall(promise.fulfill, this.subpromisesValue, promise, true);
|
||||
} else if ('subpromisesReason' in this) {
|
||||
queueCall(promise.reject, this.subpromisesReason, promise, true);
|
||||
} else {
|
||||
var subpromises = this.subpromises || (this.subpromises = []);
|
||||
subpromises.push(promise);
|
||||
}
|
||||
return promise;
|
||||
},
|
||||
get resolved() {
|
||||
return this.state === 'fulfilled';
|
||||
},
|
||||
resolve: function (value) {
|
||||
this.fulfill(value);
|
||||
}
|
||||
var deferred = getDeferred(cstr);
|
||||
var updateResult = updateDeferredFromPotentialThenable(x, deferred);
|
||||
if (updateResult) {
|
||||
var deferredPromise = deferred.promise;
|
||||
return deferredPromise.then(fulfillmentHandler, rejectionHandler);
|
||||
}
|
||||
return fulfillmentHandler(x);
|
||||
};
|
||||
}
|
||||
function createPromiseAllCountdownFunction(index, values, deferred, countdownHolder) {
|
||||
return function (x) {
|
||||
values[index] = x;
|
||||
countdownHolder.countdown--;
|
||||
if (countdownHolder.countdown === 0) {
|
||||
deferred.resolve(values);
|
||||
}
|
||||
};
|
||||
Promise.when = function Promise_when() {
|
||||
var promise = new Promise();
|
||||
if (arguments.length === 0) {
|
||||
promise.resolve();
|
||||
return promise;
|
||||
}
|
||||
function Promise(resolver) {
|
||||
if (typeof resolver !== 'function') {
|
||||
throw new TypeError('resolver is not a function');
|
||||
}
|
||||
var promise = this;
|
||||
if (typeof promise !== 'object') {
|
||||
throw new TypeError('Promise to initialize is not an object');
|
||||
}
|
||||
promise.promiseStatus = 'unresolved';
|
||||
promise.resolveReactions = [];
|
||||
promise.rejectReactions = [];
|
||||
promise.result = undefined;
|
||||
var resolve = createResolvePromiseFunction(promise);
|
||||
var reject = createRejectPromiseFunction(promise);
|
||||
try {
|
||||
var result = resolver(resolve, reject);
|
||||
} catch (e) {
|
||||
rejectPromise(promise, e);
|
||||
}
|
||||
promise.promiseConstructor = Promise;
|
||||
return promise;
|
||||
}
|
||||
Promise.all = function (iterable) {
|
||||
var deferred = getDeferred(this);
|
||||
var values = [];
|
||||
var countdownHolder = {
|
||||
countdown: 0
|
||||
};
|
||||
var index = 0;
|
||||
iterable.forEach(function (nextValue) {
|
||||
var nextPromise = this.cast(nextValue);
|
||||
var fn = createPromiseAllCountdownFunction(index, values, deferred, countdownHolder);
|
||||
nextPromise.then(fn, deferred.reject);
|
||||
index++;
|
||||
countdownHolder.countdown++;
|
||||
}, this);
|
||||
if (index === 0) {
|
||||
deferred.resolve(values);
|
||||
}
|
||||
return deferred.promise;
|
||||
};
|
||||
Promise.cast = function (x) {
|
||||
if (isPromise(x)) {
|
||||
return x;
|
||||
}
|
||||
var deferred = getDeferred(this);
|
||||
deferred.resolve(x);
|
||||
return deferred.promise;
|
||||
};
|
||||
Promise.reject = function (r) {
|
||||
var deferred = getDeferred(this);
|
||||
var rejectResult = deferred.reject(r);
|
||||
return deferred.promise;
|
||||
};
|
||||
Promise.resolve = function (x) {
|
||||
var deferred = getDeferred(this);
|
||||
var rejectResult = deferred.resolve(x);
|
||||
return deferred.promise;
|
||||
};
|
||||
Promise.prototype = {
|
||||
'catch': function (onRejected) {
|
||||
this.then(undefined, onRejected);
|
||||
},
|
||||
then: function (onFulfilled, onRejected) {
|
||||
var promise = this;
|
||||
if (!isPromise(promise)) {
|
||||
throw new TypeError('this is not a Promises');
|
||||
}
|
||||
var promises = slice.call(arguments, 0);
|
||||
var result = [];
|
||||
var i = 1;
|
||||
function fulfill(value) {
|
||||
result.push(value);
|
||||
if (i < promises.length) {
|
||||
promises[i++].then(fulfill, reject);
|
||||
} else {
|
||||
promise.resolve(result);
|
||||
}
|
||||
return value;
|
||||
var cstr = promise.promiseConstructor;
|
||||
var deferred = getDeferred(cstr);
|
||||
var rejectionHandler = typeof onRejected === 'function' ? onRejected : throwerFunction;
|
||||
var fulfillmentHandler = typeof onFulfilled === 'function' ? onFulfilled : identityFunction;
|
||||
var resolutionHandler = createPromiseResolutionHandlerFunctions(promise, fulfillmentHandler, rejectionHandler);
|
||||
var resolveReaction = {
|
||||
deferred: deferred,
|
||||
handler: resolutionHandler
|
||||
};
|
||||
var rejectReaction = {
|
||||
deferred: deferred,
|
||||
handler: rejectionHandler
|
||||
};
|
||||
switch (promise.promiseStatus) {
|
||||
case 'unresolved':
|
||||
promise.resolveReactions.push(resolveReaction);
|
||||
promise.rejectReactions.push(rejectReaction);
|
||||
break;
|
||||
case 'has-resolution':
|
||||
var resolution = promise.result;
|
||||
queueMicrotask({
|
||||
reaction: resolveReaction,
|
||||
argument: resolution
|
||||
});
|
||||
break;
|
||||
case 'has-rejection':
|
||||
var rejection = promise.result;
|
||||
queueMicrotask({
|
||||
reaction: rejectReaction,
|
||||
argument: rejection
|
||||
});
|
||||
break;
|
||||
}
|
||||
function reject(reason) {
|
||||
promise.reject(reason);
|
||||
}
|
||||
promises[0].then(fulfill, reject);
|
||||
return promise;
|
||||
};
|
||||
return Promise;
|
||||
}();
|
||||
var QuadTree = function (x, y, width, height, level) {
|
||||
return deferred.promise;
|
||||
}
|
||||
};
|
||||
global.Promise = Promise;
|
||||
}());
|
||||
var QuadTree = function (x, y, width, height, parent) {
|
||||
this.x = x | 0;
|
||||
this.y = y | 0;
|
||||
this.width = width | 0;
|
||||
this.height = height | 0;
|
||||
this.level = level | 0;
|
||||
this.stuckObjects = [];
|
||||
this.objects = [];
|
||||
if (parent) {
|
||||
this.root = parent.root;
|
||||
this.parent = parent;
|
||||
this.level = parent.level + 1;
|
||||
} else {
|
||||
this.root = this;
|
||||
this.parent = null;
|
||||
this.level = 0;
|
||||
}
|
||||
this.reset();
|
||||
};
|
||||
QuadTree.prototype.reset = function () {
|
||||
this.stuckObjects = null;
|
||||
this.objects = null;
|
||||
this.nodes = [];
|
||||
};
|
||||
QuadTree.prototype._findIndex = function (xMin, yMin, xMax, yMax) {
|
||||
QuadTree.prototype._findIndex = function (xMin, xMax, yMin, yMax) {
|
||||
var midX = this.x + (this.width / 2 | 0);
|
||||
var midY = this.y + (this.height / 2 | 0);
|
||||
var top = yMin < midY && yMax < midY;
|
||||
@ -470,57 +628,114 @@ QuadTree.prototype._findIndex = function (xMin, yMin, xMax, yMax) {
|
||||
QuadTree.prototype.insert = function (obj) {
|
||||
var nodes = this.nodes;
|
||||
if (nodes.length) {
|
||||
var index = this._findIndex(obj.xMin, obj.yMin, obj.xMax, obj.yMax);
|
||||
var index = this._findIndex(obj.xMin, obj.xMax, obj.yMin, obj.yMax);
|
||||
if (index > -1) {
|
||||
nodes[index].insert(obj);
|
||||
} else {
|
||||
this.stuckObjects.push(obj);
|
||||
obj._qtree = this;
|
||||
obj.prev = null;
|
||||
if (this.stuckObjects) {
|
||||
obj.next = this.stuckObjects;
|
||||
this.stuckObjects.prev = obj;
|
||||
} else {
|
||||
obj.next = null;
|
||||
}
|
||||
this.stuckObjects = obj;
|
||||
obj.parent = this;
|
||||
}
|
||||
return;
|
||||
}
|
||||
var objects = this.objects;
|
||||
objects.push(obj);
|
||||
if (objects.length > 4 && this.level < 10) {
|
||||
this._subdivide();
|
||||
while (objects.length) {
|
||||
this.insert(objects.shift());
|
||||
}
|
||||
return;
|
||||
}
|
||||
obj._qtree = this;
|
||||
};
|
||||
QuadTree.prototype.delete = function (obj) {
|
||||
if (obj._qtree !== this) {
|
||||
return;
|
||||
}
|
||||
var index = this.objects.indexOf(obj);
|
||||
if (index > -1) {
|
||||
this.objects.splice(index, 1);
|
||||
var numChildren = 1;
|
||||
var item = this.objects;
|
||||
if (!item) {
|
||||
obj.prev = null;
|
||||
obj.next = null;
|
||||
this.objects = obj;
|
||||
} else {
|
||||
index = this.stuckObjects.indexOf(obj);
|
||||
this.stuckObjects.splice(index, 1);
|
||||
while (item.next) {
|
||||
numChildren++;
|
||||
item = item.next;
|
||||
}
|
||||
obj.prev = item;
|
||||
obj.next = null;
|
||||
item.next = obj;
|
||||
}
|
||||
obj._qtree = null;
|
||||
if (numChildren > 4 && this.level < 10) {
|
||||
this._subdivide();
|
||||
item = this.objects;
|
||||
while (item) {
|
||||
var next = item.next;
|
||||
this.insert(item);
|
||||
item = next;
|
||||
}
|
||||
this.objects = null;
|
||||
return;
|
||||
}
|
||||
obj.parent = this;
|
||||
};
|
||||
QuadTree.prototype._stack = [];
|
||||
QuadTree.prototype._out = [];
|
||||
QuadTree.prototype.retrieve = function (xMin, yMin, xMax, yMax) {
|
||||
var stack = this._stack;
|
||||
var out = this._out;
|
||||
out.length = 0;
|
||||
QuadTree.prototype.update = function (obj) {
|
||||
var node = obj.parent;
|
||||
if (node) {
|
||||
if (obj.xMin >= node.x && obj.xMax <= node.x + node.width && obj.yMin >= node.y && obj.yMax <= node.y + node.height) {
|
||||
if (node.nodes.length) {
|
||||
var index = this._findIndex(obj.xMin, obj.xMax, obj.yMin, obj.yMax);
|
||||
if (index > -1) {
|
||||
node.remove(obj);
|
||||
node = this.nodes[index];
|
||||
node.insert(obj);
|
||||
}
|
||||
} else {
|
||||
node.remove(obj);
|
||||
node.insert(obj);
|
||||
}
|
||||
return;
|
||||
}
|
||||
node.remove(obj);
|
||||
}
|
||||
this.root.insert(obj);
|
||||
};
|
||||
QuadTree.prototype.remove = function (obj) {
|
||||
var prev = obj.prev;
|
||||
var next = obj.next;
|
||||
if (prev) {
|
||||
prev.next = next;
|
||||
obj.prev = null;
|
||||
} else {
|
||||
var node = obj.parent;
|
||||
if (node.objects === obj) {
|
||||
node.objects = next;
|
||||
} else if (node.stuckObjects === obj) {
|
||||
node.stuckObjects = next;
|
||||
}
|
||||
}
|
||||
if (next) {
|
||||
next.prev = prev;
|
||||
obj.next = null;
|
||||
}
|
||||
obj.parent = null;
|
||||
};
|
||||
QuadTree.prototype.retrieve = function (xMin, xMax, yMin, yMax) {
|
||||
var stack = [];
|
||||
var out = [];
|
||||
var node = this;
|
||||
do {
|
||||
if (node.nodes.length) {
|
||||
var index = node._findIndex(xMin, yMin, xMax, yMax);
|
||||
var index = node._findIndex(xMin, xMax, yMin, yMax);
|
||||
if (index > -1) {
|
||||
stack.push(node.nodes[index]);
|
||||
} else {
|
||||
stack.push.apply(stack, node.nodes);
|
||||
}
|
||||
}
|
||||
out.push.apply(out, node.stuckObjects);
|
||||
out.push.apply(out, node.objects);
|
||||
var item = node.objects;
|
||||
for (var i = 0; i < 2; i++) {
|
||||
while (item) {
|
||||
if (!(item.xMin > xMax || item.xMax < xMin || item.yMin > yMax || item.yMax < yMin)) {
|
||||
out.push(item);
|
||||
}
|
||||
item = item.next;
|
||||
}
|
||||
item = node.stuckObjects;
|
||||
}
|
||||
node = stack.pop();
|
||||
} while (node);
|
||||
return out;
|
||||
@ -530,11 +745,91 @@ QuadTree.prototype._subdivide = function () {
|
||||
var halfHeight = this.height / 2 | 0;
|
||||
var midX = this.x + halfWidth;
|
||||
var midY = this.y + halfHeight;
|
||||
var level = this.level + 1;
|
||||
this.nodes[0] = new QuadTree(midX, this.y, halfWidth, halfHeight, level);
|
||||
this.nodes[1] = new QuadTree(this.x, this.y, halfWidth, halfHeight, level);
|
||||
this.nodes[2] = new QuadTree(this.x, midY, halfWidth, halfHeight, level);
|
||||
this.nodes[3] = new QuadTree(midX, midY, halfWidth, halfHeight, level);
|
||||
this.nodes[0] = new QuadTree(midX, this.y, halfWidth, halfHeight, this);
|
||||
this.nodes[1] = new QuadTree(this.x, this.y, halfWidth, halfHeight, this);
|
||||
this.nodes[2] = new QuadTree(this.x, midY, halfWidth, halfHeight, this);
|
||||
this.nodes[3] = new QuadTree(midX, midY, halfWidth, halfHeight, this);
|
||||
};
|
||||
var RegionCluster = function () {
|
||||
this.regions = [];
|
||||
};
|
||||
RegionCluster.prototype.reset = function () {
|
||||
this.regions.length = 0;
|
||||
};
|
||||
RegionCluster.prototype.insert = function (region) {
|
||||
var regions = this.regions;
|
||||
if (regions.length < 3) {
|
||||
regions.push({
|
||||
xMin: region.xMin,
|
||||
xMax: region.xMax,
|
||||
yMin: region.yMin,
|
||||
yMax: region.yMax
|
||||
});
|
||||
return;
|
||||
}
|
||||
var a = region;
|
||||
var b = regions[0];
|
||||
var c = regions[1];
|
||||
var d = regions[2];
|
||||
var ab = (max(a.xMax, b.xMax) - min(a.xMin, b.xMin)) * (max(a.yMax, b.yMax) - min(a.yMin, b.yMin));
|
||||
var rb = regions[0];
|
||||
var ac = (max(a.xMax, c.xMax) - min(a.xMin, c.xMin)) * (max(a.yMax, c.yMax) - min(a.yMin, c.yMin));
|
||||
var ad = (max(a.xMax, d.xMax) - min(a.xMin, d.xMin)) * (max(a.yMax, d.yMax) - min(a.yMin, d.yMin));
|
||||
if (ac < ab) {
|
||||
ab = ac;
|
||||
rb = c;
|
||||
}
|
||||
if (ad < ab) {
|
||||
ab = ad;
|
||||
rb = d;
|
||||
}
|
||||
var bc = (max(b.xMax, c.xMax) - min(b.xMin, c.xMin)) * (max(b.yMax, c.yMax) - min(b.yMin, c.yMin));
|
||||
var bd = (max(b.xMax, d.xMax) - min(b.xMin, d.xMin)) * (max(b.yMax, d.yMax) - min(b.yMin, d.yMin));
|
||||
var cd = (max(c.xMax, d.xMax) - min(c.xMin, d.xMin)) * (max(c.yMax, d.yMax) - min(c.yMin, d.yMin));
|
||||
if (ab < bc && ab < bd && ab < cd) {
|
||||
if (a.xMin < rb.xMin) {
|
||||
rb.xMin = a.xMin;
|
||||
}
|
||||
if (a.xMax > rb.xMax) {
|
||||
rb.xMax = a.xMax;
|
||||
}
|
||||
if (a.yMin < rb.yMin) {
|
||||
rb.yMin = a.yMin;
|
||||
}
|
||||
if (a.yMax > rb.yMax) {
|
||||
rb.yMax = a.yMax;
|
||||
}
|
||||
return;
|
||||
}
|
||||
rb = regions[0];
|
||||
var rc = regions[1];
|
||||
if (bd < bc) {
|
||||
bc = bd;
|
||||
rc = regions[2];
|
||||
}
|
||||
if (cd < bc) {
|
||||
rb = regions[1];
|
||||
rc = regions[2];
|
||||
}
|
||||
if (rc.xMin < rb.xMin) {
|
||||
rb.xMin = rc.xMin;
|
||||
}
|
||||
if (rc.xMax > rb.xMax) {
|
||||
rb.xMax = rc.xMax;
|
||||
}
|
||||
if (rc.yMin < rb.yMin) {
|
||||
rb.yMin = rc.yMin;
|
||||
}
|
||||
if (rc.yMax > rb.yMax) {
|
||||
rb.yMax = rc.yMax;
|
||||
}
|
||||
rc.xMin = a.xMin;
|
||||
rc.xMax = a.xMax;
|
||||
rc.yMin = a.yMin;
|
||||
rc.yMax = a.yMax;
|
||||
};
|
||||
RegionCluster.prototype.retrieve = function () {
|
||||
return this.regions;
|
||||
};
|
||||
var EXTERNAL_INTERFACE_FEATURE = 1;
|
||||
var CLIPBOARD_FEATURE = 2;
|
||||
@ -1852,6 +2147,9 @@ function ShapePath(fillStyle, lineStyle, commandsCount, dataLength, isMorph, tra
|
||||
}
|
||||
}
|
||||
ShapePath.prototype = {
|
||||
get isEmpty() {
|
||||
return this.commands.length === 0;
|
||||
},
|
||||
moveTo: function (x, y) {
|
||||
if (this.commands[this.commands.length - 1] === SHAPE_MOVE_TO) {
|
||||
this.data[this.data.length - 2] = x;
|
||||
@ -2013,6 +2311,8 @@ ShapePath.prototype = {
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
}
|
||||
} else {
|
||||
ctx.fill();
|
||||
}
|
||||
ctx.closePath();
|
||||
},
|
||||
@ -2694,7 +2994,7 @@ function extendBoundsByY(bounds, y) {
|
||||
function morph(start, end, ratio) {
|
||||
return start + (end - start) * ratio;
|
||||
}
|
||||
function finishShapePath(path, dictionary) {
|
||||
function finishShapePath(path, dictionaryResolved) {
|
||||
if (path.fullyInitialized) {
|
||||
return path;
|
||||
}
|
||||
@ -2708,8 +3008,8 @@ function finishShapePath(path, dictionary) {
|
||||
}
|
||||
path.buffers = null;
|
||||
}
|
||||
path.fillStyle && initStyle(path.fillStyle, dictionary);
|
||||
path.lineStyle && initStyle(path.lineStyle, dictionary);
|
||||
path.fillStyle && initStyle(path.fillStyle, dictionaryResolved);
|
||||
path.lineStyle && initStyle(path.lineStyle, dictionaryResolved);
|
||||
path.fullyInitialized = true;
|
||||
return path;
|
||||
}
|
||||
@ -2769,7 +3069,7 @@ function buildBitmapPatternFactory(img, repeat) {
|
||||
fn.defaultFillStyle = defaultPattern;
|
||||
return fn;
|
||||
}
|
||||
function initStyle(style, dictionary) {
|
||||
function initStyle(style, dictionaryResolved) {
|
||||
if (style.type === undefined) {
|
||||
return;
|
||||
}
|
||||
@ -2801,9 +3101,9 @@ function initStyle(style, dictionary) {
|
||||
case GRAPHICS_FILL_CLIPPED_BITMAP:
|
||||
case GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP:
|
||||
case GRAPHICS_FILL_NONSMOOTHED_CLIPPED_BITMAP:
|
||||
var bitmap = dictionary[style.bitmapId];
|
||||
var bitmap = dictionaryResolved[style.bitmapId];
|
||||
var repeat = style.type === GRAPHICS_FILL_REPEATING_BITMAP || style.type === GRAPHICS_FILL_NONSMOOTHED_REPEATING_BITMAP;
|
||||
style.style = buildBitmapPatternFactory(bitmap.value.props.img, repeat ? 'repeat' : 'no-repeat');
|
||||
style.style = buildBitmapPatternFactory(bitmap.props.img, repeat ? 'repeat' : 'no-repeat');
|
||||
break;
|
||||
default:
|
||||
fail('invalid fill style', 'shape');
|
||||
@ -5746,7 +6046,7 @@ BodyParser.prototype = {
|
||||
var read = stream.pos;
|
||||
buffer.removeHead(read);
|
||||
this.totalRead += read;
|
||||
if (this.totalRead >= this.length && options.oncomplete) {
|
||||
if (options.oncomplete && swf.tags[swf.tags.length - 1].finalTag) {
|
||||
options.oncomplete(swf);
|
||||
}
|
||||
}
|
||||
@ -5853,6 +6153,7 @@ SWF.parse = function (buffer, options) {
|
||||
bytesTotal: bytes.length
|
||||
};
|
||||
pipe.push(bytes, progressInfo);
|
||||
pipe.close();
|
||||
};
|
||||
(function (global) {
|
||||
global['SWF']['parse'] = SWF.parse;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
0.7.806
|
||||
0.7.933
|
||||
|
@ -19,7 +19,6 @@ limitations under the License.
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<base href=""/>
|
||||
<title>Shumway viewer</title>
|
||||
|
||||
<style>
|
||||
body {
|
||||
@ -36,6 +35,7 @@ limitations under the License.
|
||||
position:fixed !important;
|
||||
left:0;top:0;bottom:0;right:0;
|
||||
overflow: hidden;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
#fallback {
|
||||
|
Loading…
Reference in New Issue
Block a user