OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "services/prediction/touch_position_correction.h" |
| 6 |
| 7 // NOTE: This class has been translated to C++ and modified from the Android |
| 8 // Open Source Project. Specifically from some functions of the following file: |
| 9 // https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/ |
| 10 // android-5.1.1_r8/java/src/com/android/inputmethod/keyboard/internal/ |
| 11 // TouchPositionCorrection.java |
| 12 |
| 13 namespace prediction { |
| 14 |
| 15 const int TouchPositionCorrection::TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3; |
| 16 |
| 17 TouchPositionCorrection::TouchPositionCorrection() { |
| 18 // value currently used by Android TouchPositionCorrection |
| 19 std::string data[9] = {"0.0038756", |
| 20 "-0.0005677", |
| 21 "0.1577026", |
| 22 "-0.0236678", |
| 23 "0.0381731", |
| 24 "0.1529972", |
| 25 "-0.0086827", |
| 26 "0.0880847", |
| 27 "0.1522819"}; |
| 28 const int data_length = 9; |
| 29 if (data_length % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) { |
| 30 return; |
| 31 } |
| 32 |
| 33 for (int i = 0; i < data_length; ++i) { |
| 34 const int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE; |
| 35 const int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE; |
| 36 const float value = std::stof(data[i]); |
| 37 if (type == 0) { |
| 38 xs_[index] = value; |
| 39 } else if (type == 1) { |
| 40 ys_[index] = value; |
| 41 } else { |
| 42 radii_[index] = value; |
| 43 } |
| 44 } |
| 45 enabled_ = data_length > 0; |
| 46 } |
| 47 |
| 48 TouchPositionCorrection::~TouchPositionCorrection() { |
| 49 } |
| 50 |
| 51 bool TouchPositionCorrection::IsValid() { |
| 52 return enabled_; |
| 53 } |
| 54 |
| 55 int TouchPositionCorrection::GetRows() { |
| 56 return 3; |
| 57 } |
| 58 |
| 59 float TouchPositionCorrection::GetX(const int row) { |
| 60 // Touch position correction data for X coordinate is obsolete. |
| 61 return 0.0f; |
| 62 } |
| 63 |
| 64 float TouchPositionCorrection::GetY(const int row) { |
| 65 return ys_[row]; |
| 66 } |
| 67 |
| 68 float TouchPositionCorrection::GetRadius(const int row) { |
| 69 return radii_[row]; |
| 70 } |
| 71 |
| 72 } // namespace prediction |
OLD | NEW |