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 14 matching lines...) Expand all Loading... |
25 #include "content/browser/renderer_host/render_process_host.h" | 25 #include "content/browser/renderer_host/render_process_host.h" |
26 #include "content/browser/renderer_host/render_widget_host.h" | 26 #include "content/browser/renderer_host/render_widget_host.h" |
27 #include "content/common/plugin_messages.h" | 27 #include "content/common/plugin_messages.h" |
28 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/content_browser_client.h" | 30 #include "content/public/browser/content_browser_client.h" |
31 #include "content/public/browser/native_web_keyboard_event.h" | 31 #include "content/public/browser/native_web_keyboard_event.h" |
32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/notification_types.h" | 33 #include "content/public/browser/notification_types.h" |
34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 35 #include "content/public/common/page_zoom.h" |
35 #include "skia/ext/skia_utils_win.h" | 36 #include "skia/ext/skia_utils_win.h" |
36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
38 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" | 39 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" |
39 #include "ui/base/ime/composition_text.h" | 40 #include "ui/base/ime/composition_text.h" |
40 #include "ui/base/l10n/l10n_util_win.h" | 41 #include "ui/base/l10n/l10n_util_win.h" |
41 #include "ui/base/text/text_elider.h" | 42 #include "ui/base/text/text_elider.h" |
42 #include "ui/base/view_prop.h" | 43 #include "ui/base/view_prop.h" |
43 #include "ui/base/win/hwnd_util.h" | 44 #include "ui/base/win/hwnd_util.h" |
44 #include "ui/base/win/mouse_wheel_util.h" | 45 #include "ui/base/win/mouse_wheel_util.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 case WM_MBUTTONDOWN: | 195 case WM_MBUTTONDOWN: |
195 ::SendMessage(GetParent(window), message, wparam, lparam); | 196 ::SendMessage(GetParent(window), message, wparam, lparam); |
196 return 0; | 197 return 0; |
197 default: | 198 default: |
198 break; | 199 break; |
199 } | 200 } |
200 } | 201 } |
201 return ::DefWindowProc(window, message, wparam, lparam); | 202 return ::DefWindowProc(window, message, wparam, lparam); |
202 } | 203 } |
203 | 204 |
204 bool DecodeScrollGesture(WPARAM wParam, | 205 bool DecodeZoomGesture(HWND hwnd, const GESTUREINFO& gi, |
205 LPARAM lParam, | 206 content::PageZoom* zoom, |
| 207 POINT* zoom_center) { |
| 208 static long start = 0; |
| 209 static POINT zoom_first; |
| 210 |
| 211 if (gi.dwFlags == GF_BEGIN) { |
| 212 start = gi.ullArguments; |
| 213 zoom_first.x = gi.ptsLocation.x; |
| 214 zoom_first.y = gi.ptsLocation.y; |
| 215 ScreenToClient(hwnd, &zoom_first); |
| 216 return false; |
| 217 } |
| 218 |
| 219 if (gi.dwFlags == GF_END) |
| 220 return false; |
| 221 |
| 222 POINT zoom_second = {0}; |
| 223 zoom_second.x = gi.ptsLocation.x; |
| 224 zoom_second.y = gi.ptsLocation.y; |
| 225 ScreenToClient(hwnd, &zoom_second); |
| 226 |
| 227 zoom_center->x = (zoom_first.x + zoom_second.x) / 2; |
| 228 zoom_center->y = (zoom_first.y + zoom_second.y) / 2; |
| 229 |
| 230 double zoom_factor = |
| 231 static_cast<double>(gi.ullArguments)/static_cast<double>(start); |
| 232 |
| 233 *zoom = zoom_factor >= 1 ? content::PAGE_ZOOM_IN : |
| 234 content::PAGE_ZOOM_OUT; |
| 235 |
| 236 start = gi.ullArguments; |
| 237 zoom_first = zoom_second; |
| 238 return true; |
| 239 } |
| 240 |
| 241 bool DecodeScrollGesture(const GESTUREINFO& gi, |
206 POINT* start, | 242 POINT* start, |
207 POINT* delta){ | 243 POINT* delta){ |
208 // Windows gestures are streams of messages with begin/end messages that | 244 // Windows gestures are streams of messages with begin/end messages that |
209 // separate each new gesture. We key off the begin message to reset | 245 // separate each new gesture. We key off the begin message to reset |
210 // the static variables. | 246 // the static variables. |
211 static POINT last_pt; | 247 static POINT last_pt; |
212 static POINT start_pt; | 248 static POINT start_pt; |
213 | 249 |
214 GESTUREINFO gi = {sizeof(GESTUREINFO)}; | |
215 HGESTUREINFO gi_handle = reinterpret_cast<HGESTUREINFO>(lParam); | |
216 if (!::GetGestureInfo(gi_handle, &gi)) { | |
217 DWORD error = GetLastError(); | |
218 NOTREACHED() << "Unable to get gesture info. Error : " << error; | |
219 } | |
220 | |
221 if (gi.dwID != GID_PAN) | |
222 return false; | |
223 | |
224 if (gi.dwFlags == GF_BEGIN) { | 250 if (gi.dwFlags == GF_BEGIN) { |
225 delta->x = 0; | 251 delta->x = 0; |
226 delta->y = 0; | 252 delta->y = 0; |
227 start_pt.x = gi.ptsLocation.x; | 253 start_pt.x = gi.ptsLocation.x; |
228 start_pt.y = gi.ptsLocation.y; | 254 start_pt.y = gi.ptsLocation.y; |
229 } else { | 255 } else { |
230 delta->x = gi.ptsLocation.x - last_pt.x; | 256 delta->x = gi.ptsLocation.x - last_pt.x; |
231 delta->y = gi.ptsLocation.y - last_pt.y; | 257 delta->y = gi.ptsLocation.y - last_pt.y; |
232 } | 258 } |
233 last_pt.x = gi.ptsLocation.x; | 259 last_pt.x = gi.ptsLocation.x; |
234 last_pt.y = gi.ptsLocation.y; | 260 last_pt.y = gi.ptsLocation.y; |
235 *start = start_pt; | 261 *start = start_pt; |
236 ::CloseGestureInfoHandle(gi_handle); | |
237 return true; | 262 return true; |
238 } | 263 } |
239 | 264 |
240 WebKit::WebMouseWheelEvent MakeFakeScrollWheelEvent(HWND hwnd, | 265 WebKit::WebMouseWheelEvent MakeFakeScrollWheelEvent(HWND hwnd, |
241 POINT start, | 266 POINT start, |
242 POINT delta) { | 267 POINT delta) { |
243 WebKit::WebMouseWheelEvent result; | 268 WebKit::WebMouseWheelEvent result; |
244 result.type = WebInputEvent::MouseWheel; | 269 result.type = WebInputEvent::MouseWheel; |
245 result.timeStampSeconds = ::GetMessageTime() / 1000.0; | 270 result.timeStampSeconds = ::GetMessageTime() / 1000.0; |
246 result.button = WebMouseEvent::ButtonNone; | 271 result.button = WebMouseEvent::ButtonNone; |
247 result.globalX = start.x; | 272 result.globalX = start.x; |
248 result.globalY = start.y; | 273 result.globalY = start.y; |
249 // Map to window coordinates. | 274 // Map to window coordinates. |
250 POINT clientPoint = { result.globalX, result.globalY }; | 275 POINT client_point = { result.globalX, result.globalY }; |
251 MapWindowPoints(0, hwnd, &clientPoint, 1); | 276 MapWindowPoints(0, hwnd, &client_point, 1); |
252 result.x = clientPoint.x; | 277 result.x = client_point.x; |
253 result.y = clientPoint.y; | 278 result.y = client_point.y; |
254 result.windowX = result.x; | 279 result.windowX = result.x; |
255 result.windowY = result.y; | 280 result.windowY = result.y; |
256 // Note that we support diagonal scrolling. | 281 // Note that we support diagonal scrolling. |
257 result.deltaX = static_cast<float>(delta.x); | 282 result.deltaX = static_cast<float>(delta.x); |
258 result.wheelTicksX = WHEEL_DELTA; | 283 result.wheelTicksX = WHEEL_DELTA; |
259 result.deltaY = static_cast<float>(delta.y); | 284 result.deltaY = static_cast<float>(delta.y); |
260 result.wheelTicksY = WHEEL_DELTA; | 285 result.wheelTicksY = WHEEL_DELTA; |
261 return result; | 286 return result; |
262 } | 287 } |
263 | 288 |
264 } // namespace | 289 } // namespace |
265 | 290 |
266 /////////////////////////////////////////////////////////////////////////////// | 291 /////////////////////////////////////////////////////////////////////////////// |
267 // RenderWidgetHostViewWin, public: | 292 // RenderWidgetHostViewWin, public: |
268 | 293 |
269 RenderWidgetHostViewWin::RenderWidgetHostViewWin(RenderWidgetHost* widget) | 294 RenderWidgetHostViewWin::RenderWidgetHostViewWin(RenderWidgetHost* widget) |
270 : render_widget_host_(widget), | 295 : render_widget_host_(widget), |
271 compositor_host_window_(NULL), | 296 compositor_host_window_(NULL), |
272 hide_compositor_window_at_next_paint_(false), | 297 hide_compositor_window_at_next_paint_(false), |
273 track_mouse_leave_(false), | 298 track_mouse_leave_(false), |
274 ime_notification_(false), | 299 ime_notification_(false), |
275 capture_enter_key_(false), | 300 capture_enter_key_(false), |
276 is_hidden_(false), | 301 is_hidden_(false), |
277 about_to_validate_and_paint_(false), | 302 about_to_validate_and_paint_(false), |
278 close_on_deactivate_(false), | 303 close_on_deactivate_(false), |
279 being_destroyed_(false), | 304 being_destroyed_(false), |
280 tooltip_hwnd_(NULL), | 305 tooltip_hwnd_(NULL), |
281 tooltip_showing_(false), | 306 tooltip_showing_(false), |
282 shutdown_factory_(this), | 307 shutdown_factory_(this), |
283 parent_hwnd_(NULL), | 308 parent_hwnd_(NULL), |
284 is_loading_(false), | 309 is_loading_(false), |
285 overlay_color_(0), | 310 overlay_color_(0), |
286 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 311 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
287 is_fullscreen_(false), | 312 is_fullscreen_(false), |
288 ignore_mouse_movement_(true) { | 313 ignore_mouse_movement_(true), |
| 314 ignore_next_lbutton_message_at_same_location(false), |
| 315 last_pointer_down_location_(0) { |
289 render_widget_host_->SetView(this); | 316 render_widget_host_->SetView(this); |
290 registrar_.Add(this, | 317 registrar_.Add(this, |
291 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 318 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
292 content::NotificationService::AllBrowserContextsAndSources()); | 319 content::NotificationService::AllBrowserContextsAndSources()); |
293 } | 320 } |
294 | 321 |
295 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { | 322 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { |
296 UnlockMouse(); | 323 UnlockMouse(); |
297 ResetTooltip(); | 324 ResetTooltip(); |
298 } | 325 } |
299 | 326 |
300 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { | 327 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { |
301 Create(parent); // ATL function to create the window. | 328 // ATL function to create the window. |
| 329 Create(parent); |
302 } | 330 } |
303 | 331 |
304 /////////////////////////////////////////////////////////////////////////////// | 332 /////////////////////////////////////////////////////////////////////////////// |
305 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: | 333 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: |
306 | 334 |
307 void RenderWidgetHostViewWin::InitAsPopup( | 335 void RenderWidgetHostViewWin::InitAsPopup( |
308 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { | 336 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { |
309 close_on_deactivate_ = true; | 337 close_on_deactivate_ = true; |
310 DoPopupOrFullscreenInit(parent_host_view->GetNativeView(), pos, | 338 DoPopupOrFullscreenInit(parent_host_view->GetNativeView(), pos, |
311 WS_EX_TOOLWINDOW); | 339 WS_EX_TOOLWINDOW); |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 ime_input_.DestroyImeWindow(m_hWnd); | 1304 ime_input_.DestroyImeWindow(m_hWnd); |
1277 // Let WTL call ::DefWindowProc() and release its resources. | 1305 // Let WTL call ::DefWindowProc() and release its resources. |
1278 handled = FALSE; | 1306 handled = FALSE; |
1279 return 0; | 1307 return 0; |
1280 } | 1308 } |
1281 | 1309 |
1282 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, | 1310 LRESULT RenderWidgetHostViewWin::OnMouseEvent(UINT message, WPARAM wparam, |
1283 LPARAM lparam, BOOL& handled) { | 1311 LPARAM lparam, BOOL& handled) { |
1284 handled = TRUE; | 1312 handled = TRUE; |
1285 | 1313 |
| 1314 if (ignore_next_lbutton_message_at_same_location && |
| 1315 message == WM_LBUTTONDOWN) { |
| 1316 ignore_next_lbutton_message_at_same_location = false; |
| 1317 LPARAM last_location = last_pointer_down_location_; |
| 1318 last_pointer_down_location_ = 0; |
| 1319 if (last_location == lparam) |
| 1320 return 0; |
| 1321 } |
| 1322 |
1286 if (message == WM_MOUSELEAVE) | 1323 if (message == WM_MOUSELEAVE) |
1287 ignore_mouse_movement_ = true; | 1324 ignore_mouse_movement_ = true; |
1288 | 1325 |
1289 if (mouse_locked_) { | 1326 if (mouse_locked_) { |
1290 HandleLockedMouseEvent(message, wparam, lparam); | 1327 HandleLockedMouseEvent(message, wparam, lparam); |
1291 MoveCursorToCenter(); | 1328 MoveCursorToCenter(); |
1292 return 0; | 1329 return 0; |
1293 } | 1330 } |
1294 | 1331 |
1295 if (::IsWindow(tooltip_hwnd_)) { | 1332 if (::IsWindow(tooltip_hwnd_)) { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 ::SetFocus(child_window); | 1565 ::SetFocus(child_window); |
1529 return MA_NOACTIVATE; | 1566 return MA_NOACTIVATE; |
1530 } | 1567 } |
1531 } | 1568 } |
1532 handled = FALSE; | 1569 handled = FALSE; |
1533 render_widget_host_->OnMouseActivate(); | 1570 render_widget_host_->OnMouseActivate(); |
1534 return MA_ACTIVATE; | 1571 return MA_ACTIVATE; |
1535 } | 1572 } |
1536 | 1573 |
1537 LRESULT RenderWidgetHostViewWin::OnGestureEvent( | 1574 LRESULT RenderWidgetHostViewWin::OnGestureEvent( |
1538 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { | 1575 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
1539 // Right now we only decode scroll gestures and we forward to the page | 1576 |
1540 // as scroll events. | 1577 handled = FALSE; |
1541 POINT start; | 1578 |
1542 POINT delta; | 1579 GESTUREINFO gi = {sizeof(GESTUREINFO)}; |
1543 if (DecodeScrollGesture(wparam, lparam, &start, &delta)) { | 1580 HGESTUREINFO gi_handle = reinterpret_cast<HGESTUREINFO>(lparam); |
1544 handled = TRUE; | 1581 if (!::GetGestureInfo(gi_handle, &gi)) { |
1545 render_widget_host_->ForwardWheelEvent( | 1582 DWORD error = GetLastError(); |
1546 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); | 1583 NOTREACHED() << "Unable to get gesture info. Error : " << error; |
1547 } else { | 1584 return 0; |
1548 handled = FALSE; | |
1549 } | 1585 } |
| 1586 |
| 1587 if (gi.dwID == GID_ZOOM) { |
| 1588 content::PageZoom zoom = content::PAGE_ZOOM_RESET; |
| 1589 POINT zoom_center = {0}; |
| 1590 if (DecodeZoomGesture(m_hWnd, gi, &zoom, &zoom_center)) { |
| 1591 handled = TRUE; |
| 1592 Send(new ViewMsg_ZoomFactor(render_widget_host_->routing_id(), |
| 1593 zoom, zoom_center.x, zoom_center.y)); |
| 1594 } |
| 1595 } else if (gi.dwID == GID_PAN) { |
| 1596 // Right now we only decode scroll gestures and we forward to the page |
| 1597 // as scroll events. |
| 1598 POINT start; |
| 1599 POINT delta; |
| 1600 if (DecodeScrollGesture(gi, &start, &delta)) { |
| 1601 handled = TRUE; |
| 1602 render_widget_host_->ForwardWheelEvent( |
| 1603 MakeFakeScrollWheelEvent(m_hWnd, start, delta)); |
| 1604 } |
| 1605 } |
| 1606 ::CloseGestureInfoHandle(gi_handle); |
1550 return 0; | 1607 return 0; |
1551 } | 1608 } |
1552 | 1609 |
1553 void RenderWidgetHostViewWin::OnAccessibilityNotifications( | 1610 void RenderWidgetHostViewWin::OnAccessibilityNotifications( |
1554 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { | 1611 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { |
1555 if (!browser_accessibility_manager_.get()) { | 1612 if (!browser_accessibility_manager_.get()) { |
1556 browser_accessibility_manager_.reset( | 1613 browser_accessibility_manager_.reset( |
1557 BrowserAccessibilityManager::CreateEmptyDocument( | 1614 BrowserAccessibilityManager::CreateEmptyDocument( |
1558 m_hWnd, static_cast<WebAccessibility::State>(0), this)); | 1615 m_hWnd, static_cast<WebAccessibility::State>(0), this)); |
1559 } | 1616 } |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1824 case WM_RBUTTONDOWN: | 1881 case WM_RBUTTONDOWN: |
1825 case WM_MBUTTONDOWN: | 1882 case WM_MBUTTONDOWN: |
1826 render_widget_host_->StartUserGesture(); | 1883 render_widget_host_->StartUserGesture(); |
1827 break; | 1884 break; |
1828 default: | 1885 default: |
1829 break; | 1886 break; |
1830 } | 1887 } |
1831 return 0; | 1888 return 0; |
1832 } | 1889 } |
1833 | 1890 |
| 1891 LRESULT RenderWidgetHostViewWin::OnPointerMessage( |
| 1892 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { |
| 1893 POINT point = {0}; |
| 1894 |
| 1895 point.x = GET_X_LPARAM(lparam); |
| 1896 point.y = GET_Y_LPARAM(lparam); |
| 1897 ScreenToClient(&point); |
| 1898 |
| 1899 lparam = MAKELPARAM(point.x, point.y); |
| 1900 |
| 1901 if (message == WM_POINTERDOWN) { |
| 1902 OnMouseEvent(WM_LBUTTONDOWN, MK_LBUTTON, lparam, handled); |
| 1903 ignore_next_lbutton_message_at_same_location = true; |
| 1904 last_pointer_down_location_ = lparam; |
| 1905 } else if (message == WM_POINTERUP) { |
| 1906 OnMouseEvent(WM_LBUTTONUP, MK_LBUTTON, lparam, handled); |
| 1907 } |
| 1908 handled = FALSE; |
| 1909 return 0; |
| 1910 } |
| 1911 |
1834 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) { | 1912 void RenderWidgetHostViewWin::OnFinalMessage(HWND window) { |
1835 // When the render widget host is being destroyed, it ends up calling | 1913 // When the render widget host is being destroyed, it ends up calling |
1836 // Destroy() which NULLs render_widget_host_. | 1914 // Destroy() which NULLs render_widget_host_. |
1837 // Note: the following bug http://crbug.com/24248 seems to report that | 1915 // Note: the following bug http://crbug.com/24248 seems to report that |
1838 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not | 1916 // OnFinalMessage is called with a deleted |render_widget_host_|. It is not |
1839 // clear how this could happen, hence the NULLing of render_widget_host_ | 1917 // clear how this could happen, hence the NULLing of render_widget_host_ |
1840 // above. | 1918 // above. |
1841 if (!render_widget_host_ && !being_destroyed_) { | 1919 if (!render_widget_host_ && !being_destroyed_) { |
1842 // If you hit this NOTREACHED, please add a comment to report it on | 1920 // If you hit this NOTREACHED, please add a comment to report it on |
1843 // http://crbug.com/24248, including what you did when it happened and if | 1921 // http://crbug.com/24248, including what you did when it happened and if |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 | 2097 |
2020 if (message == WM_MOUSEMOVE) { | 2098 if (message == WM_MOUSEMOVE) { |
2021 CPoint center = GetClientCenter(); | 2099 CPoint center = GetClientCenter(); |
2022 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). | 2100 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). |
2023 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) | 2101 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) |
2024 return; | 2102 return; |
2025 } | 2103 } |
2026 | 2104 |
2027 ForwardMouseEventToRenderer(message, wparam, lparam); | 2105 ForwardMouseEventToRenderer(message, wparam, lparam); |
2028 } | 2106 } |
OLD | NEW |