Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/WebMouseWheelEvent.h" 8 #include "public/platform/WebMouseWheelEvent.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 namespace { 12 namespace {
13 13
14 WebScopedInputEvent makeWebScopedInputEvent(const blink::WebInputEvent& event) { 14 WebScopedInputEvent makeWebScopedInputEvent(const blink::WebInputEvent& event) {
15 if (blink::WebInputEvent::isGestureEventType(event.type)) { 15 if (blink::WebInputEvent::isGestureEventType(event.type())) {
16 return WebScopedInputEvent(new blink::WebGestureEvent( 16 return WebScopedInputEvent(new blink::WebGestureEvent(
17 static_cast<const blink::WebGestureEvent&>(event))); 17 static_cast<const blink::WebGestureEvent&>(event)));
18 } 18 }
19 if (blink::WebInputEvent::isMouseEventType(event.type)) { 19 if (blink::WebInputEvent::isMouseEventType(event.type())) {
20 return WebScopedInputEvent(new blink::WebMouseEvent( 20 return WebScopedInputEvent(new blink::WebMouseEvent(
21 static_cast<const blink::WebMouseEvent&>(event))); 21 static_cast<const blink::WebMouseEvent&>(event)));
22 } 22 }
23 if (blink::WebInputEvent::isTouchEventType(event.type)) { 23 if (blink::WebInputEvent::isTouchEventType(event.type())) {
24 return WebScopedInputEvent(new blink::WebTouchEvent( 24 return WebScopedInputEvent(new blink::WebTouchEvent(
25 static_cast<const blink::WebTouchEvent&>(event))); 25 static_cast<const blink::WebTouchEvent&>(event)));
26 } 26 }
27 if (event.type == blink::WebInputEvent::MouseWheel) { 27 if (event.type() == blink::WebInputEvent::MouseWheel) {
28 return WebScopedInputEvent(new blink::WebMouseWheelEvent( 28 return WebScopedInputEvent(new blink::WebMouseWheelEvent(
29 static_cast<const blink::WebMouseWheelEvent&>(event))); 29 static_cast<const blink::WebMouseWheelEvent&>(event)));
30 } 30 }
31 if (blink::WebInputEvent::isKeyboardEventType(event.type)) { 31 if (blink::WebInputEvent::isKeyboardEventType(event.type())) {
32 return WebScopedInputEvent(new blink::WebKeyboardEvent( 32 return WebScopedInputEvent(new blink::WebKeyboardEvent(
33 static_cast<const blink::WebKeyboardEvent&>(event))); 33 static_cast<const blink::WebKeyboardEvent&>(event)));
34 } 34 }
35 NOTREACHED(); 35 NOTREACHED();
36 return WebScopedInputEvent(); 36 return WebScopedInputEvent();
37 } 37 }
38 38
39 struct WebInputEventDelete { 39 struct WebInputEventDelete {
40 template <class EventType> 40 template <class EventType>
41 bool Execute(WebInputEvent* event) const { 41 bool Execute(WebInputEvent* event) const {
42 if (!event) 42 if (!event)
43 return false; 43 return false;
44 DCHECK_EQ(sizeof(EventType), event->size); 44 DCHECK_EQ(sizeof(EventType), event->size());
45 delete static_cast<EventType*>(event); 45 delete static_cast<EventType*>(event);
46 return true; 46 return true;
47 } 47 }
48 }; 48 };
49 49
50 template <typename Operator, typename ArgIn> 50 template <typename Operator, typename ArgIn>
51 bool Apply(Operator op, WebInputEvent::Type type, const ArgIn& argIn) { 51 bool Apply(Operator op, WebInputEvent::Type type, const ArgIn& argIn) {
52 if (WebInputEvent::isMouseEventType(type)) 52 if (WebInputEvent::isMouseEventType(type))
53 return op.template Execute<WebMouseEvent>(argIn); 53 return op.template Execute<WebMouseEvent>(argIn);
54 if (type == WebInputEvent::MouseWheel) 54 if (type == WebInputEvent::MouseWheel)
55 return op.template Execute<WebMouseWheelEvent>(argIn); 55 return op.template Execute<WebMouseWheelEvent>(argIn);
56 if (WebInputEvent::isKeyboardEventType(type)) 56 if (WebInputEvent::isKeyboardEventType(type))
57 return op.template Execute<WebKeyboardEvent>(argIn); 57 return op.template Execute<WebKeyboardEvent>(argIn);
58 if (WebInputEvent::isTouchEventType(type)) 58 if (WebInputEvent::isTouchEventType(type))
59 return op.template Execute<WebTouchEvent>(argIn); 59 return op.template Execute<WebTouchEvent>(argIn);
60 if (WebInputEvent::isGestureEventType(type)) 60 if (WebInputEvent::isGestureEventType(type))
61 return op.template Execute<WebGestureEvent>(argIn); 61 return op.template Execute<WebGestureEvent>(argIn);
62 62
63 NOTREACHED() << "Unknown webkit event type " << type; 63 NOTREACHED() << "Unknown webkit event type " << type;
64 return false; 64 return false;
65 } 65 }
66 } 66 }
67 67
68 void WebInputEventDeleter::operator()(WebInputEvent* event) const { 68 void WebInputEventDeleter::operator()(WebInputEvent* event) const {
69 if (!event) 69 if (!event)
70 return; 70 return;
71 Apply(WebInputEventDelete(), event->type, event); 71 Apply(WebInputEventDelete(), event->type(), event);
72 } 72 }
73 73
74 WebInputEvent* WebCoalescedInputEvent::eventPointer() { 74 WebInputEvent* WebCoalescedInputEvent::eventPointer() {
75 return m_event.get(); 75 return m_event.get();
76 } 76 }
77 77
78 void WebCoalescedInputEvent::addCoalescedEvent( 78 void WebCoalescedInputEvent::addCoalescedEvent(
79 const blink::WebInputEvent& event) { 79 const blink::WebInputEvent& event) {
80 m_coalescedEvents.push_back(makeWebScopedInputEvent(event)); 80 m_coalescedEvents.push_back(makeWebScopedInputEvent(event));
81 } 81 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 WebCoalescedInputEvent::WebCoalescedInputEvent( 114 WebCoalescedInputEvent::WebCoalescedInputEvent(
115 const WebInputEvent& event, 115 const WebInputEvent& event,
116 const std::vector<const WebInputEvent*>& coalescedEvents) 116 const std::vector<const WebInputEvent*>& coalescedEvents)
117 : m_event(), m_coalescedEvents(coalescedEvents.size()) { 117 : m_event(), m_coalescedEvents(coalescedEvents.size()) {
118 m_event = makeWebScopedInputEvent(event); 118 m_event = makeWebScopedInputEvent(event);
119 for (const auto& coalescedEvent : coalescedEvents) 119 for (const auto& coalescedEvent : coalescedEvents)
120 m_coalescedEvents.push_back(makeWebScopedInputEvent(*coalescedEvent)); 120 m_coalescedEvents.push_back(makeWebScopedInputEvent(*coalescedEvent));
121 } 121 }
122 122
123 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698