OLD | NEW |
---|---|
(Empty) | |
1 /* | |
jbroman
2016/11/22 15:27:37
Blink-side implementations of classes in public/pl
| |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "public/platform/CoalescedWebInputEvent.h" | |
32 | |
33 #include "public/platform/WebGestureEvent.h" | |
34 | |
35 namespace blink { | |
36 | |
37 namespace { | |
38 | |
39 CoalescedWebInputEvent::ScopedWebInputEvent makeScopedWebInputEvent( | |
40 const blink::WebInputEvent& event) { | |
41 if (blink::WebInputEvent::isGestureEventType(event.type)) { | |
dtapuska
2016/11/21 18:21:18
What about keyboard?
| |
42 return CoalescedWebInputEvent::ScopedWebInputEvent( | |
43 new blink::WebGestureEvent( | |
44 static_cast<const blink::WebGestureEvent&>(event))); | |
45 } | |
46 if (blink::WebInputEvent::isMouseEventType(event.type)) { | |
47 return CoalescedWebInputEvent::ScopedWebInputEvent(new blink::WebMouseEvent( | |
48 static_cast<const blink::WebMouseEvent&>(event))); | |
49 } | |
50 if (blink::WebInputEvent::isTouchEventType(event.type)) { | |
51 return CoalescedWebInputEvent::ScopedWebInputEvent(new blink::WebTouchEvent( | |
52 static_cast<const blink::WebTouchEvent&>(event))); | |
53 } | |
54 if (event.type == blink::WebInputEvent::MouseWheel) { | |
55 return CoalescedWebInputEvent::ScopedWebInputEvent( | |
56 new blink::WebMouseWheelEvent( | |
57 static_cast<const blink::WebMouseWheelEvent&>(event))); | |
58 } | |
59 NOTREACHED(); | |
60 return CoalescedWebInputEvent::ScopedWebInputEvent(); | |
61 } | |
62 } | |
63 | |
64 CoalescedWebInputEvent::WebInputEventDeleter::WebInputEventDeleter() {} | |
65 | |
66 void CoalescedWebInputEvent::WebInputEventDeleter::operator()( | |
67 WebInputEvent* event) const { | |
68 if (!event) | |
69 return; | |
70 const WebInputEvent::Type& type = event->type; | |
71 if (WebInputEvent::isMouseEventType(type)) | |
72 delete static_cast<WebMouseEvent*>(event); | |
73 else if (type == WebInputEvent::MouseWheel) | |
74 delete static_cast<WebMouseWheelEvent*>(event); | |
75 else if (WebInputEvent::isKeyboardEventType(type)) | |
76 delete static_cast<WebKeyboardEvent*>(event); | |
77 else if (WebInputEvent::isTouchEventType(type)) | |
78 delete static_cast<WebTouchEvent*>(event); | |
79 else if (WebInputEvent::isGestureEventType(type)) | |
80 delete static_cast<WebGestureEvent*>(event); | |
81 NOTREACHED(); | |
jbroman
2016/11/22 15:27:37
This looks like it _is_ reached; there's no early
| |
82 } | |
83 | |
84 const WebInputEvent& CoalescedWebInputEvent::event() const { | |
85 return *mEvent.get(); | |
86 } | |
87 | |
88 WebInputEvent* CoalescedWebInputEvent::event() { | |
89 return mEvent.get(); | |
90 } | |
91 | |
92 void CoalescedWebInputEvent::addCoalescedEvent( | |
93 const blink::WebInputEvent& event) { | |
94 mCoalescedEvents.push_back(makeScopedWebInputEvent(event)); | |
95 } | |
96 | |
97 size_t CoalescedWebInputEvent::coalescedEventSize() { | |
98 return mCoalescedEvents.size(); | |
99 } | |
100 | |
101 WebInputEvent* CoalescedWebInputEvent::coalescedEvent(int index) { | |
102 return mCoalescedEvents[index]; | |
103 } | |
104 | |
105 const std::vector<WebInputEvent*>& | |
106 CoalescedWebInputEvent::getCoalescedEventsPointers() { | |
107 std::vector<WebInputEvent*> events(mCoalescedEvents.size()); | |
108 for (const auto& event : mCoalescedEvents) | |
109 events.push_back(event.get()); | |
110 return events; | |
111 } | |
112 | |
113 CoalescedWebInputEvent::CoalescedWebInputEvent(ScopedWebInputEvent event) | |
114 : mEvent(std::move(event)), mCoalescedEvents() { | |
115 mCoalescedEvents.push_back(makeScopedWebInputEvent(*(mEvent.get()))); | |
116 } | |
117 | |
118 CoalescedWebInputEvent::CoalescedWebInputEvent(const WebInputEvent& event) | |
119 : mEvent(makeScopedWebInputEvent(event)), mCoalescedEvents() { | |
120 mCoalescedEvents.push_back(makeScopedWebInputEvent(event)); | |
121 } | |
122 | |
123 CoalescedWebInputEvent::CoalescedWebInputEvent( | |
124 const WebInputEvent&, | |
125 const std::vector<const WebInputEvent*>& coalescedEvents) | |
126 : mEvent(makeScopedWebInputEvent(event)), | |
127 mCoalescedEvents(coalescedEvents.size()) { | |
128 for (const auto& coalescedEvent : coalescedEvents) | |
129 mCoalescedEvents.push_back(makeScopedWebInputEvent(*coalescedEvent)); | |
130 } | |
131 | |
132 } // namespace blink | |
OLD | NEW |