| Index: services/keyboard_native/key_layout.cc
|
| diff --git a/services/keyboard_native/key_layout.cc b/services/keyboard_native/key_layout.cc
|
| index 92763d9afa31e0744dfa47a87786706d9bdf5d6a..6b4fb7c6a71c8b570b4b15ced431ecfc54bed797 100644
|
| --- a/services/keyboard_native/key_layout.cc
|
| +++ b/services/keyboard_native/key_layout.cc
|
| @@ -5,9 +5,14 @@
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| #include "base/macros.h"
|
| +#include "services/keyboard_native/kActionIcon.h"
|
| +#include "services/keyboard_native/kDeleteIcon.h"
|
| +#include "services/keyboard_native/kLowerCaseIcon.h"
|
| +#include "services/keyboard_native/kUpperCaseIcon.h"
|
| #include "services/keyboard_native/key_layout.h"
|
| #include "skia/ext/refptr.h"
|
| #include "third_party/skia/include/core/SkTypeface.h"
|
| +#include "ui/gfx/codec/png_codec.h"
|
|
|
| namespace keyboard {
|
|
|
| @@ -36,6 +41,38 @@ void KeyLayout::TextKey::OnTouchUp() {
|
| touch_up_callback_.Run(*this);
|
| }
|
|
|
| +KeyLayout::ImageKey::ImageKey(
|
| + const char* text,
|
| + base::Callback<void(const TextKey&)> touch_up_callback,
|
| + const mojo::embed::Data& data)
|
| + : TextKey(text, touch_up_callback), bitmap_() {
|
| + bool result = gfx::PNGCodec::Decode(
|
| + reinterpret_cast<const unsigned char*>(data.data), data.size, &bitmap_);
|
| + DCHECK(result);
|
| + DCHECK(bitmap_.width() > 0);
|
| + DCHECK(bitmap_.height() > 0);
|
| +}
|
| +
|
| +KeyLayout::ImageKey::~ImageKey() {
|
| +}
|
| +
|
| +void KeyLayout::ImageKey::Draw(SkCanvas* canvas,
|
| + SkPaint paint,
|
| + const gfx::RectF& rect) {
|
| + float width_scale = rect.width() / bitmap_.width();
|
| + float height_scale = rect.height() / bitmap_.height();
|
| + float scale = width_scale > height_scale ? height_scale : width_scale;
|
| + float target_width = bitmap_.width() * scale;
|
| + float target_height = bitmap_.height() * scale;
|
| + float delta_width = rect.width() - target_width;
|
| + float target_x = rect.x() + (delta_width / 2.0f);
|
| + float delta_height = rect.height() - target_height;
|
| + float target_y = rect.y() + (delta_height / 2.0f);
|
| + canvas->drawBitmapRect(bitmap_, SkRect::MakeXYWH(target_x, target_y,
|
| + target_width, target_height),
|
| + &paint);
|
| +}
|
| +
|
| KeyLayout::KeyLayout()
|
| : on_text_callback_(),
|
| layout_(&letters_layout_),
|
| @@ -235,7 +272,8 @@ void KeyLayout::InitKeyMaps() {
|
| new TextKey("l", emit_text_callback)};
|
|
|
| std::vector<Key*> lower_case_key_map_row_three = {
|
| - new TextKey("/\\", switch_to_upper_case_callback),
|
| + new ImageKey("/\\", switch_to_upper_case_callback,
|
| + keyboard_native::kUpperCaseIcon),
|
| new TextKey("z", emit_text_callback),
|
| new TextKey("x", emit_text_callback),
|
| new TextKey("c", emit_text_callback),
|
| @@ -243,14 +281,14 @@ void KeyLayout::InitKeyMaps() {
|
| new TextKey("r", emit_text_callback),
|
| new TextKey("n", emit_text_callback),
|
| new TextKey("m", emit_text_callback),
|
| - new TextKey("del", do_nothing_callback)};
|
| + new ImageKey("del", do_nothing_callback, keyboard_native::kDeleteIcon)};
|
|
|
| std::vector<Key*> lower_case_key_map_row_four = {
|
| new TextKey("sym", switch_to_symbols_callback),
|
| new TextKey(",", emit_text_callback),
|
| new TextKey(" ", emit_text_callback),
|
| new TextKey(".", emit_text_callback),
|
| - new TextKey("act", do_nothing_callback)};
|
| + new ImageKey("act", do_nothing_callback, keyboard_native::kActionIcon)};
|
|
|
| lower_case_key_map_ = {lower_case_key_map_row_one,
|
| lower_case_key_map_row_two,
|
| @@ -281,7 +319,8 @@ void KeyLayout::InitKeyMaps() {
|
| new TextKey("L", emit_text_callback)};
|
|
|
| std::vector<Key*> upper_case_key_map_row_three = {
|
| - new TextKey("\\/", switch_to_lower_case_callback),
|
| + new ImageKey("\\/", switch_to_lower_case_callback,
|
| + keyboard_native::kLowerCaseIcon),
|
| new TextKey("Z", emit_text_callback),
|
| new TextKey("X", emit_text_callback),
|
| new TextKey("C", emit_text_callback),
|
| @@ -289,14 +328,14 @@ void KeyLayout::InitKeyMaps() {
|
| new TextKey("R", emit_text_callback),
|
| new TextKey("N", emit_text_callback),
|
| new TextKey("M", emit_text_callback),
|
| - new TextKey("DEL", do_nothing_callback)};
|
| + new ImageKey("DEL", do_nothing_callback, keyboard_native::kDeleteIcon)};
|
|
|
| std::vector<Key*> upper_case_key_map_row_four = {
|
| new TextKey("SYM", switch_to_symbols_callback),
|
| new TextKey(",", emit_text_callback),
|
| new TextKey(" ", emit_text_callback),
|
| new TextKey(".", emit_text_callback),
|
| - new TextKey("ACT", do_nothing_callback)};
|
| + new ImageKey("ACT", do_nothing_callback, keyboard_native::kActionIcon)};
|
|
|
| upper_case_key_map_ = {upper_case_key_map_row_one,
|
| upper_case_key_map_row_two,
|
| @@ -335,7 +374,7 @@ void KeyLayout::InitKeyMaps() {
|
| new TextKey(";", emit_text_callback),
|
| new TextKey("!", emit_text_callback),
|
| new TextKey("?", emit_text_callback),
|
| - new TextKey("del", do_nothing_callback)};
|
| + new ImageKey("del", do_nothing_callback, keyboard_native::kDeleteIcon)};
|
|
|
| std::vector<Key*> symbols_key_map_row_four = {
|
| new TextKey("ABC", switch_to_lower_case_callback),
|
| @@ -344,7 +383,7 @@ void KeyLayout::InitKeyMaps() {
|
| new TextKey(" ", emit_text_callback),
|
| new TextKey("/", emit_text_callback),
|
| new TextKey(".", emit_text_callback),
|
| - new TextKey("act", do_nothing_callback)};
|
| + new ImageKey("act", do_nothing_callback, keyboard_native::kActionIcon)};
|
|
|
| symbols_key_map_ = {symbols_key_map_row_one,
|
| symbols_key_map_row_two,
|
|
|