• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Embedded Framework Authors. Portions copyright
2 // 2013 The Chromium Authors. All rights reserved. Use of this source code is
3 // governed by a BSD-style license that can be found in the LICENSE file.
4 
5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_OSR_IME_HANDLER_WIN_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_OSR_IME_HANDLER_WIN_H_
7 #pragma once
8 
9 #include <windows.h>
10 #include <vector>
11 
12 #include "include/internal/cef_types_wrappers.h"
13 
14 namespace client {
15 
16 // Handles IME for the native parent window that hosts an off-screen browser.
17 // This object is only accessed on the CEF UI thread.
18 class OsrImeHandlerWin {
19  public:
20   explicit OsrImeHandlerWin(HWND hwnd);
21   virtual ~OsrImeHandlerWin();
22 
23   // Retrieves whether or not there is an ongoing composition.
is_composing()24   bool is_composing() const { return is_composing_; }
25 
26   // Retrieves the input language from Windows and update it.
27   void SetInputLanguage();
28 
29   // Creates the IME caret windows if required.
30   void CreateImeWindow();
31 
32   // Destroys the IME caret windows.
33   void DestroyImeWindow();
34 
35   // Cleans up the all resources attached to the given IMM32Manager object, and
36   // reset its composition status.
37   void CleanupComposition();
38 
39   // Resets the composition status and cancels the ongoing composition.
40   void ResetComposition();
41 
42   // Retrieves a composition result of the ongoing composition if it exists.
43   bool GetResult(LPARAM lparam, CefString& result);
44 
45   // Retrieves the current composition status of the ongoing composition.
46   // Includes composition text, underline information and selection range in the
47   // composition text. IMM32 does not support char selection.
48   bool GetComposition(LPARAM lparam,
49                       CefString& composition_text,
50                       std::vector<CefCompositionUnderline>& underlines,
51                       int& composition_start);
52 
53   // Enables the IME attached to the given window.
54   virtual void EnableIME();
55 
56   // Disables the IME attached to the given window.
57   virtual void DisableIME();
58 
59   // Cancels an ongoing composition of the IME.
60   virtual void CancelIME();
61 
62   // Updates the IME caret position of the given window.
63   void UpdateCaretPosition(int index);
64 
65   // Updates the composition range. |selected_range| is the range of characters
66   // that have been selected. |character_bounds| is the bounds of each character
67   // in view device coordinates.
68   void ChangeCompositionRange(const CefRange& selection_range,
69                               const std::vector<CefRect>& character_bounds);
70 
71   // Updates the position of the IME windows.
72   void MoveImeWindow();
73 
74  private:
75   // Retrieves the composition information.
76   void GetCompositionInfo(HIMC imm_context,
77                           LPARAM lparam,
78                           CefString& composition_text,
79                           std::vector<CefCompositionUnderline>& underlines,
80                           int& composition_start);
81 
82   // Retrieves a string from the IMM.
83   bool GetString(HIMC imm_context, WPARAM lparam, int type, CefString& result);
84 
85   // Represents whether or not there is an ongoing composition.
86   bool is_composing_;
87 
88   // The current composition character range and its bounds.
89   std::vector<CefRect> composition_bounds_;
90 
91   // The current input Language ID retrieved from Windows -
92   // used for processing language-specific operations in IME.
93   LANGID input_language_id_;
94 
95   // Represents whether or not the current input context has created a system
96   // caret to set the position of its IME candidate window.
97   bool system_caret_;
98 
99   // The rectangle of the input caret retrieved from a renderer process.
100   CefRect ime_rect_;
101 
102   // The current cursor index in composition string.
103   int cursor_index_;
104 
105   // The composition range in the string. This may be used to determine the
106   // offset in composition bounds.
107   CefRange composition_range_;
108 
109   // Hwnd associated with this instance.
110   HWND hwnd_;
111 };
112 
113 }  // namespace client
114 
115 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_OSR_IME_HANDLER_WIN_H_
116