2012-12-26 10:24:43 -08:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 sts=2 et: */
|
|
|
|
|
2012-02-01 16:46:50 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-02-07 21:10:01 -08:00
|
|
|
"use strict";
|
|
|
|
dump("############################### browserElementPanning.js loaded\n");
|
|
|
|
|
|
|
|
let { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Geometry.jsm");
|
|
|
|
|
2013-02-27 13:48:32 -08:00
|
|
|
var global = this;
|
|
|
|
|
2012-02-01 16:46:50 -08:00
|
|
|
const ContentPanning = {
|
2013-01-05 06:53:16 -08:00
|
|
|
// Are we listening to touch or mouse events?
|
|
|
|
watchedEventsType: '',
|
|
|
|
|
|
|
|
// Are mouse events being delivered to this content along with touch
|
|
|
|
// events, in violation of spec?
|
|
|
|
hybridEvents: false,
|
|
|
|
|
2012-02-01 16:46:50 -08:00
|
|
|
init: function cp_init() {
|
2013-01-05 06:53:16 -08:00
|
|
|
var events;
|
|
|
|
try {
|
|
|
|
content.document.createEvent('TouchEvent');
|
|
|
|
events = ['touchstart', 'touchend', 'touchmove'];
|
|
|
|
this.watchedEventsType = 'touch';
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// The gonk widget backend does not deliver mouse events per
|
|
|
|
// spec. Third-party content isn't exposed to this behavior,
|
|
|
|
// but that behavior creates some extra work for us here.
|
|
|
|
let appInfo = Cc["@mozilla.org/xre/app-info;1"];
|
|
|
|
let isParentProcess =
|
|
|
|
!appInfo || appInfo.getService(Ci.nsIXULRuntime)
|
|
|
|
.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
|
|
this.hybridEvents = isParentProcess;
|
|
|
|
#endif
|
|
|
|
} catch(e) {
|
|
|
|
// Touch events aren't supported, so fall back on mouse.
|
|
|
|
events = ['mousedown', 'mouseup', 'mousemove'];
|
|
|
|
this.watchedEventsType = 'mouse';
|
|
|
|
}
|
2013-02-27 13:48:32 -08:00
|
|
|
|
2013-07-30 11:03:42 -07:00
|
|
|
// If we are using an AsyncPanZoomController for the parent frame,
|
|
|
|
// it will handle subframe scrolling too. We don't need to listen for
|
|
|
|
// these events.
|
2013-10-30 14:06:15 -07:00
|
|
|
if (!docShell.asyncPanZoomEnabled) {
|
2013-10-11 11:41:22 -07:00
|
|
|
let els = Cc["@mozilla.org/eventlistenerservice;1"]
|
|
|
|
.getService(Ci.nsIEventListenerService);
|
|
|
|
|
2013-07-30 11:03:42 -07:00
|
|
|
events.forEach(function(type) {
|
|
|
|
// Using the system group for mouse/touch events to avoid
|
|
|
|
// missing events if .stopPropagation() has been called.
|
|
|
|
els.addSystemEventListener(global, type,
|
|
|
|
this.handleEvent.bind(this),
|
|
|
|
/* useCapture = */ false);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
2012-07-19 23:48:27 -07:00
|
|
|
|
|
|
|
addMessageListener("Viewport:Change", this._recvViewportChange.bind(this));
|
2012-08-08 21:39:02 -07:00
|
|
|
addMessageListener("Gesture:DoubleTap", this._recvDoubleTap.bind(this));
|
2013-11-22 04:45:05 -08:00
|
|
|
addEventListener("visibilitychange", this._handleVisibilityChange.bind(this));
|
2013-10-19 03:30:33 -07:00
|
|
|
Services.obs.addObserver(this, "BEC:ShownModalPrompt", false);
|
2013-11-22 04:45:05 -08:00
|
|
|
Services.obs.addObserver(this, "Activity:Success", false);
|
|
|
|
Services.obs.addObserver(this, "Activity:Error", false);
|
2012-02-01 16:46:50 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function cp_handleEvent(evt) {
|
2013-05-14 05:30:37 -07:00
|
|
|
if (evt.defaultPrevented || evt.multipleActionsPrevented) {
|
|
|
|
// clean up panning state even if touchend/mouseup has been preventDefault.
|
|
|
|
if(evt.type === 'touchend' || evt.type === 'mouseup') {
|
|
|
|
if (this.dragging &&
|
|
|
|
(this.watchedEventsType === 'mouse' ||
|
|
|
|
this.findPrimaryPointer(evt.changedTouches))) {
|
|
|
|
this._finishPanning();
|
|
|
|
}
|
|
|
|
}
|
2013-01-05 06:53:16 -08:00
|
|
|
return;
|
2013-05-14 05:30:37 -07:00
|
|
|
}
|
2013-01-05 06:53:16 -08:00
|
|
|
|
2013-10-17 00:18:13 -07:00
|
|
|
let start = Date.now();
|
|
|
|
let thread = Services.tm.currentThread;
|
|
|
|
while (this._delayEvents && (Date.now() - start) < this._activeDurationMs) {
|
|
|
|
thread.processNextEvent(true);
|
|
|
|
}
|
|
|
|
this._delayEvents = false;
|
|
|
|
|
2012-02-01 16:46:50 -08:00
|
|
|
switch (evt.type) {
|
|
|
|
case 'mousedown':
|
2013-01-05 06:53:16 -08:00
|
|
|
case 'touchstart':
|
2012-02-01 16:46:50 -08:00
|
|
|
this.onTouchStart(evt);
|
|
|
|
break;
|
|
|
|
case 'mousemove':
|
2013-01-05 06:53:16 -08:00
|
|
|
case 'touchmove':
|
2012-02-01 16:46:50 -08:00
|
|
|
this.onTouchMove(evt);
|
|
|
|
break;
|
|
|
|
case 'mouseup':
|
2013-01-05 06:53:16 -08:00
|
|
|
case 'touchend':
|
2012-02-01 16:46:50 -08:00
|
|
|
this.onTouchEnd(evt);
|
|
|
|
break;
|
|
|
|
case 'click':
|
|
|
|
evt.stopPropagation();
|
|
|
|
evt.preventDefault();
|
2012-11-28 01:18:12 -08:00
|
|
|
|
2012-03-05 00:55:51 -08:00
|
|
|
let target = evt.target;
|
2012-03-05 00:55:51 -08:00
|
|
|
let view = target.ownerDocument ? target.ownerDocument.defaultView
|
|
|
|
: target;
|
2012-08-26 23:27:41 -07:00
|
|
|
view.removeEventListener('click', this, true, true);
|
2012-02-01 16:46:50 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-19 03:30:33 -07:00
|
|
|
observe: function cp_observe(subject, topic, data) {
|
2013-11-26 09:30:12 -08:00
|
|
|
this._resetHover();
|
2013-10-19 03:30:33 -07:00
|
|
|
},
|
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
position: new Point(0 , 0),
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
findPrimaryPointer: function cp_findPrimaryPointer(touches) {
|
|
|
|
if (!('primaryPointerId' in this))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
for (let i = 0; i < touches.length; i++) {
|
|
|
|
if (touches[i].identifier === this.primaryPointerId) {
|
|
|
|
return touches[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2012-02-01 16:46:50 -08:00
|
|
|
onTouchStart: function cp_onTouchStart(evt) {
|
2013-01-05 06:53:16 -08:00
|
|
|
let screenX, screenY;
|
|
|
|
if (this.watchedEventsType == 'touch') {
|
|
|
|
if ('primaryPointerId' in this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let firstTouch = evt.changedTouches[0];
|
|
|
|
this.primaryPointerId = firstTouch.identifier;
|
|
|
|
this.pointerDownTarget = firstTouch.target;
|
|
|
|
screenX = firstTouch.screenX;
|
|
|
|
screenY = firstTouch.screenY;
|
|
|
|
} else {
|
|
|
|
this.pointerDownTarget = evt.target;
|
|
|
|
screenX = evt.screenX;
|
|
|
|
screenY = evt.screenY;
|
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
this.dragging = true;
|
2012-03-05 00:55:51 -08:00
|
|
|
this.panning = false;
|
2012-02-17 13:37:53 -08:00
|
|
|
|
2012-03-05 00:55:51 -08:00
|
|
|
let oldTarget = this.target;
|
2013-01-05 06:53:16 -08:00
|
|
|
[this.target, this.scrollCallback] = this.getPannable(this.pointerDownTarget);
|
2012-03-05 00:55:51 -08:00
|
|
|
|
2013-10-30 14:06:15 -07:00
|
|
|
// If we have a pointer down target, we may need to fill in for EventStateManager
|
|
|
|
// in setting the active state on the target element. Set a timer to
|
2013-01-05 06:53:16 -08:00
|
|
|
// ensure the pointer-down target is active. (If it's already
|
|
|
|
// active, the timer is a no-op.)
|
2013-10-30 14:06:15 -07:00
|
|
|
if (this.pointerDownTarget !== null) {
|
2013-01-05 06:53:16 -08:00
|
|
|
// If there's no possibility this is a drag/pan, activate now.
|
|
|
|
// Otherwise wait a little bit to see if the gesture isn't a
|
|
|
|
// tap.
|
|
|
|
if (this.target === null) {
|
|
|
|
this.notify(this._activationTimer);
|
|
|
|
} else {
|
|
|
|
this._activationTimer.initWithCallback(this,
|
|
|
|
this._activationDelayMs,
|
|
|
|
Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
}
|
2012-08-08 13:38:06 -07:00
|
|
|
}
|
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
// If there is a pan animation running (from a previous pan gesture) and
|
|
|
|
// the user touch back the screen, stop this animation immediatly and
|
2012-03-05 00:55:51 -08:00
|
|
|
// prevent the possible click action if the touch happens on the same
|
|
|
|
// target.
|
|
|
|
this.preventNextClick = false;
|
2012-02-17 13:37:53 -08:00
|
|
|
if (KineticPanning.active) {
|
|
|
|
KineticPanning.stop();
|
2012-03-05 00:55:51 -08:00
|
|
|
|
|
|
|
if (oldTarget && oldTarget == this.target)
|
|
|
|
this.preventNextClick = true;
|
2012-02-17 13:37:53 -08:00
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
this.position.set(screenX, screenY);
|
2012-02-17 13:37:53 -08:00
|
|
|
KineticPanning.record(new Point(0, 0), evt.timeStamp);
|
2013-09-04 05:29:46 -07:00
|
|
|
|
|
|
|
// We prevent start events to avoid sending a focus event at the end of this
|
|
|
|
// touch series. See bug 889717.
|
|
|
|
if (this.panning || this.preventNextClick) {
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
onTouchEnd: function cp_onTouchEnd(evt) {
|
2013-01-05 06:53:16 -08:00
|
|
|
let touch = null;
|
|
|
|
if (!this.dragging ||
|
|
|
|
(this.watchedEventsType == 'touch' &&
|
|
|
|
!(touch = this.findPrimaryPointer(evt.changedTouches)))) {
|
2012-02-01 16:46:50 -08:00
|
|
|
return;
|
2013-01-05 06:53:16 -08:00
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
// !isPan() and evt.detail should always give the same answer here
|
|
|
|
// since they use the same heuristics, but use the native gecko
|
|
|
|
// computation when possible.
|
|
|
|
//
|
|
|
|
// NB: when we're using touch events, then !KineticPanning.isPan()
|
|
|
|
// => this.panning, so we'll never attempt to block the click
|
|
|
|
// event. That's OK however, because we won't fire a synthetic
|
|
|
|
// click when we're using touch events and this touch series
|
|
|
|
// wasn't a "tap" gesture.
|
|
|
|
let click = (this.watchedEventsType == 'mouse') ?
|
|
|
|
evt.detail : !KineticPanning.isPan();
|
|
|
|
// Additionally, if we're seeing non-compliant hybrid events, a
|
|
|
|
// "real" click will be generated if we started and ended on the
|
|
|
|
// same element.
|
|
|
|
if (this.hybridEvents) {
|
|
|
|
let target =
|
|
|
|
content.document.elementFromPoint(touch.clientX, touch.clientY);
|
|
|
|
click |= (target === this.pointerDownTarget);
|
|
|
|
}
|
2012-02-17 13:37:53 -08:00
|
|
|
|
2012-03-05 00:55:51 -08:00
|
|
|
if (this.target && click && (this.panning || this.preventNextClick)) {
|
2013-09-04 05:29:46 -07:00
|
|
|
if (this.hybridEvents) {
|
|
|
|
let target = this.target;
|
|
|
|
let view = target.ownerDocument ? target.ownerDocument.defaultView
|
|
|
|
: target;
|
|
|
|
view.addEventListener('click', this, true, true);
|
|
|
|
} else {
|
|
|
|
// We prevent end events to avoid sending a focus event. See bug 889717.
|
|
|
|
evt.preventDefault();
|
|
|
|
}
|
2013-10-17 00:18:13 -07:00
|
|
|
} else if (this.target && click && !this.panning) {
|
|
|
|
this.notify(this._activationTimer);
|
|
|
|
|
|
|
|
this._delayEvents = true;
|
|
|
|
let start = Date.now();
|
|
|
|
let thread = Services.tm.currentThread;
|
|
|
|
while (this._delayEvents && (Date.now() - start) < this._activeDurationMs) {
|
|
|
|
thread.processNextEvent(true);
|
|
|
|
}
|
|
|
|
this._delayEvents = false;
|
2012-03-05 00:55:51 -08:00
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2013-05-14 05:30:37 -07:00
|
|
|
this._finishPanning();
|
2013-07-24 16:27:45 -07:00
|
|
|
|
|
|
|
// Now that we're done, avoid entraining the thing we just panned.
|
|
|
|
this.pointerDownTarget = null;
|
2012-02-01 16:46:50 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
onTouchMove: function cp_onTouchMove(evt) {
|
2013-01-05 06:53:16 -08:00
|
|
|
if (!this.dragging)
|
2012-02-01 16:46:50 -08:00
|
|
|
return;
|
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
let screenX, screenY;
|
|
|
|
if (this.watchedEventsType == 'touch') {
|
|
|
|
let primaryTouch = this.findPrimaryPointer(evt.changedTouches);
|
|
|
|
if (evt.touches.length > 1 || !primaryTouch)
|
|
|
|
return;
|
|
|
|
screenX = primaryTouch.screenX;
|
|
|
|
screenY = primaryTouch.screenY;
|
|
|
|
} else {
|
|
|
|
screenX = evt.screenX;
|
|
|
|
screenY = evt.screenY;
|
|
|
|
}
|
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
let current = this.position;
|
2013-01-05 06:53:16 -08:00
|
|
|
let delta = new Point(screenX - current.x, screenY - current.y);
|
|
|
|
current.set(screenX, screenY);
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
KineticPanning.record(delta, evt.timeStamp);
|
2013-01-05 06:53:16 -08:00
|
|
|
|
|
|
|
// There's no possibility of us panning anything.
|
|
|
|
if (!this.scrollCallback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let isPan = KineticPanning.isPan();
|
2013-10-30 14:06:15 -07:00
|
|
|
this.scrollCallback(delta.scale(-1));
|
2013-01-05 06:53:16 -08:00
|
|
|
|
2013-02-15 11:41:23 -08:00
|
|
|
// If we've detected a pan gesture, cancel the active state of the
|
2012-03-05 00:55:51 -08:00
|
|
|
// current target.
|
2013-01-05 06:53:16 -08:00
|
|
|
if (!this.panning && isPan) {
|
2012-03-05 00:55:51 -08:00
|
|
|
this.panning = true;
|
|
|
|
this._resetActive();
|
2013-01-05 06:53:16 -08:00
|
|
|
this._activationTimer.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.panning) {
|
2013-02-15 11:41:23 -08:00
|
|
|
// Only do this when we're actually executing a pan gesture.
|
|
|
|
// Otherwise synthetic mouse events will be canceled.
|
2013-01-05 06:53:16 -08:00
|
|
|
evt.stopPropagation();
|
|
|
|
evt.preventDefault();
|
2012-03-05 00:55:51 -08:00
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
},
|
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
// nsITimerCallback
|
|
|
|
notify: function cp_notify(timer) {
|
|
|
|
this._setActive(this.pointerDownTarget);
|
|
|
|
},
|
2012-02-01 16:46:50 -08:00
|
|
|
|
|
|
|
onKineticBegin: function cp_onKineticBegin(evt) {
|
|
|
|
},
|
|
|
|
|
|
|
|
onKineticPan: function cp_onKineticPan(delta) {
|
|
|
|
return !this.scrollCallback(delta);
|
|
|
|
},
|
|
|
|
|
|
|
|
onKineticEnd: function cp_onKineticEnd() {
|
|
|
|
if (!this.dragging)
|
|
|
|
this.scrollCallback = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
getPannable: function cp_getPannable(node) {
|
2012-11-01 00:48:45 -07:00
|
|
|
let pannableNode = this._findPannable(node);
|
|
|
|
if (pannableNode) {
|
|
|
|
return [pannableNode, this._generateCallback(pannableNode)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [null, null];
|
|
|
|
},
|
|
|
|
|
|
|
|
_findPannable: function cp_findPannable(node) {
|
|
|
|
if (!(node instanceof Ci.nsIDOMHTMLElement) || node.tagName == 'HTML') {
|
|
|
|
return null;
|
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2012-07-19 23:48:27 -07:00
|
|
|
let nodeContent = node.ownerDocument.defaultView;
|
2012-02-01 16:46:50 -08:00
|
|
|
while (!(node instanceof Ci.nsIDOMHTMLBodyElement)) {
|
2012-08-07 16:46:55 -07:00
|
|
|
let style = nodeContent.getComputedStyle(node, null);
|
|
|
|
|
|
|
|
let overflow = [style.getPropertyValue('overflow'),
|
|
|
|
style.getPropertyValue('overflow-x'),
|
|
|
|
style.getPropertyValue('overflow-y')];
|
|
|
|
|
|
|
|
let rect = node.getBoundingClientRect();
|
|
|
|
let isAuto = (overflow.indexOf('auto') != -1 &&
|
|
|
|
(rect.height < node.scrollHeight ||
|
|
|
|
rect.width < node.scrollWidth));
|
|
|
|
|
|
|
|
let isScroll = (overflow.indexOf('scroll') != -1);
|
|
|
|
|
|
|
|
let isScrollableTextarea = (node.tagName == 'TEXTAREA' &&
|
|
|
|
(node.scrollHeight > node.clientHeight ||
|
|
|
|
node.scrollWidth > node.clientWidth ||
|
|
|
|
('scrollLeftMax' in node && node.scrollLeftMax > 0) ||
|
|
|
|
('scrollTopMax' in node && node.scrollTopMax > 0)));
|
2012-11-01 00:48:45 -07:00
|
|
|
if (isScroll || isAuto || isScrollableTextarea) {
|
|
|
|
return node;
|
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
2012-08-07 07:52:23 -07:00
|
|
|
if (nodeContent.scrollMaxX || nodeContent.scrollMaxY) {
|
2012-11-01 00:48:45 -07:00
|
|
|
return nodeContent;
|
2012-08-07 07:52:23 -07:00
|
|
|
}
|
|
|
|
|
2013-01-14 09:03:32 -08:00
|
|
|
if (nodeContent.frameElement) {
|
|
|
|
return this._findPannable(nodeContent.frameElement);
|
|
|
|
}
|
|
|
|
|
2012-11-01 00:48:45 -07:00
|
|
|
return null;
|
2012-02-01 16:46:50 -08:00
|
|
|
},
|
|
|
|
|
2013-09-30 10:32:02 -07:00
|
|
|
_generateCallback: function cp_generateCallback(root) {
|
2012-11-01 00:48:45 -07:00
|
|
|
let firstScroll = true;
|
|
|
|
let target;
|
2013-09-30 10:32:02 -07:00
|
|
|
let current;
|
2012-12-26 10:24:43 -08:00
|
|
|
let win, doc, htmlNode, bodyNode;
|
2012-11-01 00:48:45 -07:00
|
|
|
|
|
|
|
function doScroll(node, delta) {
|
|
|
|
if (node instanceof Ci.nsIDOMHTMLElement) {
|
2013-09-30 10:32:02 -07:00
|
|
|
return node.scrollByNoFlush(delta.x, delta.y);
|
2012-12-26 10:24:43 -08:00
|
|
|
} else if (node instanceof Ci.nsIDOMWindow) {
|
|
|
|
win = node;
|
|
|
|
doc = win.document;
|
|
|
|
|
|
|
|
// "overflow:hidden" on either the <html> or the <body> node should
|
|
|
|
// prevent the user from scrolling the root viewport.
|
|
|
|
if (doc instanceof Ci.nsIDOMHTMLDocument) {
|
|
|
|
htmlNode = doc.documentElement;
|
|
|
|
bodyNode = doc.body;
|
|
|
|
if (win.getComputedStyle(htmlNode, null).overflowX == "hidden" ||
|
|
|
|
win.getComputedStyle(bodyNode, null).overflowX == "hidden") {
|
|
|
|
delta.x = 0;
|
|
|
|
}
|
|
|
|
if (win.getComputedStyle(htmlNode, null).overflowY == "hidden" ||
|
|
|
|
win.getComputedStyle(bodyNode, null).overflowY == "hidden") {
|
|
|
|
delta.y = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 10:32:02 -07:00
|
|
|
let oldX = node.scrollX;
|
|
|
|
let oldY = node.scrollY;
|
2012-11-01 00:48:45 -07:00
|
|
|
node.scrollBy(delta.x, delta.y);
|
2013-09-30 10:32:02 -07:00
|
|
|
return (node.scrollX != oldX || node.scrollY != oldY);
|
2012-11-01 00:48:45 -07:00
|
|
|
}
|
2012-12-26 10:24:43 -08:00
|
|
|
// If we get here, |node| isn't an HTML element and it's not a window,
|
|
|
|
// but findPannable apparently thought it was scrollable... What is it?
|
|
|
|
return false;
|
2013-09-30 10:32:02 -07:00
|
|
|
}
|
2012-11-01 00:48:45 -07:00
|
|
|
|
2013-01-14 09:03:32 -08:00
|
|
|
function targetParent(node) {
|
2013-09-30 10:32:02 -07:00
|
|
|
return node.parentNode || node.frameElement || null;
|
2013-01-14 09:03:32 -08:00
|
|
|
}
|
|
|
|
|
2012-11-01 00:48:45 -07:00
|
|
|
function scroll(delta) {
|
2013-09-30 10:32:02 -07:00
|
|
|
current = root;
|
2013-11-24 15:18:00 -08:00
|
|
|
firstScroll = true;
|
2013-09-30 10:32:02 -07:00
|
|
|
while (current) {
|
|
|
|
if (doScroll(current, delta)) {
|
|
|
|
firstScroll = false;
|
|
|
|
return true;
|
2012-11-01 00:48:45 -07:00
|
|
|
}
|
2013-09-30 10:32:02 -07:00
|
|
|
|
|
|
|
// TODO The current code looks for possible scrolling regions only if
|
|
|
|
// this is the first scroll action but this should be more dynamic.
|
|
|
|
if (!firstScroll) {
|
|
|
|
return false;
|
2012-11-01 00:48:45 -07:00
|
|
|
}
|
2013-09-30 10:32:02 -07:00
|
|
|
|
|
|
|
current = ContentPanning._findPannable(targetParent(current));
|
2012-02-01 16:46:50 -08:00
|
|
|
}
|
2013-09-30 10:32:02 -07:00
|
|
|
|
|
|
|
// There is nothing scrollable here.
|
|
|
|
return false;
|
2012-02-01 16:46:50 -08:00
|
|
|
}
|
|
|
|
return scroll;
|
2012-03-05 00:55:51 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
get _domUtils() {
|
|
|
|
delete this._domUtils;
|
|
|
|
return this._domUtils = Cc['@mozilla.org/inspector/dom-utils;1']
|
|
|
|
.getService(Ci.inIDOMUtils);
|
|
|
|
},
|
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
get _activationTimer() {
|
|
|
|
delete this._activationTimer;
|
|
|
|
return this._activationTimer = Cc["@mozilla.org/timer;1"]
|
|
|
|
.createInstance(Ci.nsITimer);
|
|
|
|
},
|
|
|
|
|
|
|
|
get _activationDelayMs() {
|
|
|
|
let delay = Services.prefs.getIntPref('ui.touch_activation.delay_ms');
|
|
|
|
delete this._activationDelayMs;
|
|
|
|
return this._activationDelayMs = delay;
|
|
|
|
},
|
|
|
|
|
2013-10-17 00:18:13 -07:00
|
|
|
get _activeDurationMs() {
|
|
|
|
let duration = Services.prefs.getIntPref('ui.touch_activation.duration_ms');
|
|
|
|
delete this._activeDurationMs;
|
|
|
|
return this._activeDurationMs = duration;
|
|
|
|
},
|
|
|
|
|
2012-03-05 00:55:51 -08:00
|
|
|
_resetActive: function cp_resetActive() {
|
2013-11-19 10:15:20 -08:00
|
|
|
let elt = this.pointerDownTarget || this.target;
|
2013-01-05 06:53:16 -08:00
|
|
|
let root = elt.ownerDocument || elt.document;
|
|
|
|
this._setActive(root.documentElement);
|
|
|
|
},
|
2012-03-05 00:55:51 -08:00
|
|
|
|
2013-10-19 03:30:33 -07:00
|
|
|
_resetHover: function cp_resetHover() {
|
|
|
|
const kStateHover = 0x00000004;
|
2013-11-22 04:45:05 -08:00
|
|
|
try {
|
|
|
|
let element = content.document.createElement('foo');
|
|
|
|
this._domUtils.setContentState(element, kStateHover);
|
|
|
|
} catch(e) {}
|
2013-10-19 03:30:33 -07:00
|
|
|
},
|
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
_setActive: function cp_setActive(elt) {
|
2012-03-05 00:55:51 -08:00
|
|
|
const kStateActive = 0x00000001;
|
2013-01-05 06:53:16 -08:00
|
|
|
this._domUtils.setContentState(elt, kStateActive);
|
2012-07-19 23:48:27 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_recvViewportChange: function(data) {
|
2012-08-08 21:39:02 -07:00
|
|
|
let metrics = data.json;
|
2012-10-11 22:46:24 -07:00
|
|
|
this._viewport = new Rect(metrics.x, metrics.y,
|
|
|
|
metrics.viewport.width,
|
|
|
|
metrics.viewport.height);
|
2012-11-28 01:18:12 -08:00
|
|
|
this._cssCompositedRect = new Rect(metrics.x, metrics.y,
|
|
|
|
metrics.cssCompositedRect.width,
|
|
|
|
metrics.cssCompositedRect.height);
|
2012-08-08 21:39:02 -07:00
|
|
|
this._cssPageRect = new Rect(metrics.cssPageRect.x,
|
|
|
|
metrics.cssPageRect.y,
|
|
|
|
metrics.cssPageRect.width,
|
|
|
|
metrics.cssPageRect.height);
|
|
|
|
},
|
|
|
|
|
|
|
|
_recvDoubleTap: function(data) {
|
|
|
|
let data = data.json;
|
|
|
|
|
|
|
|
// We haven't received a metrics update yet; don't do anything.
|
|
|
|
if (this._viewport == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let win = content;
|
|
|
|
|
|
|
|
let element = ElementTouchHelper.anyElementFromPoint(win, data.x, data.y);
|
|
|
|
if (!element) {
|
|
|
|
this._zoomOut();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (element && !this._shouldZoomToElement(element))
|
|
|
|
element = element.parentNode;
|
|
|
|
|
|
|
|
if (!element) {
|
|
|
|
this._zoomOut();
|
|
|
|
} else {
|
|
|
|
const margin = 15;
|
|
|
|
let rect = ElementTouchHelper.getBoundingContentRect(element);
|
|
|
|
|
|
|
|
let cssPageRect = this._cssPageRect;
|
|
|
|
let viewport = this._viewport;
|
2012-09-28 19:16:34 -07:00
|
|
|
let bRect = new Rect(Math.max(cssPageRect.x, rect.x - margin),
|
2012-08-08 21:39:02 -07:00
|
|
|
rect.y,
|
|
|
|
rect.w + 2 * margin,
|
|
|
|
rect.h);
|
|
|
|
// constrict the rect to the screen's right edge
|
|
|
|
bRect.width = Math.min(bRect.width, cssPageRect.right - bRect.x);
|
|
|
|
|
|
|
|
// if the rect is already taking up most of the visible area and is stretching the
|
|
|
|
// width of the page, then we want to zoom out instead.
|
2012-11-28 01:18:12 -08:00
|
|
|
if (this._isRectZoomedIn(bRect, this._cssCompositedRect)) {
|
2012-08-08 21:39:02 -07:00
|
|
|
this._zoomOut();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.x = Math.round(bRect.x);
|
|
|
|
rect.y = Math.round(bRect.y);
|
|
|
|
rect.w = Math.round(bRect.width);
|
2012-11-28 01:18:12 -08:00
|
|
|
rect.h = Math.round(bRect.height);
|
2012-08-08 21:39:02 -07:00
|
|
|
|
|
|
|
// if the block we're zooming to is really tall, and the user double-tapped
|
|
|
|
// more than a screenful of height from the top of it, then adjust the y-coordinate
|
|
|
|
// so that we center the actual point the user double-tapped upon. this prevents
|
|
|
|
// flying to the top of a page when double-tapping to zoom in (bug 761721).
|
|
|
|
// the 1.2 multiplier is just a little fuzz to compensate for bRect including horizontal
|
|
|
|
// margins but not vertical ones.
|
|
|
|
let cssTapY = viewport.y + data.y;
|
|
|
|
if ((bRect.height > rect.h) && (cssTapY > rect.y + (rect.h * 1.2))) {
|
|
|
|
rect.y = cssTapY - (rect.h / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
|
|
|
os.notifyObservers(docShell, 'browser-zoom-to-rect', JSON.stringify(rect));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-22 04:45:05 -08:00
|
|
|
_handleVisibilityChange: function(evt) {
|
2013-10-19 03:30:33 -07:00
|
|
|
if (!evt.target.hidden)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._resetHover();
|
|
|
|
},
|
|
|
|
|
2012-08-08 21:39:02 -07:00
|
|
|
_shouldZoomToElement: function(aElement) {
|
|
|
|
let win = aElement.ownerDocument.defaultView;
|
|
|
|
if (win.getComputedStyle(aElement, null).display == "inline")
|
|
|
|
return false;
|
|
|
|
if (aElement instanceof Ci.nsIDOMHTMLLIElement)
|
|
|
|
return false;
|
|
|
|
if (aElement instanceof Ci.nsIDOMHTMLQuoteElement)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
_zoomOut: function() {
|
|
|
|
let rect = new Rect(0, 0, 0, 0);
|
|
|
|
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
|
|
|
os.notifyObservers(docShell, 'browser-zoom-to-rect', JSON.stringify(rect));
|
|
|
|
},
|
|
|
|
|
|
|
|
_isRectZoomedIn: function(aRect, aViewport) {
|
|
|
|
// This function checks to see if the area of the rect visible in the
|
2012-11-28 01:18:12 -08:00
|
|
|
// viewport (i.e. the "overlapArea" variable below) is approximately
|
|
|
|
// the max area of the rect we can show.
|
2012-08-08 21:39:02 -07:00
|
|
|
let vRect = new Rect(aViewport.x, aViewport.y, aViewport.width, aViewport.height);
|
|
|
|
let overlap = vRect.intersect(aRect);
|
|
|
|
let overlapArea = overlap.width * overlap.height;
|
|
|
|
let availHeight = Math.min(aRect.width * vRect.height / vRect.width, aRect.height);
|
|
|
|
let showing = overlapArea / (aRect.width * availHeight);
|
2012-11-28 01:18:12 -08:00
|
|
|
let ratioW = (aRect.width / vRect.width);
|
|
|
|
let ratioH = (aRect.height / vRect.height);
|
2012-08-08 21:39:02 -07:00
|
|
|
|
2012-11-28 01:18:12 -08:00
|
|
|
return (showing > 0.9 && (ratioW > 0.9 || ratioH > 0.9));
|
2013-05-14 05:30:37 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_finishPanning: function() {
|
|
|
|
this._resetActive();
|
|
|
|
this.dragging = false;
|
|
|
|
delete this.primaryPointerId;
|
|
|
|
this._activationTimer.cancel();
|
|
|
|
|
|
|
|
if (this.panning) {
|
|
|
|
KineticPanning.start(this);
|
|
|
|
}
|
2012-02-01 16:46:50 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Min/max velocity of kinetic panning. This is in pixels/millisecond.
|
2013-02-05 10:05:56 -08:00
|
|
|
const kMinVelocity = 0.2;
|
2012-02-01 16:46:50 -08:00
|
|
|
const kMaxVelocity = 6;
|
|
|
|
|
|
|
|
// Constants that affect the "friction" of the scroll pane.
|
2012-02-17 13:37:53 -08:00
|
|
|
const kExponentialC = 1000;
|
2012-02-01 16:46:50 -08:00
|
|
|
const kPolynomialC = 100 / 1000000;
|
|
|
|
|
|
|
|
// How often do we change the position of the scroll pane?
|
|
|
|
// Too often and panning may jerk near the end.
|
|
|
|
// Too little and panning will be choppy. In milliseconds.
|
|
|
|
const kUpdateInterval = 16;
|
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
// The numbers of momentums to use for calculating the velocity of the pan.
|
|
|
|
// Those are taken from the end of the action
|
|
|
|
const kSamples = 5;
|
|
|
|
|
2012-02-01 16:46:50 -08:00
|
|
|
const KineticPanning = {
|
|
|
|
_position: new Point(0, 0),
|
|
|
|
_velocity: new Point(0, 0),
|
|
|
|
_acceleration: new Point(0, 0),
|
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
get active() {
|
|
|
|
return this.target !== null;
|
|
|
|
},
|
|
|
|
|
2012-02-23 16:40:49 -08:00
|
|
|
target: null,
|
2012-02-01 16:46:50 -08:00
|
|
|
start: function kp_start(target) {
|
|
|
|
this.target = target;
|
|
|
|
|
|
|
|
// Calculate the initial velocity of the movement based on user input
|
2013-02-05 10:05:56 -08:00
|
|
|
let momentums = this.momentums;
|
|
|
|
let flick = momentums[momentums.length - 1].time - momentums[0].time < 300;
|
|
|
|
|
2012-02-01 16:46:50 -08:00
|
|
|
let distance = new Point(0, 0);
|
|
|
|
momentums.forEach(function(momentum) {
|
|
|
|
distance.add(momentum.dx, momentum.dy);
|
|
|
|
});
|
|
|
|
|
|
|
|
function clampFromZero(x, min, max) {
|
|
|
|
if (x >= 0)
|
|
|
|
return Math.max(min, Math.min(max, x));
|
|
|
|
return Math.min(-min, Math.max(-max, x));
|
|
|
|
}
|
|
|
|
|
2013-02-05 10:05:56 -08:00
|
|
|
let elapsed = momentums[momentums.length - 1].time - momentums[0].time;
|
2012-02-01 16:46:50 -08:00
|
|
|
let velocityX = clampFromZero(distance.x / elapsed, 0, kMaxVelocity);
|
|
|
|
let velocityY = clampFromZero(distance.y / elapsed, 0, kMaxVelocity);
|
|
|
|
|
|
|
|
let velocity = this._velocity;
|
2013-02-05 10:05:56 -08:00
|
|
|
if (flick) {
|
|
|
|
// Very fast pan action that does not generate a click are very often pan
|
|
|
|
// action. If this is a small gesture then it will not move the view a lot
|
|
|
|
// and so it will be above the minimun threshold and not generate any
|
|
|
|
// kinetic panning. This does not look on a device since this is often
|
|
|
|
// a real gesture, so let's lower the velocity threshold for such moves.
|
|
|
|
velocity.set(velocityX, velocityY);
|
|
|
|
} else {
|
|
|
|
velocity.set(Math.abs(velocityX) < kMinVelocity ? 0 : velocityX,
|
|
|
|
Math.abs(velocityY) < kMinVelocity ? 0 : velocityY);
|
|
|
|
}
|
2012-02-17 13:37:53 -08:00
|
|
|
this.momentums = [];
|
2012-02-01 16:46:50 -08:00
|
|
|
|
|
|
|
// Set acceleration vector to opposite signs of velocity
|
|
|
|
function sign(x) {
|
|
|
|
return x ? (x > 0 ? 1 : -1) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._acceleration.set(velocity.clone().map(sign).scale(-kPolynomialC));
|
|
|
|
|
|
|
|
// Reset the position
|
|
|
|
this._position.set(0, 0);
|
|
|
|
|
|
|
|
this._startAnimation();
|
|
|
|
|
|
|
|
this.target.onKineticBegin();
|
|
|
|
},
|
|
|
|
|
|
|
|
stop: function kp_stop() {
|
|
|
|
if (!this.target)
|
|
|
|
return;
|
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
this.momentums = [];
|
2012-03-05 00:55:51 -08:00
|
|
|
this.distance.set(0, 0);
|
2012-02-01 16:46:50 -08:00
|
|
|
|
|
|
|
this.target.onKineticEnd();
|
|
|
|
this.target = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
momentums: [],
|
2012-02-17 13:37:53 -08:00
|
|
|
record: function kp_record(delta, timestamp) {
|
2013-05-23 08:52:04 -07:00
|
|
|
this.momentums.push({ 'time': this._getTime(timestamp),
|
|
|
|
'dx' : delta.x, 'dy' : delta.y });
|
2013-07-31 09:22:57 -07:00
|
|
|
|
|
|
|
// We only need to keep kSamples in this.momentums.
|
|
|
|
if (this.momentums.length > kSamples) {
|
|
|
|
this.momentums.shift();
|
|
|
|
}
|
|
|
|
|
2012-03-05 00:55:51 -08:00
|
|
|
this.distance.add(delta.x, delta.y);
|
2012-02-17 13:37:53 -08:00
|
|
|
},
|
|
|
|
|
2013-05-23 08:52:04 -07:00
|
|
|
_getTime: function kp_getTime(time) {
|
|
|
|
// Touch events generated by the platform or hand-made are defined in
|
|
|
|
// microseconds instead of milliseconds. Bug 77992 will fix this at the
|
|
|
|
// platform level.
|
|
|
|
if (time > Date.now()) {
|
|
|
|
return Math.floor(time / 1000);
|
|
|
|
} else {
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-05 00:55:51 -08:00
|
|
|
get threshold() {
|
2012-02-17 13:37:53 -08:00
|
|
|
let dpi = content.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.displayDPI;
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
let threshold = Services.prefs.getIntPref('ui.dragThresholdX') / 240 * dpi;
|
|
|
|
|
2012-03-05 00:55:51 -08:00
|
|
|
delete this.threshold;
|
|
|
|
return this.threshold = threshold;
|
|
|
|
},
|
|
|
|
|
|
|
|
distance: new Point(0, 0),
|
|
|
|
isPan: function cp_isPan() {
|
|
|
|
return (Math.abs(this.distance.x) > this.threshold ||
|
|
|
|
Math.abs(this.distance.y) > this.threshold);
|
2012-02-01 16:46:50 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_startAnimation: function kp_startAnimation() {
|
|
|
|
let c = kExponentialC;
|
|
|
|
function getNextPosition(position, v, a, t) {
|
|
|
|
// Important traits for this function:
|
|
|
|
// p(t=0) is 0
|
|
|
|
// p'(t=0) is v0
|
|
|
|
//
|
|
|
|
// We use exponential to get a smoother stop, but by itself exponential
|
|
|
|
// is too smooth at the end. Adding a polynomial with the appropriate
|
|
|
|
// weight helps to balance
|
|
|
|
position.set(v.x * Math.exp(-t / c) * -c + a.x * t * t + v.x * c,
|
|
|
|
v.y * Math.exp(-t / c) * -c + a.y * t * t + v.y * c);
|
|
|
|
}
|
|
|
|
|
|
|
|
let startTime = content.mozAnimationStartTime;
|
|
|
|
let elapsedTime = 0, targetedTime = 0, averageTime = 0;
|
|
|
|
|
|
|
|
let velocity = this._velocity;
|
|
|
|
let acceleration = this._acceleration;
|
|
|
|
|
|
|
|
let position = this._position;
|
|
|
|
let nextPosition = new Point(0, 0);
|
|
|
|
let delta = new Point(0, 0);
|
|
|
|
|
|
|
|
let callback = (function(timestamp) {
|
|
|
|
if (!this.target)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// To make animation end fast enough but to keep smoothness, average the
|
|
|
|
// ideal time frame (smooth animation) with the actual time lapse
|
|
|
|
// (end fast enough).
|
|
|
|
// Animation will never take longer than 2 times the ideal length of time.
|
|
|
|
elapsedTime = timestamp - startTime;
|
|
|
|
targetedTime += kUpdateInterval;
|
|
|
|
averageTime = (targetedTime + elapsedTime) / 2;
|
|
|
|
|
|
|
|
// Calculate new position.
|
|
|
|
getNextPosition(nextPosition, velocity, acceleration, averageTime);
|
|
|
|
delta.set(Math.round(nextPosition.x - position.x),
|
|
|
|
Math.round(nextPosition.y - position.y));
|
|
|
|
|
|
|
|
// Test to see if movement is finished for each component.
|
|
|
|
if (delta.x * acceleration.x > 0)
|
|
|
|
delta.x = position.x = velocity.x = acceleration.x = 0;
|
|
|
|
|
|
|
|
if (delta.y * acceleration.y > 0)
|
|
|
|
delta.y = position.y = velocity.y = acceleration.y = 0;
|
|
|
|
|
|
|
|
if (velocity.equals(0, 0) || delta.equals(0, 0)) {
|
|
|
|
this.stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
position.add(delta);
|
|
|
|
if (this.target.onKineticPan(delta.scale(-1))) {
|
|
|
|
this.stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
content.mozRequestAnimationFrame(callback);
|
|
|
|
}).bind(this);
|
|
|
|
|
|
|
|
content.mozRequestAnimationFrame(callback);
|
|
|
|
}
|
|
|
|
};
|
2012-08-08 21:39:02 -07:00
|
|
|
|
|
|
|
const ElementTouchHelper = {
|
|
|
|
anyElementFromPoint: function(aWindow, aX, aY) {
|
|
|
|
let cwu = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
let elem = cwu.elementFromPoint(aX, aY, true, true);
|
|
|
|
|
|
|
|
let HTMLIFrameElement = Ci.nsIDOMHTMLIFrameElement;
|
|
|
|
let HTMLFrameElement = Ci.nsIDOMHTMLFrameElement;
|
|
|
|
while (elem && (elem instanceof HTMLIFrameElement || elem instanceof HTMLFrameElement)) {
|
|
|
|
let rect = elem.getBoundingClientRect();
|
|
|
|
aX -= rect.left;
|
|
|
|
aY -= rect.top;
|
|
|
|
cwu = elem.contentDocument.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
elem = cwu.elementFromPoint(aX, aY, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
},
|
|
|
|
|
|
|
|
getBoundingContentRect: function(aElement) {
|
|
|
|
if (!aElement)
|
|
|
|
return {x: 0, y: 0, w: 0, h: 0};
|
|
|
|
|
|
|
|
let document = aElement.ownerDocument;
|
|
|
|
while (document.defaultView.frameElement)
|
|
|
|
document = document.defaultView.frameElement.ownerDocument;
|
|
|
|
|
|
|
|
let cwu = document.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
let scrollX = {}, scrollY = {};
|
|
|
|
cwu.getScrollXY(false, scrollX, scrollY);
|
|
|
|
|
|
|
|
let r = aElement.getBoundingClientRect();
|
|
|
|
|
|
|
|
// step out of iframes and frames, offsetting scroll values
|
|
|
|
for (let frame = aElement.ownerDocument.defaultView; frame.frameElement && frame != content; frame = frame.parent) {
|
|
|
|
// adjust client coordinates' origin to be top left of iframe viewport
|
|
|
|
let rect = frame.frameElement.getBoundingClientRect();
|
|
|
|
let left = frame.getComputedStyle(frame.frameElement, "").borderLeftWidth;
|
|
|
|
let top = frame.getComputedStyle(frame.frameElement, "").borderTopWidth;
|
|
|
|
scrollX.value += rect.left + parseInt(left);
|
|
|
|
scrollY.value += rect.top + parseInt(top);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {x: r.left + scrollX.value,
|
|
|
|
y: r.top + scrollY.value,
|
|
|
|
w: r.width,
|
|
|
|
h: r.height };
|
|
|
|
}
|
|
|
|
};
|