summaryrefslogtreecommitdiffstats
path: root/views/ime
diff options
context:
space:
mode:
authorpenghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-12 12:45:27 +0000
committerpenghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-12 12:45:27 +0000
commit566e824bc5d3daf32519795629d73146b36991f0 (patch)
tree0acb5eaabec4292bc562ca9de8ac9c8c09805212 /views/ime
parenta90c3b6b4b9197494293c15439065c43a27a3469 (diff)
downloadchromium_src-566e824bc5d3daf32519795629d73146b36991f0.zip
chromium_src-566e824bc5d3daf32519795629d73146b36991f0.tar.gz
chromium_src-566e824bc5d3daf32519795629d73146b36991f0.tar.bz2
Use input method to control visibility of virtual keyboard.
BUG=None TEST=Test in Chrome OS and Linux desktop Review URL: http://codereview.chromium.org/7217008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/ime')
-rw-r--r--views/ime/input_method_base.cc17
-rw-r--r--views/ime/input_method_base.h4
-rw-r--r--views/ime/input_method_gtk.cc1
-rw-r--r--views/ime/input_method_ibus.cc1
-rw-r--r--views/ime/input_method_win.cc1
-rw-r--r--views/ime/text_input_type_tracker.cc37
-rw-r--r--views/ime/text_input_type_tracker.h59
7 files changed, 120 insertions, 0 deletions
diff --git a/views/ime/input_method_base.cc b/views/ime/input_method_base.cc
index 5716f46..89753fb 100644
--- a/views/ime/input_method_base.cc
+++ b/views/ime/input_method_base.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "views/ime/input_method_base.h"
+#include "views/ime/text_input_type_tracker.h"
#include "views/view.h"
#include "views/widget/widget.h"
@@ -47,10 +48,21 @@ void InputMethodBase::Init(Widget* widget) {
void InputMethodBase::OnFocus() {
widget_focused_ = true;
+ TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged(
+ GetTextInputType(), widget_);
}
void InputMethodBase::OnBlur() {
widget_focused_ = false;
+ TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged(
+ GetTextInputType(), widget_);
+}
+
+void InputMethodBase::OnTextInputTypeChanged(View* view) {
+ if (IsViewFocused(view)) {
+ TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged(
+ GetTextInputType(), widget_);
+ }
}
TextInputClient* InputMethodBase::GetTextInputClient() const {
@@ -68,6 +80,11 @@ void InputMethodBase::FocusWillChange(View* focused_before, View* focused) {
FocusedViewWillChange();
focused_view_ = focused;
FocusedViewDidChange();
+
+ if (widget_focused_) {
+ TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged(
+ GetTextInputType(), widget_);
+ }
}
bool InputMethodBase::IsViewFocused(View* view) const {
diff --git a/views/ime/input_method_base.h b/views/ime/input_method_base.h
index 8797074..1bea526 100644
--- a/views/ime/input_method_base.h
+++ b/views/ime/input_method_base.h
@@ -42,6 +42,10 @@ class InputMethodBase : public InputMethod,
// 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;
diff --git a/views/ime/input_method_gtk.cc b/views/ime/input_method_gtk.cc
index b55ccb9..6cb35b2 100644
--- a/views/ime/input_method_gtk.cc
+++ b/views/ime/input_method_gtk.cc
@@ -161,6 +161,7 @@ void InputMethodGtk::OnTextInputTypeChanged(View* view) {
DCHECK(!composing_text_);
UpdateContextFocusState();
}
+ InputMethodBase::OnTextInputTypeChanged(view);
}
void InputMethodGtk::OnCaretBoundsChanged(View* view) {
diff --git a/views/ime/input_method_ibus.cc b/views/ime/input_method_ibus.cc
index d3d4982..f2893bf 100644
--- a/views/ime/input_method_ibus.cc
+++ b/views/ime/input_method_ibus.cc
@@ -416,6 +416,7 @@ void InputMethodIBus::OnTextInputTypeChanged(View* view) {
ResetContext();
UpdateContextFocusState();
}
+ InputMethodBase::OnTextInputTypeChanged(view);
}
void InputMethodIBus::OnCaretBoundsChanged(View* view) {
diff --git a/views/ime/input_method_win.cc b/views/ime/input_method_win.cc
index 637a069..f7eb0cc 100644
--- a/views/ime/input_method_win.cc
+++ b/views/ime/input_method_win.cc
@@ -72,6 +72,7 @@ void InputMethodWin::OnTextInputTypeChanged(View* view) {
ime_input_.CancelIME(hwnd());
UpdateIMEState();
}
+ InputMethodBase::OnTextInputTypeChanged(view);
}
void InputMethodWin::OnCaretBoundsChanged(View* view) {
diff --git a/views/ime/text_input_type_tracker.cc b/views/ime/text_input_type_tracker.cc
new file mode 100644
index 0000000..83412be
--- /dev/null
+++ b/views/ime/text_input_type_tracker.cc
@@ -0,0 +1,37 @@
+// 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 "views/ime/text_input_type_tracker.h"
+
+namespace views {
+
+void TextInputTypeTracker::AddTextInputTypeObserver(
+ TextInputTypeObserver* observer) {
+ text_input_type_observers_.AddObserver(observer);
+}
+
+void TextInputTypeTracker::RemoveTextInputTypeObserver(
+ TextInputTypeObserver* observer) {
+ text_input_type_observers_.RemoveObserver(observer);
+}
+
+void TextInputTypeTracker::OnTextInputTypeChanged(
+ ui::TextInputType type, Widget* widget) {
+ FOR_EACH_OBSERVER(TextInputTypeObserver,
+ text_input_type_observers_,
+ TextInputTypeChanged(type, widget));
+}
+
+TextInputTypeTracker::TextInputTypeTracker() {
+}
+
+TextInputTypeTracker::~TextInputTypeTracker() {
+}
+
+// static
+TextInputTypeTracker* TextInputTypeTracker::GetInstance() {
+ return Singleton<TextInputTypeTracker>::get();
+}
+
+} // namespace views
diff --git a/views/ime/text_input_type_tracker.h b/views/ime/text_input_type_tracker.h
new file mode 100644
index 0000000..ecd16fd
--- /dev/null
+++ b/views/ime/text_input_type_tracker.h
@@ -0,0 +1,59 @@
+// 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_TEXT_INPUT_TYPE_TRACKER_H_
+#define VIEWS_IME_TEXT_INPUT_TYPE_TRACKER_H_
+#pragma once
+
+#include "base/memory/singleton.h"
+#include "base/observer_list.h"
+#include "ui/base/ime/text_input_type.h"
+
+namespace views {
+
+class Widget;
+
+// This interface should be implemented by classes that want to be notified when
+// the text input type of the focused widget is changed or the focused widget is
+// changed.
+class TextInputTypeObserver {
+ public:
+ // This function will be called, when the text input type of focused |widget|
+ // is changed or the the widget is getting/losing focus.
+ virtual void TextInputTypeChanged(ui::TextInputType type, Widget* widget) = 0;
+
+ protected:
+ virtual ~TextInputTypeObserver() {}
+};
+
+// This class is for tracking the text input type of focused widget.
+class TextInputTypeTracker {
+ public:
+ // Returns the singleton instance.
+ static TextInputTypeTracker* GetInstance();
+
+ // Adds/removes a TextInputTypeObserver |observer| to the set of
+ // active observers.
+ void AddTextInputTypeObserver(TextInputTypeObserver* observer);
+ void RemoveTextInputTypeObserver(TextInputTypeObserver* observer);
+
+ // views::InputMethod should call this function with new text input |type| and
+ // the |widget| associated with the input method, when the text input type
+ // is changed.
+ // Note: The widget should have focus or is losing focus.
+ void OnTextInputTypeChanged(ui::TextInputType type, Widget* widget);
+
+ private:
+ TextInputTypeTracker();
+ ~TextInputTypeTracker();
+
+ ObserverList<TextInputTypeObserver> text_input_type_observers_;
+
+ friend struct DefaultSingletonTraits<TextInputTypeTracker>;
+ DISALLOW_COPY_AND_ASSIGN(TextInputTypeTracker);
+};
+
+} // namespace views
+
+#endif // VIEWS_IME_TEXT_INPUT_TYPE_TRACKER_H_