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 // MSVC++ requires this to be set before any other includes to get M_PI. | |
| 6 #define _USE_MATH_DEFINES | |
|
tdresser
2014/08/28 12:35:19
#include <cmath>
mustaq
2014/08/28 14:08:37
Done.
| |
| 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 |
| 7 #include "base/logging.h" | 10 #include "base/logging.h" |
| 8 #include "content/common/input/web_touch_event_traits.h" | 11 #include "content/common/input/web_touch_event_traits.h" |
| 9 | 12 |
| 10 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
| 11 using blink::WebTouchEvent; | 14 using blink::WebTouchEvent; |
| 12 using blink::WebTouchPoint; | 15 using blink::WebTouchPoint; |
| 13 | 16 |
| 14 namespace content { | 17 namespace content { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 return event_.touches[pointer_index].screenPosition.x; | 98 return event_.touches[pointer_index].screenPosition.x; |
| 96 } | 99 } |
| 97 | 100 |
| 98 float MotionEventWeb::GetRawY(size_t pointer_index) const { | 101 float MotionEventWeb::GetRawY(size_t pointer_index) const { |
| 99 DCHECK_LT(pointer_index, GetPointerCount()); | 102 DCHECK_LT(pointer_index, GetPointerCount()); |
| 100 return event_.touches[pointer_index].screenPosition.y; | 103 return event_.touches[pointer_index].screenPosition.y; |
| 101 } | 104 } |
| 102 | 105 |
| 103 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const { | 106 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const { |
| 104 DCHECK_LT(pointer_index, GetPointerCount()); | 107 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, | 108 return 2.f * std::max(event_.touches[pointer_index].radiusX, |
| 107 event_.touches[pointer_index].radiusY); | 109 event_.touches[pointer_index].radiusY); |
| 108 } | 110 } |
| 109 | 111 |
| 112 float MotionEventWeb::GetTouchMinor(size_t pointer_index) const { | |
| 113 DCHECK_LT(pointer_index, GetPointerCount()); | |
| 114 return 2.f * std::min(event_.touches[pointer_index].radiusX, | |
| 115 event_.touches[pointer_index].radiusY); | |
| 116 } | |
| 117 | |
| 118 float MotionEventWeb::GetOrientation(size_t pointer_index) const { | |
| 119 DCHECK_LT(pointer_index, GetPointerCount()); | |
| 120 | |
| 121 float rotation_angle_rad = event_.touches[pointer_index].rotationAngle | |
| 122 * M_PI / 180.f; | |
| 123 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) | |
| 124 << "Unexpected touch rotation angle"; | |
| 125 | |
| 126 if (event_.touches[pointer_index].radiusX | |
| 127 < event_.touches[pointer_index].radiusY) { | |
| 128 rotation_angle_rad -= (float) M_PI_2; | |
| 129 } | |
| 130 | |
| 131 return rotation_angle_rad; | |
| 132 } | |
| 133 | |
| 110 float MotionEventWeb::GetPressure(size_t pointer_index) const { | 134 float MotionEventWeb::GetPressure(size_t pointer_index) const { |
| 111 return 0.f; | 135 return 0.f; |
| 112 } | 136 } |
| 113 | 137 |
| 114 base::TimeTicks MotionEventWeb::GetEventTime() const { | 138 base::TimeTicks MotionEventWeb::GetEventTime() const { |
| 115 return base::TimeTicks() + | 139 return base::TimeTicks() + |
| 116 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds * | 140 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds * |
| 117 base::Time::kMicrosecondsPerSecond); | 141 base::Time::kMicrosecondsPerSecond); |
| 118 } | 142 } |
| 119 | 143 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 137 WebTouchEvent cancel_event(event_); | 161 WebTouchEvent cancel_event(event_); |
| 138 WebTouchEventTraits::ResetTypeAndTouchStates( | 162 WebTouchEventTraits::ResetTypeAndTouchStates( |
| 139 blink::WebInputEvent::TouchCancel, | 163 blink::WebInputEvent::TouchCancel, |
| 140 // TODO(rbyers): Shouldn't we use a fresh timestamp? | 164 // TODO(rbyers): Shouldn't we use a fresh timestamp? |
| 141 event_.timeStampSeconds, | 165 event_.timeStampSeconds, |
| 142 &cancel_event); | 166 &cancel_event); |
| 143 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event)); | 167 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event)); |
| 144 } | 168 } |
| 145 | 169 |
| 146 } // namespace content | 170 } // namespace content |
| OLD | NEW |