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

Unified Diff: content/browser/renderer_host/input/web_input_event_util.cc

Issue 178193022: [Android] Always insert a TouchCancel if window or tab focus is lost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 10 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
Index: content/browser/renderer_host/input/web_input_event_util.cc
diff --git a/content/browser/renderer_host/input/web_input_event_util.cc b/content/browser/renderer_host/input/web_input_event_util.cc
index 804c0b126c19ee0223b10b5048ca9a7dca276259..46d5fcbc6d3c7b654e56cf81bc9c732f862de783 100644
--- a/content/browser/renderer_host/input/web_input_event_util.cc
+++ b/content/browser/renderer_host/input/web_input_event_util.cc
@@ -5,7 +5,12 @@
#include "content/browser/renderer_host/input/web_input_event_util.h"
#include "base/strings/string_util.h"
-#include "third_party/WebKit/public/web/WebInputEvent.h"
+#include "ui/events/gesture_detection/motion_event.h"
+
+using blink::WebInputEvent;
+using blink::WebTouchEvent;
+using blink::WebTouchPoint;
+using ui::MotionEvent;
namespace {
@@ -125,6 +130,69 @@ const char* GetKeyIdentifier(ui::KeyboardCode key_code) {
};
}
+WebInputEvent::Type ToWebInputEventType(MotionEvent::Action action) {
+ switch (action) {
+ case MotionEvent::ACTION_DOWN:
+ return WebInputEvent::TouchStart;
+ case MotionEvent::ACTION_MOVE:
+ return WebInputEvent::TouchMove;
+ case MotionEvent::ACTION_UP:
+ return WebInputEvent::TouchEnd;
+ case MotionEvent::ACTION_CANCEL:
+ return WebInputEvent::TouchCancel;
+ case MotionEvent::ACTION_POINTER_DOWN:
+ return WebInputEvent::TouchStart;
+ case MotionEvent::ACTION_POINTER_UP:
+ return WebInputEvent::TouchEnd;
+ }
+ NOTREACHED() << "Invalid MotionEvent::Action.";
+ return WebInputEvent::Undefined;
+}
+
+// Note that |is_action_pointer| is meaningful only in the context of
+// |ACTION_POINTER_UP| and |ACTION_POINTER_DOWN|; other actions map directly to
+// WebTouchPoint::State.
+WebTouchPoint::State ToWebTouchPointState(MotionEvent::Action action,
+ bool is_action_pointer) {
+ switch (action) {
+ case MotionEvent::ACTION_DOWN:
+ return WebTouchPoint::StatePressed;
+ case MotionEvent::ACTION_MOVE:
+ return WebTouchPoint::StateMoved;
+ case MotionEvent::ACTION_UP:
+ return WebTouchPoint::StateReleased;
+ case MotionEvent::ACTION_CANCEL:
+ return WebTouchPoint::StateCancelled;
+ case MotionEvent::ACTION_POINTER_DOWN:
+ return is_action_pointer ? WebTouchPoint::StatePressed
+ : WebTouchPoint::StateStationary;
+ case MotionEvent::ACTION_POINTER_UP:
+ return is_action_pointer ? WebTouchPoint::StateReleased
+ : WebTouchPoint::StateStationary;
+ }
+ NOTREACHED() << "Invalid MotionEvent::Action.";
+ return WebTouchPoint::StateUndefined;
+}
+
+WebTouchPoint CreateWebTouchPoint(const MotionEvent& event,
+ size_t pointer_index,
+ float scale) {
+ WebTouchPoint touch;
+ touch.id = event.GetPointerId(pointer_index);
+ touch.state = ToWebTouchPointState(
+ event.GetAction(),
+ static_cast<int>(pointer_index) == event.GetActionIndex());
+ touch.position.x = event.GetX(pointer_index) * scale;
+ touch.position.y = event.GetY(pointer_index) * scale;
+ // TODO(joth): Raw event co-ordinates.
+ touch.screenPosition = touch.position;
+ touch.radiusX = touch.radiusY =
+ event.GetTouchMajor(pointer_index) * 0.5f * scale;
+ touch.force = event.GetPressure(pointer_index);
+
+ return touch;
+}
+
} // namespace
namespace content {
@@ -142,4 +210,26 @@ void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event,
}
}
+blink::WebTouchEvent CreateWebTouchEventFromMotionEvent(
+ const ui::MotionEvent& event,
+ float scale) {
+ blink::WebTouchEvent result;
+
+ result.type = ToWebInputEventType(event.GetAction());
+ DCHECK(WebInputEvent::isTouchEventType(result.type));
+
+ result.timeStampSeconds =
+ (event.GetEventTime() - base::TimeTicks()).InSecondsF();
+
+ result.touchesLength =
+ std::min(event.GetPointerCount(),
+ static_cast<size_t>(WebTouchEvent::touchesLengthCap));
+ DCHECK_GT(result.touchesLength, 0U);
+
+ for (size_t i = 0; i < result.touchesLength; ++i)
+ result.touches[i] = CreateWebTouchPoint(event, i, scale);
+
+ return result;
+}
+
} // namespace content
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_util.h ('k') | ui/events/gesture_detection/gesture_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698