blob: 58e4a76d0e538bd29de43abbb581238332a7dec4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef VIEWS_IME_INPUT_METHOD_BASE_H_
#define VIEWS_IME_INPUT_METHOD_BASE_H_
#pragma once
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "views/focus/focus_manager.h"
#include "views/ime/input_method.h"
#include "views/ime/input_method_delegate.h"
#include "views/ime/text_input_client.h"
namespace views {
class View;
// A helper class providing functionalities shared among InputMethod
// implementations.
class VIEWS_EXPORT InputMethodBase : public InputMethod,
public FocusChangeListener {
public:
InputMethodBase();
virtual ~InputMethodBase();
// Overriden from InputMethod.
virtual void set_delegate(internal::InputMethodDelegate* delegate) OVERRIDE;
// If a derived class overrides this method, it should call parent's
// implementation first.
virtual void Init(Widget* widget) OVERRIDE;
// If a derived class overrides this method, it should call parent's
// implementation first, to make sure |widget_focused_| flag can be updated
// correctly.
virtual void OnFocus() OVERRIDE;
// If a derived class overrides this method, it should call parent's
// implementation first, to make sure |widget_focused_| flag can be updated
// correctly.
virtual void OnBlur() OVERRIDE;
// If a derived class overrides this method, it should call parent's
// implementation.
virtual void OnTextInputTypeChanged(View* view) OVERRIDE;
virtual TextInputClient* GetTextInputClient() const OVERRIDE;
virtual ui::TextInputType GetTextInputType() const OVERRIDE;
// Overridden from FocusChangeListener. Derived classes shouldn't override
// this method. Override FocusedViewWillChange() and FocusedViewDidChange()
// instead.
virtual void FocusWillChange(View* focused_before, View* focused) OVERRIDE;
protected:
// Getters and setters of properties.
internal::InputMethodDelegate* delegate() const { return delegate_; }
Widget* widget() const { return widget_; }
View* focused_view() const { return focused_view_; }
bool widget_focused() const { return widget_focused_; }
// Checks if the given View is focused. Returns true only if the View and
// the Widget are both focused.
bool IsViewFocused(View* view) const;
// Checks if the focused text input client's text input type is
// ui::TEXT_INPUT_TYPE_NONE. Also returns true if there is no focused text
// input client.
bool IsTextInputTypeNone() const;
// Convenience method to call the focused text input client's
// OnInputMethodChanged() method. It'll only take effect if the current text
// input type is not ui::TEXT_INPUT_TYPE_NONE.
void OnInputMethodChanged() const;
// Convenience method to call delegate_->DispatchKeyEventPostIME().
void DispatchKeyEventPostIME(const KeyEvent& key) const;
// Gets the current text input client's caret bounds in Widget's coordinates.
// Returns false if the current text input client doesn't support text input.
bool GetCaretBoundsInWidget(gfx::Rect* rect) const;
// Called just before changing the focused view. Should be overridden by
// derived classes. The default implementation does nothing.
virtual void FocusedViewWillChange();
// Called just after changing the focused view. Should be overridden by
// derived classes. The default implementation does nothing.
// Note: It's called just after changing the value of |focused_view_|. As it's
// called inside FocusChangeListener's FocusWillChange() method, which is
// called by the FocusManager before actually changing the focus, the derived
// class should not rely on the actual focus state of the |focused_view_|.
virtual void FocusedViewDidChange();
private:
internal::InputMethodDelegate* delegate_;
Widget* widget_;
View* focused_view_;
// Indicates if the top-level widget is focused or not.
bool widget_focused_;
DISALLOW_COPY_AND_ASSIGN(InputMethodBase);
};
} // namespace views
#endif // VIEWS_IME_INPUT_METHOD_BASE_H_
|