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

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

Issue 8687027: IME (input method editor) support for Aura, part 2 of 3: Add views::InputMethodBridge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final rebase Created 9 years 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
« no previous file with comments | « ui/views/ime/input_method_bridge.h ('k') | ui/views/ime/input_method_ibus.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1ca16315a4e874a138a8fdb1a8b6979e982212bd
--- /dev/null
+++ b/ui/views/ime/input_method_bridge.cc
@@ -0,0 +1,204 @@
+// 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 "ui/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);
+
+ // TODO(yusukes): We don't need to call OnTextInputTypeChanged() once we move
+ // text input type tracker code to ui::InputMethodBase.
+ 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();
+ return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
+}
+
+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();
+ return client ? client->HasCompositionText() : false;
+}
+
+bool InputMethodBridge::GetTextRange(ui::Range* range) {
+ TextInputClient* client = GetTextInputClient();
+ return client ? client->GetTextRange(range) : false;
+}
+
+bool InputMethodBridge::GetCompositionTextRange(ui::Range* range) {
+ TextInputClient* client = GetTextInputClient();
+ return client ? client->GetCompositionTextRange(range) : false;
+}
+
+bool InputMethodBridge::GetSelectionRange(ui::Range* range) {
+ TextInputClient* client = GetTextInputClient();
+ return client ? client->GetSelectionRange(range) : false;
+}
+
+bool InputMethodBridge::SetSelectionRange(const ui::Range& range) {
+ TextInputClient* client = GetTextInputClient();
+ return client ? client->SetSelectionRange(range) : false;
+}
+
+bool InputMethodBridge::DeleteRange(const ui::Range& range) {
+ TextInputClient* client = GetTextInputClient();
+ return client ? client->DeleteRange(range) : false;
+}
+
+bool InputMethodBridge::GetTextFromRange(
+ const ui::Range& range, string16* text) {
+ TextInputClient* client = GetTextInputClient();
+ return client ? client->GetTextFromRange(range, text) : false;
+}
+
+void InputMethodBridge::OnInputMethodChanged() {
+ TextInputClient* client = GetTextInputClient();
+ if (client)
+ client->OnInputMethodChanged();
+}
+
+bool InputMethodBridge::ChangeTextDirectionAndLayoutAlignment(
+ base::i18n::TextDirection direction) {
+ TextInputClient* client = GetTextInputClient();
+ return client ?
+ client->ChangeTextDirectionAndLayoutAlignment(direction) : false;
+}
+
+// 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
« no previous file with comments | « ui/views/ime/input_method_bridge.h ('k') | ui/views/ime/input_method_ibus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698