Flutter Engine
The Flutter Engine
text_input_manager.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_MANAGER_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_MANAGER_H_
7
8#include <Windows.h>
9#include <Windowsx.h>
10
11#include <optional>
12#include <string>
13
14#include "flutter/fml/macros.h"
15#include "flutter/shell/platform/common/geometry.h"
16
17namespace flutter {
18
19// Management interface for IME-based text input on Windows.
20//
21// When inputting text in CJK languages, text is entered via a multi-step
22// process, where direct keyboard input is buffered into a composing string,
23// which is then converted into the desired characters by selecting from a
24// candidates list and committing the change to the string.
25//
26// This implementation wraps the Win32 IMM32 APIs and provides a mechanism for
27// creating and positioning the IME window, a system caret, and the candidates
28// list as well as for accessing composing and results string contents.
30 public:
33
34 // Sets the window handle with which the IME is associated.
35 void SetWindowHandle(HWND window_handle);
36
37 // Creates a new IME window and system caret.
38 //
39 // This method should be invoked in response to the WM_IME_SETCONTEXT and
40 // WM_IME_STARTCOMPOSITION events.
41 void CreateImeWindow();
42
43 // Destroys the current IME window and system caret.
44 //
45 // This method should be invoked in response to the WM_IME_ENDCOMPOSITION
46 // event.
47 void DestroyImeWindow();
48
49 // Updates the current IME window and system caret position.
50 //
51 // This method should be invoked when handling user input via
52 // WM_IME_COMPOSITION events.
53 void UpdateImeWindow();
54
55 // Updates the current IME window and system caret position.
56 //
57 // This method should be invoked when handling cursor position/size updates.
58 void UpdateCaretRect(const Rect& rect);
59
60 // Returns the cursor position relative to the start of the composing range.
61 virtual long GetComposingCursorPosition() const;
62
63 // Returns the contents of the composing string.
64 //
65 // This may be called in response to WM_IME_COMPOSITION events where the
66 // GCS_COMPSTR flag is set in the lparam. In some IMEs, this string may also
67 // be set in events where the GCS_RESULTSTR flag is set. This contains the
68 // in-progress composing string.
69 virtual std::optional<std::u16string> GetComposingString() const;
70
71 // Returns the contents of the result string.
72 //
73 // This may be called in response to WM_IME_COMPOSITION events where the
74 // GCS_RESULTSTR flag is set in the lparam. This contains the final string to
75 // be committed in the composing region when composition is ended.
76 virtual std::optional<std::u16string> GetResultString() const;
77
78 /// Aborts IME composing.
79 ///
80 /// Aborts composing, closes the candidates window, and clears the contents
81 /// of the composing string.
82 void AbortComposing();
83
84 private:
85 // Returns either the composing string or result string based on the value of
86 // the |type| parameter.
87 std::optional<std::u16string> GetString(int type) const;
88
89 // Moves the IME composing and candidates windows to the current caret
90 // position.
91 void MoveImeWindow(HIMC imm_context);
92
93 // The window with which the IME windows are associated.
94 HWND window_handle_ = nullptr;
95
96 // True if IME-based composing is active.
97 bool ime_active_ = false;
98
99 // The system caret rect.
100 Rect caret_rect_ = {{0, 0}, {0, 0}};
101
102 FML_DISALLOW_COPY_AND_ASSIGN(TextInputManager);
103};
104
105} // namespace flutter
106
107#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_MANAGER_H_
GLenum type
void UpdateCaretRect(const Rect &rect)
virtual std::optional< std::u16string > GetComposingString() const
void SetWindowHandle(HWND window_handle)
TextInputManager() noexcept=default
virtual std::optional< std::u16string > GetResultString() const
virtual long GetComposingCursorPosition() const
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By default
Definition: switches.h:183
Definition: ref_ptr.h:256