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

Side by Side Diff: components/mus/common/event_param_traits.cc

Issue 1755703004: Revert of IPC::ParamTraits for ui::Event (towards ui::Events over mojo IPC) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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) 2016 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 "components/mus/common/event_param_traits.h"
6
7 #include <string.h>
8
9 #include "ipc/ipc_message_utils.h"
10 #include "ipc/ipc_param_traits.h"
11 #include "ui/events/event.h"
12 #include "ui/gfx/ipc/gfx_param_traits.h"
13
14 // Generate param traits size methods.
15 #include "ipc/param_traits_size_macros.h"
16 namespace IPC {
17 #include "components/mus/common/event_param_traits_macros.h"
18 }
19
20 // Generate param traits write methods.
21 #include "ipc/param_traits_write_macros.h"
22 namespace IPC {
23 #include "components/mus/common/event_param_traits_macros.h"
24 }
25
26 // Generate param traits read methods.
27 #include "ipc/param_traits_read_macros.h"
28 namespace IPC {
29 #include "components/mus/common/event_param_traits_macros.h"
30 }
31
32 // Generate param traits log methods.
33 #include "ipc/param_traits_log_macros.h"
34 namespace IPC {
35 #include "components/mus/common/event_param_traits_macros.h"
36 }
37
38 namespace IPC {
39
40 // Implements (Write|Read|Log)Event for event type-qualified functions. Every
41 // such function invokes an implementation according to the event type and
42 // flags, or else invokes a default implementation. Event constructors require
43 // |type|, |time_stamp|, and |flags| (hence the common arguments passed to each
44 // implementation).
45 #define EVENT_IMPL(ReturnType, methodName, implName, defaultCase, ...) \
46 ReturnType ParamTraits<ui::ScopedEvent>::methodName( \
47 ui::EventType type, base::TimeDelta time_stamp, int flags, \
48 ##__VA_ARGS__) { \
49 switch (type) { \
50 case ui::EventType::ET_MOUSE_PRESSED: \
51 case ui::EventType::ET_MOUSE_DRAGGED: \
52 case ui::EventType::ET_MOUSE_RELEASED: \
53 case ui::EventType::ET_MOUSE_MOVED: \
54 case ui::EventType::ET_MOUSE_ENTERED: \
55 case ui::EventType::ET_MOUSE_EXITED: \
56 case ui::EventType::ET_MOUSE_CAPTURE_CHANGED: \
57 implName(ui::MouseEvent) \
58 case ui::EventType::ET_KEY_PRESSED: \
59 case ui::EventType::ET_KEY_RELEASED: \
60 implName(ui::KeyEvent) \
61 case ui::EventType::ET_MOUSEWHEEL: \
62 implName(ui::MouseWheelEvent) \
63 case ui::EventType::ET_TOUCH_RELEASED: \
64 case ui::EventType::ET_TOUCH_PRESSED: \
65 case ui::EventType::ET_TOUCH_MOVED: \
66 case ui::EventType::ET_TOUCH_CANCELLED: \
67 case ui::EventType::ET_DROP_TARGET_EVENT: \
68 implName(ui::TouchEvent) \
69 case ui::EventType::ET_GESTURE_SCROLL_BEGIN: \
70 case ui::EventType::ET_GESTURE_SCROLL_END: \
71 case ui::EventType::ET_GESTURE_SCROLL_UPDATE: \
72 case ui::EventType::ET_GESTURE_SHOW_PRESS: \
73 case ui::EventType::ET_GESTURE_WIN8_EDGE_SWIPE: \
74 case ui::EventType::ET_GESTURE_TAP: \
75 case ui::EventType::ET_GESTURE_TAP_DOWN: \
76 case ui::EventType::ET_GESTURE_TAP_CANCEL: \
77 case ui::EventType::ET_GESTURE_BEGIN: \
78 case ui::EventType::ET_GESTURE_END: \
79 case ui::EventType::ET_GESTURE_TWO_FINGER_TAP: \
80 case ui::EventType::ET_GESTURE_PINCH_BEGIN: \
81 case ui::EventType::ET_GESTURE_PINCH_END: \
82 case ui::EventType::ET_GESTURE_PINCH_UPDATE: \
83 case ui::EventType::ET_GESTURE_LONG_PRESS: \
84 case ui::EventType::ET_GESTURE_LONG_TAP: \
85 case ui::EventType::ET_GESTURE_SWIPE: \
86 case ui::EventType::ET_GESTURE_TAP_UNCONFIRMED: \
87 case ui::EventType::ET_GESTURE_DOUBLE_TAP: \
88 implName(ui::GestureEvent) \
89 case ui::EventType::ET_SCROLL: \
90 implName(ui::ScrollEvent) \
91 case ui::EventType::ET_SCROLL_FLING_START: \
92 case ui::EventType::ET_SCROLL_FLING_CANCEL: \
93 if (flags & ui::MouseEventFlags::EF_FROM_TOUCH) { \
94 implName(ui::GestureEvent) \
95 } else { \
96 implName(ui::MouseEvent) \
97 } \
98 case ui::EventType::ET_CANCEL_MODE: \
99 implName(ui::CancelModeEvent) \
100 default: \
101 defaultCase; \
102 } \
103 }
104
105 // Concrete event type (T) implementation procedures: size, write, read, log.
106 #define SIZE_EVENT(T) ParamTraits<T>::GetSize(s, *static_cast<T*>(p.get()));
107 #define WRITE_EVENT(T) \
108 ParamTraits<T>::Write(m, *static_cast<T*>(p.get())); \
109 break;
110 #define READ_EVENT(T) \
111 { \
112 scoped_ptr<T> event(new T(type, time_stamp, flags)); \
113 if (!ParamTraits<T>::Read(m, iter, event.get())) { \
114 p->reset(); \
115 return false; \
116 } else { \
117 *p = std::move(event); \
118 return true; \
119 } \
120 }
121 #define LOG_EVENT(T) return ParamTraits<T>::Log(*static_cast<T*>(p.get()), l);
122
123 // void SizeEvent(ui::EventType type, int flags, base::PickleSizer* s,
124 // const ui::ScopedEvent& p) { ... }
125 EVENT_IMPL(void,
126 SizeEvent,
127 SIZE_EVENT,
128 /* default switch/case: no-op */,
129 base::PickleSizer* s,
130 const ui::ScopedEvent& p)
131
132 // void WriteEvent(ui::EventType type, int flags, base::Pickle* m,
133 // const ui::ScopedEvent& p) { ... }
134 EVENT_IMPL(void,
135 WriteEvent,
136 WRITE_EVENT,
137 /* default switch/case: no-op */,
138 base::Pickle* m,
139 const ui::ScopedEvent& p)
140
141 // bool ReadEvent(ui::EventType type, int flags, base::Pickle* m,
142 // base::PickleIterator* iter, ui::ScopedEvent* p) { ... }
143 EVENT_IMPL(bool,
144 ReadEvent,
145 READ_EVENT,
146 return false;,
147 const base::Pickle* m,
148 base::PickleIterator* iter,
149 ui::ScopedEvent* p)
150
151 // void LogEvent(ui::EventType type, int flags, const ui::ScopedEvent& p,
152 // std::string* l) { ... }
153 EVENT_IMPL(void,
154 LogEvent,
155 LOG_EVENT,
156 /* default switch/case: no-op */,
157 const ui::ScopedEvent& p,
158 std::string* l)
159
160 #undef SIZE_EVENT
161 #undef WRITE_EVENT
162 #undef READ_EVENT
163 #undef LOG_EVENT
164 #undef EVENT_IMPL
165
166 void ParamTraits<ui::ScopedEvent>::GetSize(base::PickleSizer* s,
167 const param_type& p) {
168 DCHECK(p);
169 GetParamSize(s, p->type_);
170 GetParamSize(s, p->name_);
171 GetParamSize(s, p->time_stamp_);
172 GetParamSize(s, p->flags_);
173 GetParamSize(s, p->phase_);
174 GetParamSize(s, p->result_);
175 GetParamSize(s, p->cancelable_);
176 SizeEvent(p->type_, p->time_stamp_, p->flags_, s, p);
177 }
178
179 void ParamTraits<ui::ScopedEvent>::Write(base::Pickle* m, const param_type& p) {
180 DCHECK(p);
181 WriteParam(m, p->type_);
182 WriteParam(m, p->name_);
183 WriteParam(m, p->time_stamp_);
184 WriteParam(m, p->flags_);
185 WriteParam(m, p->phase_);
186 WriteParam(m, p->result_);
187 WriteParam(m, p->cancelable_);
188 WriteEvent(p->type_, p->time_stamp_, p->flags_, m, p);
189 }
190
191 bool ParamTraits<ui::ScopedEvent>::Read(const base::Pickle* m,
192 base::PickleIterator* iter,
193 param_type* p) {
194 // Expect: valid ui::ScopedEvent that does not (yet) point to anything.
195 DCHECK(p && !*p);
196
197 ui::EventType type;
198 std::string name;
199 base::TimeDelta time_stamp;
200 int flags;
201 ui::EventPhase phase;
202 ui::EventResult result;
203 bool cancelable;
204
205 // Read initial params, then invoke ReadEvent which will reset() |p| to an
206 // instance of the correct concrete event type.
207 if (!ReadParam(m, iter, &type) || !ReadParam(m, iter, &name) ||
208 !ReadParam(m, iter, &time_stamp) || !ReadParam(m, iter, &flags) ||
209 !ReadParam(m, iter, &phase) || !ReadParam(m, iter, &result) ||
210 !ReadParam(m, iter, &cancelable) ||
211 !ReadEvent(type, time_stamp, flags, m, iter, p))
212 return false;
213
214 // Fill in abstract event information.
215 (*p)->type_ = type;
216 (*p)->name_ = name;
217 (*p)->time_stamp_ = time_stamp;
218 (*p)->flags_ = flags;
219 (*p)->phase_ = phase;
220 (*p)->result_ = result;
221 (*p)->cancelable_ = cancelable;
222
223 return true;
224 }
225
226 void ParamTraits<ui::ScopedEvent>::Log(const param_type& p, std::string* l) {
227 l->append("<UI Event: ");
228 LogEvent(p->type_, p->time_stamp_, p->flags_, p, l);
229 l->append(">");
230 }
231
232 void ParamTraits<ui::CancelModeEvent>::GetSize(base::PickleSizer* s,
233 const param_type& p) {}
234
235 void ParamTraits<ui::CancelModeEvent>::Write(base::Pickle* m,
236 const param_type& p) {}
237
238 bool ParamTraits<ui::CancelModeEvent>::Read(const base::Pickle* m,
239 base::PickleIterator* iter,
240 param_type* p) {
241 return true;
242 }
243
244 void ParamTraits<ui::CancelModeEvent>::Log(const param_type& p,
245 std::string* l) {
246 l->append("<ui::CancelModeEvent>");
247 }
248
249 void ParamTraits<ui::GestureEventDetails::Details>::GetSize(
250 base::PickleSizer* s,
251 const param_type& p) {
252 s->AddBytes(sizeof(param_type));
253 }
254
255 void ParamTraits<ui::GestureEventDetails::Details>::Write(base::Pickle* m,
256 const param_type& p) {
257 m->WriteBytes(&p, sizeof(param_type));
258 }
259
260 bool ParamTraits<ui::GestureEventDetails::Details>::Read(
261 const base::Pickle* m,
262 base::PickleIterator* iter,
263 param_type* p) {
264 const char* data;
265 if (!iter->ReadBytes(&data, sizeof(param_type)))
266 return false;
267
268 memcpy(p, data, sizeof(param_type));
269 return true;
270 }
271
272 void ParamTraits<ui::GestureEventDetails::Details>::Log(const param_type& p,
273 std::string* l) {
274 l->append("<ui::GestureEventDetails::Details>");
275 }
276
277 } // namespace IPC
OLDNEW
« no previous file with comments | « components/mus/common/event_param_traits.h ('k') | components/mus/common/event_param_traits_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698