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 115 116 117 118 119 120 121 122 123
|
// Copyright 2016 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 "public/platform/WebCoalescedInputEvent.h"
#include "public/platform/WebGestureEvent.h"
#include "public/platform/WebMouseWheelEvent.h"
namespace blink {
namespace {
WebScopedInputEvent makeWebScopedInputEvent(const blink::WebInputEvent& event) {
if (blink::WebInputEvent::isGestureEventType(event.type())) {
return WebScopedInputEvent(new blink::WebGestureEvent(
static_cast<const blink::WebGestureEvent&>(event)));
}
if (blink::WebInputEvent::isMouseEventType(event.type())) {
return WebScopedInputEvent(new blink::WebMouseEvent(
static_cast<const blink::WebMouseEvent&>(event)));
}
if (blink::WebInputEvent::isTouchEventType(event.type())) {
return WebScopedInputEvent(new blink::WebTouchEvent(
static_cast<const blink::WebTouchEvent&>(event)));
}
if (event.type() == blink::WebInputEvent::MouseWheel) {
return WebScopedInputEvent(new blink::WebMouseWheelEvent(
static_cast<const blink::WebMouseWheelEvent&>(event)));
}
if (blink::WebInputEvent::isKeyboardEventType(event.type())) {
return WebScopedInputEvent(new blink::WebKeyboardEvent(
static_cast<const blink::WebKeyboardEvent&>(event)));
}
NOTREACHED();
return WebScopedInputEvent();
}
struct WebInputEventDelete {
template <class EventType>
bool Execute(WebInputEvent* event) const {
if (!event)
return false;
DCHECK_EQ(sizeof(EventType), event->size());
delete static_cast<EventType*>(event);
return true;
}
};
template <typename Operator, typename ArgIn>
bool Apply(Operator op, WebInputEvent::Type type, const ArgIn& argIn) {
if (WebInputEvent::isMouseEventType(type))
return op.template Execute<WebMouseEvent>(argIn);
if (type == WebInputEvent::MouseWheel)
return op.template Execute<WebMouseWheelEvent>(argIn);
if (WebInputEvent::isKeyboardEventType(type))
return op.template Execute<WebKeyboardEvent>(argIn);
if (WebInputEvent::isTouchEventType(type))
return op.template Execute<WebTouchEvent>(argIn);
if (WebInputEvent::isGestureEventType(type))
return op.template Execute<WebGestureEvent>(argIn);
NOTREACHED() << "Unknown webkit event type " << type;
return false;
}
}
void WebInputEventDeleter::operator()(WebInputEvent* event) const {
if (!event)
return;
Apply(WebInputEventDelete(), event->type(), event);
}
WebInputEvent* WebCoalescedInputEvent::eventPointer() {
return m_event.get();
}
void WebCoalescedInputEvent::addCoalescedEvent(
const blink::WebInputEvent& event) {
m_coalescedEvents.push_back(makeWebScopedInputEvent(event));
}
const WebInputEvent& WebCoalescedInputEvent::event() const {
return *m_event.get();
}
size_t WebCoalescedInputEvent::coalescedEventSize() const {
return m_coalescedEvents.size();
}
const WebInputEvent* WebCoalescedInputEvent::coalescedEvent(int index) const {
return m_coalescedEvents[index].get();
}
std::vector<const WebInputEvent*>
WebCoalescedInputEvent::getCoalescedEventsPointers() const {
std::vector<const WebInputEvent*> events;
for (const auto& event : m_coalescedEvents)
events.push_back(event.get());
return events;
}
WebCoalescedInputEvent::WebCoalescedInputEvent(WebScopedInputEvent event)
: m_event(std::move(event)), m_coalescedEvents() {
m_coalescedEvents.push_back(makeWebScopedInputEvent(*(m_event.get())));
}
WebCoalescedInputEvent::WebCoalescedInputEvent(const WebInputEvent& event)
: m_event(), m_coalescedEvents() {
m_event = makeWebScopedInputEvent(event);
m_coalescedEvents.push_back(makeWebScopedInputEvent(event));
}
WebCoalescedInputEvent::WebCoalescedInputEvent(
const WebInputEvent& event,
const std::vector<const WebInputEvent*>& coalescedEvents)
: m_event(), m_coalescedEvents(coalescedEvents.size()) {
m_event = makeWebScopedInputEvent(event);
for (const auto& coalescedEvent : coalescedEvents)
m_coalescedEvents.push_back(makeWebScopedInputEvent(*coalescedEvent));
}
} // namespace blink
|