| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/blink/web_input_event_traits.h" | 5 #include "ui/events/blink/web_input_event_traits.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | 9 #include "third_party/WebKit/public/platform/WebGestureEvent.h" |
| 10 #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" | 10 #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 template <class EventType> | 122 template <class EventType> |
| 123 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const { | 123 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const { |
| 124 *type_size = sizeof(EventType); | 124 *type_size = sizeof(EventType); |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 struct WebInputEventClone { | 129 struct WebInputEventClone { |
| 130 template <class EventType> | 130 template <class EventType> |
| 131 bool Execute(const WebInputEvent& event, | 131 bool Execute(const WebInputEvent& event, |
| 132 ScopedWebInputEvent* scoped_event) const { | 132 blink::WebScopedInputEvent* scoped_event) const { |
| 133 DCHECK_EQ(sizeof(EventType), event.size); | 133 DCHECK_EQ(sizeof(EventType), event.size); |
| 134 *scoped_event = ScopedWebInputEvent( | 134 *scoped_event = blink::WebScopedInputEvent( |
| 135 new EventType(static_cast<const EventType&>(event))); | 135 new EventType(static_cast<const EventType&>(event))); |
| 136 return true; | 136 return true; |
| 137 } | 137 } |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 struct WebInputEventDelete { | |
| 141 template <class EventType> | |
| 142 bool Execute(WebInputEvent* event, bool* /* dummy_var */) const { | |
| 143 if (!event) | |
| 144 return false; | |
| 145 DCHECK_EQ(sizeof(EventType), event->size); | |
| 146 delete static_cast<EventType*>(event); | |
| 147 return true; | |
| 148 } | |
| 149 }; | |
| 150 | |
| 151 template <typename Operator, typename ArgIn, typename ArgOut> | 140 template <typename Operator, typename ArgIn, typename ArgOut> |
| 152 bool Apply(Operator op, | 141 bool Apply(Operator op, |
| 153 WebInputEvent::Type type, | 142 WebInputEvent::Type type, |
| 154 const ArgIn& arg_in, | 143 const ArgIn& arg_in, |
| 155 ArgOut* arg_out) { | 144 ArgOut* arg_out) { |
| 156 if (WebInputEvent::isMouseEventType(type)) | 145 if (WebInputEvent::isMouseEventType(type)) |
| 157 return op.template Execute<WebMouseEvent>(arg_in, arg_out); | 146 return op.template Execute<WebMouseEvent>(arg_in, arg_out); |
| 158 else if (type == WebInputEvent::MouseWheel) | 147 else if (type == WebInputEvent::MouseWheel) |
| 159 return op.template Execute<WebMouseWheelEvent>(arg_in, arg_out); | 148 return op.template Execute<WebMouseWheelEvent>(arg_in, arg_out); |
| 160 else if (WebInputEvent::isKeyboardEventType(type)) | 149 else if (WebInputEvent::isKeyboardEventType(type)) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 175 Apply(WebInputEventToString(), event.type, event, &result); | 164 Apply(WebInputEventToString(), event.type, event, &result); |
| 176 return result; | 165 return result; |
| 177 } | 166 } |
| 178 | 167 |
| 179 size_t WebInputEventTraits::GetSize(WebInputEvent::Type type) { | 168 size_t WebInputEventTraits::GetSize(WebInputEvent::Type type) { |
| 180 size_t size = 0; | 169 size_t size = 0; |
| 181 Apply(WebInputEventSize(), type, type, &size); | 170 Apply(WebInputEventSize(), type, type, &size); |
| 182 return size; | 171 return size; |
| 183 } | 172 } |
| 184 | 173 |
| 185 ScopedWebInputEvent WebInputEventTraits::Clone(const WebInputEvent& event) { | 174 blink::WebScopedInputEvent WebInputEventTraits::Clone( |
| 186 ScopedWebInputEvent scoped_event; | 175 const WebInputEvent& event) { |
| 176 blink::WebScopedInputEvent scoped_event; |
| 187 Apply(WebInputEventClone(), event.type, event, &scoped_event); | 177 Apply(WebInputEventClone(), event.type, event, &scoped_event); |
| 188 return scoped_event; | 178 return scoped_event; |
| 189 } | 179 } |
| 190 | 180 |
| 191 void WebInputEventTraits::Delete(WebInputEvent* event) { | |
| 192 if (!event) | |
| 193 return; | |
| 194 bool dummy_var = false; | |
| 195 Apply(WebInputEventDelete(), event->type, event, &dummy_var); | |
| 196 } | |
| 197 | |
| 198 bool WebInputEventTraits::ShouldBlockEventStream(const WebInputEvent& event) { | 181 bool WebInputEventTraits::ShouldBlockEventStream(const WebInputEvent& event) { |
| 199 switch (event.type) { | 182 switch (event.type) { |
| 200 case WebInputEvent::MouseDown: | 183 case WebInputEvent::MouseDown: |
| 201 case WebInputEvent::MouseUp: | 184 case WebInputEvent::MouseUp: |
| 202 case WebInputEvent::MouseEnter: | 185 case WebInputEvent::MouseEnter: |
| 203 case WebInputEvent::MouseLeave: | 186 case WebInputEvent::MouseLeave: |
| 204 case WebInputEvent::ContextMenu: | 187 case WebInputEvent::ContextMenu: |
| 205 case WebInputEvent::GestureScrollBegin: | 188 case WebInputEvent::GestureScrollBegin: |
| 206 case WebInputEvent::GestureScrollEnd: | 189 case WebInputEvent::GestureScrollEnd: |
| 207 case WebInputEvent::GestureShowPress: | 190 case WebInputEvent::GestureShowPress: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 source_event_type = SourceEventType::WHEEL; | 245 source_event_type = SourceEventType::WHEEL; |
| 263 } else if (event.sourceDevice == | 246 } else if (event.sourceDevice == |
| 264 blink::WebGestureDevice::WebGestureDeviceTouchscreen) { | 247 blink::WebGestureDevice::WebGestureDeviceTouchscreen) { |
| 265 source_event_type = SourceEventType::TOUCH; | 248 source_event_type = SourceEventType::TOUCH; |
| 266 } | 249 } |
| 267 LatencyInfo latency_info(source_event_type); | 250 LatencyInfo latency_info(source_event_type); |
| 268 return latency_info; | 251 return latency_info; |
| 269 } | 252 } |
| 270 | 253 |
| 271 } // namespace ui | 254 } // namespace ui |
| OLD | NEW |