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

Side by Side Diff: content/common/input/web_platform_input_event.cc

Issue 19624005: Add InputEvent and EventPacket types for batched input delivery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 7 years, 3 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
(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_platform_input_event.h"
6
7 #include "base/logging.h"
8 #include "third_party/WebKit/public/web/WebInputEvent.h"
9
10 namespace content {
11 namespace {
12 static WebPlatformInputEvent::ScopedWebInputEvent CloneWebInputEvent(
13 const WebKit::WebInputEvent& event) {
14 WebPlatformInputEvent::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 WebPlatformInputEvent::WebInputEventDeleter::WebInputEventDeleter() {}
38
39 void WebPlatformInputEvent::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)
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 WebPlatformInputEvent::WebPlatformInputEvent(AckType ack_type, int64 id)
59 : InputEvent(WEB_PLATFORM, ack_type, id),
60 is_keyboard_shortcut(false) {}
61
62 WebPlatformInputEvent::~WebPlatformInputEvent() {}
63
64 scoped_ptr<WebPlatformInputEvent> WebPlatformInputEvent::Create() {
65 return make_scoped_ptr(new WebPlatformInputEvent(ACK_REQUIRED, 0));
66 }
67
68 scoped_ptr<WebPlatformInputEvent> WebPlatformInputEvent::Create(
69 int64 id,
70 const WebKit::WebInputEvent& event,
71 const ui::LatencyInfo& latency_info,
72 bool is_keyboard_shortcut,
73 bool can_create_followup_events) {
74 AckType ack_type = can_create_followup_events ? ACK_CAN_CREATE_FOLLOWUP_EVENTS
75 : ACK_REQUIRED;
76 scoped_ptr<WebPlatformInputEvent> web_event(
77 new WebPlatformInputEvent(ack_type, id));
78 web_event->Initialize(event,
79 latency_info,
80 is_keyboard_shortcut);
81 return web_event.Pass();
82 }
83
84 void WebPlatformInputEvent::Initialize(const WebKit::WebInputEvent& event,
85 const ui::LatencyInfo& latency_info,
86 bool is_keyboard_shortcut) {
87 this->event = CloneWebInputEvent(event);
88 this->latency_info = latency_info;
89 this->is_keyboard_shortcut = is_keyboard_shortcut;
90 }
91
92 const WebPlatformInputEvent* WebPlatformInputEvent::EventCast(
93 const InputEvent* event) {
94 DCHECK_EQ(InputEvent::WEB_PLATFORM, event->type);
95 return static_cast<const WebPlatformInputEvent*>(event);
96 }
97
98 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698