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

Unified Diff: ui/views/ime/input_method_bridge.cc

Issue 8576005: IME (input method editor) support for Aura, part 3 of 3: Use ui::InputMethod in ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/ime/input_method_bridge.cc
diff --git a/ui/views/ime/input_method_bridge.cc b/ui/views/ime/input_method_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..36a75398262ff9491ed4f6938ea10641172082c0
--- /dev/null
+++ b/ui/views/ime/input_method_bridge.cc
@@ -0,0 +1,219 @@
+// 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.
+
+#include "ui/views/ime/input_method_bridge.h"
+
+#include "ui/base/ime/input_method.h"
+#include "ui/gfx/rect.h"
+#include "views/view.h"
+#include "ui/views/widget/widget.h"
+
+namespace views {
+
+InputMethodBridge::InputMethodBridge(internal::InputMethodDelegate* delegate,
+ ui::InputMethod* host)
+ : host_(host),
+ context_focused_(false) {
+ DCHECK(host_);
+ set_delegate(delegate);
+}
+
+InputMethodBridge::~InputMethodBridge() {
+ if (host_->GetTextInputClient() == this)
+ host_->SetFocusedTextInputClient(NULL);
+}
+
+void InputMethodBridge::Init(Widget* widget) {
+ InputMethodBase::Init(widget);
+}
+
+void InputMethodBridge::OnFocus() {
+ DCHECK(!widget_focused());
+ InputMethodBase::OnFocus();
+
+ // Ask the system-wide IME to send all TextInputClient messages to |this|
+ // object.
+ host_->SetFocusedTextInputClient(this);
+
+ if (GetFocusedView())
+ OnTextInputTypeChanged(GetFocusedView());
+}
+
+void InputMethodBridge::OnBlur() {
+ DCHECK(widget_focused());
+
+ ConfirmCompositionText();
+ InputMethodBase::OnBlur();
+ if (host_->GetTextInputClient() == this)
+ host_->SetFocusedTextInputClient(NULL);
+}
+
+void InputMethodBridge::DispatchKeyEvent(const KeyEvent& key) {
+ DCHECK(key.type() == ui::ET_KEY_PRESSED || key.type() == ui::ET_KEY_RELEASED);
+ DCHECK(widget_focused());
+
+ // We can just dispatch the event here since the |key| is already processed by
+ // the system-wide IME.
+ DispatchKeyEventPostIME(key);
+}
+
+void InputMethodBridge::OnTextInputTypeChanged(View* view) {
+ if (IsViewFocused(view))
+ host_->OnTextInputTypeChanged(this);
+ InputMethodBase::OnTextInputTypeChanged(view);
+}
+
+void InputMethodBridge::OnCaretBoundsChanged(View* view) {
+ if (IsViewFocused(view) && !IsTextInputTypeNone())
+ host_->OnCaretBoundsChanged(this);
+}
+
+void InputMethodBridge::CancelComposition(View* view) {
+ if (IsViewFocused(view))
+ host_->CancelComposition(this);
+}
+
+std::string InputMethodBridge::GetInputLocale() {
+ return host_->GetInputLocale();
+}
+
+base::i18n::TextDirection InputMethodBridge::GetInputTextDirection() {
+ return host_->GetInputTextDirection();
+}
+
+bool InputMethodBridge::IsActive() {
+ return host_->IsActive();
+}
+
+// Overridden from TextInputClient. Forward an event from the system-wide IME
+// to the text input |client|, which is e.g. views::NativeTextfieldViews.
+void InputMethodBridge::SetCompositionText(
+ const ui::CompositionText& composition) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ client->SetCompositionText(composition);
+}
+
+void InputMethodBridge::ConfirmCompositionText() {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ client->ConfirmCompositionText();
+}
+
+void InputMethodBridge::ClearCompositionText() {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ client->ClearCompositionText();
+}
+
+void InputMethodBridge::InsertText(const string16& text) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ client->InsertText(text);
+}
+
+void InputMethodBridge::InsertChar(char16 ch, int flags) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ client->InsertChar(ch, flags);
+}
+
+ui::TextInputType InputMethodBridge::GetTextInputType() const {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->GetTextInputType();
+ return ui::TEXT_INPUT_TYPE_NONE;
James Su 2011/11/29 04:25:53 nit: return client ? client->GetTextInputType() :
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+gfx::Rect InputMethodBridge::GetCaretBounds() {
+ TextInputClient* client = GetTextInputClient();
+ if (!client || !GetFocusedView())
+ return gfx::Rect();
+
+ const gfx::Rect rect = client->GetCaretBounds();
+ gfx::Point origin = rect.origin();
+ gfx::Point end = gfx::Point(rect.right(), rect.bottom());
+ View::ConvertPointToScreen(GetFocusedView(), &origin);
+ View::ConvertPointToScreen(GetFocusedView(), &end);
+ return gfx::Rect(origin.x(),
+ origin.y(),
+ end.x() - origin.x(),
+ end.y() - origin.y());
+}
+
+bool InputMethodBridge::HasCompositionText() {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->HasCompositionText();
+ return false;
James Su 2011/11/29 04:25:53 nit: return client ? ... : false;
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+bool InputMethodBridge::GetTextRange(ui::Range* range) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->GetTextRange(range);
+ return false;
James Su 2011/11/29 04:25:53 ditto.
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+bool InputMethodBridge::GetCompositionTextRange(ui::Range* range) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->GetCompositionTextRange(range);
+ return false;
James Su 2011/11/29 04:25:53 ditto
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+bool InputMethodBridge::GetSelectionRange(ui::Range* range) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->GetSelectionRange(range);
+ return false;
James Su 2011/11/29 04:25:53 ditto
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+bool InputMethodBridge::SetSelectionRange(const ui::Range& range) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->SetSelectionRange(range);
+ return false;
James Su 2011/11/29 04:25:53 ditto
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+bool InputMethodBridge::DeleteRange(const ui::Range& range) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->DeleteRange(range);
+ return false;
James Su 2011/11/29 04:25:53 ditto
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+bool InputMethodBridge::GetTextFromRange(
+ const ui::Range& range, string16* text) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->GetTextFromRange(range, text);
+ return false;
James Su 2011/11/29 04:25:53 ditto
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+void InputMethodBridge::OnInputMethodChanged() {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ client->OnInputMethodChanged();
+}
+
+bool InputMethodBridge::ChangeTextDirectionAndLayoutAlignment(
+ base::i18n::TextDirection direction) {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ return client->ChangeTextDirectionAndLayoutAlignment(direction);
+ return false;
James Su 2011/11/29 04:25:53 ditto
Yusuke Sato 2011/11/29 09:06:36 Done.
+}
+
+// Overridden from FocusChangeListener.
+void InputMethodBridge::OnWillChangeFocus(View* focused_before, View* focused) {
+ ConfirmCompositionText();
+}
+
+void InputMethodBridge::OnDidChangeFocus(View* focused_before, View* focused) {
+ OnTextInputTypeChanged(GetFocusedView());
+ OnCaretBoundsChanged(GetFocusedView());
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698