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