Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
|
esprehn
2016/12/20 20:46:18
2009? Also use the short copyright for new files.
Navid Zolghadr
2016/12/22 20:50:33
Done.
| |
| 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/WebCoalescedInputEvent.h" | |
| 32 | |
| 33 #include "public/platform/WebGestureEvent.h" | |
| 34 | |
| 35 namespace blink { | |
| 36 | |
| 37 namespace { | |
| 38 | |
| 39 WebCoalescedInputEvent::ScopedWebInputEvent makeScopedWebInputEvent( | |
| 40 const blink::WebInputEvent& event) { | |
| 41 if (blink::WebInputEvent::isGestureEventType(event.type)) { | |
| 42 return WebCoalescedInputEvent::ScopedWebInputEvent( | |
| 43 new blink::WebGestureEvent( | |
| 44 static_cast<const blink::WebGestureEvent&>(event))); | |
| 45 } | |
| 46 if (blink::WebInputEvent::isMouseEventType(event.type)) { | |
| 47 return WebCoalescedInputEvent::ScopedWebInputEvent(new blink::WebMouseEvent( | |
| 48 static_cast<const blink::WebMouseEvent&>(event))); | |
| 49 } | |
| 50 if (blink::WebInputEvent::isTouchEventType(event.type)) { | |
| 51 return WebCoalescedInputEvent::ScopedWebInputEvent(new blink::WebTouchEvent( | |
| 52 static_cast<const blink::WebTouchEvent&>(event))); | |
| 53 } | |
| 54 if (event.type == blink::WebInputEvent::MouseWheel) { | |
| 55 return WebCoalescedInputEvent::ScopedWebInputEvent( | |
| 56 new blink::WebMouseWheelEvent( | |
| 57 static_cast<const blink::WebMouseWheelEvent&>(event))); | |
| 58 } | |
| 59 if (blink::WebInputEvent::isKeyboardEventType(event.type)) { | |
| 60 return WebCoalescedInputEvent::ScopedWebInputEvent( | |
| 61 new blink::WebKeyboardEvent( | |
| 62 static_cast<const blink::WebKeyboardEvent&>(event))); | |
| 63 } | |
| 64 NOTREACHED(); | |
| 65 return WebCoalescedInputEvent::ScopedWebInputEvent(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 WebCoalescedInputEvent::WebInputEventDeleter::WebInputEventDeleter() {} | |
| 70 | |
| 71 void WebCoalescedInputEvent::WebInputEventDeleter::operator()( | |
| 72 WebInputEvent* event) const { | |
| 73 if (!event) | |
| 74 return; | |
| 75 const WebInputEvent::Type& type = event->type; | |
| 76 if (WebInputEvent::isMouseEventType(type)) | |
| 77 delete static_cast<WebMouseEvent*>(event); | |
| 78 else if (type == WebInputEvent::MouseWheel) | |
| 79 delete static_cast<WebMouseWheelEvent*>(event); | |
| 80 else if (WebInputEvent::isKeyboardEventType(type)) | |
| 81 delete static_cast<WebKeyboardEvent*>(event); | |
| 82 else if (WebInputEvent::isTouchEventType(type)) | |
| 83 delete static_cast<WebTouchEvent*>(event); | |
| 84 else if (WebInputEvent::isGestureEventType(type)) | |
| 85 delete static_cast<WebGestureEvent*>(event); | |
| 86 NOTREACHED(); | |
| 87 } | |
| 88 | |
| 89 WebInputEvent* WebCoalescedInputEvent::eventPointer() { | |
| 90 return mEvent.get(); | |
| 91 } | |
| 92 | |
| 93 void WebCoalescedInputEvent::addCoalescedEvent( | |
| 94 const blink::WebInputEvent& event) { | |
| 95 mCoalescedEvents.push_back(makeScopedWebInputEvent(event)); | |
| 96 } | |
| 97 | |
| 98 const WebInputEvent& WebCoalescedInputEvent::event() const { | |
| 99 return *mEvent.get(); | |
| 100 } | |
| 101 | |
| 102 size_t WebCoalescedInputEvent::coalescedEventSize() const { | |
| 103 return mCoalescedEvents.size(); | |
| 104 } | |
| 105 | |
| 106 const WebInputEvent* WebCoalescedInputEvent::coalescedEvent(int index) const { | |
| 107 return mCoalescedEvents[index].get(); | |
| 108 } | |
| 109 | |
| 110 std::vector<const WebInputEvent*> | |
| 111 WebCoalescedInputEvent::getCoalescedEventsPointers() const { | |
| 112 std::vector<const WebInputEvent*> events(mCoalescedEvents.size()); | |
| 113 for (const auto& event : mCoalescedEvents) | |
| 114 events.push_back(event.get()); | |
| 115 return events; | |
| 116 } | |
| 117 | |
| 118 WebCoalescedInputEvent::WebCoalescedInputEvent(ScopedWebInputEvent event) | |
| 119 : mEvent(std::move(event)), mCoalescedEvents() { | |
| 120 mCoalescedEvents.push_back(makeScopedWebInputEvent(*(mEvent.get()))); | |
| 121 } | |
| 122 | |
| 123 WebCoalescedInputEvent::WebCoalescedInputEvent(const WebInputEvent& event) | |
| 124 : mEvent(), mCoalescedEvents() { | |
| 125 mEvent = makeScopedWebInputEvent(event); | |
| 126 mCoalescedEvents.push_back(makeScopedWebInputEvent(event)); | |
| 127 } | |
| 128 | |
| 129 WebCoalescedInputEvent::WebCoalescedInputEvent( | |
| 130 const WebInputEvent& event, | |
| 131 const std::vector<const WebInputEvent*>& coalescedEvents) | |
| 132 : mEvent(), mCoalescedEvents(coalescedEvents.size()) { | |
| 133 mEvent = makeScopedWebInputEvent(event); | |
| 134 for (const auto& coalescedEvent : coalescedEvents) | |
| 135 mCoalescedEvents.push_back(makeScopedWebInputEvent(*coalescedEvent)); | |
| 136 } | |
| 137 | |
| 138 } // namespace blink | |
| OLD | NEW |