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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD); | 664 text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD); |
664 // Only update caret position if the input method is enabled. | 665 // Only update caret position if the input method is enabled. |
665 if (is_enabled) | 666 if (is_enabled) |
666 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect)); | 667 ime_input_.UpdateCaretRect(m_hWnd, start_rect.Union(end_rect)); |
667 } | 668 } |
668 | 669 |
669 void RenderWidgetHostViewWin::ImeCancelComposition() { | 670 void RenderWidgetHostViewWin::ImeCancelComposition() { |
670 ime_input_.CancelIME(m_hWnd); | 671 ime_input_.CancelIME(m_hWnd); |
671 } | 672 } |
672 | 673 |
| 674 void RenderWidgetHostViewWin::ImeCompositionRangeChanged( |
| 675 const ui::Range& range) { |
| 676 composition_range_ = range; |
| 677 } |
| 678 |
673 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { | 679 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { |
674 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) | 680 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) |
675 return TRUE; | 681 return TRUE; |
676 | 682 |
677 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); | 683 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); |
678 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); | 684 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); |
679 WPARAM wparam = rect->x() << 16 | rect->y(); | 685 WPARAM wparam = rect->x() << 16 | rect->y(); |
680 lparam = rect->width() << 16 | rect->height(); | 686 lparam = rect->width() << 16 | rect->height(); |
681 | 687 |
682 // SendMessage gets the message across much quicker than PostMessage, since it | 688 // SendMessage gets the message across much quicker than PostMessage, since it |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 // of the renderer process. | 1276 // of the renderer process. |
1271 render_widget_host_->ImeCancelComposition(); | 1277 render_widget_host_->ImeCancelComposition(); |
1272 ime_input_.ResetComposition(m_hWnd); | 1278 ime_input_.ResetComposition(m_hWnd); |
1273 } | 1279 } |
1274 ime_input_.DestroyImeWindow(m_hWnd); | 1280 ime_input_.DestroyImeWindow(m_hWnd); |
1275 // Let WTL call ::DefWindowProc() and release its resources. | 1281 // Let WTL call ::DefWindowProc() and release its resources. |
1276 handled = FALSE; | 1282 handled = FALSE; |
1277 return 0; | 1283 return 0; |
1278 } | 1284 } |
1279 | 1285 |
| 1286 LRESULT RenderWidgetHostViewWin::OnImeRequest( |
| 1287 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
| 1288 if (!render_widget_host_) { |
| 1289 handled = FALSE; |
| 1290 return 0; |
| 1291 } |
| 1292 |
| 1293 // Should not receive WM_IME_REQUEST message, if IME is disabled. |
| 1294 if (text_input_type_ == ui::TEXT_INPUT_TYPE_NONE || |
| 1295 text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) { |
| 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 |
1280 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, | 1311 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, |
1281 LPARAM lparam, BOOL& handled) { | 1312 LPARAM lparam, BOOL& handled) { |
1282 handled = TRUE; | 1313 handled = TRUE; |
1283 | 1314 |
1284 if (message == WM_MOUSELEAVE) | 1315 if (message == WM_MOUSELEAVE) |
1285 ignore_mouse_movement_ = true; | 1316 ignore_mouse_movement_ = true; |
1286 | 1317 |
1287 if (mouse_locked_) { | 1318 if (mouse_locked_) { |
1288 HandleLockedMouseEvent(message, wparam, lparam); | 1319 HandleLockedMouseEvent(message, wparam, lparam); |
1289 MoveCursorToCenter(); | 1320 MoveCursorToCenter(); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2018 if (message == WM_MOUSEMOVE) { | 2049 if (message == WM_MOUSEMOVE) { |
2019 CPoint center = GetClientCenter(); | 2050 CPoint center = GetClientCenter(); |
2020 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). | 2051 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). |
2021 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) | 2052 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) |
2022 return; | 2053 return; |
2023 } | 2054 } |
2024 | 2055 |
2025 ForwardMouseEventToRenderer(message, wparam, lparam); | 2056 ForwardMouseEventToRenderer(message, wparam, lparam); |
2026 } | 2057 } |
2027 | 2058 |
| 2059 LRESULT RenderWidgetHostViewWin::OnDocumentFeed(RECONVERTSTRING* reconv) { |
| 2060 size_t target_offset; |
| 2061 size_t target_length; |
| 2062 bool has_composition; |
| 2063 if (!composition_range_.is_empty()) { |
| 2064 target_offset = composition_range_.GetMin(); |
| 2065 target_length = composition_range_.length(); |
| 2066 has_composition = true; |
| 2067 } else if (!selection_range_.is_empty()) { |
| 2068 target_offset = selection_range_.GetMin(); |
| 2069 target_length = selection_range_.length(); |
| 2070 has_composition = false; |
| 2071 } else { |
| 2072 return 0; |
| 2073 } |
| 2074 |
| 2075 size_t len = selection_text_.length(); |
| 2076 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| 2077 |
| 2078 if (target_offset < selection_text_offset_ || |
| 2079 target_offset + target_length > selection_text_offset_ + len) { |
| 2080 return 0; |
| 2081 } |
| 2082 |
| 2083 if (!reconv) |
| 2084 return need_size; |
| 2085 |
| 2086 if (reconv->dwSize < need_size) |
| 2087 return 0; |
| 2088 |
| 2089 reconv->dwVersion = 0; |
| 2090 reconv->dwStrLen = len; |
| 2091 reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| 2092 reconv->dwCompStrLen = has_composition ? target_length: 0; |
| 2093 reconv->dwCompStrOffset = |
| 2094 (target_offset - selection_text_offset_) * sizeof(WCHAR); |
| 2095 reconv->dwTargetStrLen = target_length; |
| 2096 reconv->dwTargetStrOffset = reconv->dwCompStrOffset; |
| 2097 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
| 2098 selection_text_.c_str(), len * sizeof(WCHAR)); |
| 2099 |
| 2100 return reinterpret_cast<LRESULT>(reconv); |
| 2101 } |
| 2102 |
| 2103 LRESULT RenderWidgetHostViewWin::OnReconvertString(RECONVERTSTRING* reconv) { |
| 2104 // If there is a composition string already, we don't allow reconversion. |
| 2105 if (ime_input_.is_composing()) |
| 2106 return 0; |
| 2107 |
| 2108 if (selection_range_.is_empty()) |
| 2109 return 0; |
| 2110 |
| 2111 if (selection_text_.empty()) |
| 2112 return 0; |
| 2113 |
| 2114 if (selection_range_.GetMin() < selection_text_offset_ || |
| 2115 selection_range_.GetMax() > |
| 2116 selection_text_offset_ + selection_text_.length()) { |
| 2117 return 0; |
| 2118 } |
| 2119 |
| 2120 size_t len = selection_range_.length(); |
| 2121 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| 2122 |
| 2123 if (!reconv) |
| 2124 return need_size; |
| 2125 |
| 2126 if (reconv->dwSize < need_size) |
| 2127 return 0; |
| 2128 |
| 2129 reconv->dwVersion = 0; |
| 2130 reconv->dwStrLen = len; |
| 2131 reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| 2132 reconv->dwCompStrLen = len; |
| 2133 reconv->dwCompStrOffset = 0; |
| 2134 reconv->dwTargetStrLen = len; |
| 2135 reconv->dwTargetStrOffset = 0; |
| 2136 |
| 2137 size_t offset = selection_range_.GetMin() - selection_text_offset_; |
| 2138 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
| 2139 selection_text_.c_str() + offset, len * sizeof(WCHAR)); |
| 2140 |
| 2141 return reinterpret_cast<LRESULT>(reconv); |
| 2142 } |
OLD | NEW |