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(mojo::String& input, int input_size) { | |
14 real_size_ = 0; | |
15 for (int i = 0; i < input_size; i++) { | |
16 int codepoint = (int)input[i]; | |
17 if ((codepoint >= 'a' && codepoint <= 'z') || | |
18 (codepoint >= 'A' && codepoint <= 'Z')) { | |
19 real_size_++; | |
20 } | |
21 } | |
22 codepoints_ = new int[real_size_]; | |
23 x_coordinates_ = new int[real_size_]; | |
24 y_coordinates_ = new int[real_size_]; | |
25 pointer_ids_ = new int[real_size_]; | |
26 times_ = new int[real_size_]; | |
27 } | |
28 | |
29 InputInfo::~InputInfo() { | |
30 delete[] codepoints_; | |
31 delete[] x_coordinates_; | |
32 delete[] y_coordinates_; | |
33 delete[] pointer_ids_; | |
34 delete[] times_; | |
35 } | |
36 | |
37 int* InputInfo::GetCodepoints() { | |
38 return codepoints_; | |
39 } | |
40 | |
41 int* InputInfo::GetXCoordinates() { | |
42 return x_coordinates_; | |
43 } | |
44 | |
45 int* InputInfo::GetYCoordinates() { | |
46 return y_coordinates_; | |
47 } | |
48 | |
49 int* InputInfo::GetPointerIds() { | |
50 return pointer_ids_; | |
51 } | |
52 | |
53 int* InputInfo::GetTimes() { | |
54 return times_; | |
55 } | |
56 | |
57 int InputInfo::GetRealSize() { | |
58 return real_size_; | |
59 } | |
60 | |
61 void InputInfo::ProcessInput(mojo::String& input, int input_size) { | |
APW
2015/08/03 21:38:57
You assume here that input and input_size here are
riajiang
2015/08/03 22:25:05
Done.
| |
62 int real_index = 0; | |
63 for (int i = 0; i < input_size; i++) { | |
64 int codepoint = (int)input[i]; | |
65 if ((codepoint >= 'a' && codepoint <= 'z') || | |
66 (codepoint >= 'A' && codepoint <= 'Z')) { | |
67 codepoints_[real_index] = codepoint; | |
68 for (int j = 0; j < keyset::key_count; j++) { | |
69 if (keyset::key_set[j].kcode == tolower(codepoint)) { | |
70 x_coordinates_[real_index] = | |
71 keyset::key_set[j].kx + keyset::key_set[j].kwidth / 2; | |
72 y_coordinates_[real_index] = | |
73 keyset::key_set[j].ky + keyset::key_set[j].kheight / 2; | |
74 break; | |
75 } | |
76 } | |
77 pointer_ids_[real_index] = 0; | |
78 times_[real_index] = 0; | |
79 real_index++; | |
80 } | |
81 } | |
82 } | |
83 | |
84 } // namespace prediction | |
OLD | NEW |