| 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/public/cpp/bindings/callback.h" | |
| 14 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h" | 13 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h" |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 14 |
| 16 #include "ui/gfx/geometry/point.h" | 15 class SkCanvas; |
| 17 #include "ui/gfx/geometry/rect.h" | 16 class SkPaint; |
| 17 |
| 18 namespace gfx { |
| 19 class RectF; |
| 20 class Point; |
| 21 } |
| 18 | 22 |
| 19 namespace keyboard { | 23 namespace keyboard { |
| 20 | 24 |
| 21 // Represents a drawable keyboard. | 25 // Represents a drawable keyboard. |
| 22 class KeyLayout { | 26 class KeyLayout { |
| 23 public: | 27 public: |
| 24 // All keys represented by this KeyBoard layout will implement the Key | 28 // All keys represented by this KeyBoard layout will implement the Key |
| 25 // interface. | 29 // interface. |
| 26 class Key { | 30 class Key { |
| 27 public: | 31 public: |
| 28 virtual ~Key() {} | 32 virtual ~Key() {} |
| 29 | 33 |
| 30 // Draws the Key to the SkCanvas with the given SkPaint to the given Rect. | 34 // Draws the Key to the SkCanvas with the given SkPaint to the given Rect. |
| 31 virtual void Draw(SkCanvas* canvas, | 35 virtual void Draw(SkCanvas* canvas, |
| 32 SkPaint paint, | 36 const SkPaint& paint, |
| 33 const gfx::RectF& rect) = 0; | 37 const gfx::RectF& rect) = 0; |
| 34 | 38 |
| 35 // Converts the Key to its text representation. | 39 // Converts the Key to its text representation. |
| 36 virtual const char* ToText() const = 0; | 40 virtual const char* ToText() const = 0; |
| 37 | 41 |
| 38 // Indicate to the Key that a touch up has occurred on it. | 42 // Indicate to the Key that a touch up has occurred on it. |
| 39 virtual void OnTouchUp() = 0; | 43 virtual void OnTouchUp() = 0; |
| 40 }; | 44 }; |
| 41 | 45 |
| 46 class TextKey; |
| 47 |
| 42 KeyLayout(); | 48 KeyLayout(); |
| 43 ~KeyLayout(); | 49 ~KeyLayout(); |
| 44 | 50 |
| 45 // Sets the callback to call with the text of a key whenever it's pressed. | 51 // Sets the callback to call with the text of a key whenever it's pressed. |
| 46 void SetTextCallback( | 52 void SetTextCallback( |
| 47 base::Callback<void(const std::string&)> on_text_callback); | 53 base::Callback<void(const std::string&)> on_text_callback); |
| 48 | 54 |
| 49 // Sets the callback to call whenever delete is pressed. | 55 // Sets the callback to call whenever delete is pressed. |
| 50 void SetDeleteCallback(base::Callback<void()> on_delete_callback); | 56 void SetDeleteCallback(base::Callback<void()> on_delete_callback); |
| 51 | 57 |
| 52 // Sets the dimensions the keyboard will draw itself into. | 58 // Sets the dimensions the keyboard will draw itself into. |
| 53 void SetSize(const mojo::Size& size); | 59 void SetSize(const mojo::Size& size); |
| 54 | 60 |
| 55 // Draws the keyboard to the SkCanvas. | 61 // Draws the keyboard to the SkCanvas. |
| 56 void Draw(SkCanvas* canvas); | 62 void Draw(SkCanvas* canvas); |
| 57 | 63 |
| 58 // Returns the Key at the given Point. Returns nullptr if no key is at that | 64 // Returns the Key at the given Point. Returns nullptr if no key is at that |
| 59 // Point. | 65 // Point. |
| 60 Key* GetKeyAtPoint(const gfx::Point& point); | 66 Key* GetKeyAtPoint(const gfx::Point& point); |
| 61 | 67 |
| 62 // Indicate to the keyboard that a touch up has occurred at the given Point. | 68 // Indicate to the keyboard that a touch up has occurred at the given Point. |
| 63 void OnTouchUp(const gfx::Point& touch_up); | 69 void OnTouchUp(const gfx::Point& touch_up); |
| 64 | 70 |
| 65 private: | 71 private: |
| 66 // An implementation of Key that draws itself as ASCII text. | |
| 67 class TextKey : public Key { | |
| 68 public: | |
| 69 TextKey(const char* text, | |
| 70 base::Callback<void(const TextKey&)> touch_up_callback); | |
| 71 ~TextKey() override; | |
| 72 void Draw(SkCanvas* canvas, SkPaint paint, const gfx::RectF& rect) override; | |
| 73 const char* ToText() const override; | |
| 74 void OnTouchUp() override; | |
| 75 | |
| 76 private: | |
| 77 const char* text_; | |
| 78 base::Callback<void(const TextKey&)> touch_up_callback_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(TextKey); | |
| 81 }; | |
| 82 | |
| 83 // initializes the *_layout_ vectors. | 72 // initializes the *_layout_ vectors. |
| 84 void InitLayouts(); | 73 void InitLayouts(); |
| 85 | 74 |
| 86 // initializes the *_key_map_ vectors. | 75 // initializes the *_key_map_ vectors. |
| 87 void InitKeyMaps(); | 76 void InitKeyMaps(); |
| 88 | 77 |
| 89 // A TextKey callback that does nothing. | 78 // A TextKey callback that does nothing. |
| 90 void OnKeyDoNothing(const TextKey& key); | 79 void OnKeyDoNothing(const TextKey& key); |
| 91 | 80 |
| 92 // A TextKey callback that calls on_text_callback_ with the text of the | 81 // A TextKey callback that calls on_text_callback_ with the text of the |
| (...skipping 23 matching lines...) Expand all Loading... |
| 116 std::vector<std::vector<Key*>> upper_case_key_map_; | 105 std::vector<std::vector<Key*>> upper_case_key_map_; |
| 117 std::vector<std::vector<Key*>> symbols_key_map_; | 106 std::vector<std::vector<Key*>> symbols_key_map_; |
| 118 base::WeakPtrFactory<KeyLayout> weak_factory_; | 107 base::WeakPtrFactory<KeyLayout> weak_factory_; |
| 119 | 108 |
| 120 DISALLOW_COPY_AND_ASSIGN(KeyLayout); | 109 DISALLOW_COPY_AND_ASSIGN(KeyLayout); |
| 121 }; | 110 }; |
| 122 | 111 |
| 123 } // namespace keyboard | 112 } // namespace keyboard |
| 124 | 113 |
| 125 #endif // SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ | 114 #endif // SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ |
| OLD | NEW |