Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #25225 from staktrace/vhome
Browse files Browse the repository at this point in the history
Bug 1083818 - Don't reimplement click handling in gaia when gecko can do it just fine. r=kgrandon
  • Loading branch information
KevinGrandon committed Dec 16, 2014
2 parents 009cf66 + f6fd77f commit 0a48c64
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 119 deletions.
40 changes: 0 additions & 40 deletions apps/sharedtest/test/unit/elements/gaia_grid/grid_view_test.js

This file was deleted.

82 changes: 3 additions & 79 deletions shared/elements/gaia_grid/js/grid_view.js
Expand Up @@ -4,33 +4,18 @@
/* global GridLayout */
/* global GridZoom */
/* global LazyLoader */
/* global performance */

(function(exports) {

// This constant is the delay between the last scroll event and the moment we
// listen to touchstart events again.
const PREVENT_TAP_TIMEOUT = 300;

// If the delta move from touchstart to touchend is greater than this, we'll
// ignore the touchend event to launch an app.
// "20" comes from Gecko, and we also try to have a greater value for devices
// with more pixels.
var SCROLL_THRESHOLD = 20 * window.devicePixelRatio;

/**
* GridView is a generic class to render and display a grid of items.
* @param {Object} config Configuration object containing:
* - element: The shadow root of the grid
*/
function GridView(config) {
this.config = config;
this.onTouchStart = this.onTouchStart.bind(this);
this.onTouchEnd = this.onTouchEnd.bind(this);
this.onScroll = this.onScroll.bind(this);
this.onContextMenu = this.onContextMenu.bind(this);
this.clickIcon = this.clickIcon.bind(this);
this.onVisibilityChange = this.onVisibilityChange.bind(this);
this.lastScrollTime = 0;

if (config.features.zoom) {
this.zoom = new GridZoom(this);
Expand Down Expand Up @@ -169,74 +154,13 @@
},

start: function() {
this.element.addEventListener('touchstart', this.onTouchStart);
this.element.addEventListener('touchend', this.onTouchEnd);
this.element.addEventListener('contextmenu', this.onContextMenu);
window.addEventListener('scroll', this.onScroll, true);
this.element.addEventListener('click', this.clickIcon);
window.addEventListener('visibilitychange', this.onVisibilityChange);
this.lastTouchStart = null;
},

stop: function() {
this.element.removeEventListener('touchstart', this.onTouchStart);
this.element.removeEventListener('touchend', this.onTouchEnd);
this.element.removeEventListener('contextmenu', this.onContextMenu);
window.removeEventListener('scroll', this.onScroll, true);
this.element.removeEventListener('click', this.clickIcon);
window.removeEventListener('visibilitychange', this.onVisibilityChange);
this.lastTouchStart = null;
},

onContextMenu: function(e) {
setTimeout(function() {
if (e.defaultPrevented) {
this.lastTouchStart = null;
}
}.bind(this));
},

// bug 1015000
onScroll: function() {
this.lastScrollTime = performance.now();
},

onTouchStart: function(e) {
// we track the last touchstart
this.lastTouchStart = e.changedTouches[0];
},

// click = last touchstart, then touchend for same finger happening not too
// far
// Gecko does that automatically but since we want to use touch events for
// more responsiveness, we also need to replicate that behavior.
onTouchEnd: function(e) {
var lastScrollTime = this.lastScrollTime;
this.lastScrollTime = 0;
var diff = performance.now() - lastScrollTime;
if (diff > 0 && diff < PREVENT_TAP_TIMEOUT) {
return;
}

var lastTouchStart = this.lastTouchStart;

if (!lastTouchStart) {
// This variable is deleted once a contextmenu event is received
return;
}

var touch = e.changedTouches.identifiedTouch(lastTouchStart.identifier);
if (!touch) {
return;
}

var deltaX = lastTouchStart.clientX - touch.clientX;
var deltaY = lastTouchStart.clientY - touch.clientY;

this.lastTouchStart = null;

var move = Math.hypot(deltaX, deltaY);
if (move < SCROLL_THRESHOLD) {
this.clickIcon(e);
}
},

findItemFromElement: function(element) {
Expand Down

0 comments on commit 0a48c64

Please sign in to comment.