| 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/bind.h" |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
| 15 #include "base/win/scoped_gdi_object.h" | 16 #include "base/win/scoped_gdi_object.h" |
| 16 #include "base/win/win_util.h" | 17 #include "base/win/win_util.h" |
| 18 #include "base/win/windows_version.h" |
| 17 #include "base/win/wrapped_window_proc.h" | 19 #include "base/win/wrapped_window_proc.h" |
| 18 #include "content/browser/accessibility/browser_accessibility_manager.h" | 20 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 19 #include "content/browser/accessibility/browser_accessibility_state.h" | 21 #include "content/browser/accessibility/browser_accessibility_state.h" |
| 20 #include "content/browser/accessibility/browser_accessibility_win.h" | 22 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 21 #include "content/browser/browser_thread.h" | 23 #include "content/browser/browser_thread.h" |
| 24 #include "content/browser/gpu/gpu_process_host.h" |
| 25 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 22 #include "content/browser/plugin_process_host.h" | 26 #include "content/browser/plugin_process_host.h" |
| 23 #include "content/browser/renderer_host/backing_store.h" | 27 #include "content/browser/renderer_host/backing_store.h" |
| 24 #include "content/browser/renderer_host/backing_store_win.h" | 28 #include "content/browser/renderer_host/backing_store_win.h" |
| 25 #include "content/browser/renderer_host/render_process_host.h" | 29 #include "content/browser/renderer_host/render_process_host.h" |
| 26 #include "content/browser/renderer_host/render_widget_host.h" | 30 #include "content/browser/renderer_host/render_widget_host.h" |
| 31 #include "content/common/gpu/gpu_messages.h" |
| 27 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 28 #include "content/common/plugin_messages.h" | 33 #include "content/common/plugin_messages.h" |
| 29 #include "content/common/view_messages.h" | 34 #include "content/common/view_messages.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/native_web_keyboard_event.h" | 36 #include "content/public/browser/native_web_keyboard_event.h" |
| 32 #include "content/public/browser/notification_types.h" | 37 #include "content/public/browser/notification_types.h" |
| 33 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
| 34 #include "skia/ext/skia_utils_win.h" | 39 #include "skia/ext/skia_utils_win.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" |
| 38 #include "ui/base/ime/composition_text.h" | 43 #include "ui/base/ime/composition_text.h" |
| 39 #include "ui/base/l10n/l10n_util_win.h" | 44 #include "ui/base/l10n/l10n_util_win.h" |
| 40 #include "ui/base/text/text_elider.h" | 45 #include "ui/base/text/text_elider.h" |
| 41 #include "ui/base/view_prop.h" | 46 #include "ui/base/view_prop.h" |
| 42 #include "ui/base/win/hwnd_util.h" | 47 #include "ui/base/win/hwnd_util.h" |
| 43 #include "ui/base/win/mouse_wheel_util.h" | 48 #include "ui/base/win/mouse_wheel_util.h" |
| 44 #include "ui/gfx/canvas.h" | 49 #include "ui/gfx/canvas.h" |
| 45 #include "ui/gfx/canvas_skia.h" | 50 #include "ui/gfx/canvas_skia.h" |
| 46 #include "ui/gfx/gdi_util.h" | 51 #include "ui/gfx/gdi_util.h" |
| 47 #include "ui/gfx/rect.h" | 52 #include "ui/gfx/rect.h" |
| 48 #include "ui/gfx/screen.h" | 53 #include "ui/gfx/screen.h" |
| 49 #include "webkit/glue/webaccessibility.h" | 54 #include "webkit/glue/webaccessibility.h" |
| 50 #include "webkit/glue/webcursor.h" | 55 #include "webkit/glue/webcursor.h" |
| 51 #include "webkit/plugins/npapi/plugin_constants_win.h" | 56 #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 52 #include "webkit/plugins/npapi/webplugin.h" | 57 #include "webkit/plugins/npapi/webplugin.h" |
| 53 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | 58 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
| 54 | 59 |
| 60 #pragma comment(lib, "d3d9.lib") |
| 61 |
| 55 using base::TimeDelta; | 62 using base::TimeDelta; |
| 56 using base::TimeTicks; | 63 using base::TimeTicks; |
| 57 using ui::ViewProp; | 64 using ui::ViewProp; |
| 58 using WebKit::WebInputEvent; | 65 using WebKit::WebInputEvent; |
| 59 using WebKit::WebInputEventFactory; | 66 using WebKit::WebInputEventFactory; |
| 60 using WebKit::WebMouseEvent; | 67 using WebKit::WebMouseEvent; |
| 61 using WebKit::WebTextDirection; | 68 using WebKit::WebTextDirection; |
| 62 using webkit::npapi::WebPluginGeometry; | 69 using webkit::npapi::WebPluginGeometry; |
| 63 | 70 |
| 64 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; | 71 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 case WM_MBUTTONDOWN: | 200 case WM_MBUTTONDOWN: |
| 194 ::SendMessage(GetParent(window), message, wparam, lparam); | 201 ::SendMessage(GetParent(window), message, wparam, lparam); |
| 195 return 0; | 202 return 0; |
| 196 default: | 203 default: |
| 197 break; | 204 break; |
| 198 } | 205 } |
| 199 } | 206 } |
| 200 return ::DefWindowProc(window, message, wparam, lparam); | 207 return ::DefWindowProc(window, message, wparam, lparam); |
| 201 } | 208 } |
| 202 | 209 |
| 210 void SendToGpuProcessHost(int gpu_host_id, IPC::Message* message) { |
| 211 GpuProcessHost* gpu_process_host = GpuProcessHost::FromID(gpu_host_id); |
| 212 if (!gpu_process_host) { |
| 213 delete message; |
| 214 return; |
| 215 } |
| 216 |
| 217 gpu_process_host->Send(message); |
| 218 } |
| 219 |
| 220 void PostTaskOnIOThread(const tracked_objects::Location& from_here, |
| 221 base::Closure task) { |
| 222 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, task); |
| 223 } |
| 224 |
| 203 // Must be dynamically loaded to avoid startup failures on Win XP. | 225 // Must be dynamically loaded to avoid startup failures on Win XP. |
| 204 typedef BOOL (WINAPI *ChangeWindowMessageFilterExFunction)( | 226 typedef BOOL (WINAPI *ChangeWindowMessageFilterExFunction)( |
| 205 HWND hwnd, | 227 HWND hwnd, |
| 206 UINT message, | 228 UINT message, |
| 207 DWORD action, | 229 DWORD action, |
| 208 PCHANGEFILTERSTRUCT change_filter_struct); | 230 PCHANGEFILTERSTRUCT change_filter_struct); |
| 209 ChangeWindowMessageFilterExFunction g_ChangeWindowMessageFilterEx; | 231 ChangeWindowMessageFilterExFunction g_ChangeWindowMessageFilterEx; |
| 210 | 232 |
| 211 } // namespace | 233 } // namespace |
| 212 | 234 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 235 ignore_mouse_movement_(true) { | 257 ignore_mouse_movement_(true) { |
| 236 render_widget_host_->SetView(this); | 258 render_widget_host_->SetView(this); |
| 237 registrar_.Add(this, | 259 registrar_.Add(this, |
| 238 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 260 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 239 content::NotificationService::AllBrowserContextsAndSources()); | 261 content::NotificationService::AllBrowserContextsAndSources()); |
| 240 } | 262 } |
| 241 | 263 |
| 242 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { | 264 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { |
| 243 UnlockMouse(); | 265 UnlockMouse(); |
| 244 ResetTooltip(); | 266 ResetTooltip(); |
| 267 |
| 268 if (accelerated_surface_) |
| 269 accelerated_surface_->Destroy(); |
| 245 } | 270 } |
| 246 | 271 |
| 247 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { | 272 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { |
| 248 Create(parent); // ATL function to create the window. | 273 Create(parent); // ATL function to create the window. |
| 249 } | 274 } |
| 250 | 275 |
| 251 /////////////////////////////////////////////////////////////////////////////// | 276 /////////////////////////////////////////////////////////////////////////////// |
| 252 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: | 277 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: |
| 253 | 278 |
| 254 void RenderWidgetHostViewWin::InitAsPopup( | 279 void RenderWidgetHostViewWin::InitAsPopup( |
| (...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 return 0; | 1597 return 0; |
| 1573 case WM_PAINT: | 1598 case WM_PAINT: |
| 1574 PaintCompositorHostWindow(hWnd); | 1599 PaintCompositorHostWindow(hWnd); |
| 1575 return 0; | 1600 return 0; |
| 1576 default: | 1601 default: |
| 1577 return DefWindowProc(hWnd, message, wParam, lParam); | 1602 return DefWindowProc(hWnd, message, wParam, lParam); |
| 1578 } | 1603 } |
| 1579 } | 1604 } |
| 1580 | 1605 |
| 1581 void RenderWidgetHostViewWin::ScheduleComposite() { | 1606 void RenderWidgetHostViewWin::ScheduleComposite() { |
| 1582 if (render_widget_host_) | 1607 // If we have a previous frame then present it immediately. Otherwise request |
| 1583 render_widget_host_->ScheduleComposite(); | 1608 // a new frame be composited. |
| 1609 if (accelerated_surface_.get()) { |
| 1610 accelerated_surface_->Present(); |
| 1611 } else { |
| 1612 if (render_widget_host_) |
| 1613 render_widget_host_->ScheduleComposite(); |
| 1614 } |
| 1584 } | 1615 } |
| 1585 | 1616 |
| 1586 // Creates a HWND within the RenderWidgetHostView that will serve as a host | 1617 // Creates a HWND within the RenderWidgetHostView that will serve as a host |
| 1587 // for a HWND that the GPU process will create. The host window is used | 1618 // for a HWND that the GPU process will create. The host window is used |
| 1588 // to Z-position the GPU's window relative to other plugin windows. | 1619 // to Z-position the GPU's window relative to other plugin windows. |
| 1589 gfx::PluginWindowHandle RenderWidgetHostViewWin::GetCompositingSurface() { | 1620 gfx::PluginWindowHandle RenderWidgetHostViewWin::GetCompositingSurface() { |
| 1590 // If the window has been created, don't recreate it a second time | 1621 // If the window has been created, don't recreate it a second time |
| 1591 if (compositor_host_window_) | 1622 if (compositor_host_window_) |
| 1592 return compositor_host_window_; | 1623 return compositor_host_window_; |
| 1593 | 1624 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 else | 1699 else |
| 1669 next = compositor_host_window_; | 1700 next = compositor_host_window_; |
| 1670 ::SetWindowPos(plugin_windows[i], next, 0, 0, 0, 0, | 1701 ::SetWindowPos(plugin_windows[i], next, 0, 0, 0, 0, |
| 1671 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); | 1702 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); |
| 1672 } | 1703 } |
| 1673 } else { | 1704 } else { |
| 1674 hide_compositor_window_at_next_paint_ = true; | 1705 hide_compositor_window_at_next_paint_ = true; |
| 1675 } | 1706 } |
| 1676 } | 1707 } |
| 1677 | 1708 |
| 1709 void RenderWidgetHostViewWin::AcceleratedSurfaceBuffersSwapped( |
| 1710 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, |
| 1711 int gpu_host_id) { |
| 1712 if (!accelerated_surface_.get() && compositor_host_window_) { |
| 1713 accelerated_surface_ = new AcceleratedSurface(compositor_host_window_); |
| 1714 accelerated_surface_->Initialize(); |
| 1715 } |
| 1716 |
| 1717 base::Closure acknowledge_task = |
| 1718 base::Bind(SendToGpuProcessHost, |
| 1719 gpu_host_id, |
| 1720 new AcceleratedSurfaceMsg_BuffersSwappedACK(params.route_id)); |
| 1721 |
| 1722 accelerated_surface_->AsyncPresentAndAcknowledge( |
| 1723 params.size, |
| 1724 params.surface_id, |
| 1725 base::Bind(PostTaskOnIOThread, |
| 1726 FROM_HERE, |
| 1727 acknowledge_task)); |
| 1728 } |
| 1729 |
| 1678 void RenderWidgetHostViewWin::SetAccessibilityFocus(int acc_obj_id) { | 1730 void RenderWidgetHostViewWin::SetAccessibilityFocus(int acc_obj_id) { |
| 1679 if (!render_widget_host_) | 1731 if (!render_widget_host_) |
| 1680 return; | 1732 return; |
| 1681 | 1733 |
| 1682 render_widget_host_->AccessibilitySetFocus(acc_obj_id); | 1734 render_widget_host_->AccessibilitySetFocus(acc_obj_id); |
| 1683 } | 1735 } |
| 1684 | 1736 |
| 1685 void RenderWidgetHostViewWin::AccessibilityDoDefaultAction(int acc_obj_id) { | 1737 void RenderWidgetHostViewWin::AccessibilityDoDefaultAction(int acc_obj_id) { |
| 1686 if (!render_widget_host_) | 1738 if (!render_widget_host_) |
| 1687 return; | 1739 return; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1939 | 1991 |
| 1940 if (message == WM_MOUSEMOVE) { | 1992 if (message == WM_MOUSEMOVE) { |
| 1941 CPoint center = GetClientCenter(); | 1993 CPoint center = GetClientCenter(); |
| 1942 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). | 1994 // Ignore WM_MOUSEMOVE messages generated by MoveCursorToCenter(). |
| 1943 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) | 1995 if (LOWORD(lparam) == center.x && HIWORD(lparam) == center.y) |
| 1944 return; | 1996 return; |
| 1945 } | 1997 } |
| 1946 | 1998 |
| 1947 ForwardMouseEventToRenderer(message, wparam, lparam); | 1999 ForwardMouseEventToRenderer(message, wparam, lparam); |
| 1948 } | 2000 } |
| 1949 | |
| OLD | NEW |