1 // Copyright (c) 2012 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.
5 #ifndef UI_BASE_IME_INPUT_METHOD_BASE_H_
6 #define UI_BASE_IME_INPUT_METHOD_BASE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "ui/base/ime/input_method.h"
13 #include "ui/base/ime/ui_base_ime_export.h"
21 class InputMethodObserver
;
23 class TextInputClient
;
25 // A helper class providing functionalities shared among ui::InputMethod
27 class UI_BASE_IME_EXPORT InputMethodBase
28 : NON_EXPORTED_BASE(public InputMethod
),
29 public base::SupportsWeakPtr
<InputMethodBase
> {
32 ~InputMethodBase() override
;
34 // Overriden from InputMethod.
35 void SetDelegate(internal::InputMethodDelegate
* delegate
) override
;
36 void Init(bool focused
) override
;
37 // If a derived class overrides OnFocus()/OnBlur(), it should call parent's
38 // implementation first, to make sure |system_toplevel_window_focused_| flag
39 // can be updated correctly.
40 void OnFocus() override
;
41 void OnBlur() override
;
42 void SetFocusedTextInputClient(TextInputClient
* client
) override
;
43 void DetachTextInputClient(TextInputClient
* client
) override
;
44 TextInputClient
* GetTextInputClient() const override
;
46 // If a derived class overrides this method, it should call parent's
48 void OnTextInputTypeChanged(const TextInputClient
* client
) override
;
50 TextInputType
GetTextInputType() const override
;
51 TextInputMode
GetTextInputMode() const override
;
52 int GetTextInputFlags() const override
;
53 bool CanComposeInline() const override
;
54 void ShowImeIfNeeded() override
;
56 void AddObserver(InputMethodObserver
* observer
) override
;
57 void RemoveObserver(InputMethodObserver
* observer
) override
;
60 virtual void OnWillChangeFocusedClient(TextInputClient
* focused_before
,
61 TextInputClient
* focused
) {}
62 virtual void OnDidChangeFocusedClient(TextInputClient
* focused_before
,
63 TextInputClient
* focused
) {}
65 // Returns true if |client| is currently focused.
66 bool IsTextInputClientFocused(const TextInputClient
* client
);
68 // Checks if the focused text input client's text input type is
69 // TEXT_INPUT_TYPE_NONE. Also returns true if there is no focused text
71 bool IsTextInputTypeNone() const;
73 // Convenience method to call the focused text input client's
74 // OnInputMethodChanged() method. It'll only take effect if the current text
75 // input type is not TEXT_INPUT_TYPE_NONE.
76 void OnInputMethodChanged() const;
78 // Convenience method to call delegate_->DispatchKeyEventPostIME().
79 // Returns true if the event was processed
80 bool DispatchKeyEventPostIME(const ui::KeyEvent
& event
) const;
82 // Convenience method to notify all observers of TextInputClient changes.
83 void NotifyTextInputStateChanged(const TextInputClient
* client
);
85 // Convenience method to notify all observers of CaretBounds changes on
86 // |client| which is the text input client with focus.
87 void NotifyTextInputCaretBoundsChanged(const TextInputClient
* client
);
89 // Interface for for signalling candidate window events.
90 // See also *Callback functions below. To avoid reentrancy issue that
91 // TextInputClient manipulates IME state during even handling, these methods
92 // defer sending actual signals to renderer.
93 void OnCandidateWindowShown();
94 void OnCandidateWindowUpdated();
95 void OnCandidateWindowHidden();
97 bool system_toplevel_window_focused() const {
98 return system_toplevel_window_focused_
;
102 void SetFocusedTextInputClientInternal(TextInputClient
* client
);
104 // Deferred callbacks for signalling TextInputClient about candidate window
105 // appearance changes.
106 void CandidateWindowShownCallback();
107 void CandidateWindowUpdatedCallback();
108 void CandidateWindowHiddenCallback();
110 internal::InputMethodDelegate
* delegate_
;
111 TextInputClient
* text_input_client_
;
113 ObserverList
<InputMethodObserver
> observer_list_
;
115 bool system_toplevel_window_focused_
;
117 DISALLOW_COPY_AND_ASSIGN(InputMethodBase
);
122 #endif // UI_BASE_IME_INPUT_METHOD_BASE_H_