2012-07-19 23:48:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-10-02 18:03:04 -07:00
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
2012-07-19 23:48:25 -07: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_layers_AsyncPanZoomController_h
|
|
|
|
#define mozilla_layers_AsyncPanZoomController_h
|
|
|
|
|
|
|
|
#include "GeckoContentController.h"
|
2012-07-20 13:49:12 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-24 03:04:14 -07:00
|
|
|
#include "mozilla/EventForwards.h"
|
2012-07-19 23:48:25 -07:00
|
|
|
#include "mozilla/Monitor.h"
|
2013-07-31 05:53:16 -07:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2012-07-19 23:48:25 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "InputData.h"
|
|
|
|
#include "Axis.h"
|
2012-12-10 05:50:24 -08:00
|
|
|
#include "TaskThrottler.h"
|
2013-08-06 13:20:14 -07:00
|
|
|
#include "gfx3DMatrix.h"
|
2012-07-19 23:48:25 -07:00
|
|
|
|
2012-08-21 21:37:06 -07:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
struct ScrollableLayerGuid;
|
2012-07-19 23:48:25 -07:00
|
|
|
class CompositorParent;
|
|
|
|
class GestureEventListener;
|
2012-08-03 14:29:22 -07:00
|
|
|
class ContainerLayer;
|
2012-12-23 07:50:04 -08:00
|
|
|
class ViewTransform;
|
2013-08-20 15:10:47 -07:00
|
|
|
class APZCTreeManager;
|
2012-07-19 23:48:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller for all panning and zooming logic. Any time a user input is
|
|
|
|
* detected and it must be processed in some way to affect what the user sees,
|
|
|
|
* it goes through here. Listens for any input event from InputData and can
|
2013-10-01 20:46:03 -07:00
|
|
|
* optionally handle WidgetGUIEvent-derived touch events, but this must be done
|
|
|
|
* on the main thread. Note that this class completely cross-platform.
|
2012-07-19 23:48:25 -07:00
|
|
|
*
|
|
|
|
* Input events originate on the UI thread of the platform that this runs on,
|
|
|
|
* and are then sent to this class. This class processes the event in some way;
|
|
|
|
* for example, a touch move will usually lead to a panning of content (though
|
|
|
|
* of course there are exceptions, such as if content preventDefaults the event,
|
|
|
|
* or if the target frame is not scrollable). The compositor interacts with this
|
|
|
|
* class by locking it and querying it for the current transform matrix based on
|
|
|
|
* the panning and zooming logic that was invoked on the UI thread.
|
|
|
|
*
|
|
|
|
* Currently, each outer DOM window (i.e. a website in a tab, but not any
|
|
|
|
* subframes) has its own AsyncPanZoomController. In the future, to support
|
|
|
|
* asynchronously scrolled subframes, we want to have one AsyncPanZoomController
|
|
|
|
* per frame.
|
|
|
|
*/
|
2013-07-30 11:03:40 -07:00
|
|
|
class AsyncPanZoomController {
|
2012-07-19 23:48:25 -07:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AsyncPanZoomController)
|
|
|
|
|
|
|
|
typedef mozilla::MonitorAutoLock MonitorAutoLock;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum GestureBehavior {
|
|
|
|
// The platform code is responsible for forwarding gesture events here. We
|
|
|
|
// will not attempt to generate gesture events from MultiTouchInputs.
|
|
|
|
DEFAULT_GESTURES,
|
|
|
|
// An instance of GestureEventListener is used to detect gestures. This is
|
|
|
|
// handled completely internally within this class.
|
|
|
|
USE_GESTURE_DETECTOR
|
|
|
|
};
|
|
|
|
|
2012-08-08 21:39:11 -07:00
|
|
|
/**
|
|
|
|
* Constant describing the tolerance in distance we use, multiplied by the
|
|
|
|
* device DPI, before we start panning the screen. This is to prevent us from
|
|
|
|
* accidentally processing taps as touch moves, and from very short/accidental
|
|
|
|
* touches moving the screen.
|
|
|
|
*/
|
2013-01-09 22:11:25 -08:00
|
|
|
static float GetTouchStartTolerance();
|
2012-08-08 21:39:11 -07:00
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
AsyncPanZoomController(uint64_t aLayersId,
|
2013-08-20 15:10:47 -07:00
|
|
|
APZCTreeManager* aTreeManager,
|
2013-07-30 11:03:40 -07:00
|
|
|
GeckoContentController* aController,
|
2012-07-19 23:48:25 -07:00
|
|
|
GestureBehavior aGestures = DEFAULT_GESTURES);
|
|
|
|
~AsyncPanZoomController();
|
|
|
|
|
2013-07-30 11:03:39 -07:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// These methods must only be called on the gecko thread.
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read the various prefs and do any global initialization for all APZC instances.
|
|
|
|
* This must be run on the gecko thread before any APZC instances are actually
|
|
|
|
* used for anything meaningful.
|
|
|
|
*/
|
|
|
|
static void InitializeGlobalState();
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// These methods must only be called on the controller/UI thread.
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General handler for incoming input events. Manipulates the frame metrics
|
2013-07-22 19:33:05 -07:00
|
|
|
* based on what type of input it is. For example, a PinchGestureEvent will
|
2012-08-21 21:37:06 -07:00
|
|
|
* cause scaling. This should only be called externally to this class.
|
|
|
|
* HandleInputEvent() should be used internally.
|
2012-07-19 23:48:25 -07:00
|
|
|
*/
|
2012-08-21 21:37:06 -07:00
|
|
|
nsEventStatus ReceiveInputEvent(const InputData& aEvent);
|
2012-07-19 23:48:25 -07:00
|
|
|
|
|
|
|
/**
|
2012-09-28 19:16:34 -07:00
|
|
|
* Updates the composition bounds, i.e. the dimensions of the final size of
|
|
|
|
* the frame this is tied to during composition onto, in device pixels. In
|
|
|
|
* general, this will just be:
|
|
|
|
* { x = 0, y = 0, width = surface.width, height = surface.height }, however
|
|
|
|
* there is no hard requirement for this.
|
2012-07-19 23:48:25 -07:00
|
|
|
*/
|
2013-06-14 13:11:29 -07:00
|
|
|
void UpdateCompositionBounds(const ScreenIntRect& aCompositionBounds);
|
2012-07-19 23:48:25 -07:00
|
|
|
|
2012-08-08 13:38:06 -07:00
|
|
|
/**
|
2013-01-05 06:53:16 -08:00
|
|
|
* We are scrolling a subframe, so disable our machinery until we hit
|
2012-08-08 13:38:06 -07:00
|
|
|
* a touch end or a new touch start. This prevents us from accidentally
|
|
|
|
* panning both the subframe and the parent frame.
|
|
|
|
*
|
|
|
|
* XXX/bug 775452: We should eventually be supporting async scrollable
|
|
|
|
* subframes.
|
|
|
|
*/
|
|
|
|
void CancelDefaultPanZoom();
|
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
/**
|
|
|
|
* We have found a scrollable subframe, so we need to delay the scrolling
|
|
|
|
* gesture executed and let subframe do the scrolling first.
|
|
|
|
*/
|
|
|
|
void DetectScrollableSubframe();
|
|
|
|
|
2012-08-08 21:39:02 -07:00
|
|
|
/**
|
|
|
|
* Kicks an animation to zoom to a rect. This may be either a zoom out or zoom
|
|
|
|
* in. The actual animation is done on the compositor thread after being set
|
2013-07-11 07:43:35 -07:00
|
|
|
* up.
|
2012-08-08 21:39:02 -07:00
|
|
|
*/
|
2013-07-11 07:43:35 -07:00
|
|
|
void ZoomToRect(CSSRect aRect);
|
2012-08-08 21:39:02 -07:00
|
|
|
|
2012-08-21 21:37:06 -07:00
|
|
|
/**
|
|
|
|
* If we have touch listeners, this should always be called when we know
|
|
|
|
* definitively whether or not content has preventDefaulted any touch events
|
|
|
|
* that have come in. If |aPreventDefault| is true, any touch events in the
|
|
|
|
* queue will be discarded.
|
|
|
|
*/
|
|
|
|
void ContentReceivedTouch(bool aPreventDefault);
|
|
|
|
|
2012-09-28 19:18:18 -07:00
|
|
|
/**
|
|
|
|
* Updates any zoom constraints contained in the <meta name="viewport"> tag.
|
|
|
|
* We try to obey everything it asks us elsewhere, but here we only handle
|
|
|
|
* minimum-scale, maximum-scale, and user-scalable.
|
|
|
|
*/
|
2013-08-26 06:50:30 -07:00
|
|
|
void UpdateZoomConstraints(bool aAllowZoom,
|
|
|
|
const mozilla::CSSToScreenScale& aMinScale,
|
|
|
|
const mozilla::CSSToScreenScale& aMaxScale);
|
2012-09-28 19:18:18 -07:00
|
|
|
|
2013-02-25 12:50:49 -08:00
|
|
|
/**
|
|
|
|
* Schedules a runnable to run on the controller/UI thread at some time
|
|
|
|
* in the future.
|
|
|
|
*/
|
|
|
|
void PostDelayedTask(Task* aTask, int aDelayMs);
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// These methods must only be called on the compositor thread.
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The compositor calls this when it's about to draw pannable/zoomable content
|
|
|
|
* and is setting up transforms for compositing the layer tree. This is not
|
|
|
|
* idempotent. For example, a fling transform can be applied each time this is
|
|
|
|
* called (though not necessarily). |aSampleTime| is the time that this is
|
|
|
|
* sampled at; this is used for interpolating animations. Calling this sets a
|
2013-07-30 11:03:40 -07:00
|
|
|
* new transform in |aNewTransform| which should be multiplied to the transform
|
|
|
|
* in the shadow layer corresponding to this APZC.
|
2012-07-19 23:48:25 -07:00
|
|
|
*
|
|
|
|
* Return value indicates whether or not any currently running animation
|
|
|
|
* should continue. That is, if true, the compositor should schedule another
|
|
|
|
* composite.
|
|
|
|
*/
|
|
|
|
bool SampleContentTransformForFrame(const TimeStamp& aSampleTime,
|
2013-04-26 10:26:39 -07:00
|
|
|
ViewTransform* aNewTransform,
|
2013-06-14 13:11:29 -07:00
|
|
|
ScreenPoint& aScrollOffset);
|
2012-07-19 23:48:25 -07:00
|
|
|
|
|
|
|
/**
|
2013-07-30 11:03:40 -07:00
|
|
|
* A shadow layer update has arrived. |aLayerMetrics| is the new FrameMetrics
|
|
|
|
* for the container layer corresponding to this APZC.
|
|
|
|
* |aIsFirstPaint| is a flag passed from the shadow
|
2012-07-19 23:48:25 -07:00
|
|
|
* layers code indicating that the frame metrics being sent with this call are
|
|
|
|
* the initial metrics and the initial paint of the frame has just happened.
|
|
|
|
*/
|
2013-07-30 11:03:40 -07:00
|
|
|
void NotifyLayersUpdated(const FrameMetrics& aLayerMetrics, bool aIsFirstPaint);
|
2012-07-19 23:48:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The platform implementation must set the compositor parent so that we can
|
|
|
|
* request composites.
|
|
|
|
*/
|
|
|
|
void SetCompositorParent(CompositorParent* aCompositorParent);
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// These methods can be called from any thread.
|
|
|
|
//
|
|
|
|
|
2013-07-30 11:03:39 -07:00
|
|
|
/**
|
|
|
|
* Shut down the controller/UI thread state and prepare to be
|
|
|
|
* deleted (which may happen from any thread).
|
|
|
|
*/
|
|
|
|
void Destroy();
|
|
|
|
|
2013-07-30 11:03:41 -07:00
|
|
|
/**
|
|
|
|
* Returns the incremental transformation corresponding to the async pan/zoom
|
|
|
|
* in progress. That is, when this transform is multiplied with the layer's
|
|
|
|
* existing transform, it will make the layer appear with the desired pan/zoom
|
|
|
|
* amount.
|
|
|
|
*/
|
|
|
|
ViewTransform GetCurrentAsyncTransform();
|
|
|
|
|
2012-09-28 19:18:18 -07:00
|
|
|
/**
|
|
|
|
* Recalculates the displayport. Ideally, this should paint an area bigger
|
|
|
|
* than the composite-to dimensions so that when you scroll down, you don't
|
|
|
|
* checkerboard immediately. This includes a bunch of logic, including
|
|
|
|
* algorithms to bias painting in the direction of the velocity.
|
|
|
|
*/
|
2013-06-10 06:05:42 -07:00
|
|
|
static const CSSRect CalculatePendingDisplayPort(
|
2012-09-28 19:18:18 -07:00
|
|
|
const FrameMetrics& aFrameMetrics,
|
2012-09-28 21:02:45 -07:00
|
|
|
const gfx::Point& aVelocity,
|
|
|
|
const gfx::Point& aAcceleration,
|
|
|
|
double aEstimatedPaintDuration);
|
2012-09-28 19:18:18 -07:00
|
|
|
|
2012-12-24 22:09:34 -08:00
|
|
|
/**
|
|
|
|
* Send an mozbrowserasyncscroll event.
|
|
|
|
* *** The monitor must be held while calling this.
|
|
|
|
*/
|
|
|
|
void SendAsyncScrollEvent();
|
|
|
|
|
2012-08-21 21:37:06 -07:00
|
|
|
/**
|
2013-01-10 08:10:23 -08:00
|
|
|
* Handler for events which should not be intercepted by the touch listener.
|
|
|
|
* Does the work for ReceiveInputEvent().
|
2012-08-21 21:37:06 -07:00
|
|
|
*/
|
|
|
|
nsEventStatus HandleInputEvent(const InputData& aEvent);
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
/**
|
|
|
|
* Returns true if this APZC instance is for the layer identified by the guid.
|
|
|
|
*/
|
|
|
|
bool Matches(const ScrollableLayerGuid& aGuid);
|
|
|
|
|
2013-06-24 12:24:42 -07:00
|
|
|
/**
|
|
|
|
* Sync panning and zooming animation using a fixed frame time.
|
|
|
|
* This will ensure that we animate the APZC correctly with other external
|
|
|
|
* animations to the same timestamp.
|
|
|
|
*/
|
|
|
|
static void SetFrameTime(const TimeStamp& aMilliseconds);
|
|
|
|
|
2013-07-22 19:33:05 -07:00
|
|
|
/**
|
|
|
|
* Update mFrameMetrics.mScrollOffset to the given offset.
|
|
|
|
* This is necessary in cases where a scroll is not caused by user
|
|
|
|
* input (for example, a content scrollTo()).
|
|
|
|
*/
|
2013-07-30 11:03:40 -07:00
|
|
|
void UpdateScrollOffset(const CSSPoint& aScrollOffset);
|
2013-07-22 19:33:05 -07:00
|
|
|
|
2013-07-23 13:41:22 -07:00
|
|
|
/**
|
|
|
|
* Cancels any currently running animation. Note that all this does is set the
|
|
|
|
* state of the AsyncPanZoomController back to NOTHING, but it is the
|
|
|
|
* animation's responsibility to check this before advancing.
|
|
|
|
*/
|
|
|
|
void CancelAnimation();
|
|
|
|
|
2013-08-20 16:00:57 -07:00
|
|
|
/**
|
|
|
|
* Attempt to scroll in response to a touch-move from |aStartPoint| to
|
|
|
|
* |aEndPoint|, which are in our (transformed) screen coordinates.
|
|
|
|
* Due to overscroll handling, there may not actually have been a touch-move
|
|
|
|
* at these points, but this function will scroll as if there had been.
|
|
|
|
* If this attempt causes overscroll (i.e. the layer cannot be scrolled
|
|
|
|
* by the entire amount requested), the overscroll is passed back to the
|
|
|
|
* tree manager via APZCTreeManager::HandleOverscroll().
|
|
|
|
*/
|
|
|
|
void AttemptScroll(const ScreenPoint& aStartPoint, const ScreenPoint& aEndPoint);
|
|
|
|
|
2013-01-10 08:10:23 -08:00
|
|
|
protected:
|
2012-07-19 23:48:25 -07:00
|
|
|
/**
|
|
|
|
* Helper method for touches beginning. Sets everything up for panning and any
|
|
|
|
* multitouch gestures.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnTouchStart(const MultiTouchInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for touches moving. Does any transforms needed when panning.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnTouchMove(const MultiTouchInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for touches ending. Redraws the screen if necessary and does
|
|
|
|
* any cleanup after a touch has ended.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnTouchEnd(const MultiTouchInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for touches being cancelled. Treated roughly the same as a
|
|
|
|
* touch ending (OnTouchEnd()).
|
|
|
|
*/
|
|
|
|
nsEventStatus OnTouchCancel(const MultiTouchInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for scales beginning. Distinct from the OnTouch* handlers in
|
|
|
|
* that this implies some outside implementation has determined that the user
|
|
|
|
* is pinching.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnScaleBegin(const PinchGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for scaling. As the user moves their fingers when pinching,
|
|
|
|
* this changes the scale of the page.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnScale(const PinchGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for scales ending. Redraws the screen if necessary and does
|
|
|
|
* any cleanup after a scale has ended.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnScaleEnd(const PinchGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for long press gestures.
|
|
|
|
*
|
|
|
|
* XXX: Implement this.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnLongPress(const TapGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for single tap gestures.
|
|
|
|
*
|
|
|
|
* XXX: Implement this.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnSingleTapUp(const TapGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for a single tap confirmed.
|
|
|
|
*
|
|
|
|
* XXX: Implement this.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnSingleTapConfirmed(const TapGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for double taps.
|
|
|
|
*
|
|
|
|
* XXX: Implement this.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnDoubleTap(const TapGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to cancel any gesture currently going to Gecko. Used
|
|
|
|
* primarily when a user taps the screen over some clickable content but then
|
|
|
|
* pans down instead of letting go (i.e. to cancel a previous touch so that a
|
|
|
|
* new one can properly take effect.
|
|
|
|
*/
|
|
|
|
nsEventStatus OnCancelTap(const TapGestureInput& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrolls the viewport by an X,Y offset.
|
|
|
|
*/
|
2013-06-11 15:13:11 -07:00
|
|
|
void ScrollBy(const CSSPoint& aOffset);
|
2012-07-19 23:48:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scales the viewport by an amount (note that it multiplies this scale in to
|
|
|
|
* the current scale, it doesn't set it to |aScale|). Also considers a focus
|
2013-10-10 09:21:50 -07:00
|
|
|
* point so that the page zooms inward/outward from that point.
|
2012-07-19 23:48:25 -07:00
|
|
|
*/
|
2013-10-10 09:21:50 -07:00
|
|
|
void ScaleWithFocus(float aScale,
|
|
|
|
const CSSPoint& aFocus);
|
2012-07-19 23:48:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedules a composite on the compositor thread. Wrapper for
|
|
|
|
* CompositorParent::ScheduleRenderOnCompositorThread().
|
|
|
|
*/
|
|
|
|
void ScheduleComposite();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the displacement of the current touch since it began. That is, it is
|
|
|
|
* the distance between the current position and the initial position of the
|
|
|
|
* current touch (this only makes sense if a touch is currently happening and
|
|
|
|
* OnTouchMove() is being invoked).
|
|
|
|
*/
|
2012-07-22 20:49:07 -07:00
|
|
|
float PanDistance();
|
2012-07-19 23:48:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a vector of the velocities of each axis.
|
|
|
|
*/
|
2012-08-08 13:38:23 -07:00
|
|
|
const gfx::Point GetVelocityVector();
|
2012-07-19 23:48:25 -07:00
|
|
|
|
2012-09-28 21:02:45 -07:00
|
|
|
/**
|
|
|
|
* Gets a vector of the acceleration factors of each axis.
|
|
|
|
*/
|
|
|
|
const gfx::Point GetAccelerationVector();
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
/**
|
2013-10-02 18:03:04 -07:00
|
|
|
* Gets a reference to the first touch point from a MultiTouchInput. This
|
2012-07-19 23:48:25 -07:00
|
|
|
* gets only the first one and assumes the rest are either missing or not
|
|
|
|
* relevant.
|
|
|
|
*/
|
2013-10-02 18:03:04 -07:00
|
|
|
ScreenIntPoint& GetFirstTouchScreenPoint(const MultiTouchInput& aEvent);
|
2012-07-19 23:48:25 -07:00
|
|
|
|
2012-07-22 20:49:07 -07:00
|
|
|
/**
|
2012-10-24 01:37:53 -07:00
|
|
|
* Sets up anything needed for panning. This takes us out of the "TOUCHING"
|
|
|
|
* state and starts actually panning us.
|
2012-07-22 20:49:07 -07:00
|
|
|
*/
|
2013-10-02 18:03:04 -07:00
|
|
|
nsEventStatus StartPanning(const MultiTouchInput& aStartPoint);
|
2012-07-22 20:49:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper for Axis::UpdateWithTouchAtDevicePoint(). Calls this function for
|
|
|
|
* both axes and factors in the time delta from the last update.
|
|
|
|
*/
|
|
|
|
void UpdateWithTouchAtDevicePoint(const MultiTouchInput& aEvent);
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
/**
|
|
|
|
* Does any panning required due to a new touch event.
|
|
|
|
*/
|
|
|
|
void TrackTouch(const MultiTouchInput& aEvent);
|
|
|
|
|
2012-08-08 13:38:23 -07:00
|
|
|
/**
|
|
|
|
* Attempts to enlarge the displayport along a single axis. Returns whether or
|
|
|
|
* not the displayport was enlarged. This will fail in circumstances where the
|
|
|
|
* velocity along that axis is not high enough to need any changes. The
|
|
|
|
* displayport metrics are expected to be passed into |aDisplayPortOffset| and
|
|
|
|
* |aDisplayPortLength|. If enlarged, these will be updated with the new
|
|
|
|
* metrics.
|
|
|
|
*/
|
2012-09-28 21:02:45 -07:00
|
|
|
static bool EnlargeDisplayPortAlongAxis(float aSkateSizeMultiplier,
|
|
|
|
double aEstimatedPaintDuration,
|
|
|
|
float aCompositionBounds,
|
2012-09-28 19:18:18 -07:00
|
|
|
float aVelocity,
|
2012-09-28 21:02:45 -07:00
|
|
|
float aAcceleration,
|
2012-09-28 19:18:18 -07:00
|
|
|
float* aDisplayPortOffset,
|
|
|
|
float* aDisplayPortLength);
|
2012-08-08 13:38:23 -07:00
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
/**
|
|
|
|
* Utility function to send updated FrameMetrics to Gecko so that it can paint
|
|
|
|
* the displayport area. Calls into GeckoContentController to do the actual
|
2012-07-27 00:33:48 -07:00
|
|
|
* work. Note that only one paint request can be active at a time. If a paint
|
|
|
|
* request is made while a paint is currently happening, it gets queued up. If
|
|
|
|
* a new paint request arrives before a paint is completed, the old request
|
|
|
|
* gets discarded.
|
2012-07-19 23:48:25 -07:00
|
|
|
*/
|
|
|
|
void RequestContentRepaint();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Advances a fling by an interpolated amount based on the passed in |aDelta|.
|
|
|
|
* This should be called whenever sampling the content transform for this
|
|
|
|
* frame. Returns true if the fling animation should be advanced by one frame,
|
|
|
|
* or false if there is no fling or the fling has ended.
|
|
|
|
*/
|
|
|
|
bool DoFling(const TimeDuration& aDelta);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current frame metrics. This is *not* the Gecko copy stored in the
|
|
|
|
* layers code.
|
|
|
|
*/
|
|
|
|
const FrameMetrics& GetFrameMetrics();
|
|
|
|
|
2012-08-21 21:37:06 -07:00
|
|
|
/**
|
|
|
|
* Timeout function for touch listeners. This should be called on a timer
|
|
|
|
* after we get our first touch event in a batch, under the condition that we
|
|
|
|
* have touch listeners. If a notification comes indicating whether or not
|
|
|
|
* content preventDefaulted a series of touch events before the timeout, the
|
|
|
|
* timeout should be cancelled.
|
|
|
|
*/
|
|
|
|
void TimeoutTouchListeners();
|
|
|
|
|
2012-09-28 19:16:38 -07:00
|
|
|
/**
|
|
|
|
* Utility function that sets the zoom and resolution simultaneously. This is
|
|
|
|
* useful when we want to repaint at the current zoom level.
|
|
|
|
*
|
|
|
|
* *** The monitor must be held while calling this.
|
|
|
|
*/
|
2013-08-26 06:50:30 -07:00
|
|
|
void SetZoomAndResolution(const mozilla::CSSToScreenScale& aZoom);
|
2012-09-28 19:16:38 -07:00
|
|
|
|
2012-12-24 22:09:34 -08:00
|
|
|
/**
|
|
|
|
* Timeout function for mozbrowserasyncscroll event. Because we throttle
|
|
|
|
* mozbrowserasyncscroll events in some conditions, this function ensures
|
|
|
|
* that the last mozbrowserasyncscroll event will be fired after a period of
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
void FireAsyncScrollOnTimeout();
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
private:
|
|
|
|
enum PanZoomState {
|
|
|
|
NOTHING, /* no touch-start events received */
|
|
|
|
FLING, /* all touches removed, but we're still scrolling page */
|
|
|
|
TOUCHING, /* one touch-start event received */
|
2013-10-02 18:03:04 -07:00
|
|
|
|
|
|
|
PANNING, /* panning the frame */
|
|
|
|
PANNING_LOCKED_X, /* touch-start followed by move (i.e. panning with axis lock) X axis */
|
|
|
|
PANNING_LOCKED_Y, /* as above for Y axis */
|
|
|
|
|
2013-10-02 18:03:04 -07:00
|
|
|
CROSS_SLIDING_X, /* Panning disabled while user does a horizontal gesture
|
|
|
|
on a vertically-scrollable view. This used for the
|
|
|
|
Windows Metro "cross-slide" gesture. */
|
|
|
|
CROSS_SLIDING_Y, /* as above for Y axis */
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
PINCHING, /* nth touch-start, where n > 1. this mode allows pan and zoom */
|
2012-08-21 21:37:06 -07:00
|
|
|
ANIMATING_ZOOM, /* animated zoom to a new rect */
|
|
|
|
WAITING_LISTENERS, /* a state halfway between NOTHING and TOUCHING - the user has
|
|
|
|
put a finger down, but we don't yet know if a touch listener has
|
|
|
|
prevented the default actions yet. we still need to abort animations. */
|
2012-07-19 23:48:25 -07:00
|
|
|
};
|
|
|
|
|
2013-10-02 18:03:04 -07:00
|
|
|
enum AxisLockMode {
|
|
|
|
FREE, /* No locking at all */
|
|
|
|
STANDARD, /* Default axis locking mode that remains locked until pan ends*/
|
|
|
|
STICKY, /* Allow lock to be broken, with hysteresis */
|
|
|
|
};
|
|
|
|
|
|
|
|
static AxisLockMode GetAxisLockMode();
|
|
|
|
|
2012-08-08 13:38:20 -07:00
|
|
|
/**
|
|
|
|
* Helper to set the current state. Holds the monitor before actually setting
|
|
|
|
* it. If the monitor is already held by the current thread, it is safe to
|
|
|
|
* instead use: |mState = NEWSTATE;|
|
|
|
|
*/
|
|
|
|
void SetState(PanZoomState aState);
|
|
|
|
|
2013-10-02 18:03:04 -07:00
|
|
|
bool IsPanningState(PanZoomState mState);
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
uint64_t mLayersId;
|
2012-07-19 23:48:25 -07:00
|
|
|
nsRefPtr<CompositorParent> mCompositorParent;
|
2012-12-10 05:50:24 -08:00
|
|
|
TaskThrottler mPaintThrottler;
|
2013-07-30 11:03:39 -07:00
|
|
|
|
|
|
|
/* Access to the following two fields is protected by the mRefPtrMonitor,
|
|
|
|
since they are accessed on the UI thread but can be cleared on the
|
|
|
|
compositor thread. */
|
2012-07-19 23:48:25 -07:00
|
|
|
nsRefPtr<GeckoContentController> mGeckoContentController;
|
|
|
|
nsRefPtr<GestureEventListener> mGestureEventListener;
|
2013-07-30 11:03:39 -07:00
|
|
|
Monitor mRefPtrMonitor;
|
|
|
|
|
|
|
|
/* Utility functions that return a addrefed pointer to the corresponding fields. */
|
|
|
|
already_AddRefed<GeckoContentController> GetGeckoContentController();
|
|
|
|
already_AddRefed<GestureEventListener> GetGestureEventListener();
|
2012-07-19 23:48:25 -07:00
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
protected:
|
2012-07-19 23:48:25 -07:00
|
|
|
// Both |mFrameMetrics| and |mLastContentPaintMetrics| are protected by the
|
|
|
|
// monitor. Do not read from or modify either of them without locking.
|
|
|
|
FrameMetrics mFrameMetrics;
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
// Protects |mFrameMetrics|, |mLastContentPaintMetrics|, and |mState|.
|
|
|
|
// Before manipulating |mFrameMetrics| or |mLastContentPaintMetrics|, the
|
|
|
|
// monitor should be held. When setting |mState|, either the SetState()
|
|
|
|
// function can be used, or the monitor can be held and then |mState| updated.
|
2013-07-31 05:53:16 -07:00
|
|
|
ReentrantMonitor mMonitor;
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
private:
|
2013-07-30 11:03:40 -07:00
|
|
|
// Metrics of the container layer corresponding to this APZC. This is
|
|
|
|
// stored here so that it is accessible from the UI/controller thread.
|
2012-07-19 23:48:25 -07:00
|
|
|
// These are the metrics at last content paint, the most recent
|
2013-07-30 11:03:40 -07:00
|
|
|
// values we were notified of in NotifyLayersUpdate(). Since it represents
|
|
|
|
// the Gecko state, it should be used as a basis for untransformation when
|
|
|
|
// sending messages back to Gecko.
|
2012-07-19 23:48:25 -07:00
|
|
|
FrameMetrics mLastContentPaintMetrics;
|
2012-07-27 00:33:48 -07:00
|
|
|
// The last metrics that we requested a paint for. These are used to make sure
|
|
|
|
// that we're not requesting a paint of the same thing that's already drawn.
|
|
|
|
// If we don't do this check, we don't get a ShadowLayersUpdated back.
|
|
|
|
FrameMetrics mLastPaintRequestMetrics;
|
2012-07-19 23:48:25 -07:00
|
|
|
|
2012-08-08 21:39:02 -07:00
|
|
|
// Old metrics from before we started a zoom animation. This is only valid
|
|
|
|
// when we are in the "ANIMATED_ZOOM" state. This is used so that we can
|
|
|
|
// interpolate between the start and end frames. We only use the
|
|
|
|
// |mViewportScrollOffset| and |mResolution| fields on this.
|
|
|
|
FrameMetrics mStartZoomToMetrics;
|
|
|
|
// Target metrics for a zoom to animation. This is only valid when we are in
|
|
|
|
// the "ANIMATED_ZOOM" state. We only use the |mViewportScrollOffset| and
|
|
|
|
// |mResolution| fields on this.
|
|
|
|
FrameMetrics mEndZoomToMetrics;
|
|
|
|
|
2012-08-21 21:37:06 -07:00
|
|
|
nsTArray<MultiTouchInput> mTouchQueue;
|
|
|
|
|
|
|
|
CancelableTask* mTouchListenerTimeoutTask;
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
AxisX mX;
|
|
|
|
AxisY mY;
|
|
|
|
|
2012-09-28 19:18:18 -07:00
|
|
|
// Most up-to-date constraints on zooming. These should always be reasonable
|
|
|
|
// values; for example, allowing a min zoom of 0.0 can cause very bad things
|
|
|
|
// to happen.
|
|
|
|
bool mAllowZoom;
|
2013-08-26 06:50:30 -07:00
|
|
|
mozilla::CSSToScreenScale mMinZoom;
|
|
|
|
mozilla::CSSToScreenScale mMaxZoom;
|
2012-09-28 19:18:18 -07:00
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
// The last time the compositor has sampled the content transform for this
|
|
|
|
// frame.
|
|
|
|
TimeStamp mLastSampleTime;
|
|
|
|
// The last time a touch event came through on the UI thread.
|
2013-04-09 19:17:54 -07:00
|
|
|
uint32_t mLastEventTime;
|
2012-07-19 23:48:25 -07:00
|
|
|
|
2012-08-08 21:39:02 -07:00
|
|
|
// Start time of an animation. This is used for a zoom to animation to mark
|
|
|
|
// the beginning.
|
|
|
|
TimeStamp mAnimationStartTime;
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
// Stores the previous focus point if there is a pinch gesture happening. Used
|
|
|
|
// to allow panning by moving multiple fingers (thus moving the focus point).
|
2013-06-11 15:13:11 -07:00
|
|
|
ScreenPoint mLastZoomFocus;
|
2012-08-08 13:38:20 -07:00
|
|
|
|
|
|
|
// Stores the state of panning and zooming this frame. This is protected by
|
|
|
|
// |mMonitor|; that is, it should be held whenever this is updated.
|
2012-07-19 23:48:25 -07:00
|
|
|
PanZoomState mState;
|
2012-08-08 13:38:20 -07:00
|
|
|
|
2012-12-24 22:09:34 -08:00
|
|
|
// The last time and offset we fire the mozbrowserasyncscroll event when
|
|
|
|
// compositor has sampled the content transform for this frame.
|
|
|
|
TimeStamp mLastAsyncScrollTime;
|
2013-06-10 06:05:44 -07:00
|
|
|
CSSPoint mLastAsyncScrollOffset;
|
2012-12-24 22:09:34 -08:00
|
|
|
|
|
|
|
// The current offset drawn on the screen, it may not be sent since we have
|
|
|
|
// throttling policy for mozbrowserasyncscroll event.
|
2013-06-10 06:05:44 -07:00
|
|
|
CSSPoint mCurrentAsyncScrollOffset;
|
2012-12-24 22:09:34 -08:00
|
|
|
|
|
|
|
// The delay task triggered by the throttling mozbrowserasyncscroll event
|
|
|
|
// ensures the last mozbrowserasyncscroll event is always been fired.
|
|
|
|
CancelableTask* mAsyncScrollTimeoutTask;
|
|
|
|
|
2012-08-08 13:38:06 -07:00
|
|
|
// Flag used to determine whether or not we should disable handling of the
|
|
|
|
// next batch of touch events. This is used for sync scrolling of subframes.
|
|
|
|
bool mDisableNextTouchBatch;
|
|
|
|
|
2012-08-21 21:37:06 -07:00
|
|
|
// Flag used to determine whether or not we should try to enter the
|
|
|
|
// WAITING_LISTENERS state. This is used in the case that we are processing a
|
|
|
|
// queued up event block. If set, this means that we are handling this queue
|
|
|
|
// and we don't want to queue the events back up again.
|
|
|
|
bool mHandlingTouchQueue;
|
|
|
|
|
2013-01-05 06:53:16 -08:00
|
|
|
// Flag used to determine whether or not we should try scrolling by
|
|
|
|
// BrowserElementScrolling first. If set, we delay delivering
|
|
|
|
// touchmove events to GestureListener until BrowserElementScrolling
|
|
|
|
// decides whether it wants to handle panning for this touch series.
|
|
|
|
bool mDelayPanning;
|
|
|
|
|
2012-07-19 23:48:25 -07:00
|
|
|
friend class Axis;
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
/* The functions and members in this section are used to build a tree
|
|
|
|
* structure out of APZC instances. This tree can only be walked or
|
|
|
|
* manipulated while holding the lock in the associated APZCTreeManager
|
|
|
|
* instance.
|
|
|
|
*/
|
|
|
|
public:
|
2013-08-21 09:03:02 -07:00
|
|
|
void SetLastChild(AsyncPanZoomController* child) {
|
|
|
|
mLastChild = child;
|
|
|
|
if (child) {
|
|
|
|
child->mParent = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPrevSibling(AsyncPanZoomController* sibling) {
|
|
|
|
mPrevSibling = sibling;
|
|
|
|
if (sibling) {
|
|
|
|
sibling->mParent = mParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
AsyncPanZoomController* GetLastChild() const { return mLastChild; }
|
|
|
|
AsyncPanZoomController* GetPrevSibling() const { return mPrevSibling; }
|
2013-08-21 09:03:02 -07:00
|
|
|
AsyncPanZoomController* GetParent() const { return mParent; }
|
2013-08-22 07:40:44 -07:00
|
|
|
|
|
|
|
/* Returns true if there is no APZC higher in the tree with the same
|
|
|
|
* layers id.
|
|
|
|
*/
|
|
|
|
bool IsRootForLayersId() const {
|
|
|
|
return !mParent || (mParent->mLayersId != mLayersId);
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
private:
|
2013-08-20 15:10:47 -07:00
|
|
|
// This is a raw pointer to avoid introducing a reference cycle between
|
|
|
|
// AsyncPanZoomController and APZCTreeManager. Since these objects don't
|
|
|
|
// live on the main thread, we can't use the cycle collector with them.
|
|
|
|
// The APZCTreeManager owns the lifetime of the APZCs, so nulling this
|
|
|
|
// pointer out in Destroy() will prevent accessing deleted memory.
|
|
|
|
APZCTreeManager* mTreeManager;
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> mLastChild;
|
|
|
|
nsRefPtr<AsyncPanZoomController> mPrevSibling;
|
2013-08-21 09:03:02 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> mParent;
|
2013-07-30 11:03:41 -07:00
|
|
|
|
|
|
|
/* The functions and members in this section are used to maintain the
|
|
|
|
* area that this APZC instance is responsible for. This is used when
|
|
|
|
* hit-testing to see which APZC instance should handle touch events.
|
|
|
|
*/
|
|
|
|
public:
|
2013-08-14 07:15:54 -07:00
|
|
|
void SetLayerHitTestData(const LayerRect& aRect, const gfx3DMatrix& aTransformToLayer,
|
|
|
|
const gfx3DMatrix& aTransformForLayer) {
|
2013-08-06 13:20:14 -07:00
|
|
|
mVisibleRect = aRect;
|
2013-08-14 07:15:54 -07:00
|
|
|
mAncestorTransform = aTransformToLayer;
|
|
|
|
mCSSTransform = aTransformForLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx3DMatrix GetAncestorTransform() const {
|
|
|
|
return mAncestorTransform;
|
2013-08-06 13:20:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx3DMatrix GetCSSTransform() const {
|
|
|
|
return mCSSTransform;
|
|
|
|
}
|
2013-07-30 11:03:41 -07:00
|
|
|
|
2013-08-06 13:20:14 -07:00
|
|
|
bool VisibleRegionContains(const LayerPoint& aPoint) const {
|
|
|
|
return mVisibleRect.Contains(aPoint);
|
2013-07-30 11:03:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-08-06 13:20:14 -07:00
|
|
|
/* This is the viewport of the layer that this APZC corresponds to, in
|
|
|
|
* layer pixels. It position here does not account for any transformations
|
|
|
|
* applied to any layers, whether they are CSS transforms or async
|
|
|
|
* transforms. */
|
|
|
|
LayerRect mVisibleRect;
|
2013-08-14 07:15:54 -07:00
|
|
|
/* This is the cumulative CSS transform for all the layers between the parent
|
|
|
|
* APZC and this one (not inclusive) */
|
|
|
|
gfx3DMatrix mAncestorTransform;
|
|
|
|
/* This is the CSS transform for this APZC's layer. */
|
2013-08-06 13:20:14 -07:00
|
|
|
gfx3DMatrix mCSSTransform;
|
2012-07-19 23:48:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // mozilla_layers_PanZoomController_h
|