OLD | NEW |
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 close_on_deactivate_(false), | 225 close_on_deactivate_(false), |
226 being_destroyed_(false), | 226 being_destroyed_(false), |
227 tooltip_hwnd_(NULL), | 227 tooltip_hwnd_(NULL), |
228 tooltip_showing_(false), | 228 tooltip_showing_(false), |
229 shutdown_factory_(this), | 229 shutdown_factory_(this), |
230 parent_hwnd_(NULL), | 230 parent_hwnd_(NULL), |
231 is_loading_(false), | 231 is_loading_(false), |
232 overlay_color_(0), | 232 overlay_color_(0), |
233 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 233 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
234 is_fullscreen_(false), | 234 is_fullscreen_(false), |
235 ignore_mouse_movement_(true) { | 235 ignore_mouse_movement_(true), |
| 236 selection_text_offset_(0), |
| 237 selection_range_(ui::Range::InvalidRange()), |
| 238 composition_range_(ui::Range::InvalidRange()) { |
236 render_widget_host_->SetView(this); | 239 render_widget_host_->SetView(this); |
237 registrar_.Add(this, | 240 registrar_.Add(this, |
238 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 241 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
239 content::NotificationService::AllBrowserContextsAndSources()); | 242 content::NotificationService::AllBrowserContextsAndSources()); |
240 } | 243 } |
241 | 244 |
242 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { | 245 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { |
243 UnlockMouse(); | 246 UnlockMouse(); |
244 ResetTooltip(); | 247 ResetTooltip(); |
245 } | 248 } |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 type != ui::TEXT_INPUT_TYPE_PASSWORD); | 607 type != ui::TEXT_INPUT_TYPE_PASSWORD); |
605 if (text_input_type_ != type) { | 608 if (text_input_type_ != type) { |
606 text_input_type_ = type; | 609 text_input_type_ = type; |
607 if (is_enabled) | 610 if (is_enabled) |
608 ime_input_.EnableIME(m_hWnd); | 611 ime_input_.EnableIME(m_hWnd); |
609 else | 612 else |
610 ime_input_.DisableIME(m_hWnd); | 613 ime_input_.DisableIME(m_hWnd); |
611 } | 614 } |
612 } | 615 } |
613 | 616 |
| 617 void RenderWidgetHostViewWin::SelectionChanged( |
| 618 const string16& text, |
| 619 size_t offset, |
| 620 const ui::Range& range) { |
| 621 selection_text_ = text; |
| 622 selection_text_offset_ = offset; |
| 623 selection_range_ = range; |
| 624 } |
| 625 |
614 void RenderWidgetHostViewWin::SelectionBoundsChanged( | 626 void RenderWidgetHostViewWin::SelectionBoundsChanged( |
615 const gfx::Rect& start_rect, | 627 const gfx::Rect& start_rect, |
616 const gfx::Rect& end_rect) { | 628 const gfx::Rect& end_rect) { |
617 bool is_enabled = (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE && | 629 bool is_enabled = (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE && |
618 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD); | 630 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD); |
619 // Only update caret position if the input method is enabled. | 631 // Only update caret position if the input method is enabled. |
620 if (is_enabled) | 632 if (is_enabled) |
621 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect)); | 633 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect)); |
622 } | 634 } |
623 | 635 |
624 void RenderWidgetHostViewWin::ImeCancelComposition() { | 636 void RenderWidgetHostViewWin::ImeCancelComposition() { |
625 ime_input_.CancelIME(m_hWnd); | 637 ime_input_.CancelIME(m_hWnd); |
626 } | 638 } |
627 | 639 |
| 640 void RenderWidgetHostViewWin::ImeCompositionRangeChanged( |
| 641 const ui::Range& range) { |
| 642 composition_range_ = range; |
| 643 } |
| 644 |
628 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { | 645 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { |
629 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) | 646 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) |
630 return TRUE; | 647 return TRUE; |
631 | 648 |
632 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); | 649 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); |
633 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); | 650 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); |
634 WPARAM wparam = rect->x() << 16 | rect->y(); | 651 WPARAM wparam = rect->x() << 16 | rect->y(); |
635 lparam = rect->width() << 16 | rect->height(); | 652 lparam = rect->width() << 16 | rect->height(); |
636 | 653 |
637 // SendMessage gets the message across much quicker than PostMessage, since it | 654 // SendMessage gets the message across much quicker than PostMessage, since it |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 // of the renderer process. | 1225 // of the renderer process. |
1209 render_widget_host_->ImeCancelComposition(); | 1226 render_widget_host_->ImeCancelComposition(); |
1210 ime_input_.ResetComposition(m_hWnd); | 1227 ime_input_.ResetComposition(m_hWnd); |
1211 } | 1228 } |
1212 ime_input_.DestroyImeWindow(m_hWnd); | 1229 ime_input_.DestroyImeWindow(m_hWnd); |
1213 // Let WTL call ::DefWindowProc() and release its resources. | 1230 // Let WTL call ::DefWindowProc() and release its resources. |
1214 handled = FALSE; | 1231 handled = FALSE; |
1215 return 0; | 1232 return 0; |
1216 } | 1233 } |
1217 | 1234 |
| 1235 LRESULT RenderWidgetHostViewWin::OnDocumentFeed(RECONVERTSTRING* reconv) { |
| 1236 size_t target_offset; |
| 1237 size_t target_length; |
| 1238 bool has_composition; |
| 1239 if (!composition_range_.is_empty()) { |
| 1240 target_offset = composition_range_.GetMin(); |
| 1241 target_length = composition_range_.length(); |
| 1242 has_composition = true; |
| 1243 } else if (!selection_range_.is_empty()) { |
| 1244 target_offset = selection_range_.GetMin(); |
| 1245 target_length = selection_range_.length(); |
| 1246 has_composition = false; |
| 1247 } else { |
| 1248 return 0; |
| 1249 } |
| 1250 |
| 1251 size_t len = selection_text_.length(); |
| 1252 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| 1253 |
| 1254 if (target_offset < selection_text_offset_ || |
| 1255 target_offset + target_length > selection_text_offset_ + len) { |
| 1256 return 0; |
| 1257 } |
| 1258 |
| 1259 if (!reconv) |
| 1260 return need_size; |
| 1261 |
| 1262 if (reconv->dwSize < need_size) |
| 1263 return 0; |
| 1264 |
| 1265 reconv->dwVersion = 0; |
| 1266 reconv->dwStrLen = len; |
| 1267 reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| 1268 reconv->dwCompStrLen = has_composition ? target_length: 0; |
| 1269 reconv->dwCompStrOffset = |
| 1270 (target_offset - selection_text_offset_) * sizeof(WCHAR); |
| 1271 reconv->dwTargetStrLen = target_length; |
| 1272 reconv->dwTargetStrOffset = reconv->dwCompStrOffset; |
| 1273 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
| 1274 selection_text_.c_str(), len * sizeof(WCHAR)); |
| 1275 |
| 1276 return need_size; |
| 1277 } |
| 1278 |
| 1279 LRESULT RenderWidgetHostViewWin::OnReconvertString(RECONVERTSTRING* reconv) { |
| 1280 // If there is a composition string already, we don't allow reconversion. |
| 1281 if (ime_input_.is_composing()) |
| 1282 return 0; |
| 1283 |
| 1284 if (selection_range_.is_empty()) |
| 1285 return 0; |
| 1286 |
| 1287 if (selection_text_.empty()) |
| 1288 return 0; |
| 1289 |
| 1290 if (selection_range_.GetMin() < selection_text_offset_ || |
| 1291 selection_range_.GetMax() > |
| 1292 selection_text_offset_ + selection_text_.length()) { |
| 1293 return 0; |
| 1294 } |
| 1295 |
| 1296 size_t len = selection_range_.length(); |
| 1297 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| 1298 |
| 1299 if (!reconv) |
| 1300 return need_size; |
| 1301 |
| 1302 if (reconv->dwSize < need_size) |
| 1303 return 0; |
| 1304 |
| 1305 reconv->dwVersion = 0; |
| 1306 reconv->dwStrLen = len; |
| 1307 reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| 1308 reconv->dwCompStrLen = len; |
| 1309 reconv->dwCompStrOffset = 0; |
| 1310 reconv->dwTargetStrLen = len; |
| 1311 reconv->dwTargetStrOffset = 0; |
| 1312 |
| 1313 size_t offset = selection_range_.GetMin() - selection_text_offset_; |
| 1314 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
| 1315 selection_text_.c_str() + offset, len * sizeof(WCHAR)); |
| 1316 |
| 1317 return need_size; |
| 1318 } |
| 1319 |
| 1320 LRESULT RenderWidgetHostViewWin::OnImeRequest( |
| 1321 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
| 1322 if (!render_widget_host_) { |
| 1323 handled = FALSE; |
| 1324 return 0; |
| 1325 } |
| 1326 |
| 1327 switch (wparam) { |
| 1328 case IMR_RECONVERTSTRING: |
| 1329 return OnReconvertString(reinterpret_cast<RECONVERTSTRING*>(lparam)); |
| 1330 case IMR_DOCUMENTFEED: |
| 1331 return OnDocumentFeed(reinterpret_cast<RECONVERTSTRING*>(lparam)); |
| 1332 default: |
| 1333 handled = FALSE; |
| 1334 return 0; |
| 1335 } |
| 1336 } |
| 1337 |
1218 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, | 1338 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, |
1219 LPARAM lparam, BOOL& handled) { | 1339 LPARAM lparam, BOOL& handled) { |
1220 handled = TRUE; | 1340 handled = TRUE; |
1221 | 1341 |
1222 if (message == WM_MOUSELEAVE) | 1342 if (message == WM_MOUSELEAVE) |
1223 ignore_mouse_movement_ = true; | 1343 ignore_mouse_movement_ = true; |
1224 | 1344 |
1225 if (mouse_locked_) { | 1345 if (mouse_locked_) { |
1226 HandleLockedMouseEvent(message, wparam, lparam); | 1346 HandleLockedMouseEvent(message, wparam, lparam); |
1227 MoveCursorToCenter(); | 1347 MoveCursorToCenter(); |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 if (message == WM_MOUSEMOVE) { | 2060 if (message == WM_MOUSEMOVE) { |
1941 CPoint center = GetClientCenter(); | 2061 CPoint center = GetClientCenter(); |
1942 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). | 2062 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). |
1943 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) | 2063 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) |
1944 return; | 2064 return; |
1945 } | 2065 } |
1946 | 2066 |
1947 ForwardMouseEventToRenderer(message, wparam, lparam); | 2067 ForwardMouseEventToRenderer(message, wparam, lparam); |
1948 } | 2068 } |
1949 | 2069 |
OLD | NEW |