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

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: Fix review issues 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 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 close_on_deactivate_(false), 217 close_on_deactivate_(false),
218 being_destroyed_(false), 218 being_destroyed_(false),
219 tooltip_hwnd_(NULL), 219 tooltip_hwnd_(NULL),
220 tooltip_showing_(false), 220 tooltip_showing_(false),
221 shutdown_factory_(this), 221 shutdown_factory_(this),
222 parent_hwnd_(NULL), 222 parent_hwnd_(NULL),
223 is_loading_(false), 223 is_loading_(false),
224 overlay_color_(0), 224 overlay_color_(0),
225 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 225 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
226 is_fullscreen_(false), 226 is_fullscreen_(false),
227 ignore_mouse_movement_(true) { 227 ignore_mouse_movement_(true),
228 composition_range_(ui::Range::InvalidRange()) {
228 render_widget_host_->SetView(this); 229 render_widget_host_->SetView(this);
229 registrar_.Add(this, 230 registrar_.Add(this,
230 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 231 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
231 content::NotificationService::AllBrowserContextsAndSources()); 232 content::NotificationService::AllBrowserContextsAndSources());
232 } 233 }
233 234
234 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { 235 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() {
235 UnlockMouse(); 236 UnlockMouse();
236 ResetTooltip(); 237 ResetTooltip();
237 } 238 }
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD); 603 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD);
603 // Only update caret position if the input method is enabled. 604 // Only update caret position if the input method is enabled.
604 if (is_enabled) 605 if (is_enabled)
605 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect)); 606 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect));
606 } 607 }
607 608
608 void RenderWidgetHostViewWin::ImeCancelComposition() { 609 void RenderWidgetHostViewWin::ImeCancelComposition() {
609 ime_input_.CancelIME(m_hWnd); 610 ime_input_.CancelIME(m_hWnd);
610 } 611 }
611 612
613 void RenderWidgetHostViewWin::ImeCompositionRangeChanged(
614 const ui::Range& range) {
615 composition_range_ = range;
616 }
617
612 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { 618 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) {
613 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) 619 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd))
614 return TRUE; 620 return TRUE;
615 621
616 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); 622 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam);
617 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); 623 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName);
618 WPARAM wparam = rect->x() << 16 | rect->y(); 624 WPARAM wparam = rect->x() << 16 | rect->y();
619 lparam = rect->width() << 16 | rect->height(); 625 lparam = rect->width() << 16 | rect->height();
620 626
621 // SendMessage gets the message across much quicker than PostMessage, since it 627 // SendMessage gets the message across much quicker than PostMessage, since it
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 // of the renderer process. 1198 // of the renderer process.
1193 render_widget_host_->ImeCancelComposition(); 1199 render_widget_host_->ImeCancelComposition();
1194 ime_input_.ResetComposition(m_hWnd); 1200 ime_input_.ResetComposition(m_hWnd);
1195 } 1201 }
1196 ime_input_.DestroyImeWindow(m_hWnd); 1202 ime_input_.DestroyImeWindow(m_hWnd);
1197 // Let WTL call ::DefWindowProc() and release its resources. 1203 // Let WTL call ::DefWindowProc() and release its resources.
1198 handled = FALSE; 1204 handled = FALSE;
1199 return 0; 1205 return 0;
1200 } 1206 }
1201 1207
1208 LRESULT RenderWidgetHostViewWin::OnDocumentFeed(RECONVERTSTRING* reconv) {
1209 size_t target_offset;
1210 size_t target_length;
1211 bool has_composition;
1212 if (!composition_range_.is_empty()) {
1213 target_offset = composition_range_.GetMin();
1214 target_length = composition_range_.length();
1215 has_composition = true;
1216 } else if (!selection_range_.is_empty()) {
1217 target_offset = selection_range_.GetMin();
1218 target_length = selection_range_.length();
1219 has_composition = false;
1220 } else {
1221 return 0;
1222 }
1223
1224 size_t len = selection_text_.length();
1225 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
1226
1227 if (target_offset < selection_text_offset_ ||
1228 target_offset + target_length > selection_text_offset_ + len) {
1229 return 0;
1230 }
1231
1232 if (!reconv)
1233 return need_size;
1234
1235 if (reconv->dwSize < need_size)
1236 return 0;
1237
1238 reconv->dwVersion = 0;
1239 reconv->dwStrLen = len;
1240 reconv->dwStrOffset = sizeof(RECONVERTSTRING);
1241 reconv->dwCompStrLen = has_composition ? target_length: 0;
1242 reconv->dwCompStrOffset =
1243 (target_offset - selection_text_offset_) * sizeof(WCHAR);
1244 reconv->dwTargetStrLen = target_length;
1245 reconv->dwTargetStrOffset = reconv->dwCompStrOffset;
1246 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING),
1247 selection_text_.c_str(), len * sizeof(WCHAR));
1248
1249 return need_size;
1250 }
1251
1252 LRESULT RenderWidgetHostViewWin::OnReconvertString(RECONVERTSTRING* reconv) {
1253 // If there is a composition string already, we don't allow reconversion.
1254 if (ime_input_.is_composing())
1255 return 0;
1256
1257 if (selection_range_.is_empty())
1258 return 0;
1259
1260 if (selection_text_.empty())
1261 return 0;
1262
1263 if (selection_range_.GetMin() < selection_text_offset_ ||
1264 selection_range_.GetMax() >
1265 selection_text_offset_ + selection_text_.length()) {
1266 return 0;
1267 }
1268
1269 size_t len = selection_range_.length();
1270 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
1271
1272 if (!reconv)
1273 return need_size;
1274
1275 if (reconv->dwSize < need_size)
1276 return 0;
1277
1278 reconv->dwVersion = 0;
1279 reconv->dwStrLen = len;
1280 reconv->dwStrOffset = sizeof(RECONVERTSTRING);
1281 reconv->dwCompStrLen = len;
1282 reconv->dwCompStrOffset = 0;
1283 reconv->dwTargetStrLen = len;
1284 reconv->dwTargetStrOffset = 0;
1285
1286 size_t offset = selection_range_.GetMin() - selection_text_offset_;
1287 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING),
1288 selection_text_.c_str() + offset, len * sizeof(WCHAR));
1289
1290 return need_size;
1291 }
1292
1293 LRESULT RenderWidgetHostViewWin::OnImeRequest(
1294 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
1295 if (!render_widget_host_) {
1296 handled = FALSE;
1297 return 0;
1298 }
1299
1300 switch (wparam) {
1301 case IMR_RECONVERTSTRING:
1302 return OnReconvertString(reinterpret_cast<RECONVERTSTRING*>(lparam));
1303 case IMR_DOCUMENTFEED:
1304 return OnDocumentFeed(reinterpret_cast<RECONVERTSTRING*>(lparam));
1305 default:
1306 handled = FALSE;
1307 return 0;
1308 }
1309 }
1310
1202 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, 1311 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam,
1203 LPARAM lparam, BOOL& handled) { 1312 LPARAM lparam, BOOL& handled) {
1204 handled = TRUE; 1313 handled = TRUE;
1205 1314
1206 if (message == WM_MOUSELEAVE) 1315 if (message == WM_MOUSELEAVE)
1207 ignore_mouse_movement_ = true; 1316 ignore_mouse_movement_ = true;
1208 1317
1209 if (mouse_locked_) { 1318 if (mouse_locked_) {
1210 HandleLockedMouseEvent(message, wparam, lparam); 1319 HandleLockedMouseEvent(message, wparam, lparam);
1211 MoveCursorToCenter(); 1320 MoveCursorToCenter();
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 if (message == WM_MOUSEMOVE) { 2033 if (message == WM_MOUSEMOVE) {
1925 CPoint center = GetClientCenter(); 2034 CPoint center = GetClientCenter();
1926 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). 2035 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter().
1927 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) 2036 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y)
1928 return; 2037 return;
1929 } 2038 }
1930 2039
1931 ForwardMouseEventToRenderer(message, wparam, lparam); 2040 ForwardMouseEventToRenderer(message, wparam, lparam);
1932 } 2041 }
1933 2042
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698