Commit 28025f2c authored by andresantoso's avatar andresantoso Committed by Commit bot

Mac: Fix Korean input on OSX 10.11

handling_input_event_ needs to be set in RenderWidget::OnImeSetComposition,
otherwise RenderView::DidChangeSelection will skip sending the selection
change message the the browser, even though it was correctly set on the
renderer side.

Also fix incorrectly set selectedRange_ in -setMarkedText,
|newSelRange| is relative to the marked text while selectedRange_ is
relative to the entire text storage.

BUG=500376

Review URL: https://codereview.chromium.org/1240943002

Cr-Commit-Position: refs/heads/master@{#339754}
parent c6f82b15
...@@ -120,6 +120,9 @@ class Layer; ...@@ -120,6 +120,9 @@ class Layer;
// Marked text which was generated by handling a key down event. // Marked text which was generated by handling a key down event.
base::string16 markedText_; base::string16 markedText_;
// Selected range of |markedText_|.
NSRange markedTextSelectedRange_;
// Underline information of the |markedText_|. // Underline information of the |markedText_|.
std::vector<blink::WebCompositionUnderline> underlines_; std::vector<blink::WebCompositionUnderline> underlines_;
......
...@@ -2101,6 +2101,7 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( ...@@ -2101,6 +2101,7 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged(
// Clear them here so that we can know whether they have changed afterwards. // Clear them here so that we can know whether they have changed afterwards.
textToBeInserted_.clear(); textToBeInserted_.clear();
markedText_.clear(); markedText_.clear();
markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0);
underlines_.clear(); underlines_.clear();
unmarkTextCalled_ = NO; unmarkTextCalled_ = NO;
hasEditCommands_ = NO; hasEditCommands_ = NO;
...@@ -2184,11 +2185,11 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( ...@@ -2184,11 +2185,11 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged(
if (hasMarkedText_ && markedText_.length()) { if (hasMarkedText_ && markedText_.length()) {
// Sends the updated marked text to the renderer so it can update the // Sends the updated marked text to the renderer so it can update the
// composition node in WebKit. // composition node in WebKit.
// When marked text is available, |selectedRange_| will be the range being // When marked text is available, |markedTextSelectedRange_| will be the
// selected inside the marked text. // range being selected inside the marked text.
widgetHost->ImeSetComposition(markedText_, underlines_, widgetHost->ImeSetComposition(markedText_, underlines_,
selectedRange_.location, markedTextSelectedRange_.location,
NSMaxRange(selectedRange_)); NSMaxRange(markedTextSelectedRange_));
} else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) { } else if (oldHasMarkedText && !hasMarkedText_ && !textInserted) {
if (unmarkTextCalled_) { if (unmarkTextCalled_) {
widgetHost->ImeConfirmComposition( widgetHost->ImeConfirmComposition(
...@@ -2920,6 +2921,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName; ...@@ -2920,6 +2921,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
// input method calls this method. // input method calls this method.
hasMarkedText_ = NO; hasMarkedText_ = NO;
markedText_.clear(); markedText_.clear();
markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0);
underlines_.clear(); underlines_.clear();
// If we are handling a key down event, then ConfirmComposition() will be // If we are handling a key down event, then ConfirmComposition() will be
...@@ -2944,7 +2946,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName; ...@@ -2944,7 +2946,7 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
int length = [im_text length]; int length = [im_text length];
// |markedRange_| will get set on a callback from ImeSetComposition(). // |markedRange_| will get set on a callback from ImeSetComposition().
selectedRange_ = newSelRange; markedTextSelectedRange_ = newSelRange;
markedText_ = base::SysNSStringToUTF16(im_text); markedText_ = base::SysNSStringToUTF16(im_text);
hasMarkedText_ = (length > 0); hasMarkedText_ = (length > 0);
......
...@@ -1685,6 +1685,8 @@ void RenderWidget::OnImeSetComposition( ...@@ -1685,6 +1685,8 @@ void RenderWidget::OnImeSetComposition(
if (!ShouldHandleImeEvent()) if (!ShouldHandleImeEvent())
return; return;
ImeEventGuard guard(this); ImeEventGuard guard(this);
base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_,
true);
if (!webwidget_->setComposition( if (!webwidget_->setComposition(
text, WebVector<WebCompositionUnderline>(underlines), text, WebVector<WebCompositionUnderline>(underlines),
selection_start, selection_end)) { selection_start, selection_end)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment