15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 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) 5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#ifndef CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ 6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#define CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "chromeos/chromeos_export.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chromeos/ime/input_method_descriptor.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chromeos/ime/input_method_property.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Accelerator; 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ui 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos { 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class ComponentExtensionIMEManager; 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class InputMethodEngineInterface; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace input_method { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class InputMethodUtil; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class XKeyboard; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class manages input methodshandles. Classes can add themselves as 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// observers. Clients can get an instance of this library class by: 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// InputMethodManager::Get(). 32b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class CHROMEOS_EXPORT InputMethodManager { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum State { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_LOGIN_SCREEN = 0, 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_BROWSER_SCREEN, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_LOCK_SCREEN, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_TERMINATING, 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class Observer { 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Observer() {} 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the current input method is changed. |show_message| 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // indicates whether the user should be notified of this change. 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void InputMethodChanged(InputMethodManager* manager, 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool show_message) = 0; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the list of properties is changed. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void InputMethodPropertyChanged(InputMethodManager* manager) = 0; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // CandidateWindowObserver is notified of events related to the candidate 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // window. The "suggestion window" used by IMEs such as ibus-mozc does not 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // count as the candidate window (this may change if we later want suggestion 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // window events as well). These events also won't occur when the virtual 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // keyboard is used, since it controls its own candidate window. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class CandidateWindowObserver { 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~CandidateWindowObserver() {} 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the candidate window is opened. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void CandidateWindowOpened(InputMethodManager* manager) = 0; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the candidate window is closed. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void CandidateWindowClosed(InputMethodManager* manager) = 0; 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~InputMethodManager() {} 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 68b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Gets the global instance of InputMethodManager. Initialize() must be called 69b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // first. 70b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static CHROMEOS_EXPORT InputMethodManager* Get(); 71b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 72b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Sets the global instance. |instance| will be owned by the internal pointer 73b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // and deleted by Shutdown(). 74b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // TODO(nona): Instanciate InputMethodManagerImpl inside of this function once 75b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // crbug.com/164375 is fixed. 76b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static CHROMEOS_EXPORT void Initialize(InputMethodManager* instance); 77b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 78b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Destroy the global instance. 79b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static CHROMEOS_EXPORT void Shutdown(); 80b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds an observer to receive notifications of input method related 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // changes as desribed in the Observer class above. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AddObserver(Observer* observer) = 0; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AddCandidateWindowObserver( 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CandidateWindowObserver* observer) = 0; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RemoveObserver(Observer* observer) = 0; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RemoveCandidateWindowObserver( 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CandidateWindowObserver* observer) = 0; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns all input methods that are supported, including ones not active. 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This function never returns NULL. Note that input method extensions are NOT 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // included in the result. 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual scoped_ptr<InputMethodDescriptors> 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetSupportedInputMethods() const = 0; 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the list of input methods we can select (i.e. active) including 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // extension input methods. 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual scoped_ptr<InputMethodDescriptors> GetActiveInputMethods() const = 0; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 100a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // Returns the list of input methods we can select (i.e. active) including 101a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // extension input methods. 102a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // The same as GetActiveInputMethods but returns reference to internal list. 103a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch virtual const std::vector<std::string>& GetActiveInputMethodIds() const = 0; 104a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the number of active input methods including extension input 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // methods. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual size_t GetNumActiveInputMethods() const = 0; 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Changes the current input method to |input_method_id|. If |input_method_id| 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is not active, switch to the first one in the active input method list. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ChangeInputMethod(const std::string& input_method_id) = 0; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Enables keyboard layouts (e.g. US Qwerty, US Dvorak, French Azerty) that 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // are necessary for the |language_code| and then switches to |initial_layout| 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if the string is not empty. For example, if |language_code| is "en-US", US 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Qwerty, US International, US Extended, US Dvorak, and US Colemak layouts 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // would be enabled. Likewise, for Germany locale, US Qwerty which corresponds 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to the hardware keyboard layout and several keyboard layouts for Germany 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // would be enabled. 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is for setting up i18n keyboard layouts for the login screen. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void EnableLayouts(const std::string& language_code, 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& initial_layout) = 0; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Activates the input method property specified by the |key|. 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ActivateInputMethodProperty(const std::string& key) = 0; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the list of active input method IDs, and then starts or stops the 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // system input method framework as needed. 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool EnableInputMethods( 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::vector<std::string>& new_active_input_method_ids) = 0; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 132a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // Adds one entry to the list of active input method IDs, and then starts or 133a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // stops the system input method framework as needed. 134a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch virtual bool EnableInputMethod( 135a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch const std::string& new_active_input_method_id) = 0; 136a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds an input method extension. This function does not takes ownership of 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |instance|. 1397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void AddInputMethodExtension( 1407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::string& id, 1417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::string& name, 1427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::vector<std::string>& layouts, 1437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const std::vector<std::string>& languages, 1447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const GURL& options_url, 145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const GURL& inputview_url, 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) InputMethodEngineInterface* instance) = 0; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes an input method extension. 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RemoveInputMethodExtension(const std::string& id) = 0; 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a list of descriptors for all Input Method Extensions. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0; 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 154b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Sets the list of extension IME ids which should be enabled. 155b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) = 0; 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 157424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Sets current input method to default (first owners, then hardware). 158424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void SetInputMethodDefault() = 0; 159424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets the descriptor of the input method which is currently selected. 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual InputMethodDescriptor GetCurrentInputMethod() const = 0; 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets the list of input method properties. The list could be empty(). 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual InputMethodPropertyList GetCurrentInputMethodProperties() const = 0; 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 166f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Sets the list of input method properties. The list could be empty(). 167f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void SetCurrentInputMethodProperties( 168f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const InputMethodPropertyList& property_list) = 0; 169f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns an X keyboard object which could be used to change the current XKB 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // layout, change the caps lock status, and set the auto repeat rate/interval. 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual XKeyboard* GetXKeyboard() = 0; 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns an InputMethodUtil object. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual InputMethodUtil* GetInputMethodUtil() = 0; 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Returns a ComponentExtentionIMEManager object. 178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() = 0; 179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Switches the current input method (or keyboard layout) to the next one. 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool SwitchToNextInputMethod() = 0; 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Switches the current input method (or keyboard layout) to the previous one. 184a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch virtual bool SwitchToPreviousInputMethod( 185a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch const ui::Accelerator& accelerator) = 0; 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Switches to an input method (or keyboard layout) which is associated with 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the |accelerator|. 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) = 0; 190a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch 191a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch // If keyboard layout can be uset at login screen 192424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual bool IsLoginKeyboard(const std::string& layout) const = 0; 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace input_method 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace chromeos 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif // CHROMEOS_IME_INPUT_METHOD_MANAGER_H_ 199