19ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 59ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#ifndef UI_BASE_IME_WIN_IMM32_MANAGER_H 69ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#define UI_BASE_IME_WIN_IMM32_MANAGER_H 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <windows.h> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/i18n/rtl.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/strings/string16.h" 16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/base/ime/text_input_mode.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/ui_export.h" 187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/gfx/rect.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct CompositionText; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This header file defines a struct and a class used for encapsulating IMM32 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// APIs, controls IMEs attached to a window, and enables the 'on-the-spot' 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// input without deep knowledge about the APIs, i.e. knowledge about the 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// language-specific and IME-specific behaviors. 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The following items enumerates the simplest steps for an (window) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// application to control its IMEs with the struct and the class defined 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this file. 319ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// 1. Add an instance of the IMM32Manager class to its window class. 329ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// (The IMM32Manager class needs a window handle.) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2. Add messages handlers listed in the following subsections, follow the 349ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// instructions written in each subsection, and use the IMM32Manager class. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2.1. WM_IME_SETCONTEXT (0x0281) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call the functions listed below: 379ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::CreateImeWindow(); 389ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::CleanupComposition(), and; 399ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::SetImeWindowStyle(). 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An application MUST prevent from calling ::DefWindowProc(). 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2.2. WM_IME_STARTCOMPOSITION (0x010D) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call the functions listed below: 439ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::CreateImeWindow(), and; 449ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::ResetComposition(). 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An application MUST prevent from calling ::DefWindowProc(). 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2.3. WM_IME_COMPOSITION (0x010F) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call the functions listed below: 489ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::UpdateImeWindow(); 499ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::GetResult(); 509ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::GetComposition(), and; 519ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::ResetComposition() (optional). 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An application MUST prevent from calling ::DefWindowProc(). 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2.4. WM_IME_ENDCOMPOSITION (0x010E) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call the functions listed below: 559ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::ResetComposition(), and; 569ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::DestroyImeWindow(). 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An application CAN call ::DefWindowProc(). 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2.5. WM_INPUTLANGCHANGE (0x0051) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call the functions listed below: 609ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch// - IMM32Manager::SetInputLanguage(). 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An application CAN call ::DefWindowProc(). 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class controls the IMM (Input Method Manager) through IMM32 APIs and 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// enables it to retrieve the string being controled by the IMM. (I wrote 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// a note to describe the reason why I do not use 'IME' but 'IMM' below.) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE(hbono): 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Fortunately or unfortunately, TSF (Text Service Framework) and 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// CUAS (Cicero Unaware Application Support) allows IMM32 APIs for 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// retrieving not only the inputs from IMEs (Input Method Editors), used 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// only for inputting East-Asian language texts, but also the ones from 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// tablets (on Windows XP Tablet PC Edition and Windows Vista), voice 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// recognizers (e.g. ViaVoice and Microsoft Office), etc. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We can disable TSF and CUAS in Windows XP Tablet PC Edition. On the other 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// hand, we can NEVER disable either TSF or CUAS in Windows Vista, i.e. 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// THIS CLASS IS NOT ONLY USED ON THE INPUT CONTEXTS OF EAST-ASIAN 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LANGUAGES BUT ALSO USED ON THE INPUT CONTEXTS OF ALL LANGUAGES. 779ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdochclass UI_EXPORT IMM32Manager { 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 799ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch IMM32Manager(); 80ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch virtual ~IMM32Manager(); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves whether or not there is an ongoing composition. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_composing() const { return is_composing_; } 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves the input language from Windows and update it. 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return values 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * true 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The given input language has IMEs. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * false 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The given input language does not have IMEs. 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool SetInputLanguage(); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates the IME windows, and allocate required resources for them. 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CreateImeWindow(HWND window_handle); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the style of the IME windows. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * message [in] (UINT) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * wparam [in] (WPARAM) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * lparam [in] (LPARAM) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represent the windows message of the caller. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These parameters are used for verifying if this function is called 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in a handler function for WM_IME_SETCONTEXT messages because this 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // function uses ::DefWindowProc() to update the style. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A caller just has to pass the input parameters for the handler 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // function without modifications. 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * handled [out] (BOOL*) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns ::DefWindowProc() is really called in this function. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // PLEASE DO NOT CALL ::DefWindowProc() IF THIS VALUE IS TRUE! 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // All the window styles set in this function are over-written when 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // calling ::DefWindowProc() after returning this function. 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the value returned by DefWindowProc. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LRESULT SetImeWindowStyle(HWND window_handle, UINT message, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WPARAM wparam, LPARAM lparam, BOOL* handled); 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Destroys the IME windows and all the resources attached to them. 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DestroyImeWindow(HWND window_handle); 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the position of the IME windows. 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateImeWindow(HWND window_handle); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1339ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // Cleans up the all resources attached to the given IMM32Manager object, and 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reset its composition status. 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CleanupComposition(HWND window_handle); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Resets the composition status. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancel the ongoing composition if it exists. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE(hbono): This method does not release the allocated resources. 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ResetComposition(HWND window_handle); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves a composition result of the ongoing composition if it exists. 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * lparam [in] (LPARAM) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Specifies the updated members of the ongoing composition, and must be 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the same parameter of a WM_IME_COMPOSITION message handler. 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This parameter is used for checking if the ongoing composition has 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // its result string, 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * result [out] (string16) 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the object contains the composition result. 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return values 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * true 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The ongoing composition has a composition result. 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * false 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The ongoing composition does not have composition results. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remarks 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This function is designed for being called from WM_IME_COMPOSITION 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // message handlers. 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetResult(HWND window_handle, LPARAM lparam, string16* result); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves the current composition status of the ongoing composition. 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * lparam [in] (LPARAM) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Specifies the updated members of the ongoing composition, and must be 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the same parameter of a WM_IME_COMPOSITION message handler. 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This parameter is used for checking if the ongoing composition has 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // its result string, 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * composition [out] (Composition) 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the struct contains the composition status. 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Return values 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * true 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The status of the ongoing composition is updated. 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * false 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The status of the ongoing composition is not updated. 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remarks 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This function is designed for being called from WM_IME_COMPOSITION 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // message handlers. 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetComposition(HWND window_handle, LPARAM lparam, 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CompositionText* composition); 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Enables the IME attached to the given window, i.e. allows user-input 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // events to be dispatched to the IME. 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * complete [in] (bool) 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents whether or not to complete the ongoing composition. 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // + true 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // After finishing the ongoing composition and close its IME windows, 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // start another composition and display its IME windows to the given 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // position. 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // + false 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Just move the IME windows of the ongoing composition to the given 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // position without finishing it. 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void EnableIME(HWND window_handle); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Disables the IME attached to the given window, i.e. prohibits any 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // user-input events from being dispatched to the IME. 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // In Chrome, this function is used when: 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * a renreder process sets its input focus to a password input. 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DisableIME(HWND window_handle); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels an ongoing composition of the IME attached to the given window. 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CancelIME(HWND window_handle); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the caret position of the given window. 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parameters 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * window_handle [in] (HWND) 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents the window handle of the caller. 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * caret_rect [in] (const gfx::Rect&) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represent the rectangle of the input caret. 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This rectangle is used for controlling the positions of IME windows. 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateCaretRect(HWND window_handle, const gfx::Rect& caret_rect); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the setting whether we want IME to render composition text. 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetUseCompositionWindow(bool use_composition_window); 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the current input language id. 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LANGID input_language_id() const { return input_language_id_; } 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns BCP-47 tag name of the current input language. 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string GetInputLanguageName() const; 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the text direction of the current input language. 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::i18n::TextDirection GetTextDirection() const; 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 243a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Sets conversion status corresponding to |input_mode|. 244ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch virtual void SetTextInputMode(HWND window_handle, TextInputMode input_mode); 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Helper functions ---------------------------------------------------------- 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks if there is any RTL keyboard layout installed in the system. 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsRTLKeyboardLayoutInstalled(); 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks if the user pressed both Ctrl and right or left Shift keys to 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // requrest to change the text direction and layout alignment explicitly. 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if only a Ctrl key and a Shift key are down. The desired text 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // direction will be stored in |*direction|. 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsCtrlShiftPressed(base::i18n::TextDirection* direction); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 257a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Gets parameters for ::ImmSetOpenStatus and ::ImmSetConversionStatus from 258a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // |input_mode|. 259a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) static void ConvertInputModeToImmFlags(TextInputMode input_mode, 260a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DWORD initial_conversion_mode, 261a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BOOL* open, 262a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DWORD* new_conversion_mode); 263a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 264a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves the composition information. 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetCompositionInfo(HIMC imm_context, LPARAM lparam, 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CompositionText* composition); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the position of the IME windows. 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void MoveImeWindow(HWND window_handle, HIMC imm_context); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Completes the ongoing composition if it exists. 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CompleteComposition(HWND window_handle, HIMC imm_context); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves a string from the IMM. 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetString(HIMC imm_context, WPARAM lparam, int type, string16* result); 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents whether or not there is an ongoing composition in a browser 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // process, i.e. whether or not a browser process is composing a text. 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_composing_; 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This value represents whether or not the current input context has IMEs. 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The following table shows the list of IME status: 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Value Description 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false The current input language does not have IMEs. 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true The current input language has IMEs. 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ime_status_; 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The current input Language ID retrieved from Windows, which consists of: 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * Primary Language ID (bit 0 to bit 9), which shows a natunal language 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (English, Korean, Chinese, Japanese, etc.) and; 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * Sub-Language ID (bit 10 to bit 15), which shows a geometrical region 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the language is spoken (For English, United States, United Kingdom, 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Australia, Canada, etc.) 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The following list enumerates some examples for the Language ID: 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * "en-US" (0x0409) 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * "ko-KR" (0x0412) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * "zh-TW" (0x0404) 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * "zh-CN" (0x0804) 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * "ja-JP" (0x0411) 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // MAKELANGID(LANG_JAPANESE, SUBLANG_JAPANESE_JAPAN), etc. 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (See <winnt.h> for other available values.) 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This Language ID is used for processing language-specific operations in 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IME functions. 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LANGID input_language_id_; 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Represents whether or not the current input context has created a system 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // caret to set the position of its IME candidate window. 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * true: it creates a system caret. 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // * false: it does not create a system caret. 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool system_caret_; 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The rectangle of the input caret retrieved from a renderer process. 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect caret_rect_; 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates whether or not we want IME to render composition text. 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool use_composition_window_; 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3259ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch DISALLOW_COPY_AND_ASSIGN(IMM32Manager); 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ui 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3309ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#endif // UI_BASE_IME_WIN_IMM32_MANAGER_H 331