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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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::OnImeRequest( |
| 1209 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
| 1210 if (!render_widget_host_) { |
| 1211 handled = FALSE; |
| 1212 return 0; |
| 1213 } |
| 1214 |
| 1215 // Should not receive WM_IME_REQUEST message, if IME is disabled. |
| 1216 if (text_input_type_ == ui::TEXT_INPUT_TYPE_NONE || |
| 1217 text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) { |
| 1218 handled = FALSE; |
| 1219 return 0; |
| 1220 } |
| 1221 |
| 1222 switch (wparam) { |
| 1223 case IMR_RECONVERTSTRING: |
| 1224 return OnReconvertString(reinterpret_cast<RECONVERTSTRING*>(lparam)); |
| 1225 case IMR_DOCUMENTFEED: |
| 1226 return OnDocumentFeed(reinterpret_cast<RECONVERTSTRING*>(lparam)); |
| 1227 default: |
| 1228 handled = FALSE; |
| 1229 return 0; |
| 1230 } |
| 1231 } |
| 1232 |
1202 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, | 1233 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, |
1203 LPARAM lparam, BOOL& handled) { | 1234 LPARAM lparam, BOOL& handled) { |
1204 handled = TRUE; | 1235 handled = TRUE; |
1205 | 1236 |
1206 if (message == WM_MOUSELEAVE) | 1237 if (message == WM_MOUSELEAVE) |
1207 ignore_mouse_movement_ = true; | 1238 ignore_mouse_movement_ = true; |
1208 | 1239 |
1209 if (mouse_locked_) { | 1240 if (mouse_locked_) { |
1210 HandleLockedMouseEvent(message, wparam, lparam); | 1241 HandleLockedMouseEvent(message, wparam, lparam); |
1211 MoveCursorToCenter(); | 1242 MoveCursorToCenter(); |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 if (message == WM_MOUSEMOVE) { | 1955 if (message == WM_MOUSEMOVE) { |
1925 CPoint center = GetClientCenter(); | 1956 CPoint center = GetClientCenter(); |
1926 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). | 1957 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). |
1927 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) | 1958 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) |
1928 return; | 1959 return; |
1929 } | 1960 } |
1930 | 1961 |
1931 ForwardMouseEventToRenderer(message, wparam, lparam); | 1962 ForwardMouseEventToRenderer(message, wparam, lparam); |
1932 } | 1963 } |
1933 | 1964 |
| 1965 LRESULT RenderWidgetHostViewWin::OnDocumentFeed(RECONVERTSTRING* reconv) { |
| 1966 size_t target_offset; |
| 1967 size_t target_length; |
| 1968 bool has_composition; |
| 1969 if (!composition_range_.is_empty()) { |
| 1970 target_offset = composition_range_.GetMin(); |
| 1971 target_length = composition_range_.length(); |
| 1972 has_composition = true; |
| 1973 } else if (!selection_range_.is_empty()) { |
| 1974 target_offset = selection_range_.GetMin(); |
| 1975 target_length = selection_range_.length(); |
| 1976 has_composition = false; |
| 1977 } else { |
| 1978 return 0; |
| 1979 } |
| 1980 |
| 1981 size_t len = selection_text_.length(); |
| 1982 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| 1983 |
| 1984 if (target_offset < selection_text_offset_ || |
| 1985 target_offset + target_length > selection_text_offset_ + len) { |
| 1986 return 0; |
| 1987 } |
| 1988 |
| 1989 if (!reconv) |
| 1990 return need_size; |
| 1991 |
| 1992 if (reconv->dwSize < need_size) |
| 1993 return 0; |
| 1994 |
| 1995 reconv->dwVersion = 0; |
| 1996 reconv->dwStrLen = len; |
| 1997 reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| 1998 reconv->dwCompStrLen = has_composition ? target_length: 0; |
| 1999 reconv->dwCompStrOffset = |
| 2000 (target_offset - selection_text_offset_) * sizeof(WCHAR); |
| 2001 reconv->dwTargetStrLen = target_length; |
| 2002 reconv->dwTargetStrOffset = reconv->dwCompStrOffset; |
| 2003 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
| 2004 selection_text_.c_str(), len * sizeof(WCHAR)); |
| 2005 |
| 2006 return need_size; |
| 2007 } |
| 2008 |
| 2009 LRESULT RenderWidgetHostViewWin::OnReconvertString(RECONVERTSTRING* reconv) { |
| 2010 // If there is a composition string already, we don't allow reconversion. |
| 2011 if (ime_input_.is_composing()) |
| 2012 return 0; |
| 2013 |
| 2014 if (selection_range_.is_empty()) |
| 2015 return 0; |
| 2016 |
| 2017 if (selection_text_.empty()) |
| 2018 return 0; |
| 2019 |
| 2020 if (selection_range_.GetMin() < selection_text_offset_ || |
| 2021 selection_range_.GetMax() > |
| 2022 selection_text_offset_ + selection_text_.length()) { |
| 2023 return 0; |
| 2024 } |
| 2025 |
| 2026 size_t len = selection_text_.length(); |
| 2027 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); |
| 2028 |
| 2029 if (!reconv) |
| 2030 return need_size; |
| 2031 |
| 2032 if (reconv->dwSize < need_size) |
| 2033 return 0; |
| 2034 |
| 2035 reconv->dwVersion = 0; |
| 2036 reconv->dwStrLen = len; |
| 2037 reconv->dwStrOffset = sizeof(RECONVERTSTRING); |
| 2038 reconv->dwCompStrLen = selection_range_.length(); |
| 2039 reconv->dwCompStrOffset = |
| 2040 (selection_range_.GetMin() - selection_text_offset_) * sizeof(WCHAR); |
| 2041 reconv->dwTargetStrLen = reconv->dwCompStrLen; |
| 2042 reconv->dwTargetStrOffset = reconv->dwCompStrOffset; |
| 2043 |
| 2044 size_t offset = selection_range_.GetMin() - selection_text_offset_; |
| 2045 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), |
| 2046 selection_text_.c_str(), len * sizeof(WCHAR)); |
| 2047 |
| 2048 return need_size; |
| 2049 } |
OLD | NEW |