| 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 the Delegate 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 Delegate { | 
|  | 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 Delegate to be notified of all text input messages. | 
|  | 53   // Passing a null |delegate| causes IME messages to be ignored. | 
|  | 54   void set_delegate(Delegate* delegate) { delegate_ = delegate; } | 
|  | 55 | 
|  | 56   // Sends text from IME to the blimp engine. | 
|  | 57   void OnImeTextEntered(const std::string& text); | 
|  | 58 | 
|  | 59  private: | 
|  | 60   // BlimpMessageProcessor implementation. | 
|  | 61   void ProcessMessage(scoped_ptr<BlimpMessage> message, | 
|  | 62                       const net::CompletionCallback& callback) override; | 
|  | 63 | 
|  | 64   // Delegate for processing the text input related messages. |delegate_| must | 
|  | 65   // remain valid until the last message has been passed to ImeFeature. | 
|  | 66   Delegate* delegate_ = nullptr; | 
|  | 67 | 
|  | 68   // Tab id and render widget id for the input field for which user input is | 
|  | 69   // being requested. | 
|  | 70   // The values are cached from the ImeMessage::SHOW_IME message and sent back | 
|  | 71   // to engine in the subsequent ImeMessage::SET_TEXT message. | 
|  | 72   // The cached values are cleared on receiving ImeMessage::HIDE_IME request. | 
|  | 73   int tab_id_ = -1; | 
|  | 74   int render_widget_id_ = 0; | 
|  | 75 | 
|  | 76   // Used to send BlimpMessage::IME messages to the engine. | 
|  | 77   scoped_ptr<BlimpMessageProcessor> outgoing_message_processor_; | 
|  | 78 | 
|  | 79   DISALLOW_COPY_AND_ASSIGN(ImeFeature); | 
|  | 80 }; | 
|  | 81 | 
|  | 82 }  // namespace client | 
|  | 83 }  // namespace blimp | 
|  | 84 | 
|  | 85 #endif  // BLIMP_CLIENT_FEATURE_IME_FEATURE_H_ | 
| OLD | NEW | 
|---|