| 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. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "content/browser/renderer_host/input/motion_event_web.h" | 8 #include "content/browser/renderer_host/input/motion_event_web.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 << "Invalid action for GetActionIndex(): " << cached_action_; | 84 << "Invalid action for GetActionIndex(): " << cached_action_; |
| 85 DCHECK_GE(cached_action_index_, 0); | 85 DCHECK_GE(cached_action_index_, 0); |
| 86 DCHECK_LT(cached_action_index_, static_cast<int>(event_.touchesLength)); | 86 DCHECK_LT(cached_action_index_, static_cast<int>(event_.touchesLength)); |
| 87 return cached_action_index_; | 87 return cached_action_index_; |
| 88 } | 88 } |
| 89 | 89 |
| 90 size_t MotionEventWeb::GetPointerCount() const { return event_.touchesLength; } | 90 size_t MotionEventWeb::GetPointerCount() const { return event_.touchesLength; } |
| 91 | 91 |
| 92 int MotionEventWeb::GetPointerId(size_t pointer_index) const { | 92 int MotionEventWeb::GetPointerId(size_t pointer_index) const { |
| 93 DCHECK_LT(pointer_index, GetPointerCount()); | 93 DCHECK_LT(pointer_index, GetPointerCount()); |
| 94 return event_.touches[pointer_index].id; | 94 return event_.touches[pointer_index].pointerId; |
| 95 } | 95 } |
| 96 | 96 |
| 97 float MotionEventWeb::GetX(size_t pointer_index) const { | 97 float MotionEventWeb::GetX(size_t pointer_index) const { |
| 98 DCHECK_LT(pointer_index, GetPointerCount()); | 98 DCHECK_LT(pointer_index, GetPointerCount()); |
| 99 return event_.touches[pointer_index].position.x; | 99 return event_.touches[pointer_index].position.x; |
| 100 } | 100 } |
| 101 | 101 |
| 102 float MotionEventWeb::GetY(size_t pointer_index) const { | 102 float MotionEventWeb::GetY(size_t pointer_index) const { |
| 103 DCHECK_LT(pointer_index, GetPointerCount()); | 103 DCHECK_LT(pointer_index, GetPointerCount()); |
| 104 return event_.touches[pointer_index].position.y; | 104 return event_.touches[pointer_index].position.y; |
| 105 } | 105 } |
| 106 | 106 |
| 107 float MotionEventWeb::GetRawX(size_t pointer_index) const { | 107 float MotionEventWeb::GetRawX(size_t pointer_index) const { |
| 108 DCHECK_LT(pointer_index, GetPointerCount()); | 108 DCHECK_LT(pointer_index, GetPointerCount()); |
| 109 return event_.touches[pointer_index].screenPosition.x; | 109 return event_.touches[pointer_index].screenPosition.x; |
| 110 } | 110 } |
| 111 | 111 |
| 112 float MotionEventWeb::GetRawY(size_t pointer_index) const { | 112 float MotionEventWeb::GetRawY(size_t pointer_index) const { |
| 113 DCHECK_LT(pointer_index, GetPointerCount()); | 113 DCHECK_LT(pointer_index, GetPointerCount()); |
| 114 return event_.touches[pointer_index].screenPosition.y; | 114 return event_.touches[pointer_index].screenPosition.y; |
| 115 } | 115 } |
| 116 | 116 |
| 117 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const { | 117 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const { |
| 118 DCHECK_LT(pointer_index, GetPointerCount()); | 118 DCHECK_LT(pointer_index, GetPointerCount()); |
| 119 return 2.f * std::max(event_.touches[pointer_index].radiusX, | 119 return 2.f * std::max(event_.touches[pointer_index].width, |
| 120 event_.touches[pointer_index].radiusY); | 120 event_.touches[pointer_index].height); |
| 121 } | 121 } |
| 122 | 122 |
| 123 float MotionEventWeb::GetTouchMinor(size_t pointer_index) const { | 123 float MotionEventWeb::GetTouchMinor(size_t pointer_index) const { |
| 124 DCHECK_LT(pointer_index, GetPointerCount()); | 124 DCHECK_LT(pointer_index, GetPointerCount()); |
| 125 return 2.f * std::min(event_.touches[pointer_index].radiusX, | 125 return 2.f * std::min(event_.touches[pointer_index].width, |
| 126 event_.touches[pointer_index].radiusY); | 126 event_.touches[pointer_index].height); |
| 127 } | 127 } |
| 128 | 128 |
| 129 float MotionEventWeb::GetOrientation(size_t pointer_index) const { | 129 float MotionEventWeb::GetOrientation(size_t pointer_index) const { |
| 130 DCHECK_LT(pointer_index, GetPointerCount()); | 130 DCHECK_LT(pointer_index, GetPointerCount()); |
| 131 | 131 |
| 132 float rotation_angle_rad = event_.touches[pointer_index].rotationAngle | 132 float rotation_angle_rad = event_.touches[pointer_index].rotationAngle |
| 133 * M_PI / 180.f; | 133 * M_PI / 180.f; |
| 134 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) | 134 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) |
| 135 << "Unexpected touch rotation angle"; | 135 << "Unexpected touch rotation angle"; |
| 136 | 136 |
| 137 if (event_.touches[pointer_index].radiusX | 137 if (event_.touches[pointer_index].width > |
| 138 > event_.touches[pointer_index].radiusY) { | 138 event_.touches[pointer_index].height) { |
| 139 // The case radiusX == radiusY is omitted from here on purpose: for circles, | 139 // The case width == height is omitted from here on purpose: for circles, |
| 140 // we want to pass the angle (which could be any value in such cases but | 140 // we want to pass the angle (which could be any value in such cases but |
| 141 // always seem to be set to zero) unchanged. | 141 // always seem to be set to zero) unchanged. |
| 142 rotation_angle_rad -= (float) M_PI_2; | 142 rotation_angle_rad -= (float) M_PI_2; |
| 143 } | 143 } |
| 144 | 144 |
| 145 return rotation_angle_rad; | 145 return rotation_angle_rad; |
| 146 } | 146 } |
| 147 | 147 |
| 148 float MotionEventWeb::GetPressure(size_t pointer_index) const { | 148 float MotionEventWeb::GetPressure(size_t pointer_index) const { |
| 149 return 0.f; | 149 return 0.f; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 164 | 164 |
| 165 int MotionEventWeb::GetButtonState() const { | 165 int MotionEventWeb::GetButtonState() const { |
| 166 return 0; | 166 return 0; |
| 167 } | 167 } |
| 168 | 168 |
| 169 int MotionEventWeb::GetFlags() const { | 169 int MotionEventWeb::GetFlags() const { |
| 170 return WebEventModifiersToEventFlags(event_.modifiers); | 170 return WebEventModifiersToEventFlags(event_.modifiers); |
| 171 } | 171 } |
| 172 | 172 |
| 173 } // namespace content | 173 } // namespace content |
| OLD | NEW |