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