diff options
Diffstat (limited to 'blimp/net')
-rw-r--r-- | blimp/net/BUILD.gn | 1 | ||||
-rw-r--r-- | blimp/net/DEPS | 1 | ||||
-rw-r--r-- | blimp/net/input_message_converter.cc | 83 | ||||
-rw-r--r-- | blimp/net/input_message_converter.h | 15 | ||||
-rw-r--r-- | blimp/net/input_message_unittest.cc | 9 |
5 files changed, 106 insertions, 3 deletions
diff --git a/blimp/net/BUILD.gn b/blimp/net/BUILD.gn index 0fe0cfd..00b771f 100644 --- a/blimp/net/BUILD.gn +++ b/blimp/net/BUILD.gn @@ -65,6 +65,7 @@ component("blimp_net") { "//blimp/common:blimp_common", "//blimp/common/proto", "//net", + "//ui/base/ime:text_input_types", ] } diff --git a/blimp/net/DEPS b/blimp/net/DEPS index 211c82c..b2abd3d 100644 --- a/blimp/net/DEPS +++ b/blimp/net/DEPS @@ -2,4 +2,5 @@ include_rules = [ "+net", "+third_party/WebKit/public/platform/WebGestureDevice.h", "+third_party/WebKit/public/web/WebInputEvent.h", + "+ui/base/ime/text_input_type.h", ] diff --git a/blimp/net/input_message_converter.cc b/blimp/net/input_message_converter.cc index 9cfd3c8..5f3854e 100644 --- a/blimp/net/input_message_converter.cc +++ b/blimp/net/input_message_converter.cc @@ -178,4 +178,87 @@ scoped_ptr<blink::WebGestureEvent> InputMessageConverter::ProcessMessage( return event; } +ui::TextInputType InputMessageConverter::TextInputTypeFromProto( + ImeMessage_InputType type) { + switch (type) { + case ImeMessage_InputType_NONE: + return ui::TEXT_INPUT_TYPE_NONE; + case ImeMessage_InputType_TEXT: + return ui::TEXT_INPUT_TYPE_TEXT; + case ImeMessage_InputType_PASSWORD: + return ui::TEXT_INPUT_TYPE_PASSWORD; + case ImeMessage_InputType_SEARCH: + return ui::TEXT_INPUT_TYPE_SEARCH; + case ImeMessage_InputType_EMAIL: + return ui::TEXT_INPUT_TYPE_EMAIL; + case ImeMessage_InputType_NUMBER: + return ui::TEXT_INPUT_TYPE_NUMBER; + case ImeMessage_InputType_TELEPHONE: + return ui::TEXT_INPUT_TYPE_TELEPHONE; + case ImeMessage_InputType_URL: + return ui::TEXT_INPUT_TYPE_URL; + case ImeMessage_InputType_DATE: + return ui::TEXT_INPUT_TYPE_DATE; + case ImeMessage_InputType_DATE_TIME: + return ui::TEXT_INPUT_TYPE_DATE_TIME; + case ImeMessage_InputType_DATE_TIME_LOCAL: + return ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL; + case ImeMessage_InputType_MONTH: + return ui::TEXT_INPUT_TYPE_MONTH; + case ImeMessage_InputType_TIME: + return ui::TEXT_INPUT_TYPE_TIME; + case ImeMessage_InputType_WEEK: + return ui::TEXT_INPUT_TYPE_WEEK; + case ImeMessage_InputType_TEXT_AREA: + return ui::TEXT_INPUT_TYPE_TEXT_AREA; + case ImeMessage_InputType_CONTENT_EDITABLE: + return ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE; + case ImeMessage_InputType_DATE_TIME_FIELD: + return ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD; + } + return ui::TEXT_INPUT_TYPE_NONE; +} + +ImeMessage_InputType InputMessageConverter::TextInputTypeToProto( + ui::TextInputType type) { + switch (type) { + case ui::TEXT_INPUT_TYPE_NONE: + NOTREACHED() << "IME needs an editable TextInputType"; + return ImeMessage_InputType_NONE; + case ui::TEXT_INPUT_TYPE_TEXT: + return ImeMessage_InputType_TEXT; + case ui::TEXT_INPUT_TYPE_PASSWORD: + return ImeMessage_InputType_PASSWORD; + case ui::TEXT_INPUT_TYPE_SEARCH: + return ImeMessage_InputType_SEARCH; + case ui::TEXT_INPUT_TYPE_EMAIL: + return ImeMessage_InputType_EMAIL; + case ui::TEXT_INPUT_TYPE_NUMBER: + return ImeMessage_InputType_NUMBER; + case ui::TEXT_INPUT_TYPE_TELEPHONE: + return ImeMessage_InputType_TELEPHONE; + case ui::TEXT_INPUT_TYPE_URL: + return ImeMessage_InputType_URL; + case ui::TEXT_INPUT_TYPE_DATE: + return ImeMessage_InputType_DATE; + case ui::TEXT_INPUT_TYPE_DATE_TIME: + return ImeMessage_InputType_DATE_TIME; + case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: + return ImeMessage_InputType_DATE_TIME_LOCAL; + case ui::TEXT_INPUT_TYPE_MONTH: + return ImeMessage_InputType_MONTH; + case ui::TEXT_INPUT_TYPE_TIME: + return ImeMessage_InputType_TIME; + case ui::TEXT_INPUT_TYPE_WEEK: + return ImeMessage_InputType_WEEK; + case ui::TEXT_INPUT_TYPE_TEXT_AREA: + return ImeMessage_InputType_TEXT_AREA; + case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE: + return ImeMessage_InputType_CONTENT_EDITABLE; + case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: + return ImeMessage_InputType_DATE_TIME_FIELD; + } + return ImeMessage_InputType_NONE; +} + } // namespace blimp diff --git a/blimp/net/input_message_converter.h b/blimp/net/input_message_converter.h index 53606c1..7d21216 100644 --- a/blimp/net/input_message_converter.h +++ b/blimp/net/input_message_converter.h @@ -7,7 +7,9 @@ #include "base/macros.h" #include "base/memory/scoped_ptr.h" +#include "blimp/common/proto/ime.pb.h" #include "blimp/net/blimp_net_export.h" +#include "ui/base/ime/text_input_type.h" namespace blink { class WebGestureEvent; @@ -17,9 +19,12 @@ namespace blimp { class InputMessage; -// Handles creating WebGestureEvents from a stream of InputMessage protos. This -// class may be stateful to optimize the size of the serialized transmission -// data. See InputMessageConverter for the deserialize code. +// A generic class to provide conversion utilities for protos such as : +// 1) Creating WebGestureEvents from a stream of InputMessage protos. +// This class may be stateful to optimize the size of the serialized +// transmission +// data. See InputMessageConverter for the deserialize code. +// 2) Conversion between ui::TextInputType and ImeMessage proto. class BLIMP_NET_EXPORT InputMessageConverter { public: InputMessageConverter(); @@ -30,6 +35,10 @@ class BLIMP_NET_EXPORT InputMessageConverter { scoped_ptr<blink::WebGestureEvent> ProcessMessage( const InputMessage& message); + // Converts a ui::TextInputType to ImeMessage proto. + static ImeMessage_InputType TextInputTypeToProto(ui::TextInputType type); + static ui::TextInputType TextInputTypeFromProto(ImeMessage_InputType type); + private: DISALLOW_COPY_AND_ASSIGN(InputMessageConverter); }; diff --git a/blimp/net/input_message_unittest.cc b/blimp/net/input_message_unittest.cc index 6157f2b0..02579d7 100644 --- a/blimp/net/input_message_unittest.cc +++ b/blimp/net/input_message_unittest.cc @@ -130,4 +130,13 @@ TEST(InputMessageTest, TestUnsupportedInputEventSerializationFails) { EXPECT_EQ(nullptr, generator.GenerateMessage(event).get()); } +TEST(InputMessageConverterTest, TestTextInputTypeToProtoConversion) { + for (size_t i = ui::TextInputType::TEXT_INPUT_TYPE_TEXT; + i < ui::TextInputType::TEXT_INPUT_TYPE_MAX; i++) { + ui::TextInputType type = static_cast<ui::TextInputType>(i); + EXPECT_EQ(type, InputMessageConverter::TextInputTypeFromProto( + InputMessageConverter::TextInputTypeToProto(type))); + } +} + } // namespace blimp |