Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 "content/common/input/web_input_event_payload.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 9 | |
| 10 namespace content { | |
| 11 namespace { | |
| 12 static WebInputEventPayload::ScopedWebInputEvent CloneWebInputEvent( | |
| 13 const WebKit::WebInputEvent& event) { | |
| 14 WebInputEventPayload::ScopedWebInputEvent clone; | |
| 15 if (WebKit::WebInputEvent::isMouseEventType(event.type)) | |
| 16 clone.reset(new WebKit::WebMouseEvent()); | |
| 17 else if (event.type == WebKit::WebInputEvent::MouseWheel) | |
| 18 clone.reset(new WebKit::WebMouseWheelEvent()); | |
| 19 else if (WebKit::WebInputEvent::isKeyboardEventType(event.type)) | |
| 20 clone.reset(new WebKit::WebKeyboardEvent()); | |
| 21 else if (WebKit::WebInputEvent::isTouchEventType(event.type)) | |
| 22 clone.reset(new WebKit::WebTouchEvent()); | |
| 23 else if (WebKit::WebInputEvent::isGestureEventType(event.type)) | |
| 24 clone.reset(new WebKit::WebGestureEvent()); | |
| 25 else | |
| 26 NOTREACHED() << "Unknown webkit event type " << event.type; | |
| 27 | |
| 28 if (!clone) | |
| 29 return clone.Pass(); | |
| 30 | |
| 31 DCHECK_EQ(event.size, clone->size); | |
| 32 memcpy(clone.get(), &event, event.size); | |
| 33 return clone.Pass(); | |
| 34 } | |
| 35 } // namespace | |
| 36 | |
| 37 WebInputEventPayload::WebInputEventDeleter::WebInputEventDeleter() {} | |
| 38 | |
| 39 void WebInputEventPayload::WebInputEventDeleter::operator()( | |
| 40 WebKit::WebInputEvent* event) const { | |
| 41 if (!event) | |
| 42 return; | |
| 43 | |
| 44 if (WebKit::WebInputEvent::isMouseEventType(event->type)) | |
| 45 delete static_cast<WebKit::WebMouseEvent*>(event); | |
| 46 else if (event->type == WebKit::WebInputEvent::MouseWheel) | |
|
palmer
2013/09/05 18:56:30
No isMouseWheelEventType method?
jdduke (slow)
2013/09/05 19:31:49
No, it does seem a bit odd. I believe it's nonexi
| |
| 47 delete static_cast<WebKit::WebMouseWheelEvent*>(event); | |
| 48 else if (WebKit::WebInputEvent::isKeyboardEventType(event->type)) | |
| 49 delete static_cast<WebKit::WebKeyboardEvent*>(event); | |
| 50 else if (WebKit::WebInputEvent::isTouchEventType(event->type)) | |
| 51 delete static_cast<WebKit::WebTouchEvent*>(event); | |
| 52 else if (WebKit::WebInputEvent::isGestureEventType(event->type)) | |
| 53 delete static_cast<WebKit::WebGestureEvent*>(event); | |
| 54 else | |
| 55 NOTREACHED() << "Unknown webkit event type " << event->type; | |
| 56 } | |
| 57 | |
| 58 WebInputEventPayload::WebInputEventPayload() | |
| 59 : is_keyboard_shortcut_(false) {} | |
| 60 | |
| 61 WebInputEventPayload::~WebInputEventPayload() {} | |
| 62 | |
| 63 scoped_ptr<WebInputEventPayload> WebInputEventPayload::Create() { | |
| 64 return make_scoped_ptr(new WebInputEventPayload()); | |
| 65 } | |
| 66 | |
| 67 scoped_ptr<WebInputEventPayload> WebInputEventPayload::Create( | |
| 68 const WebKit::WebInputEvent& event, | |
| 69 const ui::LatencyInfo& latency_info, | |
| 70 bool is_keyboard_shortcut) { | |
| 71 scoped_ptr<WebInputEventPayload> payload = Create(); | |
| 72 payload->Initialize(event, latency_info, is_keyboard_shortcut); | |
| 73 return payload.Pass(); | |
| 74 } | |
| 75 | |
| 76 const WebInputEventPayload* WebInputEventPayload::Cast(const Payload* payload) { | |
| 77 DCHECK(payload); | |
| 78 DCHECK_EQ(WEB_INPUT_EVENT, payload->GetType()); | |
| 79 return static_cast<const WebInputEventPayload*>(payload); | |
| 80 } | |
| 81 | |
| 82 InputEvent::Payload::Type WebInputEventPayload::GetType() const { | |
| 83 return WEB_INPUT_EVENT; | |
| 84 } | |
| 85 | |
| 86 void WebInputEventPayload::Initialize(const WebKit::WebInputEvent& web_event, | |
| 87 const ui::LatencyInfo& latency_info, | |
| 88 bool is_keyboard_shortcut) { | |
| 89 DCHECK(!web_event_) << "WebInputEventPayload already initialized"; | |
| 90 web_event_ = CloneWebInputEvent(web_event); | |
| 91 latency_info_ = latency_info; | |
| 92 is_keyboard_shortcut_ = is_keyboard_shortcut; | |
| 93 } | |
| 94 | |
| 95 bool WebInputEventPayload::CanCreateFollowupEvents() const { | |
| 96 return WebKit::WebInputEvent::isTouchEventType(web_event()->type); | |
| 97 } | |
| 98 | |
| 99 } // namespace content | |
| OLD | NEW |