Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: views/ime/input_method_base.cc

Issue 6688049: New InputMethod api for Views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add an OWNERS file. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "views/ime/input_method_base.h"
6 #include "views/view.h"
7 #include "views/widget/widget.h"
8
9 #include "base/logging.h"
10
11 namespace views {
12
13 InputMethodBase::InputMethodBase()
14 : delegate_(NULL),
15 widget_(NULL),
16 focused_view_(NULL),
17 widget_focused_(false) {
18 }
19
20 InputMethodBase::~InputMethodBase() {
21 if (widget_) {
22 widget_->GetFocusManager()->RemoveFocusChangeListener(this);
23 widget_ = NULL;
24 }
25 }
26
27 void InputMethodBase::set_delegate(internal::InputMethodDelegate* delegate) {
28 DCHECK(delegate);
29 delegate_ = delegate;
30 }
31
32 void InputMethodBase::Init(Widget* widget) {
33 DCHECK(widget);
34 DCHECK(widget->GetFocusManager());
35
36 if (widget_) {
37 NOTREACHED() << "The input method is already initialized.";
38 return;
39 }
40
41 widget_ = widget;
42 widget->GetFocusManager()->AddFocusChangeListener(this);
43 }
44
45 void InputMethodBase::OnFocusIn() {
46 widget_focused_ = true;
47 }
48
49 void InputMethodBase::OnFocusOut() {
50 widget_focused_ = false;
51 }
52
53 void InputMethodBase::FocusWillChange(View* focused_before, View* focused) {
54 DCHECK_EQ(focused_view_, focused_before);
55 FocusedViewWillChange();
56 focused_view_ = focused;
57 FocusedViewDidChange();
58 }
59
60 bool InputMethodBase::IsViewFocused(View* view) const {
61 return widget_focused_ && view && focused_view_ == view;
62 }
63
64 TextInputClient* InputMethodBase::GetTextInputClient() const {
65 return (widget_focused_ && focused_view_) ?
66 focused_view_->GetTextInputClient() : NULL;
67 }
68
69 ui::TextInputType InputMethodBase::GetTextInputType() const {
70 TextInputClient* client = GetTextInputClient();
71 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
72 }
73
74 bool InputMethodBase::IsTextInputTypeNone() const {
75 return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE;
76 }
77
78 void InputMethodBase::OnInputMethodChanged() const {
79 TextInputClient* client = GetTextInputClient();
80 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
81 client->OnInputMethodChanged();
82 }
83
84 void InputMethodBase::DispatchKeyEventPostIME(const KeyEvent& key) const {
85 if (delegate_)
86 delegate_->DispatchKeyEventPostIME(key);
87 }
88
89 bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const {
90 DCHECK(rect);
91 TextInputClient* client = GetTextInputClient();
92 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
93 return false;
94
95 *rect = client->GetCaretBounds();
96 gfx::Point origin = rect->origin();
97 gfx::Point end = gfx::Point(rect->right(), rect->bottom());
98
99 View::ConvertPointToWidget(focused_view_, &origin);
100 View::ConvertPointToWidget(focused_view_, &end);
101 rect->SetRect(origin.x(), origin.y(),
102 end.x() - origin.x(), end.y() - origin.y());
103
104 // We need to do coordinate conversion if the focused view is inside a child
105 // Widget.
106 if (focused_view_->GetWidget() != widget_)
107 return Widget::ConvertRect(focused_view_->GetWidget(), widget_, rect);
108 return true;
109 }
110
111 void InputMethodBase::FocusedViewWillChange() {
112 }
113
114 void InputMethodBase::FocusedViewDidChange() {
115 }
116
117 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698