2012-05-21 15:12:37 +04: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/. */
|
|
|
|
|
2010-09-04 00:10:46 +04:00
|
|
|
function init() {
|
2011-01-12 00:34:31 +03:00
|
|
|
enableAsyncScrolling();
|
2010-09-04 00:10:46 +04:00
|
|
|
messageManager.loadFrameScript(
|
|
|
|
"chrome://global/content/test-ipcbrowser-content.js", true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function browser() {
|
|
|
|
return document.getElementById("content");
|
|
|
|
}
|
|
|
|
|
2011-01-26 09:26:37 +03:00
|
|
|
function frameLoader() {
|
|
|
|
return browser().QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader;
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:31 +03:00
|
|
|
function viewManager() {
|
2011-01-26 09:26:37 +03:00
|
|
|
return frameLoader().QueryInterface(Components.interfaces.nsIContentViewManager);
|
2011-01-13 20:45:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function rootView() {
|
|
|
|
return viewManager().rootContentView;
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
2011-01-12 00:34:31 +03:00
|
|
|
function enableAsyncScrolling() {
|
2011-08-09 23:38:26 +04:00
|
|
|
frameLoader().renderMode = Components.interfaces.nsIFrameLoader.RENDER_MODE_ASYNC_SCROLL;
|
2011-01-12 00:34:31 +03:00
|
|
|
}
|
|
|
|
|
2010-09-04 00:10:46 +04:00
|
|
|
// Functions affecting the content window.
|
|
|
|
|
|
|
|
function loadURL(url) {
|
|
|
|
browser().setAttribute('src', url);
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollContentBy(dx, dy) {
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("scrollBy",
|
|
|
|
{ dx: dx, dy: dy });
|
2010-09-04 00:10:46 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollContentTo(x, y) {
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("scrollTo",
|
|
|
|
{ x: x, y: y });
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setContentViewport(w, h) {
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("setViewport",
|
|
|
|
{ w: w, h: h });
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setContentDisplayPort(x, y, w, h) {
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("setDisplayPort",
|
|
|
|
{ x: x, y: y, w: w, h: h });
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setContentResolution(xres, yres) {
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("setResolution",
|
|
|
|
{ xres: xres, yres: yres });
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Functions affecting <browser>.
|
|
|
|
|
|
|
|
function scrollViewportBy(dx, dy) {
|
2011-01-13 20:45:31 +03:00
|
|
|
rootView().scrollBy(dx, dy);
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function scrollViewportTo(x, y) {
|
2011-01-13 20:45:31 +03:00
|
|
|
rootView().scrollTo(x, y);
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setViewportScale(xs, ys) {
|
2011-01-13 20:45:31 +03:00
|
|
|
rootView().setScale(xs, ys);
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var kDelayMs = 100;
|
|
|
|
var kDurationMs = 250;
|
|
|
|
var scrolling = false;
|
|
|
|
function startAnimatedScrollBy(dx, dy) {
|
|
|
|
if (scrolling)
|
|
|
|
throw "don't interrupt me!";
|
|
|
|
|
|
|
|
scrolling = true;
|
|
|
|
|
|
|
|
var start = mozAnimationStartTime;
|
|
|
|
var end = start + kDurationMs;
|
|
|
|
// |- k| so that we do something in first invocation of nudge()
|
|
|
|
var prevNow = start - 20;
|
|
|
|
var accumDx = 0, accumDy = 0;
|
|
|
|
|
|
|
|
var sentScrollBy = false;
|
|
|
|
function nudgeScroll(now) {
|
2011-11-28 16:49:44 +04:00
|
|
|
if (!scrolling) {
|
|
|
|
// we've been canceled
|
|
|
|
return;
|
|
|
|
}
|
2010-09-04 00:10:46 +04:00
|
|
|
var ddx = dx * (now - prevNow) / kDurationMs;
|
|
|
|
var ddy = dy * (now - prevNow) / kDurationMs;
|
|
|
|
|
|
|
|
ddx = Math.min(dx - accumDx, ddx);
|
|
|
|
ddy = Math.min(dy - accumDy, ddy);
|
|
|
|
accumDx += ddx;
|
|
|
|
accumDy += ddy;
|
|
|
|
|
2011-01-13 20:45:31 +03:00
|
|
|
rootView().scrollBy(ddx, ddy);
|
2010-09-04 00:10:46 +04:00
|
|
|
|
|
|
|
if (!sentScrollBy && 100 <= (now - start)) {
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("scrollBy",
|
|
|
|
{ dx: dx, dy: dy });
|
2010-09-04 00:10:46 +04:00
|
|
|
sentScrollBy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (now >= end || (accumDx >= dx && accumDy >= dy)) {
|
|
|
|
var fixupDx = Math.max(dx - accumDx, 0);
|
|
|
|
var fixupDy = Math.max(dy - accumDy, 0);
|
2011-01-13 20:45:31 +03:00
|
|
|
rootView().scrollBy(fixupDx, fixupDy);
|
2010-09-04 00:10:46 +04:00
|
|
|
|
|
|
|
scrolling = false;
|
|
|
|
}
|
|
|
|
else {
|
2011-11-28 16:49:44 +04:00
|
|
|
mozRequestAnimationFrame(nudgeScroll);
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
prevNow = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
nudgeScroll(start);
|
2011-11-28 16:49:44 +04:00
|
|
|
mozRequestAnimationFrame(nudgeScroll);
|
2010-09-04 00:10:46 +04:00
|
|
|
}
|