Index: content/renderer/render_widget.cc |
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc |
index 3f3fc75882ac89903770af4f3389e5d2b6c209cd..d68a01d456782766fd01daa0a0b61f110f703e83 100644 |
--- a/content/renderer/render_widget.cc |
+++ b/content/renderer/render_widget.cc |
@@ -12,6 +12,7 @@ |
#include "build/build_config.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/render_messages.h" |
+#include "chrome/common/text_input_client_messages.h" |
#include "chrome/renderer/render_process.h" |
#include "chrome/renderer/render_thread.h" |
#include "content/common/view_messages.h" |
@@ -23,6 +24,7 @@ |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
@@ -49,6 +51,7 @@ using WebKit::WebNavigationPolicy; |
using WebKit::WebPopupMenu; |
using WebKit::WebPopupMenuInfo; |
using WebKit::WebPopupType; |
+using WebKit::WebRange; |
using WebKit::WebRect; |
using WebKit::WebScreenInfo; |
using WebKit::WebSize; |
@@ -883,19 +886,54 @@ void RenderWidget::OnImeSetComposition( |
int selection_start, int selection_end) { |
if (!webwidget_) |
return; |
- if (!webwidget_->setComposition( |
+ if (webwidget_->setComposition( |
text, WebVector<WebCompositionUnderline>(underlines), |
selection_start, selection_end)) { |
+ // Setting the IME composition was successful. Send the new composition |
+ // range to the browser. |
+ ui::Range range(ui::Range::InvalidRange()); |
+ size_t location, length; |
+ if (webwidget_->compositionRange(&location, &length)) { |
+ range.set_start(location); |
+ range.set_end(location + length); |
+ } |
+ // The IME was cancelled via the Esc key, so just send back the caret. |
+ else if (webwidget_->caretOrSelectionRange(&location, &length)) { |
+ range.set_start(location); |
+ range.set_end(location + length); |
+ } |
+ Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
+ range)); |
+ } else { |
// If we failed to set the composition text, then we need to let the browser |
// process to cancel the input method's ongoing composition session, to make |
// sure we are in a consistent state. |
Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
+ |
+ // Send an updated IME range with just the caret range. |
+ ui::Range range(ui::Range::InvalidRange()); |
+ size_t location, length; |
+ if (webwidget_->caretOrSelectionRange(&location, &length)) { |
+ range.set_start(location); |
+ range.set_end(location + length); |
+ } |
+ Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
+ range)); |
} |
} |
void RenderWidget::OnImeConfirmComposition(const string16& text) { |
if (webwidget_) |
webwidget_->confirmComposition(text); |
+ // Send an updated IME range with just the caret range. |
+ ui::Range range(ui::Range::InvalidRange()); |
+ size_t location, length; |
+ if (webwidget_->caretOrSelectionRange(&location, &length)) { |
+ range.set_start(location); |
+ range.set_end(location + length); |
+ } |
+ Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
+ range)); |
} |
// This message causes the renderer to render an image of the |
@@ -1087,6 +1125,16 @@ void RenderWidget::resetInputMethod() { |
if (webwidget_->confirmComposition()) |
Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
} |
+ |
+ // Send an updated IME range with the current caret rect. |
+ ui::Range range(ui::Range::InvalidRange()); |
+ size_t location, length; |
+ if (webwidget_->caretOrSelectionRange(&location, &length)) { |
+ range.set_start(location); |
+ range.set_end(location + length); |
+ } |
+ Send(new TextInputClientViewHostMsg_ImeCompositionRangeChanged(routing_id(), |
+ range)); |
} |
void RenderWidget::SchedulePluginMove( |