From 2e04af953463643791f6362bd8ef4c6ba190abfa Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 18 Apr 2012 13:48:51 -0700 Subject: Squashed commit of the following: commit 2054551bfb01a0f4ca2e138b9d724835462d45cd Merge: 765c2da 616a853 Author: Valerio Virgillito Date: Wed Apr 18 13:48:21 2012 -0700 Merge branch 'refs/heads/master' into integration commit 765c2da8e1aa03550caf42b2bd5f367555ad2843 Author: Valerio Virgillito Date: Tue Apr 17 15:29:41 2012 -0700 updating the picasa carousel Signed-off-by: Valerio Virgillito commit 9484f1c82b81e27edf2dc0a1bcc1fa3b12077406 Merge: d27f2df cacb4a2 Author: Valerio Virgillito Date: Tue Apr 17 15:03:50 2012 -0700 Merge branch 'refs/heads/master' into integration commit d27f2df4d846064444263d7832d213535962abe7 Author: Valerio Virgillito Date: Wed Apr 11 10:39:36 2012 -0700 integrating new picasa carousel component Signed-off-by: Valerio Virgillito commit 6f98384c9ecbc8abe55ccfe1fc25a0c7ce22c493 Author: Valerio Virgillito Date: Tue Apr 10 14:33:00 2012 -0700 fixed the text area case issue Text area was renamed from TextArea to Textarea Signed-off-by: Valerio Virgillito commit 1e83e26652266136802bc7af930379c1ecd631a6 Author: Valerio Virgillito Date: Mon Apr 9 22:10:45 2012 -0700 integrating montage v0.8 into ninja. Signed-off-by: Valerio Virgillito Signed-off-by: Valerio Virgillito --- .../montage/ui/composer/long-press-composer.js | 232 --------------------- node_modules/montage/ui/composer/press-composer.js | 126 +++++++++-- .../montage/ui/composer/translate-composer.js | 133 ++++++++---- 3 files changed, 201 insertions(+), 290 deletions(-) delete mode 100644 node_modules/montage/ui/composer/long-press-composer.js (limited to 'node_modules/montage/ui/composer') diff --git a/node_modules/montage/ui/composer/long-press-composer.js b/node_modules/montage/ui/composer/long-press-composer.js deleted file mode 100644 index 717bb42e..00000000 --- a/node_modules/montage/ui/composer/long-press-composer.js +++ /dev/null @@ -1,232 +0,0 @@ -/* - This file contains proprietary software owned by Motorola Mobility, Inc.
- No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
- (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ -/** - @module montage/ui/composer/long-press-composer - @requires montage - @requires montage/ui/composer/composer -*/ -var Montage = require("montage").Montage, - Composer = require("ui/composer/composer").Composer; -/** - @class module:montage/ui/composer/long-press-composer.LongPressComposer - @extends module:montage/ui/composer/composer.Composer -*/ -exports.LongPressComposer = Montage.create(Composer,/** @lends module:montage/ui/event/composer/long-press-composer.LongPressComposer# */ { - -/** - Description TODO - @private -*/ - _motionThreshold: { - value: 10 - }, -/** - Description TODO - @private -*/ - _longpressTimeOut: { - value: 1500 - }, - - _longPressTimer: { - value: null - }, - - _fingerId: { - value: null - }, - - _X: { - value: null - }, - - _Y: { - value: null - }, - - /** - Description TODO - @function - */ - load: { - value: function () { - if (window.Touch) { - this._element.addEventListener("touchstart", this); - this._element.addEventListener("touchmove", this); - this._element.addEventListener("touchend", this); - } else { - this._element.addEventListener("mousedown", this); - } - } - }, - /** - Description TODO - @function - */ - unload: { - value: function () { - if (window.Touch) { - this._element.removeEventListener("touchstart", this); - this._element.removeEventListener("touchmove", this); - this._element.removeEventListener("touchend", this); - } - else { - this._element.removeEventListener("mousedown", this); - } - } - }, -/** - Description TODO - @function - @param {Event} event This event. - */ - handleTouchstart: { - value: function (event) { - var self = this; - /* If two longpress on same target then the first one will be cleared*/ - if (this._longpressTimer) { - clearTimeout(this._longpressTimer); - this._longpressTimer = null; - } - this._fingerId = event.changedTouches[0].identifier; - this._X = event.changedTouches[0].clientX; - this._Y = event.changedTouches[0].clientY; - this._longpressTimer = null; - this._longpressTimer = setTimeout(function () { - // FIXME should be dispatched against something else - self._dispatchLongPress(self._element); - }, this._longpressTimeOut); - } - }, -/** - Description TODO - @function - @param {Event} event This event. - */ - handleTouchmove: { - value: function (event) { - var i, deltaX, deltaY, len; - /* the longpresstimer is checked so that the flushing of the timer occurs only once even though touchmoves are received */ - if (this._longpressTimer) { - len = event.changedTouches.length; - for (i = 0; i < len; i++) { - /*Checked if two fingers on same target and both are moved */ - if (this._fingerId === event.changedTouches[i].identifier) { - deltaX = Math.abs(event.changedTouches[i].clientX - this._X); - deltaY = Math.abs(event.changedTouches[i].clientY - this._Y); - /* Clearing timer only on some considerable motion */ - if (deltaX > this._motionThreshold || deltaY > this._motionThreshold) { - this._clearLongpress(event.currentTarget); - break; - } - } - } - } - } - }, - /** - Description TODO - @function - @param {Event} event This event. - */ - handleTouchend: { - value: function (event) { - var target = event.currentTarget; - /* longpresstimer checked because end occurs after its move then timer is already cleared. */ - if (this._longpressTimer && this._fingerId === event.changedTouches[0].identifier) { - this._clearLongpress(target); - } - } - }, -/** - Description TODO - @function - @param {Event} event This event. - */ - handleMousedown: { - value: function (event) { - var target = event.currentTarget; - var self = this; - target.addEventListener("mousemove", this); - target.addEventListener("mouseup", this); - target.addEventListener("mouseout", this); - this._fingerId = 0; - this._X = event.clientX; - this._Y = event.clientY; - this._longpressTimer = setTimeout(function () { - self._dispatchLongPress(target); - }, this._longpressTimeOut); - } - }, -/** - Description TODO - @function - @param {Event} event This event. - */ - handleMouseup: { - value: function (event) { - this._clearLongpress(event.currentTarget); - } - }, -/** - Description TODO - @function - @param {Event} event This event. - */ - handleMouseout: { - value: function (event) { - this._clearLongpress(event.currentTarget); - } - }, -/** - Description TODO - @function - @param {Event} event This event. - */ - handleMousemove: { - value: function (event) { - this._clearLongpress(event.currentTarget); - } - }, - /** - Description TODO - @private -*/ - _dispatchLongPress: { - value: function (target) { - longPressEvent = document.createEvent("CustomEvent"); - longPressEvent.clientX = this._X; - longPressEvent.clientY = this._Y; - longPressEvent.identifier = this._fingerId; - longPressEvent.initCustomEvent("longpress", true, true, null); - this.dispatchEvent(longPressEvent); - this._clearLongpress(target); - } - }, -/** - Description TODO - @private -*/ - _clearLongpress: { - value: function (target) { - if (this._longpressTimer) { - clearTimeout(this._longpressTimer); - this._longpressTimer = null; - this._X = null; - this._Y = null; - } - if (window.Touch) { - this._fingerId = null; - } else { - target.removeEventListener("mouseup", this); - target.removeEventListener("mousemove", this); - target.removeEventListener("mouseout", this); - } - } - } - - -}); diff --git a/node_modules/montage/ui/composer/press-composer.js b/node_modules/montage/ui/composer/press-composer.js index 4a6b99b2..680c301d 100644 --- a/node_modules/montage/ui/composer/press-composer.js +++ b/node_modules/montage/ui/composer/press-composer.js @@ -20,11 +20,11 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m /** @event - @name pressstart + @name pressStart @param {Event} event Dispatched when a press begins. It is ended by either a {@link press} or - {@link presscancel} event. + {@link pressCancel} event. */ /** @@ -37,7 +37,15 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m /** @event - @name presscancel + @name longPress + @param {Event} event + + Dispatched when a press lasts for longer than (@link longPressTimeout} + */ + + /** + @event + @name pressCancel @param {Event} event Dispatched when a press is canceled. This could be because the pointer @@ -67,6 +75,35 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m } }, + /** + Cancel the current press. + + Can be used in a "longPress" event handler to prevent the "press" event + being fired. + @returns Boolean true if a press was canceled, false if the composer was + already in a unpressed or canceled state. + */ + cancelPress: { + value: function() { + if (this._state === PressComposer.PRESSED) { + this._dispatchPressCancel(); + this._endInteraction(); + return true; + } + return false; + } + }, + + // Optimisation so that we don't set a timeout if we do not need to + addEventListener: { + value: function(type, listener, useCapture) { + Composer.addEventListener.call(this, type, listener, useCapture); + if (type === "longPress") { + this._shouldDispatchLongPress = true; + } + } + }, + UNPRESSED: { value: 0 }, @@ -87,6 +124,34 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m } }, + _shouldDispatchLongPress: { + enumerable: false, + value: false + }, + + _longPressTimeout: { + enumerable: false, + value: 1000 + }, + /** + How long a press has to last for a longPress event to be dispatched + */ + longPressTimeout: { + get: function() { + return this._longPressTimeout; + }, + set: function(value) { + if (this._longPressTimeout !== value) { + this._longPressTimeout = value; + } + } + }, + + _longPressTimer: { + enumberable: false, + value: null + }, + // Magic /** @@ -140,7 +205,7 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m this.component.eventManager.claimPointer(this._observedPointer, this); - this._dispatchPressstart(event); + this._dispatchPressStart(event); } }, @@ -165,12 +230,12 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m while (target !== this._element && target && target.parentNode) { target = target.parentNode; } - isTarget = target === this.component.element; + isTarget = target === this._element; if (isSurrendered && event.type === "click") { // Pointer surrendered, so prevent the default action event.preventDefault(); - // No need to dispatch an event as presscancel was dispatched + // No need to dispatch an event as pressCancel was dispatched // in surrenderPointer, just end the interaction. this._endInteraction(event); return; @@ -183,7 +248,7 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m } if (!isSurrendered && !isTarget && event.type === "mouseup") { - this._dispatchPresscancel(event); + this._dispatchPressCancel(event); this._endInteraction(event); return; } @@ -247,7 +312,7 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m return false; } - this._dispatchPresscancel(); + this._dispatchPressCancel(); return true; } }, @@ -280,7 +345,7 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m value: function(event) { if (this._observedPointer === null || this._changedTouchisObserved(event.changedTouches) !== false) { if (this.component.eventManager.isPointerClaimedByComponent(this._observedPointer, this)) { - this._dispatchPresscancel(event); + this._dispatchPressCancel(event); } this._endInteraction(event); } @@ -331,14 +396,21 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m }, /** - Dispatch the pressstart event + Dispatch the pressStart event @private */ - _dispatchPressstart: { + _dispatchPressStart: { enumerable: false, value: function (event) { this._state = PressComposer.PRESSED; - this.dispatchEvent(this._createPressEvent("pressstart", event)); + this.dispatchEvent(this._createPressEvent("pressStart", event)); + + if (this._shouldDispatchLongPress) { + var self = this; + this._longPressTimer = setTimeout(function () { + self._dispatchLongPress(); + }, this._longPressTimeout); + } } }, @@ -349,20 +421,44 @@ var PressComposer = exports.PressComposer = Montage.create(Composer,/** @lends m _dispatchPress: { enumerable: false, value: function (event) { + if (this._shouldDispatchLongPress) { + clearTimeout(this._longPressTimer); + this._longPressTimer = null; + } + this.dispatchEvent(this._createPressEvent("press", event)); this._state = PressComposer.UNPRESSED; } }, /** - Dispatch the presscancel event + Dispatch the long press event + @private + */ + _dispatchLongPress: { + enumerable: false, + value: function (event) { + if (this._shouldDispatchLongPress) { + this.dispatchEvent(this._createPressEvent("longPress", event)); + this._longPressTimer = null; + } + } + }, + + /** + Dispatch the pressCancel event @private */ - _dispatchPresscancel: { + _dispatchPressCancel: { enumerable: false, value: function (event) { + if (this._shouldDispatchLongPress) { + clearTimeout(this._longPressTimer); + this._longPressTimer = null; + } + this._state = PressComposer.CANCELLED; - this.dispatchEvent(this._createPressEvent("presscancel", event)); + this.dispatchEvent(this._createPressEvent("pressCancel", event)); } } diff --git a/node_modules/montage/ui/composer/translate-composer.js b/node_modules/montage/ui/composer/translate-composer.js index 4ce165dc..6e762af9 100644 --- a/node_modules/montage/ui/composer/translate-composer.js +++ b/node_modules/montage/ui/composer/translate-composer.js @@ -4,7 +4,7 @@ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ /** - @module montage/ui/composer/long-press-composer + @module montage/ui/composer/translate-composer @requires montage @requires montage/ui/composer/composer */ @@ -66,6 +66,11 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** value: null }, + _shouldDispatchTranslate: { + value: false, + enumerable: false + }, + _isSelfUpdate: { enumerable: false, value: false @@ -203,7 +208,19 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** } }, - invertAxis: {value: null}, + _invertAxis: { + value: false, + enumerable: false + }, + + invertAxis: { + get: function() { + return this._invertAxis; + }, + set: function(value) { + this._invertAxis=value?true:false; + } + }, _hasMomentum: { enumerable: false, @@ -233,33 +250,34 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** } }, - _momentumDuration: { + __momentumDuration: { enumerable: false, value: 650 }, - momentumDuration: { + _momentumDuration: { get: function () { - return this._momentumDuration; + return this.__momentumDuration; }, set: function (value) { - this._momentumDuration=isNaN(value)?1:value>>0; - if (this._momentumDuration<1) this._momentumDuration=1; - } + this.__momentumDuration=isNaN(value)?1:value>>0; + if (this.__momentumDuration<1) this.__momentumDuration=1; + }, + enumerable: false }, - _bouncingDuration: { + __bouncingDuration: { enumerable: false, value: 750 }, - bouncingDuration: { + _bouncingDuration: { get: function () { - return this._bouncingDuration; + return this.__bouncingDuration; }, set: function (value) { - this._bouncingDuration=isNaN(value)?1:value>>0; - if (this._bouncingDuration<1) this._bouncingDuration=1; + this.__bouncingDuration=isNaN(value)?1:value>>0; + if (this.__bouncingDuration<1) this.__bouncingDuration=1; } }, @@ -538,38 +556,44 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** value: function (event) { var self = this; + var oldTranslateY = this._translateY; this.translateY = this._translateY - (event.wheelDeltaY * 20) / 120; this._dispatchTranslateStart(); window.clearTimeout(this._translateEndTimeout); this._translateEndTimeout = window.setTimeout(function () { self._dispatchTranslateEnd(); }, 400); - event.preventDefault(); + + // If we're not at one of the extremes (i.e. the scroll actully + // changed the translate) then we want to preventDefault to stop + // the page scrolling. + if (oldTranslateY !== this._translateY) { + event.preventDefault(); + } } }, _move: { enumerable: false, value: function (x, y) { - + var pointerDelta; this._isSelfUpdate=true; - var delta; if (this._axis!="vertical") { - var delta = this.invertAxis ? (x-this._pointerX) : (this._pointerX-x); + pointerDelta = this._invertAxis ? (this._pointerX-x) : (x-this._pointerX); if ((this._translateX<0)||(this._translateX>this._maxTranslateX)) { - this.translateX+=(delta/2)*this._pointerSpeedMultiplier; + this.translateX+=((pointerDelta)/2)*this._pointerSpeedMultiplier; } else { - this.translateX+=(delta)*this._pointerSpeedMultiplier; + this.translateX+=(pointerDelta)*this._pointerSpeedMultiplier; } } if (this._axis!="horizontal") { + pointerDelta = this._invertAxis ? (this._pointerY-y) : (y-this._pointerY); if ((this._translateY<0)||(this._translateY>this._maxTranslateY)) { - this.translateY+=((this._pointerY-y)/2)*this._pointerSpeedMultiplier; + this.translateY+=((pointerDelta)/2)*this._pointerSpeedMultiplier; } else { - this.translateY+=(this._pointerY-y)*this._pointerSpeedMultiplier; + this.translateY+=(pointerDelta)*this._pointerSpeedMultiplier; } } - this._isSelfUpdate=false; this._pointerX=x; this._pointerY=y; @@ -577,6 +601,9 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** this._dispatchTranslateStart(); this._isFirstMove = false; } + if (this._shouldDispatchTranslate) { + this._dispatchTranslate(); + } } }, @@ -627,6 +654,17 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** } }, + _dispatchTranslate: { + enumerable: false, + value: function() { + var translateEvent = document.createEvent("CustomEvent"); + translateEvent.initCustomEvent("translate", true, true, null); + translateEvent.translateX = this._translateX; + translateEvent.translateY = this._translateY; + this.dispatchEvent(translateEvent); + } + }, + _end: { enumerable: false, @@ -662,8 +700,8 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** } else { momentumY=0; } - endX=startX-(momentumX*this._momentumDuration/2000); - endY=startY-(momentumY*this._momentumDuration/2000); + endX=startX-(momentumX*this.__momentumDuration/2000); + endY=startY-(momentumY*this.__momentumDuration/2000); animateMomentum=true; } @@ -672,9 +710,9 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** if (animateMomentum) { t=time-startTime; - if (tself._bouncingDuration) { - t=self._bouncingDuration; + if ((tself.__bouncingDuration) { + t=self.__bouncingDuration; } - tmpX=tmpX*(1-self._bezierTValue(t/self._bouncingDuration, .17, .93, .19, 1)); + tmpX=tmpX*(1-self._bezierTValue(t/self.__bouncingDuration, .17, .93, .19, 1)); } else { tmpX=0; animateBouncingX=false; @@ -712,11 +750,11 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** startTimeBounceY=time; } t=time-startTimeBounceY; - if ((tself._bouncingDuration) { - t=self._bouncingDuration; + if ((tself.__bouncingDuration) { + t=self.__bouncingDuration; } - tmpY=tmpY*(1-self._bezierTValue(t/self._bouncingDuration, .17, .93, .19, 1)); + tmpY=tmpY*(1-self._bezierTValue(t/self.__bouncingDuration, .17, .93, .19, 1)); } else { tmpY=0; animateBouncingY=false; @@ -733,11 +771,11 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** startTimeBounceX=time; } t=time-startTimeBounceX; - if ((tself._bouncingDuration) { - t=self._bouncingDuration; + if ((tself.__bouncingDuration) { + t=self.__bouncingDuration; } - tmpX=self._maxTranslateX+(tmpX-self._maxTranslateX)*(1-self._bezierTValue(t/self._bouncingDuration, .17, .93, .19, 1)); + tmpX=self._maxTranslateX+(tmpX-self._maxTranslateX)*(1-self._bezierTValue(t/self.__bouncingDuration, .17, .93, .19, 1)); } else { tmpX=self._maxTranslateX; animateBouncingX=false; @@ -754,11 +792,11 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** startTimeBounceY=time; } t=time-startTimeBounceY; - if ((tself._bouncingDuration) { - t=self._bouncingDuration; + if ((tself.__bouncingDuration) { + t=self.__bouncingDuration; } - tmpY=self._maxTranslateY+(tmpY-self._maxTranslateY)*(1-self._bezierTValue(t/self._bouncingDuration, .17, .93, .19, 1)); + tmpY=self._maxTranslateY+(tmpY-self._maxTranslateY)*(1-self._bezierTValue(t/self.__bouncingDuration, .17, .93, .19, 1)); } else { tmpY=self._maxTranslateY; animateBouncingY=false; @@ -809,6 +847,15 @@ var TranslateComposer = exports.TranslateComposer = Montage.create(Composer,/** this.eventManager.isStoringPointerEvents = true; } + }, + + addEventListener: { + value: function(type, listener, useCapture) { + Composer.addEventListener.call(this, type, listener, useCapture); + if (type === "translate") { + this._shouldDispatchTranslate = true; + } + } } }); -- cgit v1.2.3