| 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/motion_event_web.h" | 5 #include "content/browser/renderer_host/input/motion_event_web.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/input/web_touch_event_traits.h" |
| 8 | 9 |
| 9 using blink::WebInputEvent; | 10 using blink::WebInputEvent; |
| 10 using blink::WebTouchEvent; | 11 using blink::WebTouchEvent; |
| 11 using blink::WebTouchPoint; | 12 using blink::WebTouchPoint; |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 bool AllTouchPointsHaveState(const WebTouchEvent& event, | |
| 17 WebTouchPoint::State state) { | |
| 18 for (size_t i = 0; i < event.touchesLength; ++i) { | |
| 19 if (event.touches[i].state != state) | |
| 20 return false; | |
| 21 } | |
| 22 return true; | |
| 23 } | |
| 24 | |
| 25 ui::MotionEvent::Action GetActionFrom(const WebTouchEvent& event) { | 17 ui::MotionEvent::Action GetActionFrom(const WebTouchEvent& event) { |
| 26 // TODO(jdduke): Use WebTouchEventTraits. | |
| 27 DCHECK(event.touchesLength); | 18 DCHECK(event.touchesLength); |
| 28 switch (event.type) { | 19 switch (event.type) { |
| 29 case WebInputEvent::TouchStart: | 20 case WebInputEvent::TouchStart: |
| 30 if (AllTouchPointsHaveState(event, WebTouchPoint::StatePressed)) | 21 if (WebTouchEventTraits::AllTouchPointsHaveState( |
| 22 event, WebTouchPoint::StatePressed)) |
| 31 return ui::MotionEvent::ACTION_DOWN; | 23 return ui::MotionEvent::ACTION_DOWN; |
| 32 else | 24 else |
| 33 return ui::MotionEvent::ACTION_POINTER_DOWN; | 25 return ui::MotionEvent::ACTION_POINTER_DOWN; |
| 34 case WebInputEvent::TouchEnd: | 26 case WebInputEvent::TouchEnd: |
| 35 if (AllTouchPointsHaveState(event, WebTouchPoint::StateReleased)) | 27 if (WebTouchEventTraits::AllTouchPointsHaveState( |
| 28 event, WebTouchPoint::StateReleased)) |
| 36 return ui::MotionEvent::ACTION_UP; | 29 return ui::MotionEvent::ACTION_UP; |
| 37 else | 30 else |
| 38 return ui::MotionEvent::ACTION_POINTER_UP; | 31 return ui::MotionEvent::ACTION_POINTER_UP; |
| 39 case WebInputEvent::TouchCancel: | 32 case WebInputEvent::TouchCancel: |
| 40 DCHECK(AllTouchPointsHaveState(event, WebTouchPoint::StateCancelled)); | 33 DCHECK(WebTouchEventTraits::AllTouchPointsHaveState( |
| 34 event, WebTouchPoint::StateCancelled)); |
| 41 return ui::MotionEvent::ACTION_CANCEL; | 35 return ui::MotionEvent::ACTION_CANCEL; |
| 42 case WebInputEvent::TouchMove: | 36 case WebInputEvent::TouchMove: |
| 43 return ui::MotionEvent::ACTION_MOVE; | 37 return ui::MotionEvent::ACTION_MOVE; |
| 44 default: | 38 default: |
| 45 break; | 39 break; |
| 46 }; | 40 }; |
| 47 NOTREACHED() | 41 NOTREACHED() |
| 48 << "Unable to derive a valid MotionEvent::Action from the WebTouchEvent."; | 42 << "Unable to derive a valid MotionEvent::Action from the WebTouchEvent."; |
| 49 return ui::MotionEvent::ACTION_CANCEL; | 43 return ui::MotionEvent::ACTION_CANCEL; |
| 50 } | 44 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 NOTIMPLEMENTED(); | 132 NOTIMPLEMENTED(); |
| 139 return 0.f; | 133 return 0.f; |
| 140 } | 134 } |
| 141 | 135 |
| 142 scoped_ptr<ui::MotionEvent> MotionEventWeb::Clone() const { | 136 scoped_ptr<ui::MotionEvent> MotionEventWeb::Clone() const { |
| 143 return scoped_ptr<MotionEvent>(new MotionEventWeb(event_)); | 137 return scoped_ptr<MotionEvent>(new MotionEventWeb(event_)); |
| 144 } | 138 } |
| 145 | 139 |
| 146 scoped_ptr<ui::MotionEvent> MotionEventWeb::Cancel() const { | 140 scoped_ptr<ui::MotionEvent> MotionEventWeb::Cancel() const { |
| 147 WebTouchEvent cancel_event(event_); | 141 WebTouchEvent cancel_event(event_); |
| 148 | 142 WebTouchEventTraits::ResetTypeAndTouchStates( |
| 149 cancel_event.type = WebInputEvent::TouchCancel; | 143 blink::WebInputEvent::TouchCancel, |
| 150 for (size_t i = 0; i < cancel_event.touchesLength; ++i) | 144 // TODO(rbyers): Shouldn't we use a fresh timestamp? |
| 151 cancel_event.touches[i].state = WebTouchPoint::StateCancelled; | 145 event_.timeStampSeconds, |
| 152 | 146 &cancel_event); |
| 153 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event)); | 147 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event)); |
| 154 } | 148 } |
| 155 | 149 |
| 156 } // namespace content | 150 } // namespace content |
| OLD | NEW |