This source file includes following definitions.
- AllTouchPointsHaveState
- GetActionFrom
- GetActionIndexFrom
- cached_action_index_
- GetId
- GetAction
- GetActionIndex
- GetPointerCount
- GetPointerId
- GetX
- GetY
- GetTouchMajor
- GetPressure
- GetEventTime
- GetHistorySize
- GetHistoricalEventTime
- GetHistoricalTouchMajor
- GetHistoricalX
- GetHistoricalY
- Clone
- Cancel
#include "content/browser/renderer_host/input/motion_event_web.h"
#include "base/logging.h"
using blink::WebInputEvent;
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) {
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()
<< "Unable to derive a valid MotionEvent::Action from the WebTouchEvent.";
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;
}
}
MotionEventWeb::MotionEventWeb(const WebTouchEvent& event)
: event_(event),
cached_action_(GetActionFrom(event)),
cached_action_index_(GetActionIndexFrom(event)) {
DCHECK_GT(GetPointerCount(), 0U);
}
MotionEventWeb::~MotionEventWeb() {}
int MotionEventWeb::GetId() const {
return 0;
}
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());
return 2.f * std::max(event_.touches[pointer_index].radiusX,
event_.touches[pointer_index].radiusY);
}
float MotionEventWeb::GetPressure(size_t pointer_index) const {
return 0.f;
}
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));
}
}