1 // Copyright 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.
5 #include "content/common/input/web_input_event_payload.h"
7 #include "base/logging.h"
8 #include "third_party/WebKit/public/web/WebInputEvent.h"
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());
26 NOTREACHED() << "Unknown webkit event type " << event
.type
;
31 DCHECK_EQ(event
.size
, clone
->size
);
32 memcpy(clone
.get(), &event
, event
.size
);
37 WebInputEventPayload::WebInputEventDeleter::WebInputEventDeleter() {}
39 void WebInputEventPayload::WebInputEventDeleter::operator()(
40 WebKit::WebInputEvent
* event
) const {
44 if (WebKit::WebInputEvent::isMouseEventType(event
->type
))
45 delete static_cast<WebKit::WebMouseEvent
*>(event
);
46 else if (event
->type
== WebKit::WebInputEvent::MouseWheel
)
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
);
55 NOTREACHED() << "Unknown webkit event type " << event
->type
;
58 WebInputEventPayload::WebInputEventPayload() : is_keyboard_shortcut_(false) {}
60 WebInputEventPayload::~WebInputEventPayload() {}
62 scoped_ptr
<WebInputEventPayload
> WebInputEventPayload::Create() {
63 return make_scoped_ptr(new WebInputEventPayload());
66 scoped_ptr
<WebInputEventPayload
> WebInputEventPayload::Create(
67 const WebKit::WebInputEvent
& event
,
68 const ui::LatencyInfo
& latency_info
,
69 bool is_keyboard_shortcut
) {
70 scoped_ptr
<WebInputEventPayload
> payload
= Create();
71 payload
->Initialize(event
, latency_info
, is_keyboard_shortcut
);
72 return payload
.Pass();
75 const WebInputEventPayload
* WebInputEventPayload::Cast(const Payload
* payload
) {
77 DCHECK_EQ(WEB_INPUT_EVENT
, payload
->GetType());
78 return static_cast<const WebInputEventPayload
*>(payload
);
81 InputEvent::Payload::Type
WebInputEventPayload::GetType() const {
82 return WEB_INPUT_EVENT
;
85 void WebInputEventPayload::Initialize(const WebKit::WebInputEvent
& web_event
,
86 const ui::LatencyInfo
& latency_info
,
87 bool is_keyboard_shortcut
) {
88 DCHECK(!web_event_
) << "WebInputEventPayload already initialized";
89 web_event_
= CloneWebInputEvent(web_event
);
90 latency_info_
= latency_info
;
91 is_keyboard_shortcut_
= is_keyboard_shortcut
;
94 bool WebInputEventPayload::CanCreateFollowupEvents() const {
95 return WebKit::WebInputEvent::isTouchEventType(web_event()->type
);
98 } // namespace content