Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: content/browser/renderer_host/input/motion_event_web.cc

Issue 247433003: Mark touchcancel events as uncancelable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up and add tests Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:
jdduke (slow) 2014/04/23 21:55:47 Is this "git cl format" ed?
30 if (AllTouchPointsHaveState(event, WebTouchPoint::StatePressed)) 21 if (WebTouchEventTraits::AllTouchPointsHaveState(event,
22 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(event,
28 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(event,
34 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
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::ResetType(&cancel_event,
149 cancel_event.type = WebInputEvent::TouchCancel; 143 blink::WebInputEvent::TouchCancel,
150 for (size_t i = 0; i < cancel_event.touchesLength; ++i) 144 // FIXME: Shouldn't we use a fresh timestamp?
jdduke (slow) 2014/04/23 21:55:47 Hmm... yeah, probably.
Rick Byers 2014/04/23 23:15:35 This is simple enough that I can just fix it here
151 cancel_event.touches[i].state = WebTouchPoint::StateCancelled; 145 event_.timeStampSeconds,
152 146 WebTouchEventTraits::RESET_TOUCHES_STATE);
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698