From f5742c91259f37aef0c84ff411b58187e65ffbad Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Fri, 29 Apr 2011 15:06:33 -0700 Subject: [PATCH] Bug 650339 - Add escape borders from touchEvents in Fennec. r=mbrubeck --- mobile/app/mobile.js | 2 ++ mobile/chrome/content/browser.js | 32 ++++++++++++++++++++++++++------ mobile/chrome/content/content.js | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/mobile/app/mobile.js b/mobile/app/mobile.js index bd4e098b272..63c23a64904 100644 --- a/mobile/app/mobile.js +++ b/mobile/app/mobile.js @@ -586,6 +586,8 @@ pref("image.mem.min_discard_timeout_ms", 20000); // enable touch events interfaces pref("dom.w3c_touch_events.enabled", true); +pref("dom.w3c_touch_events.safetyX", 0); // escape borders in units of 1/240" +pref("dom.w3c_touch_events.safetyY", 120); // escape borders in units of 1/240" #ifdef MOZ_SAFE_BROWSING // Safe browsing does nothing unless this pref is set diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index c4b9a50836b..98db185f612 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -1628,7 +1628,7 @@ const ContentTouchHandler = { // Use lightweight transactions so that old context menus and tap // highlights don't ever see the light of day. _messageId: 0, - contentCanCaptureMouse: false, + contentMightCaptureMouse: false, init: function init() { document.addEventListener("TapDown", this, true); @@ -1739,15 +1739,16 @@ const ContentTouchHandler = { } break; case "Browser:CaptureEvents": - this.contentCanCaptureMouse = true; + this.contentMightCaptureMouse = true; if (this.touchTimeout) { clearTimeout(this.touchTimeout); this.touchTimeout = null; } - Elements.browsers.customDragger.contentMouseCapture = aMessage.json.panning; + if (this.canCancelPan) + Elements.browsers.customDragger.contentMouseCapture = aMessage.json.panning; break; case "Browser:CanCaptureMouse:Return": - ContentTouchHandler.contentCanCaptureMouse = aMessage.json.contentCanCaptureMouse; + ContentTouchHandler.contentMightCaptureMouse = aMessage.json.contentMightCaptureMouse; break; } }, @@ -1784,6 +1785,24 @@ const ContentTouchHandler = { touchTimeout: null, + canCancelPan: false, + + updateCanCancel: function(aX, aY) { + let dpi = Browser.windowUtils.displayDPI; + + const kSafetyX = Services.prefs.getIntPref("dom.w3c_touch_events.safetyX") / 240 * dpi; + const kSafetyY = Services.prefs.getIntPref("dom.w3c_touch_events.safetyY") / 240 * dpi; + let browser = getBrowser(); + let bcr = browser.getBoundingClientRect(); + let rect = new Rect(0, 0, window.innerWidth, window.innerHeight); + rect.restrictTo(Rect.fromRect(bcr)); + + // Check if the user touched near to one of the edges of the browser area + // or if the urlbar is showing + this.canCancelPan = (aX >= rect.left + kSafetyX) && (aX <= rect.right - kSafetyX) && + (aY >= rect.top + kSafetyY) && bcr.top == 0; + }, + tapDown: function tapDown(aX, aY) { // Ensure that the content process has gets an activate event let browser = getBrowser(); @@ -1794,13 +1813,14 @@ const ContentTouchHandler = { } catch (e) {} // if the page might capture touch events, we give it the option - Elements.browsers.customDragger.contentMouseCapture = this.contentCanCaptureMouse; + this.updateCanCancel(aX, aY); + Elements.browsers.customDragger.contentMouseCapture = this.canCancelPan && this.contentMightCaptureMouse; if (this.touchTimeout) { clearTimeout(this.touchTimeout); this.touchTimeout = null; } - if (this.contentCanCaptureMouse) { + if (this.contentMightCaptureMouse) { this.touchTimeout = setTimeout(function() { Elements.browsers.customDragger.contentMouseCapture = false; }, kTouchTimeout) diff --git a/mobile/chrome/content/content.js b/mobile/chrome/content/content.js index 07910908019..5fec6e160e9 100644 --- a/mobile/chrome/content/content.js +++ b/mobile/chrome/content/content.js @@ -1223,7 +1223,7 @@ var TouchEventHandler = { switch (aMessage.name) { case "Browser:MouseDown": let cwu = Util.getWindowUtils(content); - this.element = cwu.elementFromPoint(json.x, json.y, false, false); + this.element = elementFromPoint(json.x, json.y); cancelled = !this.sendEvent("touchstart", json, this.element); break;