OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 VIEWS_IME_TEXT_INPUT_CLIENT_H_ |
| 6 #define VIEWS_IME_TEXT_INPUT_CLIENT_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/string16.h" |
| 14 #include "ui/base/ime/composition_text.h" |
| 15 #include "ui/base/ime/text_input_type.h" |
| 16 #include "ui/base/range/range.h" |
| 17 |
| 18 namespace gfx { |
| 19 class Rect; |
| 20 } |
| 21 |
| 22 namespace views { |
| 23 |
| 24 // An interface implemented by a View that needs text input support. |
| 25 class TextInputClient { |
| 26 public: |
| 27 virtual ~TextInputClient() {} |
| 28 |
| 29 // Input method result ------------------------------------------------------- |
| 30 |
| 31 // Sets composition text and attributes. If there is composition text already, |
| 32 // it’ll be replaced by the new one. Otherwise, current selection will be |
| 33 // replaced. If there is no selection, the composition text will be inserted |
| 34 // at the insertion point. |
| 35 virtual void SetCompositionText(const ui::CompositionText& composition) = 0; |
| 36 |
| 37 // Converts current composition text into final content. |
| 38 virtual void ConfirmCompositionText() = 0; |
| 39 |
| 40 // Removes current composition text. |
| 41 virtual void ClearCompositionText() = 0; |
| 42 |
| 43 // Inserts a given text at the insertion point. Current composition text or |
| 44 // selection will be removed. This method should never be called when the |
| 45 // current text input type is TEXT_INPUT_TYPE_NONE. |
| 46 virtual void InsertText(const string16& text) = 0; |
| 47 |
| 48 // Inserts a single char at the insertion point. Unlike above InsertText() |
| 49 // method, this method has an extra |flags| parameter indicating the modifier |
| 50 // key states when the character is generated. This method should only be |
| 51 // called when a key press is not handled by the input method but still |
| 52 // generates a character (eg. by the keyboard driver). In another word, the |
| 53 // preceding key press event should not be a VKEY_PROCESSKEY. |
| 54 // This method will be called whenever a char is generated by the keyboard, |
| 55 // even if the current text input type is TEXT_INPUT_TYPE_NONE. |
| 56 virtual void InsertChar(char16 ch, int flags) = 0; |
| 57 |
| 58 // Input context information ------------------------------------------------- |
| 59 |
| 60 // Returns current text input type. It could be changed and even becomes |
| 61 // TEXT_INPUT_TYPE_NONE at runtime. |
| 62 virtual ui::TextInputType GetTextInputType() = 0; |
| 63 |
| 64 // Returns current caret (insertion point) bounds relative to the View’s |
| 65 // coordinates. If there is selection, then the selection bounds will be |
| 66 // returned. |
| 67 virtual gfx::Rect GetCaretBounds() = 0; |
| 68 |
| 69 // Returns true if there is composition text. |
| 70 virtual bool HasCompositionText() = 0; |
| 71 |
| 72 // Document content operations ---------------------------------------------- |
| 73 |
| 74 // Retrieves the UTF-16 based character range containing all text in the View. |
| 75 // Returns false if the information cannot be retrieved right now. |
| 76 virtual bool GetTextRange(ui::Range* range) = 0; |
| 77 |
| 78 // Retrieves the UTF-16 based character range of current composition text. |
| 79 // Returns false if the information cannot be retrieved right now. |
| 80 virtual bool GetCompositionTextRange(ui::Range* range) = 0; |
| 81 |
| 82 // Retrieves the UTF-16 based character range of current selection. |
| 83 // Returns false if the information cannot be retrieved right now. |
| 84 virtual bool GetSelectionRange(ui::Range* range) = 0; |
| 85 |
| 86 // Selects the given UTF-16 based character range. Current composition text |
| 87 // will be confirmed before selecting the range. |
| 88 // Returns false if the operation is not supported. |
| 89 virtual bool SetSelectionRange(const ui::Range& range) = 0; |
| 90 |
| 91 // Deletes contents in the given UTF-16 based character range. Current |
| 92 // composition text will be confirmed before deleting the range. |
| 93 // The input caret will be moved to the place where the range gets deleted. |
| 94 // Returns false if the oepration is not supported. |
| 95 virtual bool DeleteRange(const ui::Range& range) = 0; |
| 96 |
| 97 // Retrieves the text content in a given UTF-16 based character range. |
| 98 // The result will be send back to the input method by calling the given |
| 99 // callback, which may happen asynchronously. |
| 100 // Returns false if the operation is not supported. |
| 101 virtual bool GetTextFromRange( |
| 102 const ui::Range& range, |
| 103 const base::Callback<void(const string16&)>& callback) = 0; |
| 104 |
| 105 // Miscellaneous ------------------------------------------------------------ |
| 106 |
| 107 // Called whenever current keyboard layout or input method is changed, |
| 108 // especially the change of input locale and text direction. |
| 109 virtual void OnInputMethodChanged() = 0; |
| 110 |
| 111 // Called whenever the user requests to change the text direction and layout |
| 112 // alignment of the current text box. It’s for supporting ctrl-shift on |
| 113 // Windows. |
| 114 // Returns false if the operation is not supported. |
| 115 virtual bool ChangeTextDirectionAndLayoutAlignment( |
| 116 base::i18n::TextDirection direction) = 0; |
| 117 }; |
| 118 |
| 119 } // namespace views |
| 120 |
| 121 #endif // VIEWS_IME_TEXT_INPUT_CLIENT_H_ |
OLD | NEW |