summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 21:15:13 +0000
committerstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 21:15:13 +0000
commitb7f75868cb53eb45d3e15263a663327e381d40db (patch)
treebc2faeff6b2f1137e79be528168a26decc646231 /webkit
parentdb5523bcb7e0419955172709c241a188ab94e8e0 (diff)
downloadchromium_src-b7f75868cb53eb45d3e15263a663327e381d40db.zip
chromium_src-b7f75868cb53eb45d3e15263a663327e381d40db.tar.gz
chromium_src-b7f75868cb53eb45d3e15263a663327e381d40db.tar.bz2
Update Mac plugin IME handling to match updated spec
This changes IME handling per the recent NPAPI spec clarification, and adds the new bool to indicate conformance to the new model. Also: - Fixes an existing bug where the initial key down would be sent to the wrong IME system (since it happens before plugin IME starts) by having the render widget track whether a plugin is focused. - Changes ComplexTextInputPanel to match recent upstream changes. BUG=70427 TEST=None (plugins have not yet implemented Cocoa IME). Review URL: http://codereview.chromium.org/6259013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72190 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/plugins/npapi/plugin_host.cc10
-rw-r--r--webkit/plugins/npapi/webplugin.h7
-rw-r--r--webkit/plugins/npapi/webplugin_delegate_impl.h13
-rw-r--r--webkit/plugins/npapi/webplugin_delegate_impl_mac.mm78
4 files changed, 81 insertions, 27 deletions
diff --git a/webkit/plugins/npapi/plugin_host.cc b/webkit/plugins/npapi/plugin_host.cc
index 53841c3..9aed03b 100644
--- a/webkit/plugins/npapi/plugin_host.cc
+++ b/webkit/plugins/npapi/plugin_host.cc
@@ -840,6 +840,16 @@ NPError NPN_GetValue(NPP id, NPNVariable variable, void* value) {
rv = NPERR_NO_ERROR;
break;
}
+ case NPNVsupportsUpdatedCocoaTextInputBool: {
+ // We support the clarifications to the Cocoa IME event spec, but since
+ // IME currently only works on 10.6, only answer true there.
+ NPBool* supports_update = reinterpret_cast<NPBool*>(value);
+ int32 major, minor, bugfix;
+ base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix);
+ *supports_update = major > 10 || (major == 10 && minor > 5);
+ rv = NPERR_NO_ERROR;
+ break;
+ }
#endif // OS_MACOSX
case NPNVPepperExtensions:
// Available for any plugin that attempts to get it.
diff --git a/webkit/plugins/npapi/webplugin.h b/webkit/plugins/npapi/webplugin.h
index c596949..afd2865 100644
--- a/webkit/plugins/npapi/webplugin.h
+++ b/webkit/plugins/npapi/webplugin.h
@@ -151,8 +151,11 @@ class WebPlugin {
bool defer) = 0;
#if defined(OS_MACOSX)
- // Enables/disables plugin IME.
- virtual void SetImeEnabled(bool enabled) {};
+ // Called to inform the WebPlugin that the plugin has gained or lost focus.
+ virtual void FocusChanged(bool focused) {};
+
+ // Starts plugin IME.
+ virtual void StartIme() {};
// Synthesize a fake window handle for the plug-in to identify the instance
// to the browser, allowing mapping to a surface for hardware accelleration
diff --git a/webkit/plugins/npapi/webplugin_delegate_impl.h b/webkit/plugins/npapi/webplugin_delegate_impl.h
index 9f64f3a..edb319e 100644
--- a/webkit/plugins/npapi/webplugin_delegate_impl.h
+++ b/webkit/plugins/npapi/webplugin_delegate_impl.h
@@ -162,8 +162,9 @@ class WebPluginDelegateImpl : public 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 plugin that IME composition has completed.
+ // If |text| is empty, IME was cancelled.
+ void ImeCompositionCompleted(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.
@@ -391,8 +392,8 @@ class WebPluginDelegateImpl : public WebPluginDelegate {
// Updates anything that depends on plugin visibility.
void PluginVisibilityChanged();
- // Enables/disables IME.
- void SetImeEnabled(bool enabled);
+ // Starts an IME session.
+ void StartIme();
// Informs the browser about the updated accelerated drawing surface.
void UpdateAcceleratedSurface();
@@ -400,6 +401,9 @@ class WebPluginDelegateImpl : public WebPluginDelegate {
// Uses a CARenderer to draw the plug-in's layer in our OpenGL surface.
void DrawLayerInSurface();
+ // Returns true if plugin IME is supported.
+ bool IsImeSupported();
+
#ifndef NP_NO_CARBON
// Moves our dummy window to match the current screen location of the plugin.
void UpdateDummyWindowBounds(const gfx::Point& plugin_origin);
@@ -446,6 +450,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate {
gfx::Rect cached_clip_rect_;
bool ime_enabled_;
+ int keyup_ignore_count_;
scoped_ptr<ExternalDragTracker> external_drag_tracker_;
#endif // OS_MACOSX
diff --git a/webkit/plugins/npapi/webplugin_delegate_impl_mac.mm b/webkit/plugins/npapi/webplugin_delegate_impl_mac.mm
index 6d71a35..e43453d 100644
--- a/webkit/plugins/npapi/webplugin_delegate_impl_mac.mm
+++ b/webkit/plugins/npapi/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_info.h"
#include "base/sys_string_conversions.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "webkit/glue/webkit_glue.h"
@@ -266,6 +267,7 @@ WebPluginDelegateImpl::WebPluginDelegateImpl(
container_is_visible_(false),
have_called_set_window_(false),
ime_enabled_(false),
+ keyup_ignore_count_(0),
external_drag_tracker_(new ExternalDragTracker()),
handle_event_depth_(0),
first_set_window_call_(true),
@@ -505,6 +507,21 @@ bool WebPluginDelegateImpl::PlatformHandleInputEvent(
current_windowless_cursor_.GetCursorInfo(cursor_info);
}
+ // Per the Cocoa Plugin IME spec, plugins shoudn't receive keydown or keyup
+ // events while composition is in progress. Treat them as handled, however,
+ // since IME is consuming them on behalf of the plugin.
+ if ((event.type == WebInputEvent::KeyDown && ime_enabled_) ||
+ (event.type == WebInputEvent::KeyUp && keyup_ignore_count_)) {
+ // Composition ends on a keydown, so ime_enabled_ will be false at keyup;
+ // because the keydown wasn't sent to the plugin, the keyup shouldn't be
+ // either (per the spec).
+ if (event.type == WebInputEvent::KeyDown)
+ ++keyup_ignore_count_;
+ else
+ --keyup_ignore_count_;
+ return true;
+ }
+
#ifndef NP_NO_CARBON
if (instance()->event_model() == NPEventModelCarbon) {
#ifndef NP_NO_QUICKDRAW
@@ -585,9 +602,11 @@ bool WebPluginDelegateImpl::PlatformHandleInputEvent(
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);
+ // Start IME if requested by the plugin.
+ if (handled && handle_response == kNPEventStartIME &&
+ event.type == WebInputEvent::KeyDown) {
+ StartIme();
+ ++keyup_ignore_count_;
}
// Plugins don't give accurate information about whether or not they handled
@@ -793,9 +812,6 @@ 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)
@@ -832,8 +848,7 @@ bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) {
if (!have_called_set_window_)
return false;
- if (!focused)
- SetImeEnabled(false);
+ plugin_->FocusChanged(focused);
ScopedActiveDelegate active_delegate(this);
@@ -899,18 +914,24 @@ void WebPluginDelegateImpl::WindowFrameChanged(const gfx::Rect& window_frame,
SetContentAreaOrigin(gfx::Point(view_frame.x(), view_frame.y()));
}
-void WebPluginDelegateImpl::ImeCompositionConfirmed(const string16& text) {
+void WebPluginDelegateImpl::ImeCompositionCompleted(const string16& text) {
if (instance()->event_model() != NPEventModelCocoa) {
- DLOG(ERROR) << "IME text receieved in Carbon event model";
+ DLOG(ERROR) << "IME notification 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);
+ ime_enabled_ = false;
+
+ // If |text| is empty this was just called to tell us composition was
+ // cancelled externally (e.g., the user pressed esc).
+ if (!text.empty()) {
+ 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) {
@@ -971,13 +992,28 @@ void WebPluginDelegateImpl::PluginVisibilityChanged() {
}
}
-void WebPluginDelegateImpl::SetImeEnabled(bool enabled) {
- if (instance()->event_model() != NPEventModelCocoa)
+void WebPluginDelegateImpl::StartIme() {
+ if (instance()->event_model() != NPEventModelCocoa ||
+ !IsImeSupported()) {
return;
- if (enabled == ime_enabled_)
+ }
+ if (ime_enabled_)
return;
- ime_enabled_ = enabled;
- plugin_->SetImeEnabled(enabled);
+ ime_enabled_ = true;
+ plugin_->StartIme();
+}
+
+bool WebPluginDelegateImpl::IsImeSupported() {
+ // Currently the plugin IME implementation only works on 10.6.
+ static BOOL sImeSupported = NO;
+ static BOOL sHaveCheckedSupport = NO;
+ if (!sHaveCheckedSupport) {
+ int32 major, minor, bugfix;
+ base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix);
+ sImeSupported = major > 10 || (major == 10 && minor > 5);
+ sHaveCheckedSupport = YES;
+ }
+ return sImeSupported;
}
#pragma mark -