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..e42d8386f36313c494d8968657bcf0058c5da87b |
--- /dev/null |
+++ b/services/prediction/input_info.cc |
@@ -0,0 +1,87 @@ |
+// 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/prediction/defines.h" |
+ |
+namespace prediction { |
+ |
+InputInfo::InputInfo() { |
+ real_size_ = 0; |
+} |
+ |
+InputInfo::~InputInfo() { |
+ delete[] codepoints_; |
APW
2015/07/31 21:49:15
this will crash if no own ever calls ProcessInput
riajiang
2015/08/01 01:23:08
Added checking if real_size is bigger than 0
|
+ 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 = std::min((int)input.size(), MAX_WORD_LENGTH); |
+ 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_]; |
+ 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 |