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 <new> | |
6 | |
7 #include "services/prediction/input_info.h" | |
8 #include "services/prediction/key_set.h" | |
9 #include "third_party/prediction/defines.h" | |
10 | |
11 namespace prediction { | |
12 | |
13 InputInfo::InputInfo() { | |
14 real_size_ = 0; | |
15 } | |
16 | |
17 InputInfo::~InputInfo() { | |
18 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
| |
19 delete[] x_coordinates_; | |
20 delete[] y_coordinates_; | |
21 delete[] pointer_ids_; | |
22 delete[] times_; | |
23 } | |
24 | |
25 int* InputInfo::GetCodepoints() { | |
26 return codepoints_; | |
27 } | |
28 | |
29 int* InputInfo::GetXCoordinates() { | |
30 return x_coordinates_; | |
31 } | |
32 | |
33 int* InputInfo::GetYCoordinates() { | |
34 return y_coordinates_; | |
35 } | |
36 | |
37 int* InputInfo::GetPointerIds() { | |
38 return pointer_ids_; | |
39 } | |
40 | |
41 int* InputInfo::GetTimes() { | |
42 return times_; | |
43 } | |
44 | |
45 int InputInfo::GetRealSize() { | |
46 return real_size_; | |
47 } | |
48 | |
49 void InputInfo::ProcessInput(mojo::String& input) { | |
50 int input_size = std::min((int)input.size(), MAX_WORD_LENGTH); | |
51 real_size_ = 0; | |
52 for (int i = 0; i < input_size; i++) { | |
53 int codepoint = (int)input[i]; | |
54 if ((codepoint >= 'a' && codepoint <= 'z') || | |
55 (codepoint >= 'A' && codepoint <= 'Z')) { | |
56 real_size_++; | |
57 } | |
58 } | |
59 | |
60 codepoints_ = new int[real_size_]; | |
61 x_coordinates_ = new int[real_size_]; | |
62 y_coordinates_ = new int[real_size_]; | |
63 pointer_ids_ = new int[real_size_]; | |
64 times_ = new int[real_size_]; | |
65 int real_index = 0; | |
66 for (int i = 0; i < input_size; i++) { | |
67 int codepoint = (int)input[i]; | |
68 if ((codepoint >= 'a' && codepoint <= 'z') || | |
69 (codepoint >= 'A' && codepoint <= 'Z')) { | |
70 codepoints_[real_index] = codepoint; | |
71 for (int j = 0; j < KeySet::key_count; j++) { | |
72 if (KeySet::key_set[j].kcode == tolower(codepoint)) { | |
73 x_coordinates_[real_index] = | |
74 KeySet::key_set[j].kx + KeySet::key_set[j].kwidth / 2; | |
75 y_coordinates_[real_index] = | |
76 KeySet::key_set[j].ky + KeySet::key_set[j].kheight / 2; | |
77 break; | |
78 } | |
79 } | |
80 pointer_ids_[real_index] = 0; | |
81 times_[real_index] = 0; | |
82 real_index++; | |
83 } | |
84 } | |
85 } | |
86 | |
87 } // namespace prediction | |
OLD | NEW |