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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « services/prediction/input_info.h ('k') | services/prediction/key_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/android_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 ProcessInput(input, input_size);
29 }
30
31 InputInfo::~InputInfo() {
32 delete[] codepoints_;
33 delete[] x_coordinates_;
34 delete[] y_coordinates_;
35 delete[] pointer_ids_;
36 delete[] times_;
37 }
38
39 int* InputInfo::GetCodepoints() {
40 return codepoints_;
41 }
42
43 int* InputInfo::GetXCoordinates() {
44 return x_coordinates_;
45 }
46
47 int* InputInfo::GetYCoordinates() {
48 return y_coordinates_;
49 }
50
51 int* InputInfo::GetPointerIds() {
52 return pointer_ids_;
53 }
54
55 int* InputInfo::GetTimes() {
56 return times_;
57 }
58
59 int InputInfo::GetRealSize() {
60 return real_size_;
61 }
62
63 void InputInfo::ProcessInput(mojo::String& input, int input_size) {
64 int real_index = 0;
65 for (int i = 0; i < input_size; i++) {
66 int codepoint = (int)input[i];
67 if ((codepoint >= 'a' && codepoint <= 'z') ||
68 (codepoint >= 'A' && codepoint <= 'Z')) {
69 codepoints_[real_index] = codepoint;
70 for (int j = 0; j < keyset::key_count; j++) {
71 if (keyset::key_set[j].kcode == tolower(codepoint)) {
72 x_coordinates_[real_index] =
73 keyset::key_set[j].kx + keyset::key_set[j].kwidth / 2;
74 y_coordinates_[real_index] =
75 keyset::key_set[j].ky + keyset::key_set[j].kheight / 2;
76 break;
77 }
78 }
79 pointer_ids_[real_index] = 0;
80 times_[real_index] = 0;
81 real_index++;
82 }
83 }
84 }
85
86 } // namespace prediction
OLDNEW
« 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