| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "public/platform/WebCoalescedInputEvent.h" |
| 6 |
| 7 #include "public/platform/WebGestureEvent.h" |
| 8 #include "public/platform/WebMouseWheelEvent.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 namespace { |
| 13 |
| 14 WebScopedInputEvent makeWebScopedInputEvent(const blink::WebInputEvent& event) { |
| 15 if (blink::WebInputEvent::isGestureEventType(event.type)) { |
| 16 return WebScopedInputEvent(new blink::WebGestureEvent( |
| 17 static_cast<const blink::WebGestureEvent&>(event))); |
| 18 } |
| 19 if (blink::WebInputEvent::isMouseEventType(event.type)) { |
| 20 return WebScopedInputEvent(new blink::WebMouseEvent( |
| 21 static_cast<const blink::WebMouseEvent&>(event))); |
| 22 } |
| 23 if (blink::WebInputEvent::isTouchEventType(event.type)) { |
| 24 return WebScopedInputEvent(new blink::WebTouchEvent( |
| 25 static_cast<const blink::WebTouchEvent&>(event))); |
| 26 } |
| 27 if (event.type == blink::WebInputEvent::MouseWheel) { |
| 28 return WebScopedInputEvent(new blink::WebMouseWheelEvent( |
| 29 static_cast<const blink::WebMouseWheelEvent&>(event))); |
| 30 } |
| 31 if (blink::WebInputEvent::isKeyboardEventType(event.type)) { |
| 32 return WebScopedInputEvent(new blink::WebKeyboardEvent( |
| 33 static_cast<const blink::WebKeyboardEvent&>(event))); |
| 34 } |
| 35 NOTREACHED(); |
| 36 return WebScopedInputEvent(); |
| 37 } |
| 38 |
| 39 struct WebInputEventDelete { |
| 40 template <class EventType> |
| 41 bool Execute(WebInputEvent* event) const { |
| 42 if (!event) |
| 43 return false; |
| 44 DCHECK_EQ(sizeof(EventType), event->size); |
| 45 delete static_cast<EventType*>(event); |
| 46 return true; |
| 47 } |
| 48 }; |
| 49 |
| 50 template <typename Operator, typename ArgIn> |
| 51 bool Apply(Operator op, WebInputEvent::Type type, const ArgIn& argIn) { |
| 52 if (WebInputEvent::isMouseEventType(type)) |
| 53 return op.template Execute<WebMouseEvent>(argIn); |
| 54 if (type == WebInputEvent::MouseWheel) |
| 55 return op.template Execute<WebMouseWheelEvent>(argIn); |
| 56 if (WebInputEvent::isKeyboardEventType(type)) |
| 57 return op.template Execute<WebKeyboardEvent>(argIn); |
| 58 if (WebInputEvent::isTouchEventType(type)) |
| 59 return op.template Execute<WebTouchEvent>(argIn); |
| 60 if (WebInputEvent::isGestureEventType(type)) |
| 61 return op.template Execute<WebGestureEvent>(argIn); |
| 62 |
| 63 NOTREACHED() << "Unknown webkit event type " << type; |
| 64 return false; |
| 65 } |
| 66 } |
| 67 |
| 68 void WebInputEventDeleter::operator()(WebInputEvent* event) const { |
| 69 if (!event) |
| 70 return; |
| 71 Apply(WebInputEventDelete(), event->type, event); |
| 72 } |
| 73 |
| 74 WebInputEvent* WebCoalescedInputEvent::eventPointer() { |
| 75 return m_event.get(); |
| 76 } |
| 77 |
| 78 void WebCoalescedInputEvent::addCoalescedEvent( |
| 79 const blink::WebInputEvent& event) { |
| 80 m_coalescedEvents.push_back(makeWebScopedInputEvent(event)); |
| 81 } |
| 82 |
| 83 const WebInputEvent& WebCoalescedInputEvent::event() const { |
| 84 return *m_event.get(); |
| 85 } |
| 86 |
| 87 size_t WebCoalescedInputEvent::coalescedEventSize() const { |
| 88 return m_coalescedEvents.size(); |
| 89 } |
| 90 |
| 91 const WebInputEvent* WebCoalescedInputEvent::coalescedEvent(int index) const { |
| 92 return m_coalescedEvents[index].get(); |
| 93 } |
| 94 |
| 95 std::vector<const WebInputEvent*> |
| 96 WebCoalescedInputEvent::getCoalescedEventsPointers() const { |
| 97 std::vector<const WebInputEvent*> events; |
| 98 for (const auto& event : m_coalescedEvents) |
| 99 events.push_back(event.get()); |
| 100 return events; |
| 101 } |
| 102 |
| 103 WebCoalescedInputEvent::WebCoalescedInputEvent(WebScopedInputEvent event) |
| 104 : m_event(std::move(event)), m_coalescedEvents() { |
| 105 m_coalescedEvents.push_back(makeWebScopedInputEvent(*(m_event.get()))); |
| 106 } |
| 107 |
| 108 WebCoalescedInputEvent::WebCoalescedInputEvent(const WebInputEvent& event) |
| 109 : m_event(), m_coalescedEvents() { |
| 110 m_event = makeWebScopedInputEvent(event); |
| 111 m_coalescedEvents.push_back(makeWebScopedInputEvent(event)); |
| 112 } |
| 113 |
| 114 WebCoalescedInputEvent::WebCoalescedInputEvent( |
| 115 const WebInputEvent& event, |
| 116 const std::vector<const WebInputEvent*>& coalescedEvents) |
| 117 : m_event(), m_coalescedEvents(coalescedEvents.size()) { |
| 118 m_event = makeWebScopedInputEvent(event); |
| 119 for (const auto& coalescedEvent : coalescedEvents) |
| 120 m_coalescedEvents.push_back(makeWebScopedInputEvent(*coalescedEvent)); |
| 121 } |
| 122 |
| 123 } // namespace blink |
| OLD | NEW |