Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/renderer_host/input/gesture_event_packet.h" | 5 #include "content/browser/renderer_host/input/gesture_event_packet.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/events/gesture_detection/motion_event.h" | |
| 8 | 9 |
| 9 using blink::WebGestureEvent; | 10 using blink::WebGestureEvent; |
| 10 using blink::WebInputEvent; | 11 using blink::WebInputEvent; |
| 11 using blink::WebTouchEvent; | 12 using blink::WebTouchEvent; |
| 12 using blink::WebTouchPoint; | 13 using blink::WebTouchPoint; |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 GestureEventPacket::GestureSource ToGestureSource(const WebTouchEvent& event) { | 18 GestureEventPacket::GestureSource |
| 18 if (!event.touchesLength) | 19 ToGestureSource(const ui::MotionEvent& event) { |
|
tdresser
2014/02/27 15:28:30
Nice cleanup here.
jdduke (slow)
2014/02/27 17:40:29
:)
| |
| 19 return GestureEventPacket::INVALID; | 20 switch (event.GetAction()) { |
| 20 switch (event.type) { | 21 case ui::MotionEvent::ACTION_DOWN: |
| 21 case WebInputEvent::TouchStart: | |
| 22 for (size_t i = 0; i < event.touchesLength; i++) { | |
| 23 if (event.touches[i].state != WebTouchPoint::StatePressed) | |
| 24 return GestureEventPacket::TOUCH_BEGIN; | |
| 25 } | |
| 26 return GestureEventPacket::TOUCH_SEQUENCE_BEGIN; | 22 return GestureEventPacket::TOUCH_SEQUENCE_BEGIN; |
| 27 case WebInputEvent::TouchMove: | 23 case ui::MotionEvent::ACTION_UP: |
| 24 return GestureEventPacket::TOUCH_SEQUENCE_END; | |
| 25 case ui::MotionEvent::ACTION_MOVE: | |
| 28 return GestureEventPacket::TOUCH_MOVE; | 26 return GestureEventPacket::TOUCH_MOVE; |
| 29 case WebInputEvent::TouchEnd: | 27 case ui::MotionEvent::ACTION_CANCEL: |
| 30 case WebInputEvent::TouchCancel: | |
| 31 for (size_t i = 0; i < event.touchesLength; i++) { | |
| 32 if (event.touches[i].state != WebTouchPoint::StateReleased && | |
| 33 event.touches[i].state != WebTouchPoint::StateCancelled) { | |
| 34 return GestureEventPacket::TOUCH_END; | |
| 35 } | |
| 36 } | |
| 37 return GestureEventPacket::TOUCH_SEQUENCE_END; | 28 return GestureEventPacket::TOUCH_SEQUENCE_END; |
| 38 default: | 29 case ui::MotionEvent::ACTION_POINTER_DOWN: |
| 39 return GestureEventPacket::INVALID; | 30 return GestureEventPacket::TOUCH_BEGIN; |
| 40 } | 31 case ui::MotionEvent::ACTION_POINTER_UP: |
| 32 return GestureEventPacket::TOUCH_END; | |
| 33 }; | |
| 34 NOTREACHED() << "Invalid ui::MotionEvent action: " << event.GetAction(); | |
| 35 return GestureEventPacket::INVALID; | |
| 41 } | 36 } |
| 42 | 37 |
| 43 } // namespace | 38 } // namespace |
| 44 | 39 |
| 45 GestureEventPacket::GestureEventPacket() | 40 GestureEventPacket::GestureEventPacket() |
| 46 : gesture_count_(0), | 41 : gesture_count_(0), |
| 47 gesture_source_(UNDEFINED) {} | 42 gesture_source_(UNDEFINED) {} |
| 48 | 43 |
| 49 GestureEventPacket::GestureEventPacket(GestureSource source) | 44 GestureEventPacket::GestureEventPacket(GestureSource source) |
| 50 : gesture_count_(0), | 45 : gesture_count_(0), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 67 std::copy(other.gestures_, other.gestures_ + other.gesture_count_, gestures_); | 62 std::copy(other.gestures_, other.gestures_ + other.gesture_count_, gestures_); |
| 68 return *this; | 63 return *this; |
| 69 } | 64 } |
| 70 | 65 |
| 71 void GestureEventPacket::Push(const blink::WebGestureEvent& gesture) { | 66 void GestureEventPacket::Push(const blink::WebGestureEvent& gesture) { |
| 72 DCHECK(WebInputEvent::isGestureEventType(gesture.type)); | 67 DCHECK(WebInputEvent::isGestureEventType(gesture.type)); |
| 73 CHECK_LT(gesture_count_, static_cast<size_t>(kMaxGesturesPerTouch)); | 68 CHECK_LT(gesture_count_, static_cast<size_t>(kMaxGesturesPerTouch)); |
| 74 gestures_[gesture_count_++] = gesture; | 69 gestures_[gesture_count_++] = gesture; |
| 75 } | 70 } |
| 76 | 71 |
| 77 GestureEventPacket GestureEventPacket::FromTouch(const WebTouchEvent& event) { | 72 GestureEventPacket GestureEventPacket::FromTouch(const ui::MotionEvent& event) { |
| 78 return GestureEventPacket(ToGestureSource(event)); | 73 return GestureEventPacket(ToGestureSource(event)); |
| 79 } | 74 } |
| 80 | 75 |
| 81 GestureEventPacket GestureEventPacket::FromTouchTimeout( | 76 GestureEventPacket GestureEventPacket::FromTouchTimeout( |
| 82 const WebGestureEvent& event) { | 77 const WebGestureEvent& event) { |
| 83 GestureEventPacket packet(TOUCH_TIMEOUT); | 78 GestureEventPacket packet(TOUCH_TIMEOUT); |
| 84 packet.Push(event); | 79 packet.Push(event); |
| 85 return packet; | 80 return packet; |
| 86 } | 81 } |
| 87 | 82 |
| 88 } // namespace content | 83 } // namespace content |
| OLD | NEW |