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

Unified Diff: services/prediction/input_info.cc

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: format README and CHROMIUM.diff Created 5 years, 4 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
« no previous file with comments | « services/prediction/input_info.h ('k') | services/prediction/key_set.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/prediction/input_info.cc
diff --git a/services/prediction/input_info.cc b/services/prediction/input_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..061c0c8df2a717026fa8bb6c7e9f0db23fb744da
--- /dev/null
+++ b/services/prediction/input_info.cc
@@ -0,0 +1,86 @@
+// 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 <new>
+
+#include "services/prediction/input_info.h"
+#include "services/prediction/key_set.h"
+#include "third_party/android_prediction/defines.h"
+
+namespace prediction {
+
+InputInfo::InputInfo(mojo::String& input, int input_size) {
+ real_size_ = 0;
+ for (int i = 0; i < input_size; i++) {
+ int codepoint = (int)input[i];
+ if ((codepoint >= 'a' && codepoint <= 'z') ||
+ (codepoint >= 'A' && codepoint <= 'Z')) {
+ real_size_++;
+ }
+ }
+ codepoints_ = new int[real_size_];
+ x_coordinates_ = new int[real_size_];
+ y_coordinates_ = new int[real_size_];
+ pointer_ids_ = new int[real_size_];
+ times_ = new int[real_size_];
+
+ ProcessInput(input, input_size);
+}
+
+InputInfo::~InputInfo() {
+ delete[] codepoints_;
+ delete[] x_coordinates_;
+ delete[] y_coordinates_;
+ delete[] pointer_ids_;
+ delete[] times_;
+}
+
+int* InputInfo::GetCodepoints() {
+ return codepoints_;
+}
+
+int* InputInfo::GetXCoordinates() {
+ return x_coordinates_;
+}
+
+int* InputInfo::GetYCoordinates() {
+ return y_coordinates_;
+}
+
+int* InputInfo::GetPointerIds() {
+ return pointer_ids_;
+}
+
+int* InputInfo::GetTimes() {
+ return times_;
+}
+
+int InputInfo::GetRealSize() {
+ return real_size_;
+}
+
+void InputInfo::ProcessInput(mojo::String& input, int input_size) {
+ int real_index = 0;
+ for (int i = 0; i < input_size; i++) {
+ int codepoint = (int)input[i];
+ if ((codepoint >= 'a' && codepoint <= 'z') ||
+ (codepoint >= 'A' && codepoint <= 'Z')) {
+ codepoints_[real_index] = codepoint;
+ for (int j = 0; j < keyset::key_count; j++) {
+ if (keyset::key_set[j].kcode == tolower(codepoint)) {
+ x_coordinates_[real_index] =
+ keyset::key_set[j].kx + keyset::key_set[j].kwidth / 2;
+ y_coordinates_[real_index] =
+ keyset::key_set[j].ky + keyset::key_set[j].kheight / 2;
+ break;
+ }
+ }
+ pointer_ids_[real_index] = 0;
+ times_[real_index] = 0;
+ real_index++;
+ }
+ }
+}
+
+} // namespace prediction
« no previous file with comments | « services/prediction/input_info.h ('k') | services/prediction/key_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698