Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: src/views/SkTouchGesture.cpp

Issue 1996613002: Correct gesture scale and translation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/views/SkTouchGesture.h ('k') | tools/viewer/Viewer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/views/SkTouchGesture.cpp
diff --git a/src/views/SkTouchGesture.cpp b/src/views/SkTouchGesture.cpp
index 5fc8d7ee90b1e5c3fb371576e9cffbcfa6659115..752828e37f3a866edc2dc66ae86717ec64bce956 100644
--- a/src/views/SkTouchGesture.cpp
+++ b/src/views/SkTouchGesture.cpp
@@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
-
+#include <algorithm>
#include "SkTouchGesture.h"
#include "SkMatrix.h"
@@ -109,6 +109,7 @@ SkTouchGesture::~SkTouchGesture() {
}
void SkTouchGesture::reset() {
+ fIsTransLimited = false;
fTouches.reset();
fState = kEmpty_State;
fLocalM.reset();
@@ -293,6 +294,8 @@ void SkTouchGesture::touchEnd(void* owner) {
}
fTouches.removeShuffle(index);
+
+ limitTrans();
}
float SkTouchGesture::computePinch(const Rec& rec0, const Rec& rec1) {
@@ -327,3 +330,24 @@ bool SkTouchGesture::handleDblTap(float x, float y) {
fLastUpP.set(x, y);
return found;
}
+
+void SkTouchGesture::setTransLimit(const SkRect& contentRect, const SkRect& windowRect) {
+ fIsTransLimited = true;
+ fContentRect = contentRect;
+ fWindowRect = windowRect;
+}
+
+void SkTouchGesture::limitTrans() {
+ if (!fIsTransLimited) {
+ return;
+ }
+
+ SkRect scaledContent = fContentRect;
+ fGlobalM.mapRect(&scaledContent);
+ const SkScalar ZERO = 0;
+
+ fGlobalM.postTranslate(ZERO, std::min(ZERO, fWindowRect.fBottom - scaledContent.fTop));
+ fGlobalM.postTranslate(ZERO, std::max(ZERO, fWindowRect.fTop - scaledContent.fBottom));
+ fGlobalM.postTranslate(std::min(ZERO, fWindowRect.fRight - scaledContent.fLeft), ZERO);
+ fGlobalM.postTranslate(std::max(ZERO, fWindowRect.fLeft - scaledContent.fRight), ZERO);
+}
« no previous file with comments | « include/views/SkTouchGesture.h ('k') | tools/viewer/Viewer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698