Bug 1194876 - Extract a TouchCounter class. r=botond

--HG--
extra : commitid : Au3xHqP2lQW
This commit is contained in:
Kartikaya Gupta 2015-08-25 07:50:01 -04:00
parent a29424aea3
commit d324c5c3c5
5 changed files with 97 additions and 23 deletions

View File

@ -95,7 +95,6 @@ APZCTreeManager::APZCTreeManager()
mTreeLock("APZCTreeLock"),
mHitResultForInputBlock(HitNothing),
mRetainedTouchIdentifier(-1),
mTouchCount(0),
mApzcTreeLog("apzctree")
{
MOZ_ASSERT(NS_IsMainThread());
@ -730,9 +729,6 @@ APZCTreeManager::ProcessTouchInput(MultiTouchInput& aInput,
return nsEventStatus_eConsumeNoDefault;
}
// NS_TOUCH_START event contains all active touches of the current
// session thus resetting mTouchCount.
mTouchCount = aInput.mTouches.Length();
mHitResultForInputBlock = HitNothing;
nsRefPtr<AsyncPanZoomController> apzc = GetTouchInputBlockAPZC(aInput, &mHitResultForInputBlock);
// XXX the following check assumes mHitResultForInputBlock == HitLayer
@ -802,21 +798,11 @@ APZCTreeManager::ProcessTouchInput(MultiTouchInput& aInput,
}
}
if (aInput.mType == MultiTouchInput::MULTITOUCH_END) {
if (mTouchCount >= aInput.mTouches.Length()) {
// NS_TOUCH_END event contains only released touches thus decrementing.
mTouchCount -= aInput.mTouches.Length();
} else {
NS_WARNING("Got an unexpected touchend/touchcancel");
mTouchCount = 0;
}
} else if (aInput.mType == MultiTouchInput::MULTITOUCH_CANCEL) {
mTouchCount = 0;
}
mTouchCounter.Update(aInput);
// If it's the end of the touch sequence then clear out variables so we
// don't keep dangling references and leak things.
if (mTouchCount == 0) {
if (mTouchCounter.GetActiveTouchCount() == 0) {
mApzcForInputBlock = nullptr;
mHitResultForInputBlock = HitNothing;
mRetainedTouchIdentifier = -1;

View File

@ -8,20 +8,22 @@
#include <stdint.h> // for uint64_t, uint32_t
#include <map> // for std::map
#include "FrameMetrics.h" // for FrameMetrics, etc
#include "Units.h" // for CSSPoint, CSSRect, etc
#include "gfxPoint.h" // for gfxPoint
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
#include "mozilla/EventForwards.h" // for WidgetInputEvent, nsEventStatus
#include "mozilla/Monitor.h" // for Monitor
#include "mozilla/gfx/Logging.h" // for gfx::TreeLog
#include "mozilla/gfx/Matrix.h" // for Matrix4x4
#include "mozilla/layers/APZUtils.h" // for HitTestResult
#include "mozilla/layers/TouchCounter.h"// for TouchCounter
#include "mozilla/Monitor.h" // for Monitor
#include "mozilla/Vector.h" // for mozilla::Vector
#include "nsAutoPtr.h" // for nsRefPtr
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
#include "mozilla/Vector.h" // for mozilla::Vector
#include "nsTArrayForwardDeclare.h" // for nsTArray, nsTArray_Impl, etc
#include "mozilla/gfx/Logging.h" // for gfx::TreeLog
#include "mozilla/layers/APZUtils.h" // for HitTestResult
#include "Units.h" // for CSSPoint, CSSRect, etc
namespace mozilla {
class InputData;
@ -520,8 +522,9 @@ private:
* this is set to -1.
*/
int32_t mRetainedTouchIdentifier;
/* The number of touch points we are tracking that are currently on the screen. */
uint32_t mTouchCount;
/* Tracks the number of touch points we are tracking that are currently on
* the screen. */
TouchCounter mTouchCounter;
/* For logging the APZC tree for debugging (enabled by the apz.printtree
* pref). */
gfx::TreeLog mApzcTreeLog;

View File

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 2; 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/. */
#include "TouchCounter.h"
#include "InputData.h"
namespace mozilla {
namespace layers {
TouchCounter::TouchCounter()
: mActiveTouchCount(0)
{
}
void
TouchCounter::Update(const MultiTouchInput& aInput)
{
switch (aInput.mType) {
case MultiTouchInput::MULTITOUCH_START:
// touch-start event contains all active touches of the current session
mActiveTouchCount = aInput.mTouches.Length();
break;
case MultiTouchInput::MULTITOUCH_END:
if (mActiveTouchCount >= aInput.mTouches.Length()) {
// touch-end event contains only released touches
mActiveTouchCount -= aInput.mTouches.Length();
} else {
NS_WARNING("Got an unexpected touchend/touchcancel");
mActiveTouchCount = 0;
}
break;
case MultiTouchInput::MULTITOUCH_CANCEL:
mActiveTouchCount = 0;
break;
default:
break;
}
}
uint32_t
TouchCounter::GetActiveTouchCount() const
{
return mActiveTouchCount;
}
} // namespace layers
} // namespace mozilla

View File

@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 2; 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_TouchCounter_h
#define mozilla_layers_TouchCounter_h
#include "mozilla/EventForwards.h"
namespace mozilla {
class MultiTouchInput;
namespace layers {
// TouchCounter simply tracks the number of active touch points. Feed it
// your input events to update the internal state.
class TouchCounter
{
public:
TouchCounter();
void Update(const MultiTouchInput& aInput);
uint32_t GetActiveTouchCount() const;
private:
uint32_t mActiveTouchCount;
};
} // namespace layers
} // namespace mozilla
#endif /* mozilla_layers_TouchCounter_h */

View File

@ -98,6 +98,7 @@ EXPORTS.mozilla.layers += [
'apz/src/APZCTreeManager.h',
'apz/src/APZUtils.h',
'apz/src/AsyncPanZoomAnimation.h',
'apz/src/TouchCounter.h',
'apz/testutil/APZTestData.h',
'apz/util/ActiveElementManager.h',
'apz/util/APZCCallbackHelper.h',
@ -241,6 +242,7 @@ UNIFIED_SOURCES += [
'apz/src/InputQueue.cpp',
'apz/src/OverscrollHandoffState.cpp',
'apz/src/TaskThrottler.cpp',
'apz/src/TouchCounter.cpp',
'apz/src/WheelScrollAnimation.cpp',
'apz/testutil/APZTestData.cpp',
'apz/util/ActiveElementManager.cpp',