[go: nahoru, domu]

blob: 500bb3d04bee7afc083897505592e765b277c584 [file] [log] [blame]
ChromeOS Developerca17ee62013-12-16 22:04:451// Copyright (c) 2013 The Chromium OS 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#ifndef SUGGEST_SUGGEST_H_
5#define SUGGEST_SUGGEST_H_
6
7#include <string>
8#include <list>
9#include <vector>
10
11#include "types.h"
12
13namespace suggest {
14
15class SuggestEngine;
16class SuggestEngineSession;
17
18// Description of a key.
19// The coordinate system can be chosen by the user of this library,
20// but keep in mind that all calculations are made in integer arithmetics.
21// the rectangle is defined as location of the top left corner and size.
22struct Key {
23 Key() {}
24 Key(vec2f location, vec2f size, charcode _code) :
25 rect(location, size), code(_code) {
26 }
27
28 rect2f rect;
29 charcode code;
30
31 static Key InvalidKey;
32};
33
34// A single word suggestion including confidences
35struct Suggestion {
36 std::string word;
37 int frequency;
38 int commit_first_word_confidence;
39};
40
41// Next to the coordinates of a touch, suggest needs to know which
42// character your keyboard recognized and displays to the users.
43struct Touch {
44 Touch() {}
45 Touch(vec2f pos, charcode code);
46
47 // create touch based on location only. Looks up which key is
48 // at this location.
49 Touch(vec2f pos, const SuggestEngine& engine);
50
51 // create a touch based on char code, assumes the key is hit right at
52 // the center.
53 Touch(charcode code, const SuggestEngine& engine);
54
55 vec2f pos;
56 charcode code;
57};
58
59// Parameters to tweak the suggestion process.
60// The list of parameters might change during iterations of the
61// library, but the constructor will always choose sane default values.
62// The provided locale name will be used to pick the right dictionary
63// from /usr/share/libsuggest/
64struct SuggestParameters {
65 SuggestParameters(std::string locale);
66
67 vec2f grid_cells;
68 float search_box_size_factor;
69 std::string locale;
70};
71
72// I am not 100% sure what the session concept in AOSP is used for,
73// so far I have been using a single session for all suggestions.
74// The session allows you to receive suggestions based on a list
75// of touch coordinates and (optional) the previously typed word.
76class SuggestSession {
77 public:
78 virtual const std::list<Suggestion>& GetSuggestions(
79 const std::vector<Touch> &touches,
80 std::string previous_word="") = 0;
81};
82
83// Main class of the suggestion process, which builds the keyboard definition
84// and allows suggest sessions to be created with this keyboard.
85class SuggestEngine {
86 public:
87 virtual Key GetKeyAt(vec2f pos) const = 0;
88 virtual Key GetKey(charcode code) const = 0;
89
90 // start a new session
91 virtual bool LoadDictionary(std::string locale) = 0;
92 virtual SuggestSession* NewSession() = 0;
93};
94
95// To hide the implementation details of the SuggestEngine class
96// (especially for hiding the AOSP API)
97SuggestEngine* NewSuggestEngine(vec2f keyboard_size, vec2f common_key_size,
98 const std::vector<Key> &keylist,
99 const SuggestParameters &parameters);
100
101
102} // namespace suggest
103
104#endif // SUGGEST_SUGGEST_H_