summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandresantoso@chromium.org <andresantoso@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-16 19:42:00 +0000
committerandresantoso@chromium.org <andresantoso@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-16 19:42:00 +0000
commit53e7daf0702f41b05429c2c64432d84a642e605c (patch)
tree70e32ae06547e744086ffd307e68a90df1c676dc
parentc0e5837700c0d2b72ae80cb2805c3ea967c6b478 (diff)
downloadchromium_src-53e7daf0702f41b05429c2c64432d84a642e605c.zip
chromium_src-53e7daf0702f41b05429c2c64432d84a642e605c.tar.gz
chromium_src-53e7daf0702f41b05429c2c64432d84a642e605c.tar.bz2
MacViews: Fill in InputMethod access in NativeWidgetMac.
Add NativeWidgetMac implementation of CreateInputMethod() and GetHostInputMethod(). We can now pass more unit tests including TextfieldTest and ComboboxTest. BUG=374077 Review URL: https://codereview.chromium.org/332893003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277521 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/views/cocoa/bridged_native_widget.h20
-rw-r--r--ui/views/cocoa/bridged_native_widget.mm35
-rw-r--r--ui/views/cocoa/bridged_native_widget_unittest.mm10
-rw-r--r--ui/views/widget/native_widget_mac.mm9
4 files changed, 66 insertions, 8 deletions
diff --git a/ui/views/cocoa/bridged_native_widget.h b/ui/views/cocoa/bridged_native_widget.h
index 79304e9..59754d1 100644
--- a/ui/views/cocoa/bridged_native_widget.h
+++ b/ui/views/cocoa/bridged_native_widget.h
@@ -8,21 +8,29 @@
#import <Cocoa/Cocoa.h>
#import "base/mac/scoped_nsobject.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/views/ime/input_method_delegate.h"
#include "ui/views/views_export.h"
@class BridgedContentView;
+namespace ui {
+class InputMethod;
+}
+
namespace views {
+class InputMethod;
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 {
+class VIEWS_EXPORT BridgedNativeWidget : public internal::InputMethodDelegate {
+
public:
BridgedNativeWidget();
- ~BridgedNativeWidget();
+ virtual ~BridgedNativeWidget();
// Initialize the bridge, "retains" ownership of |window|.
void Init(base::scoped_nsobject<NSWindow> window);
@@ -31,12 +39,20 @@ class VIEWS_EXPORT BridgedNativeWidget {
// take ownership of |view|.
void SetRootView(views::View* view);
+ // See widget.h for documentation.
+ InputMethod* CreateInputMethod();
+ ui::InputMethod* GetHostInputMethod();
+
BridgedContentView* ns_view() { return bridged_view_; }
NSWindow* ns_window() { return window_; }
+ // Overridden from internal::InputMethodDelegate:
+ virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
+
private:
base::scoped_nsobject<NSWindow> window_;
base::scoped_nsobject<BridgedContentView> bridged_view_;
+ scoped_ptr<ui::InputMethod> input_method_;
DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget);
};
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm
index 8ab8e4a..e4b754f7 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -5,7 +5,14 @@
#import "ui/views/cocoa/bridged_native_widget.h"
#include "base/logging.h"
+#include "ui/base/ime/input_method.h"
+#include "ui/base/ime/input_method_factory.h"
+#include "ui/base/ui_base_switches_util.h"
#import "ui/views/cocoa/bridged_content_view.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/widget/widget.h"
namespace views {
@@ -40,4 +47,32 @@ void BridgedNativeWidget::SetRootView(views::View* view) {
[window_ setContentView:bridged_view_];
}
+InputMethod* BridgedNativeWidget::CreateInputMethod() {
+ if (switches::IsTextInputFocusManagerEnabled())
+ return new NullInputMethod();
+
+ return new InputMethodBridge(this, GetHostInputMethod(), true);
+}
+
+ui::InputMethod* BridgedNativeWidget::GetHostInputMethod() {
+ if (!input_method_) {
+ // Delegate is NULL because Mac IME does not need DispatchKeyEventPostIME
+ // callbacks.
+ input_method_ = ui::CreateInputMethod(NULL, nil);
+ }
+ return input_method_.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// BridgedNativeWidget, internal::InputMethodDelegate:
+
+void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
+ // Mac key events don't go through this, but some unit tests that use
+ // MockInputMethod do.
+ Widget* widget = [bridged_view_ hostedView]->GetWidget();
+ widget->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
+ if (!key.handled() && widget->GetFocusManager())
+ widget->GetFocusManager()->OnKeyEvent(key);
+}
+
} // namespace views
diff --git a/ui/views/cocoa/bridged_native_widget_unittest.mm b/ui/views/cocoa/bridged_native_widget_unittest.mm
index c321b73..6d30f41 100644
--- a/ui/views/cocoa/bridged_native_widget_unittest.mm
+++ b/ui/views/cocoa/bridged_native_widget_unittest.mm
@@ -10,6 +10,7 @@
#import "testing/gtest_mac.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"
#import "ui/views/cocoa/bridged_content_view.h"
+#include "ui/views/ime/input_method.h"
#include "ui/views/view.h"
namespace views {
@@ -104,4 +105,13 @@ TEST_F(BridgedNativeWidgetTest, ViewSizeTracksWindow) {
EXPECT_EQ(kTestNewHeight, view_->height());
}
+TEST_F(BridgedNativeWidgetTest, CreateInputMethod) {
+ scoped_ptr<views::InputMethod> input_method(bridge_->CreateInputMethod());
+ EXPECT_TRUE(input_method);
+}
+
+TEST_F(BridgedNativeWidgetTest, GetHostInputMethod) {
+ EXPECT_TRUE(bridge_->GetHostInputMethod());
+}
+
} // namespace views
diff --git a/ui/views/widget/native_widget_mac.mm b/ui/views/widget/native_widget_mac.mm
index 4e222d4..729207a 100644
--- a/ui/views/widget/native_widget_mac.mm
+++ b/ui/views/widget/native_widget_mac.mm
@@ -131,18 +131,15 @@ bool NativeWidgetMac::HasCapture() const {
}
InputMethod* NativeWidgetMac::CreateInputMethod() {
- NOTIMPLEMENTED();
- return NULL;
+ return bridge_->CreateInputMethod();
}
internal::InputMethodDelegate* NativeWidgetMac::GetInputMethodDelegate() {
- NOTIMPLEMENTED();
- return NULL;
+ return bridge_.get();
}
ui::InputMethod* NativeWidgetMac::GetHostInputMethod() {
- NOTIMPLEMENTED();
- return NULL;
+ return bridge_->GetHostInputMethod();
}
void NativeWidgetMac::CenterWindow(const gfx::Size& size) {