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

Unified Diff: services/prediction/touch_position_correction.cc

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: services/prediction/touch_position_correction.cc
diff --git a/services/prediction/touch_position_correction.cc b/services/prediction/touch_position_correction.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aacda611ae176a87b76f13d158041acf9c52af78
--- /dev/null
+++ b/services/prediction/touch_position_correction.cc
@@ -0,0 +1,79 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/prediction/touch_position_correction.h"
+
+// NOTE: This class has been translated to C++ and modified from the Android
+// Open Source Project. Specifically from some functions of the following file:
+// https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/
+// android-5.1.1_r8/java/src/com/android/inputmethod/keyboard/internal/
+// TouchPositionCorrection.java
+
+namespace prediction {
+
+const int TouchPositionCorrection::TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
+
+TouchPositionCorrection::TouchPositionCorrection() {
+ // value currently used by Android TouchPositionCorrection
+ std::string data[9] = {"0.0038756",
+ "-0.0005677",
+ "0.1577026",
+ "-0.0236678",
+ "0.0381731",
+ "0.1529972",
+ "-0.0086827",
+ "0.0880847",
+ "0.1522819"};
+ const int data_length = 9;
+ if (data_length % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) {
+ return;
+ }
+
+ const int length = data_length / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ xs = new float[length];
+ ys = new float[length];
+ radii = new float[length];
+ for (int i = 0; i < data_length; ++i) {
+ const int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ const int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ const float value = std::stof(data[i]);
+ if (type == 0) {
+ xs[index] = value;
+ } else if (type == 1) {
+ ys[index] = value;
+ } else {
+ radii[index] = value;
+ }
+ }
+ enabled = data_length > 0;
+}
+
+TouchPositionCorrection::~TouchPositionCorrection() {
+ delete[] xs;
+ delete[] ys;
+ delete[] radii;
APW 2015/07/23 20:11:28 as we know length, I don't think any of these need
riajiang 2015/07/31 02:13:04 Done.
+}
+
+bool TouchPositionCorrection::IsValid() {
+ return enabled;
+}
+
+int TouchPositionCorrection::GetRows() {
+ return 3;
+}
+
+float TouchPositionCorrection::GetX(const int row) {
+ // Touch position correction data for X coordinate is obsolete.
+ return 0.0f;
+}
+
+float TouchPositionCorrection::GetY(const int row) {
+ return ys[row];
+}
+
+float TouchPositionCorrection::GetRadius(const int row) {
+ return radii[row];
+}
+
+} // namespace prediction

Powered by Google App Engine
This is Rietveld 408576698