Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ui / base / ime / input_method_chromeos.h
bloba67a2447d8fedb06e66e026a2e1a01ea5ed906ef
1 // Copyright 2014 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_CHROMEOS_H_
6 #define UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_
8 #include <set>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "ui/base/ime/chromeos/character_composer.h"
16 #include "ui/base/ime/chromeos/ime_bridge.h"
17 #include "ui/base/ime/composition_text.h"
18 #include "ui/base/ime/input_method_base.h"
20 namespace ui {
22 // A ui::InputMethod implementation based on IBus.
23 class UI_BASE_EXPORT InputMethodChromeOS
24 : public InputMethodBase,
25 public chromeos::IMEInputContextHandlerInterface {
26 public:
27 explicit InputMethodChromeOS(internal::InputMethodDelegate* delegate);
28 virtual ~InputMethodChromeOS();
30 // Overridden from InputMethod:
31 virtual void OnFocus() OVERRIDE;
32 virtual void OnBlur() OVERRIDE;
33 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
34 NativeEventResult* result) OVERRIDE;
35 virtual bool DispatchKeyEvent(const ui::KeyEvent& event) OVERRIDE;
36 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE;
37 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE;
38 virtual void CancelComposition(const TextInputClient* client) OVERRIDE;
39 virtual void OnInputLocaleChanged() OVERRIDE;
40 virtual std::string GetInputLocale() OVERRIDE;
41 virtual bool IsActive() OVERRIDE;
42 virtual bool IsCandidatePopupOpen() const OVERRIDE;
44 protected:
45 // Converts |text| into CompositionText.
46 void ExtractCompositionText(const chromeos::CompositionText& text,
47 uint32 cursor_position,
48 CompositionText* out_composition) const;
50 // Process a key returned from the input method.
51 virtual void ProcessKeyEventPostIME(const ui::KeyEvent& event,
52 bool handled);
54 // Resets context and abandon all pending results and key events.
55 void ResetContext();
57 private:
58 class PendingKeyEvent;
60 // Overridden from InputMethodBase:
61 virtual void OnWillChangeFocusedClient(TextInputClient* focused_before,
62 TextInputClient* focused) OVERRIDE;
63 virtual void OnDidChangeFocusedClient(TextInputClient* focused_before,
64 TextInputClient* focused) OVERRIDE;
66 // Asks the client to confirm current composition text.
67 void ConfirmCompositionText();
69 // Checks the availability of focused text input client and update focus
70 // state.
71 void UpdateContextFocusState();
73 // Processes a key event that was already filtered by the input method.
74 // A VKEY_PROCESSKEY may be dispatched to the focused View.
75 void ProcessFilteredKeyPressEvent(const ui::KeyEvent& event);
77 // Processes a key event that was not filtered by the input method.
78 void ProcessUnfilteredKeyPressEvent(const ui::KeyEvent& event);
80 // Sends input method result caused by the given key event to the focused text
81 // input client.
82 void ProcessInputMethodResult(const ui::KeyEvent& event, bool filtered);
84 // Checks if the pending input method result needs inserting into the focused
85 // text input client as a single character.
86 bool NeedInsertChar() const;
88 // Checks if there is pending input method result.
89 bool HasInputMethodResult() const;
91 // Abandons all pending key events. It usually happends when we lose keyboard
92 // focus, the text input type is changed or we are destroyed.
93 void AbandonAllPendingKeyEvents();
95 // Passes keyevent and executes character composition if necessary. Returns
96 // true if character composer comsumes key event.
97 bool ExecuteCharacterComposer(const ui::KeyEvent& event);
99 // chromeos::IMEInputContextHandlerInterface overrides:
100 virtual void CommitText(const std::string& text) OVERRIDE;
101 virtual void UpdateCompositionText(const chromeos::CompositionText& text,
102 uint32 cursor_pos,
103 bool visible) OVERRIDE;
104 virtual void DeleteSurroundingText(int32 offset, uint32 length) OVERRIDE;
106 // Hides the composition text.
107 void HidePreeditText();
109 // Callback function for IMEEngineHandlerInterface::ProcessKeyEvent.
110 void ProcessKeyEventDone(uint32 id, ui::KeyEvent* event, bool is_handled);
112 // Returns whether an input field is focused. Note that password field is not
113 // considered as an input field.
114 bool IsInputFieldFocused();
116 // All pending key events. Note: we do not own these object, we just save
117 // pointers to these object so that we can abandon them when necessary.
118 // They will be deleted in ProcessKeyEventDone().
119 std::set<uint32> pending_key_events_;
121 // Pending composition text generated by the current pending key event.
122 // It'll be sent to the focused text input client as soon as we receive the
123 // processing result of the pending key event.
124 CompositionText composition_;
126 // Pending result text generated by the current pending key event.
127 // It'll be sent to the focused text input client as soon as we receive the
128 // processing result of the pending key event.
129 base::string16 result_text_;
131 base::string16 previous_surrounding_text_;
132 gfx::Range previous_selection_range_;
134 // Indicates if there is an ongoing composition text.
135 bool composing_text_;
137 // Indicates if the composition text is changed or deleted.
138 bool composition_changed_;
140 // The latest id of key event.
141 uint32 current_keyevent_id_;
143 // An object to compose a character from a sequence of key presses
144 // including dead key etc.
145 CharacterComposer character_composer_;
147 TextInputType previous_textinput_type_;
149 // Used for making callbacks.
150 base::WeakPtrFactory<InputMethodChromeOS> weak_ptr_factory_;
152 DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOS);
155 } // namespace ui
157 #endif // UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_