Bug 976605 - Group some fields of AsyncPanZoomController into a TouchBlockState structure. r=kats

--HG--
extra : source : 80ac8ba2dec8939065411e86526bcdfa1c4b3f6d
This commit is contained in:
Botond Ballo 2014-04-08 15:17:09 -04:00
parent bf3ff244a8
commit 46dc820f8e
2 changed files with 47 additions and 35 deletions

View File

@ -421,9 +421,6 @@ AsyncPanZoomController::AsyncPanZoomController(uint64_t aLayersId,
mCurrentAsyncScrollOffset(0, 0),
mAsyncScrollTimeoutTask(nullptr),
mHandlingTouchQueue(false),
mAllowedTouchBehaviorSet(false),
mPreventDefault(false),
mPreventDefaultSet(false),
mTreeManager(aTreeManager),
mScrollParentId(FrameMetrics::NULL_SCROLL_ID),
mAPZCId(sAsyncPanZoomControllerCount++),
@ -499,6 +496,12 @@ AsyncPanZoomController::GetTouchStartTolerance()
}
nsEventStatus AsyncPanZoomController::ReceiveInputEvent(const InputData& aEvent) {
if (aEvent.mInputType == MULTITOUCH_INPUT &&
aEvent.AsMultiTouchInput().mType == MultiTouchInput::MULTITOUCH_START) {
// Starting a new touch block, clear old touch block state.
mTouchBlockState = TouchBlockState();
}
// If we may have touch listeners and touch action property is enabled, we
// enable the machinery that allows touch listeners to preventDefault any touch inputs
// and also waits for the allowed touch behavior values to be received from the outside.
@ -510,10 +513,6 @@ nsEventStatus AsyncPanZoomController::ReceiveInputEvent(const InputData& aEvent)
(mState == NOTHING || mState == TOUCHING || IsPanningState(mState))) {
const MultiTouchInput& multiTouchInput = aEvent.AsMultiTouchInput();
if (multiTouchInput.mType == MultiTouchInput::MULTITOUCH_START) {
mAllowedTouchBehaviors.Clear();
mAllowedTouchBehaviorSet = false;
mPreventDefault = false;
mPreventDefaultSet = false;
SetState(WAITING_CONTENT_RESPONSE);
}
}
@ -1905,8 +1904,8 @@ void AsyncPanZoomController::ZoomToRect(CSSRect aRect) {
}
void AsyncPanZoomController::ContentReceivedTouch(bool aPreventDefault) {
mPreventDefaultSet = true;
mPreventDefault = aPreventDefault;
mTouchBlockState.mPreventDefaultSet = true;
mTouchBlockState.mPreventDefault = aPreventDefault;
CheckContentResponse();
}
@ -1914,11 +1913,11 @@ void AsyncPanZoomController::CheckContentResponse() {
bool canProceedToTouchState = true;
if (mFrameMetrics.mMayHaveTouchListeners) {
canProceedToTouchState &= mPreventDefaultSet;
canProceedToTouchState &= mTouchBlockState.mPreventDefaultSet;
}
if (mTouchActionPropertyEnabled) {
canProceedToTouchState &= mAllowedTouchBehaviorSet;
canProceedToTouchState &= mTouchBlockState.mAllowedTouchBehaviorSet;
}
if (!canProceedToTouchState) {
@ -1931,14 +1930,14 @@ void AsyncPanZoomController::CheckContentResponse() {
}
if (mState == WAITING_CONTENT_RESPONSE) {
if (!mPreventDefault) {
if (!mTouchBlockState.mPreventDefault) {
SetState(NOTHING);
}
mHandlingTouchQueue = true;
while (!mTouchQueue.IsEmpty()) {
if (!mPreventDefault) {
if (!mTouchBlockState.mPreventDefault) {
HandleInputEvent(mTouchQueue[0]);
}
@ -1962,8 +1961,8 @@ bool AsyncPanZoomController::TouchActionAllowZoom() {
// Pointer events specification implies all touch points to allow zoom
// to perform it.
for (size_t i = 0; i < mAllowedTouchBehaviors.Length(); i++) {
if (!(mAllowedTouchBehaviors[i] & AllowedTouchBehavior::ZOOM)) {
for (size_t i = 0; i < mTouchBlockState.mAllowedTouchBehaviors.Length(); i++) {
if (!(mTouchBlockState.mAllowedTouchBehaviors[i] & AllowedTouchBehavior::ZOOM)) {
return false;
}
}
@ -1973,8 +1972,8 @@ bool AsyncPanZoomController::TouchActionAllowZoom() {
AsyncPanZoomController::TouchBehaviorFlags
AsyncPanZoomController::GetTouchBehavior(uint32_t touchIndex) {
if (touchIndex < mAllowedTouchBehaviors.Length()) {
return mAllowedTouchBehaviors[touchIndex];
if (touchIndex < mTouchBlockState.mAllowedTouchBehaviors.Length()) {
return mTouchBlockState.mAllowedTouchBehaviors[touchIndex];
}
return DefaultTouchBehavior;
}
@ -1988,9 +1987,9 @@ AsyncPanZoomController::GetAllowedTouchBehavior(ScreenIntPoint& aPoint) {
}
void AsyncPanZoomController::SetAllowedTouchBehavior(const nsTArray<TouchBehaviorFlags>& aBehaviors) {
mAllowedTouchBehaviors.Clear();
mAllowedTouchBehaviors.AppendElements(aBehaviors);
mAllowedTouchBehaviorSet = true;
mTouchBlockState.mAllowedTouchBehaviors.Clear();
mTouchBlockState.mAllowedTouchBehaviors.AppendElements(aBehaviors);
mTouchBlockState.mAllowedTouchBehaviorSet = true;
CheckContentResponse();
}

View File

@ -562,6 +562,32 @@ private:
was not set yet. we still need to abort animations. */
};
// State related to a single touch block. Does not persist across touch blocks.
struct TouchBlockState {
TouchBlockState()
: mAllowedTouchBehaviorSet(false),
mPreventDefault(false),
mPreventDefaultSet(false)
{}
// Values of allowed touch behavior for touch points of this touch block.
// Since there are maybe a few current active touch points per time (multitouch case)
// and each touch point should have its own value of allowed touch behavior- we're
// keeping an array of allowed touch behavior values, not the single value.
nsTArray<TouchBehaviorFlags> mAllowedTouchBehaviors;
// Specifies whether mAllowedTouchBehaviors is set for this touch events block.
bool mAllowedTouchBehaviorSet;
// Flag used to specify that content prevented the default behavior of this
// touch events block.
bool mPreventDefault;
// Specifies whether mPreventDefault property is set for this touch events block.
bool mPreventDefaultSet;
};
/*
* Returns whether current touch behavior values allow zooming.
*/
@ -725,21 +751,8 @@ private:
// and we don't want to queue the events back up again.
bool mHandlingTouchQueue;
// Values of allowed touch behavior for current touch points.
// Since there are maybe a few current active touch points per time (multitouch case)
// and each touch point should have its own value of allowed touch behavior- we're
// keeping an array of allowed touch behavior values, not the single value.
nsTArray<TouchBehaviorFlags> mAllowedTouchBehaviors;
// Specifies whether mAllowedTouchBehaviors is set for current touch events block.
bool mAllowedTouchBehaviorSet;
// Flag used to specify that content prevented the default behavior of the current
// touch events block.
bool mPreventDefault;
// Specifies whether mPreventDefault property is set for current touch events block.
bool mPreventDefaultSet;
// Stores information about the current touch block.
TouchBlockState mTouchBlockState;
// Extra offset to add in SampleContentTransformForFrame for testing
CSSPoint mTestAsyncScrollOffset;