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

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

Issue 494833003: Completed webkit radiusX, radiusY and rotationAngle handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES
7
5 #include "content/browser/renderer_host/input/motion_event_web.h" 8 #include "content/browser/renderer_host/input/motion_event_web.h"
6 9
10 #include <cmath>
11
7 #include "base/logging.h" 12 #include "base/logging.h"
8 #include "content/common/input/web_touch_event_traits.h" 13 #include "content/common/input/web_touch_event_traits.h"
9 14
10 using blink::WebInputEvent; 15 using blink::WebInputEvent;
11 using blink::WebTouchEvent; 16 using blink::WebTouchEvent;
12 using blink::WebTouchPoint; 17 using blink::WebTouchPoint;
13 18
14 namespace content { 19 namespace content {
15 namespace { 20 namespace {
16 21
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return event_.touches[pointer_index].screenPosition.x; 100 return event_.touches[pointer_index].screenPosition.x;
96 } 101 }
97 102
98 float MotionEventWeb::GetRawY(size_t pointer_index) const { 103 float MotionEventWeb::GetRawY(size_t pointer_index) const {
99 DCHECK_LT(pointer_index, GetPointerCount()); 104 DCHECK_LT(pointer_index, GetPointerCount());
100 return event_.touches[pointer_index].screenPosition.y; 105 return event_.touches[pointer_index].screenPosition.y;
101 } 106 }
102 107
103 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const { 108 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const {
104 DCHECK_LT(pointer_index, GetPointerCount()); 109 DCHECK_LT(pointer_index, GetPointerCount());
105 // TODO(jdduke): We should be a bit more careful about axes here.
106 return 2.f * std::max(event_.touches[pointer_index].radiusX, 110 return 2.f * std::max(event_.touches[pointer_index].radiusX,
107 event_.touches[pointer_index].radiusY); 111 event_.touches[pointer_index].radiusY);
108 } 112 }
109 113
114 float MotionEventWeb::GetTouchMinor(size_t pointer_index) const {
115 DCHECK_LT(pointer_index, GetPointerCount());
116 return 2.f * std::min(event_.touches[pointer_index].radiusX,
117 event_.touches[pointer_index].radiusY);
118 }
119
120 float MotionEventWeb::GetOrientation(size_t pointer_index) const {
121 DCHECK_LT(pointer_index, GetPointerCount());
122
123 float rotation_angle_rad = event_.touches[pointer_index].rotationAngle
124 * M_PI / 180.f;
125 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2)
126 << "Unexpected touch rotation angle";
127
128 if (event_.touches[pointer_index].radiusX
129 > event_.touches[pointer_index].radiusY) {
130 // The case radiusX == radiusY is omitted from here on purpose: for circles,
131 // we want to pass the angle (which could be any value in such cases but
132 // always seem to be set to zero) unchanged.
133 rotation_angle_rad -= (float) M_PI_2;
134 }
135
136 return rotation_angle_rad;
137 }
138
110 float MotionEventWeb::GetPressure(size_t pointer_index) const { 139 float MotionEventWeb::GetPressure(size_t pointer_index) const {
111 return 0.f; 140 return 0.f;
112 } 141 }
113 142
114 base::TimeTicks MotionEventWeb::GetEventTime() const { 143 base::TimeTicks MotionEventWeb::GetEventTime() const {
115 return base::TimeTicks() + 144 return base::TimeTicks() +
116 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds * 145 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *
117 base::Time::kMicrosecondsPerSecond); 146 base::Time::kMicrosecondsPerSecond);
118 } 147 }
119 148
(...skipping 17 matching lines...) Expand all
137 WebTouchEvent cancel_event(event_); 166 WebTouchEvent cancel_event(event_);
138 WebTouchEventTraits::ResetTypeAndTouchStates( 167 WebTouchEventTraits::ResetTypeAndTouchStates(
139 blink::WebInputEvent::TouchCancel, 168 blink::WebInputEvent::TouchCancel,
140 // TODO(rbyers): Shouldn't we use a fresh timestamp? 169 // TODO(rbyers): Shouldn't we use a fresh timestamp?
141 event_.timeStampSeconds, 170 event_.timeStampSeconds,
142 &cancel_event); 171 &cancel_event);
143 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event)); 172 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event));
144 } 173 }
145 174
146 } // namespace content 175 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/motion_event_web.h ('k') | content/browser/renderer_host/input/web_input_event_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698