Commit b8f269fd authored by Kartikaya Gupta's avatar Kartikaya Gupta
Browse files

Bug 1525570 - Move TouchCounter to apz/util/ and allow counting WidgetTouchEvent too. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D21577

--HG--
rename : gfx/layers/apz/src/TouchCounter.cpp => gfx/layers/apz/util/TouchCounter.cpp
rename : gfx/layers/apz/src/TouchCounter.h => gfx/layers/apz/util/TouchCounter.h
extra : moz-landing-system : lando
parent 83a64ce3
......@@ -20,12 +20,12 @@
#include "mozilla/layers/IAPZCTreeManager.h" // for IAPZCTreeManager
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/KeyboardMap.h" // for KeyboardMap
#include "mozilla/layers/TouchCounter.h" // for TouchCounter
#include "mozilla/RecursiveMutex.h" // for RecursiveMutex
#include "mozilla/RefPtr.h" // for RefPtr
#include "mozilla/TimeStamp.h" // for mozilla::TimeStamp
#include "mozilla/UniquePtr.h" // for UniquePtr
#include "nsCOMPtr.h" // for already_AddRefed
#include "TouchCounter.h" // for TouchCounter
#if defined(MOZ_WIDGET_ANDROID)
# include "mozilla/layers/AndroidDynamicToolbarAnimator.h"
......
......@@ -14,9 +14,9 @@
#include "mozilla/layers/APZUtils.h"
#include "mozilla/layers/LayersTypes.h" // for TouchBehaviorFlags
#include "mozilla/layers/AsyncDragMetrics.h"
#include "mozilla/layers/TouchCounter.h"
#include "mozilla/TimeStamp.h" // for TimeStamp
#include "nsTArray.h" // for nsTArray
#include "TouchCounter.h"
namespace mozilla {
namespace layers {
......
......@@ -11,10 +11,10 @@
#include "DragTracker.h"
#include "InputData.h"
#include "mozilla/EventForwards.h"
#include "mozilla/layers/TouchCounter.h"
#include "mozilla/RefPtr.h"
#include "mozilla/UniquePtr.h"
#include "nsTArray.h"
#include "TouchCounter.h"
namespace mozilla {
......
......@@ -7,6 +7,7 @@
#include "TouchCounter.h"
#include "InputData.h"
#include "mozilla/TouchEvents.h"
namespace mozilla {
namespace layers {
......@@ -24,7 +25,7 @@ void TouchCounter::Update(const MultiTouchInput& aInput) {
// touch-end event contains only released touches
mActiveTouchCount -= aInput.mTouches.Length();
} else {
NS_WARNING("Got an unexpected touchend/touchcancel");
NS_WARNING("Got an unexpected touchend");
mActiveTouchCount = 0;
}
break;
......@@ -36,6 +37,29 @@ void TouchCounter::Update(const MultiTouchInput& aInput) {
}
}
void TouchCounter::Update(const WidgetTouchEvent& aEvent) {
switch (aEvent.mMessage) {
case eTouchStart:
// touch-start event contains all active touches of the current session
mActiveTouchCount = aEvent.mTouches.Length();
break;
case eTouchEnd:
if (mActiveTouchCount >= aEvent.mTouches.Length()) {
// touch-end event contains only released touches
mActiveTouchCount -= aEvent.mTouches.Length();
} else {
NS_WARNING("Got an unexpected touchend");
mActiveTouchCount = 0;
}
break;
case eTouchCancel:
mActiveTouchCount = 0;
break;
default:
break;
}
}
uint32_t TouchCounter::GetActiveTouchCount() const { return mActiveTouchCount; }
} // namespace layers
......
......@@ -16,11 +16,14 @@ class MultiTouchInput;
namespace layers {
// TouchCounter simply tracks the number of active touch points. Feed it
// your input events to update the internal state.
// your input events to update the internal state. Generally you should
// only be calling one of the Update functions, depending on which type
// of touch inputs you have access to.
class TouchCounter {
public:
TouchCounter();
void Update(const MultiTouchInput& aInput);
void Update(const WidgetTouchEvent& aEvent);
uint32_t GetActiveTouchCount() const;
private:
......
......@@ -118,6 +118,7 @@ EXPORTS.mozilla.layers += [
'apz/util/InputAPZContext.h',
'apz/util/ScrollLinkedEffectDetector.h',
'apz/util/TouchActionHelper.h',
'apz/util/TouchCounter.h',
'AsyncCanvasRenderer.h',
'AtomicRefCountedWithFinalize.h',
'AxisPhysicsModel.h',
......@@ -336,7 +337,6 @@ UNIFIED_SOURCES += [
'apz/src/PotentialCheckerboardDurationTracker.cpp',
'apz/src/QueuedInput.cpp',
'apz/src/SimpleVelocityTracker.cpp',
'apz/src/TouchCounter.cpp',
'apz/src/WheelScrollAnimation.cpp',
'apz/testutil/APZTestData.cpp',
'apz/util/ActiveElementManager.cpp',
......@@ -350,6 +350,7 @@ UNIFIED_SOURCES += [
'apz/util/InputAPZContext.cpp',
'apz/util/ScrollLinkedEffectDetector.cpp',
'apz/util/TouchActionHelper.cpp',
'apz/util/TouchCounter.cpp',
'AsyncCanvasRenderer.cpp',
'AxisPhysicsModel.cpp',
'AxisPhysicsMSDModel.cpp',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment