2012-07-20 06:48:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "CompositorParent.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2012-08-06 20:32:11 +00:00
|
|
|
#include "mozilla/Constants.h"
|
2012-07-20 06:48:25 +00:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
#include "mozilla/XPCOM.h"
|
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "AsyncPanZoomController.h"
|
|
|
|
#include "GestureEventListener.h"
|
|
|
|
#include "nsIThreadManager.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2012-07-31 23:19:25 +00:00
|
|
|
#include "Layers.h"
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
static const float EPSILON = 0.0001;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum amount of time while panning before sending a viewport change. This
|
|
|
|
* will asynchronously repaint the page. It is also forced when panning stops.
|
|
|
|
*/
|
|
|
|
static const PRInt32 PAN_REPAINT_INTERVAL = 250;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum amount of time flinging before sending a viewport change. This will
|
|
|
|
* asynchronously repaint the page.
|
|
|
|
*/
|
|
|
|
static const PRInt32 FLING_REPAINT_INTERVAL = 75;
|
|
|
|
|
2012-07-23 01:51:23 +00:00
|
|
|
/**
|
|
|
|
* Minimum amount of speed along an axis before we begin painting far ahead by
|
|
|
|
* adjusting the displayport.
|
|
|
|
*/
|
|
|
|
static const float MIN_SKATE_SPEED = 0.5f;
|
|
|
|
|
2012-07-23 03:49:07 +00:00
|
|
|
/**
|
|
|
|
* Angle from axis within which we stay axis-locked.
|
|
|
|
*/
|
|
|
|
static const float AXIS_LOCK_ANGLE = M_PI / 6.0;
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
AsyncPanZoomController::AsyncPanZoomController(GeckoContentController* aGeckoContentController,
|
|
|
|
GestureBehavior aGestures)
|
|
|
|
: mGeckoContentController(aGeckoContentController),
|
|
|
|
mX(this),
|
|
|
|
mY(this),
|
|
|
|
mMonitor("AsyncPanZoomController"),
|
|
|
|
mLastSampleTime(TimeStamp::Now()),
|
|
|
|
mState(NOTHING),
|
2012-07-27 07:33:48 +00:00
|
|
|
mDPI(72),
|
2012-08-08 20:37:57 +00:00
|
|
|
mContentPainterStatus(CONTENT_IDLE),
|
2012-08-08 20:38:06 +00:00
|
|
|
mMayHaveTouchListeners(false),
|
|
|
|
mDisableNextTouchBatch(false)
|
2012-07-20 06:48:25 +00:00
|
|
|
{
|
|
|
|
if (aGestures == USE_GESTURE_DETECTOR) {
|
|
|
|
mGestureEventListener = new GestureEventListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDPI(mDPI);
|
|
|
|
}
|
|
|
|
|
|
|
|
AsyncPanZoomController::~AsyncPanZoomController() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static gfx::Point
|
|
|
|
WidgetSpaceToCompensatedViewportSpace(const gfx::Point& aPoint,
|
|
|
|
gfxFloat aCurrentZoom)
|
|
|
|
{
|
|
|
|
// Transform the input point from local widget space to the content document
|
|
|
|
// space that the user is seeing, from last composite.
|
|
|
|
gfx::Point pt(aPoint);
|
|
|
|
pt = pt / aCurrentZoom;
|
|
|
|
|
|
|
|
// FIXME/bug 775451: this doesn't attempt to compensate for content transforms
|
|
|
|
// in effect on the compositor. The problem is that it's very hard for us to
|
|
|
|
// know what content CSS pixel is at widget point 0,0 based on information
|
|
|
|
// available here. So we use this hacky implementation for now, which works
|
|
|
|
// in quiescent states.
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
AsyncPanZoomController::HandleInputEvent(const nsInputEvent& aEvent,
|
|
|
|
nsInputEvent* aOutEvent)
|
|
|
|
{
|
|
|
|
float currentZoom;
|
|
|
|
gfx::Point currentScrollOffset, lastScrollOffset;
|
|
|
|
{
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
currentZoom = mFrameMetrics.mResolution.width;
|
|
|
|
currentScrollOffset = gfx::Point(mFrameMetrics.mViewportScrollOffset.x,
|
|
|
|
mFrameMetrics.mViewportScrollOffset.y);
|
|
|
|
lastScrollOffset = gfx::Point(mLastContentPaintMetrics.mViewportScrollOffset.x,
|
|
|
|
mLastContentPaintMetrics.mViewportScrollOffset.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
switch (aEvent.eventStructType) {
|
|
|
|
case NS_TOUCH_EVENT: {
|
|
|
|
MultiTouchInput event(static_cast<const nsTouchEvent&>(aEvent));
|
|
|
|
status = HandleInputEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NS_MOUSE_EVENT: {
|
|
|
|
MultiTouchInput event(static_cast<const nsMouseEvent&>(aEvent));
|
|
|
|
status = HandleInputEvent(event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
status = nsEventStatus_eIgnore;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent.eventStructType) {
|
|
|
|
case NS_TOUCH_EVENT: {
|
|
|
|
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aOutEvent);
|
|
|
|
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
|
|
|
for (PRUint32 i = 0; i < touches.Length(); ++i) {
|
|
|
|
nsIDOMTouch* touch = touches[i];
|
|
|
|
if (touch) {
|
|
|
|
gfx::Point refPoint = WidgetSpaceToCompensatedViewportSpace(
|
|
|
|
gfx::Point(touch->mRefPoint.x, touch->mRefPoint.y),
|
|
|
|
currentZoom);
|
|
|
|
touch->mRefPoint = nsIntPoint(refPoint.x, refPoint.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
gfx::Point refPoint = WidgetSpaceToCompensatedViewportSpace(
|
|
|
|
gfx::Point(aOutEvent->refPoint.x, aOutEvent->refPoint.y),
|
|
|
|
currentZoom);
|
|
|
|
aOutEvent->refPoint = nsIntPoint(refPoint.x, refPoint.y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::HandleInputEvent(const InputData& aEvent) {
|
|
|
|
nsEventStatus rv = nsEventStatus_eIgnore;
|
|
|
|
|
2012-08-08 20:38:10 +00:00
|
|
|
if (mGestureEventListener && !mDisableNextTouchBatch) {
|
2012-07-20 06:48:25 +00:00
|
|
|
nsEventStatus rv = mGestureEventListener->HandleInputEvent(aEvent);
|
|
|
|
if (rv == nsEventStatus_eConsumeNoDefault)
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent.mInputType) {
|
|
|
|
case MULTITOUCH_INPUT: {
|
|
|
|
const MultiTouchInput& multiTouchInput = aEvent.AsMultiTouchInput();
|
|
|
|
switch (multiTouchInput.mType) {
|
|
|
|
case MultiTouchInput::MULTITOUCH_START: rv = OnTouchStart(multiTouchInput); break;
|
|
|
|
case MultiTouchInput::MULTITOUCH_MOVE: rv = OnTouchMove(multiTouchInput); break;
|
|
|
|
case MultiTouchInput::MULTITOUCH_END: rv = OnTouchEnd(multiTouchInput); break;
|
|
|
|
case MultiTouchInput::MULTITOUCH_CANCEL: rv = OnTouchCancel(multiTouchInput); break;
|
|
|
|
default: NS_WARNING("Unhandled multitouch"); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PINCHGESTURE_INPUT: {
|
|
|
|
const PinchGestureInput& pinchGestureInput = aEvent.AsPinchGestureInput();
|
|
|
|
switch (pinchGestureInput.mType) {
|
|
|
|
case PinchGestureInput::PINCHGESTURE_START: rv = OnScaleBegin(pinchGestureInput); break;
|
|
|
|
case PinchGestureInput::PINCHGESTURE_SCALE: rv = OnScale(pinchGestureInput); break;
|
|
|
|
case PinchGestureInput::PINCHGESTURE_END: rv = OnScaleEnd(pinchGestureInput); break;
|
|
|
|
default: NS_WARNING("Unhandled pinch gesture"); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TAPGESTURE_INPUT: {
|
|
|
|
const TapGestureInput& tapGestureInput = aEvent.AsTapGestureInput();
|
|
|
|
switch (tapGestureInput.mType) {
|
|
|
|
case TapGestureInput::TAPGESTURE_LONG: rv = OnLongPress(tapGestureInput); break;
|
|
|
|
case TapGestureInput::TAPGESTURE_UP: rv = OnSingleTapUp(tapGestureInput); break;
|
|
|
|
case TapGestureInput::TAPGESTURE_CONFIRMED: rv = OnSingleTapConfirmed(tapGestureInput); break;
|
|
|
|
case TapGestureInput::TAPGESTURE_DOUBLE: rv = OnDoubleTap(tapGestureInput); break;
|
|
|
|
case TapGestureInput::TAPGESTURE_CANCEL: rv = OnCancelTap(tapGestureInput); break;
|
|
|
|
default: NS_WARNING("Unhandled tap gesture"); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: NS_WARNING("Unhandled input event"); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastEventTime = aEvent.mTime;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnTouchStart(const MultiTouchInput& aEvent) {
|
|
|
|
SingleTouchData& touch = GetFirstSingleTouch(aEvent);
|
|
|
|
|
|
|
|
nsIntPoint point = touch.mScreenPoint;
|
|
|
|
PRInt32 xPos = point.x, yPos = point.y;
|
|
|
|
|
|
|
|
switch (mState) {
|
|
|
|
case FLING:
|
2012-08-08 03:40:48 +00:00
|
|
|
CancelAnimation();
|
2012-07-20 06:48:25 +00:00
|
|
|
// Fall through.
|
|
|
|
case NOTHING:
|
|
|
|
mX.StartTouch(xPos);
|
|
|
|
mY.StartTouch(yPos);
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(TOUCHING);
|
2012-07-20 06:48:25 +00:00
|
|
|
break;
|
|
|
|
case TOUCHING:
|
|
|
|
case PANNING:
|
|
|
|
case PINCHING:
|
|
|
|
NS_WARNING("Received impossible touch in OnTouchStart");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("Unhandled case in OnTouchStart");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnTouchMove(const MultiTouchInput& aEvent) {
|
2012-08-08 20:38:06 +00:00
|
|
|
if (mDisableNextTouchBatch) {
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
switch (mState) {
|
|
|
|
case FLING:
|
|
|
|
case NOTHING:
|
|
|
|
// May happen if the user double-taps and drags without lifting after the
|
|
|
|
// second tap. Ignore the move if this happens.
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
case TOUCHING: {
|
2012-08-08 03:40:48 +00:00
|
|
|
float panThreshold = 1.0f/2.0f * mDPI;
|
2012-08-08 01:51:11 +00:00
|
|
|
UpdateWithTouchAtDevicePoint(aEvent);
|
2012-08-08 20:38:16 +00:00
|
|
|
|
2012-07-23 03:49:07 +00:00
|
|
|
if (PanDistance() < panThreshold) {
|
2012-07-20 06:48:25 +00:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
2012-08-08 20:38:16 +00:00
|
|
|
|
2012-07-23 03:49:07 +00:00
|
|
|
StartPanning(aEvent);
|
2012-08-08 20:38:16 +00:00
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PANNING:
|
|
|
|
TrackTouch(aEvent);
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
|
|
|
case PINCHING:
|
|
|
|
// The scale gesture listener should have handled this.
|
|
|
|
NS_WARNING("Gesture listener should have handled pinching in OnTouchMove.");
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnTouchEnd(const MultiTouchInput& aEvent) {
|
2012-08-08 20:38:06 +00:00
|
|
|
if (mDisableNextTouchBatch) {
|
|
|
|
mDisableNextTouchBatch = false;
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
switch (mState) {
|
|
|
|
case FLING:
|
|
|
|
// Should never happen.
|
|
|
|
NS_WARNING("Received impossible touch end in OnTouchEnd.");
|
|
|
|
// Fall through.
|
|
|
|
case NOTHING:
|
|
|
|
// May happen if the user double-taps and drags without lifting after the
|
|
|
|
// second tap. Ignore if this happens.
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
case TOUCHING:
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(NOTHING);
|
2012-07-20 06:48:25 +00:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
case PANNING:
|
|
|
|
{
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
ScheduleComposite();
|
|
|
|
RequestContentRepaint();
|
|
|
|
}
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(FLING);
|
2012-07-20 06:48:25 +00:00
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
case PINCHING:
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(NOTHING);
|
2012-07-20 06:48:25 +00:00
|
|
|
// Scale gesture listener should have handled this.
|
|
|
|
NS_WARNING("Gesture listener should have handled pinching in OnTouchEnd.");
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnTouchCancel(const MultiTouchInput& aEvent) {
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(NOTHING);
|
2012-07-20 06:48:25 +00:00
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnScaleBegin(const PinchGestureInput& aEvent) {
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(PINCHING);
|
2012-07-20 06:48:25 +00:00
|
|
|
mLastZoomFocus = aEvent.mFocusPoint;
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnScale(const PinchGestureInput& aEvent) {
|
|
|
|
float prevSpan = aEvent.mPreviousSpan;
|
|
|
|
if (fabsf(prevSpan) <= EPSILON || fabsf(aEvent.mCurrentSpan) <= EPSILON) {
|
|
|
|
// We're still handling it; we've just decided to throw this event away.
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
float spanRatio = aEvent.mCurrentSpan / aEvent.mPreviousSpan;
|
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
|
|
|
|
float scale = mFrameMetrics.mResolution.width;
|
|
|
|
|
|
|
|
nsIntPoint focusPoint = aEvent.mFocusPoint;
|
|
|
|
PRInt32 xFocusChange = (mLastZoomFocus.x - focusPoint.x) / scale, yFocusChange = (mLastZoomFocus.y - focusPoint.y) / scale;
|
|
|
|
// If displacing by the change in focus point will take us off page bounds,
|
|
|
|
// then reduce the displacement such that it doesn't.
|
|
|
|
if (mX.DisplacementWillOverscroll(xFocusChange) != Axis::OVERSCROLL_NONE) {
|
|
|
|
xFocusChange -= mX.DisplacementWillOverscrollAmount(xFocusChange);
|
|
|
|
}
|
|
|
|
if (mY.DisplacementWillOverscroll(yFocusChange) != Axis::OVERSCROLL_NONE) {
|
|
|
|
yFocusChange -= mY.DisplacementWillOverscrollAmount(yFocusChange);
|
|
|
|
}
|
|
|
|
ScrollBy(nsIntPoint(xFocusChange, yFocusChange));
|
|
|
|
|
|
|
|
// When we zoom in with focus, we can zoom too much towards the boundaries
|
|
|
|
// that we actually go over them. These are the needed displacements along
|
|
|
|
// either axis such that we don't overscroll the boundaries when zooming.
|
|
|
|
PRInt32 neededDisplacementX = 0, neededDisplacementY = 0;
|
|
|
|
|
|
|
|
// Only do the scaling if we won't go over 8x zoom in or out.
|
2012-08-08 03:40:48 +00:00
|
|
|
bool doScale = (scale < 8.0f && spanRatio > 1.0f) || (scale > 0.125f && spanRatio < 1.0f);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// If this zoom will take it over 8x zoom in either direction, but it's not
|
|
|
|
// already there, then normalize it.
|
2012-08-08 03:40:48 +00:00
|
|
|
if (scale * spanRatio > 8.0f) {
|
|
|
|
spanRatio = scale / 8.0f;
|
|
|
|
} else if (scale * spanRatio < 0.125f) {
|
|
|
|
spanRatio = scale / 0.125f;
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (doScale) {
|
|
|
|
switch (mX.ScaleWillOverscroll(spanRatio, focusPoint.x))
|
|
|
|
{
|
|
|
|
case Axis::OVERSCROLL_NONE:
|
|
|
|
break;
|
|
|
|
case Axis::OVERSCROLL_MINUS:
|
|
|
|
case Axis::OVERSCROLL_PLUS:
|
|
|
|
neededDisplacementX = -mX.ScaleWillOverscrollAmount(spanRatio, focusPoint.x);
|
|
|
|
break;
|
|
|
|
case Axis::OVERSCROLL_BOTH:
|
|
|
|
// If scaling this way will make us overscroll in both directions, then
|
|
|
|
// we must already be at the maximum zoomed out amount. In this case, we
|
|
|
|
// don't want to allow this scaling to go through and instead clamp it
|
|
|
|
// here.
|
|
|
|
doScale = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doScale) {
|
|
|
|
switch (mY.ScaleWillOverscroll(spanRatio, focusPoint.y))
|
|
|
|
{
|
|
|
|
case Axis::OVERSCROLL_NONE:
|
|
|
|
break;
|
|
|
|
case Axis::OVERSCROLL_MINUS:
|
|
|
|
case Axis::OVERSCROLL_PLUS:
|
|
|
|
neededDisplacementY = -mY.ScaleWillOverscrollAmount(spanRatio, focusPoint.y);
|
|
|
|
break;
|
|
|
|
case Axis::OVERSCROLL_BOTH:
|
|
|
|
doScale = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doScale) {
|
|
|
|
ScaleWithFocus(scale * spanRatio,
|
|
|
|
focusPoint);
|
|
|
|
|
|
|
|
if (neededDisplacementX != 0 || neededDisplacementY != 0) {
|
|
|
|
ScrollBy(nsIntPoint(neededDisplacementX, neededDisplacementY));
|
|
|
|
}
|
|
|
|
|
|
|
|
ScheduleComposite();
|
|
|
|
// We don't want to redraw on every scale, so don't use
|
|
|
|
// RequestContentRepaint()
|
|
|
|
}
|
|
|
|
|
|
|
|
mLastZoomFocus = focusPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnScaleEnd(const PinchGestureInput& aEvent) {
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(PANNING);
|
2012-07-20 06:48:25 +00:00
|
|
|
mX.StartTouch(aEvent.mFocusPoint.x);
|
|
|
|
mY.StartTouch(aEvent.mFocusPoint.y);
|
|
|
|
{
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
ScheduleComposite();
|
|
|
|
RequestContentRepaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnLongPress(const TapGestureInput& aEvent) {
|
|
|
|
// XXX: Implement this.
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnSingleTapUp(const TapGestureInput& aEvent) {
|
|
|
|
// XXX: Implement this.
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnSingleTapConfirmed(const TapGestureInput& aEvent) {
|
|
|
|
// XXX: Implement this.
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnDoubleTap(const TapGestureInput& aEvent) {
|
2012-08-08 03:40:48 +00:00
|
|
|
// XXX: Implement this.
|
2012-07-20 06:48:25 +00:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus AsyncPanZoomController::OnCancelTap(const TapGestureInput& aEvent) {
|
|
|
|
// XXX: Implement this.
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2012-07-23 03:49:07 +00:00
|
|
|
float AsyncPanZoomController::PanDistance() {
|
2012-08-08 20:38:16 +00:00
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
return NS_hypot(mX.PanDistance(), mY.PanDistance());
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 20:38:23 +00:00
|
|
|
const gfx::Point AsyncPanZoomController::GetVelocityVector() {
|
|
|
|
return gfx::Point(mX.GetVelocity(), mY.GetVelocity());
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 03:49:07 +00:00
|
|
|
void AsyncPanZoomController::StartPanning(const MultiTouchInput& aEvent) {
|
|
|
|
SingleTouchData& touch = GetFirstSingleTouch(aEvent);
|
|
|
|
|
|
|
|
float dx = mX.PanDistance(),
|
|
|
|
dy = mY.PanDistance();
|
|
|
|
|
|
|
|
double angle = atan2(dy, dx); // range [-pi, pi]
|
|
|
|
angle = fabs(angle); // range [0, pi]
|
|
|
|
|
|
|
|
mX.StartTouch(touch.mScreenPoint.x);
|
|
|
|
mY.StartTouch(touch.mScreenPoint.y);
|
2012-08-08 20:38:20 +00:00
|
|
|
SetState(PANNING);
|
2012-07-23 03:49:07 +00:00
|
|
|
|
|
|
|
if (angle < AXIS_LOCK_ANGLE || angle > (M_PI - AXIS_LOCK_ANGLE)) {
|
|
|
|
mY.LockPanning();
|
|
|
|
} else if (fabsf(angle - M_PI / 2) < AXIS_LOCK_ANGLE) {
|
|
|
|
mX.LockPanning();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::UpdateWithTouchAtDevicePoint(const MultiTouchInput& aEvent) {
|
2012-07-20 06:48:25 +00:00
|
|
|
SingleTouchData& touch = GetFirstSingleTouch(aEvent);
|
|
|
|
nsIntPoint point = touch.mScreenPoint;
|
2012-07-23 01:43:37 +00:00
|
|
|
PRInt32 xPos = point.x, yPos = point.y;
|
|
|
|
TimeDuration timeDelta = TimeDuration().FromMilliseconds(aEvent.mTime - mLastEventTime);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// Probably a duplicate event, just throw it away.
|
2012-07-23 01:43:37 +00:00
|
|
|
if (timeDelta.ToMilliseconds() <= EPSILON) {
|
2012-07-20 06:48:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-23 03:49:07 +00:00
|
|
|
mX.UpdateWithTouchAtDevicePoint(xPos, timeDelta);
|
|
|
|
mY.UpdateWithTouchAtDevicePoint(yPos, timeDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::TrackTouch(const MultiTouchInput& aEvent) {
|
|
|
|
TimeDuration timeDelta = TimeDuration().FromMilliseconds(aEvent.mTime - mLastEventTime);
|
|
|
|
|
|
|
|
// Probably a duplicate event, just throw it away.
|
|
|
|
if (timeDelta.ToMilliseconds() <= EPSILON) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateWithTouchAtDevicePoint(aEvent);
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
{
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
|
|
|
|
// We want to inversely scale it because when you're zoomed further in, a
|
|
|
|
// larger swipe should move you a shorter distance.
|
|
|
|
float inverseScale = 1 / mFrameMetrics.mResolution.width;
|
|
|
|
|
2012-07-23 01:43:37 +00:00
|
|
|
PRInt32 xDisplacement = mX.GetDisplacementForDuration(inverseScale, timeDelta);
|
|
|
|
PRInt32 yDisplacement = mY.GetDisplacementForDuration(inverseScale, timeDelta);
|
2012-07-20 06:48:25 +00:00
|
|
|
if (!xDisplacement && !yDisplacement) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollBy(nsIntPoint(xDisplacement, yDisplacement));
|
|
|
|
ScheduleComposite();
|
|
|
|
|
2012-07-27 07:33:57 +00:00
|
|
|
RequestContentRepaint();
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SingleTouchData& AsyncPanZoomController::GetFirstSingleTouch(const MultiTouchInput& aEvent) {
|
|
|
|
return (SingleTouchData&)aEvent.mTouches[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsyncPanZoomController::DoFling(const TimeDuration& aDelta) {
|
|
|
|
if (mState != FLING) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-23 01:50:41 +00:00
|
|
|
bool shouldContinueFlingX = mX.FlingApplyFrictionOrCancel(aDelta),
|
|
|
|
shouldContinueFlingY = mY.FlingApplyFrictionOrCancel(aDelta);
|
|
|
|
// If we shouldn't continue the fling, let's just stop and repaint.
|
|
|
|
if (!shouldContinueFlingX && !shouldContinueFlingY) {
|
2012-07-20 06:48:25 +00:00
|
|
|
RequestContentRepaint();
|
|
|
|
mState = NOTHING;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to inversely scale it because when you're zoomed further in, a
|
|
|
|
// larger swipe should move you a shorter distance.
|
|
|
|
float inverseScale = 1 / mFrameMetrics.mResolution.width;
|
|
|
|
|
|
|
|
ScrollBy(nsIntPoint(
|
2012-07-23 01:43:37 +00:00
|
|
|
mX.GetDisplacementForDuration(inverseScale, aDelta),
|
|
|
|
mY.GetDisplacementForDuration(inverseScale, aDelta)
|
2012-07-20 06:48:25 +00:00
|
|
|
));
|
|
|
|
RequestContentRepaint();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::CancelAnimation() {
|
|
|
|
mState = NOTHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::SetCompositorParent(CompositorParent* aCompositorParent) {
|
|
|
|
mCompositorParent = aCompositorParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::ScrollBy(const nsIntPoint& aOffset) {
|
|
|
|
nsIntPoint newOffset(mFrameMetrics.mViewportScrollOffset.x + aOffset.x,
|
|
|
|
mFrameMetrics.mViewportScrollOffset.y + aOffset.y);
|
|
|
|
FrameMetrics metrics(mFrameMetrics);
|
|
|
|
metrics.mViewportScrollOffset = newOffset;
|
|
|
|
mFrameMetrics = metrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::SetPageRect(const gfx::Rect& aCSSPageRect) {
|
|
|
|
FrameMetrics metrics = mFrameMetrics;
|
|
|
|
gfx::Rect pageSize = aCSSPageRect;
|
|
|
|
float scale = mFrameMetrics.mResolution.width;
|
|
|
|
|
|
|
|
// The page rect is the css page rect scaled by the current zoom.
|
2012-08-08 03:40:48 +00:00
|
|
|
pageSize.ScaleRoundOut(scale);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// Round the page rect so we don't get any truncation, then get the nsIntRect
|
|
|
|
// from this.
|
|
|
|
metrics.mContentRect = nsIntRect(pageSize.x, pageSize.y, pageSize.width, pageSize.height);
|
|
|
|
metrics.mCSSContentRect = aCSSPageRect;
|
|
|
|
|
|
|
|
mFrameMetrics = metrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::ScaleWithFocus(float aScale, const nsIntPoint& aFocus) {
|
|
|
|
FrameMetrics metrics(mFrameMetrics);
|
|
|
|
|
|
|
|
// Don't set the scale to the inputted value, but rather multiply it in.
|
2012-08-08 20:38:14 +00:00
|
|
|
float scaleFactor = aScale / metrics.mResolution.width,
|
|
|
|
oldScale = metrics.mResolution.width;
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
metrics.mResolution.width = metrics.mResolution.height = aScale;
|
|
|
|
|
|
|
|
// Force a recalculation of the page rect based on the new zoom and the
|
|
|
|
// current CSS page rect (which is unchanged since it's not affected by zoom).
|
|
|
|
SetPageRect(mFrameMetrics.mCSSContentRect);
|
|
|
|
|
|
|
|
nsIntPoint scrollOffset = metrics.mViewportScrollOffset;
|
|
|
|
|
2012-08-08 20:38:14 +00:00
|
|
|
scrollOffset.x += NS_lround(float(aFocus.x) * (scaleFactor - 1.0f) / oldScale);
|
|
|
|
scrollOffset.y += NS_lround(float(aFocus.y) * (scaleFactor - 1.0f) / oldScale);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
metrics.mViewportScrollOffset = scrollOffset;
|
|
|
|
|
|
|
|
mFrameMetrics = metrics;
|
|
|
|
}
|
|
|
|
|
2012-08-08 20:38:23 +00:00
|
|
|
bool AsyncPanZoomController::EnlargeDisplayPortAlongAxis(float aViewport,
|
|
|
|
float aVelocity,
|
|
|
|
float* aDisplayPortOffset,
|
|
|
|
float* aDisplayPortLength)
|
|
|
|
{
|
|
|
|
const float MIN_SKATE_SIZE_MULTIPLIER = 2.0f;
|
|
|
|
const float MAX_SKATE_SIZE_MULTIPLIER = 4.0f;
|
|
|
|
|
|
|
|
if (fabsf(aVelocity) > MIN_SKATE_SPEED) {
|
|
|
|
*aDisplayPortLength = aViewport * clamped(fabsf(aVelocity),
|
|
|
|
MIN_SKATE_SIZE_MULTIPLIER, MAX_SKATE_SIZE_MULTIPLIER);
|
|
|
|
*aDisplayPortOffset = aVelocity > 0 ? 0 : aViewport - *aDisplayPortLength;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
const nsIntRect AsyncPanZoomController::CalculatePendingDisplayPort() {
|
|
|
|
float scale = mFrameMetrics.mResolution.width;
|
|
|
|
nsIntRect viewport = mFrameMetrics.mViewport;
|
|
|
|
viewport.ScaleRoundIn(1 / scale);
|
|
|
|
|
|
|
|
nsIntPoint scrollOffset = mFrameMetrics.mViewportScrollOffset;
|
2012-08-08 20:38:23 +00:00
|
|
|
gfx::Point velocity = GetVelocityVector();
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// The displayport is relative to the current scroll offset. Here's a little
|
|
|
|
// diagram to make it easier to see:
|
|
|
|
//
|
|
|
|
// - - - -
|
|
|
|
// | |
|
|
|
|
// *************
|
|
|
|
// * | | *
|
|
|
|
// - -*- @------ -*- -
|
|
|
|
// | * |=====| * |
|
|
|
|
// * |=====| *
|
|
|
|
// | * |=====| * |
|
|
|
|
// - -*- ------- -*- -
|
|
|
|
// * | | *
|
|
|
|
// *************
|
|
|
|
// | |
|
|
|
|
// - - - -
|
|
|
|
//
|
|
|
|
// The full --- area with === inside it is the actual viewport rect, the *** area
|
|
|
|
// is the displayport, and the - - - area is an imaginary additional page on all 4
|
|
|
|
// borders of the actual page. Notice that the displayport intersects half-way with
|
|
|
|
// each of the imaginary extra pages. The @ symbol at the top left of the
|
|
|
|
// viewport marks the current scroll offset. From the @ symbol to the far left
|
|
|
|
// and far top, it is clear that this distance is 1/4 of the displayport's
|
|
|
|
// height/width dimension.
|
2012-07-23 01:51:23 +00:00
|
|
|
const float STATIONARY_SIZE_MULTIPLIER = 2.0f;
|
|
|
|
gfx::Rect displayPort(0, 0,
|
|
|
|
viewport.width * STATIONARY_SIZE_MULTIPLIER,
|
|
|
|
viewport.height * STATIONARY_SIZE_MULTIPLIER);
|
|
|
|
|
2012-08-08 20:38:23 +00:00
|
|
|
// If there's motion along an axis of movement, and it's above a threshold,
|
|
|
|
// then we want to paint a larger area in the direction of that motion so that
|
|
|
|
// it's less likely to checkerboard.
|
|
|
|
bool enlargedX = EnlargeDisplayPortAlongAxis(
|
|
|
|
viewport.width, velocity.x, &displayPort.x, &displayPort.width);
|
|
|
|
bool enlargedY = EnlargeDisplayPortAlongAxis(
|
|
|
|
viewport.height, velocity.y, &displayPort.y, &displayPort.height);
|
|
|
|
|
|
|
|
if (!enlargedX && !enlargedY) {
|
2012-07-23 01:51:23 +00:00
|
|
|
displayPort.x = -displayPort.width / 4;
|
|
|
|
displayPort.y = -displayPort.height / 4;
|
2012-08-08 20:38:23 +00:00
|
|
|
} else if (!enlargedX) {
|
|
|
|
displayPort.width = viewport.width;
|
|
|
|
} else if (!enlargedY) {
|
|
|
|
displayPort.height = viewport.height;
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 01:51:23 +00:00
|
|
|
gfx::Rect shiftedDisplayPort = displayPort;
|
2012-07-27 07:33:53 +00:00
|
|
|
shiftedDisplayPort.MoveBy(scrollOffset.x, scrollOffset.y);
|
2012-07-23 01:51:23 +00:00
|
|
|
displayPort = shiftedDisplayPort.Intersect(mFrameMetrics.mCSSContentRect);
|
2012-07-27 07:33:53 +00:00
|
|
|
displayPort.MoveBy(-scrollOffset.x, -scrollOffset.y);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// Round the displayport so we don't get any truncation, then get the nsIntRect
|
|
|
|
// from this.
|
|
|
|
displayPort.Round();
|
|
|
|
return nsIntRect(displayPort.x, displayPort.y, displayPort.width, displayPort.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::SetDPI(int aDPI) {
|
|
|
|
mDPI = aDPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::ScheduleComposite() {
|
|
|
|
if (mCompositorParent) {
|
|
|
|
mCompositorParent->ScheduleRenderOnCompositorThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::RequestContentRepaint() {
|
|
|
|
mFrameMetrics.mDisplayPort = CalculatePendingDisplayPort();
|
2012-07-27 07:33:48 +00:00
|
|
|
|
|
|
|
// If we're trying to paint what we already think is painted, discard this
|
|
|
|
// request since it's a pointless paint.
|
|
|
|
nsIntRect oldDisplayPort = mLastPaintRequestMetrics.mDisplayPort,
|
|
|
|
newDisplayPort = mFrameMetrics.mDisplayPort;
|
|
|
|
oldDisplayPort.MoveBy(mLastPaintRequestMetrics.mViewportScrollOffset);
|
|
|
|
newDisplayPort.MoveBy(mFrameMetrics.mViewportScrollOffset);
|
|
|
|
|
|
|
|
if (oldDisplayPort.IsEqualEdges(newDisplayPort) &&
|
|
|
|
mFrameMetrics.mResolution.width == mLastPaintRequestMetrics.mResolution.width) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mContentPainterStatus == CONTENT_IDLE) {
|
|
|
|
mContentPainterStatus = CONTENT_PAINTING;
|
|
|
|
mLastPaintRequestMetrics = mFrameMetrics;
|
|
|
|
mGeckoContentController->RequestContentRepaint(mFrameMetrics);
|
|
|
|
} else {
|
|
|
|
mContentPainterStatus = CONTENT_PAINTING_AND_PAINT_PENDING;
|
|
|
|
}
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AsyncPanZoomController::SampleContentTransformForFrame(const TimeStamp& aSampleTime,
|
2012-08-03 21:29:22 +00:00
|
|
|
ContainerLayer* aLayer,
|
2012-07-20 06:48:25 +00:00
|
|
|
gfx3DMatrix* aNewTransform) {
|
|
|
|
// The eventual return value of this function. The compositor needs to know
|
|
|
|
// whether or not to advance by a frame as soon as it can. For example, if a
|
|
|
|
// fling is happening, it has to keep compositing so that the animation is
|
|
|
|
// smooth. If an animation frame is requested, it is the compositor's
|
|
|
|
// responsibility to schedule a composite.
|
|
|
|
bool requestAnimationFrame = false;
|
|
|
|
|
2012-07-31 23:19:25 +00:00
|
|
|
const gfx3DMatrix& currentTransform = aLayer->GetTransform();
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
// Scales on the root layer, on what's currently painted.
|
2012-07-31 23:19:25 +00:00
|
|
|
float rootScaleX = currentTransform.GetXScale(),
|
|
|
|
rootScaleY = currentTransform.GetYScale();
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
nsIntPoint metricsScrollOffset(0, 0);
|
|
|
|
nsIntPoint scrollOffset;
|
|
|
|
float localScaleX, localScaleY;
|
2012-08-03 21:29:22 +00:00
|
|
|
const FrameMetrics& frame = aLayer->GetFrameMetrics();
|
2012-07-20 06:48:25 +00:00
|
|
|
{
|
|
|
|
MonitorAutoLock mon(mMonitor);
|
|
|
|
|
2012-08-08 03:40:48 +00:00
|
|
|
// If a fling is currently happening, apply it now. We can pull the updated
|
|
|
|
// metrics afterwards.
|
|
|
|
requestAnimationFrame = requestAnimationFrame || DoFling(aSampleTime - mLastSampleTime);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
// Current local transform; this is not what's painted but rather what PZC has
|
|
|
|
// transformed due to touches like panning or pinching. Eventually, the root
|
|
|
|
// layer transform will become this during runtime, but we must wait for Gecko
|
|
|
|
// to repaint.
|
|
|
|
localScaleX = mFrameMetrics.mResolution.width;
|
|
|
|
localScaleY = mFrameMetrics.mResolution.height;
|
|
|
|
|
2012-08-03 21:29:22 +00:00
|
|
|
if (frame.IsScrollable()) {
|
|
|
|
metricsScrollOffset = frame.mViewportScrollOffset;
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scrollOffset = mFrameMetrics.mViewportScrollOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint scrollCompensation(
|
|
|
|
(scrollOffset.x / rootScaleX - metricsScrollOffset.x) * localScaleX,
|
|
|
|
(scrollOffset.y / rootScaleY - metricsScrollOffset.y) * localScaleY);
|
|
|
|
|
|
|
|
ViewTransform treeTransform(-scrollCompensation, localScaleX, localScaleY);
|
2012-07-31 23:19:25 +00:00
|
|
|
*aNewTransform = gfx3DMatrix(treeTransform) * currentTransform;
|
|
|
|
|
|
|
|
// The transform already takes the resolution scale into account. Since we
|
|
|
|
// will apply the resolution scale again when computing the effective
|
|
|
|
// transform, we must apply the inverse resolution scale here.
|
2012-08-03 21:29:22 +00:00
|
|
|
aNewTransform->Scale(1.0f/aLayer->GetPreXScale(),
|
|
|
|
1.0f/aLayer->GetPreYScale(),
|
2012-07-31 23:19:25 +00:00
|
|
|
1);
|
2012-08-03 21:29:22 +00:00
|
|
|
aNewTransform->ScalePost(1.0f/aLayer->GetPostXScale(),
|
|
|
|
1.0f/aLayer->GetPostYScale(),
|
|
|
|
1);
|
2012-07-20 06:48:25 +00:00
|
|
|
|
|
|
|
mLastSampleTime = aSampleTime;
|
|
|
|
|
|
|
|
return requestAnimationFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::NotifyLayersUpdated(const FrameMetrics& aViewportFrame, bool aIsFirstPaint) {
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
|
|
|
|
mLastContentPaintMetrics = aViewportFrame;
|
|
|
|
|
2012-07-27 07:33:48 +00:00
|
|
|
if (mContentPainterStatus != CONTENT_IDLE) {
|
|
|
|
if (mContentPainterStatus == CONTENT_PAINTING_AND_PAINT_PENDING) {
|
|
|
|
mContentPainterStatus = CONTENT_IDLE;
|
|
|
|
RequestContentRepaint();
|
|
|
|
} else {
|
|
|
|
mContentPainterStatus = CONTENT_IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
if (aIsFirstPaint || mFrameMetrics.IsDefault()) {
|
2012-07-27 07:33:48 +00:00
|
|
|
mContentPainterStatus = CONTENT_IDLE;
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
mX.StopTouch();
|
|
|
|
mY.StopTouch();
|
|
|
|
mFrameMetrics = aViewportFrame;
|
|
|
|
mFrameMetrics.mResolution.width = 1 / mFrameMetrics.mResolution.width;
|
|
|
|
mFrameMetrics.mResolution.height = 1 / mFrameMetrics.mResolution.height;
|
|
|
|
SetPageRect(mFrameMetrics.mCSSContentRect);
|
2012-07-23 01:51:38 +00:00
|
|
|
|
|
|
|
// Bug 776413/fixme: Request a repaint as soon as a page is loaded so that
|
|
|
|
// we get a larger displayport. This is very bad because we're wasting a
|
|
|
|
// paint and not initializating the displayport correctly.
|
|
|
|
RequestContentRepaint();
|
2012-08-08 20:37:57 +00:00
|
|
|
|
|
|
|
// Assuming a first paint means a new page has been loaded, clear the flag
|
|
|
|
// indicating that we may have touch listeners.
|
|
|
|
mMayHaveTouchListeners = false;
|
2012-08-08 03:40:48 +00:00
|
|
|
} else if (!mFrameMetrics.mContentRect.IsEqualEdges(aViewportFrame.mContentRect)) {
|
2012-07-20 06:48:25 +00:00
|
|
|
mFrameMetrics.mCSSContentRect = aViewportFrame.mCSSContentRect;
|
|
|
|
SetPageRect(mFrameMetrics.mCSSContentRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const FrameMetrics& AsyncPanZoomController::GetFrameMetrics() {
|
|
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
|
|
return mFrameMetrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncPanZoomController::UpdateViewportSize(int aWidth, int aHeight) {
|
|
|
|
MonitorAutoLock mon(mMonitor);
|
|
|
|
FrameMetrics metrics = GetFrameMetrics();
|
|
|
|
metrics.mViewport = nsIntRect(0, 0, aWidth, aHeight);
|
|
|
|
mFrameMetrics = metrics;
|
|
|
|
}
|
|
|
|
|
2012-08-08 20:37:57 +00:00
|
|
|
void AsyncPanZoomController::NotifyDOMTouchListenerAdded() {
|
|
|
|
mMayHaveTouchListeners = true;
|
|
|
|
}
|
|
|
|
|
2012-08-08 20:38:06 +00:00
|
|
|
void AsyncPanZoomController::CancelDefaultPanZoom() {
|
|
|
|
mDisableNextTouchBatch = true;
|
2012-08-08 20:38:10 +00:00
|
|
|
if (mGestureEventListener) {
|
|
|
|
mGestureEventListener->CancelGesture();
|
|
|
|
}
|
2012-08-08 20:38:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 20:38:20 +00:00
|
|
|
void AsyncPanZoomController::SetState(PanZoomState aState) {
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
mState = aState;
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:48:25 +00:00
|
|
|
}
|
|
|
|
}
|