OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ | 5 #ifndef SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ |
6 #define SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ | 6 #define SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h" | 13 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h" |
14 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
15 | 15 |
16 class SkCanvas; | 16 class SkCanvas; |
17 class SkPaint; | 17 class SkPaint; |
18 | 18 |
19 namespace gfx { | 19 namespace gfx { |
20 class PointF; | 20 class PointF; |
21 } | 21 } |
22 | 22 |
23 namespace keyboard { | 23 namespace keyboard { |
24 | 24 |
| 25 class Predictor; |
| 26 class TextUpdateKey; |
| 27 |
25 // Represents a drawable keyboard. | 28 // Represents a drawable keyboard. |
26 class KeyLayout { | 29 class KeyLayout { |
27 public: | 30 public: |
28 // All keys represented by this KeyBoard layout will implement the Key | 31 // All keys represented by this KeyBoard layout will implement the Key |
29 // interface. | 32 // interface. |
30 class Key { | 33 class Key { |
31 public: | 34 public: |
32 virtual ~Key() {} | 35 virtual ~Key() {} |
33 | 36 |
34 // Draws the Key to the SkCanvas with the given SkPaint to the given Rect. | 37 // Draws the Key to the SkCanvas with the given SkPaint to the given Rect. |
(...skipping 13 matching lines...) Expand all Loading... |
48 KeyLayout(); | 51 KeyLayout(); |
49 ~KeyLayout(); | 52 ~KeyLayout(); |
50 | 53 |
51 // Sets the callback to call with the text of a key whenever it's pressed. | 54 // Sets the callback to call with the text of a key whenever it's pressed. |
52 void SetTextCallback( | 55 void SetTextCallback( |
53 base::Callback<void(const std::string&)> on_text_callback); | 56 base::Callback<void(const std::string&)> on_text_callback); |
54 | 57 |
55 // Sets the callback to call whenever delete is pressed. | 58 // Sets the callback to call whenever delete is pressed. |
56 void SetDeleteCallback(base::Callback<void()> on_delete_callback); | 59 void SetDeleteCallback(base::Callback<void()> on_delete_callback); |
57 | 60 |
| 61 void SetSuggestTextCallback( |
| 62 base::Callback<void(const std::string&)> on_suggest_text_callback); |
| 63 |
58 // Sets the dimensions the keyboard will draw itself into. | 64 // Sets the dimensions the keyboard will draw itself into. |
59 void SetKeyArea(const gfx::RectF& key_area); | 65 void SetKeyArea(const gfx::RectF& key_area); |
60 | 66 |
61 // Draws the keyboard to the SkCanvas. | 67 // Draws the keyboard to the SkCanvas. |
62 void Draw(SkCanvas* canvas); | 68 void Draw(SkCanvas* canvas); |
63 | 69 |
64 // Returns the Key at the given Point. Returns nullptr if no key is at that | 70 // Returns the Key at the given Point. Returns nullptr if no key is at that |
65 // Point. | 71 // Point. |
66 Key* GetKeyAtPoint(const gfx::PointF& point); | 72 Key* GetKeyAtPoint(const gfx::PointF& point); |
67 | 73 |
68 // Indicate to the keyboard that a touch up has occurred at the given Point. | 74 // Indicate to the keyboard that a touch up has occurred at the given Point. |
69 void OnTouchUp(const gfx::PointF& touch_up); | 75 void OnTouchUp(const gfx::PointF& touch_up); |
70 | 76 |
| 77 void SetPredictor(Predictor* predictor); |
| 78 |
71 private: | 79 private: |
72 // initializes the *_layout_ vectors. | 80 // initializes the *_layout_ vectors. |
73 void InitLayouts(); | 81 void InitLayouts(); |
74 | 82 |
75 // initializes the *_key_map_ vectors. | 83 // initializes the *_key_map_ vectors. |
76 void InitKeyMaps(); | 84 void InitKeyMaps(); |
77 | 85 |
78 // A TextKey callback that does nothing. | 86 // A TextKey callback that does nothing. |
79 void OnKeyDoNothing(const TextKey& key); | 87 void OnKeyDoNothing(const TextKey& key); |
80 | 88 |
81 // A TextKey callback that calls on_text_callback_ with the text of the | 89 // A TextKey callback that calls on_text_callback_ with the text of the |
82 // TextKey. | 90 // TextKey. |
83 void OnKeyEmitText(const TextKey& key); | 91 void OnKeyEmitText(const TextKey& key); |
84 | 92 |
85 // A TextKey callback that calls on_delete_callback_. | 93 // A TextKey callback that calls on_delete_callback_. |
86 void OnKeyDelete(const TextKey& key); | 94 void OnKeyDelete(const TextKey& key); |
87 | 95 |
| 96 void OnSuggestKeyEmitText(const TextUpdateKey& key); |
| 97 |
88 // A TextKey callback that switches the layout_ and key_map_ to upper case. | 98 // A TextKey callback that switches the layout_ and key_map_ to upper case. |
89 void OnKeySwitchToUpperCase(const TextKey& key); | 99 void OnKeySwitchToUpperCase(const TextKey& key); |
90 | 100 |
91 // A TextKey callback that switches the layout_ and key_map_ to lower case. | 101 // A TextKey callback that switches the layout_ and key_map_ to lower case. |
92 void OnKeySwitchToLowerCase(const TextKey& key); | 102 void OnKeySwitchToLowerCase(const TextKey& key); |
93 | 103 |
94 // A TextKey callback that switches the layout_ and key_map_ to symbols. | 104 // A TextKey callback that switches the layout_ and key_map_ to symbols. |
95 void OnKeySwitchToSymbols(const TextKey& key); | 105 void OnKeySwitchToSymbols(const TextKey& key); |
96 | 106 |
97 base::Callback<void(const std::string&)> on_text_callback_; | 107 base::Callback<void(const std::string&)> on_text_callback_; |
98 base::Callback<void()> on_delete_callback_; | 108 base::Callback<void()> on_delete_callback_; |
| 109 base::Callback<void(const std::string&)> on_suggest_text_callback_; |
99 gfx::RectF key_area_; | 110 gfx::RectF key_area_; |
100 std::vector<std::vector<float>>* layout_; | 111 std::vector<std::vector<float>>* layout_; |
101 std::vector<std::vector<float>> letters_layout_; | 112 std::vector<std::vector<float>> letters_layout_; |
102 std::vector<std::vector<float>> symbols_layout_; | 113 std::vector<std::vector<float>> symbols_layout_; |
103 std::vector<std::vector<Key*>>* key_map_; | 114 std::vector<std::vector<Key*>>* key_map_; |
104 std::vector<std::vector<Key*>> lower_case_key_map_; | 115 std::vector<std::vector<Key*>> lower_case_key_map_; |
105 std::vector<std::vector<Key*>> upper_case_key_map_; | 116 std::vector<std::vector<Key*>> upper_case_key_map_; |
106 std::vector<std::vector<Key*>> symbols_key_map_; | 117 std::vector<std::vector<Key*>> symbols_key_map_; |
| 118 Predictor* predictor_; |
107 base::WeakPtrFactory<KeyLayout> weak_factory_; | 119 base::WeakPtrFactory<KeyLayout> weak_factory_; |
108 | 120 |
109 DISALLOW_COPY_AND_ASSIGN(KeyLayout); | 121 DISALLOW_COPY_AND_ASSIGN(KeyLayout); |
110 }; | 122 }; |
111 | 123 |
112 } // namespace keyboard | 124 } // namespace keyboard |
113 | 125 |
114 #endif // SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ | 126 #endif // SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ |
OLD | NEW |