1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
// Copyright 2015 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/synthetic_touch_driver.h"
#include "content/browser/renderer_host/input/synthetic_gesture_target.h"
namespace content {
SyntheticTouchDriver::SyntheticTouchDriver() {
std::fill(index_map_.begin(), index_map_.end(), -1);
}
SyntheticTouchDriver::SyntheticTouchDriver(SyntheticWebTouchEvent touch_event)
: touch_event_(touch_event) {
std::fill(index_map_.begin(), index_map_.end(), -1);
}
SyntheticTouchDriver::~SyntheticTouchDriver() {}
void SyntheticTouchDriver::DispatchEvent(SyntheticGestureTarget* target,
const base::TimeTicks& timestamp) {
touch_event_.SetTimeStamp(timestamp);
if (touch_event_.GetType() != blink::WebInputEvent::kUndefined)
target->DispatchInputEventToPlatform(touch_event_);
touch_event_.ResetPoints();
ResetIndexMap();
}
void SyntheticTouchDriver::Press(float x,
float y,
int index,
SyntheticPointerActionParams::Button button) {
DCHECK_GE(index, 0);
DCHECK_LT(index, blink::WebTouchEvent::kTouchesLengthCap);
int touch_index = touch_event_.PressPoint(x, y);
index_map_[index] = touch_index;
}
void SyntheticTouchDriver::Move(float x, float y, int index) {
DCHECK_GE(index, 0);
DCHECK_LT(index, blink::WebTouchEvent::kTouchesLengthCap);
touch_event_.MovePoint(index_map_[index], x, y);
}
void SyntheticTouchDriver::Release(
int index,
SyntheticPointerActionParams::Button button) {
DCHECK_GE(index, 0);
DCHECK_LT(index, blink::WebTouchEvent::kTouchesLengthCap);
touch_event_.ReleasePoint(index_map_[index]);
index_map_[index] = -1;
}
void SyntheticTouchDriver::Leave(int index) {
NOTIMPLEMENTED();
}
bool SyntheticTouchDriver::UserInputCheck(
const SyntheticPointerActionParams& params) const {
if (params.index() < 0 ||
params.index() >= blink::WebTouchEvent::kTouchesLengthCap)
return false;
if (params.pointer_action_type() ==
SyntheticPointerActionParams::PointerActionType::NOT_INITIALIZED) {
return false;
}
if (params.pointer_action_type() ==
SyntheticPointerActionParams::PointerActionType::PRESS &&
index_map_[params.index()] >= 0) {
return false;
}
if (params.pointer_action_type() ==
SyntheticPointerActionParams::PointerActionType::MOVE &&
index_map_[params.index()] == -1) {
return false;
}
if (params.pointer_action_type() ==
SyntheticPointerActionParams::PointerActionType::RELEASE &&
index_map_[params.index()] == -1) {
return false;
}
return true;
}
void SyntheticTouchDriver::ResetIndexMap() {
unsigned free_index = 0;
for (unsigned int i = 0; i < blink::WebTouchEvent::kTouchesLengthCap; ++i) {
if (free_index >= touch_event_.touches_length)
break;
if (touch_event_.touches[i].state !=
blink::WebTouchPoint::kStateUndefined) {
touch_event_.touches[free_index] = touch_event_.touches[i];
int index = GetIndexFromMap(i);
index_map_[index] = free_index;
free_index++;
}
}
}
int SyntheticTouchDriver::GetIndexFromMap(int value) const {
int index = std::find(index_map_.begin(), index_map_.end(), value) -
index_map_.begin();
DCHECK(index >= 0 && index < blink::WebTouchEvent::kTouchesLengthCap);
return index;
}
} // namespace content
|