Revert of Fix missing GN dependencies. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / ui / base / ime / input_method_base.h
blobd014500717aeb0cf64422d27be277829ff338590
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"
15 namespace gfx {
16 class Rect;
17 } // namespace gfx
19 namespace ui {
21 class InputMethodObserver;
22 class KeyEvent;
23 class TextInputClient;
25 // A helper class providing functionalities shared among ui::InputMethod
26 // implementations.
27 class UI_BASE_IME_EXPORT InputMethodBase
28 : NON_EXPORTED_BASE(public InputMethod),
29 public base::SupportsWeakPtr<InputMethodBase> {
30 public:
31 InputMethodBase();
32 ~InputMethodBase() override;
34 // Overriden from InputMethod.
35 void SetDelegate(internal::InputMethodDelegate* delegate) override;
36 // If a derived class overrides OnFocus()/OnBlur(), it should call parent's
37 // implementation first, to make sure |system_toplevel_window_focused_| flag
38 // can be updated correctly.
39 void OnFocus() override;
40 void OnBlur() override;
41 void SetFocusedTextInputClient(TextInputClient* client) override;
42 void DetachTextInputClient(TextInputClient* client) override;
43 TextInputClient* GetTextInputClient() const override;
45 // If a derived class overrides this method, it should call parent's
46 // implementation.
47 void OnTextInputTypeChanged(const TextInputClient* client) override;
49 TextInputType GetTextInputType() const override;
50 TextInputMode GetTextInputMode() const override;
51 int GetTextInputFlags() const override;
52 bool CanComposeInline() const override;
53 void ShowImeIfNeeded() override;
55 void AddObserver(InputMethodObserver* observer) override;
56 void RemoveObserver(InputMethodObserver* observer) override;
58 protected:
59 virtual void OnWillChangeFocusedClient(TextInputClient* focused_before,
60 TextInputClient* focused) {}
61 virtual void OnDidChangeFocusedClient(TextInputClient* focused_before,
62 TextInputClient* focused) {}
64 // Returns true if |client| is currently focused.
65 bool IsTextInputClientFocused(const TextInputClient* client);
67 // Checks if the focused text input client's text input type is
68 // TEXT_INPUT_TYPE_NONE. Also returns true if there is no focused text
69 // input client.
70 bool IsTextInputTypeNone() const;
72 // Convenience method to call the focused text input client's
73 // OnInputMethodChanged() method. It'll only take effect if the current text
74 // input type is not TEXT_INPUT_TYPE_NONE.
75 void OnInputMethodChanged() const;
77 // Convenience method to call delegate_->DispatchKeyEventPostIME().
78 // Returns true if the event was processed
79 bool DispatchKeyEventPostIME(const ui::KeyEvent& event) const;
81 // Convenience method to notify all observers of TextInputClient changes.
82 void NotifyTextInputStateChanged(const TextInputClient* client);
84 // Convenience method to notify all observers of CaretBounds changes on
85 // |client| which is the text input client with focus.
86 void NotifyTextInputCaretBoundsChanged(const TextInputClient* client);
88 // Interface for for signalling candidate window events.
89 // See also *Callback functions below. To avoid reentrancy issue that
90 // TextInputClient manipulates IME state during even handling, these methods
91 // defer sending actual signals to renderer.
92 void OnCandidateWindowShown();
93 void OnCandidateWindowUpdated();
94 void OnCandidateWindowHidden();
96 bool system_toplevel_window_focused() const {
97 return system_toplevel_window_focused_;
100 private:
101 void SetFocusedTextInputClientInternal(TextInputClient* client);
103 // Deferred callbacks for signalling TextInputClient about candidate window
104 // appearance changes.
105 void CandidateWindowShownCallback();
106 void CandidateWindowUpdatedCallback();
107 void CandidateWindowHiddenCallback();
109 internal::InputMethodDelegate* delegate_;
110 TextInputClient* text_input_client_;
112 ObserverList<InputMethodObserver> observer_list_;
114 bool system_toplevel_window_focused_;
116 DISALLOW_COPY_AND_ASSIGN(InputMethodBase);
119 } // namespace ui
121 #endif // UI_BASE_IME_INPUT_METHOD_BASE_H_