summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshuchen <shuchen@chromium.org>2015-07-01 19:11:14 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-02 02:11:48 +0000
commit12f77cb7c9b7b8256df62a4423e03e539a980b3b (patch)
tree89dbfb2402ab76c5e181ba8997077577f0e85888
parent85f8564bcc24eb33885a13b8048f98e32dfc4062 (diff)
downloadchromium_src-12f77cb7c9b7b8256df62a4423e03e539a980b3b.zip
chromium_src-12f77cb7c9b7b8256df62a4423e03e539a980b3b.tar.gz
chromium_src-12f77cb7c9b7b8256df62a4423e03e539a980b3b.tar.bz2
Remove the 2-level input method system & InputMethodBridge.
This is IMF refactoring according to the design: - For @google.com: https://docs.google.com/document/d/14PQN4fbbSTlJmIk6qk7RzsuNr7O22DUTfNQ6slxKWV0 - For @chromium.org: https://docs.google.com/document/d/1sDES_kuEVUjb_FwCvKsg0Ef48edq5lAx589r0qUtG4g This cl includes some fundamental changes: 1) Removed ui/views/ime/... 2) All TextInputClient's use InputMethod::SetFocusedTextInputClient() to inform InputMethod that itself is focused. 3) Supports mocking input method in InputMethodFactory for TextfieldTest. 4) Removed views::View::GetTextInputClient() which is useless. The rest changes follow the above major changes. BUG=474828 TEST=Verified locally on Win7/Win8/Linux/CrOS/Mac. Tests passed. Review URL: https://codereview.chromium.org/1177503003 Cr-Commit-Position: refs/heads/master@{#337157}
-rw-r--r--ash/magnifier/magnification_controller_unittest.cc2
-rw-r--r--chrome/browser/chromeos/options/passphrase_textfield.cc3
-rw-r--r--chrome/browser/ui/views/find_bar_view.cc4
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc7
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc7
-rw-r--r--ui/base/ime/BUILD.gn2
-rw-r--r--ui/base/ime/dummy_input_method_delegate.cc19
-rw-r--r--ui/base/ime/dummy_input_method_delegate.h30
-rw-r--r--ui/base/ime/input_method_factory.cc12
-rw-r--r--ui/base/ime/input_method_factory.h1
-rw-r--r--ui/base/ime/ui_base_ime.gyp2
-rw-r--r--ui/views/cocoa/bridged_content_view.mm2
-rw-r--r--ui/views/cocoa/bridged_native_widget.h25
-rw-r--r--ui/views/cocoa/bridged_native_widget.mm29
-rw-r--r--ui/views/cocoa/bridged_native_widget_unittest.mm11
-rw-r--r--ui/views/controls/combobox/combobox.cc27
-rw-r--r--ui/views/controls/combobox/combobox.h3
-rw-r--r--ui/views/controls/combobox/combobox_unittest.cc21
-rw-r--r--ui/views/controls/menu/menu_controller.cc2
-rw-r--r--ui/views/controls/menu/submenu_view.cc9
-rw-r--r--ui/views/controls/menu/submenu_view.h3
-rw-r--r--ui/views/controls/prefix_selector.cc1
-rw-r--r--ui/views/controls/prefix_selector_unittest.cc5
-rw-r--r--ui/views/controls/textfield/textfield.cc19
-rw-r--r--ui/views/controls/textfield/textfield.h1
-rw-r--r--ui/views/controls/textfield/textfield_unittest.cc202
-rw-r--r--ui/views/controls/tree/tree_view.cc28
-rw-r--r--ui/views/controls/tree/tree_view.h3
-rw-r--r--ui/views/controls/tree/tree_view_unittest.cc3
-rw-r--r--ui/views/controls/webview/webview.cc4
-rw-r--r--ui/views/controls/webview/webview.h1
-rw-r--r--ui/views/ime/OWNERS7
-rw-r--r--ui/views/ime/input_method.h125
-rw-r--r--ui/views/ime/input_method_base.cc104
-rw-r--r--ui/views/ime/input_method_base.h78
-rw-r--r--ui/views/ime/input_method_bridge.cc346
-rw-r--r--ui/views/ime/input_method_bridge.h106
-rw-r--r--ui/views/ime/input_method_bridge_unittest.cc43
-rw-r--r--ui/views/ime/input_method_delegate.h31
-rw-r--r--ui/views/ime/mock_input_method.cc147
-rw-r--r--ui/views/ime/mock_input_method.h84
-rw-r--r--ui/views/ime/null_input_method.cc58
-rw-r--r--ui/views/ime/null_input_method.h49
-rw-r--r--ui/views/test/widget_test.h7
-rw-r--r--ui/views/test/widget_test_aura.cc6
-rw-r--r--ui/views/test/widget_test_mac.mm7
-rw-r--r--ui/views/view.cc17
-rw-r--r--ui/views/view.h16
-rw-r--r--ui/views/views.gyp12
-rw-r--r--ui/views/widget/desktop_aura/desktop_native_widget_aura.cc38
-rw-r--r--ui/views/widget/desktop_aura/desktop_native_widget_aura.h10
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc1
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc4
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_x11_interactive_uitest.cc8
-rw-r--r--ui/views/widget/desktop_aura/x11_desktop_handler.cc1
-rw-r--r--ui/views/widget/native_widget_aura.cc68
-rw-r--r--ui/views/widget/native_widget_aura.h9
-rw-r--r--ui/views/widget/native_widget_delegate.h6
-rw-r--r--ui/views/widget/native_widget_mac.h4
-rw-r--r--ui/views/widget/native_widget_mac.mm12
-rw-r--r--ui/views/widget/native_widget_private.h15
-rw-r--r--ui/views/widget/widget.cc72
-rw-r--r--ui/views/widget/widget.h21
-rw-r--r--ui/views/widget/widget_interactive_uitest.cc38
-rw-r--r--ui/views/widget/widget_unittest.cc5
-rw-r--r--ui/views/win/hwnd_message_handler.cc9
-rw-r--r--ui/views/win/hwnd_message_handler.h6
67 files changed, 402 insertions, 1656 deletions
diff --git a/ash/magnifier/magnification_controller_unittest.cc b/ash/magnifier/magnification_controller_unittest.cc
index 20dfb43..01a1e84 100644
--- a/ash/magnifier/magnification_controller_unittest.cc
+++ b/ash/magnifier/magnification_controller_unittest.cc
@@ -148,7 +148,7 @@ class MagnificationControllerTest: public test::AshTestBase {
ui::InputMethod* GetInputMethod() {
DCHECK(text_input_view_);
- return text_input_view_->GetWidget()->GetHostInputMethod();
+ return text_input_view_->GetWidget()->GetInputMethod();
}
DISALLOW_COPY_AND_ASSIGN(MagnificationControllerTest);
diff --git a/chrome/browser/chromeos/options/passphrase_textfield.cc b/chrome/browser/chromeos/options/passphrase_textfield.cc
index cea7ffa..8267edf 100644
--- a/chrome/browser/chromeos/options/passphrase_textfield.cc
+++ b/chrome/browser/chromeos/options/passphrase_textfield.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/chromeos/options/passphrase_textfield.h"
#include "base/strings/utf_string_conversions.h"
-#include "ui/views/ime/input_method.h"
namespace chromeos {
@@ -29,7 +28,6 @@ void PassphraseTextfield::OnFocus() {
if (show_fake_ && !changed_)
ClearFakePassphrase();
Textfield::OnFocus();
- GetInputMethod()->OnFocus();
}
void PassphraseTextfield::OnBlur() {
@@ -37,7 +35,6 @@ void PassphraseTextfield::OnBlur() {
if (show_fake_ && text().empty())
SetFakePassphrase();
Textfield::OnBlur();
- GetInputMethod()->OnFocus();
}
std::string PassphraseTextfield::GetPassphrase() {
diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc
index c64082d..8d78644 100644
--- a/chrome/browser/ui/views/find_bar_view.cc
+++ b/chrome/browser/ui/views/find_bar_view.cc
@@ -22,6 +22,7 @@
#include "chrome/grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkPaint.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
@@ -32,7 +33,6 @@
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/label.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/painter.h"
#include "ui/views/widget/widget.h"
@@ -234,7 +234,7 @@ void FindBarView::ClearMatchCount() {
void FindBarView::SetFocusAndSelection(bool select_all) {
find_text_->RequestFocus();
- GetInputMethod()->ShowImeIfNeeded();
+ GetWidget()->GetInputMethod()->ShowImeIfNeeded();
if (select_all && !find_text_->text().empty())
find_text_->SelectAll(true);
}
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 080f3fd..f9e68d4 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -35,6 +35,7 @@
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/base/l10n/l10n_util.h"
@@ -48,7 +49,6 @@
#include "ui/views/border.h"
#include "ui/views/button_drag_utils.h"
#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
@@ -187,7 +187,7 @@ void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) {
// session here. It may affect the selection status, so order is
// also important.
if (IsIMEComposing()) {
- GetTextInputClient()->ConfirmCompositionText();
+ ConfirmCompositionText();
GetInputMethod()->CancelComposition(this);
}
@@ -578,8 +578,7 @@ bool OmniboxViewViews::IsImeShowingPopup() const {
#if defined(OS_CHROMEOS)
return ime_candidate_window_open_;
#else
- const views::InputMethod* input_method = this->GetInputMethod();
- return input_method && input_method->IsCandidatePopupOpen();
+ return GetInputMethod() ? GetInputMethod()->IsCandidatePopupOpen() : false;
#endif
}
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
index 29f29ca..08f5fba 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc
@@ -20,13 +20,14 @@
#include "chrome/test/base/interactive_test_utils.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
+#include "ui/base/ime/input_method.h"
+#include "ui/base/ime/text_input_client.h"
#include "ui/base/test/ui_controls.h"
#include "ui/base/ui_base_switches.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/controls/textfield/textfield_test_api.h"
-#include "ui/views/ime/input_method.h"
namespace {
@@ -381,8 +382,8 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, FocusedTextInputClient) {
OmniboxView* view = NULL;
ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view));
OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view);
- views::InputMethod* input_method =
+ ui::InputMethod* input_method =
omnibox_view_views->GetWidget()->GetInputMethod();
- EXPECT_EQ(omnibox_view_views->GetTextInputClient(),
+ EXPECT_EQ(static_cast<ui::TextInputClient*>(omnibox_view_views),
input_method->GetTextInputClient());
}
diff --git a/ui/base/ime/BUILD.gn b/ui/base/ime/BUILD.gn
index 5125aa2..d8e3798 100644
--- a/ui/base/ime/BUILD.gn
+++ b/ui/base/ime/BUILD.gn
@@ -52,8 +52,6 @@ component("ime") {
"composition_text_util_pango.cc",
"composition_text_util_pango.h",
"composition_underline.h",
- "dummy_input_method_delegate.cc",
- "dummy_input_method_delegate.h",
"infolist_entry.cc",
"infolist_entry.h",
"input_method.h",
diff --git a/ui/base/ime/dummy_input_method_delegate.cc b/ui/base/ime/dummy_input_method_delegate.cc
deleted file mode 100644
index 473884a..0000000
--- a/ui/base/ime/dummy_input_method_delegate.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2013 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/base/ime/dummy_input_method_delegate.h"
-
-namespace ui {
-namespace internal {
-
-DummyInputMethodDelegate::DummyInputMethodDelegate() {}
-DummyInputMethodDelegate::~DummyInputMethodDelegate() {}
-
-bool DummyInputMethodDelegate::DispatchKeyEventPostIME(
- const ui::KeyEvent& key_event) {
- return true;
-}
-
-} // namespace internal
-} // namespace ui
diff --git a/ui/base/ime/dummy_input_method_delegate.h b/ui/base/ime/dummy_input_method_delegate.h
deleted file mode 100644
index 5bbd382..0000000
--- a/ui/base/ime/dummy_input_method_delegate.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2013 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 UI_BASE_IME_DUMMY_INPUT_METHOD_DELEGATE_H_
-#define UI_BASE_IME_DUMMY_INPUT_METHOD_DELEGATE_H_
-
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "ui/base/ime/input_method_delegate.h"
-
-namespace ui {
-namespace internal {
-
-class UI_BASE_IME_EXPORT DummyInputMethodDelegate : public InputMethodDelegate {
- public:
- DummyInputMethodDelegate();
- ~DummyInputMethodDelegate() override;
-
- // Overridden from InputMethodDelegate:
- bool DispatchKeyEventPostIME(const ui::KeyEvent& key_event) override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(DummyInputMethodDelegate);
-};
-
-} // namespace internal
-} // namespace ui
-
-#endif // UI_BASE_IME_DUMMY_INPUT_METHOD_DELEGATE_H_
diff --git a/ui/base/ime/input_method_factory.cc b/ui/base/ime/input_method_factory.cc
index 0076083..b4aa3cd 100644
--- a/ui/base/ime/input_method_factory.cc
+++ b/ui/base/ime/input_method_factory.cc
@@ -23,6 +23,8 @@
namespace {
+ui::InputMethod* g_input_method_for_testing = nullptr;
+
bool g_input_method_set_for_testing = false;
bool g_create_input_method_called = false;
@@ -37,6 +39,12 @@ scoped_ptr<InputMethod> CreateInputMethod(
if (!g_create_input_method_called)
g_create_input_method_called = true;
+ if (g_input_method_for_testing) {
+ ui::InputMethod* ret = g_input_method_for_testing;
+ g_input_method_for_testing = nullptr;
+ return make_scoped_ptr(ret);
+ }
+
if (g_input_method_set_for_testing)
return make_scoped_ptr(new MockInputMethod(delegate));
@@ -68,4 +76,8 @@ void SetUpInputMethodFactoryForTesting() {
g_input_method_set_for_testing = true;
}
+void SetUpInputMethodForTesting(InputMethod* input_method) {
+ g_input_method_for_testing = input_method;
+}
+
} // namespace ui
diff --git a/ui/base/ime/input_method_factory.h b/ui/base/ime/input_method_factory.h
index d3a6e25..30132cb 100644
--- a/ui/base/ime/input_method_factory.h
+++ b/ui/base/ime/input_method_factory.h
@@ -26,6 +26,7 @@ UI_BASE_IME_EXPORT scoped_ptr<InputMethod> CreateInputMethod(
// Makes CreateInputMethod return a MockInputMethod.
UI_BASE_IME_EXPORT void SetUpInputMethodFactoryForTesting();
+UI_BASE_IME_EXPORT void SetUpInputMethodForTesting(InputMethod* input_method);
} // namespace ui;
diff --git a/ui/base/ime/ui_base_ime.gyp b/ui/base/ime/ui_base_ime.gyp
index b612984..b1487583 100644
--- a/ui/base/ime/ui_base_ime.gyp
+++ b/ui/base/ime/ui_base_ime.gyp
@@ -73,8 +73,6 @@
'composition_text_util_pango.cc',
'composition_text_util_pango.h',
'composition_underline.h',
- 'dummy_input_method_delegate.cc',
- 'dummy_input_method_delegate.h',
'infolist_entry.cc',
'infolist_entry.h',
'input_method.h',
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm
index e23db5b..3a3e839 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -7,6 +7,7 @@
#include "base/logging.h"
#import "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/compositor/canvas_painter.h"
#import "ui/events/cocoa/cocoa_event_utils.h"
@@ -16,7 +17,6 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/controls/menu/menu_controller.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
diff --git a/ui/views/cocoa/bridged_native_widget.h b/ui/views/cocoa/bridged_native_widget.h
index 5f52831..6e4cff5 100644
--- a/ui/views/cocoa/bridged_native_widget.h
+++ b/ui/views/cocoa/bridged_native_widget.h
@@ -10,12 +10,12 @@
#import "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
+#include "ui/base/ime/input_method_delegate.h"
#include "ui/compositor/layer_owner.h"
#import "ui/accelerated_widget_mac/accelerated_widget_mac.h"
#import "ui/views/cocoa/bridged_native_widget_owner.h"
#import "ui/views/cocoa/cocoa_mouse_capture_delegate.h"
#import "ui/views/focus/focus_manager.h"
-#include "ui/views/ime/input_method_delegate.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/widget.h"
@@ -29,20 +29,20 @@ class InputMethod;
namespace views {
class CocoaMouseCapture;
-class InputMethod;
class NativeWidgetMac;
class View;
// A bridge to an NSWindow managed by an instance of NativeWidgetMac or
// DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the
// NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window.
-class VIEWS_EXPORT BridgedNativeWidget : public ui::LayerDelegate,
- public ui::LayerOwner,
- public internal::InputMethodDelegate,
- public CocoaMouseCaptureDelegate,
- public FocusChangeListener,
- public ui::AcceleratedWidgetMacNSView,
- public BridgedNativeWidgetOwner {
+class VIEWS_EXPORT BridgedNativeWidget
+ : public ui::LayerDelegate,
+ public ui::LayerOwner,
+ public ui::internal::InputMethodDelegate,
+ public CocoaMouseCaptureDelegate,
+ public FocusChangeListener,
+ public ui::AcceleratedWidgetMacNSView,
+ public BridgedNativeWidgetOwner {
public:
// Ways of changing the visibility of the bridged NSWindow.
enum WindowVisibilityState {
@@ -142,8 +142,7 @@ class VIEWS_EXPORT BridgedNativeWidget : public ui::LayerDelegate,
void OnSizeConstraintsChanged();
// See widget.h for documentation.
- InputMethod* CreateInputMethod();
- ui::InputMethod* GetHostInputMethod();
+ ui::InputMethod* GetInputMethod();
// The restored bounds will be derived from the current NSWindow frame unless
// fullscreen or transitioning between fullscreen states.
@@ -169,8 +168,8 @@ class VIEWS_EXPORT BridgedNativeWidget : public ui::LayerDelegate,
bool target_fullscreen_state() const { return target_fullscreen_state_; }
bool window_visible() { return window_visible_; }
- // Overridden from internal::InputMethodDelegate:
- void DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
+ // Overridden from ui::internal::InputMethodDelegate:
+ bool DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
private:
// Closes all child windows. BridgedNativeWidget children will be destroyed.
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm
index c5fa0a2..eaa875b 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -25,8 +25,6 @@
#include "ui/views/cocoa/tooltip_manager_mac.h"
#import "ui/views/cocoa/views_nswindow_delegate.h"
#import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
-#include "ui/views/ime/input_method_bridge.h"
-#include "ui/views/ime/null_input_method.h"
#include "ui/views/view.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget_mac.h"
@@ -707,15 +705,12 @@ void BridgedNativeWidget::OnSizeConstraintsChanged() {
shows_fullscreen_controls);
}
-InputMethod* BridgedNativeWidget::CreateInputMethod() {
- return new InputMethodBridge(this, GetHostInputMethod(), true);
-}
-
-ui::InputMethod* BridgedNativeWidget::GetHostInputMethod() {
+ui::InputMethod* BridgedNativeWidget::GetInputMethod() {
if (!input_method_) {
- // Delegate is NULL because Mac IME does not need DispatchKeyEventPostIME
- // callbacks.
- input_method_ = ui::CreateInputMethod(NULL, nil);
+ input_method_ = ui::CreateInputMethod(this, nil);
+ // For now, use always-focused mode on Mac for the input method.
+ // TODO(tapted): Move this to OnWindowKeyStatusChangedTo() and balance.
+ input_method_->OnFocus();
}
return input_method_.get();
}
@@ -757,11 +752,12 @@ void BridgedNativeWidget::CreateLayer(ui::LayerType layer_type,
////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidget, internal::InputMethodDelegate:
-void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
+bool BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
DCHECK(focus_manager_);
native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
if (!key.handled())
- focus_manager_->OnKeyEvent(key);
+ return !focus_manager_->OnKeyEvent(key);
+ return key.handled();
}
////////////////////////////////////////////////////////////////////////////////
@@ -784,9 +780,12 @@ void BridgedNativeWidget::OnWillChangeFocus(View* focused_before,
void BridgedNativeWidget::OnDidChangeFocus(View* focused_before,
View* focused_now) {
- ui::TextInputClient* input_client =
- focused_now ? focused_now->GetTextInputClient() : NULL;
- [bridged_view_ setTextInputClient:input_client];
+ ui::InputMethod* input_method =
+ native_widget_mac_->GetWidget()->GetInputMethod();
+ if (input_method) {
+ ui::TextInputClient* input_client = input_method->GetTextInputClient();
+ [bridged_view_ setTextInputClient:input_client];
+ }
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ui/views/cocoa/bridged_native_widget_unittest.mm b/ui/views/cocoa/bridged_native_widget_unittest.mm
index af08bf0..479203e 100644
--- a/ui/views/cocoa/bridged_native_widget_unittest.mm
+++ b/ui/views/cocoa/bridged_native_widget_unittest.mm
@@ -14,12 +14,12 @@
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "testing/gtest_mac.h"
+#include "ui/base/ime/input_method.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"
#import "ui/views/cocoa/bridged_content_view.h"
#import "ui/views/cocoa/native_widget_mac_nswindow.h"
#import "ui/views/cocoa/views_nswindow_delegate.h"
#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/view.h"
#include "ui/views/widget/native_widget_mac.h"
#include "ui/views/widget/root_view.h"
@@ -268,13 +268,8 @@ TEST_F(BridgedNativeWidgetTest, ViewSizeTracksWindow) {
EXPECT_EQ(kTestNewHeight, view_->height());
}
-TEST_F(BridgedNativeWidgetTest, CreateInputMethodShouldNotReturnNull) {
- scoped_ptr<views::InputMethod> input_method(bridge()->CreateInputMethod());
- EXPECT_TRUE(input_method);
-}
-
-TEST_F(BridgedNativeWidgetTest, GetHostInputMethodShouldNotReturnNull) {
- EXPECT_TRUE(bridge()->GetHostInputMethod());
+TEST_F(BridgedNativeWidgetTest, GetInputMethodShouldNotReturnNull) {
+ EXPECT_TRUE(bridge()->GetInputMethod());
}
// A simpler test harness for testing initialization flows.
diff --git a/ui/views/controls/combobox/combobox.cc b/ui/views/controls/combobox/combobox.cc
index af332fb..7d527a9 100644
--- a/ui/views/controls/combobox/combobox.cc
+++ b/ui/views/controls/combobox/combobox.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_view_state.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/models/combobox_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/event.h"
@@ -32,7 +33,6 @@
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/controls/prefix_selector.h"
#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/mouse_constants.h"
#include "ui/views/painter.h"
#include "ui/views/resources/grit/views_resources.h"
@@ -273,6 +273,11 @@ Combobox::Combobox(ui::ComboboxModel* model)
Combobox::~Combobox() {
model_->RemoveObserver(this);
+
+ if (GetInputMethod() && selector_.get()) {
+ // Combobox should have been blurred before destroy.
+ DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient());
+ }
}
// static
@@ -335,12 +340,6 @@ void Combobox::SetInvalid(bool invalid) {
SchedulePaint();
}
-ui::TextInputClient* Combobox::GetTextInputClient() {
- if (!selector_)
- selector_.reset(new PrefixSelector(this));
- return selector_.get();
-}
-
void Combobox::Layout() {
PrefixDelegate::Layout();
@@ -540,14 +539,18 @@ void Combobox::OnPaint(gfx::Canvas* canvas) {
}
void Combobox::OnFocus() {
- GetInputMethod()->OnFocus();
+ if (GetInputMethod())
+ GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector());
+
View::OnFocus();
// Border renders differently when focused.
SchedulePaint();
}
void Combobox::OnBlur() {
- GetInputMethod()->OnBlur();
+ if (GetInputMethod())
+ GetInputMethod()->DetachTextInputClient(GetPrefixSelector());
+
if (selector_)
selector_->OnViewBlur();
// Border renders differently when focused.
@@ -865,4 +868,10 @@ gfx::Size Combobox::ArrowSize() const {
ignored);
}
+PrefixSelector* Combobox::GetPrefixSelector() {
+ if (!selector_)
+ selector_.reset(new PrefixSelector(this));
+ return selector_.get();
+}
+
} // namespace views
diff --git a/ui/views/controls/combobox/combobox.h b/ui/views/controls/combobox/combobox.h
index 4355504e..5508764 100644
--- a/ui/views/controls/combobox/combobox.h
+++ b/ui/views/controls/combobox/combobox.h
@@ -102,7 +102,6 @@ class VIEWS_EXPORT Combobox : public MenuDelegate,
void OnFocus() override;
void OnBlur() override;
void GetAccessibleState(ui::AXViewState* state) override;
- ui::TextInputClient* GetTextInputClient() override;
void Layout() override;
// Overridden from MenuDelegate:
@@ -164,6 +163,8 @@ class VIEWS_EXPORT Combobox : public MenuDelegate,
// Handles the clicking event.
void HandleClickEvent();
+ PrefixSelector* GetPrefixSelector();
+
// Our model. Not owned.
ui::ComboboxModel* model_;
diff --git a/ui/views/controls/combobox/combobox_unittest.cc b/ui/views/controls/combobox/combobox_unittest.cc
index c811603..a3cba30 100644
--- a/ui/views/controls/combobox/combobox_unittest.cc
+++ b/ui/views/controls/combobox/combobox_unittest.cc
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/strings/utf_string_conversions.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/models/combobox_model.h"
#include "ui/events/event.h"
@@ -17,7 +18,6 @@
#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/menu/menu_runner_handler.h"
-#include "ui/views/ime/mock_input_method.h"
#include "ui/views/test/menu_runner_test_api.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
@@ -225,11 +225,6 @@ class ComboboxTest : public ViewsTestBase {
widget_->SetContentsView(container);
container->AddChildView(combobox_);
- widget_->ReplaceInputMethod(new MockInputMethod);
-
- // Assumes the Widget is always focused.
- widget_->GetInputMethod()->OnFocus();
-
combobox_->RequestFocus();
combobox_->SizeToPreferredSize();
}
@@ -241,7 +236,10 @@ class ComboboxTest : public ViewsTestBase {
void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) {
ui::KeyEvent event(type, key_code, ui::EF_NONE);
- widget_->GetInputMethod()->DispatchKeyEvent(event);
+ FocusManager* focus_manager = widget_->GetFocusManager();
+ widget_->OnKeyEvent(&event);
+ if (!event.handled() && focus_manager)
+ focus_manager->OnKeyEvent(event);
}
View* GetFocusedView() {
@@ -669,24 +667,27 @@ TEST_F(ComboboxTest, TypingPrefixNotifiesListener) {
TestComboboxListener listener;
combobox_->set_listener(&listener);
+ ui::TextInputClient* input_client =
+ widget_->GetInputMethod()->GetTextInputClient();
// Type the first character of the second menu item ("JELLY").
- combobox_->GetTextInputClient()->InsertChar('J', ui::EF_NONE);
+ input_client->InsertChar('J', ui::EF_NONE);
EXPECT_EQ(1, listener.actions_performed());
EXPECT_EQ(1, listener.perform_action_index());
// Type the second character of "JELLY", item shouldn't change and
// OnPerformAction() shouldn't be re-called.
- combobox_->GetTextInputClient()->InsertChar('E', ui::EF_NONE);
+ input_client->InsertChar('E', ui::EF_NONE);
EXPECT_EQ(1, listener.actions_performed());
EXPECT_EQ(1, listener.perform_action_index());
// Clears the typed text.
combobox_->OnBlur();
+ combobox_->RequestFocus();
// Type the first character of "PEANUT BUTTER", which should change the
// selected index and perform an action.
- combobox_->GetTextInputClient()->InsertChar('P', ui::EF_NONE);
+ input_client->InsertChar('P', ui::EF_NONE);
EXPECT_EQ(2, listener.actions_performed());
EXPECT_EQ(2, listener.perform_action_index());
}
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index 062c5f1..54d3410 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -2078,7 +2078,7 @@ bool MenuController::SelectByChar(base::char16 character) {
return AcceptOrSelect(item, details);
if (is_combobox_) {
- item->GetSubmenu()->GetTextInputClient()->InsertChar(character, 0);
+ item->GetSubmenu()->GetPrefixSelector()->InsertChar(character, 0);
} else {
// If no mnemonics found, look at first character of titles.
details = FindChildForMnemonic(item, key, &TitleMatchesMnemonic);
diff --git a/ui/views/controls/menu/submenu_view.cc b/ui/views/controls/menu/submenu_view.cc
index b147aa6..f80aedf 100644
--- a/ui/views/controls/menu/submenu_view.cc
+++ b/ui/views/controls/menu/submenu_view.cc
@@ -8,6 +8,7 @@
#include "base/compiler_specific.h"
#include "ui/accessibility/ax_view_state.h"
+#include "ui/base/ime/input_method.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
@@ -80,6 +81,10 @@ MenuItemView* SubmenuView::GetMenuItemAt(int index) {
return NULL;
}
+PrefixSelector* SubmenuView::GetPrefixSelector() {
+ return &prefix_selector_;
+}
+
void SubmenuView::ChildPreferredSizeChanged(View* child) {
if (!resize_open_menu_)
return;
@@ -184,10 +189,6 @@ void SubmenuView::GetAccessibleState(ui::AXViewState* state) {
state->role = ui::AX_ROLE_MENU_LIST_POPUP;
}
-ui::TextInputClient* SubmenuView::GetTextInputClient() {
- return &prefix_selector_;
-}
-
void SubmenuView::PaintChildren(const ui::PaintContext& context) {
View::PaintChildren(context);
diff --git a/ui/views/controls/menu/submenu_view.h b/ui/views/controls/menu/submenu_view.h
index d2aebf8..be221cf 100644
--- a/ui/views/controls/menu/submenu_view.h
+++ b/ui/views/controls/menu/submenu_view.h
@@ -52,6 +52,8 @@ class VIEWS_EXPORT SubmenuView : public PrefixDelegate,
// Returns the MenuItemView at the specified index.
MenuItemView* GetMenuItemAt(int index);
+ PrefixSelector* GetPrefixSelector();
+
// Positions and sizes the child views. This tiles the views vertically,
// giving each child the available width.
void Layout() override;
@@ -59,7 +61,6 @@ class VIEWS_EXPORT SubmenuView : public PrefixDelegate,
// Override from View.
void GetAccessibleState(ui::AXViewState* state) override;
- ui::TextInputClient* GetTextInputClient() override;
// Painting.
void PaintChildren(const ui::PaintContext& context) override;
diff --git a/ui/views/controls/prefix_selector.cc b/ui/views/controls/prefix_selector.cc
index f7e8f66..37a5708 100644
--- a/ui/views/controls/prefix_selector.cc
+++ b/ui/views/controls/prefix_selector.cc
@@ -5,6 +5,7 @@
#include "ui/views/controls/prefix_selector.h"
#include "base/i18n/case_conversion.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/range/range.h"
#include "ui/views/controls/prefix_delegate.h"
diff --git a/ui/views/controls/prefix_selector_unittest.cc b/ui/views/controls/prefix_selector_unittest.cc
index fe7614b..fe2651c 100644
--- a/ui/views/controls/prefix_selector_unittest.cc
+++ b/ui/views/controls/prefix_selector_unittest.cc
@@ -46,6 +46,11 @@ class PrefixSelectorTest : public ViewsTestBase {
PrefixSelectorTest() {
selector_.reset(new PrefixSelector(&delegate_));
}
+ ~PrefixSelectorTest() override {
+ // Explicitly release |selector_| here which can happen before releasing
+ // |delegate_|.
+ selector_.reset();
+ }
protected:
scoped_ptr<PrefixSelector> selector_;
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 7602b0e..4a6c105 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -12,6 +12,7 @@
#include "ui/base/cursor/cursor.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/drag_utils.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/touch/selection_bound.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/canvas_painter.h"
@@ -31,7 +32,6 @@
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/drag_utils.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/metrics.h"
#include "ui/views/native_cursor.h"
#include "ui/views/painter.h"
@@ -298,7 +298,12 @@ Textfield::Textfield()
AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN));
}
-Textfield::~Textfield() {}
+Textfield::~Textfield() {
+ if (GetInputMethod()) {
+ // The textfield should have been blurred before destroy.
+ DCHECK(this != GetInputMethod()->GetTextInputClient());
+ }
+}
void Textfield::SetReadOnly(bool read_only) {
// Update read-only without changing the focusable state (or active, etc.).
@@ -722,10 +727,6 @@ bool Textfield::OnKeyPressed(const ui::KeyEvent& event) {
return handled;
}
-ui::TextInputClient* Textfield::GetTextInputClient() {
- return this;
-}
-
void Textfield::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) {
case ui::ET_GESTURE_TAP_DOWN:
@@ -1005,7 +1006,8 @@ void Textfield::OnFocus() {
GetRenderText()->set_focused(true);
cursor_visible_ = true;
SchedulePaint();
- GetInputMethod()->OnFocus();
+ if (GetInputMethod())
+ GetInputMethod()->SetFocusedTextInputClient(this);
OnCaretBoundsChanged();
const size_t caret_blink_ms = Textfield::GetCaretBlinkMs();
@@ -1021,7 +1023,8 @@ void Textfield::OnFocus() {
void Textfield::OnBlur() {
GetRenderText()->set_focused(false);
- GetInputMethod()->OnBlur();
+ if (GetInputMethod())
+ GetInputMethod()->DetachTextInputClient(this);
cursor_repaint_timer_.Stop();
if (cursor_visible_) {
cursor_visible_ = false;
diff --git a/ui/views/controls/textfield/textfield.h b/ui/views/controls/textfield/textfield.h
index a9660d4..290d2be 100644
--- a/ui/views/controls/textfield/textfield.h
+++ b/ui/views/controls/textfield/textfield.h
@@ -218,7 +218,6 @@ class VIEWS_EXPORT Textfield : public View,
bool OnMouseDragged(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
bool OnKeyPressed(const ui::KeyEvent& event) override;
- ui::TextInputClient* GetTextInputClient() override;
void OnGestureEvent(ui::GestureEvent* event) override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
bool CanHandleAccelerators() const override;
diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc
index a02456e..2df3dd2 100644
--- a/ui/views/controls/textfield/textfield_unittest.cc
+++ b/ui/views/controls/textfield/textfield_unittest.cc
@@ -16,11 +16,15 @@
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/dragdrop/drag_drop_types.h"
+#include "ui/base/ime/input_method_base.h"
+#include "ui/base/ime/input_method_delegate.h"
+#include "ui/base/ime/input_method_factory.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/events/event.h"
+#include "ui/events/event_processor.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/test/event_generator.h"
@@ -30,7 +34,6 @@
#include "ui/views/controls/textfield/textfield_model.h"
#include "ui/views/controls/textfield/textfield_test_api.h"
#include "ui/views/focus/focus_manager.h"
-#include "ui/views/ime/mock_input_method.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/widget_test.h"
@@ -59,6 +62,184 @@ namespace {
const base::char16 kHebrewLetterSamekh = 0x05E1;
+class MockInputMethod : public ui::InputMethodBase {
+ public:
+ MockInputMethod();
+ ~MockInputMethod() override;
+
+ // Overridden from InputMethod:
+ bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
+ NativeEventResult* result) override;
+ bool DispatchKeyEvent(const ui::KeyEvent& key) override;
+ void OnTextInputTypeChanged(const ui::TextInputClient* client) override;
+ void OnCaretBoundsChanged(const ui::TextInputClient* client) override {}
+ void CancelComposition(const ui::TextInputClient* client) override;
+ void OnInputLocaleChanged() override {}
+ std::string GetInputLocale() override;
+ bool IsActive() override;
+ bool IsCandidatePopupOpen() const override;
+ void ShowImeIfNeeded() override {}
+
+ bool untranslated_ime_message_called() const {
+ return untranslated_ime_message_called_;
+ }
+ bool text_input_type_changed() const { return text_input_type_changed_; }
+ bool cancel_composition_called() const { return cancel_composition_called_; }
+
+ // Clears all internal states and result.
+ void Clear();
+
+ void SetCompositionTextForNextKey(const ui::CompositionText& composition);
+ void SetResultTextForNextKey(const base::string16& result);
+
+ private:
+ // Overridden from InputMethodBase.
+ void OnWillChangeFocusedClient(ui::TextInputClient* focused_before,
+ ui::TextInputClient* focused) override;
+
+ // Clears boolean states defined below.
+ void ClearStates();
+
+ // Whether a mock composition or result is scheduled for the next key event.
+ bool HasComposition();
+
+ // Clears only composition information and result text.
+ void ClearComposition();
+
+ // Composition information for the next key event. It'll be cleared
+ // automatically after dispatching the next key event.
+ ui::CompositionText composition_;
+
+ // Result text for the next key event. It'll be cleared automatically after
+ // dispatching the next key event.
+ base::string16 result_text_;
+
+ // Record call state of corresponding methods. They will be set to false
+ // automatically before dispatching a key event.
+ bool untranslated_ime_message_called_;
+ bool text_input_type_changed_;
+ bool cancel_composition_called_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockInputMethod);
+};
+
+MockInputMethod::MockInputMethod()
+ : untranslated_ime_message_called_(false),
+ text_input_type_changed_(false),
+ cancel_composition_called_(false) {
+}
+
+MockInputMethod::~MockInputMethod() {
+}
+
+bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event,
+ NativeEventResult* result) {
+ if (result)
+ *result = NativeEventResult();
+ return false;
+}
+
+bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) {
+ // Checks whether the key event is from EventGenerator on Windows which will
+ // generate key event for WM_CHAR.
+ // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here.
+ if (key.is_char() && key.HasNativeEvent())
+ return true;
+
+ bool handled = !IsTextInputTypeNone() && HasComposition();
+ ClearStates();
+ if (handled) {
+ DCHECK(!key.is_char());
+ ui::KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags());
+ DispatchKeyEventPostIME(mock_key);
+ } else {
+ DispatchKeyEventPostIME(key);
+ }
+
+ ui::TextInputClient* client = GetTextInputClient();
+ if (client) {
+ if (handled) {
+ if (result_text_.length())
+ client->InsertText(result_text_);
+ if (composition_.text.length())
+ client->SetCompositionText(composition_);
+ else
+ client->ClearCompositionText();
+ } else if (key.type() == ui::ET_KEY_PRESSED) {
+ base::char16 ch = key.GetCharacter();
+ if (ch)
+ client->InsertChar(ch, key.flags());
+ }
+ }
+
+ ClearComposition();
+ return true;
+}
+
+void MockInputMethod::OnTextInputTypeChanged(
+ const ui::TextInputClient* client) {
+ if (IsTextInputClientFocused(client))
+ text_input_type_changed_ = true;
+ InputMethodBase::OnTextInputTypeChanged(client);
+}
+
+void MockInputMethod::CancelComposition(const ui::TextInputClient* client) {
+ if (IsTextInputClientFocused(client)) {
+ cancel_composition_called_ = true;
+ ClearComposition();
+ }
+}
+
+std::string MockInputMethod::GetInputLocale() {
+ return "en-US";
+}
+
+bool MockInputMethod::IsActive() {
+ return true;
+}
+
+bool MockInputMethod::IsCandidatePopupOpen() const {
+ return false;
+}
+
+void MockInputMethod::OnWillChangeFocusedClient(
+ ui::TextInputClient* focused_before,
+ ui::TextInputClient* focused) {
+ ui::TextInputClient* client = GetTextInputClient();
+ if (client && client->HasCompositionText())
+ client->ConfirmCompositionText();
+ ClearComposition();
+}
+
+void MockInputMethod::Clear() {
+ ClearStates();
+ ClearComposition();
+}
+
+void MockInputMethod::SetCompositionTextForNextKey(
+ const ui::CompositionText& composition) {
+ composition_ = composition;
+}
+
+void MockInputMethod::SetResultTextForNextKey(const base::string16& result) {
+ result_text_ = result;
+}
+
+void MockInputMethod::ClearStates() {
+ untranslated_ime_message_called_ = false;
+ text_input_type_changed_ = false;
+ cancel_composition_called_ = false;
+}
+
+bool MockInputMethod::HasComposition() {
+ return composition_.text.length() || result_text_.length();
+}
+
+void MockInputMethod::ClearComposition() {
+ composition_.Clear();
+ result_text_.clear();
+}
+
// A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults.
class TestTextfield : public views::Textfield {
public:
@@ -139,6 +320,7 @@ class TextfieldDestroyerController : public views::TextfieldController {
// views::TextfieldController:
bool HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) override {
+ target_->OnBlur();
target_.reset();
return false;
}
@@ -171,6 +353,8 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
on_before_user_action_(0),
on_after_user_action_(0),
copied_to_clipboard_(ui::CLIPBOARD_TYPE_LAST) {
+ input_method_ = new MockInputMethod();
+ ui::SetUpInputMethodForTesting(input_method_);
}
// ::testing::Test:
@@ -224,6 +408,8 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
params.bounds = gfx::Rect(100, 100, 100, 100);
widget_->Init(params);
+ input_method_->SetDelegate(
+ test::WidgetTest::GetInputMethodDelegateForWidget(widget_));
View* container = new View();
widget_->SetContentsView(container);
container->AddChildView(textfield_);
@@ -240,9 +426,6 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
model_ = test_api_->model();
model_->ClearEditHistory();
- input_method_ = new MockInputMethod();
- widget_->ReplaceInputMethod(input_method_);
-
// Since the window type is activatable, showing the widget will also
// activate it. Calling Activate directly is insufficient, since that does
// not also _focus_ an aura::Window (i.e. using the FocusClient). Both the
@@ -1283,7 +1466,7 @@ TEST_F(TextfieldTest, ReadOnlyTest) {
TEST_F(TextfieldTest, TextInputClientTest) {
InitTextfield();
- ui::TextInputClient* client = textfield_->GetTextInputClient();
+ ui::TextInputClient* client = textfield_;
EXPECT_TRUE(client);
EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType());
@@ -1380,24 +1563,21 @@ TEST_F(TextfieldTest, TextInputClientTest) {
// Changing the Textfield to readonly shouldn't change the input client, since
// it's still required for selections and clipboard copy.
- ui::TextInputClient* text_input_client = textfield_->GetTextInputClient();
+ ui::TextInputClient* text_input_client = textfield_;
EXPECT_TRUE(text_input_client);
EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
textfield_->SetReadOnly(true);
EXPECT_TRUE(input_method_->text_input_type_changed());
- EXPECT_EQ(text_input_client, textfield_->GetTextInputClient());
EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
input_method_->Clear();
textfield_->SetReadOnly(false);
EXPECT_TRUE(input_method_->text_input_type_changed());
- EXPECT_EQ(text_input_client, textfield_->GetTextInputClient());
EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
input_method_->Clear();
textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
EXPECT_TRUE(input_method_->text_input_type_changed());
- EXPECT_TRUE(textfield_->GetTextInputClient());
}
TEST_F(TextfieldTest, UndoRedoTest) {
@@ -1908,7 +2088,7 @@ TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) {
ui::CompositionText composition;
composition.text = UTF8ToUTF16("abc123");
const uint32 char_count = static_cast<uint32>(composition.text.length());
- ui::TextInputClient* client = textfield_->GetTextInputClient();
+ ui::TextInputClient* client = textfield_;
// Compare the composition character bounds with surrounding cursor bounds.
for (uint32 i = 0; i < char_count; ++i) {
@@ -1954,7 +2134,7 @@ TEST_F(TextfieldTest, GetCompositionCharacterBounds_ComplexText) {
ui::CompositionText composition;
composition.text.assign(kUtf16Chars, kUtf16Chars + kUtf16CharsCount);
- ui::TextInputClient* client = textfield_->GetTextInputClient();
+ ui::TextInputClient* client = textfield_;
client->SetCompositionText(composition);
// Make sure GetCompositionCharacterBounds never fails for index.
diff --git a/ui/views/controls/tree/tree_view.cc b/ui/views/controls/tree/tree_view.cc
index f103df8..b791843 100644
--- a/ui/views/controls/tree/tree_view.cc
+++ b/ui/views/controls/tree/tree_view.cc
@@ -9,6 +9,7 @@
#include "base/i18n/rtl.h"
#include "base/message_loop/message_loop.h"
#include "ui/accessibility/ax_view_state.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
@@ -23,7 +24,6 @@
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/tree/tree_view_controller.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/resources/grit/views_resources.h"
using ui::TreeModel;
@@ -95,6 +95,12 @@ TreeView::TreeView()
TreeView::~TreeView() {
if (model_)
model_->RemoveObserver(this);
+
+ if (GetInputMethod() && selector_.get()) {
+ // TreeView should have been blurred before destroy.
+ DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient());
+ }
+
if (focus_manager_) {
focus_manager_->RemoveFocusChangeListener(this);
focus_manager_ = NULL;
@@ -370,12 +376,6 @@ bool TreeView::OnMousePressed(const ui::MouseEvent& event) {
return OnClickOrTap(event);
}
-ui::TextInputClient* TreeView::GetTextInputClient() {
- if (!selector_)
- selector_.reset(new PrefixSelector(this));
- return selector_.get();
-}
-
void TreeView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP) {
if (OnClickOrTap(*event))
@@ -618,17 +618,19 @@ void TreeView::OnPaint(gfx::Canvas* canvas) {
}
void TreeView::OnFocus() {
- GetInputMethod()->OnFocus();
+ if (GetInputMethod())
+ GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector());
View::OnFocus();
SchedulePaintForNode(selected_node_);
// Notify the InputMethod so that it knows to query the TextInputClient.
if (GetInputMethod())
- GetInputMethod()->OnCaretBoundsChanged(this);
+ GetInputMethod()->OnCaretBoundsChanged(GetPrefixSelector());
}
void TreeView::OnBlur() {
- GetInputMethod()->OnBlur();
+ if (GetInputMethod())
+ GetInputMethod()->DetachTextInputClient(GetPrefixSelector());
SchedulePaintForNode(selected_node_);
if (selector_)
selector_->OnViewBlur();
@@ -1003,6 +1005,12 @@ bool TreeView::ExpandImpl(TreeModelNode* model_node) {
return return_value;
}
+PrefixSelector* TreeView::GetPrefixSelector() {
+ if (!selector_)
+ selector_.reset(new PrefixSelector(this));
+ return selector_.get();
+}
+
// InternalNode ----------------------------------------------------------------
TreeView::InternalNode::InternalNode()
diff --git a/ui/views/controls/tree/tree_view.h b/ui/views/controls/tree/tree_view.h
index 0cb3760..fdcff67 100644
--- a/ui/views/controls/tree/tree_view.h
+++ b/ui/views/controls/tree/tree_view.h
@@ -124,7 +124,6 @@ class VIEWS_EXPORT TreeView : public ui::TreeModelObserver,
gfx::Size GetPreferredSize() const override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
- ui::TextInputClient* GetTextInputClient() override;
void OnGestureEvent(ui::GestureEvent* event) override;
void ShowContextMenu(const gfx::Point& p,
ui::MenuSourceType source_type) override;
@@ -330,6 +329,8 @@ class VIEWS_EXPORT TreeView : public ui::TreeModelObserver,
// that previously wasn't.
bool ExpandImpl(ui::TreeModelNode* model_node);
+ PrefixSelector* GetPrefixSelector();
+
// The model, may be null.
ui::TreeModel* model_;
diff --git a/ui/views/controls/tree/tree_view_unittest.cc b/ui/views/controls/tree/tree_view_unittest.cc
index fef0417..0af68a9 100644
--- a/ui/views/controls/tree/tree_view_unittest.cc
+++ b/ui/views/controls/tree/tree_view_unittest.cc
@@ -62,7 +62,7 @@ class TreeViewTest : public ViewsTestBase {
void CollapseOrSelectParent();
void ExpandOrSelectChild();
int GetRowCount();
- PrefixSelector* selector() { return tree_.selector_.get(); }
+ PrefixSelector* selector() { return tree_.GetPrefixSelector(); }
ui::TreeNodeModel<TestNode > model_;
TreeView tree_;
@@ -392,7 +392,6 @@ TEST_F(TreeViewTest, ExpandOrSelectChild) {
TEST_F(TreeViewTest, SelectOnKeyStroke) {
tree_.SetModel(&model_);
tree_.ExpandAll(model_.GetRoot());
- tree_.GetTextInputClient();
selector()->InsertText(ASCIIToUTF16("b"));
EXPECT_EQ("b", GetSelectedNodeTitle());
selector()->InsertText(ASCIIToUTF16("1"));
diff --git a/ui/views/controls/webview/webview.cc b/ui/views/controls/webview/webview.cc
index adeeadc..43121b9 100644
--- a/ui/views/controls/webview/webview.cc
+++ b/ui/views/controls/webview/webview.cc
@@ -109,10 +109,6 @@ const char* WebView::GetClassName() const {
return kViewClassName;
}
-ui::TextInputClient* WebView::GetTextInputClient() {
- return NULL;
-}
-
scoped_ptr<content::WebContents> WebView::SwapWebContents(
scoped_ptr<content::WebContents> new_web_contents) {
if (wc_owner_)
diff --git a/ui/views/controls/webview/webview.h b/ui/views/controls/webview/webview.h
index 8ae132e..a493662 100644
--- a/ui/views/controls/webview/webview.h
+++ b/ui/views/controls/webview/webview.h
@@ -90,7 +90,6 @@ class WEBVIEW_EXPORT WebView : public View,
// Overridden from View:
const char* GetClassName() const override;
- ui::TextInputClient* GetTextInputClient() override;
protected:
// Swaps the owned WebContents |wc_owner_| with |new_web_contents|. Returns
diff --git a/ui/views/ime/OWNERS b/ui/views/ime/OWNERS
deleted file mode 100644
index 7976b04..0000000
--- a/ui/views/ime/OWNERS
+++ /dev/null
@@ -1,7 +0,0 @@
-# primary reviewer
-shuchen@chromium.org
-
-# backup reviewers.
-yukishiino@chromium.org
-mukai@chromium.org
-nona@chromium.org
diff --git a/ui/views/ime/input_method.h b/ui/views/ime/input_method.h
deleted file mode 100644
index 268c9f1..0000000
--- a/ui/views/ime/input_method.h
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright (c) 2012 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 UI_VIEWS_IME_INPUT_METHOD_H_
-#define UI_VIEWS_IME_INPUT_METHOD_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/event_types.h"
-#include "base/i18n/rtl.h"
-#include "ui/base/ime/text_input_type.h"
-#include "ui/views/views_export.h"
-
-namespace ui {
-class KeyEvent;
-class TextInputClient;
-} // namespace ui
-
-namespace views {
-
-namespace internal {
-class InputMethodDelegate;
-} // namespace internal
-
-class View;
-class Widget;
-
-// An interface implemented by an object that encapsulates a native input method
-// service provided by the underlying operation system. Input method services
-// are typically bound to individual native windows (HWND, aura::Window, etc.).
-// In Views, only the top-level Widgets get keyboard focus, so this API is
-// designed to be bound to top-level Widgets.
-class VIEWS_EXPORT InputMethod {
- public:
-
-#if defined(OS_WIN)
- typedef LRESULT NativeEventResult;
-#else
- typedef int32 NativeEventResult;
-#endif
-
- virtual ~InputMethod() {}
-
- // Sets the delegate used by this InputMethod instance.
- // This should only be called by the owner Widget or testing code.
- virtual void SetDelegate(internal::InputMethodDelegate* delegate) = 0;
-
- // Initialize the InputMethod object and attach it to the given |widget|.
- // The |widget| must already be initialized.
- virtual void Init(Widget* widget) = 0;
-
- // Called when the top-level Widget gains or loses keyboard focus.
- // These should only be called by the Widget that owns this InputMethod.
- virtual void OnFocus() = 0;
- virtual void OnBlur() = 0;
-
- // Called when the focused window receives native IME messages that are not
- // translated into other predefined event callbacks. Currently this method is
- // used only for IME functionalities specific to Windows.
- // TODO(ime): Break down these messages into platform-neutral methods.
- virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
- NativeEventResult* result) = 0;
-
- // Dispatch a key event to the input method. The key event will be dispatched
- // back to the caller via InputMethodDelegate::DispatchKeyEventPostIME(), once
- // it has been processed by the input method. It should only be called by the
- // top-level Widget that owns this InputMethod instance, or other related
- // platform-specific code, such as a message dispatcher.
- virtual void DispatchKeyEvent(const ui::KeyEvent& key) = 0;
-
- // Called by the focused |view| whenever its text input type has changed.
- // Before calling this method, the focused |view| must confirm or clear any
- // existing composition text and call InputMethod::CancelComposition() when
- // necessary. This method has no effect if |view| is not focused.
- virtual void OnTextInputTypeChanged(View* view) = 0;
-
- // Called by the focused |view| whenever its caret bounds have changed.
- // This method has no effect if |view| is not focused.
- virtual void OnCaretBoundsChanged(View* view) = 0;
-
- // Called by the focused |view| to cancel the ongoing composition session.
- // This method has no effect if |view| is not focused.
- virtual void CancelComposition(View* view) = 0;
-
- // Called by the focused client whenever its input locale is changed.
- // This method is currently used only on Windows.
- // This method does not take a parameter of View for historical reasons.
- // TODO(ime): Consider to take a parameter of View.
- virtual void OnInputLocaleChanged() = 0;
-
- // Returns the locale of current keyboard layout or input method, as a BCP-47
- // tag, or an empty string if the input method cannot provide it.
- virtual std::string GetInputLocale() = 0;
-
- // Returns true if the input method is ready to process keyboard events and
- // generate composition or text results. It is not necessary to notify
- // inactive input methods of caret bounds or text input type changes.
- // Note: TextInputClient::InsertChar() may be called to send input to the text
- // input client even if the input method is not active.
- virtual bool IsActive() = 0;
-
- // Returns the focused text input client, or NULL if the Widget is not active,
- // has no focused View, or if the focused View does not support text input.
- virtual ui::TextInputClient* GetTextInputClient() const = 0;
-
- // Gets the text input type of the focused text input client. Returns
- // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client.
- virtual ui::TextInputType GetTextInputType() const = 0;
-
- // Returns true if we know for sure that a candidate window (or IME suggest,
- // etc.) is open. Returns false if no popup window is open or the detection
- // of IME popups is not supported.
- virtual bool IsCandidatePopupOpen() const = 0;
-
- // Displays an on screen keyboard if enabled.
- virtual void ShowImeIfNeeded() = 0;
-
- // TODO(suzhe): Support mouse/touch event.
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_IME_INPUT_METHOD_H_
diff --git a/ui/views/ime/input_method_base.cc b/ui/views/ime/input_method_base.cc
deleted file mode 100644
index 6eb5179..0000000
--- a/ui/views/ime/input_method_base.cc
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c) 2012 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_base.h"
-
-#include "base/logging.h"
-#include "ui/base/ime/text_input_client.h"
-#include "ui/events/event.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-InputMethodBase::InputMethodBase() : delegate_(NULL), widget_(NULL) {}
-
-InputMethodBase::~InputMethodBase() {
- DetachFromWidget();
-}
-
-void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) {
- DCHECK(delegate);
- delegate_ = delegate;
-}
-
-void InputMethodBase::Init(Widget* widget) {
- DCHECK(widget);
- DCHECK(widget->GetFocusManager());
- DCHECK(!widget_) << "The input method is already initialized.";
-
- widget_ = widget;
- // Alert the InputMethod of the Widget's currently focused view.
- View* focused = widget->GetFocusManager()->GetFocusedView();
- if (focused)
- OnWillChangeFocus(NULL, focused);
- widget->GetFocusManager()->AddFocusChangeListener(this);
-}
-
-views::View* InputMethodBase::GetFocusedView() const {
- return widget_ ? widget_->GetFocusManager()->GetFocusedView() : NULL;
-}
-
-void InputMethodBase::OnTextInputTypeChanged(View* view) {}
-
-ui::TextInputClient* InputMethodBase::GetTextInputClient() const {
- return (widget_ && widget_->IsActive() && GetFocusedView()) ?
- GetFocusedView()->GetTextInputClient() : NULL;
-}
-
-ui::TextInputType InputMethodBase::GetTextInputType() const {
- ui::TextInputClient* client = GetTextInputClient();
- return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
-}
-
-void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) {}
-
-void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) {}
-
-bool InputMethodBase::IsViewFocused(View* view) const {
- return widget_ && widget_->IsActive() && view && GetFocusedView() == view;
-}
-
-bool InputMethodBase::IsTextInputTypeNone() const {
- return GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE;
-}
-
-void InputMethodBase::OnInputMethodChanged() const {
- ui::TextInputClient* client = GetTextInputClient();
- if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
- client->OnInputMethodChanged();
-}
-
-void InputMethodBase::DispatchKeyEventPostIME(const ui::KeyEvent& key) const {
- if (delegate_)
- delegate_->DispatchKeyEventPostIME(key);
-}
-
-bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const {
- DCHECK(rect);
- ui::TextInputClient* client = GetTextInputClient();
- if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
- return false;
-
- gfx::Rect caret_bounds = client->GetCaretBounds();
- gfx::Point caret_origin = caret_bounds.origin();
- View::ConvertPointFromScreen(GetFocusedView(), &caret_origin);
- caret_bounds.set_origin(caret_origin);
- *rect = GetFocusedView()->ConvertRectToWidget(caret_bounds);
-
- // Convert coordinates if the focused view is inside a child Widget.
- if (GetFocusedView()->GetWidget() != widget_)
- return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget_, rect);
- return true;
-}
-
-void InputMethodBase::DetachFromWidget() {
- if (!widget_)
- return;
-
- widget_->GetFocusManager()->RemoveFocusChangeListener(this);
- widget_ = NULL;
-}
-
-} // namespace views
diff --git a/ui/views/ime/input_method_base.h b/ui/views/ime/input_method_base.h
deleted file mode 100644
index 75fd6fc..0000000
--- a/ui/views/ime/input_method_base.h
+++ /dev/null
@@ -1,78 +0,0 @@
-// 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 UI_VIEWS_IME_INPUT_METHOD_BASE_H_
-#define UI_VIEWS_IME_INPUT_METHOD_BASE_H_
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ui/views/focus/focus_manager.h"
-#include "ui/views/ime/input_method.h"
-#include "ui/views/ime/input_method_delegate.h"
-
-namespace gfx {
-class Rect;
-}
-
-namespace ui {
-class KeyEvent;
-}
-
-namespace views {
-
-// A helper that provides functionality shared by InputMethod implementations.
-class VIEWS_EXPORT InputMethodBase : public InputMethod,
- public FocusChangeListener {
- public:
- InputMethodBase();
- ~InputMethodBase() override;
-
- // Overridden from InputMethod.
- void SetDelegate(internal::InputMethodDelegate* delegate) override;
- void Init(Widget* widget) override;
- void OnTextInputTypeChanged(View* view) override;
- ui::TextInputClient* GetTextInputClient() const override;
- ui::TextInputType GetTextInputType() const override;
-
- // Overridden from FocusChangeListener.
- void OnWillChangeFocus(View* focused_before, View* focused) override;
- void OnDidChangeFocus(View* focused_before, View* focused) override;
-
- protected:
- internal::InputMethodDelegate* delegate() const { return delegate_; }
- Widget* widget() const { return widget_; }
- View* GetFocusedView() const;
-
- // Returns true only if the View is focused and its Widget is active.
- bool IsViewFocused(View* view) const;
-
- // Returns true if there is no focused text input client or its type is none.
- bool IsTextInputTypeNone() const;
-
- // Calls the focused text input client's OnInputMethodChanged() method.
- // This has no effect if the text input type is ui::TEXT_INPUT_TYPE_NONE.
- void OnInputMethodChanged() const;
-
- // Convenience method to call delegate_->DispatchKeyEventPostIME().
- void DispatchKeyEventPostIME(const ui::KeyEvent& key) const;
-
- // Gets the current text input client's caret bounds in Widget's coordinates.
- // Returns false if the current text input client doesn't support text input.
- bool GetCaretBoundsInWidget(gfx::Rect* rect) const;
-
- // Removes any state installed on |widget_| and NULLs it out. Use if the
- // widget is in a state such that it should no longer be used (such as when
- // this is in its destructor).
- void DetachFromWidget();
-
- private:
- internal::InputMethodDelegate* delegate_;
- Widget* widget_;
-
- DISALLOW_COPY_AND_ASSIGN(InputMethodBase);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_IME_INPUT_METHOD_BASE_H_
diff --git a/ui/views/ime/input_method_bridge.cc b/ui/views/ime/input_method_bridge.cc
deleted file mode 100644
index 88ceec7..0000000
--- a/ui/views/ime/input_method_bridge.cc
+++ /dev/null
@@ -1,346 +0,0 @@
-// Copyright (c) 2012 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/base/ime/input_method_observer.h"
-#include "ui/events/event.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-// InputMethodBridge::HostObserver class ---------------------------------------
-
-// An observer class for observing the host input method. When the host input
-// method is destroyed, it will null out the |host_| field on the
-// InputMethodBridge object.
-class InputMethodBridge::HostObserver : public ui::InputMethodObserver {
- public:
- explicit HostObserver(InputMethodBridge* bridge);
- ~HostObserver() override;
-
- void OnTextInputTypeChanged(const ui::TextInputClient* client) override {}
- void OnFocus() override {}
- void OnBlur() override {}
- void OnCaretBoundsChanged(const ui::TextInputClient* client) override {}
- void OnTextInputStateChanged(const ui::TextInputClient* client) override {}
- void OnInputMethodDestroyed(const ui::InputMethod* input_method) override;
- void OnShowImeIfNeeded() override {}
-
- private:
- InputMethodBridge* bridge_;
-
- DISALLOW_COPY_AND_ASSIGN(HostObserver);
-};
-
-InputMethodBridge::HostObserver::HostObserver(InputMethodBridge* bridge)
- : bridge_(bridge) {
- bridge_->host_->AddObserver(this);
-}
-
-InputMethodBridge::HostObserver::~HostObserver() {
- if (bridge_->host_)
- bridge_->host_->RemoveObserver(this);
-}
-
-void InputMethodBridge::HostObserver::OnInputMethodDestroyed(
- const ui::InputMethod* input_method) {
- DCHECK_EQ(bridge_->host_, input_method);
- bridge_->host_->RemoveObserver(this);
- bridge_->host_ = NULL;
-}
-
-// InputMethodBridge class -----------------------------------------------------
-
-InputMethodBridge::InputMethodBridge(internal::InputMethodDelegate* delegate,
- ui::InputMethod* host,
- bool shared_input_method)
- : host_(host),
- shared_input_method_(shared_input_method) {
- DCHECK(host_);
- SetDelegate(delegate);
-
- host_observer_.reset(new HostObserver(this));
-}
-
-InputMethodBridge::~InputMethodBridge() {
- // By the time we get here it's very likely |widget_|'s NativeWidget has been
- // destroyed. This means any calls to |widget_| that go to the NativeWidget,
- // such as IsActive(), will crash. SetFocusedTextInputClient() may callback to
- // this and go into |widget_|. NULL out |widget_| so we don't attempt to use
- // it.
- DetachFromWidget();
-
- // Host input method might have been destroyed at this point.
- if (host_)
- host_->DetachTextInputClient(this);
-}
-
-void InputMethodBridge::OnFocus() {
- if (!host_) // |host_| could be NULL after OnInputMethodDestroyed.
- return;
-
- // Direct the shared IME to send TextInputClient messages to |this| object.
- if (shared_input_method_ || !host_->GetTextInputClient())
- 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());
- OnCaretBoundsChanged(GetFocusedView());
- }
-}
-
-void InputMethodBridge::OnBlur() {
- if (!host_) // |host_| could be NULL after OnInputMethodDestroyed.
- return;
-
- if (HasCompositionText()) {
- ConfirmCompositionText();
- host_->CancelComposition(this);
- }
-
- if (host_->GetTextInputClient() == this)
- host_->SetFocusedTextInputClient(NULL);
-}
-
-bool InputMethodBridge::OnUntranslatedIMEMessage(const base::NativeEvent& event,
- NativeEventResult* result) {
- DCHECK(host_);
-
- return host_->OnUntranslatedIMEMessage(event, result);
-}
-
-void InputMethodBridge::DispatchKeyEvent(const ui::KeyEvent& key) {
- DCHECK(key.type() == ui::ET_KEY_PRESSED || key.type() == ui::ET_KEY_RELEASED);
-
- // 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) {
- DCHECK(host_);
-
- if (IsViewFocused(view))
- host_->OnTextInputTypeChanged(this);
- InputMethodBase::OnTextInputTypeChanged(view);
-}
-
-void InputMethodBridge::OnCaretBoundsChanged(View* view) {
- DCHECK(host_);
-
- if (IsViewFocused(view) && !IsTextInputTypeNone())
- host_->OnCaretBoundsChanged(this);
-}
-
-void InputMethodBridge::CancelComposition(View* view) {
- DCHECK(host_);
-
- if (IsViewFocused(view))
- host_->CancelComposition(this);
-}
-
-void InputMethodBridge::OnInputLocaleChanged() {
- DCHECK(host_);
-
- host_->OnInputLocaleChanged();
-}
-
-std::string InputMethodBridge::GetInputLocale() {
- DCHECK(host_);
-
- return host_->GetInputLocale();
-}
-
-bool InputMethodBridge::IsActive() {
- DCHECK(host_);
-
- return host_->IsActive();
-}
-
-bool InputMethodBridge::IsCandidatePopupOpen() const {
- DCHECK(host_);
-
- return host_->IsCandidatePopupOpen();
-}
-
-void InputMethodBridge::ShowImeIfNeeded() {
- DCHECK(host_);
- host_->ShowImeIfNeeded();
-}
-
-// Overridden from TextInputClient. Forward an event from the system-wide IME
-// to the text input |client|, which is e.g. views::Textfield.
-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 base::string16& text) {
- TextInputClient* client = GetTextInputClient();
- if (client)
- client->InsertText(text);
-}
-
-void InputMethodBridge::InsertChar(base::char16 ch, int flags) {
- TextInputClient* client = GetTextInputClient();
- if (client)
- client->InsertChar(ch, flags);
-}
-
-gfx::NativeWindow InputMethodBridge::GetAttachedWindow() const {
- TextInputClient* client = GetTextInputClient();
- return client ?
- client->GetAttachedWindow() : static_cast<gfx::NativeWindow>(NULL);
-}
-
-ui::TextInputType InputMethodBridge::GetTextInputType() const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
-}
-
-ui::TextInputMode InputMethodBridge::GetTextInputMode() const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->GetTextInputMode() : ui::TEXT_INPUT_MODE_DEFAULT;
-}
-
-int InputMethodBridge::GetTextInputFlags() const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->GetTextInputFlags() : 0;
-}
-
-bool InputMethodBridge::CanComposeInline() const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->CanComposeInline() : true;
-}
-
-gfx::Rect InputMethodBridge::GetCaretBounds() const {
- TextInputClient* client = GetTextInputClient();
- if (!client)
- return gfx::Rect();
-
- return client->GetCaretBounds();
-}
-
-bool InputMethodBridge::GetCompositionCharacterBounds(uint32 index,
- gfx::Rect* rect) const {
- DCHECK(rect);
- TextInputClient* client = GetTextInputClient();
- if (!client)
- return false;
-
- return client->GetCompositionCharacterBounds(index, rect);
-}
-
-bool InputMethodBridge::HasCompositionText() const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->HasCompositionText() : false;
-}
-
-bool InputMethodBridge::GetTextRange(gfx::Range* range) const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->GetTextRange(range) : false;
-}
-
-bool InputMethodBridge::GetCompositionTextRange(gfx::Range* range) const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->GetCompositionTextRange(range) : false;
-}
-
-bool InputMethodBridge::GetSelectionRange(gfx::Range* range) const {
- TextInputClient* client = GetTextInputClient();
- return client ? client->GetSelectionRange(range) : false;
-}
-
-bool InputMethodBridge::SetSelectionRange(const gfx::Range& range) {
- TextInputClient* client = GetTextInputClient();
- return client ? client->SetSelectionRange(range) : false;
-}
-
-bool InputMethodBridge::DeleteRange(const gfx::Range& range) {
- TextInputClient* client = GetTextInputClient();
- return client ? client->DeleteRange(range) : false;
-}
-
-bool InputMethodBridge::GetTextFromRange(const gfx::Range& range,
- base::string16* text) const {
- 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;
-}
-
-void InputMethodBridge::ExtendSelectionAndDelete(size_t before, size_t after) {
- TextInputClient* client = GetTextInputClient();
- if (client)
- client->ExtendSelectionAndDelete(before, after);
-}
-
-void InputMethodBridge::EnsureCaretInRect(const gfx::Rect& rect) {
- TextInputClient* client = GetTextInputClient();
- if (client)
- client->EnsureCaretInRect(rect);
-}
-
-bool InputMethodBridge::IsEditCommandEnabled(int command_id) {
- TextInputClient* client = GetTextInputClient();
- return client ? client->IsEditCommandEnabled(command_id) : false;
-}
-
-void InputMethodBridge::SetEditCommandForNextKeyEvent(int command_id) {
- TextInputClient* client = GetTextInputClient();
- if (client)
- client->SetEditCommandForNextKeyEvent(command_id);
-}
-
-// Overridden from FocusChangeListener.
-void InputMethodBridge::OnWillChangeFocus(View* focused_before, View* focused) {
- if (HasCompositionText()) {
- ConfirmCompositionText();
- CancelComposition(focused_before);
- }
-}
-
-void InputMethodBridge::OnDidChangeFocus(View* focused_before, View* focused) {
- DCHECK_EQ(GetFocusedView(), focused);
- OnTextInputTypeChanged(focused);
- OnCaretBoundsChanged(focused);
-}
-
-ui::InputMethod* InputMethodBridge::GetHostInputMethod() const {
- return host_;
-}
-
-
-} // namespace views
diff --git a/ui/views/ime/input_method_bridge.h b/ui/views/ime/input_method_bridge.h
deleted file mode 100644
index ce7e3c4..0000000
--- a/ui/views/ime/input_method_bridge.h
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) 2012 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 UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_
-#define UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ui/base/ime/text_input_client.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/views/ime/input_method_base.h"
-
-namespace ui {
-class InputMethod;
-} // namespace ui
-
-namespace views {
-
-class View;
-
-// A "bridge" InputMethod implementation for views top-level widgets, which just
-// sends/receives IME related events to/from a system-wide ui::InputMethod
-// object.
-class InputMethodBridge : public InputMethodBase,
- public ui::TextInputClient {
- public:
- // |shared_input_method| indicates if |host| is shared among other top level
- // widgets.
- InputMethodBridge(internal::InputMethodDelegate* delegate,
- ui::InputMethod* host,
- bool shared_input_method);
- ~InputMethodBridge() override;
-
- // Overridden from InputMethod:
- void OnFocus() override;
- void OnBlur() override;
- bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
- NativeEventResult* result) override;
- void DispatchKeyEvent(const ui::KeyEvent& key) override;
- void OnTextInputTypeChanged(View* view) override;
- void OnCaretBoundsChanged(View* view) override;
- void CancelComposition(View* view) override;
- void OnInputLocaleChanged() override;
- std::string GetInputLocale() override;
- bool IsActive() override;
- bool IsCandidatePopupOpen() const override;
- void ShowImeIfNeeded() override;
-
- // Overridden from TextInputClient:
- void SetCompositionText(const ui::CompositionText& composition) override;
- void ConfirmCompositionText() override;
- void ClearCompositionText() override;
- void InsertText(const base::string16& text) override;
- void InsertChar(base::char16 ch, int flags) override;
- gfx::NativeWindow GetAttachedWindow() const override;
- ui::TextInputType GetTextInputType() const override;
- ui::TextInputMode GetTextInputMode() const override;
- int GetTextInputFlags() const override;
- bool CanComposeInline() const override;
- gfx::Rect GetCaretBounds() const override;
- bool GetCompositionCharacterBounds(uint32 index,
- gfx::Rect* rect) const override;
- bool HasCompositionText() const override;
- bool GetTextRange(gfx::Range* range) const override;
- bool GetCompositionTextRange(gfx::Range* range) const override;
- bool GetSelectionRange(gfx::Range* range) const override;
- bool SetSelectionRange(const gfx::Range& range) override;
- bool DeleteRange(const gfx::Range& range) override;
- bool GetTextFromRange(const gfx::Range& range,
- base::string16* text) const override;
- void OnInputMethodChanged() override;
- bool ChangeTextDirectionAndLayoutAlignment(
- base::i18n::TextDirection direction) override;
- void ExtendSelectionAndDelete(size_t before, size_t after) override;
- void EnsureCaretInRect(const gfx::Rect& rect) override;
- bool IsEditCommandEnabled(int command_id) override;
- void SetEditCommandForNextKeyEvent(int command_id) override;
-
- // Overridden from FocusChangeListener.
- void OnWillChangeFocus(View* focused_before, View* focused) override;
- void OnDidChangeFocus(View* focused_before, View* focused) override;
-
- ui::InputMethod* GetHostInputMethod() const;
-
- private:
- class HostObserver;
-
- void UpdateViewFocusState();
-
- ui::InputMethod* host_;
-
- // An observer observing the host input method for cases that the host input
- // method is destroyed before this bridge input method.
- scoped_ptr<HostObserver> host_observer_;
-
- const bool shared_input_method_;
-
- DISALLOW_COPY_AND_ASSIGN(InputMethodBridge);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_IME_INPUT_METHOD_BRIDGE_H_
diff --git a/ui/views/ime/input_method_bridge_unittest.cc b/ui/views/ime/input_method_bridge_unittest.cc
deleted file mode 100644
index 5102645..0000000
--- a/ui/views/ime/input_method_bridge_unittest.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2013 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/aura/window.h"
-#include "ui/base/ime/dummy_input_method_delegate.h"
-#include "ui/base/ime/input_method_minimal.h"
-#include "ui/base/ime/text_input_client.h"
-#include "ui/views/ime/input_method.h"
-#include "ui/views/test/views_test_base.h"
-#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
-#include "ui/views/widget/native_widget_aura.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-typedef ViewsTestBase InputMethodBridgeTest;
-
-TEST_F(InputMethodBridgeTest, DestructTest) {
- ui::internal::DummyInputMethodDelegate input_method_delegate;
- ui::InputMethodMinimal input_method(&input_method_delegate);
-
- Widget* toplevel = new Widget;
- Widget::InitParams toplevel_params =
- CreateParams(Widget::InitParams::TYPE_WINDOW);
- // |child| owns |native_widget|.
- toplevel_params.native_widget = new DesktopNativeWidgetAura(toplevel);
- toplevel->Init(toplevel_params);
-
- Widget* child = new Widget;
- Widget::InitParams child_params =
- CreateParams(Widget::InitParams::TYPE_POPUP);
- child_params.parent = toplevel->GetNativeView();
- // |child| owns |native_widget|.
- child_params.native_widget = new NativeWidgetAura(child);
- child->Init(child_params);
-
- child->GetInputMethod()->OnFocus();
-
- toplevel->CloseNow();
-}
-
-} // namespace views
diff --git a/ui/views/ime/input_method_delegate.h b/ui/views/ime/input_method_delegate.h
deleted file mode 100644
index 59bc9dc..0000000
--- a/ui/views/ime/input_method_delegate.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// 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 UI_VIEWS_IME_INPUT_METHOD_DELEGATE_H_
-#define UI_VIEWS_IME_INPUT_METHOD_DELEGATE_H_
-
-#include "ui/views/views_export.h"
-
-namespace ui {
-class KeyEvent;
-}
-
-namespace views {
-
-namespace internal {
-
-// An interface implemented by the object that handles events sent back from an
-// InputMethod implementation.
-class VIEWS_EXPORT InputMethodDelegate {
- public:
- virtual ~InputMethodDelegate() {}
-
- // Dispatch a key event already processed by the input method.
- virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) = 0;
-};
-
-} // namespace internal
-} // namespace views
-
-#endif // UI_VIEWS_IME_INPUT_METHOD_DELEGATE_H_
diff --git a/ui/views/ime/mock_input_method.cc b/ui/views/ime/mock_input_method.cc
deleted file mode 100644
index a56c96a..0000000
--- a/ui/views/ime/mock_input_method.cc
+++ /dev/null
@@ -1,147 +0,0 @@
-// 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/mock_input_method.h"
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "ui/base/ime/text_input_client.h"
-#include "ui/events/event.h"
-#include "ui/events/keycodes/keyboard_codes.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-MockInputMethod::MockInputMethod()
- : untranslated_ime_message_called_(false),
- text_input_type_changed_(false),
- cancel_composition_called_(false) {
-}
-
-MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
- : untranslated_ime_message_called_(false),
- text_input_type_changed_(false),
- cancel_composition_called_(false) {
- SetDelegate(delegate);
-}
-
-MockInputMethod::~MockInputMethod() {
-}
-
-void MockInputMethod::OnFocus() {}
-
-void MockInputMethod::OnBlur() {}
-
-bool MockInputMethod::OnUntranslatedIMEMessage(
- const base::NativeEvent& event,
- NativeEventResult* result) {
- untranslated_ime_message_called_ = true;
- if (result)
- *result = InputMethod::NativeEventResult();
- return false;
-}
-
-void MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) {
- bool handled = !IsTextInputTypeNone() && HasComposition();
-
- ClearStates();
- if (handled) {
- DCHECK(!key.is_char());
- ui::KeyEvent mock_key(ui::ET_KEY_PRESSED,
- ui::VKEY_PROCESSKEY,
- key.flags());
- DispatchKeyEventPostIME(mock_key);
- } else {
- DispatchKeyEventPostIME(key);
- }
-
- ui::TextInputClient* client = GetTextInputClient();
- if (client) {
- if (handled) {
- if (result_text_.length())
- client->InsertText(result_text_);
- if (composition_.text.length())
- client->SetCompositionText(composition_);
- else
- client->ClearCompositionText();
- } else if (key.type() == ui::ET_KEY_PRESSED) {
- base::char16 ch = key.GetCharacter();
- client->InsertChar(ch, key.flags());
- }
- }
-
- ClearComposition();
-}
-
-void MockInputMethod::OnTextInputTypeChanged(View* view) {
- if (IsViewFocused(view))
- text_input_type_changed_ = true;
- InputMethodBase::OnTextInputTypeChanged(view);
-}
-
-void MockInputMethod::OnCaretBoundsChanged(View* view) {
-}
-
-void MockInputMethod::CancelComposition(View* view) {
- if (IsViewFocused(view)) {
- cancel_composition_called_ = true;
- ClearComposition();
- }
-}
-
-void MockInputMethod::OnInputLocaleChanged() {
-}
-
-std::string MockInputMethod::GetInputLocale() {
- return "en-US";
-}
-
-bool MockInputMethod::IsActive() {
- return true;
-}
-
-bool MockInputMethod::IsCandidatePopupOpen() const {
- return false;
-}
-
-void MockInputMethod::ShowImeIfNeeded() {
-}
-
-void MockInputMethod::OnWillChangeFocus(View* focused_before, View* focused) {
- ui::TextInputClient* client = GetTextInputClient();
- if (client && client->HasCompositionText())
- client->ConfirmCompositionText();
- ClearComposition();
-}
-
-void MockInputMethod::Clear() {
- ClearStates();
- ClearComposition();
-}
-
-void MockInputMethod::SetCompositionTextForNextKey(
- const ui::CompositionText& composition) {
- composition_ = composition;
-}
-
-void MockInputMethod::SetResultTextForNextKey(const base::string16& result) {
- result_text_ = result;
-}
-
-void MockInputMethod::ClearStates() {
- untranslated_ime_message_called_ = false;
- text_input_type_changed_ = false;
- cancel_composition_called_ = false;
-}
-
-bool MockInputMethod::HasComposition() {
- return composition_.text.length() || result_text_.length();
-}
-
-void MockInputMethod::ClearComposition() {
- composition_.Clear();
- result_text_.clear();
-}
-
-} // namespace views
diff --git a/ui/views/ime/mock_input_method.h b/ui/views/ime/mock_input_method.h
deleted file mode 100644
index ddee3c2..0000000
--- a/ui/views/ime/mock_input_method.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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 UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
-#define UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ui/base/ime/composition_text.h"
-#include "ui/views/ime/input_method_base.h"
-#include "ui/views/view.h"
-
-namespace views {
-
-// A mock InputMethod implementation for testing purpose.
-class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
- public:
- MockInputMethod();
- explicit MockInputMethod(internal::InputMethodDelegate* delegate);
- ~MockInputMethod() override;
-
- // Overridden from InputMethod:
- void OnFocus() override;
- void OnBlur() override;
- bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
- NativeEventResult* result) override;
- void DispatchKeyEvent(const ui::KeyEvent& key) override;
- void OnTextInputTypeChanged(View* view) override;
- void OnCaretBoundsChanged(View* view) override;
- void CancelComposition(View* view) override;
- void OnInputLocaleChanged() override;
- std::string GetInputLocale() override;
- bool IsActive() override;
- bool IsCandidatePopupOpen() const override;
- void ShowImeIfNeeded() override;
-
- bool untranslated_ime_message_called() const {
- return untranslated_ime_message_called_;
- }
- bool text_input_type_changed() const { return text_input_type_changed_; }
- bool cancel_composition_called() const { return cancel_composition_called_; }
-
- // Clears all internal states and result.
- void Clear();
-
- void SetCompositionTextForNextKey(const ui::CompositionText& composition);
- void SetResultTextForNextKey(const base::string16& result);
-
- private:
- // Overridden from InputMethodBase.
- void OnWillChangeFocus(View* focused_before, View* focused) override;
-
- // Clears boolean states defined below.
- void ClearStates();
-
- // Whether a mock composition or result is scheduled for the next key event.
- bool HasComposition();
-
- // Clears only composition information and result text.
- void ClearComposition();
-
- // Composition information for the next key event. It'll be cleared
- // automatically after dispatching the next key event.
- ui::CompositionText composition_;
-
- // Result text for the next key event. It'll be cleared automatically after
- // dispatching the next key event.
- base::string16 result_text_;
-
- // Record call state of corresponding methods. They will be set to false
- // automatically before dispatching a key event.
- bool untranslated_ime_message_called_;
- bool text_input_type_changed_;
- bool cancel_composition_called_;
-
- DISALLOW_COPY_AND_ASSIGN(MockInputMethod);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
diff --git a/ui/views/ime/null_input_method.cc b/ui/views/ime/null_input_method.cc
deleted file mode 100644
index d98988c..0000000
--- a/ui/views/ime/null_input_method.cc
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2014 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/null_input_method.h"
-
-namespace views {
-
-NullInputMethod::NullInputMethod() {}
-
-void NullInputMethod::SetDelegate(
- internal::InputMethodDelegate* /* delegate */) {}
-
-void NullInputMethod::Init(Widget* /* widget */) {}
-
-void NullInputMethod::OnFocus() {}
-
-void NullInputMethod::OnBlur() {}
-
-bool NullInputMethod::OnUntranslatedIMEMessage(
- const base::NativeEvent& /* event */,
- NativeEventResult* /* result */) {
- return false;
-}
-
-void NullInputMethod::DispatchKeyEvent(const ui::KeyEvent& /* key */) {}
-
-void NullInputMethod::OnTextInputTypeChanged(View* /* view */) {}
-
-void NullInputMethod::OnCaretBoundsChanged(View* /* view */) {}
-
-void NullInputMethod::CancelComposition(View* /* view */) {}
-
-void NullInputMethod::OnInputLocaleChanged() {}
-
-std::string NullInputMethod::GetInputLocale() {
- return std::string();
-}
-
-bool NullInputMethod::IsActive() {
- return false;
-}
-
-ui::TextInputClient* NullInputMethod::GetTextInputClient() const {
- return NULL;
-}
-
-ui::TextInputType NullInputMethod::GetTextInputType() const {
- return ui::TEXT_INPUT_TYPE_NONE;
-}
-
-bool NullInputMethod::IsCandidatePopupOpen() const {
- return false;
-}
-
-void NullInputMethod::ShowImeIfNeeded() {}
-
-} // namespace views
diff --git a/ui/views/ime/null_input_method.h b/ui/views/ime/null_input_method.h
deleted file mode 100644
index 83980c3..0000000
--- a/ui/views/ime/null_input_method.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2014 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 UI_VIEWS_IME_NULL_INPUT_METHOD_H_
-#define UI_VIEWS_IME_NULL_INPUT_METHOD_H_
-
-#include "base/compiler_specific.h"
-#include "base/macros.h"
-#include "ui/views/ime/input_method.h"
-
-namespace views {
-
-// An implementation of views::InputMethod which does nothing.
-//
-// We're working on removing views::InputMethod{,Base,Bridge} and going to use
-// only ui::InputMethod. Use this class instead of views::InputMethodBridge
-// with ui::TextInputFocusManager to effectively eliminate the
-// views::InputMethod layer.
-class NullInputMethod : public InputMethod {
- public:
- NullInputMethod();
-
- // Overridden from InputMethod:
- void SetDelegate(internal::InputMethodDelegate* delegate) override;
- void Init(Widget* widget) override;
- void OnFocus() override;
- void OnBlur() override;
- bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
- NativeEventResult* result) override;
- void DispatchKeyEvent(const ui::KeyEvent& key) override;
- void OnTextInputTypeChanged(View* view) override;
- void OnCaretBoundsChanged(View* view) override;
- void CancelComposition(View* view) override;
- void OnInputLocaleChanged() override;
- std::string GetInputLocale() override;
- bool IsActive() override;
- ui::TextInputClient* GetTextInputClient() const override;
- ui::TextInputType GetTextInputType() const override;
- bool IsCandidatePopupOpen() const override;
- void ShowImeIfNeeded() override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(NullInputMethod);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_IME_NULL_INPUT_METHOD_H_
diff --git a/ui/views/test/widget_test.h b/ui/views/test/widget_test.h
index 16cf492..41a2647 100644
--- a/ui/views/test/widget_test.h
+++ b/ui/views/test/widget_test.h
@@ -18,6 +18,9 @@
#endif
namespace ui {
+namespace internal {
+class InputMethodDelegate;
+}
class EventProcessor;
}
@@ -130,6 +133,10 @@ class WidgetTest : public ViewsTestBase {
// processor.
static ui::EventProcessor* GetEventProcessor(Widget* widget);
+ // Get the InputMethodDelegate, for setting on a Mock InputMethod in tests.
+ static ui::internal::InputMethodDelegate* GetInputMethodDelegateForWidget(
+ Widget* widget);
+
#if defined(OS_MACOSX)
static scoped_ptr<FakeActivation> FakeWidgetIsActiveAlways();
#endif
diff --git a/ui/views/test/widget_test_aura.cc b/ui/views/test/widget_test_aura.cc
index 2542607..502d7d0 100644
--- a/ui/views/test/widget_test_aura.cc
+++ b/ui/views/test/widget_test_aura.cc
@@ -104,5 +104,11 @@ ui::EventProcessor* WidgetTest::GetEventProcessor(Widget* widget) {
return widget->GetNativeWindow()->GetHost()->event_processor();
}
+// static
+ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget(
+ Widget* widget) {
+ return widget->GetNativeWindow()->GetRootWindow()->GetHost();
+}
+
} // namespace test
} // namespace views
diff --git a/ui/views/test/widget_test_mac.mm b/ui/views/test/widget_test_mac.mm
index c6608ae..628655f 100644
--- a/ui/views/test/widget_test_mac.mm
+++ b/ui/views/test/widget_test_mac.mm
@@ -8,6 +8,7 @@
#import "base/mac/scoped_nsobject.h"
#import "base/mac/scoped_objc_class_swizzler.h"
+#import "ui/views/cocoa/bridged_native_widget.h"
#include "ui/views/widget/root_view.h"
@interface IsKeyWindowDonor : NSObject
@@ -108,5 +109,11 @@ scoped_ptr<WidgetTest::FakeActivation> WidgetTest::FakeWidgetIsActiveAlways() {
return make_scoped_ptr(new FakeActivationMac);
}
+// static
+ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget(
+ Widget* widget) {
+ return NativeWidgetMac::GetBridgeForNativeWindow(widget->GetNativeWindow());
+}
+
} // namespace test
} // namespace views
diff --git a/ui/views/view.cc b/ui/views/view.cc
index a072426..07b8201 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -19,6 +19,7 @@
#include "ui/accessibility/ax_enums.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/dragdrop/drag_drop_types.h"
+#include "ui/base/ime/input_method.h"
#include "ui/compositor/clip_transform_recorder.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/dip_util.h"
@@ -1010,18 +1011,10 @@ void View::OnTouchEvent(ui::TouchEvent* event) {
void View::OnGestureEvent(ui::GestureEvent* event) {
}
-ui::TextInputClient* View::GetTextInputClient() {
- return NULL;
-}
-
-InputMethod* View::GetInputMethod() {
- Widget* widget = GetWidget();
- return widget ? widget->GetInputMethod() : NULL;
-}
-
-const InputMethod* View::GetInputMethod() const {
- const Widget* widget = GetWidget();
- return widget ? widget->GetInputMethod() : NULL;
+const ui::InputMethod* View::GetInputMethod() const {
+ Widget* widget = const_cast<Widget*>(GetWidget());
+ return widget ? const_cast<const ui::InputMethod*>(widget->GetInputMethod())
+ : nullptr;
}
scoped_ptr<ViewTargeter>
diff --git a/ui/views/view.h b/ui/views/view.h
index 7e3183e..9447c1f 100644
--- a/ui/views/view.h
+++ b/ui/views/view.h
@@ -50,6 +50,7 @@ class Transform;
namespace ui {
struct AXViewState;
class Compositor;
+class InputMethod;
class Layer;
class NativeTheme;
class PaintContext;
@@ -66,7 +67,6 @@ class ContextMenuController;
class DragController;
class FocusManager;
class FocusTraversable;
-class InputMethod;
class LayoutManager;
class NativeViewAccessibility;
class ScrollView;
@@ -692,15 +692,13 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
return notify_enter_exit_on_child_;
}
- // Returns the View's TextInputClient instance or NULL if the View doesn't
- // support text input.
- virtual ui::TextInputClient* GetTextInputClient();
-
// Convenience method to retrieve the InputMethod associated with the
- // Widget that contains this view. Returns NULL if this view is not part of a
- // view hierarchy with a Widget.
- virtual InputMethod* GetInputMethod();
- virtual const InputMethod* GetInputMethod() const;
+ // Widget that contains this view.
+ ui::InputMethod* GetInputMethod() {
+ return const_cast<ui::InputMethod*>(
+ const_cast<const View*>(this)->GetInputMethod());
+ }
+ const ui::InputMethod* GetInputMethod() const;
// Sets a new ViewTargeter for the view, and returns the previous
// ViewTargeter.
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index bde2e88..3f41be1 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -223,16 +223,6 @@
'focus/view_storage.h',
'focus/widget_focus_manager.cc',
'focus/widget_focus_manager.h',
- 'ime/input_method.h',
- 'ime/input_method_base.cc',
- 'ime/input_method_base.h',
- 'ime/input_method_bridge.cc',
- 'ime/input_method_bridge.h',
- 'ime/input_method_delegate.h',
- 'ime/mock_input_method.cc',
- 'ime/mock_input_method.h',
- 'ime/null_input_method.cc',
- 'ime/null_input_method.h',
'layout/box_layout.cc',
'layout/box_layout.h',
'layout/fill_layout.cc',
@@ -576,7 +566,6 @@
'window/dialog_delegate_unittest.cc',
],
'views_unittests_desktop_sources': [
- 'ime/input_method_bridge_unittest.cc',
'widget/desktop_widget_unittest.cc',
],
'views_unittests_aura_sources': [
@@ -902,7 +891,6 @@
'sources!': [
'bubble/bubble_window_targeter_unittest.cc',
'controls/native/native_view_host_unittest.cc',
- 'ime/input_method_bridge_unittest.cc',
'widget/window_reorderer_unittest.cc',
]
}],
diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
index cbe70fa..466f98e 100644
--- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
+++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
@@ -27,8 +27,6 @@
#include "ui/views/corewm/tooltip.h"
#include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/drag_utils.h"
-#include "ui/views/ime/input_method_bridge.h"
-#include "ui/views/ime/null_input_method.h"
#include "ui/views/view_constants_aura.h"
#include "ui/views/widget/desktop_aura/desktop_capture_client.h"
#include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
@@ -385,7 +383,7 @@ void DesktopNativeWidgetAura::HandleActivationChanged(bool active) {
view_for_activation->GetWidget()->GetNativeView());
// Refreshes the focus info to IMF in case that IMF cached the old info
// about focused text input client when it was "inactive".
- GetHostInputMethod()->OnFocus();
+ GetInputMethod()->OnFocus();
}
} else {
// If we're not active we need to deactivate the corresponding
@@ -395,7 +393,7 @@ void DesktopNativeWidgetAura::HandleActivationChanged(bool active) {
aura::Window* active_window = activation_client->GetActiveWindow();
if (active_window) {
activation_client->DeactivateWindow(active_window);
- GetHostInputMethod()->OnBlur();
+ GetInputMethod()->OnBlur();
}
}
}
@@ -633,17 +631,8 @@ bool DesktopNativeWidgetAura::HasCapture() const {
desktop_window_tree_host_->HasCapture();
}
-InputMethod* DesktopNativeWidgetAura::CreateInputMethod() {
- return new InputMethodBridge(this, GetHostInputMethod(), false);
-}
-
-internal::InputMethodDelegate*
- DesktopNativeWidgetAura::GetInputMethodDelegate() {
- return this;
-}
-
-ui::InputMethod* DesktopNativeWidgetAura::GetHostInputMethod() {
- return host()->GetInputMethod();
+ui::InputMethod* DesktopNativeWidgetAura::GetInputMethod() {
+ return host() ? host()->GetInputMethod() : nullptr;
}
void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) {
@@ -1133,13 +1122,6 @@ void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
if (content_window_ == gained_focus) {
desktop_window_tree_host_->OnNativeWidgetFocus();
native_widget_delegate_->OnNativeFocus();
-
- // If focus is moving from a descendant Window to |content_window_| then
- // native activation hasn't changed. Still, the InputMethod must be informed
- // of the Window focus change.
- InputMethod* input_method = GetWidget()->GetInputMethod();
- if (input_method)
- input_method->OnFocus();
} else if (content_window_ == lost_focus) {
desktop_window_tree_host_->OnNativeWidgetBlur();
native_widget_delegate_->OnNativeBlur();
@@ -1147,18 +1129,6 @@ void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
}
////////////////////////////////////////////////////////////////////////////////
-// DesktopNativeWidgetAura, views::internal::InputMethodDelegate:
-
-void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
- FocusManager* focus_manager =
- native_widget_delegate_->AsWidget()->GetFocusManager();
- native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
- if (key.handled() || !focus_manager)
- return;
- focus_manager->OnKeyEvent(key);
-}
-
-////////////////////////////////////////////////////////////////////////////////
// DesktopNativeWidgetAura, aura::WindowDragDropDelegate implementation:
void DesktopNativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) {
diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.h b/ui/views/widget/desktop_aura/desktop_native_widget_aura.h
index 26895ff..0b67073 100644
--- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.h
+++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.h
@@ -10,7 +10,6 @@
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_tree_host_observer.h"
#include "ui/base/cursor/cursor.h"
-#include "ui/views/ime/input_method_delegate.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/public/activation_change_observer.h"
@@ -32,7 +31,6 @@ namespace wm {
class CompoundEventFilter;
class CursorManager;
class FocusController;
-class InputMethodEventFilter;
class ShadowController;
class VisibilityController;
class WindowModalityController;
@@ -58,7 +56,6 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
public aura::client::ActivationDelegate,
public aura::client::ActivationChangeObserver,
public aura::client::FocusChangeObserver,
- public views::internal::InputMethodDelegate,
public aura::client::DragDropDelegate,
public aura::WindowTreeHostObserver {
public:
@@ -112,9 +109,7 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
void SetCapture() override;
void ReleaseCapture() override;
bool HasCapture() const override;
- InputMethod* CreateInputMethod() override;
- internal::InputMethodDelegate* GetInputMethodDelegate() override;
- ui::InputMethod* GetHostInputMethod() override;
+ ui::InputMethod* GetInputMethod() override;
void CenterWindow(const gfx::Size& size) override;
void GetWindowPlacement(gfx::Rect* bounds,
ui::WindowShowState* maximized) const override;
@@ -219,9 +214,6 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override;
- // Overridden from views::internal::InputMethodDelegate:
- void DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
-
// Overridden from aura::client::DragDropDelegate:
void OnDragEntered(const ui::DropTargetEvent& event) override;
int OnDragUpdated(const ui::DropTargetEvent& event) override;
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
index b560d97..93b3c5b 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
@@ -26,7 +26,6 @@
#include "ui/native_theme/native_theme_aura.h"
#include "ui/native_theme/native_theme_win.h"
#include "ui/views/corewm/tooltip_win.h"
-#include "ui/views/ime/input_method_bridge.h"
#include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h"
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index bce1086..a56deb7 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -40,7 +40,6 @@
#include "ui/gfx/screen.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/corewm/tooltip_aura.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/views_delegate.h"
#include "ui/views/views_switches.h"
@@ -908,12 +907,9 @@ void DesktopWindowTreeHostX11::OnRootViewLayout() {
}
void DesktopWindowTreeHostX11::OnNativeWidgetFocus() {
- native_widget_delegate_->AsWidget()->GetInputMethod()->OnFocus();
}
void DesktopWindowTreeHostX11::OnNativeWidgetBlur() {
- if (xwindow_)
- native_widget_delegate_->AsWidget()->GetInputMethod()->OnBlur();
}
bool DesktopWindowTreeHostX11::IsAnimatingClosed() const {
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_interactive_uitest.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_interactive_uitest.cc
index 3876873..3d06653 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_interactive_uitest.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_interactive_uitest.cc
@@ -15,6 +15,7 @@
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/base/x/x11_util.h"
@@ -24,7 +25,6 @@
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gl/gl_surface.h"
#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/x11_property_change_waiter.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
@@ -262,8 +262,10 @@ TEST_F(DesktopWindowTreeHostX11Test, InputMethodFocus) {
textfield->RequestFocus();
EXPECT_FALSE(widget->IsActive());
- EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
- widget->GetInputMethod()->GetTextInputType());
+ // TODO(shuchen): uncomment the below check once the
+ // "default-focused-input-method" logic is removed in aura::WindowTreeHost.
+ //EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
+ // widget->GetInputMethod()->GetTextInputType());
widget->Activate();
diff --git a/ui/views/widget/desktop_aura/x11_desktop_handler.cc b/ui/views/widget/desktop_aura/x11_desktop_handler.cc
index b7ca334..70aa47d 100644
--- a/ui/views/widget/desktop_aura/x11_desktop_handler.cc
+++ b/ui/views/widget/desktop_aura/x11_desktop_handler.cc
@@ -15,7 +15,6 @@
#include "ui/base/x/x11_util.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/x/x11_error_tracker.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
namespace {
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index 1e195f6..c6c6819 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -26,8 +26,7 @@
#include "ui/gfx/screen.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/views/drag_utils.h"
-#include "ui/views/ime/input_method_bridge.h"
-#include "ui/views/ime/null_input_method.h"
+#include "ui/views/views_delegate.h"
#include "ui/views/widget/drop_helper.h"
#include "ui/views/widget/native_widget_delegate.h"
#include "ui/views/widget/root_view.h"
@@ -266,20 +265,11 @@ bool NativeWidgetAura::HasCapture() const {
return window_ && window_->HasCapture();
}
-InputMethod* NativeWidgetAura::CreateInputMethod() {
+ui::InputMethod* NativeWidgetAura::GetInputMethod() {
if (!window_)
- return NULL;
-
- return new InputMethodBridge(this, GetHostInputMethod(), true);
-}
-
-internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() {
- return this;
-}
-
-ui::InputMethod* NativeWidgetAura::GetHostInputMethod() {
+ return nullptr;
aura::Window* root_window = window_->GetRootWindow();
- return root_window->GetHost()->GetInputMethod();
+ return root_window ? root_window->GetHost()->GetInputMethod() : nullptr;
}
void NativeWidgetAura::CenterWindow(const gfx::Size& size) {
@@ -726,17 +716,6 @@ void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) {
}
////////////////////////////////////////////////////////////////////////////////
-// NativeWidgetAura, views::InputMethodDelegate implementation:
-
-void NativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
- FocusManager* focus_manager = GetWidget()->GetFocusManager();
- delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
- if (key.handled() || !focus_manager)
- return;
- focus_manager->OnKeyEvent(key);
-}
-
-////////////////////////////////////////////////////////////////////////////////
// NativeWidgetAura, aura::WindowDelegate implementation:
gfx::Size NativeWidgetAura::GetMinimumSize() const {
@@ -870,21 +849,15 @@ void NativeWidgetAura::OnWindowPropertyChanged(aura::Window* window,
void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
DCHECK(window_);
- if (event->is_char()) {
- // If a ui::InputMethod object is attached to the root window, character
- // events are handled inside the object and are not passed to this function.
- // If such object is not attached, character events might be sent (e.g. on
- // Windows). In this case, we just skip these.
- return;
- }
// Renderer may send a key event back to us if the key event wasn't handled,
// and the window may be invisible by that time.
if (!window_->IsVisible())
return;
- InputMethod* input_method = GetWidget()->GetInputMethod();
- if (!input_method)
- return;
- input_method->DispatchKeyEvent(*event);
+
+ FocusManager* focus_manager = GetWidget()->GetFocusManager();
+ delegate_->OnKeyEvent(event);
+ if (!event->handled() && focus_manager)
+ focus_manager->OnKeyEvent(*event);
event->SetHandled();
}
@@ -942,29 +915,10 @@ void NativeWidgetAura::OnWindowActivated(
void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) {
- if (window_ == gained_focus) {
- // In aura, it is possible for child native widgets to take input and focus,
- // this differs from the behavior on windows.
- if (GetWidget()->GetInputMethod()) // Null in tests.
- GetWidget()->GetInputMethod()->OnFocus();
+ if (window_ == gained_focus)
delegate_->OnNativeFocus();
- } else if (window_ == lost_focus) {
- // GetInputMethod() recreates the input method if it's previously been
- // destroyed. If we get called during destruction, the input method will be
- // gone, and creating a new one and telling it that we lost the focus will
- // trigger a DCHECK (the new input method doesn't think that we have the
- // focus and doesn't expect a blur). OnBlur() shouldn't be called during
- // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the
- // case in tests).
- if (!destroying_) {
- if (GetWidget()->GetInputMethod())
- GetWidget()->GetInputMethod()->OnBlur();
- } else {
- DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
- }
-
+ else if (window_ == lost_focus)
delegate_->OnNativeBlur();
- }
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h
index 11ae749..b849017 100644
--- a/ui/views/widget/native_widget_aura.h
+++ b/ui/views/widget/native_widget_aura.h
@@ -12,7 +12,6 @@
#include "ui/aura/window_observer.h"
#include "ui/base/cursor/cursor.h"
#include "ui/events/event_constants.h"
-#include "ui/views/ime/input_method_delegate.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/wm/public/activation_change_observer.h"
@@ -34,7 +33,6 @@ class WindowReorderer;
class VIEWS_EXPORT NativeWidgetAura
: public internal::NativeWidgetPrivate,
- public internal::InputMethodDelegate,
public aura::WindowDelegate,
public aura::WindowObserver,
public aura::client::ActivationDelegate,
@@ -71,9 +69,7 @@ class VIEWS_EXPORT NativeWidgetAura
void SetCapture() override;
void ReleaseCapture() override;
bool HasCapture() const override;
- InputMethod* CreateInputMethod() override;
- internal::InputMethodDelegate* GetInputMethodDelegate() override;
- ui::InputMethod* GetHostInputMethod() override;
+ ui::InputMethod* GetInputMethod() override;
void CenterWindow(const gfx::Size& size) override;
void GetWindowPlacement(gfx::Rect* bounds,
ui::WindowShowState* maximized) const override;
@@ -138,9 +134,6 @@ class VIEWS_EXPORT NativeWidgetAura
void OnSizeConstraintsChanged() override;
void RepostNativeEvent(gfx::NativeEvent native_event) override;
- // Overridden from views::InputMethodDelegate:
- void DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
-
// Overridden from aura::WindowDelegate:
gfx::Size GetMinimumSize() const override;
gfx::Size GetMaximumSize() const override;
diff --git a/ui/views/widget/native_widget_delegate.h b/ui/views/widget/native_widget_delegate.h
index 4f5ed9e..224972c 100644
--- a/ui/views/widget/native_widget_delegate.h
+++ b/ui/views/widget/native_widget_delegate.h
@@ -28,7 +28,6 @@ class TouchEvent;
}
namespace views {
-class InputMethod;
class Widget;
namespace internal {
@@ -125,11 +124,6 @@ class VIEWS_EXPORT NativeWidgetDelegate {
// Runs the specified native command. Returns true if the command is handled.
virtual bool ExecuteCommand(int command_id) = 0;
- // Returns the input method of the widget this delegate is associated with.
- // Note that this does not use the top level widget, so may return NULL
- // if the widget doesn't have input method.
- virtual InputMethod* GetInputMethodDirect() = 0;
-
// Returns the child Layers of the Widgets layer that were created by Views.
virtual const std::vector<ui::Layer*>& GetRootLayers() = 0;
diff --git a/ui/views/widget/native_widget_mac.h b/ui/views/widget/native_widget_mac.h
index 6d3c84b..b050a4b 100644
--- a/ui/views/widget/native_widget_mac.h
+++ b/ui/views/widget/native_widget_mac.h
@@ -57,9 +57,7 @@ class VIEWS_EXPORT NativeWidgetMac : public internal::NativeWidgetPrivate {
void SetCapture() override;
void ReleaseCapture() override;
bool HasCapture() const override;
- InputMethod* CreateInputMethod() override;
- internal::InputMethodDelegate* GetInputMethodDelegate() override;
- ui::InputMethod* GetHostInputMethod() override;
+ ui::InputMethod* GetInputMethod() override;
void CenterWindow(const gfx::Size& size) override;
void GetWindowPlacement(gfx::Rect* bounds,
ui::WindowShowState* show_state) const override;
diff --git a/ui/views/widget/native_widget_mac.mm b/ui/views/widget/native_widget_mac.mm
index 0cd870c..63465a8 100644
--- a/ui/views/widget/native_widget_mac.mm
+++ b/ui/views/widget/native_widget_mac.mm
@@ -213,16 +213,8 @@ bool NativeWidgetMac::HasCapture() const {
return bridge_ && bridge_->HasCapture();
}
-InputMethod* NativeWidgetMac::CreateInputMethod() {
- return bridge_ ? bridge_->CreateInputMethod() : NULL;
-}
-
-internal::InputMethodDelegate* NativeWidgetMac::GetInputMethodDelegate() {
- return bridge_.get();
-}
-
-ui::InputMethod* NativeWidgetMac::GetHostInputMethod() {
- return bridge_ ? bridge_->GetHostInputMethod() : NULL;
+ui::InputMethod* NativeWidgetMac::GetInputMethod() {
+ return bridge_ ? bridge_->GetInputMethod() : NULL;
}
void NativeWidgetMac::CenterWindow(const gfx::Size& size) {
diff --git a/ui/views/widget/native_widget_private.h b/ui/views/widget/native_widget_private.h
index bee16b2..2adf589 100644
--- a/ui/views/widget/native_widget_private.h
+++ b/ui/views/widget/native_widget_private.h
@@ -23,10 +23,8 @@ class OSExchangeData;
}
namespace views {
-class InputMethod;
class TooltipManager;
namespace internal {
-class InputMethodDelegate;
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetPrivate interface
@@ -133,19 +131,8 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
// Returns true if this native widget is capturing events.
virtual bool HasCapture() const = 0;
- // Returns the InputMethod for this native widget.
- // Note that all widgets in a widget hierarchy share the same input method.
- // TODO(suzhe): rename to GetInputMethod() when NativeWidget implementation
- // class doesn't inherit Widget anymore.
- virtual InputMethod* CreateInputMethod() = 0;
-
- // Returns the InputMethodDelegate for this native widget.
- virtual InputMethodDelegate* GetInputMethodDelegate() = 0;
-
// Returns the ui::InputMethod for this native widget.
- // TODO(yukishiino): Rename this method to GetInputMethod once we remove
- // views::InputMethod.
- virtual ui::InputMethod* GetHostInputMethod() = 0;
+ virtual ui::InputMethod* GetInputMethod() = 0;
// Centers the window and sizes it to the specified size.
virtual void CenterWindow(const gfx::Size& size) = 0;
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index a573920..8baea97 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -11,6 +11,7 @@
#include "ui/base/cursor/cursor.h"
#include "ui/base/default_theme_provider.h"
#include "ui/base/hit_test.h"
+#include "ui/base/ime/input_method.h"
#include "ui/base/l10n/l10n_font_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/compositor.h"
@@ -24,7 +25,6 @@
#include "ui/views/focus/focus_manager_factory.h"
#include "ui/views/focus/view_storage.h"
#include "ui/views/focus/widget_focus_manager.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget_private.h"
#include "ui/views/widget/root_view.h"
@@ -64,6 +64,14 @@ NativeWidget* CreateNativeWidget(NativeWidget* native_widget,
return native_widget;
}
+void NotifyCaretBoundsChanged(ui::InputMethod* input_method) {
+ if (!input_method)
+ return;
+ ui::TextInputClient* client = input_method->GetTextInputClient();
+ if (client)
+ input_method->OnCaretBoundsChanged(client);
+}
+
} // namespace
// A default implementation of WidgetDelegate, used by Widget when no
@@ -764,36 +772,25 @@ const FocusManager* Widget::GetFocusManager() const {
}
ui::TextInputClient* Widget::GetFocusedTextInputClient() {
- FocusManager* focus_manager = GetFocusManager();
- View* view = focus_manager ? focus_manager->GetFocusedView() : nullptr;
- return view ? view->GetTextInputClient() : nullptr;
-}
-
-InputMethod* Widget::GetInputMethod() {
- return const_cast<InputMethod*>(
- const_cast<const Widget*>(this)->GetInputMethod());
+ return nullptr;
}
-const InputMethod* Widget::GetInputMethod() const {
+ui::InputMethod* Widget::GetInputMethod() {
if (is_top_level()) {
- if (!input_method_.get())
- input_method_ = const_cast<Widget*>(this)->CreateInputMethod().Pass();
- return input_method_.get();
+ // Only creates the shared the input method instance on top level widget.
+ return native_widget_private()->GetInputMethod();
} else {
- const Widget* toplevel = GetTopLevelWidget();
+ Widget* toplevel = GetTopLevelWidget();
// If GetTopLevelWidget() returns itself which is not toplevel,
// the widget is detached from toplevel widget.
// TODO(oshima): Fix GetTopLevelWidget() to return NULL
// if there is no toplevel. We probably need to add GetTopMostWidget()
// to replace some use cases.
- return (toplevel && toplevel != this) ? toplevel->GetInputMethod() : NULL;
+ return (toplevel && toplevel != this) ? toplevel->GetInputMethod()
+ : nullptr;
}
}
-ui::InputMethod* Widget::GetHostInputMethod() {
- return native_widget_private()->GetHostInputMethod();
-}
-
void Widget::RunShellDrag(View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
@@ -1115,12 +1112,8 @@ gfx::Size Widget::GetMaximumSize() const {
void Widget::OnNativeWidgetMove() {
widget_delegate_->OnWidgetMove();
- View* root = GetRootView();
- if (root && root->GetFocusManager()) {
- View* focused_view = root->GetFocusManager()->GetFocusedView();
- if (focused_view && focused_view->GetInputMethod())
- focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
- }
+ NotifyCaretBoundsChanged(GetInputMethod());
+
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
this,
GetWindowBoundsInScreen()));
@@ -1128,14 +1121,10 @@ void Widget::OnNativeWidgetMove() {
void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
View* root = GetRootView();
- if (root) {
+ if (root)
root->SetSize(new_size);
- if (root->GetFocusManager()) {
- View* focused_view = GetRootView()->GetFocusManager()->GetFocusedView();
- if (focused_view && focused_view->GetInputMethod())
- focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
- }
- }
+
+ NotifyCaretBoundsChanged(GetInputMethod());
SaveWindowPlacementIfInitialized();
FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
@@ -1294,10 +1283,6 @@ bool Widget::ExecuteCommand(int command_id) {
return widget_delegate_->ExecuteWindowsCommand(command_id);
}
-InputMethod* Widget::GetInputMethodDirect() {
- return input_method_.get();
-}
-
const std::vector<ui::Layer*>& Widget::GetRootLayers() {
if (root_layers_dirty_) {
root_layers_dirty_ = false;
@@ -1391,8 +1376,6 @@ internal::RootView* Widget::CreateRootView() {
void Widget::DestroyRootView() {
non_client_view_ = NULL;
root_view_.reset();
- // Input method has to be destroyed before focus manager.
- input_method_.reset();
}
void Widget::OnDragWillStart() {
@@ -1500,19 +1483,6 @@ bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds,
return false;
}
-scoped_ptr<InputMethod> Widget::CreateInputMethod() {
- scoped_ptr<InputMethod> input_method(native_widget_->CreateInputMethod());
- if (input_method.get())
- input_method->Init(this);
- return input_method.Pass();
-}
-
-void Widget::ReplaceInputMethod(InputMethod* input_method) {
- input_method_.reset(input_method);
- input_method->SetDelegate(native_widget_->GetInputMethodDelegate());
- input_method->Init(this);
-}
-
namespace internal {
////////////////////////////////////////////////////////////////////////////////
diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h
index b418a47..d4e06d8 100644
--- a/ui/views/widget/widget.h
+++ b/ui/views/widget/widget.h
@@ -60,7 +60,6 @@ class ThemeProvider;
namespace views {
class DesktopWindowTreeHost;
-class InputMethod;
class NativeWidget;
class NonClientFrameView;
class TooltipManager;
@@ -569,15 +568,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// Returns the focused text input client within this widget.
ui::TextInputClient* GetFocusedTextInputClient();
- // Returns the InputMethod for this widget.
- // Note that all widgets in a widget hierarchy share the same input method.
- InputMethod* GetInputMethod();
- const InputMethod* GetInputMethod() const;
-
// Returns the ui::InputMethod for this widget.
- // TODO(yukishiino): Rename this method to GetInputMethod once we remove
- // views::InputMethod.
- ui::InputMethod* GetHostInputMethod();
+ ui::InputMethod* GetInputMethod();
// Starts a drag operation for the specified view. This blocks until the drag
// operation completes. |view| can be NULL.
@@ -802,7 +794,6 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
void OnScrollEvent(ui::ScrollEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
bool ExecuteCommand(int command_id) override;
- InputMethod* GetInputMethodDirect() override;
const std::vector<ui::Layer*>& GetRootLayers() override;
bool HasHitTestMask() const override;
void GetHitTestMask(gfx::Path* mask) const override;
@@ -866,14 +857,6 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
bool GetSavedWindowPlacement(gfx::Rect* bounds,
ui::WindowShowState* show_state);
- // Creates and initializes a new InputMethod and returns it, otherwise null.
- scoped_ptr<InputMethod> CreateInputMethod();
-
- // Sets a different InputMethod instance to this widget. The instance
- // must not be initialized, the ownership will be assumed by the widget.
- // It's only for testing purpose.
- void ReplaceInputMethod(InputMethod* input_method);
-
internal::NativeWidgetPrivate* native_widget_;
base::ObserverList<WidgetObserver> observers_;
@@ -938,8 +921,6 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// initial focus for the widget.
bool focus_on_creation_;
- mutable scoped_ptr<InputMethod> input_method_;
-
// See |is_top_level()| accessor.
bool is_top_level_;
diff --git a/ui/views/widget/widget_interactive_uitest.cc b/ui/views/widget/widget_interactive_uitest.cc
index 35c9cef..4b5a01d 100644
--- a/ui/views/widget/widget_interactive_uitest.cc
+++ b/ui/views/widget/widget_interactive_uitest.cc
@@ -22,7 +22,6 @@
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/textfield/textfield_test_api.h"
#include "ui/views/focus/focus_manager.h"
-#include "ui/views/ime/input_method.h"
#include "ui/views/test/focus_manager_test.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/touchui/touch_selection_controller_impl.h"
@@ -1566,43 +1565,6 @@ TEST_F(WidgetInputMethodInteractiveTest, TwoWindows) {
parent->CloseNow();
}
-// Test input method focus changes affected by focus changes cross 2 top
-// windows.
-TEST_F(WidgetInputMethodInteractiveTest, TwoTopWindows) {
- Widget* widget1 = CreateWidget();
- Widget* widget2 = CreateWidget();
- Textfield* textfield1 = new Textfield;
- Textfield* textfield2 = new Textfield;
- textfield2->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
- widget1->GetRootView()->AddChildView(textfield1);
- widget2->GetRootView()->AddChildView(textfield2);
-
- // Do the initial shows synchronously. Otherwise, on X11, the window server
- // messages may be interleaved with the activation requests below.
- ShowSync(widget1);
- ShowSync(widget2);
-
- textfield1->RequestFocus();
- textfield2->RequestFocus();
-
- ActivateSync(widget1);
-
- EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT,
- widget1->GetInputMethod()->GetTextInputType());
- EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
- widget2->GetInputMethod()->GetTextInputType());
-
- ActivateSync(widget2);
-
- EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE,
- widget1->GetInputMethod()->GetTextInputType());
- EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD,
- widget2->GetInputMethod()->GetTextInputType());
-
- widget2->CloseNow();
- widget1->CloseNow();
-}
-
// Test input method focus changes affected by textfield's state changes.
TEST_F(WidgetInputMethodInteractiveTest, TextField) {
Widget* widget = CreateWidget();
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index ecdacc7..ba0c03b 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -310,8 +310,6 @@ TEST_F(WidgetTest, GetTopLevelWidget_Native) {
// when window activation changes.
TEST_F(WidgetTest, ChangeActivation) {
Widget* top1 = CreateTopLevelPlatformWidget();
- // CreateInputMethod before activated
- top1->GetInputMethod();
top1->Show();
RunPendingMessages();
@@ -322,8 +320,6 @@ TEST_F(WidgetTest, ChangeActivation) {
top1->Activate();
RunPendingMessages();
- // Create InputMethod after deactivated.
- top2->GetInputMethod();
top2->Activate();
RunPendingMessages();
@@ -802,7 +798,6 @@ class WidgetWithDestroyedNativeViewTest : public ViewsTestBase {
widget->GetThemeProvider();
widget->GetNativeTheme();
widget->GetFocusManager();
- widget->GetInputMethod();
widget->SchedulePaintInRect(gfx::Rect(0, 0, 1, 2));
widget->IsMouseEventsEnabled();
widget->SetNativeWindowProperty("xx", widget);
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
index 485b553..c020e78 100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -848,13 +848,6 @@ void HWNDMessageHandler::SizeConstraintsChanged() {
}
////////////////////////////////////////////////////////////////////////////////
-// HWNDMessageHandler, InputMethodDelegate implementation:
-
-void HWNDMessageHandler::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
- SetMsgHandled(delegate_->HandleKeyEvent(key));
-}
-
-////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, gfx::WindowImpl overrides:
HICON HWNDMessageHandler::GetDefaultWindowIcon() const {
@@ -1623,7 +1616,7 @@ LRESULT HWNDMessageHandler::OnKeyEvent(UINT message,
hwnd(), message, w_param, l_param, static_cast<DWORD>(GetMessageTime())};
ui::KeyEvent key(msg);
if (!delegate_->HandleUntranslatedKeyEvent(key))
- DispatchKeyEventPostIME(key);
+ SetMsgHandled(FALSE);
return 0;
}
diff --git a/ui/views/win/hwnd_message_handler.h b/ui/views/win/hwnd_message_handler.h
index 565b1d3..79374fd 100644
--- a/ui/views/win/hwnd_message_handler.h
+++ b/ui/views/win/hwnd_message_handler.h
@@ -24,7 +24,6 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/sequential_id_generator.h"
#include "ui/gfx/win/window_impl.h"
-#include "ui/views/ime/input_method_delegate.h"
#include "ui/views/views_export.h"
namespace gfx {
@@ -41,7 +40,6 @@ namespace views {
class FullscreenHandler;
class HWNDMessageHandlerDelegate;
-class InputMethod;
class WindowsSessionChangeObserver;
// These two messages aren't defined in winuser.h, but they are sent to windows
@@ -111,7 +109,6 @@ const int WM_NCUAHDRAWFRAME = 0xAF;
// TODO(beng): This object should eventually *become* the WindowImpl.
class VIEWS_EXPORT HWNDMessageHandler :
public gfx::WindowImpl,
- public internal::InputMethodDelegate,
public ui::WindowEventTarget {
public:
explicit HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate);
@@ -208,9 +205,6 @@ class VIEWS_EXPORT HWNDMessageHandler :
private:
typedef std::set<DWORD> TouchIDs;
- // Overridden from internal::InputMethodDelegate:
- void DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
-
// Overridden from WindowImpl:
HICON GetDefaultWindowIcon() const override;
HICON GetSmallWindowIcon() const override;