2013-07-30 11:03:40 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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_APZCTreeManager_h
|
|
|
|
#define mozilla_layers_APZCTreeManager_h
|
|
|
|
|
2013-08-11 16:17:23 -07:00
|
|
|
#include <stdint.h> // for uint64_t, uint32_t
|
|
|
|
#include "FrameMetrics.h" // for FrameMetrics, etc
|
|
|
|
#include "Units.h" // for CSSPoint, CSSRect, etc
|
|
|
|
#include "gfxPoint.h" // for gfxPoint
|
2013-08-20 16:00:57 -07:00
|
|
|
#include "gfx3DMatrix.h" // for gfx3DMatrix
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
|
2013-10-01 00:23:02 -07:00
|
|
|
#include "mozilla/EventForwards.h" // for WidgetInputEvent, nsEventStatus
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "mozilla/Monitor.h" // for Monitor
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
|
|
|
|
|
|
|
|
class gfx3DMatrix;
|
|
|
|
template <class E> class nsTArray;
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-08-11 16:17:23 -07:00
|
|
|
class InputData;
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
namespace layers {
|
|
|
|
|
2013-08-11 16:17:23 -07:00
|
|
|
class Layer;
|
2013-07-30 11:03:40 -07:00
|
|
|
class AsyncPanZoomController;
|
|
|
|
class CompositorParent;
|
|
|
|
|
2013-07-30 11:03:40 -07:00
|
|
|
/**
|
|
|
|
* This class allows us to uniquely identify a scrollable layer. The
|
|
|
|
* mLayersId identifies the layer tree (corresponding to a child process
|
|
|
|
* and/or tab) that the scrollable layer belongs to. The mPresShellId
|
|
|
|
* is a temporal identifier (corresponding to the document loaded that
|
|
|
|
* contains the scrollable layer, which may change over time). The
|
|
|
|
* mScrollId corresponds to the actual frame that is scrollable.
|
|
|
|
*/
|
|
|
|
struct ScrollableLayerGuid {
|
|
|
|
uint64_t mLayersId;
|
|
|
|
uint32_t mPresShellId;
|
|
|
|
FrameMetrics::ViewID mScrollId;
|
|
|
|
|
|
|
|
ScrollableLayerGuid(uint64_t aLayersId, uint32_t aPresShellId,
|
|
|
|
FrameMetrics::ViewID aScrollId)
|
|
|
|
: mLayersId(aLayersId)
|
|
|
|
, mPresShellId(aPresShellId)
|
|
|
|
, mScrollId(aScrollId)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ScrollableLayerGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollableLayerGuid(uint64_t aLayersId, const FrameMetrics& aMetrics)
|
|
|
|
: mLayersId(aLayersId)
|
|
|
|
, mPresShellId(aMetrics.mPresShellId)
|
|
|
|
, mScrollId(aMetrics.mScrollId)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ScrollableLayerGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollableLayerGuid(uint64_t aLayersId)
|
|
|
|
: mLayersId(aLayersId)
|
|
|
|
, mPresShellId(0)
|
|
|
|
, mScrollId(FrameMetrics::ROOT_SCROLL_ID)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ScrollableLayerGuid);
|
|
|
|
// TODO: get rid of this constructor once all callers know their
|
|
|
|
// presShellId and scrollId
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScrollableLayerGuid()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ScrollableLayerGuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const ScrollableLayerGuid& other) const
|
|
|
|
{
|
|
|
|
return mLayersId == other.mLayersId
|
|
|
|
&& mPresShellId == other.mPresShellId
|
|
|
|
&& mScrollId == other.mScrollId;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const ScrollableLayerGuid& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class manages the tree of AsyncPanZoomController instances. There is one
|
|
|
|
* instance of this class owned by each CompositorParent, and it contains as
|
|
|
|
* many AsyncPanZoomController instances as there are scrollable container layers.
|
|
|
|
* This class generally lives on the compositor thread, although some functions
|
|
|
|
* may be called from other threads as noted; thread safety is ensured internally.
|
|
|
|
*
|
|
|
|
* The bulk of the work of this class happens as part of the UpdatePanZoomControllerTree
|
|
|
|
* function, which is when a layer tree update is received by the compositor.
|
|
|
|
* This function walks through the layer tree and creates a tree of APZC instances
|
|
|
|
* to match the scrollable container layers. APZC instances may be preserved across
|
|
|
|
* calls to this function if the corresponding layers are still present in the layer
|
|
|
|
* tree.
|
|
|
|
*
|
|
|
|
* The other functions on this class are used by various pieces of client code to
|
|
|
|
* notify the APZC instances of events relevant to them. This includes, for example,
|
|
|
|
* user input events that drive panning and zooming, changes to the scroll viewport
|
|
|
|
* area, and changes to pan/zoom constraints.
|
|
|
|
*
|
|
|
|
* Note that the ClearTree function MUST be called when this class is no longer needed;
|
|
|
|
* see the method documentation for details.
|
|
|
|
*/
|
2013-07-30 11:03:41 -07:00
|
|
|
class APZCTreeManager {
|
2013-07-30 11:03:40 -07:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(APZCTreeManager)
|
|
|
|
|
|
|
|
public:
|
|
|
|
APZCTreeManager();
|
2013-08-11 16:17:23 -07:00
|
|
|
virtual ~APZCTreeManager();
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rebuild the APZC tree based on the layer update that just came up. Preserve
|
|
|
|
* APZC instances where possible, but retire those whose layers are no longer
|
|
|
|
* in the layer tree.
|
|
|
|
*
|
|
|
|
* This must be called on the compositor thread as it walks the layer tree.
|
2013-07-30 11:03:40 -07:00
|
|
|
*
|
|
|
|
* @param aCompositor A pointer to the compositor parent instance that owns
|
|
|
|
* this APZCTreeManager
|
|
|
|
* @param aRoot The root of the (full) layer tree
|
|
|
|
* @param aFirstPaintLayersId The layers id of the subtree to which aIsFirstPaint
|
|
|
|
* applies.
|
|
|
|
* @param aIsFirstPaint True if the layers update that this is called in response
|
|
|
|
* to included a first-paint. If this is true, the part of
|
|
|
|
* the tree that is affected by the first-paint flag is
|
|
|
|
* indicated by the aFirstPaintLayersId parameter.
|
2013-07-30 11:03:40 -07:00
|
|
|
*/
|
|
|
|
void UpdatePanZoomControllerTree(CompositorParent* aCompositor, Layer* aRoot,
|
2013-07-30 11:03:40 -07:00
|
|
|
bool aIsFirstPaint, uint64_t aFirstPaintLayersId);
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* General handler for incoming input events. Manipulates the frame metrics
|
|
|
|
* based on what type of input it is. For example, a PinchGestureEvent will
|
|
|
|
* cause scaling. This should only be called externally to this class.
|
|
|
|
*/
|
|
|
|
nsEventStatus ReceiveInputEvent(const InputData& aEvent);
|
|
|
|
|
|
|
|
/**
|
2013-10-01 00:23:02 -07:00
|
|
|
* WidgetInputEvent handler. Sets |aOutEvent| (which is assumed to be an
|
|
|
|
* already-existing instance of an WidgetInputEvent which may be an
|
2013-09-26 23:20:57 -07:00
|
|
|
* WidgetTouchEvent) to have its coordinates in DOM space. This is so that the
|
2013-09-24 14:17:26 -07:00
|
|
|
* event can be passed through the DOM and content can handle them.
|
2013-07-30 11:03:40 -07:00
|
|
|
*
|
2013-10-01 00:23:02 -07:00
|
|
|
* NOTE: Be careful of invoking the WidgetInputEvent variant. This can only be
|
2013-07-30 11:03:40 -07:00
|
|
|
* called on the main thread. See widget/InputData.h for more information on
|
2013-10-01 00:23:02 -07:00
|
|
|
* why we have InputData and WidgetInputEvent separated.
|
2013-09-24 14:17:26 -07:00
|
|
|
* NOTE: On unix, mouse events are treated as touch and are forwarded
|
|
|
|
* to the appropriate apz as such.
|
|
|
|
*
|
|
|
|
* @param aEvent input event object, will not be modified
|
|
|
|
* @param aOutEvent event object transformed to DOM coordinate space.
|
2013-07-30 11:03:40 -07:00
|
|
|
*/
|
2013-10-01 00:23:02 -07:00
|
|
|
nsEventStatus ReceiveInputEvent(const WidgetInputEvent& aEvent,
|
|
|
|
WidgetInputEvent* aOutEvent);
|
2013-07-30 11:03:40 -07:00
|
|
|
|
2013-09-24 14:17:26 -07:00
|
|
|
/**
|
2013-10-01 00:23:02 -07:00
|
|
|
* WidgetInputEvent handler with inline dom transform of the passed in
|
|
|
|
* WidgetInputEvent. Must be called on the main thread.
|
2013-09-24 14:17:26 -07:00
|
|
|
*
|
|
|
|
* @param aEvent input event object
|
|
|
|
*/
|
2013-10-01 00:23:02 -07:00
|
|
|
nsEventStatus ReceiveInputEvent(WidgetInputEvent& aEvent);
|
2013-09-24 14:17:26 -07:00
|
|
|
|
2013-07-30 11:03:40 -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.
|
|
|
|
*/
|
|
|
|
void UpdateCompositionBounds(const ScrollableLayerGuid& aGuid,
|
|
|
|
const ScreenIntRect& aCompositionBounds);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* up. |aRect| must be given in CSS pixels, relative to the document.
|
|
|
|
*/
|
|
|
|
void ZoomToRect(const ScrollableLayerGuid& aGuid,
|
|
|
|
const CSSRect& aRect);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(const ScrollableLayerGuid& aGuid,
|
|
|
|
bool aPreventDefault);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void UpdateZoomConstraints(const ScrollableLayerGuid& aGuid,
|
|
|
|
bool aAllowZoom,
|
2013-08-26 06:50:30 -07:00
|
|
|
const CSSToScreenScale& aMinScale,
|
|
|
|
const CSSToScreenScale& aMaxScale);
|
2013-07-30 11:03:40 -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()).
|
|
|
|
*/
|
|
|
|
void UpdateScrollOffset(const ScrollableLayerGuid& aGuid,
|
|
|
|
const CSSPoint& aScrollOffset);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(const ScrollableLayerGuid &aGuid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls Destroy() on all APZC instances attached to the tree, and resets the
|
|
|
|
* tree back to empty. This function may be called multiple times during the
|
|
|
|
* lifetime of this APZCTreeManager, but it must always be called at least once
|
|
|
|
* when this APZCTreeManager is no longer needed. Failing to call this function
|
|
|
|
* may prevent objects from being freed properly.
|
|
|
|
*/
|
|
|
|
void ClearTree();
|
|
|
|
|
2013-09-24 14:17:26 -07:00
|
|
|
/**
|
|
|
|
* Tests if a screen point intersect an apz in the tree.
|
|
|
|
*/
|
|
|
|
bool HitTestAPZC(const ScreenPoint& aPoint);
|
|
|
|
|
2013-08-22 17:28:02 -07:00
|
|
|
/**
|
|
|
|
* Set the dpi value used by all AsyncPanZoomControllers.
|
|
|
|
* DPI defaults to 72 if not set using SetDPI() at any point.
|
|
|
|
*/
|
|
|
|
static void SetDPI(float aDpiValue) { sDPI = aDpiValue; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current dpi value in use.
|
|
|
|
*/
|
|
|
|
static float GetDPI() { return sDPI; }
|
|
|
|
|
2013-08-20 16:00:57 -07:00
|
|
|
/**
|
|
|
|
* This is a callback for AsyncPanZoomController to call when a touch-move
|
|
|
|
* event causes overscroll. The overscroll will be passed on to the parent
|
|
|
|
* APZC. |aStartPoint| and |aEndPoint| are in |aAPZC|'s transformed screen
|
|
|
|
* coordinates (i.e. the same coordinates in which touch points are given to
|
|
|
|
* APZCs). The amount of the overscroll is represented by two points rather
|
|
|
|
* than a displacement because with certain 3D transforms, the same
|
|
|
|
* displacement between different points in transformed coordinates can
|
|
|
|
* represent different displacements in untransformed coordinates.
|
|
|
|
*/
|
|
|
|
void HandleOverscroll(AsyncPanZoomController* aAPZC, ScreenPoint aStartPoint, ScreenPoint aEndPoint);
|
|
|
|
|
2013-07-30 11:03:41 -07:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Debug-build assertion that can be called to ensure code is running on the
|
|
|
|
* compositor thread.
|
|
|
|
*/
|
|
|
|
virtual void AssertOnCompositorThread();
|
|
|
|
|
|
|
|
public:
|
2013-07-30 11:03:40 -07:00
|
|
|
/* Some helper functions to find an APZC given some identifying input. These functions
|
|
|
|
lock the tree of APZCs while they find the right one, and then return an addref'd
|
|
|
|
pointer to it. This allows caller code to just use the target APZC without worrying
|
2013-07-30 11:03:41 -07:00
|
|
|
about it going away. These are public for testing code and generally should not be
|
|
|
|
used by other production code.
|
2013-07-30 11:03:40 -07:00
|
|
|
*/
|
|
|
|
already_AddRefed<AsyncPanZoomController> GetTargetAPZC(const ScrollableLayerGuid& aGuid);
|
2013-08-21 09:03:03 -07:00
|
|
|
already_AddRefed<AsyncPanZoomController> GetTargetAPZC(const ScreenPoint& aPoint);
|
|
|
|
void GetInputTransforms(AsyncPanZoomController *aApzc, gfx3DMatrix& aTransformToApzcOut,
|
2013-10-31 11:44:33 -07:00
|
|
|
gfx3DMatrix& aTransformToGeckoOut);
|
2013-07-30 11:03:41 -07:00
|
|
|
private:
|
2013-08-21 09:03:02 -07:00
|
|
|
/* Helpers */
|
2013-07-30 11:03:40 -07:00
|
|
|
AsyncPanZoomController* FindTargetAPZC(AsyncPanZoomController* aApzc, const ScrollableLayerGuid& aGuid);
|
2013-08-21 09:03:02 -07:00
|
|
|
AsyncPanZoomController* GetAPZCAtPoint(AsyncPanZoomController* aApzc, const gfxPoint& aHitTestPoint);
|
2013-08-21 09:03:03 -07:00
|
|
|
AsyncPanZoomController* CommonAncestor(AsyncPanZoomController* aApzc1, AsyncPanZoomController* aApzc2);
|
2013-08-22 07:40:44 -07:00
|
|
|
AsyncPanZoomController* RootAPZCForLayersId(AsyncPanZoomController* aApzc);
|
2013-09-26 23:20:57 -07:00
|
|
|
AsyncPanZoomController* GetTouchInputBlockAPZC(const WidgetTouchEvent& aEvent, ScreenPoint aPoint);
|
|
|
|
nsEventStatus ProcessTouchEvent(const WidgetTouchEvent& touchEvent, WidgetTouchEvent* aOutEvent);
|
2013-10-01 23:38:27 -07:00
|
|
|
nsEventStatus ProcessMouseEvent(const WidgetMouseEvent& mouseEvent, WidgetMouseEvent* aOutEvent);
|
2013-10-01 00:23:02 -07:00
|
|
|
nsEventStatus ProcessEvent(const WidgetInputEvent& inputEvent, WidgetInputEvent* aOutEvent);
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursive helper function to build the APZC tree. The tree of APZC instances has
|
|
|
|
* the same shape as the layer tree, but excludes all the layers that are not scrollable.
|
|
|
|
* Note that this means APZCs corresponding to layers at different depths in the tree
|
|
|
|
* may end up becoming siblings. It also means that the "root" APZC may have siblings.
|
|
|
|
* This function walks the layer tree backwards through siblings and constructs the APZC
|
|
|
|
* tree also as a last-child-prev-sibling tree because that simplifies the hit detection
|
|
|
|
* code.
|
|
|
|
*/
|
|
|
|
AsyncPanZoomController* UpdatePanZoomControllerTree(CompositorParent* aCompositor,
|
|
|
|
Layer* aLayer, uint64_t aLayersId,
|
2013-08-06 13:20:14 -07:00
|
|
|
gfx3DMatrix aTransform,
|
2013-07-30 11:03:40 -07:00
|
|
|
AsyncPanZoomController* aParent,
|
|
|
|
AsyncPanZoomController* aNextSibling,
|
|
|
|
bool aIsFirstPaint,
|
|
|
|
uint64_t aFirstPaintLayersId,
|
|
|
|
nsTArray< nsRefPtr<AsyncPanZoomController> >* aApzcsToDestroy);
|
2013-07-30 11:03:40 -07:00
|
|
|
|
|
|
|
private:
|
2013-07-30 11:03:40 -07:00
|
|
|
/* Whenever walking or mutating the tree rooted at mRootApzc, mTreeLock must be held.
|
2013-07-30 11:03:40 -07:00
|
|
|
* This lock does not need to be held while manipulating a single APZC instance in
|
2013-07-30 11:03:40 -07:00
|
|
|
* isolation (that is, if its tree pointers are not being accessed or mutated). The
|
|
|
|
* lock also needs to be held when accessing the mRootApzc instance variable, as that
|
|
|
|
* is considered part of the APZC tree management state. */
|
2013-07-30 11:03:40 -07:00
|
|
|
mozilla::Monitor mTreeLock;
|
2013-07-30 11:03:40 -07:00
|
|
|
nsRefPtr<AsyncPanZoomController> mRootApzc;
|
2013-08-21 09:03:02 -07:00
|
|
|
/* This tracks the APZC that should receive all inputs for the current input event block.
|
|
|
|
* This allows touch points to move outside the thing they started on, but still have the
|
|
|
|
* touch events delivered to the same initial APZC. This will only ever be touched on the
|
|
|
|
* input delivery thread, and so does not require locking.
|
|
|
|
*/
|
|
|
|
nsRefPtr<AsyncPanZoomController> mApzcForInputBlock;
|
2013-11-07 13:10:29 -08:00
|
|
|
/* The number of touch points we are tracking that are currently on the screen. */
|
|
|
|
uint32_t mTouchCount;
|
2013-08-20 16:00:57 -07:00
|
|
|
/* The transform from root screen coordinates into mApzcForInputBlock's
|
|
|
|
* screen coordinates, as returned through the 'aTransformToApzcOut' parameter
|
|
|
|
* of GetInputTransform(), at the start of the input block. This is cached
|
|
|
|
* because this transform can change over the course of the input block,
|
|
|
|
* but for some operations we need to use the initial tranform.
|
|
|
|
* Meaningless if mApzcForInputBlock is nullptr.
|
|
|
|
*/
|
|
|
|
gfx3DMatrix mCachedTransformToApzcForInputBlock;
|
2013-08-22 17:28:02 -07:00
|
|
|
|
|
|
|
static float sDPI;
|
2013-07-30 11:03:40 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // mozilla_layers_PanZoomController_h
|