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

Side by Side 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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_win.h" 5 #include "content/browser/renderer_host/render_widget_host_view_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 close_on_deactivate_(false), 278 close_on_deactivate_(false),
279 being_destroyed_(false), 279 being_destroyed_(false),
280 tooltip_hwnd_(NULL), 280 tooltip_hwnd_(NULL),
281 tooltip_showing_(false), 281 tooltip_showing_(false),
282 shutdown_factory_(this), 282 shutdown_factory_(this),
283 parent_hwnd_(NULL), 283 parent_hwnd_(NULL),
284 is_loading_(false), 284 is_loading_(false),
285 overlay_color_(0), 285 overlay_color_(0),
286 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 286 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
287 is_fullscreen_(false), 287 is_fullscreen_(false),
288 ignore_mouse_movement_(true) { 288 ignore_mouse_movement_(true),
289 composition_range_(ui::Range::InvalidRange()) {
289 render_widget_host_->SetView(this); 290 render_widget_host_->SetView(this);
290 registrar_.Add(this, 291 registrar_.Add(this,
291 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 292 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
292 content::NotificationService::AllBrowserContextsAndSources()); 293 content::NotificationService::AllBrowserContextsAndSources());
293 } 294 }
294 295
295 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { 296 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() {
296 UnlockMouse(); 297 UnlockMouse();
297 ResetTooltip(); 298 ResetTooltip();
298 } 299 }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD); 669 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD);
669 // Only update caret position if the input method is enabled. 670 // Only update caret position if the input method is enabled.
670 if (is_enabled) 671 if (is_enabled)
671 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect)); 672 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect));
672 } 673 }
673 674
674 void RenderWidgetHostViewWin::ImeCancelComposition() { 675 void RenderWidgetHostViewWin::ImeCancelComposition() {
675 ime_input_.CancelIME(m_hWnd); 676 ime_input_.CancelIME(m_hWnd);
676 } 677 }
677 678
679 void RenderWidgetHostViewWin::ImeCompositionRangeChanged(
680 const ui::Range& range) {
681 composition_range_ = range;
682 }
683
678 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { 684 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) {
679 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) 685 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd))
680 return TRUE; 686 return TRUE;
681 687
682 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); 688 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam);
683 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); 689 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName);
684 WPARAM wparam = rect->x() << 16 | rect->y(); 690 WPARAM wparam = rect->x() << 16 | rect->y();
685 lparam = rect->width() << 16 | rect->height(); 691 lparam = rect->width() << 16 | rect->height();
686 692
687 // SendMessage gets the message across much quicker than PostMessage, since it 693 // SendMessage gets the message across much quicker than PostMessage, since it
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 // of the renderer process. 1278 // of the renderer process.
1273 render_widget_host_->ImeCancelComposition(); 1279 render_widget_host_->ImeCancelComposition();
1274 ime_input_.ResetComposition(m_hWnd); 1280 ime_input_.ResetComposition(m_hWnd);
1275 } 1281 }
1276 ime_input_.DestroyImeWindow(m_hWnd); 1282 ime_input_.DestroyImeWindow(m_hWnd);
1277 // Let WTL call ::DefWindowProc() and release its resources. 1283 // Let WTL call ::DefWindowProc() and release its resources.
1278 handled = FALSE; 1284 handled = FALSE;
1279 return 0; 1285 return 0;
1280 } 1286 }
1281 1287
1288 LRESULT RenderWidgetHostViewWin::OnImeRequest(
1289 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
1290 if (!render_widget_host_) {
1291 handled = FALSE;
1292 return 0;
1293 }
1294
1295 // Should not receive WM_IME_REQUEST message, if IME is disabled.
1296 if (text_input_type_ == ui::TEXT_INPUT_TYPE_NONE ||
1297 text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) {
1298 handled = FALSE;
1299 return 0;
1300 }
1301
1302 switch (wparam) {
1303 case IMR_RECONVERTSTRING:
1304 return OnReconvertString(reinterpret_cast<RECONVERTSTRING*>(lparam));
1305 case IMR_DOCUMENTFEED:
1306 return OnDocumentFeed(reinterpret_cast<RECONVERTSTRING*>(lparam));
1307 default:
1308 handled = FALSE;
1309 return 0;
1310 }
1311 }
1312
1282 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, 1313 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam,
1283 LPARAM lparam, BOOL& handled) { 1314 LPARAM lparam, BOOL& handled) {
1284 handled = TRUE; 1315 handled = TRUE;
1285 1316
1286 if (message == WM_MOUSELEAVE) 1317 if (message == WM_MOUSELEAVE)
1287 ignore_mouse_movement_ = true; 1318 ignore_mouse_movement_ = true;
1288 1319
1289 if (mouse_locked_) { 1320 if (mouse_locked_) {
1290 HandleLockedMouseEvent(message, wparam, lparam); 1321 HandleLockedMouseEvent(message, wparam, lparam);
1291 MoveCursorToCenter(); 1322 MoveCursorToCenter();
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 2050
2020 if (message == WM_MOUSEMOVE) { 2051 if (message == WM_MOUSEMOVE) {
2021 CPoint center = GetClientCenter(); 2052 CPoint center = GetClientCenter();
2022 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). 2053 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter().
2023 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) 2054 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y)
2024 return; 2055 return;
2025 } 2056 }
2026 2057
2027 ForwardMouseEventToRenderer(message, wparam, lparam); 2058 ForwardMouseEventToRenderer(message, wparam, lparam);
2028 } 2059 }
2060
2061 LRESULT RenderWidgetHostViewWin::OnDocumentFeed(RECONVERTSTRING* reconv) {
2062 size_t target_offset;
2063 size_t target_length;
2064 bool has_composition;
2065 if (!composition_range_.is_empty()) {
2066 target_offset = composition_range_.GetMin();
2067 target_length = composition_range_.length();
2068 has_composition = true;
2069 } else if (selection_range_.IsValid()) {
2070 target_offset = selection_range_.GetMin();
2071 target_length = selection_range_.length();
2072 has_composition = false;
2073 } else {
2074 return 0;
2075 }
2076
2077 size_t len = selection_text_.length();
2078 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
2079
2080 if (target_offset < selection_text_offset_ ||
2081 target_offset + target_length > selection_text_offset_ + len) {
2082 return 0;
2083 }
2084
2085 if (!reconv)
2086 return need_size;
2087
2088 if (reconv->dwSize < need_size)
2089 return 0;
2090
2091 reconv->dwVersion = 0;
2092 reconv->dwStrLen = len;
2093 reconv->dwStrOffset = sizeof(RECONVERTSTRING);
2094 reconv->dwCompStrLen = has_composition ? target_length: 0;
2095 reconv->dwCompStrOffset =
2096 (target_offset - selection_text_offset_) * sizeof(WCHAR);
2097 reconv->dwTargetStrLen = target_length;
2098 reconv->dwTargetStrOffset = reconv->dwCompStrOffset;
2099 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING),
2100 selection_text_.c_str(), len * sizeof(WCHAR));
2101
2102 // According to Microsft API document, IMR_RECONVERTSTRING and
2103 // IMR_DOCUMENTFEED should return reconv, but some applications return
2104 // need_size.
2105 return reinterpret_cast<LRESULT>(reconv);
2106 }
2107
2108 LRESULT RenderWidgetHostViewWin::OnReconvertString(RECONVERTSTRING* reconv) {
2109 // If there is a composition string already, we don't allow reconversion.
2110 if (ime_input_.is_composing())
2111 return 0;
2112
2113 if (selection_range_.is_empty())
2114 return 0;
2115
2116 if (selection_text_.empty())
2117 return 0;
2118
2119 if (selection_range_.GetMin() < selection_text_offset_ ||
2120 selection_range_.GetMax() >
2121 selection_text_offset_ + selection_text_.length()) {
2122 return 0;
2123 }
2124
2125 size_t len = selection_range_.length();
2126 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
2127
2128 if (!reconv)
2129 return need_size;
2130
2131 if (reconv->dwSize < need_size)
2132 return 0;
2133
2134 reconv->dwVersion = 0;
2135 reconv->dwStrLen = len;
2136 reconv->dwStrOffset = sizeof(RECONVERTSTRING);
2137 reconv->dwCompStrLen = len;
2138 reconv->dwCompStrOffset = 0;
2139 reconv->dwTargetStrLen = len;
2140 reconv->dwTargetStrOffset = 0;
2141
2142 size_t offset = selection_range_.GetMin() - selection_text_offset_;
2143 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING),
2144 selection_text_.c_str() + offset, len * sizeof(WCHAR));
2145
2146 // According to Microsft API document, IMR_RECONVERTSTRING and
2147 // IMR_DOCUMENTFEED should return reconv, but some applications return
2148 // need_size.
2149 return reinterpret_cast<LRESULT>(reconv);
2150 }
OLDNEW
« 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