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_VIEWS_IME_INPUT_METHOD_BRIDGE_H_
6 #define UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "ui/base/ime/text_input_client.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/views/ime/input_method_base.h"
24 // A "bridge" InputMethod implementation for views top-level widgets, which just
25 // sends/receives IME related events to/from a system-wide ui::InputMethod
27 class InputMethodBridge
: public InputMethodBase
,
28 public ui::TextInputClient
{
30 // |shared_input_method| indicates if |host| is shared among other top level
32 InputMethodBridge(internal::InputMethodDelegate
* delegate
,
33 ui::InputMethod
* host
,
34 bool shared_input_method
);
35 virtual ~InputMethodBridge();
37 // Overridden from InputMethod:
38 virtual void OnFocus() OVERRIDE
;
39 virtual void OnBlur() OVERRIDE
;
40 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent
& event
,
41 NativeEventResult
* result
) OVERRIDE
;
42 virtual void DispatchKeyEvent(const ui::KeyEvent
& key
) OVERRIDE
;
43 virtual void OnTextInputTypeChanged(View
* view
) OVERRIDE
;
44 virtual void OnCaretBoundsChanged(View
* view
) OVERRIDE
;
45 virtual void CancelComposition(View
* view
) OVERRIDE
;
46 virtual void OnInputLocaleChanged() OVERRIDE
;
47 virtual std::string
GetInputLocale() OVERRIDE
;
48 virtual bool IsActive() OVERRIDE
;
49 virtual bool IsCandidatePopupOpen() const OVERRIDE
;
50 virtual void ShowImeIfNeeded() OVERRIDE
;
52 // Overridden from TextInputClient:
53 virtual void SetCompositionText(
54 const ui::CompositionText
& composition
) OVERRIDE
;
55 virtual void ConfirmCompositionText() OVERRIDE
;
56 virtual void ClearCompositionText() OVERRIDE
;
57 virtual void InsertText(const base::string16
& text
) OVERRIDE
;
58 virtual void InsertChar(base::char16 ch
, int flags
) OVERRIDE
;
59 virtual gfx::NativeWindow
GetAttachedWindow() const OVERRIDE
;
60 virtual ui::TextInputType
GetTextInputType() const OVERRIDE
;
61 virtual ui::TextInputMode
GetTextInputMode() const OVERRIDE
;
62 virtual bool CanComposeInline() const OVERRIDE
;
63 virtual gfx::Rect
GetCaretBounds() const OVERRIDE
;
64 virtual bool GetCompositionCharacterBounds(uint32 index
,
65 gfx::Rect
* rect
) const OVERRIDE
;
66 virtual bool HasCompositionText() const OVERRIDE
;
67 virtual bool GetTextRange(gfx::Range
* range
) const OVERRIDE
;
68 virtual bool GetCompositionTextRange(gfx::Range
* range
) const OVERRIDE
;
69 virtual bool GetSelectionRange(gfx::Range
* range
) const OVERRIDE
;
70 virtual bool SetSelectionRange(const gfx::Range
& range
) OVERRIDE
;
71 virtual bool DeleteRange(const gfx::Range
& range
) OVERRIDE
;
72 virtual bool GetTextFromRange(const gfx::Range
& range
,
73 base::string16
* text
) const OVERRIDE
;
74 virtual void OnInputMethodChanged() OVERRIDE
;
75 virtual bool ChangeTextDirectionAndLayoutAlignment(
76 base::i18n::TextDirection direction
) OVERRIDE
;
77 virtual void ExtendSelectionAndDelete(size_t before
, size_t after
) OVERRIDE
;
78 virtual void EnsureCaretInRect(const gfx::Rect
& rect
) OVERRIDE
;
79 virtual void OnCandidateWindowShown() OVERRIDE
;
80 virtual void OnCandidateWindowUpdated() OVERRIDE
;
81 virtual void OnCandidateWindowHidden() OVERRIDE
;
82 virtual bool IsEditingCommandEnabled(int command_id
) OVERRIDE
;
83 virtual void ExecuteEditingCommand(int command_id
) OVERRIDE
;
85 // Overridden from FocusChangeListener.
86 virtual void OnWillChangeFocus(View
* focused_before
, View
* focused
) OVERRIDE
;
87 virtual void OnDidChangeFocus(View
* focused_before
, View
* focused
) OVERRIDE
;
89 ui::InputMethod
* GetHostInputMethod() const;
94 void UpdateViewFocusState();
96 ui::InputMethod
* host_
;
98 // An observer observing the host input method for cases that the host input
99 // method is destroyed before this bridge input method.
100 scoped_ptr
<HostObserver
> host_observer_
;
102 const bool shared_input_method_
;
104 DISALLOW_COPY_AND_ASSIGN(InputMethodBridge
);
109 #endif // UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_