diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-29 03:45:07 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-29 03:45:07 +0000 |
commit | 99374c4b5d9bbb508e0583425ab1c17b5580bfe8 (patch) | |
tree | 35a5522ac80264133d9b48e5bc7a643e8b59a50f /chrome/browser | |
parent | 1c658ef8ae0835ecffc1f4061c00e84b2ddea927 (diff) | |
download | chromium_src-99374c4b5d9bbb508e0583425ab1c17b5580bfe8.zip chromium_src-99374c4b5d9bbb508e0583425ab1c17b5580bfe8.tar.gz chromium_src-99374c4b5d9bbb508e0583425ab1c17b5580bfe8.tar.bz2 |
A workaround fix for Issue 26880.
Same as Safari, this change just finishes an ongoing IME composition and reset the IME state when a renderer requests.
BUG=26880
TEST=Enable a Chinese IME, type "baobao", click outside from the candidate window, and check if the candidate window is closed.
Review URL: http://codereview.chromium.org/661069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42924 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.h | 14 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 28 |
2 files changed, 34 insertions, 8 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h index d475acf..c6ed3b7 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.h +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h @@ -157,6 +157,11 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { void set_parent_view(BaseView* parent_view) { parent_view_ = parent_view; } + // Cancels the ongoing composition and cleans up all input-method resources. + // This function dispatches a cancelation request from a renderer to + // NSInputManager to synchronize the input-method status with it. + void IMECleanupComposition(); + // These member variables should be private, but the associated ObjC class // needs access to them and can't be made a friend. @@ -197,11 +202,10 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { // Represents whether or not an input method is composing a text. bool im_composing_; - // Represents the range of the composition string (i.e. a text being - // composed by an input method), and the range of the selected text of the - // composition string. - // TODO(hbono): need to save the composition string itself for the - // attributedSubstringFromRange method? + // Represents the composition string (i.e. a text being composed by an input + // method), its range, and the range of the selected text in the composition + // string. + string16 im_text_; NSRange im_marked_range_; NSRange im_selected_range_; diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 15eff1b..e7d0c56 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -308,8 +308,9 @@ void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { void RenderWidgetHostViewMac::IMEUpdateStatus(int control, const gfx::Rect& caret_rect) { - // The renderer updates its IME status. - // We need to control the input method according to the given message. + // Reset the IME state and finish an ongoing composition in the renderer. + if (control == IME_DISABLE || control == IME_COMPLETE_COMPOSITION) + IMECleanupComposition(); // We need to convert the coordinate of the cursor rectangle sent from the // renderer and save it. Our IME backend uses a coordinate system whose @@ -522,6 +523,22 @@ void RenderWidgetHostViewMac::KillSelf() { } } +void RenderWidgetHostViewMac::IMECleanupComposition() { + if (!im_composing_) + return; + + // Cancel the ongoing composition. [NSInputManager markedTextAbandoned:] + // doesn't call any NSTextInput functions, such as setMarkedText or + // insertText. So, we need to send an IPC message to a renderer so it can + // delete the composition node. + NSInputManager *currentInputManager = [NSInputManager currentInputManager]; + [currentInputManager markedTextAbandoned:[cocoa_view_ self]]; + + render_widget_host_->ImeCancelComposition(); + im_text_.clear(); + im_composing_ = false; +} + gfx::PluginWindowHandle RenderWidgetHostViewMac::AllocateFakePluginWindowHandle() { // Make sure we have a layer for the plugin to draw into. @@ -774,6 +791,9 @@ bool RenderWidgetHostViewMac::ContainsNativeView( WebInputEventFactory::mouseEvent(theEvent, self); if (renderWidgetHostView_->render_widget_host_) renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); + + if ([theEvent type] == NSLeftMouseDown) + renderWidgetHostView_->IMECleanupComposition(); } - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { @@ -1532,8 +1552,9 @@ extern NSString *NSTextInputReplacementRangeAttributeName; // is empty to update the IME state. (Our IME backend can automatically // cancels an ongoing composition when we send an empty text. So, it is OK // to send an empty text to the renderer.) + renderWidgetHostView_->im_text_ = UTF8ToUTF16([im_text UTF8String]); renderWidgetHostView_->render_widget_host_->ImeSetComposition( - UTF8ToUTF16([im_text UTF8String]), cursor, target_start, target_end); + renderWidgetHostView_->im_text_, cursor, target_start, target_end); renderWidgetHostView_->GetRenderWidgetHost()->ImeSetInputMode(true); renderWidgetHostView_->im_composing_ = length > 0; renderWidgetHostView_->im_marked_range_.location = 0; @@ -1600,6 +1621,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName; renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( UTF8ToUTF16([im_text UTF8String])); } + renderWidgetHostView_->im_text_.clear(); renderWidgetHostView_->im_composing_ = false; textInserted_ = YES; } |