| 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 ec83c95debb4a94299de056a07e130a69e357c1d..fb112a874b9cc647b395dc541fcdeebfcb59746d 100644
|
| --- a/content/browser/renderer_host/render_widget_host_view_win.cc
|
| +++ b/content/browser/renderer_host/render_widget_host_view_win.cc
|
| @@ -232,7 +232,10 @@ RenderWidgetHostViewWin::RenderWidgetHostViewWin(RenderWidgetHost* widget)
|
| overlay_color_(0),
|
| text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
|
| is_fullscreen_(false),
|
| - ignore_mouse_movement_(true) {
|
| + ignore_mouse_movement_(true),
|
| + selection_text_offset_(0),
|
| + selection_range_(ui::Range::InvalidRange()),
|
| + composition_range_(ui::Range::InvalidRange()) {
|
| render_widget_host_->SetView(this);
|
| registrar_.Add(this,
|
| content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
|
| @@ -611,6 +614,15 @@ void RenderWidgetHostViewWin::TextInputStateChanged(
|
| }
|
| }
|
|
|
| +void RenderWidgetHostViewWin::SelectionChanged(
|
| + const string16& text,
|
| + size_t offset,
|
| + const ui::Range& range) {
|
| + selection_text_ = text;
|
| + selection_text_offset_ = offset;
|
| + selection_range_ = range;
|
| +}
|
| +
|
| void RenderWidgetHostViewWin::SelectionBoundsChanged(
|
| const gfx::Rect& start_rect,
|
| const gfx::Rect& end_rect) {
|
| @@ -625,6 +637,11 @@ void RenderWidgetHostViewWin::ImeCancelComposition() {
|
| ime_input_.CancelIME(m_hWnd);
|
| }
|
|
|
| +void RenderWidgetHostViewWin::ImeCompositionRangeChanged(
|
| + const ui::Range& range) {
|
| + composition_range_ = range;
|
| +}
|
| +
|
| BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) {
|
| if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd))
|
| return TRUE;
|
| @@ -1215,6 +1232,109 @@ LRESULT RenderWidgetHostViewWin::OnImeEndComposition(
|
| return 0;
|
| }
|
|
|
| +LRESULT RenderWidgetHostViewWin::OnDocumentFeed(RECONVERTSTRING *reconv) {
|
| + size_t target_offset;
|
| + size_t target_length;
|
| + bool has_composition;
|
| + if (!composition_range_.is_empty()) {
|
| + target_offset = composition_range_.GetMin();
|
| + target_length = composition_range_.length();
|
| + has_composition = true;
|
| + } else if (!selection_range_.is_empty()) {
|
| + target_offset = selection_range_.GetMin();
|
| + target_length = selection_range_.length();
|
| + has_composition = false;
|
| + } else {
|
| + return 0;
|
| + }
|
| +
|
| + size_t len = selection_text_.length();
|
| + size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
|
| +
|
| + if (target_offset < selection_text_offset_ ||
|
| + target_offset + target_length > selection_text_offset_ + len) {
|
| + return 0;
|
| + }
|
| +
|
| + if (!reconv)
|
| + return need_size;
|
| +
|
| + if (reconv->dwSize < need_size)
|
| + return 0;
|
| +
|
| + reconv->dwVersion = 0;
|
| + reconv->dwStrLen = len;
|
| + reconv->dwStrOffset = sizeof(RECONVERTSTRING);
|
| + reconv->dwCompStrLen = has_composition ? target_length: 0;
|
| + reconv->dwCompStrOffset =
|
| + (target_offset - selection_text_offset_) * sizeof(WCHAR);
|
| + reconv->dwTargetStrLen = target_length;
|
| + reconv->dwTargetStrOffset = reconv->dwCompStrOffset;
|
| + memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING),
|
| + selection_text_.c_str(), len * sizeof(WCHAR));
|
| +
|
| + return need_size;
|
| +}
|
| +
|
| +LRESULT RenderWidgetHostViewWin::OnReconvertString(RECONVERTSTRING *reconv) {
|
| + // If there is a composition string already, we don't allow reconversion.
|
| + if (ime_input_.is_composing())
|
| + return 0;
|
| +
|
| + if (selection_range_.is_empty())
|
| + return 0;
|
| +
|
| + if (selection_text_.empty())
|
| + return 0;
|
| +
|
| + if (selection_range_.GetMin() < selection_text_offset_ ||
|
| + selection_range_.GetMax() >
|
| + selection_text_offset_ + selection_text_.length()) {
|
| + return 0;
|
| + }
|
| +
|
| + size_t len = selection_range_.length();
|
| + size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
|
| +
|
| + if (!reconv)
|
| + return need_size;
|
| +
|
| + if (reconv->dwSize < need_size)
|
| + return 0;
|
| +
|
| + reconv->dwVersion = 0;
|
| + reconv->dwStrLen = len;
|
| + reconv->dwStrOffset = sizeof(RECONVERTSTRING);
|
| + reconv->dwCompStrLen = len;
|
| + reconv->dwCompStrOffset = 0;
|
| + reconv->dwTargetStrLen = len;
|
| + reconv->dwTargetStrOffset = 0;
|
| +
|
| + size_t offset = selection_range_.GetMin() - selection_text_offset_;
|
| + memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING),
|
| + selection_text_.c_str() + offset, len * sizeof(WCHAR));
|
| +
|
| + return need_size;
|
| +}
|
| +
|
| +LRESULT RenderWidgetHostViewWin::OnImeRequest(
|
| + UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
|
| + if (!render_widget_host_) {
|
| + handled = FALSE;
|
| + return 0;
|
| + }
|
| +
|
| + switch (wparam) {
|
| + case IMR_RECONVERTSTRING:
|
| + return OnReconvertString(reinterpret_cast<RECONVERTSTRING*>(lparam));
|
| + case IMR_DOCUMENTFEED:
|
| + return OnDocumentFeed(reinterpret_cast<RECONVERTSTRING*>(lparam));
|
| + default:
|
| + handled = FALSE;
|
| + return 0;
|
| + }
|
| +}
|
| +
|
| LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam,
|
| LPARAM lparam, BOOL& handled) {
|
| handled = TRUE;
|
|
|