| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 event.movedBeyondSlopRegion, event.uniqueTouchEventId); | 103 event.movedBeyondSlopRegion, event.uniqueTouchEventId); |
| 104 for (unsigned i = 0; i < event.touchesLength; ++i) | 104 for (unsigned i = 0; i < event.touchesLength; ++i) |
| 105 ApppendTouchPointDetails(event.touches[i], result); | 105 ApppendTouchPointDetails(event.touches[i], result); |
| 106 result->append(" ]\n}"); | 106 result->append(" ]\n}"); |
| 107 } | 107 } |
| 108 | 108 |
| 109 struct WebInputEventToString { | 109 struct WebInputEventToString { |
| 110 template <class EventType> | 110 template <class EventType> |
| 111 bool Execute(const WebInputEvent& event, std::string* result) const { | 111 bool Execute(const WebInputEvent& event, std::string* result) const { |
| 112 SStringPrintf(result, "%s (Time: %lf, Modifiers: %d)\n", | 112 SStringPrintf(result, "%s (Time: %lf, Modifiers: %d)\n", |
| 113 WebInputEvent::GetName(event.type), event.timeStampSeconds, | 113 WebInputEvent::GetName(event.type()), |
| 114 event.modifiers); | 114 event.timeStampSeconds(), event.modifiers()); |
| 115 const EventType& typed_event = static_cast<const EventType&>(event); | 115 const EventType& typed_event = static_cast<const EventType&>(event); |
| 116 ApppendEventDetails(typed_event, result); | 116 ApppendEventDetails(typed_event, result); |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 struct WebInputEventSize { | 121 struct WebInputEventSize { |
| 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 blink::WebScopedInputEvent* 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 = blink::WebScopedInputEvent( | 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 template <typename Operator, typename ArgIn, typename ArgOut> | 140 template <typename Operator, typename ArgIn, typename ArgOut> |
| 141 bool Apply(Operator op, | 141 bool Apply(Operator op, |
| 142 WebInputEvent::Type type, | 142 WebInputEvent::Type type, |
| 143 const ArgIn& arg_in, | 143 const ArgIn& arg_in, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 154 return op.template Execute<WebGestureEvent>(arg_in, arg_out); | 154 return op.template Execute<WebGestureEvent>(arg_in, arg_out); |
| 155 | 155 |
| 156 NOTREACHED() << "Unknown webkit event type " << type; | 156 NOTREACHED() << "Unknown webkit event type " << type; |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace | 160 } // namespace |
| 161 | 161 |
| 162 std::string WebInputEventTraits::ToString(const WebInputEvent& event) { | 162 std::string WebInputEventTraits::ToString(const WebInputEvent& event) { |
| 163 std::string result; | 163 std::string result; |
| 164 Apply(WebInputEventToString(), event.type, event, &result); | 164 Apply(WebInputEventToString(), event.type(), event, &result); |
| 165 return result; | 165 return result; |
| 166 } | 166 } |
| 167 | 167 |
| 168 size_t WebInputEventTraits::GetSize(WebInputEvent::Type type) { | 168 size_t WebInputEventTraits::GetSize(WebInputEvent::Type type) { |
| 169 size_t size = 0; | 169 size_t size = 0; |
| 170 Apply(WebInputEventSize(), type, type, &size); | 170 Apply(WebInputEventSize(), type, type, &size); |
| 171 return size; | 171 return size; |
| 172 } | 172 } |
| 173 | 173 |
| 174 blink::WebScopedInputEvent WebInputEventTraits::Clone( | 174 blink::WebScopedInputEvent WebInputEventTraits::Clone( |
| 175 const WebInputEvent& event) { | 175 const WebInputEvent& event) { |
| 176 blink::WebScopedInputEvent scoped_event; | 176 blink::WebScopedInputEvent scoped_event; |
| 177 Apply(WebInputEventClone(), event.type, event, &scoped_event); | 177 Apply(WebInputEventClone(), event.type(), event, &scoped_event); |
| 178 return scoped_event; | 178 return scoped_event; |
| 179 } | 179 } |
| 180 | 180 |
| 181 bool WebInputEventTraits::ShouldBlockEventStream(const WebInputEvent& event) { | 181 bool WebInputEventTraits::ShouldBlockEventStream(const WebInputEvent& event) { |
| 182 switch (event.type) { | 182 switch (event.type()) { |
| 183 case WebInputEvent::MouseDown: | 183 case WebInputEvent::MouseDown: |
| 184 case WebInputEvent::MouseUp: | 184 case WebInputEvent::MouseUp: |
| 185 case WebInputEvent::MouseEnter: | 185 case WebInputEvent::MouseEnter: |
| 186 case WebInputEvent::MouseLeave: | 186 case WebInputEvent::MouseLeave: |
| 187 case WebInputEvent::ContextMenu: | 187 case WebInputEvent::ContextMenu: |
| 188 case WebInputEvent::GestureScrollBegin: | 188 case WebInputEvent::GestureScrollBegin: |
| 189 case WebInputEvent::GestureScrollEnd: | 189 case WebInputEvent::GestureScrollEnd: |
| 190 case WebInputEvent::GestureShowPress: | 190 case WebInputEvent::GestureShowPress: |
| 191 case WebInputEvent::GestureTapUnconfirmed: | 191 case WebInputEvent::GestureTapUnconfirmed: |
| 192 case WebInputEvent::GestureTapDown: | 192 case WebInputEvent::GestureTapDown: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 216 return true; | 216 return true; |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool WebInputEventTraits::CanCauseScroll( | 220 bool WebInputEventTraits::CanCauseScroll( |
| 221 const blink::WebMouseWheelEvent& event) { | 221 const blink::WebMouseWheelEvent& event) { |
| 222 #if defined(USE_AURA) | 222 #if defined(USE_AURA) |
| 223 // Scroll events generated from the mouse wheel when the control key is held | 223 // Scroll events generated from the mouse wheel when the control key is held |
| 224 // don't trigger scrolling. Instead, they may cause zooming. | 224 // don't trigger scrolling. Instead, they may cause zooming. |
| 225 return event.hasPreciseScrollingDeltas || | 225 return event.hasPreciseScrollingDeltas || |
| 226 (event.modifiers & blink::WebInputEvent::ControlKey) == 0; | 226 (event.modifiers() & blink::WebInputEvent::ControlKey) == 0; |
| 227 #else | 227 #else |
| 228 return true; | 228 return true; |
| 229 #endif | 229 #endif |
| 230 } | 230 } |
| 231 | 231 |
| 232 uint32_t WebInputEventTraits::GetUniqueTouchEventId( | 232 uint32_t WebInputEventTraits::GetUniqueTouchEventId( |
| 233 const WebInputEvent& event) { | 233 const WebInputEvent& event) { |
| 234 if (WebInputEvent::isTouchEventType(event.type)) { | 234 if (WebInputEvent::isTouchEventType(event.type())) { |
| 235 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId; | 235 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId; |
| 236 } | 236 } |
| 237 return 0U; | 237 return 0U; |
| 238 } | 238 } |
| 239 | 239 |
| 240 // static | 240 // static |
| 241 LatencyInfo WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( | 241 LatencyInfo WebInputEventTraits::CreateLatencyInfoForWebGestureEvent( |
| 242 const WebGestureEvent& event) { | 242 const WebGestureEvent& event) { |
| 243 SourceEventType source_event_type = SourceEventType::UNKNOWN; | 243 SourceEventType source_event_type = SourceEventType::UNKNOWN; |
| 244 if (event.sourceDevice == blink::WebGestureDevice::WebGestureDeviceTouchpad) { | 244 if (event.sourceDevice == blink::WebGestureDevice::WebGestureDeviceTouchpad) { |
| 245 source_event_type = SourceEventType::WHEEL; | 245 source_event_type = SourceEventType::WHEEL; |
| 246 } else if (event.sourceDevice == | 246 } else if (event.sourceDevice == |
| 247 blink::WebGestureDevice::WebGestureDeviceTouchscreen) { | 247 blink::WebGestureDevice::WebGestureDeviceTouchscreen) { |
| 248 source_event_type = SourceEventType::TOUCH; | 248 source_event_type = SourceEventType::TOUCH; |
| 249 } | 249 } |
| 250 LatencyInfo latency_info(source_event_type); | 250 LatencyInfo latency_info(source_event_type); |
| 251 return latency_info; | 251 return latency_info; |
| 252 } | 252 } |
| 253 | 253 |
| 254 } // namespace ui | 254 } // namespace ui |
| OLD | NEW |