Update V8 to version 4.7.45.
[chromium-blink-merge.git] / ui / base / ime / input_method_base.h
blob345683906be6c2e56844f23dbb0a99dc75f902ce
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/ime/ui_base_ime_export.h"
14 #include "ui/events/event_dispatcher.h"
16 namespace gfx {
17 class Rect;
18 } // namespace gfx
20 namespace ui {
22 class InputMethodObserver;
23 class KeyEvent;
24 class TextInputClient;
26 // A helper class providing functionalities shared among ui::InputMethod
27 // implementations.
28 class UI_BASE_IME_EXPORT InputMethodBase
29 : NON_EXPORTED_BASE(public InputMethod),
30 public base::SupportsWeakPtr<InputMethodBase> {
31 public:
32 InputMethodBase();
33 ~InputMethodBase() override;
35 // Overriden from InputMethod.
36 void SetDelegate(internal::InputMethodDelegate* delegate) 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 void OnFocus() override;
41 void OnBlur() override;
42 void SetFocusedTextInputClient(TextInputClient* client) override;
43 void DetachTextInputClient(TextInputClient* client) override;
44 TextInputClient* GetTextInputClient() const override;
46 // If a derived class overrides this method, it should call parent's
47 // implementation.
48 void OnTextInputTypeChanged(const TextInputClient* client) override;
50 TextInputType GetTextInputType() const override;
51 TextInputMode GetTextInputMode() const override;
52 int GetTextInputFlags() const override;
53 bool CanComposeInline() const override;
54 void ShowImeIfNeeded() override;
56 void AddObserver(InputMethodObserver* observer) override;
57 void RemoveObserver(InputMethodObserver* observer) override;
59 protected:
60 virtual void OnWillChangeFocusedClient(TextInputClient* focused_before,
61 TextInputClient* focused) {}
62 virtual void OnDidChangeFocusedClient(TextInputClient* focused_before,
63 TextInputClient* focused) {}
65 // Returns true if |client| is currently focused.
66 bool IsTextInputClientFocused(const TextInputClient* client);
68 // Checks if the focused text input client's text input type is
69 // TEXT_INPUT_TYPE_NONE. Also returns true if there is no focused text
70 // input client.
71 bool IsTextInputTypeNone() const;
73 // Convenience method to call the focused text input client's
74 // OnInputMethodChanged() method. It'll only take effect if the current text
75 // input type is not TEXT_INPUT_TYPE_NONE.
76 void OnInputMethodChanged() const;
78 // Convenience method to call delegate_->DispatchKeyEventPostIME().
79 // Returns true if the event was processed
80 ui::EventDispatchDetails DispatchKeyEventPostIME(
81 ui::KeyEvent* event) const;
83 // Convenience method to notify all observers of TextInputClient changes.
84 void NotifyTextInputStateChanged(const TextInputClient* client);
86 // Convenience method to notify all observers of CaretBounds changes on
87 // |client| which is the text input client with focus.
88 void NotifyTextInputCaretBoundsChanged(const TextInputClient* client);
90 bool system_toplevel_window_focused() const {
91 return system_toplevel_window_focused_;
94 private:
95 void SetFocusedTextInputClientInternal(TextInputClient* client);
97 internal::InputMethodDelegate* delegate_;
98 TextInputClient* text_input_client_;
100 base::ObserverList<InputMethodObserver> observer_list_;
102 bool system_toplevel_window_focused_;
104 DISALLOW_COPY_AND_ASSIGN(InputMethodBase);
107 } // namespace ui
109 #endif // UI_BASE_IME_INPUT_METHOD_BASE_H_