Skip to content

Commit

Permalink
Continue reverting IMM32 removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
win32ss committed Feb 25, 2024
1 parent 19a2397 commit 48275c7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ui/base/ime/win/tsf_input_scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ typedef HRESULT (WINAPI *SetInputScopesFunc)(HWND window_handle,
WCHAR*, /* unused */
WCHAR* /* unused */);

SetInputScopesFunc g_set_input_scopes = NULL;
bool g_get_proc_done = false;

InputScope ConvertTextInputTypeToInputScope(TextInputType text_input_type) {
// Following mapping is based in IE10 on Windows 8.
switch (text_input_type) {
Expand Down Expand Up @@ -150,6 +153,25 @@ InputScope ConvertTextInputModeToInputScope(TextInputMode text_input_mode) {

} // namespace

void InitializeTsfForInputScopes() {
DCHECK(base::CurrentUIThread::IsSet());
// Thread safety is not required because this function is under UI thread.
if (!g_get_proc_done) {
g_get_proc_done = true;

// For stability reasons, we do not support Windows XP.
if (base::win::GetVersion() < base::win::Version::VISTA)
return;

HMODULE module = NULL;
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll",
&module)) {
g_set_input_scopes = reinterpret_cast<SetInputScopesFunc>(
GetProcAddress(module, "SetInputScopes"));
}
}
}

std::vector<InputScope> GetInputScopes(TextInputType text_input_type,
TextInputMode text_input_mode) {
std::vector<InputScope> input_scopes;
Expand Down Expand Up @@ -179,4 +201,16 @@ ITfInputScope* CreateInputScope(TextInputType text_input_type,
return new TSFInputScope(input_scopes);
}

void SetInputScopeForTsfUnawareWindow(HWND window_handle,
TextInputType text_input_type,
TextInputMode text_input_mode) {
if (!g_set_input_scopes)
return;

std::vector<InputScope> input_scopes = GetInputScopes(text_input_type,
text_input_mode);
g_set_input_scopes(window_handle, &input_scopes[0], input_scopes.size(),
NULL, 0, NULL, NULL);
}

} // namespace ui::tsf_inputscope
13 changes: 13 additions & 0 deletions ui/base/ime/win/tsf_input_scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
namespace ui {
namespace tsf_inputscope {

// Initializes the TSF for input scopes. It loads the tsf dll and get the
// function pointer for setting the input scopes in TSF.
COMPONENT_EXPORT(UI_BASE_IME_WIN) void InitializeTsfForInputScopes();

// Returns InputScope list corresoponding to ui::TextInputType and
// ui::TextInputMode.
// This function is only used from following functions but declared for test.
Expand All @@ -34,6 +38,15 @@ ITfInputScope* CreateInputScope(TextInputType text_input_type,
TextInputMode text_input_mode,
bool should_do_learning);

// A wrapper of the SetInputScopes API exported by msctf.dll.
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms629026.aspx
// Does nothing on Windows XP in case TSF is disabled.
// NOTE: For TSF-aware window, you should use ITfInputScope instead.
COMPONENT_EXPORT(UI_BASE_IME_WIN)
void SetInputScopeForTsfUnawareWindow(HWND window_handle,
TextInputType text_input_type,
TextInputMode text_input_mode);

} // namespace tsf_inputscope
} // namespace ui

Expand Down

0 comments on commit 48275c7

Please sign in to comment.