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

Side by Side Diff: content/common/input/web_touch_event_traits.cc

Issue 1560553002: Framelet Prototype 2016 Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased + Applied Brett's Windows + Fixed security issue Created 4 years, 11 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
« no previous file with comments | « content/common/input/web_touch_event_traits.h ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/common/input/web_touch_event_traits.h"
6
7 #include <stddef.h>
8
9 #include "base/logging.h"
10
11 using blink::WebInputEvent;
12 using blink::WebTouchEvent;
13 using blink::WebTouchPoint;
14
15 namespace content {
16
17 bool WebTouchEventTraits::AllTouchPointsHaveState(
18 const WebTouchEvent& event,
19 blink::WebTouchPoint::State state) {
20 if (!event.touchesLength)
21 return false;
22 for (size_t i = 0; i < event.touchesLength; ++i) {
23 if (event.touches[i].state != state)
24 return false;
25 }
26 return true;
27 }
28
29 bool WebTouchEventTraits::IsTouchSequenceStart(const WebTouchEvent& event) {
30 DCHECK(event.touchesLength);
31 if (event.type != WebInputEvent::TouchStart)
32 return false;
33 return AllTouchPointsHaveState(event, blink::WebTouchPoint::StatePressed);
34 }
35
36 bool WebTouchEventTraits::IsTouchSequenceEnd(const WebTouchEvent& event) {
37 if (event.type != WebInputEvent::TouchEnd &&
38 event.type != WebInputEvent::TouchCancel)
39 return false;
40 if (!event.touchesLength)
41 return true;
42 for (size_t i = 0; i < event.touchesLength; ++i) {
43 if (event.touches[i].state != blink::WebTouchPoint::StateReleased &&
44 event.touches[i].state != blink::WebTouchPoint::StateCancelled)
45 return false;
46 }
47 return true;
48 }
49
50 void WebTouchEventTraits::ResetType(WebInputEvent::Type type,
51 double timestamp_sec,
52 WebTouchEvent* event) {
53 DCHECK(WebInputEvent::isTouchEventType(type));
54 event->type = type;
55 event->cancelable = (type != WebInputEvent::TouchCancel);
56 event->timeStampSeconds = timestamp_sec;
57 }
58
59 void WebTouchEventTraits::ResetTypeAndTouchStates(WebInputEvent::Type type,
60 double timestamp_sec,
61 WebTouchEvent* event) {
62 ResetType(type, timestamp_sec, event);
63
64 WebTouchPoint::State newState = WebTouchPoint::StateUndefined;
65 switch (event->type) {
66 case WebInputEvent::TouchStart:
67 newState = WebTouchPoint::StatePressed;
68 break;
69 case WebInputEvent::TouchMove:
70 newState = WebTouchPoint::StateMoved;
71 break;
72 case WebInputEvent::TouchEnd:
73 newState = WebTouchPoint::StateReleased;
74 break;
75 case WebInputEvent::TouchCancel:
76 newState = WebTouchPoint::StateCancelled;
77 break;
78 default:
79 NOTREACHED();
80 break;
81 }
82 for (size_t i = 0; i < event->touchesLength; ++i)
83 event->touches[i].state = newState;
84 }
85
86 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/web_touch_event_traits.h ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698