diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-15 23:31:55 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-15 23:31:55 +0000 |
commit | 935d63deb04754a6c831c5a5edfef35f71c0b805 (patch) | |
tree | 9ebbc892c6bd4abb5496bf246d0677a1e7f3c571 /webkit | |
parent | df39d8740b4de18d5a57ec3a9fc519d89b26b1cc (diff) | |
download | chromium_src-935d63deb04754a6c831c5a5edfef35f71c0b805.zip chromium_src-935d63deb04754a6c831c5a5edfef35f71c0b805.tar.gz chromium_src-935d63deb04754a6c831c5a5edfef35f71c0b805.tar.bz2 |
Implement IME for Mac plugins using the Cocoa event model on 10.6
Based on the implementation of Gecko's Cocoa event model IME handling on 64-bit, but modified to fit Chrome's cross-process event handling.
Because NSTextInputContext is 10.6+, 10.5 will need a cempletely different implementation.
BUG=30905
TEST=Plugins implementing the updated NPAPI Cocoa IME spec should handle IME on 10.6.
Review URL: http://codereview.chromium.org/3808001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/webplugin.h | 3 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl.h | 17 | ||||
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl_mac.mm | 39 |
3 files changed, 49 insertions, 10 deletions
diff --git a/webkit/glue/plugins/webplugin.h b/webkit/glue/plugins/webplugin.h index 1a14d545..36426fa 100644 --- a/webkit/glue/plugins/webplugin.h +++ b/webkit/glue/plugins/webplugin.h @@ -149,6 +149,9 @@ class WebPlugin { bool defer) = 0; #if defined(OS_MACOSX) + // Enables/disables plugin IME. + virtual void SetImeEnabled(bool enabled) {}; + // Synthesize a fake window handle for the plug-in to identify the instance // to the browser, allowing mapping to a surface for hardware accelleration // of plug-in content. The browser generates the handle which is then set on diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index 55381f9..30a4a58 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -161,6 +161,8 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { // Frames are in screen coordinates. void WindowFrameChanged(const gfx::Rect& window_frame, const gfx::Rect& view_frame); + // Informs the plugin that IME composition has been confirmed. + void ImeCompositionConfirmed(const string16& text); // Informs the delegate that the plugin set a Carbon ThemeCursor. void SetThemeCursor(ThemeCursor cursor); // Informs the delegate that the plugin set a Carbon Cursor. @@ -385,20 +387,15 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { void SetContentAreaOrigin(const gfx::Point& origin); // Updates everything that depends on the plugin's absolute screen location. void PluginScreenLocationChanged(); + // Updates anything that depends on plugin visibility. + void PluginVisibilityChanged(); - // Returns the apparent zoom ratio for the given event, as inferred from our - // current knowledge about about where on screen the plugin is. - // This is a temporary workaround for <http://crbug.com/9996>; once that is - // fixed we should have correct event coordinates (or an explicit - // notification of zoom level). - float ApparentEventZoomLevel(const WebKit::WebMouseEvent& event); + // Enables/disables IME. + void SetImeEnabled(bool enabled); // Informs the browser about the updated accelerated drawing surface. void UpdateAcceleratedSurface(); - // Updates anything that depends on plugin visibility. - void PluginVisibilityChanged(); - // Uses a CARenderer to draw the plug-in's layer in our OpenGL surface. void DrawLayerInSurface(); @@ -447,6 +444,8 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { gfx::Rect cached_clip_rect_; + bool ime_enabled_; + scoped_ptr<ExternalDragTracker> external_drag_tracker_; #endif // OS_MACOSX diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index b7e7702..cca8695 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -17,6 +17,7 @@ #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "base/sys_string_conversions.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/plugin_lib.h" @@ -263,6 +264,7 @@ WebPluginDelegateImpl::WebPluginDelegateImpl( initial_window_focus_(false), container_is_visible_(false), have_called_set_window_(false), + ime_enabled_(false), external_drag_tracker_(new ExternalDragTracker()), handle_event_depth_(0), first_set_window_call_(true), @@ -573,7 +575,13 @@ bool WebPluginDelegateImpl::PlatformHandleInputEvent( event_scope.reset(new NPAPI::ScopedCurrentPluginEvent( instance(), static_cast<NPCocoaEvent*>(plugin_event))); } - bool handled = instance()->NPP_HandleEvent(plugin_event) != 0; + int16_t handle_response = instance()->NPP_HandleEvent(plugin_event); + bool handled = handle_response != kNPEventNotHandled; + + if (handled && event.type == WebInputEvent::KeyDown) { + // Update IME state as requested by the plugin. + SetImeEnabled(handle_response == kNPEventStartIME); + } // Plugins don't give accurate information about whether or not they handled // events, so browsers on the Mac ignore the return value. @@ -778,6 +786,9 @@ void WebPluginDelegateImpl::SetWindowHasFocus(bool has_focus) { return; containing_window_has_focus_ = has_focus; + if (!has_focus) + SetImeEnabled(false); + #ifndef NP_NO_QUICKDRAW // Make sure controls repaint with the correct look. if (quirks_ & PLUGIN_QUIRK_ALLOW_FASTER_QUICKDRAW_PATH) @@ -814,6 +825,9 @@ bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) { if (!have_called_set_window_) return false; + if (!focused) + SetImeEnabled(false); + ScopedActiveDelegate active_delegate(this); switch (instance()->event_model()) { @@ -878,6 +892,20 @@ void WebPluginDelegateImpl::WindowFrameChanged(const gfx::Rect& window_frame, SetContentAreaOrigin(gfx::Point(view_frame.x(), view_frame.y())); } +void WebPluginDelegateImpl::ImeCompositionConfirmed(const string16& text) { + if (instance()->event_model() != NPEventModelCocoa) { + DLOG(ERROR) << "IME text receieved in Carbon event model"; + return; + } + + NPCocoaEvent text_event; + memset(&text_event, 0, sizeof(NPCocoaEvent)); + text_event.type = NPCocoaEventTextInput; + text_event.data.text.text = + reinterpret_cast<NPNSString*>(base::SysUTF16ToNSString(text)); + instance()->NPP_HandleEvent(&text_event); +} + void WebPluginDelegateImpl::SetThemeCursor(ThemeCursor cursor) { current_windowless_cursor_.InitFromThemeCursor(cursor); } @@ -936,6 +964,15 @@ void WebPluginDelegateImpl::PluginVisibilityChanged() { } } +void WebPluginDelegateImpl::SetImeEnabled(bool enabled) { + if (instance()->event_model() != NPEventModelCocoa) + return; + if (enabled == ime_enabled_) + return; + ime_enabled_ = enabled; + plugin_->SetImeEnabled(enabled); +} + #pragma mark - #pragma mark Core Animation Support |