GitHub PullRequestReviewCommentEvent at 2014-03-12 16:19:32
Repository: ol3
Actor: twpayne
Payload: {"comment":{"url":"https://api.github.com/repos/openlayers/ol3/pulls/comments/10525590","id":10525590,"diff_hunk":"@@ -0,0 +1,448 @@\n+// Based on https://github.com/Polymer/PointerEvents\n+\n+// Copyright (c) 2013 The Polymer Authors. All rights reserved.\n+//\n+// Redistribution and use in source and binary forms, with or without\n+// modification, are permitted provided that the following conditions are\n+// met:\n+//\n+// * Redistributions of source code must retain the above copyright\n+// notice, this list of conditions and the following disclaimer.\n+// * Redistributions in binary form must reproduce the above\n+// copyright notice, this list of conditions and the following disclaimer\n+// in the documentation and/or other materials provided with the\n+// distribution.\n+// * Neither the name of Google Inc. nor the names of its\n+// contributors may be used to endorse or promote products derived from\n+// this software without specific prior written permission.\n+//\n+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+\n+goog.provide('ol.pointer.TouchSource');\n+\n+goog.require('goog.array');\n+goog.require('goog.math.Coordinate');\n+goog.require('ol.pointer.EventSource');\n+\n+\n+\n+/**\n+ * @constructor\n+ * @param {ol.pointer.PointerEventHandler} dispatcher\n+ * @param {ol.pointer.MouseSource} mouseSource\n+ * @extends {ol.pointer.EventSource}\n+ */\n+ol.pointer.TouchSource = function(dispatcher, mouseSource) {\n+  var mapping = {\n+    'touchstart': this.touchstart,\n+    'touchmove': this.touchmove,\n+    'touchend': this.touchend,\n+    'touchcancel': this.touchcancel\n+  };\n+  goog.base(this, dispatcher, mapping);\n+\n+  /**\n+   * @const\n+   * @type {goog.structs.Map}\n+   */\n+  this.pointerMap = dispatcher.pointerMap;\n+\n+  /**\n+   * @const\n+   * @type {ol.pointer.MouseSource}\n+   */\n+  this.mouseSource = mouseSource;\n+\n+  /**\n+   * @private\n+   * @type {number|undefined}\n+   */\n+  this.firstTouchId_ = undefined;\n+\n+  /**\n+   * @private\n+   * @type {number}\n+   */\n+  this.clickCount_ = 0;\n+\n+  /**\n+   * @private\n+   * @type {number|undefined}\n+   */\n+  this.resetId_ = undefined;\n+};\n+goog.inherits(ol.pointer.TouchSource, ol.pointer.EventSource);\n+\n+\n+/**\n+ * Mouse event timeout: This should be long enough to\n+ * ignore compat mouse events made by touch.\n+ * @const\n+ * @type {number}\n+ */\n+ol.pointer.TouchSource.DEDUP_TIMEOUT = 2500;\n+\n+\n+/**\n+ * @const\n+ * @type {number}\n+ */\n+ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT = 200;\n+\n+\n+/**\n+ * @const\n+ * @type {string}\n+ */\n+ol.pointer.TouchSource.POINTER_TYPE = 'touch';\n+\n+\n+/**\n+ * @private\n+ * @param {Touch} inTouch\n+ * @return {boolean} True, if this is the primary touch.\n+ */\n+ol.pointer.TouchSource.prototype.isPrimaryTouch_ = function(inTouch) {\n+  return this.firstTouchId_ === inTouch.identifier;\n+};\n+\n+\n+/**\n+ * Set primary touch if there are no pointers, or the only pointer is the mouse.\n+ * @param {Touch} inTouch\n+ * @private\n+ */\n+ol.pointer.TouchSource.prototype.setPrimaryTouch_ = function(inTouch) {\n+  if (this.pointerMap.getCount() === 0 ||\n+      (this.pointerMap.getCount() === 1 && this.pointerMap.containsKey(1))) {\n+    this.firstTouchId_ = inTouch.identifier;\n+    this.cancelResetClickCount_();\n+  }\n+};\n+\n+\n+/**\n+ * @private\n+ * @param {Object} inPointer\n+ */\n+ol.pointer.TouchSource.prototype.removePrimaryPointer_ = function(inPointer) {\n+  if (inPointer.isPrimary) {\n+    this.firstTouchId_ = undefined;\n+    this.resetClickCount_();\n+  }\n+};\n+\n+\n+/**\n+ * @private\n+ */\n+ol.pointer.TouchSource.prototype.resetClickCount_ = function() {\n+  var fn = function() {\n+    this.clickCount_ = 0;\n+    this.resetId_ = undefined;\n+  };\n+  this.resetId_ = goog.global.setTimeout(goog.bind(fn, this),\n+      ol.pointer.TouchSource.CLICK_COUNT_TIMEOUT);","path":"src/ol/pointer/touchsource.js","position":155,"original_position":155,"commit_id":"f4866a93025e7c9763f64aca20d21842beb07e1e","original_commit_id":"f4866a93025e7c9763f64aca20d21842beb07e1e","user":{"login":"twpayne","id":6942,"avatar_url":"https://gravatar.com/avatar/223139cd460f00528796f94dc2415633?d=https%3A%2F%2Fidenticons.github.com%2Fc236337b043acf93c7df397fdb9082b3.png&r=x","gravatar_id":"223139cd460f00528796f94dc2415633","url":"https://api.github.com/users/twpayne","html_url":"https://github.com/twpayne","followers_url":"https://api.github.com/users/twpayne/followers","following_url":"https://api.github.com/users/twpayne/following{/other_user}","gists_url":"https://api.github.com/users/twpayne/gists{/gist_id}","starred_url":"https://api.github.com/users/twpayne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twpayne/subscriptions","organizations_url":"https://api.github.com/users/twpayne/orgs","repos_url":"https://api.github.com/users/twpayne/repos","events_url":"https://api.github.com/users/twpayne/events{/privacy}","received_events_url":"https://api.github.com/users/twpayne/received_events","type":"User","site_admin":false},"body":"`fn` and `goog.bind(fn, this)` can be created once in the constructor, stored in a private member variable, and re-used.","created_at":"2014-03-12T16:19:32Z","updated_at":"2014-03-12T16:19:32Z","html_url":"https://github.com/openlayers/ol3/pull/1840#discussion_r10525590","pull_request_url":"https://api.github.com/repos/openlayers/ol3/pulls/1840","_links":{"self":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/comments/10525590"},"html":{"href":"https://github.com/openlayers/ol3/pull/1840#discussion_r10525590"},"pull_request":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/1840"}}}}