2010-06-25 14:16:01 -07:00
|
|
|
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
|
|
|
|
/*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Mobile Browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Benjamin Stover <bstover@mozilla.com>
|
|
|
|
* Matt Brubeck <mbrubeck@mozilla.com>
|
|
|
|
* Jaakko Kiviluoto <jaakko.kiviluoto@digia.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responsible for zooming in to a given view rectangle
|
|
|
|
*/
|
2010-09-15 15:05:50 -07:00
|
|
|
const AnimatedZoom = {
|
2011-02-02 11:03:46 -08:00
|
|
|
startScale: null,
|
|
|
|
|
2010-09-02 16:49:14 -07:00
|
|
|
/** Starts an animated zoom to zoomRect. */
|
|
|
|
animateTo: function(aZoomRect) {
|
|
|
|
if (!aZoomRect)
|
|
|
|
return;
|
2010-08-12 08:43:00 -07:00
|
|
|
|
2010-09-02 16:49:14 -07:00
|
|
|
this.zoomTo = aZoomRect.clone();
|
2010-06-25 14:16:01 -07:00
|
|
|
|
2010-09-02 16:49:14 -07:00
|
|
|
if (this.animationDuration === undefined)
|
|
|
|
this.animationDuration = Services.prefs.getIntPref("browser.ui.zoom.animationDuration");
|
2010-06-25 14:16:01 -07:00
|
|
|
|
2010-09-02 16:49:14 -07:00
|
|
|
Browser.hideSidebars();
|
|
|
|
Browser.hideTitlebar();
|
|
|
|
Browser.forceChromeReflow();
|
|
|
|
|
2011-02-02 11:03:46 -08:00
|
|
|
this.start();
|
2010-09-02 16:49:14 -07:00
|
|
|
|
|
|
|
// Check if zooming animations were occuring before.
|
2011-02-02 11:03:46 -08:00
|
|
|
if (!this.zoomRect) {
|
2010-09-02 09:46:07 -07:00
|
|
|
this.updateTo(this.zoomFrom);
|
2010-09-02 16:49:14 -07:00
|
|
|
|
2011-01-31 15:10:01 -08:00
|
|
|
mozRequestAnimationFrame(this);
|
2010-11-04 03:54:12 -07:00
|
|
|
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("AnimatedZoomBegin", true, true);
|
|
|
|
window.dispatchEvent(event);
|
2010-06-25 14:16:01 -07:00
|
|
|
}
|
2010-09-02 09:46:07 -07:00
|
|
|
},
|
|
|
|
|
2011-02-02 11:03:46 -08:00
|
|
|
start: function start() {
|
|
|
|
this.browser = getBrowser();
|
|
|
|
this.zoomFrom = this.zoomRect || this.getStartRect();
|
|
|
|
this.startScale = this.browser.scale;
|
|
|
|
this.beginTime = mozAnimationStartTime;
|
|
|
|
},
|
|
|
|
|
2010-10-19 09:29:23 -07:00
|
|
|
/** Get the visible rect, in device pixels relative to the content origin. */
|
2010-09-17 14:16:43 -07:00
|
|
|
getStartRect: function getStartRect() {
|
2011-02-02 11:03:46 -08:00
|
|
|
let browser = this.browser;
|
2010-10-19 09:29:23 -07:00
|
|
|
let bcr = browser.getBoundingClientRect();
|
2011-01-18 14:00:36 -08:00
|
|
|
let scroll = browser.getRootView().getPosition();
|
2010-10-19 09:29:23 -07:00
|
|
|
return new Rect(scroll.x, scroll.y, bcr.width, bcr.height);
|
2010-09-17 14:16:43 -07:00
|
|
|
},
|
|
|
|
|
2010-10-19 09:29:23 -07:00
|
|
|
/** Update the visible rect, in device pixels relative to the content origin. */
|
2010-09-02 09:46:07 -07:00
|
|
|
updateTo: function(nextRect) {
|
|
|
|
let zoomRatio = window.innerWidth / nextRect.width;
|
2011-02-02 11:03:46 -08:00
|
|
|
let scale = this.startScale * zoomRatio;
|
|
|
|
let scrollX = nextRect.left * zoomRatio;
|
|
|
|
let scrollY = nextRect.top * zoomRatio;
|
2011-01-25 06:28:41 -08:00
|
|
|
|
2011-02-02 11:03:46 -08:00
|
|
|
this.browser.fuzzyZoom(scale, scrollX, scrollY);
|
2011-01-25 06:28:41 -08:00
|
|
|
|
2010-09-02 16:49:14 -07:00
|
|
|
this.zoomRect = nextRect;
|
2010-09-02 09:46:07 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/** Stop animation, zoom to point, and clean up. */
|
|
|
|
finish: function() {
|
2011-02-02 11:03:46 -08:00
|
|
|
this.updateTo(this.zoomTo || this.zoomRect);
|
|
|
|
this.browser.finishFuzzyZoom();
|
|
|
|
|
|
|
|
Browser.hideSidebars();
|
|
|
|
Browser.hideTitlebar();
|
|
|
|
|
2010-09-02 09:46:07 -07:00
|
|
|
this.beginTime = null;
|
2010-08-24 10:13:00 -07:00
|
|
|
this.zoomTo = null;
|
2010-09-02 16:49:14 -07:00
|
|
|
this.zoomFrom = null;
|
|
|
|
this.zoomRect = null;
|
2011-02-02 11:03:46 -08:00
|
|
|
this.startScale = null;
|
2010-11-04 03:54:12 -07:00
|
|
|
|
|
|
|
let event = document.createEvent("Events");
|
|
|
|
event.initEvent("AnimatedZoomEnd", true, true);
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
|
|
|
|
isZooming: function isZooming() {
|
|
|
|
return this.beginTime != null;
|
2010-09-02 16:49:14 -07:00
|
|
|
},
|
|
|
|
|
2011-01-31 15:10:01 -08:00
|
|
|
onBeforePaint: function(aTimeStamp) {
|
2010-09-02 16:49:14 -07:00
|
|
|
try {
|
2011-01-31 15:10:01 -08:00
|
|
|
let tdiff = aTimeStamp - this.beginTime;
|
2010-09-02 16:49:14 -07:00
|
|
|
let counter = tdiff / this.animationDuration;
|
|
|
|
if (counter < 1) {
|
|
|
|
// update browser to interpolated rectangle
|
2010-09-15 15:05:50 -07:00
|
|
|
let rect = this.zoomFrom.blend(this.zoomTo, counter);
|
2010-09-02 16:49:14 -07:00
|
|
|
this.updateTo(rect);
|
2011-01-31 15:10:01 -08:00
|
|
|
mozRequestAnimationFrame(this);
|
2010-09-15 15:05:50 -07:00
|
|
|
} else {
|
2010-09-02 16:49:14 -07:00
|
|
|
// last cycle already rendered final scaled image, now clean up
|
|
|
|
this.finish();
|
|
|
|
}
|
2010-09-15 15:05:50 -07:00
|
|
|
} catch(e) {
|
2010-09-02 16:49:14 -07:00
|
|
|
this.finish();
|
|
|
|
throw e;
|
|
|
|
}
|
2010-06-25 14:16:01 -07:00
|
|
|
}
|
2010-07-20 13:49:31 -07:00
|
|
|
};
|