1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_BASE_IME_ASH_TEXT_INPUT_METHOD_H_
#define UI_BASE_IME_ASH_TEXT_INPUT_METHOD_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "build/build_config.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_mode.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/events/event_constants.h"
namespace gfx {
class Rect;
} // namespace gfx
namespace ui {
class VirtualKeyboardController;
class KeyEvent;
namespace ime {
struct AssistiveWindowButton;
enum class KeyEventHandledState {
kNotHandled = 0,
kHandledByIME = 1,
kHandledByAssistiveSuggester = 2,
// Same as kNotHandled, except that the autorepeat for this key should be
// suppressed.
kNotHandledSuppressAutoRepeat = 3,
};
} // namespace ime
} // namespace ui
namespace ash {
namespace ime {
struct AssistiveWindow;
}
enum class PersonalizationMode {
// The input method MUST not use anything from the input field to update any
// personalized data (e.g. to improve suggestions quality). Personalization
// could be disabled if the content is privacy-sensitive (e.g. incognito mode
// in
// Chrome browser), or if using personalization does not make sense (e.g.
// playing a typing game may pollute the dictionary with uncommon words).
kDisabled,
// The input method MAY use the input field contents for personalization.
kEnabled
};
enum class AutocompletionMode { kUnspecified, kDisabled, kEnabled };
enum class AutocorrectionMode { kUnspecified, kDisabled, kEnabled };
enum class SpellcheckMode { kUnspecified, kDisabled, kEnabled };
enum class AutocapitalizationMode {
kUnspecified,
kNone,
kCharacters,
kWords,
kSentences,
};
// An interface representing an input method that can read and manipulate text
// in a TextInputTarget. For example, this can represent a Japanese input method
// that can compose and insert Japanese characters into a TextInputTarget.
class COMPONENT_EXPORT(UI_BASE_IME_ASH) TextInputMethod {
public:
using KeyEventDoneCallback =
base::OnceCallback<void(ui::ime::KeyEventHandledState)>;
// A information about a focused text input field.
// A type of each member is based on the html spec, but InputContext can be
// used to specify about a non html text field like Omnibox.
struct InputContext {
explicit InputContext(ui::TextInputType type) : type(type) {}
ui::TextInputType type = ui::TEXT_INPUT_TYPE_NONE;
ui::TextInputMode mode = ui::TEXT_INPUT_MODE_DEFAULT;
AutocompletionMode autocompletion_mode = AutocompletionMode::kUnspecified;
AutocorrectionMode autocorrection_mode = AutocorrectionMode::kUnspecified;
SpellcheckMode spellcheck_mode = SpellcheckMode::kUnspecified;
AutocapitalizationMode autocapitalization_mode =
AutocapitalizationMode::kUnspecified;
// How this input field was focused.
ui::TextInputClient::FocusReason focus_reason =
ui::TextInputClient::FOCUS_REASON_NONE;
// Whether text entered in this field should be used to improve typing
// suggestions for the user.
PersonalizationMode personalization_mode = PersonalizationMode::kDisabled;
};
virtual ~TextInputMethod() = default;
// Informs the input method that an input field has gained focus.
// `input_context` contains information about the newly focused input field.
virtual void Focus(const InputContext& input_context) = 0;
// Informs the input method that focus has been lost.
virtual void Blur() = 0;
// Called when the IME is enabled.
virtual void Enable(const std::string& component_id) = 0;
// Called when the IME is disabled.
virtual void Disable() = 0;
// Called when the IME is reset.
virtual void Reset() = 0;
// Called when the key event is received.
// Actual implementation must call |callback| after key event handling.
virtual void ProcessKeyEvent(const ui::KeyEvent& key_event,
KeyEventDoneCallback callback) = 0;
// Called when the surrounding text has changed. The |text| is surrounding
// text and |selection_range| is the range of selection within |text|.
// |selection_range| has a direction: the start is also called the 'anchor`
// and the end is also called the 'focus'. If not all surrounding text is
// given, |offset_pos| indicates the starting offset of |text|.
virtual void SetSurroundingText(const std::u16string& text,
gfx::Range selection_range,
uint32_t offset_pos) = 0;
// Called when caret bounds changed.
virtual void SetCaretBounds(const gfx::Rect& caret_bounds) = 0;
// Gets the implementation of the keyboard controller.
virtual ui::VirtualKeyboardController* GetVirtualKeyboardController()
const = 0;
// Called when a property is activated or changed.
virtual void PropertyActivate(const std::string& property_name) = 0;
// Called when the candidate in lookup table is clicked. The |index| is 0
// based candidate index in lookup table.
virtual void CandidateClicked(uint32_t index) = 0;
// Called when assistive window is clicked.
virtual void AssistiveWindowButtonClicked(
const ui::ime::AssistiveWindowButton& button) {}
// Called when an input's assistive window state is updated.
virtual void AssistiveWindowChanged(const ime::AssistiveWindow& window) = 0;
// Returns whether the IME is ready to accept key events for testing.
virtual bool IsReadyForTesting() = 0;
};
} // namespace ash
#endif // UI_BASE_IME_ASH_TEXT_INPUT_METHOD_H_
|