Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BLIMP_CLIENT_FEATURE_IME_FEATURE_H_ | |
| 6 #define BLIMP_CLIENT_FEATURE_IME_FEATURE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "blimp/client/blimp_client_export.h" | |
| 13 #include "blimp/net/blimp_message_processor.h" | |
| 14 #include "ui/base/ime/text_input_type.h" | |
| 15 | |
| 16 namespace blimp { | |
| 17 namespace client { | |
| 18 | |
| 19 // Handles all incoming and outgoing protobuf messages for text input of type | |
| 20 // BlimpMessage::IME for blimp client. | |
| 21 // Upon receiving a text input request from the engine, the ImeFeature caches | |
| 22 // the |tab_id_| and |render_widget_id_| for the request and | |
| 23 // delegates the request to ImeFeatureDelegate which then opens up the IME. | |
| 24 // After user is done typing, the text is passed back to ImeFeature, which then | |
| 25 // sends the text to the engine over network along with the same |tab_id_| and | |
| 26 // |render_widget_id_|. | |
| 27 // Any time user taps on an input text, ImeMessage::SHOW_IME message will be | |
| 28 // sent to client. Similarly, any time the text input is out of focus (e.g. if | |
| 29 // user navigates away from the currently page or the page loads for the first | |
| 30 // time), ImeMessage::HIDE_IME will be sent. | |
| 31 | |
| 32 class BLIMP_CLIENT_EXPORT ImeFeature : public BlimpMessageProcessor { | |
| 33 public: | |
| 34 // A delegate to be notified of text input requests. | |
| 35 class ImeFeatureDelegate { | |
|
Wez
2016/03/22 21:43:38
nit: Either call this ImeFeatureDelegate and move
shaktisahu
2016/03/22 23:45:42
I think we can't just call it Delegate since it wo
Wez
2016/03/23 00:10:53
I don't understand why the name would make any dif
| |
| 36 public: | |
| 37 virtual void OnShowImeRequested(ui::TextInputType input_type, | |
| 38 const std::string& text) = 0; | |
| 39 virtual void OnHideImeRequested() = 0; | |
| 40 }; | |
| 41 | |
| 42 ImeFeature(); | |
| 43 ~ImeFeature() override; | |
| 44 | |
| 45 // Set the BlimpMessageProcessor that will be used to send BlimpMessage::IME | |
| 46 // messages to the engine. | |
| 47 void set_outgoing_message_processor( | |
| 48 scoped_ptr<BlimpMessageProcessor> processor) { | |
| 49 outgoing_message_processor_ = std::move(processor); | |
| 50 } | |
| 51 | |
| 52 // Sets a ImeFeatureDelegate to be notified of all text input messages. | |
| 53 void set_delegate(ImeFeatureDelegate* delegate) { delegate_ = delegate; } | |
| 54 | |
| 55 // Sends text from IME to the blimp engine. | |
| 56 void OnImeTextEntered(const std::string& text); | |
| 57 | |
| 58 private: | |
| 59 // BlimpMessageProcessor implementation. | |
| 60 void ProcessMessage(scoped_ptr<BlimpMessage> message, | |
| 61 const net::CompletionCallback& callback) override; | |
| 62 | |
| 63 // Delegate for processing the text input related messages. |delegate_| must | |
| 64 // remain valid until the last message has been passed to ImeFeature. | |
| 65 ImeFeatureDelegate* delegate_; | |
| 66 | |
| 67 // Tab id and render widget id for the input field for which user input is | |
| 68 // being requested. | |
| 69 // The values are cached from the ImeMessage::SHOW_IME message and sent back | |
| 70 // to engine in the subsequent ImeMessage::SET_TEXT message. | |
| 71 // The cached values are cleared on receiving ImeMessage::HIDE_IME request. | |
| 72 int tab_id_; | |
| 73 int render_widget_id_; | |
| 74 | |
| 75 // Used to send BlimpMessage::IME messages to the engine. | |
| 76 scoped_ptr<BlimpMessageProcessor> outgoing_message_processor_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(ImeFeature); | |
| 79 }; | |
| 80 | |
| 81 } // namespace client | |
| 82 } // namespace blimp | |
| 83 | |
| 84 #endif // BLIMP_CLIENT_FEATURE_IME_FEATURE_H_ | |
| OLD | NEW |