OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/input/web_input_event_traits.h" | 5 #include "content/common/input/web_input_event_traits.h" |
6 | 6 |
7 #include <bitset> | 7 #include <bitset> |
| 8 #include <limits> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 | 11 |
11 using blink::WebGestureEvent; | 12 using blink::WebGestureEvent; |
12 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
13 using blink::WebKeyboardEvent; | 14 using blink::WebKeyboardEvent; |
14 using blink::WebMouseEvent; | 15 using blink::WebMouseEvent; |
15 using blink::WebMouseWheelEvent; | 16 using blink::WebMouseWheelEvent; |
16 using blink::WebTouchEvent; | 17 using blink::WebTouchEvent; |
| 18 using std::numeric_limits; |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 namespace { | 21 namespace { |
20 | 22 |
21 const int kInvalidTouchIndex = -1; | 23 const int kInvalidTouchIndex = -1; |
22 | 24 |
23 bool CanCoalesce(const WebKeyboardEvent& event_to_coalesce, | 25 bool CanCoalesce(const WebKeyboardEvent& event_to_coalesce, |
24 const WebKeyboardEvent& event) { | 26 const WebKeyboardEvent& event) { |
25 return false; | 27 return false; |
26 } | 28 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 void Coalesce(const WebGestureEvent& event_to_coalesce, | 168 void Coalesce(const WebGestureEvent& event_to_coalesce, |
167 WebGestureEvent* event) { | 169 WebGestureEvent* event) { |
168 DCHECK(CanCoalesce(event_to_coalesce, *event)); | 170 DCHECK(CanCoalesce(event_to_coalesce, *event)); |
169 if (event->type == WebInputEvent::GestureScrollUpdate) { | 171 if (event->type == WebInputEvent::GestureScrollUpdate) { |
170 event->data.scrollUpdate.deltaX += | 172 event->data.scrollUpdate.deltaX += |
171 event_to_coalesce.data.scrollUpdate.deltaX; | 173 event_to_coalesce.data.scrollUpdate.deltaX; |
172 event->data.scrollUpdate.deltaY += | 174 event->data.scrollUpdate.deltaY += |
173 event_to_coalesce.data.scrollUpdate.deltaY; | 175 event_to_coalesce.data.scrollUpdate.deltaY; |
174 } else if (event->type == WebInputEvent::GesturePinchUpdate) { | 176 } else if (event->type == WebInputEvent::GesturePinchUpdate) { |
175 event->data.pinchUpdate.scale *= event_to_coalesce.data.pinchUpdate.scale; | 177 event->data.pinchUpdate.scale *= event_to_coalesce.data.pinchUpdate.scale; |
| 178 // Ensure the scale remains bounded above 0 and below Infinity so that |
| 179 // we can reliably perform operations like log on the values. |
| 180 if (event->data.pinchUpdate.scale < numeric_limits<float>::min()) |
| 181 event->data.pinchUpdate.scale = numeric_limits<float>::min(); |
| 182 else if (event->data.pinchUpdate.scale > numeric_limits<float>::max()) |
| 183 event->data.pinchUpdate.scale = numeric_limits<float>::max(); |
176 } | 184 } |
177 } | 185 } |
178 | 186 |
179 struct WebInputEventSize { | 187 struct WebInputEventSize { |
180 template <class EventType> | 188 template <class EventType> |
181 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const { | 189 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const { |
182 *type_size = sizeof(EventType); | 190 *type_size = sizeof(EventType); |
183 return true; | 191 return true; |
184 } | 192 } |
185 }; | 193 }; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 case WebInputEvent::TouchStart: | 362 case WebInputEvent::TouchStart: |
355 case WebInputEvent::TouchMove: | 363 case WebInputEvent::TouchMove: |
356 case WebInputEvent::TouchEnd: | 364 case WebInputEvent::TouchEnd: |
357 return !static_cast<const WebTouchEvent&>(event).cancelable; | 365 return !static_cast<const WebTouchEvent&>(event).cancelable; |
358 default: | 366 default: |
359 return false; | 367 return false; |
360 } | 368 } |
361 } | 369 } |
362 | 370 |
363 } // namespace content | 371 } // namespace content |
OLD | NEW |