mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
optimize pinchGesture
Signed-off-by: wangzezhen <wangzezhen@huawei.com> Change-Id: Ie7abf00ecdba4ee67c04337e780864fc2ada34e1
This commit is contained in:
parent
679c40358f
commit
ba13161736
@ -170,6 +170,30 @@ void EventManager::TouchTest(
|
||||
renderNode->TouchTest(point, point, touchRestrict, axisTouchTestResult_);
|
||||
}
|
||||
|
||||
void EventManager::FlushTouchEventsBegin(const std::list<TouchEvent>& touchEvents)
|
||||
{
|
||||
for (auto iter = touchEvents.begin(); iter != touchEvents.end(); ++iter) {
|
||||
const auto result = touchTestResults_.find((*iter).id);
|
||||
if (result != touchTestResults_.end()) {
|
||||
for (auto entry = result->second.rbegin(); entry != result->second.rend(); ++entry) {
|
||||
(*entry)->OnFlushTouchEventsBegin();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::FlushTouchEventsEnd(const std::list<TouchEvent>& touchEvents)
|
||||
{
|
||||
for (auto iter = touchEvents.begin(); iter != touchEvents.end(); ++iter) {
|
||||
const auto result = touchTestResults_.find((*iter).id);
|
||||
if (result != touchTestResults_.end()) {
|
||||
for (auto entry = result->second.rbegin(); entry != result->second.rend(); ++entry) {
|
||||
(*entry)->OnFlushTouchEventsEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EventManager::DispatchTouchEvent(const TouchEvent& point)
|
||||
{
|
||||
ContainerScope scope(instanceId_);
|
||||
|
@ -69,6 +69,8 @@ public:
|
||||
|
||||
bool DispatchTouchEvent(const TouchEvent& point);
|
||||
bool DispatchTouchEvent(const AxisEvent& event);
|
||||
void FlushTouchEventsBegin(const std::list<TouchEvent>& touchEvents);
|
||||
void FlushTouchEventsEnd(const std::list<TouchEvent>& touchEvents);
|
||||
|
||||
// Distribute the key event to the corresponding root node. If the root node is not processed, return false and the
|
||||
// platform will handle it.
|
||||
|
@ -360,6 +360,8 @@ public:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual void OnFlushTouchEventsBegin() {}
|
||||
virtual void OnFlushTouchEventsEnd() {}
|
||||
|
||||
void SetTouchRestrict(const TouchRestrict& touchRestrict)
|
||||
{
|
||||
|
@ -20,9 +20,8 @@
|
||||
#include "base/geometry/offset.h"
|
||||
#include "base/log/log.h"
|
||||
#include "base/memory/ace_type.h"
|
||||
#include "core/gestures/click_recognizer.h"
|
||||
#include "core/gestures/gesture_referee.h"
|
||||
#include "core/gestures/pan_recognizer.h"
|
||||
#include "core/gestures/pinch_recognizer.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
@ -51,11 +50,9 @@ void ExclusiveRecognizer::OnAccepted(size_t touchId)
|
||||
}
|
||||
}
|
||||
|
||||
if (AceType::InstanceOf<PanRecognizer>(activeRecognizer_) ||
|
||||
AceType::InstanceOf<PinchRecognizer>(activeRecognizer_)) {
|
||||
return;
|
||||
if (AceType::InstanceOf<ClickRecognizer>(activeRecognizer_)) {
|
||||
Reset();
|
||||
}
|
||||
Reset();
|
||||
}
|
||||
|
||||
void ExclusiveRecognizer::OnRejected(size_t touchId)
|
||||
@ -121,6 +118,20 @@ bool ExclusiveRecognizer::HandleEvent(const TouchEvent& point)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ExclusiveRecognizer::OnFlushTouchEventsBegin()
|
||||
{
|
||||
for (auto& recognizer : recognizers_) {
|
||||
recognizer->OnFlushTouchEventsBegin();
|
||||
}
|
||||
}
|
||||
|
||||
void ExclusiveRecognizer::OnFlushTouchEventsEnd()
|
||||
{
|
||||
for (auto& recognizer : recognizers_) {
|
||||
recognizer->OnFlushTouchEventsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void ExclusiveRecognizer::BatchAdjudicate(
|
||||
const std::set<size_t>& touchIds, const RefPtr<GestureRecognizer>& recognizer, GestureDisposal disposal)
|
||||
{
|
||||
|
@ -50,6 +50,8 @@ public:
|
||||
void OnRejected(size_t touchId) override;
|
||||
void OnPending(size_t touchId) override;
|
||||
bool HandleEvent(const TouchEvent& point) override;
|
||||
void OnFlushTouchEventsBegin() override;
|
||||
void OnFlushTouchEventsEnd() override;
|
||||
|
||||
private:
|
||||
void HandleTouchDownEvent(const TouchEvent& event) override {};
|
||||
|
@ -101,6 +101,20 @@ bool ParallelRecognizer::HandleEvent(const TouchEvent& point)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParallelRecognizer::OnFlushTouchEventsBegin()
|
||||
{
|
||||
for (auto& recognizer : recognizers_) {
|
||||
recognizer->OnFlushTouchEventsBegin();
|
||||
}
|
||||
}
|
||||
|
||||
void ParallelRecognizer::OnFlushTouchEventsEnd()
|
||||
{
|
||||
for (auto& recognizer : recognizers_) {
|
||||
recognizer->OnFlushTouchEventsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
bool ParallelRecognizer::IsRecognizeEnd(const RefPtr<GestureRecognizer>& recognizer)
|
||||
{
|
||||
DetectState currState = recognizer->GetDetectState();
|
||||
|
@ -50,6 +50,8 @@ public:
|
||||
void OnRejected(size_t touchId) override;
|
||||
void OnPending(size_t touchId) override;
|
||||
bool HandleEvent(const TouchEvent& point) override;
|
||||
void OnFlushTouchEventsBegin() override;
|
||||
void OnFlushTouchEventsEnd() override;
|
||||
|
||||
private:
|
||||
void HandleTouchDownEvent(const TouchEvent& event) override {};
|
||||
|
@ -31,7 +31,6 @@ constexpr int32_t AXIS_PINCH_FINGERS = 2;
|
||||
void PinchRecognizer::OnAccepted()
|
||||
{
|
||||
SendCallbackMsg(onActionStart_);
|
||||
SendCallbackMsg(onActionUpdate_);
|
||||
|
||||
if (pendingEnd_) {
|
||||
SendCallbackMsg(onActionEnd_);
|
||||
@ -143,10 +142,22 @@ void PinchRecognizer::HandleTouchMoveEvent(const TouchEvent& event)
|
||||
}
|
||||
} else if (state_ == DetectState::DETECTED && refereeState_ == RefereeState::SUCCEED) {
|
||||
scale_ = currentDev_ / initialDev_;
|
||||
SendCallbackMsg(onActionUpdate_);
|
||||
if (isFlushTouchEventsEnd_) {
|
||||
SendCallbackMsg(onActionUpdate_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PinchRecognizer::OnFlushTouchEventsBegin()
|
||||
{
|
||||
isFlushTouchEventsEnd_ = false;
|
||||
}
|
||||
|
||||
void PinchRecognizer::OnFlushTouchEventsEnd()
|
||||
{
|
||||
isFlushTouchEventsEnd_ = true;
|
||||
}
|
||||
|
||||
void PinchRecognizer::HandleTouchMoveEvent(const AxisEvent& event)
|
||||
{
|
||||
LOGD("pinch recognizer receives touch move event");
|
||||
|
@ -51,6 +51,8 @@ private:
|
||||
void Reset();
|
||||
void SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& callback);
|
||||
Offset ComputePinchCenter();
|
||||
void OnFlushTouchEventsBegin() override;
|
||||
void OnFlushTouchEventsEnd() override;
|
||||
|
||||
double distance_ = 0.0;
|
||||
double initialDev_ = 0.0;
|
||||
@ -61,6 +63,7 @@ private:
|
||||
std::map<int32_t, TouchEvent> touchPoints_;
|
||||
bool pendingEnd_ = false;
|
||||
bool pendingCancel_ = false;
|
||||
bool isFlushTouchEventsEnd_ = false;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -131,6 +131,20 @@ bool SequencedRecognizer::HandleEvent(const TouchEvent& point)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SequencedRecognizer::OnFlushTouchEventsBegin()
|
||||
{
|
||||
for (auto& recognizer : recognizers_) {
|
||||
recognizer->OnFlushTouchEventsBegin();
|
||||
}
|
||||
}
|
||||
|
||||
void SequencedRecognizer::OnFlushTouchEventsEnd()
|
||||
{
|
||||
for (auto& recognizer : recognizers_) {
|
||||
recognizer->OnFlushTouchEventsEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void SequencedRecognizer::BatchAdjudicate(
|
||||
const std::set<size_t>& touchIds, const RefPtr<GestureRecognizer>& recognizer, GestureDisposal disposal)
|
||||
{
|
||||
|
@ -43,6 +43,8 @@ public:
|
||||
void OnRejected() override;
|
||||
bool HandleEvent(const TouchEvent& point) override;
|
||||
void OnPending(size_t touchId) override;
|
||||
void OnFlushTouchEventsBegin() override;
|
||||
void OnFlushTouchEventsEnd() override;
|
||||
|
||||
private:
|
||||
void HandleTouchDownEvent(const TouchEvent& event) override {};
|
||||
|
@ -1670,20 +1670,31 @@ void PipelineContext::FlushTouchEvents()
|
||||
return;
|
||||
}
|
||||
{
|
||||
eventManager_->FlushTouchEventsBegin(touchEvents_);
|
||||
std::unordered_set<int32_t> moveEventIds;
|
||||
decltype(touchEvents_) touchEvents(std::move(touchEvents_));
|
||||
if (touchEvents.empty()) {
|
||||
return;
|
||||
}
|
||||
std::list<TouchEvent> touchPoints;
|
||||
for (auto iter = touchEvents.rbegin(); iter != touchEvents.rend(); ++iter) {
|
||||
auto scalePoint = (*iter).CreateScalePoint(GetViewScale());
|
||||
auto result = moveEventIds.emplace(scalePoint.id);
|
||||
if (result.second) {
|
||||
ResSchedReport::GetInstance().DispatchTouchEventStart(scalePoint.type);
|
||||
eventManager_->DispatchTouchEvent(scalePoint);
|
||||
ResSchedReport::GetInstance().DispatchTouchEventEnd();
|
||||
touchPoints.emplace_front(scalePoint);
|
||||
}
|
||||
}
|
||||
|
||||
auto maxSize = touchPoints.size();
|
||||
for (auto iter = touchPoints.rbegin(); iter != touchPoints.rend(); ++iter) {
|
||||
maxSize--;
|
||||
if (maxSize == 0) {
|
||||
eventManager_->FlushTouchEventsEnd(touchPoints);
|
||||
}
|
||||
ResSchedReport::GetInstance().DispatchTouchEventStart((*iter).type);
|
||||
eventManager_->DispatchTouchEvent(*iter);
|
||||
ResSchedReport::GetInstance().DispatchTouchEventEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user