Index: content/browser/renderer_host/render_widget_host_view_win.cc |
diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc |
index 32775cb25b1900bd0c213ea59aeb393031590584..2010e7144186e8301caf58d7762017d218b5562d 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_win.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_win.cc |
@@ -3024,14 +3024,23 @@ LRESULT RenderWidgetHostViewWin::OnQueryCharPosition( |
IMECHARPOSITION* position) { |
DCHECK(position); |
- if (!ime_input_.is_composing() || composition_range_.is_empty() || |
- position->dwSize < sizeof(IMECHARPOSITION) || |
- position->dwCharPos >= composition_character_bounds_.size()) { |
+ if (position->dwSize < sizeof(IMECHARPOSITION)) |
return 0; |
- } |
- RECT target_rect = |
- composition_character_bounds_[position->dwCharPos].ToRECT(); |
+ RECT target_rect = {}; |
+ if (ime_input_.is_composing() && !composition_range_.is_empty() && |
+ position->dwCharPos < composition_character_bounds_.size()) { |
+ target_rect = |
+ composition_character_bounds_[position->dwCharPos].ToRECT(); |
+ } else if (position->dwCharPos == 0) { |
+ // When there is no on-going composition but |position->dwCharPos| is 0, |
+ // use the caret rect. This behavior is the same to RichEdit. In fact, |
+ // CUAS (Cicero Unaware Application Support) relies on this behavior to |
+ // implement ITfContextView::GetTextExt on top of IMM32-based applications. |
+ target_rect = caret_rect_.ToRECT(); |
+ } else { |
+ return 0; |
+ } |
ClientToScreen(&target_rect); |
RECT document_rect = GetViewBounds().ToRECT(); |