blob: 6726fc9197fd2ee124feb1d0e36be5725e10f860 [file] [log] [blame]
Ria Runjie Jiang1e6163c2015-08-06 13:06:25 -07001// 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
13namespace prediction {
14
15const int TouchPositionCorrection::TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
16
17TouchPositionCorrection::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
48TouchPositionCorrection::~TouchPositionCorrection() {
49}
50
51bool TouchPositionCorrection::IsValid() {
52 return enabled_;
53}
54
55int TouchPositionCorrection::GetRows() {
56 return 3;
57}
58
59float TouchPositionCorrection::GetX(const int row) {
60 // Touch position correction data for X coordinate is obsolete.
61 return 0.0f;
62}
63
64float TouchPositionCorrection::GetY(const int row) {
65 return ys_[row];
66}
67
68float TouchPositionCorrection::GetRadius(const int row) {
69 return radii_[row];
70}
71
James Robinson04362ac2015-09-18 18:24:02 -070072} // namespace prediction