Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Unified Diff: content/browser/renderer_host/render_widget_host_view_win.cc

Issue 8294026: Support IMM32 reconversion on Windows (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebase Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_win.h ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 087301545b11d51f67b1e8e215887e15be2c7ffa..be4dd139278e28c1e9dc78e97363a6a8a21e37d4 100644
--- a/content/browser/renderer_host/render_widget_host_view_win.cc
+++ b/content/browser/renderer_host/render_widget_host_view_win.cc
@@ -285,7 +285,8 @@ 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),
+ composition_range_(ui::Range::InvalidRange()) {
render_widget_host_->SetView(this);
registrar_.Add(this,
content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
@@ -675,6 +676,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;
@@ -1279,6 +1285,31 @@ LRESULT RenderWidgetHostViewWin::OnImeEndComposition(
return 0;
}
+LRESULT RenderWidgetHostViewWin::OnImeRequest(
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
+ if (!render_widget_host_) {
+ handled = FALSE;
+ return 0;
+ }
+
+ // Should not receive WM_IME_REQUEST message, if IME is disabled.
+ if (text_input_type_ == ui::TEXT_INPUT_TYPE_NONE ||
+ text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) {
+ 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;
@@ -2026,3 +2057,94 @@ void RenderWidgetHostViewWin::HandleLockedMouseEvent(UINT message,
ForwardMouseEventToRenderer(message, wparam, lparam);
}
+
+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_.IsValid()) {
+ 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));
+
+ // According to Microsft API document, IMR_RECONVERTSTRING and
+ // IMR_DOCUMENTFEED should return reconv, but some applications return
+ // need_size.
+ return reinterpret_cast<LRESULT>(reconv);
+}
+
+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));
+
+ // According to Microsft API document, IMR_RECONVERTSTRING and
+ // IMR_DOCUMENTFEED should return reconv, but some applications return
+ // need_size.
+ return reinterpret_cast<LRESULT>(reconv);
+}
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_win.h ('k') | content/renderer/render_view_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698