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