Add include.
[chromium-blink-merge.git] / ui / views / ime / input_method_bridge.h
blob8813e87b947c0236cfeb24965c8c1ef5f84d7939
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_
8 #include <string>
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"
16 namespace ui {
17 class InputMethod;
18 } // namespace ui
20 namespace views {
22 class View;
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
26 // object.
27 class InputMethodBridge : public InputMethodBase,
28 public ui::TextInputClient {
29 public:
30 // |shared_input_method| indicates if |host| is shared among other top level
31 // widgets.
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 int GetTextInputFlags() const override;
63 virtual bool CanComposeInline() const override;
64 virtual gfx::Rect GetCaretBounds() const override;
65 virtual bool GetCompositionCharacterBounds(uint32 index,
66 gfx::Rect* rect) const override;
67 virtual bool HasCompositionText() const override;
68 virtual bool GetTextRange(gfx::Range* range) const override;
69 virtual bool GetCompositionTextRange(gfx::Range* range) const override;
70 virtual bool GetSelectionRange(gfx::Range* range) const override;
71 virtual bool SetSelectionRange(const gfx::Range& range) override;
72 virtual bool DeleteRange(const gfx::Range& range) override;
73 virtual bool GetTextFromRange(const gfx::Range& range,
74 base::string16* text) const override;
75 virtual void OnInputMethodChanged() override;
76 virtual bool ChangeTextDirectionAndLayoutAlignment(
77 base::i18n::TextDirection direction) override;
78 virtual void ExtendSelectionAndDelete(size_t before, size_t after) override;
79 virtual void EnsureCaretInRect(const gfx::Rect& rect) override;
80 virtual void OnCandidateWindowShown() override;
81 virtual void OnCandidateWindowUpdated() override;
82 virtual void OnCandidateWindowHidden() override;
83 virtual bool IsEditingCommandEnabled(int command_id) override;
84 virtual void ExecuteEditingCommand(int command_id) override;
86 // Overridden from FocusChangeListener.
87 virtual void OnWillChangeFocus(View* focused_before, View* focused) override;
88 virtual void OnDidChangeFocus(View* focused_before, View* focused) override;
90 ui::InputMethod* GetHostInputMethod() const;
92 private:
93 class HostObserver;
95 void UpdateViewFocusState();
97 ui::InputMethod* host_;
99 // An observer observing the host input method for cases that the host input
100 // method is destroyed before this bridge input method.
101 scoped_ptr<HostObserver> host_observer_;
103 const bool shared_input_method_;
105 DISALLOW_COPY_AND_ASSIGN(InputMethodBridge);
108 } // namespace views
110 #endif // UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_