- add sources.
[platform/framework/web/crosswalk.git] / src / ui / views / ime / input_method_bridge.h
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.
4
5 #ifndef UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_
6 #define UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_
7
8 #include <string>
9
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"
15
16 namespace ui {
17 class InputMethod;
18 }  // namespace ui
19
20 namespace views {
21
22 class View;
23
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();
36
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 base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
49   virtual bool IsActive() OVERRIDE;
50   virtual bool IsCandidatePopupOpen() const OVERRIDE;
51
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 string16& text) OVERRIDE;
58   virtual void InsertChar(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                                 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
80   // Overridden from FocusChangeListener.
81   virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE;
82   virtual void OnDidChangeFocus(View* focused_before, View* focused) OVERRIDE;
83
84   ui::InputMethod* GetHostInputMethod() const;
85
86  private:
87   void UpdateViewFocusState();
88
89   ui::InputMethod* const host_;
90
91   const bool shared_input_method_;
92
93   DISALLOW_COPY_AND_ASSIGN(InputMethodBridge);
94 };
95
96 }  // namespace views
97
98 #endif  // UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_