• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium 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 UI_BASE_IME_REMOTE_INPUT_METHOD_WIN_H_
6 #define UI_BASE_IME_REMOTE_INPUT_METHOD_WIN_H_
7 
8 #include <Windows.h>
9 
10 #include <string>
11 
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "ui/base/ui_export.h"
17 #include "ui/gfx/native_widget_types.h"
18 
19 namespace ui {
20 namespace internal {
21 class InputMethodDelegate;
22 class RemoteInputMethodDelegateWin;
23 }  // namespace internal
24 
25 class InputMethod;
26 struct CompositionText;
27 
28 // RemoteInputMethodWin is a special implementation of ui::InputMethod that
29 // works as a proxy of an IME handler running in the metro_driver process.
30 // RemoteInputMethodWin works as follows.
31 // - Any action to RemoteInputMethodWin should be delegated to the
32 //   metro_driver process via RemoteInputMethodDelegateWin.
33 // - Data retrieval from RemoteInputMethodPrivateWin is implemented with
34 //   data cache. Whenever the IME state in the metro_driver process is changed,
35 //   RemoteRootWindowHostWin, which receives IPCs from metro_driver process,
36 //   will call RemoteInputMethodPrivateWin::OnCandidatePopupChanged and/or
37 //   RemoteInputMethodPrivateWin::OnInputSourceChanged accordingly so that
38 //   the state cache should be updated.
39 // - Some IPC messages that represent actions to TextInputClient should be
40 //   delegated to RemoteInputMethodPrivateWin so that RemoteInputMethodWin can
41 //   work as a real proxy.
42 
43 // Returns true if |widget| requires RemoteInputMethodWin.
44 bool IsRemoteInputMethodWinRequired(gfx::AcceleratedWidget widget);
45 
46 // Returns the public interface of RemoteInputMethodWin.
47 // Caveats: Currently only one instance of RemoteInputMethodWin is able to run
48 // at the same time.
49 UI_EXPORT scoped_ptr<InputMethod> CreateRemoteInputMethodWin(
50     internal::InputMethodDelegate* delegate);
51 
52 // Private interface of RemoteInputMethodWin.
53 class UI_EXPORT RemoteInputMethodPrivateWin {
54  public:
55   RemoteInputMethodPrivateWin();
56 
57   // Returns the private interface of RemoteInputMethodWin when and only when
58   // |input_method| is instanciated via CreateRemoteInputMethodWin. Caller does
59   // not take the ownership of the returned object.
60   // As you might notice, this is yet another reinplementation of dynamic_cast
61   // or IUnknown::QueryInterface.
62   static RemoteInputMethodPrivateWin* Get(InputMethod* input_method);
63 
64   // Installs RemoteInputMethodDelegateWin delegate. Set NULL to |delegate| to
65   // unregister.
66   virtual void SetRemoteDelegate(
67       internal::RemoteInputMethodDelegateWin* delegate) = 0;
68 
69   // Updates internal cache so that subsequent calls of
70   // RemoteInputMethodWin::IsCandidatePopupOpen can return the correct value
71   // based on remote IME activities in the metro_driver process.
72   virtual void OnCandidatePopupChanged(bool visible) = 0;
73 
74   // Updates internal cache so that subsequent calls of
75   // RemoteInputMethodWin::GetInputLocale and
76   // RemoteInputMethodWin::GetInputTextDirection can return the correct
77   // values based on remote IME activities in the metro_driver process.
78   virtual void OnInputSourceChanged(LANGID langid, bool is_ime) = 0;
79 
80   // Handles composition-update events occurred in the metro_driver process.
81   // Caveats: This method is designed to be used only with
82   // metro_driver::TextService. In other words, there is no garantee that this
83   // method works a wrapper to call ui::TextInputClient::SetCompositionText.
84   virtual void OnCompositionChanged(
85       const CompositionText& composition_text) = 0;
86 
87   // Handles text-commit events occurred in the metro_driver process.
88   // Caveats: This method is designed to be used only with
89   // metro_driver::TextService. In other words, there is no garantee that this
90   // method works a wrapper to call ui::TextInputClient::InsertText. In fact,
91   // this method may call ui::TextInputClient::InsertChar when the text input
92   // type of the focused text input client is TEXT_INPUT_TYPE_NONE.
93   virtual void OnTextCommitted(const base::string16& text) = 0;
94 
95  private:
96   DISALLOW_COPY_AND_ASSIGN(RemoteInputMethodPrivateWin);
97 };
98 
99 }  // namespace ui
100 
101 #endif  // UI_BASE_IME_REMOTE_INPUT_METHOD_WIN_H_
102