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

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

Issue 181833003: [Android] Out with the Android GR, in with the new unified C++ GR (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and 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/motion_event_web.cc
diff --git a/content/browser/renderer_host/input/motion_event_web.cc b/content/browser/renderer_host/input/motion_event_web.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aca4cc6afc0b388327f60958ef3783dfadcc9332
--- /dev/null
+++ b/content/browser/renderer_host/input/motion_event_web.cc
@@ -0,0 +1,150 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/input/motion_event_web.h"
+
+#include "base/logging.h"
+
+using blink::WebInputEvent;
+using blink::WebPoint;
+using blink::WebTouchEvent;
+using blink::WebTouchPoint;
+
+namespace content {
+namespace {
+
+bool AllTouchPointsHaveState(const WebTouchEvent& event,
+ WebTouchPoint::State state) {
+ for (size_t i = 0; i < event.touchesLength; ++i) {
+ if (event.touches[i].state != state)
+ return false;
+ }
+ return true;
+}
+
+ui::MotionEvent::Action GetActionFrom(const WebTouchEvent& event) {
+ // TODO(jdduke): Use WebTouchEventTraits.
+ DCHECK(event.touchesLength);
+ switch (event.type) {
+ case WebInputEvent::TouchStart:
+ if (AllTouchPointsHaveState(event, WebTouchPoint::StatePressed))
+ return ui::MotionEvent::ACTION_DOWN;
+ else
+ return ui::MotionEvent::ACTION_POINTER_DOWN;
+ case WebInputEvent::TouchEnd:
+ if (AllTouchPointsHaveState(event, WebTouchPoint::StateReleased))
+ return ui::MotionEvent::ACTION_UP;
+ else
+ return ui::MotionEvent::ACTION_POINTER_UP;
+ case WebInputEvent::TouchCancel:
+ DCHECK(AllTouchPointsHaveState(event, WebTouchPoint::StateCancelled));
+ return ui::MotionEvent::ACTION_CANCEL;
+ case WebInputEvent::TouchMove:
+ return ui::MotionEvent::ACTION_MOVE;
+ default:
+ break;
+ };
+ NOTREACHED() << "Invalid masked TouchEvent action.";
tdresser 2014/02/27 15:28:30 What does the word "masked" mean here?
jdduke (slow) 2014/02/27 17:40:29 Oops, relic of the |GetActionMasked()| call that u
+ return ui::MotionEvent::ACTION_CANCEL;
+}
+
+int GetActionIndexFrom(const WebTouchEvent& event) {
+ for (size_t i = 0; i < event.touchesLength; ++i) {
+ if (event.touches[i].state != WebTouchPoint::StateUndefined &&
+ event.touches[i].state != WebTouchPoint::StateStationary)
+ return i;
+ }
+ return -1;
+}
+
+} // namespace
+
+MotionEventWeb::MotionEventWeb(const WebTouchEvent& event)
+ : event_(event),
+ cached_action_(GetActionFrom(event)),
+ cached_action_index_(GetActionIndexFrom(event)) {
+ DCHECK_GT(GetPointerCount(), 0U);
+}
+
+MotionEventWeb::~MotionEventWeb() {}
+
+MotionEventWeb::Action MotionEventWeb::GetAction() const {
+ return cached_action_;
+}
+
+int MotionEventWeb::GetActionIndex() const { return cached_action_index_; }
+
+size_t MotionEventWeb::GetPointerCount() const { return event_.touchesLength; }
+
+int MotionEventWeb::GetPointerId(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ return event_.touches[pointer_index].id;
+}
+
+float MotionEventWeb::GetX(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ return event_.touches[pointer_index].position.x;
+}
+
+float MotionEventWeb::GetY(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ return event_.touches[pointer_index].position.y;
+}
+
+float MotionEventWeb::GetTouchMajor(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+ // TODO(jdduke): We should be a bit more careful about axes here.
+ return 2.f * std::max(event_.touches[pointer_index].radiusX,
+ event_.touches[pointer_index].radiusY);
+}
+
+base::TimeTicks MotionEventWeb::GetEventTime() const {
+ return base::TimeTicks() +
+ base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *
+ base::Time::kMicrosecondsPerSecond);
+}
+
+size_t MotionEventWeb::GetHistorySize() const { return 0; }
+
+base::TimeTicks MotionEventWeb::GetHistoricalEventTime(
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return base::TimeTicks();
+}
+
+float MotionEventWeb::GetHistoricalTouchMajor(size_t pointer_index,
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return 0.f;
+}
+
+float MotionEventWeb::GetHistoricalX(size_t pointer_index,
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return 0.f;
+}
+
+float MotionEventWeb::GetHistoricalY(size_t pointer_index,
+ size_t historical_index) const {
+ NOTIMPLEMENTED();
+ return 0.f;
+}
+
+scoped_ptr<ui::MotionEvent> MotionEventWeb::Clone() const {
+ return scoped_ptr<MotionEvent>(new MotionEventWeb(event_));
+}
+
+scoped_ptr<ui::MotionEvent> MotionEventWeb::Cancel() const {
+ WebTouchEvent cancel_event(event_);
+
+ cancel_event.type = WebInputEvent::TouchCancel;
+ for (size_t i = 0; i < cancel_event.touchesLength; ++i)
+ cancel_event.touches[i].state = WebTouchPoint::StateCancelled;
+
+ return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event));
+}
+
+// StackAllocatedMotionEventWeb
tdresser 2014/02/27 15:28:30 This comment feels out of date.
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698