Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ui / base / ime / input_method_base.h
blobce3801537d26cd52f28ec2ddeaf4f8d4cbc964f2
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/ui_base_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_EXPORT InputMethodBase
28 : NON_EXPORTED_BASE(public InputMethod),
29 public base::SupportsWeakPtr<InputMethodBase> {
30 public:
31 InputMethodBase();
32 virtual ~InputMethodBase();
34 // Overriden from InputMethod.
35 virtual void SetDelegate(internal::InputMethodDelegate* delegate) OVERRIDE;
36 virtual 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 virtual void OnFocus() OVERRIDE;
41 virtual void OnBlur() OVERRIDE;
42 virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE;
43 virtual void DetachTextInputClient(TextInputClient* client) OVERRIDE;
44 virtual TextInputClient* GetTextInputClient() const OVERRIDE;
46 // If a derived class overrides this method, it should call parent's
47 // implementation.
48 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE;
50 virtual TextInputType GetTextInputType() const OVERRIDE;
51 virtual TextInputMode GetTextInputMode() const OVERRIDE;
52 virtual bool CanComposeInline() const OVERRIDE;
53 virtual void ShowImeIfNeeded() OVERRIDE;
55 virtual void AddObserver(InputMethodObserver* observer) OVERRIDE;
56 virtual 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 // Interface for for signalling candidate window events.
85 // See also *Callback functions below. To avoid reentrancy issue that
86 // TextInputClient manipulates IME state during even handling, these methods
87 // defer sending actual signals to renderer.
88 void OnCandidateWindowShown();
89 void OnCandidateWindowUpdated();
90 void OnCandidateWindowHidden();
92 bool system_toplevel_window_focused() const {
93 return system_toplevel_window_focused_;
96 private:
97 void SetFocusedTextInputClientInternal(TextInputClient* client);
99 // Deferred callbacks for signalling TextInputClient about candidate window
100 // appearance changes.
101 void CandidateWindowShownCallback();
102 void CandidateWindowUpdatedCallback();
103 void CandidateWindowHiddenCallback();
105 internal::InputMethodDelegate* delegate_;
106 TextInputClient* text_input_client_;
108 ObserverList<InputMethodObserver> observer_list_;
110 bool system_toplevel_window_focused_;
112 DISALLOW_COPY_AND_ASSIGN(InputMethodBase);
115 } // namespace ui
117 #endif // UI_BASE_IME_INPUT_METHOD_BASE_H_