OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 VIEWS_IME_INPUT_METHOD_BASE_H_ | |
6 #define VIEWS_IME_INPUT_METHOD_BASE_H_ | |
7 #pragma once | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/compiler_specific.h" | |
11 #include "views/focus/focus_manager.h" | |
12 #include "views/ime/input_method.h" | |
13 #include "views/ime/input_method_delegate.h" | |
14 #include "views/ime/text_input_client.h" | |
15 | |
16 namespace views { | |
17 | |
18 class View; | |
19 | |
20 // A helper class providing functionalities shared among InputMethod | |
21 // implementations. | |
22 class InputMethodBase : public InputMethod, | |
23 public FocusChangeListener { | |
24 public: | |
25 InputMethodBase(); | |
26 virtual ~InputMethodBase(); | |
27 | |
28 // Overriden from InputMethod. | |
29 virtual void set_delegate(internal::InputMethodDelegate* delegate) OVERRIDE; | |
30 | |
31 // If a derived class overrides this method, it should call parent's | |
32 // implementation first. | |
33 virtual void Init(Widget* widget) OVERRIDE; | |
34 | |
35 // Overridden from FocusChangeListener. Derived classes shouldn't override | |
36 // this method. Override FocusedViewWillChange() and FocusedViewDidChange() | |
37 // instead. | |
38 virtual void FocusWillChange(View* focused_before, View* focused) OVERRIDE; | |
39 | |
40 protected: | |
41 // Getters and setters of properties. | |
42 internal::InputMethodDelegate* delegate() const { return delegate_; } | |
43 Widget* widget() const { return widget_; } | |
44 View* focused_view() const { return focused_view_; } | |
45 | |
46 // Derived classes should call this method to update Widget's focus state when | |
47 // the Widget gets or loses keyboard focus. | |
48 void set_widget_focused(bool focused) { widget_focused_ = focused; } | |
49 bool widget_focused() const { return widget_focused_; } | |
50 | |
51 // Checks if the given View is focused. Returns true only if the View and | |
52 // the Widget are both focused. | |
53 bool IsViewFocused(View* view) const; | |
54 | |
55 // Gets the focused text input client. Returns NULL if the Widget is not | |
56 // focused, or there is no focused View or the focused View doesn't support | |
57 // text input. | |
58 TextInputClient* GetTextInputClient() const; | |
59 | |
60 // Gets the text input type of the focused text input client. Returns | |
61 // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client. | |
62 ui::TextInputType GetTextInputType() const; | |
63 | |
64 // Check is the focused text input client supports text input, i.e. if its | |
oshima
2011/03/22 22:35:51
Check if
James Su
2011/03/22 23:08:47
Done.
| |
65 // text input type is not ui::TEXT_INPUT_TYPE_NONE. | |
66 bool IsClientSupportTextInput() const; | |
oshima
2011/03/22 22:35:51
IfClientSupports..,DoesClientSupports.. ? don't ha
James Su
2011/03/22 23:08:47
I renamed it to IsTextInputTypeNone() (the behavio
| |
67 | |
68 // Convenience method to call the focused text input client's | |
69 // OnInputMethodChanged() method. It'll only take effect if the current text | |
70 // input type is not ui::TEXT_INPUT_TYPE_NONE. | |
71 void OnInputMethodChanged() const; | |
72 | |
73 // Convenience method to call delegate_->DispatchKeyEventPostIME(). | |
74 void DispatchKeyEventPostIME(const KeyEvent& key) const; | |
75 | |
76 // Gets the current text input client's caret bounds in Widget's coordinates. | |
77 // Returns false if the current text input client doesn't support text input. | |
78 bool GetCaretBoundsInWidget(gfx::Rect* rect) const; | |
79 | |
80 // Called just before changing the focused view. Should be overridden by | |
81 // derived classes. The default implementation does nothing. | |
82 virtual void FocusedViewWillChange(); | |
83 | |
84 // Called just after changing the focused view. Should be overridden by | |
85 // derived classes. The default implementation does nothing. | |
86 // Note: It's called just after changing the value of |focused_view_|. As it's | |
87 // called inside FocusChangeListener's FocusWillChange() method, which is | |
88 // called by the FocusManager before actually changing the focus, the derived | |
89 // class should not rely on the actual focus state of the |focused_view_|. | |
90 virtual void FocusedViewDidChange(); | |
91 | |
92 private: | |
93 internal::InputMethodDelegate* delegate_; | |
94 Widget* widget_; | |
95 View* focused_view_; | |
96 | |
97 // Indicates if the top-level widget is focused or not. | |
98 bool widget_focused_; | |
99 | |
100 DISALLOW_COPY_AND_ASSIGN(InputMethodBase); | |
101 }; | |
102 | |
103 } // namespace views | |
104 | |
105 #endif // VIEWS_IME_INPUT_METHOD_BASE_H_ | |
OLD | NEW |