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

Side by Side Diff: services/keyboard_native/key_layout.h

Issue 1149293002: Add the ability for keys to be drawn as an image. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix .gitignore and other issues Created 5 years, 6 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
OLDNEW
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" 13 #include "mojo/public/cpp/bindings/callback.h"
14 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h" 14 #include "mojo/services/geometry/public/interfaces/geometry.mojom.h"
15 #include "mojo/tools/embed/data.h"
15 #include "third_party/skia/include/core/SkCanvas.h" 16 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "third_party/skia/include/core/SkImageDecoder.h"
viettrungluu 2015/06/02 22:29:35 I don't think you need these includes in the .h, o
APW 2015/06/02 23:16:55 Done.
18 #include "third_party/skia/include/core/SkStream.h"
16 #include "ui/gfx/geometry/point.h" 19 #include "ui/gfx/geometry/point.h"
17 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
18 21
19 namespace keyboard { 22 namespace keyboard {
20 23
21 // Represents a drawable keyboard. 24 // Represents a drawable keyboard.
22 class KeyLayout { 25 class KeyLayout {
23 public: 26 public:
24 // All keys represented by this KeyBoard layout will implement the Key 27 // All keys represented by this KeyBoard layout will implement the Key
25 // interface. 28 // interface.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // Indicate to the keyboard that a touch up has occurred at the given Point. 65 // Indicate to the keyboard that a touch up has occurred at the given Point.
63 void OnTouchUp(const gfx::Point& touch_up); 66 void OnTouchUp(const gfx::Point& touch_up);
64 67
65 private: 68 private:
66 // An implementation of Key that draws itself as ASCII text. 69 // An implementation of Key that draws itself as ASCII text.
67 class TextKey : public Key { 70 class TextKey : public Key {
68 public: 71 public:
69 TextKey(const char* text, 72 TextKey(const char* text,
70 base::Callback<void(const TextKey&)> touch_up_callback); 73 base::Callback<void(const TextKey&)> touch_up_callback);
71 ~TextKey() override; 74 ~TextKey() override;
75
76 // Key implementation.
72 void Draw(SkCanvas* canvas, SkPaint paint, const gfx::RectF& rect) override; 77 void Draw(SkCanvas* canvas, SkPaint paint, const gfx::RectF& rect) override;
73 const char* ToText() const override; 78 const char* ToText() const override;
74 void OnTouchUp() override; 79 void OnTouchUp() override;
75 80
76 private: 81 private:
77 const char* text_; 82 const char* text_;
78 base::Callback<void(const TextKey&)> touch_up_callback_; 83 base::Callback<void(const TextKey&)> touch_up_callback_;
79 84
80 DISALLOW_COPY_AND_ASSIGN(TextKey); 85 DISALLOW_COPY_AND_ASSIGN(TextKey);
81 }; 86 };
82 87
88 // An implementation of Key that draws itself as an image.
89 class ImageKey : public Key {
90 public:
91 ImageKey(const char* text,
92 base::Callback<void(const TextKey&)> touch_up_callback,
93 const mojo::embed::Data& data);
viettrungluu 2015/06/02 22:29:35 Probably you can just forward declare mojo::embed:
APW 2015/06/02 23:16:55 Done.
94 ~ImageKey() override;
95
96 // Key implementation.
97 void Draw(SkCanvas* canvas, SkPaint paint, const gfx::RectF& rect) override;
98 const char* ToText() const override;
99 void OnTouchUp() override;
100
101 private:
102 TextKey text_key_;
103 bool bitmap_valid_;
104 SkBitmap bitmap_;
105
106 DISALLOW_COPY_AND_ASSIGN(ImageKey);
107 };
108
83 // initializes the *_layout_ vectors. 109 // initializes the *_layout_ vectors.
84 void InitLayouts(); 110 void InitLayouts();
85 111
86 // initializes the *_key_map_ vectors. 112 // initializes the *_key_map_ vectors.
87 void InitKeyMaps(); 113 void InitKeyMaps();
88 114
89 // A TextKey callback that does nothing. 115 // A TextKey callback that does nothing.
90 void OnKeyDoNothing(const TextKey& key); 116 void OnKeyDoNothing(const TextKey& key);
91 117
92 // A TextKey callback that calls on_text_callback_ with the text of the 118 // A TextKey callback that calls on_text_callback_ with the text of the
(...skipping 23 matching lines...) Expand all
116 std::vector<std::vector<Key*>> upper_case_key_map_; 142 std::vector<std::vector<Key*>> upper_case_key_map_;
117 std::vector<std::vector<Key*>> symbols_key_map_; 143 std::vector<std::vector<Key*>> symbols_key_map_;
118 base::WeakPtrFactory<KeyLayout> weak_factory_; 144 base::WeakPtrFactory<KeyLayout> weak_factory_;
119 145
120 DISALLOW_COPY_AND_ASSIGN(KeyLayout); 146 DISALLOW_COPY_AND_ASSIGN(KeyLayout);
121 }; 147 };
122 148
123 } // namespace keyboard 149 } // namespace keyboard
124 150
125 #endif // SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_ 151 #endif // SERVICES_KEYBOARD_NATIVE_KEY_LAYOUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698