| 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/WebKeyboardEvent.h" | 10 #include "third_party/WebKit/public/platform/WebKeyboardEvent.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 StringAppendF(result, | 101 StringAppendF(result, |
| 102 "{\n Touches: %u, DispatchType: %d, CausesScrolling: %d," | 102 "{\n Touches: %u, DispatchType: %d, CausesScrolling: %d," |
| 103 " uniqueTouchEventId: %u\n[\n", | 103 " uniqueTouchEventId: %u\n[\n", |
| 104 event.touchesLength, event.dispatchType, | 104 event.touchesLength, event.dispatchType, |
| 105 event.movedBeyondSlopRegion, event.uniqueTouchEventId); | 105 event.movedBeyondSlopRegion, event.uniqueTouchEventId); |
| 106 for (unsigned i = 0; i < event.touchesLength; ++i) | 106 for (unsigned i = 0; i < event.touchesLength; ++i) |
| 107 ApppendTouchPointDetails(event.touches[i], result); | 107 ApppendTouchPointDetails(event.touches[i], result); |
| 108 result->append(" ]\n}"); | 108 result->append(" ]\n}"); |
| 109 } | 109 } |
| 110 | 110 |
| 111 struct WebInputEventDelete { |
| 112 template <class EventType> |
| 113 bool Execute(WebInputEvent* event, void*) const { |
| 114 if (!event) |
| 115 return false; |
| 116 DCHECK_EQ(sizeof(EventType), event->size()); |
| 117 delete static_cast<EventType*>(event); |
| 118 return true; |
| 119 } |
| 120 }; |
| 121 |
| 111 struct WebInputEventToString { | 122 struct WebInputEventToString { |
| 112 template <class EventType> | 123 template <class EventType> |
| 113 bool Execute(const WebInputEvent& event, std::string* result) const { | 124 bool Execute(const WebInputEvent& event, std::string* result) const { |
| 114 SStringPrintf(result, "%s (Time: %lf, Modifiers: %d)\n", | 125 SStringPrintf(result, "%s (Time: %lf, Modifiers: %d)\n", |
| 115 WebInputEvent::GetName(event.type()), | 126 WebInputEvent::GetName(event.type()), |
| 116 event.timeStampSeconds(), event.modifiers()); | 127 event.timeStampSeconds(), event.modifiers()); |
| 117 const EventType& typed_event = static_cast<const EventType&>(event); | 128 const EventType& typed_event = static_cast<const EventType&>(event); |
| 118 ApppendEventDetails(typed_event, result); | 129 ApppendEventDetails(typed_event, result); |
| 119 return true; | 130 return true; |
| 120 } | 131 } |
| 121 }; | 132 }; |
| 122 | 133 |
| 123 struct WebInputEventSize { | 134 struct WebInputEventSize { |
| 124 template <class EventType> | 135 template <class EventType> |
| 125 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const { | 136 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const { |
| 126 *type_size = sizeof(EventType); | 137 *type_size = sizeof(EventType); |
| 127 return true; | 138 return true; |
| 128 } | 139 } |
| 129 }; | 140 }; |
| 130 | 141 |
| 131 struct WebInputEventClone { | 142 struct WebInputEventClone { |
| 132 template <class EventType> | 143 template <class EventType> |
| 133 bool Execute(const WebInputEvent& event, | 144 bool Execute(const WebInputEvent& event, |
| 134 blink::WebScopedInputEvent* scoped_event) const { | 145 WebScopedInputEvent* scoped_event) const { |
| 135 DCHECK_EQ(sizeof(EventType), event.size()); | 146 DCHECK_EQ(sizeof(EventType), event.size()); |
| 136 *scoped_event = blink::WebScopedInputEvent( | 147 *scoped_event = WebScopedInputEvent( |
| 137 new EventType(static_cast<const EventType&>(event))); | 148 new EventType(static_cast<const EventType&>(event))); |
| 138 return true; | 149 return true; |
| 139 } | 150 } |
| 140 }; | 151 }; |
| 141 | 152 |
| 142 template <typename Operator, typename ArgIn, typename ArgOut> | 153 template <typename Operator, typename ArgIn, typename ArgOut> |
| 143 bool Apply(Operator op, | 154 bool Apply(Operator op, |
| 144 WebInputEvent::Type type, | 155 WebInputEvent::Type type, |
| 145 const ArgIn& arg_in, | 156 const ArgIn& arg_in, |
| 146 ArgOut* arg_out) { | 157 ArgOut* arg_out) { |
| 147 if (WebInputEvent::isMouseEventType(type)) | 158 if (WebInputEvent::isMouseEventType(type)) |
| 148 return op.template Execute<WebMouseEvent>(arg_in, arg_out); | 159 return op.template Execute<WebMouseEvent>(arg_in, arg_out); |
| 149 else if (type == WebInputEvent::MouseWheel) | 160 else if (type == WebInputEvent::MouseWheel) |
| 150 return op.template Execute<WebMouseWheelEvent>(arg_in, arg_out); | 161 return op.template Execute<WebMouseWheelEvent>(arg_in, arg_out); |
| 151 else if (WebInputEvent::isKeyboardEventType(type)) | 162 else if (WebInputEvent::isKeyboardEventType(type)) |
| 152 return op.template Execute<WebKeyboardEvent>(arg_in, arg_out); | 163 return op.template Execute<WebKeyboardEvent>(arg_in, arg_out); |
| 153 else if (WebInputEvent::isTouchEventType(type)) | 164 else if (WebInputEvent::isTouchEventType(type)) |
| 154 return op.template Execute<WebTouchEvent>(arg_in, arg_out); | 165 return op.template Execute<WebTouchEvent>(arg_in, arg_out); |
| 155 else if (WebInputEvent::isGestureEventType(type)) | 166 else if (WebInputEvent::isGestureEventType(type)) |
| 156 return op.template Execute<WebGestureEvent>(arg_in, arg_out); | 167 return op.template Execute<WebGestureEvent>(arg_in, arg_out); |
| 157 | 168 |
| 158 NOTREACHED() << "Unknown webkit event type " << type; | 169 NOTREACHED() << "Unknown webkit event type " << type; |
| 159 return false; | 170 return false; |
| 160 } | 171 } |
| 161 | 172 |
| 162 } // namespace | 173 } // namespace |
| 163 | 174 |
| 175 void WebInputEventDeleter::operator()(WebInputEvent* event) const { |
| 176 if (!event) |
| 177 return; |
| 178 void* temp = nullptr; |
| 179 Apply(WebInputEventDelete(), event->type(), event, temp); |
| 180 } |
| 181 |
| 164 std::string WebInputEventTraits::ToString(const WebInputEvent& event) { | 182 std::string WebInputEventTraits::ToString(const WebInputEvent& event) { |
| 165 std::string result; | 183 std::string result; |
| 166 Apply(WebInputEventToString(), event.type(), event, &result); | 184 Apply(WebInputEventToString(), event.type(), event, &result); |
| 167 return result; | 185 return result; |
| 168 } | 186 } |
| 169 | 187 |
| 170 size_t WebInputEventTraits::GetSize(WebInputEvent::Type type) { | 188 size_t WebInputEventTraits::GetSize(WebInputEvent::Type type) { |
| 171 size_t size = 0; | 189 size_t size = 0; |
| 172 Apply(WebInputEventSize(), type, type, &size); | 190 Apply(WebInputEventSize(), type, type, &size); |
| 173 return size; | 191 return size; |
| 174 } | 192 } |
| 175 | 193 |
| 176 blink::WebScopedInputEvent WebInputEventTraits::Clone( | 194 WebScopedInputEvent WebInputEventTraits::Clone(const WebInputEvent& event) { |
| 177 const WebInputEvent& event) { | 195 WebScopedInputEvent scoped_event; |
| 178 blink::WebScopedInputEvent scoped_event; | |
| 179 Apply(WebInputEventClone(), event.type(), event, &scoped_event); | 196 Apply(WebInputEventClone(), event.type(), event, &scoped_event); |
| 180 return scoped_event; | 197 return scoped_event; |
| 181 } | 198 } |
| 182 | 199 |
| 183 bool WebInputEventTraits::ShouldBlockEventStream(const WebInputEvent& event) { | 200 bool WebInputEventTraits::ShouldBlockEventStream(const WebInputEvent& event) { |
| 184 switch (event.type()) { | 201 switch (event.type()) { |
| 185 case WebInputEvent::MouseDown: | 202 case WebInputEvent::MouseDown: |
| 186 case WebInputEvent::MouseUp: | 203 case WebInputEvent::MouseUp: |
| 187 case WebInputEvent::MouseEnter: | 204 case WebInputEvent::MouseEnter: |
| 188 case WebInputEvent::MouseLeave: | 205 case WebInputEvent::MouseLeave: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 source_event_type = SourceEventType::WHEEL; | 264 source_event_type = SourceEventType::WHEEL; |
| 248 } else if (event.sourceDevice == | 265 } else if (event.sourceDevice == |
| 249 blink::WebGestureDevice::WebGestureDeviceTouchscreen) { | 266 blink::WebGestureDevice::WebGestureDeviceTouchscreen) { |
| 250 source_event_type = SourceEventType::TOUCH; | 267 source_event_type = SourceEventType::TOUCH; |
| 251 } | 268 } |
| 252 LatencyInfo latency_info(source_event_type); | 269 LatencyInfo latency_info(source_event_type); |
| 253 return latency_info; | 270 return latency_info; |
| 254 } | 271 } |
| 255 | 272 |
| 256 } // namespace ui | 273 } // namespace ui |
| OLD | NEW |