| OLD | NEW |
| (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/geometry/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_POINTER_DOWN: \ | |
| 70 case ui::EventType::ET_POINTER_MOVED: \ | |
| 71 case ui::EventType::ET_POINTER_UP: \ | |
| 72 case ui::EventType::ET_POINTER_CANCELLED: \ | |
| 73 case ui::EventType::ET_POINTER_ENTERED: \ | |
| 74 case ui::EventType::ET_POINTER_EXITED: \ | |
| 75 implName(ui::PointerEvent) \ | |
| 76 case ui::EventType::ET_GESTURE_SCROLL_BEGIN: \ | |
| 77 case ui::EventType::ET_GESTURE_SCROLL_END: \ | |
| 78 case ui::EventType::ET_GESTURE_SCROLL_UPDATE: \ | |
| 79 case ui::EventType::ET_GESTURE_SHOW_PRESS: \ | |
| 80 case ui::EventType::ET_GESTURE_WIN8_EDGE_SWIPE: \ | |
| 81 case ui::EventType::ET_GESTURE_TAP: \ | |
| 82 case ui::EventType::ET_GESTURE_TAP_DOWN: \ | |
| 83 case ui::EventType::ET_GESTURE_TAP_CANCEL: \ | |
| 84 case ui::EventType::ET_GESTURE_BEGIN: \ | |
| 85 case ui::EventType::ET_GESTURE_END: \ | |
| 86 case ui::EventType::ET_GESTURE_TWO_FINGER_TAP: \ | |
| 87 case ui::EventType::ET_GESTURE_PINCH_BEGIN: \ | |
| 88 case ui::EventType::ET_GESTURE_PINCH_END: \ | |
| 89 case ui::EventType::ET_GESTURE_PINCH_UPDATE: \ | |
| 90 case ui::EventType::ET_GESTURE_LONG_PRESS: \ | |
| 91 case ui::EventType::ET_GESTURE_LONG_TAP: \ | |
| 92 case ui::EventType::ET_GESTURE_SWIPE: \ | |
| 93 case ui::EventType::ET_GESTURE_TAP_UNCONFIRMED: \ | |
| 94 case ui::EventType::ET_GESTURE_DOUBLE_TAP: \ | |
| 95 implName(ui::GestureEvent) \ | |
| 96 case ui::EventType::ET_SCROLL: \ | |
| 97 implName(ui::ScrollEvent) \ | |
| 98 case ui::EventType::ET_SCROLL_FLING_START: \ | |
| 99 case ui::EventType::ET_SCROLL_FLING_CANCEL: \ | |
| 100 if (flags & ui::MouseEventFlags::EF_FROM_TOUCH) { \ | |
| 101 implName(ui::GestureEvent) \ | |
| 102 } else { \ | |
| 103 implName(ui::MouseEvent) \ | |
| 104 } \ | |
| 105 case ui::EventType::ET_CANCEL_MODE: \ | |
| 106 implName(ui::CancelModeEvent) \ | |
| 107 default: \ | |
| 108 defaultCase; \ | |
| 109 } \ | |
| 110 } | |
| 111 | |
| 112 // Concrete event type (T) implementation procedures: size, write, read, log. | |
| 113 #define SIZE_EVENT(T) ParamTraits<T>::GetSize(s, *static_cast<T*>(p.get())); | |
| 114 #define WRITE_EVENT(T) \ | |
| 115 ParamTraits<T>::Write(m, *static_cast<T*>(p.get())); \ | |
| 116 break; | |
| 117 #define READ_EVENT(T) \ | |
| 118 { \ | |
| 119 std::unique_ptr<T> event(new T(type, time_stamp, flags)); \ | |
| 120 if (!ParamTraits<T>::Read(m, iter, event.get())) { \ | |
| 121 p->reset(); \ | |
| 122 return false; \ | |
| 123 } else { \ | |
| 124 *p = std::move(event); \ | |
| 125 return true; \ | |
| 126 } \ | |
| 127 } | |
| 128 #define LOG_EVENT(T) return ParamTraits<T>::Log(*static_cast<T*>(p.get()), l); | |
| 129 | |
| 130 // void SizeEvent(ui::EventType type, int flags, base::PickleSizer* s, | |
| 131 // const ui::ScopedEvent& p) { ... } | |
| 132 EVENT_IMPL(void, | |
| 133 SizeEvent, | |
| 134 SIZE_EVENT, | |
| 135 /* default switch/case: no-op */, | |
| 136 base::PickleSizer* s, | |
| 137 const ui::ScopedEvent& p) | |
| 138 | |
| 139 // void WriteEvent(ui::EventType type, int flags, base::Pickle* m, | |
| 140 // const ui::ScopedEvent& p) { ... } | |
| 141 EVENT_IMPL(void, | |
| 142 WriteEvent, | |
| 143 WRITE_EVENT, | |
| 144 /* default switch/case: no-op */, | |
| 145 base::Pickle* m, | |
| 146 const ui::ScopedEvent& p) | |
| 147 | |
| 148 // bool ReadEvent(ui::EventType type, int flags, base::Pickle* m, | |
| 149 // base::PickleIterator* iter, ui::ScopedEvent* p) { ... } | |
| 150 EVENT_IMPL(bool, | |
| 151 ReadEvent, | |
| 152 READ_EVENT, | |
| 153 return false;, | |
| 154 const base::Pickle* m, | |
| 155 base::PickleIterator* iter, | |
| 156 ui::ScopedEvent* p) | |
| 157 | |
| 158 // void LogEvent(ui::EventType type, int flags, const ui::ScopedEvent& p, | |
| 159 // std::string* l) { ... } | |
| 160 EVENT_IMPL(void, | |
| 161 LogEvent, | |
| 162 LOG_EVENT, | |
| 163 /* default switch/case: no-op */, | |
| 164 const ui::ScopedEvent& p, | |
| 165 std::string* l) | |
| 166 | |
| 167 #undef SIZE_EVENT | |
| 168 #undef WRITE_EVENT | |
| 169 #undef READ_EVENT | |
| 170 #undef LOG_EVENT | |
| 171 #undef EVENT_IMPL | |
| 172 | |
| 173 void ParamTraits<ui::ScopedEvent>::GetSize(base::PickleSizer* s, | |
| 174 const param_type& p) { | |
| 175 DCHECK(p); | |
| 176 GetParamSize(s, p->type_); | |
| 177 GetParamSize(s, p->name_); | |
| 178 GetParamSize(s, p->time_stamp_); | |
| 179 GetParamSize(s, p->flags_); | |
| 180 GetParamSize(s, p->phase_); | |
| 181 GetParamSize(s, p->result_); | |
| 182 GetParamSize(s, p->cancelable_); | |
| 183 SizeEvent(p->type_, p->time_stamp_, p->flags_, s, p); | |
| 184 } | |
| 185 | |
| 186 void ParamTraits<ui::ScopedEvent>::Write(base::Pickle* m, const param_type& p) { | |
| 187 DCHECK(p); | |
| 188 WriteParam(m, p->type_); | |
| 189 WriteParam(m, p->name_); | |
| 190 WriteParam(m, p->time_stamp_); | |
| 191 WriteParam(m, p->flags_); | |
| 192 WriteParam(m, p->phase_); | |
| 193 WriteParam(m, p->result_); | |
| 194 WriteParam(m, p->cancelable_); | |
| 195 WriteEvent(p->type_, p->time_stamp_, p->flags_, m, p); | |
| 196 } | |
| 197 | |
| 198 bool ParamTraits<ui::ScopedEvent>::Read(const base::Pickle* m, | |
| 199 base::PickleIterator* iter, | |
| 200 param_type* p) { | |
| 201 // Expect: valid ui::ScopedEvent that does not (yet) point to anything. | |
| 202 DCHECK(p && !*p); | |
| 203 | |
| 204 ui::EventType type; | |
| 205 std::string name; | |
| 206 base::TimeDelta time_stamp; | |
| 207 int flags; | |
| 208 ui::EventPhase phase; | |
| 209 ui::EventResult result; | |
| 210 bool cancelable; | |
| 211 | |
| 212 // Read initial params, then invoke ReadEvent which will reset() |p| to an | |
| 213 // instance of the correct concrete event type. | |
| 214 if (!ReadParam(m, iter, &type) || !ReadParam(m, iter, &name) || | |
| 215 !ReadParam(m, iter, &time_stamp) || !ReadParam(m, iter, &flags) || | |
| 216 !ReadParam(m, iter, &phase) || !ReadParam(m, iter, &result) || | |
| 217 !ReadParam(m, iter, &cancelable) || | |
| 218 !ReadEvent(type, time_stamp, flags, m, iter, p)) | |
| 219 return false; | |
| 220 | |
| 221 // Fill in abstract event information. | |
| 222 (*p)->type_ = type; | |
| 223 (*p)->name_ = name; | |
| 224 (*p)->time_stamp_ = time_stamp; | |
| 225 (*p)->flags_ = flags; | |
| 226 (*p)->phase_ = phase; | |
| 227 (*p)->result_ = result; | |
| 228 (*p)->cancelable_ = cancelable; | |
| 229 | |
| 230 return true; | |
| 231 } | |
| 232 | |
| 233 void ParamTraits<ui::ScopedEvent>::Log(const param_type& p, std::string* l) { | |
| 234 l->append("<UI Event: "); | |
| 235 LogEvent(p->type_, p->time_stamp_, p->flags_, p, l); | |
| 236 l->append(">"); | |
| 237 } | |
| 238 | |
| 239 void ParamTraits<ui::CancelModeEvent>::GetSize(base::PickleSizer* s, | |
| 240 const param_type& p) {} | |
| 241 | |
| 242 void ParamTraits<ui::CancelModeEvent>::Write(base::Pickle* m, | |
| 243 const param_type& p) {} | |
| 244 | |
| 245 bool ParamTraits<ui::CancelModeEvent>::Read(const base::Pickle* m, | |
| 246 base::PickleIterator* iter, | |
| 247 param_type* p) { | |
| 248 return true; | |
| 249 } | |
| 250 | |
| 251 void ParamTraits<ui::CancelModeEvent>::Log(const param_type& p, | |
| 252 std::string* l) { | |
| 253 l->append("<ui::CancelModeEvent>"); | |
| 254 } | |
| 255 | |
| 256 void ParamTraits<ui::GestureEventDetails::Details>::GetSize( | |
| 257 base::PickleSizer* s, | |
| 258 const param_type& p) { | |
| 259 s->AddBytes(sizeof(param_type)); | |
| 260 } | |
| 261 | |
| 262 void ParamTraits<ui::GestureEventDetails::Details>::Write(base::Pickle* m, | |
| 263 const param_type& p) { | |
| 264 m->WriteBytes(&p, sizeof(param_type)); | |
| 265 } | |
| 266 | |
| 267 bool ParamTraits<ui::GestureEventDetails::Details>::Read( | |
| 268 const base::Pickle* m, | |
| 269 base::PickleIterator* iter, | |
| 270 param_type* p) { | |
| 271 const char* data; | |
| 272 if (!iter->ReadBytes(&data, sizeof(param_type))) | |
| 273 return false; | |
| 274 | |
| 275 memcpy(p, data, sizeof(param_type)); | |
| 276 return true; | |
| 277 } | |
| 278 | |
| 279 void ParamTraits<ui::GestureEventDetails::Details>::Log(const param_type& p, | |
| 280 std::string* l) { | |
| 281 l->append("<ui::GestureEventDetails::Details>"); | |
| 282 } | |
| 283 | |
| 284 } // namespace IPC | |
| OLD | NEW |