diff --git a/AppKit/CoreAnimation/CPAnimationContext.j b/AppKit/CoreAnimation/CPAnimationContext.j index 8a0b25b2c..9e9d0d123 100644 --- a/AppKit/CoreAnimation/CPAnimationContext.j +++ b/AppKit/CoreAnimation/CPAnimationContext.j @@ -585,112 +585,3 @@ var _animationFlushingObserverCallback = function() _animationFlushingObserver = nil; } }; - -var FrameUpdater = function(anIdentifier) -{ - this._identifier = anIdentifier; - this._requestId = null; - this._duration = 0; - this._stop = false; - this._targets = []; - this._callbacks = []; - - var frameUpdater = this; - - this._updateFunction = function(timestamp) - { - if (frameUpdater._startDate == null) - frameUpdater._startDate = timestamp; - - if (frameUpdater._stop) - return; - - for (var i = 0; i < frameUpdater._callbacks.length; i++) - frameUpdater._callbacks[i](); - - if (timestamp - frameUpdater._startDate < frameUpdater._duration * 1000) - window.requestAnimationFrame(frameUpdater._updateFunction); - }; -}; - -FrameUpdater.prototype.start = function() -{ - this._requestId = window.requestAnimationFrame(this._updateFunction); -}; - -FrameUpdater.prototype.stop = function() -{ - // window.cancelAnimationFrame support is Chrome 24, Firefox 23, IE 10, Opera 15, Safari 6.1 - if (window.cancelAnimationFrame) - window.cancelAnimationFrame(this._requestId); - - this._stop = true; -}; - -FrameUpdater.prototype.updateFunction = function() -{ - return this._updateFunction; -}; - -FrameUpdater.prototype.identifier = function() -{ - return this._identifier; -}; - -FrameUpdater.prototype.addTarget = function(target, keyPath, duration) -{ - var callback = createUpdateFrame(target, keyPath); - - if (callback) - { - this._duration = MAX(this._duration, duration); - this._targets.push(target); - this._callbacks.push(callback); - } -}; - -var createUpdateFrame = function(aView, aKeyPath) -{ - if (aKeyPath !== "frame" && aKeyPath !== "frameSize" && aKeyPath !== "frameOrigin") - return nil; - - var style = getComputedStyle(aView._DOMElement), - getCSSPropertyValue = function(prop) { - return ROUND(parseFloat(style.getPropertyValue(prop))); - }, - initialOrigin = CGPointMakeCopy([aView frameOrigin]), - transformProperty = CPBrowserCSSProperty("transform"), - updateFrame = function(timestamp) - { - var width = getCSSPropertyValue("width"), - height = getCSSPropertyValue("height"); - - if (aKeyPath === "frameSize") - { - [aView setFrameSize:CGSizeMake(width, height)]; - } - else - { - [aView _setInhibitDOMUpdates:YES]; - - var matrix = style[transformProperty].split('(')[1].split(')')[0].split(','), - x = ROUND(initialOrigin.x + parseFloat(matrix[4])), - y = ROUND(initialOrigin.y + parseFloat(matrix[5])); - - if (aKeyPath === "frame") - { - [aView setFrame:CGRectMake(x, y, width, height)]; - } - else - { - [aView setFrameOrigin:CGPointMake(x, y)]; - } - - [aView _setInhibitDOMUpdates:NO]; - } - - [[CPRunLoop currentRunLoop] performSelectors]; - }; - - return updateFrame; -}; diff --git a/AppKit/CoreAnimation/CPViewAnimator.j b/AppKit/CoreAnimation/CPViewAnimator.j index e69846727..013a6cc4c 100644 --- a/AppKit/CoreAnimation/CPViewAnimator.j +++ b/AppKit/CoreAnimation/CPViewAnimator.j @@ -223,3 +223,123 @@ var DEFAULT_CSS_PROPERTIES = nil; } @end + +var FrameUpdater = function(anIdentifier) +{ + this._identifier = anIdentifier; + this._requestId = null; + this._duration = 0; + this._stop = false; + this._targets = []; + this._callbacks = []; + + var frameUpdater = this; + + this._updateFunction = function(timestamp) + { + if (frameUpdater._startDate == null) + frameUpdater._startDate = timestamp; + + if (frameUpdater._stop) + return; + + for (var i = 0; i < frameUpdater._callbacks.length; i++) + frameUpdater._callbacks[i](); + + if (timestamp - frameUpdater._startDate < frameUpdater._duration * 1000) + window.requestAnimationFrame(frameUpdater._updateFunction); + }; +}; + +FrameUpdater.prototype.start = function() +{ + this._requestId = window.requestAnimationFrame(this._updateFunction); +}; + +FrameUpdater.prototype.stop = function() +{ + CPLog.warn("STOP FrameUpdater" + this._identifier); + + // window.cancelAnimationFrame support is Chrome 24, Firefox 23, IE 10, Opera 15, Safari 6.1 + if (window.cancelAnimationFrame) + window.cancelAnimationFrame(this._requestId); + + this._stop = true; +}; + +FrameUpdater.prototype.updateFunction = function() +{ + return this._updateFunction; +}; + +FrameUpdater.prototype.identifier = function() +{ + return this._identifier; +}; + +FrameUpdater.prototype.description = function() +{ + return ""; +}; + +FrameUpdater.prototype.addTarget = function(target, keyPath, duration) +{ + var callback = createUpdateFrame(target, keyPath); + + if (callback) + { + this._duration = MAX(this._duration, duration); + this._targets.push(target); + this._callbacks.push(callback); + } +}; + +var createUpdateFrame = function(aView, aKeyPath) +{ + if (aKeyPath !== "frame" && aKeyPath !== "frameSize" && aKeyPath !== "frameOrigin") + return nil; + + var style = getComputedStyle([aView _DOMElement]), + getCSSPropertyValue = function(prop) { + return ROUND(parseFloat(style.getPropertyValue(prop))); + }, + initialOrigin = CGPointMakeCopy([aView frameOrigin]), + transformProperty = CPBrowserStyleProperty("transform"), + updateFrame = function(timestamp) + { + if (aKeyPath === "frameSize") + { + var width = getCSSPropertyValue("width"), + height = getCSSPropertyValue("height"); + + [aView setFrameSize:CGSizeMake(width, height)]; + } + else + { + [aView _setInhibitDOMUpdates:YES]; + + var matrix = style[transformProperty].split('(')[1].split(')')[0].split(','), + x = ROUND(initialOrigin.x + parseFloat(matrix[4])), + y = ROUND(initialOrigin.y + parseFloat(matrix[5])); + + if (aKeyPath === "frame") + { + var width = getCSSPropertyValue("width"), + height = getCSSPropertyValue("height"); + + [aView setFrame:CGRectMake(x, y, width, height)]; + } + else + { + [aView setFrameOrigin:CGPointMake(x, y)]; + } + + [aView _setInhibitDOMUpdates:NO]; + } + + [[CPRunLoop currentRunLoop] performSelectors]; + // CPLog.debug("update " + [aView debug_description]); + }; + + return updateFrame; +};