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

Side by Side Diff: content/common/input/web_input_event_payload.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: Win export fix 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
« no previous file with comments | « content/common/input/web_input_event_payload.h ('k') | content/common/input_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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)
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() : is_keyboard_shortcut_(false) {}
59
60 WebInputEventPayload::~WebInputEventPayload() {}
61
62 scoped_ptr<WebInputEventPayload> WebInputEventPayload::Create() {
63 return make_scoped_ptr(new WebInputEventPayload());
64 }
65
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();
73 }
74
75 const WebInputEventPayload* WebInputEventPayload::Cast(const Payload* payload) {
76 DCHECK(payload);
77 DCHECK_EQ(WEB_INPUT_EVENT, payload->GetType());
78 return static_cast<const WebInputEventPayload*>(payload);
79 }
80
81 InputEvent::Payload::Type WebInputEventPayload::GetType() const {
82 return WEB_INPUT_EVENT;
83 }
84
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;
92 }
93
94 bool WebInputEventPayload::CanCreateFollowupEvents() const {
95 return WebKit::WebInputEvent::isTouchEventType(web_event()->type);
96 }
97
98 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/web_input_event_payload.h ('k') | content/common/input_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698