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

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: Update according to review feedbacks. 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::FocusWillChange(View* focused_before, View* focused) {
46 DCHECK_EQ(focused_view_, focused_before);
47 FocusedViewWillChange();
48 focused_view_ = focused;
49 FocusedViewDidChange();
50 }
51
52 bool InputMethodBase::IsViewFocused(View* view) const {
53 return widget_focused_ && view && focused_view_ == view;
54 }
55
56 TextInputClient* InputMethodBase::GetTextInputClient() const {
57 return (widget_focused_ && focused_view_) ?
58 focused_view_->GetTextInputClient() : NULL;
59 }
60
61 ui::TextInputType InputMethodBase::GetTextInputType() const {
62 TextInputClient* client = GetTextInputClient();
63 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
64 }
65
66 bool InputMethodBase::IsClientSupportTextInput() const {
67 return GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
68 }
69
70 void InputMethodBase::OnInputMethodChanged() const {
71 TextInputClient* client = GetTextInputClient();
72 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
73 client->OnInputMethodChanged();
74 }
75
76 void InputMethodBase::DispatchKeyEventPostIME(const KeyEvent& key) const {
77 if (delegate_)
78 delegate_->DispatchKeyEventPostIME(key);
79 }
80
81 bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const {
82 DCHECK(rect);
83 TextInputClient* client = GetTextInputClient();
84 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
85 return false;
86
87 *rect = client->GetCaretBounds();
88 gfx::Point origin = rect->origin();
89 gfx::Point end = gfx::Point(rect->right(), rect->bottom());
90
91 View::ConvertPointToWidget(focused_view_, &origin);
92 View::ConvertPointToWidget(focused_view_, &end);
93 rect->SetRect(origin.x(), origin.y(),
94 end.x() - origin.x(), end.y() - origin.y());
95
96 // We need to do coordinate conversion if the focused view is inside a child
97 // Widget.
98 if (focused_view_->GetWidget() != widget_)
99 return Widget::ConvertRect(focused_view_->GetWidget(), widget_, rect);
100 return true;
101 }
102
103 void InputMethodBase::FocusedViewWillChange() {
104 }
105
106 void InputMethodBase::FocusedViewDidChange() {
107 }
108
109 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698