| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/render_widget_host_view_win.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/l10n_util_win.h" | 10 #include "app/l10n_util_win.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "gfx/rect.h" | 39 #include "gfx/rect.h" |
| 40 #include "grit/webkit_resources.h" | 40 #include "grit/webkit_resources.h" |
| 41 #include "skia/ext/skia_utils_win.h" | 41 #include "skia/ext/skia_utils_win.h" |
| 42 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 42 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
| 43 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" | 43 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" |
| 44 #include "views/accessibility/view_accessibility.h" | 44 #include "views/accessibility/view_accessibility.h" |
| 45 #include "views/focus/focus_manager.h" | 45 #include "views/focus/focus_manager.h" |
| 46 #include "views/focus/focus_util_win.h" | 46 #include "views/focus/focus_util_win.h" |
| 47 // Included for views::kReflectedMessage - TODO(beng): move this to win_util.h! | 47 // Included for views::kReflectedMessage - TODO(beng): move this to win_util.h! |
| 48 #include "views/widget/widget_win.h" | 48 #include "views/widget/widget_win.h" |
| 49 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 50 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 51 #include "webkit/glue/plugins/webplugin.h" |
| 49 #include "webkit/glue/webaccessibility.h" | 52 #include "webkit/glue/webaccessibility.h" |
| 50 #include "webkit/glue/webcursor.h" | 53 #include "webkit/glue/webcursor.h" |
| 51 #include "webkit/plugins/npapi/plugin_constants_win.h" | |
| 52 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | |
| 53 #include "webkit/plugins/npapi/webplugin.h" | |
| 54 | 54 |
| 55 using app::ViewProp; | 55 using app::ViewProp; |
| 56 using base::TimeDelta; | 56 using base::TimeDelta; |
| 57 using base::TimeTicks; | 57 using base::TimeTicks; |
| 58 using WebKit::WebInputEvent; | 58 using WebKit::WebInputEvent; |
| 59 using WebKit::WebInputEventFactory; | 59 using WebKit::WebInputEventFactory; |
| 60 using WebKit::WebMouseEvent; | 60 using WebKit::WebMouseEvent; |
| 61 using WebKit::WebTextDirection; | 61 using WebKit::WebTextDirection; |
| 62 using webkit::npapi::WebPluginGeometry; | 62 using webkit_glue::WebPluginGeometry; |
| 63 | 63 |
| 64 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; | 64 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; |
| 65 | 65 |
| 66 namespace { | 66 namespace { |
| 67 | 67 |
| 68 // Tooltips will wrap after this width. Yes, wrap. Imagine that! | 68 // Tooltips will wrap after this width. Yes, wrap. Imagine that! |
| 69 const int kTooltipMaxWidthPixels = 300; | 69 const int kTooltipMaxWidthPixels = 300; |
| 70 | 70 |
| 71 // Maximum number of characters we allow in a tooltip. | 71 // Maximum number of characters we allow in a tooltip. |
| 72 const int kMaxTooltipLength = 1024; | 72 const int kMaxTooltipLength = 1024; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 // How many times we try to find a PluginProcessHost whose process matches | 230 // How many times we try to find a PluginProcessHost whose process matches |
| 231 // the HWND. | 231 // the HWND. |
| 232 static const int kMaxTries = 5; | 232 static const int kMaxTries = 5; |
| 233 // How long to wait between each try. | 233 // How long to wait between each try. |
| 234 static const int kTryDelayMs = 200; | 234 static const int kTryDelayMs = 200; |
| 235 }; | 235 }; |
| 236 | 236 |
| 237 // Windows callback for OnDestroy to detach the plugin windows. | 237 // Windows callback for OnDestroy to detach the plugin windows. |
| 238 BOOL CALLBACK DetachPluginWindowsCallback(HWND window, LPARAM param) { | 238 BOOL CALLBACK DetachPluginWindowsCallback(HWND window, LPARAM param) { |
| 239 if (webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(window) && | 239 if (WebPluginDelegateImpl::IsPluginDelegateWindow(window) && |
| 240 !IsHungAppWindow(window)) { | 240 !IsHungAppWindow(window)) { |
| 241 ::ShowWindow(window, SW_HIDE); | 241 ::ShowWindow(window, SW_HIDE); |
| 242 SetParent(window, NULL); | 242 SetParent(window, NULL); |
| 243 } | 243 } |
| 244 return TRUE; | 244 return TRUE; |
| 245 } | 245 } |
| 246 | 246 |
| 247 // Draw the contents of |backing_store_dc| onto |paint_rect| with a 70% grey | 247 // Draw the contents of |backing_store_dc| onto |paint_rect| with a 70% grey |
| 248 // filter. | 248 // filter. |
| 249 void DrawDeemphasized(const SkColor& color, | 249 void DrawDeemphasized(const SkColor& color, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 wcex.cbSize = sizeof(WNDCLASSEX); | 483 wcex.cbSize = sizeof(WNDCLASSEX); |
| 484 wcex.style = CS_DBLCLKS; | 484 wcex.style = CS_DBLCLKS; |
| 485 wcex.lpfnWndProc = ::DefWindowProc; | 485 wcex.lpfnWndProc = ::DefWindowProc; |
| 486 wcex.cbClsExtra = 0; | 486 wcex.cbClsExtra = 0; |
| 487 wcex.cbWndExtra = 0; | 487 wcex.cbWndExtra = 0; |
| 488 wcex.hInstance = GetModuleHandle(NULL); | 488 wcex.hInstance = GetModuleHandle(NULL); |
| 489 wcex.hIcon = 0; | 489 wcex.hIcon = 0; |
| 490 wcex.hCursor = 0; | 490 wcex.hCursor = 0; |
| 491 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); | 491 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); |
| 492 wcex.lpszMenuName = 0; | 492 wcex.lpszMenuName = 0; |
| 493 wcex.lpszClassName = webkit::npapi::kWrapperNativeWindowClassName; | 493 wcex.lpszClassName = kWrapperNativeWindowClassName; |
| 494 wcex.hIconSm = 0; | 494 wcex.hIconSm = 0; |
| 495 window_class = RegisterClassEx(&wcex); | 495 window_class = RegisterClassEx(&wcex); |
| 496 } | 496 } |
| 497 DCHECK(window_class); | 497 DCHECK(window_class); |
| 498 | 498 |
| 499 // TODO(apatrick): the parent window is disabled if the plugin window is | 499 // TODO(apatrick): the parent window is disabled if the plugin window is |
| 500 // disabled so that mouse messages from the plugin window are passed on to the | 500 // disabled so that mouse messages from the plugin window are passed on to the |
| 501 // browser window. This does not work for regular plugins because it prevents | 501 // browser window. This does not work for regular plugins because it prevents |
| 502 // them from receiving mouse and keyboard input. WS_DISABLED is not | 502 // them from receiving mouse and keyboard input. WS_DISABLED is not |
| 503 // needed when the GPU process stops using child windows for 3D rendering. | 503 // needed when the GPU process stops using child windows for 3D rendering. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 // Only update caret position if the input method is enabled. | 647 // Only update caret position if the input method is enabled. |
| 648 if (type == WebKit::WebTextInputTypeText) | 648 if (type == WebKit::WebTextInputTypeText) |
| 649 ime_input_.UpdateCaretRect(m_hWnd, caret_rect); | 649 ime_input_.UpdateCaretRect(m_hWnd, caret_rect); |
| 650 } | 650 } |
| 651 | 651 |
| 652 void RenderWidgetHostViewWin::ImeCancelComposition() { | 652 void RenderWidgetHostViewWin::ImeCancelComposition() { |
| 653 ime_input_.CancelIME(m_hWnd); | 653 ime_input_.CancelIME(m_hWnd); |
| 654 } | 654 } |
| 655 | 655 |
| 656 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { | 656 BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lparam) { |
| 657 if (!webkit::npapi::WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) | 657 if (!WebPluginDelegateImpl::IsPluginDelegateWindow(hwnd)) |
| 658 return TRUE; | 658 return TRUE; |
| 659 | 659 |
| 660 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); | 660 gfx::Rect* rect = reinterpret_cast<gfx::Rect*>(lparam); |
| 661 static UINT msg = RegisterWindowMessage(webkit::npapi::kPaintMessageName); | 661 static UINT msg = RegisterWindowMessage(kPaintMessageName); |
| 662 WPARAM wparam = rect->x() << 16 | rect->y(); | 662 WPARAM wparam = rect->x() << 16 | rect->y(); |
| 663 lparam = rect->width() << 16 | rect->height(); | 663 lparam = rect->width() << 16 | rect->height(); |
| 664 | 664 |
| 665 // SendMessage gets the message across much quicker than PostMessage, since it | 665 // SendMessage gets the message across much quicker than PostMessage, since it |
| 666 // doesn't get queued. When the plugin thread calls PeekMessage or other | 666 // doesn't get queued. When the plugin thread calls PeekMessage or other |
| 667 // Win32 APIs, sent messages are dispatched automatically. | 667 // Win32 APIs, sent messages are dispatched automatically. |
| 668 SendNotifyMessage(hwnd, msg, wparam, lparam); | 668 SendNotifyMessage(hwnd, msg, wparam, lparam); |
| 669 | 669 |
| 670 return TRUE; | 670 return TRUE; |
| 671 } | 671 } |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 // an event to the renderer which would then eventually send over | 1440 // an event to the renderer which would then eventually send over |
| 1441 // a setFocus call to the plugin widget. This would ensure that | 1441 // a setFocus call to the plugin widget. This would ensure that |
| 1442 // the renderer (webkit) knows about the plugin widget receiving | 1442 // the renderer (webkit) knows about the plugin widget receiving |
| 1443 // focus. | 1443 // focus. |
| 1444 // TODO(iyengar) Do the right thing as per the above comment. | 1444 // TODO(iyengar) Do the right thing as per the above comment. |
| 1445 POINT cursor_pos = {0}; | 1445 POINT cursor_pos = {0}; |
| 1446 ::GetCursorPos(&cursor_pos); | 1446 ::GetCursorPos(&cursor_pos); |
| 1447 ::ScreenToClient(m_hWnd, &cursor_pos); | 1447 ::ScreenToClient(m_hWnd, &cursor_pos); |
| 1448 HWND child_window = ::RealChildWindowFromPoint(m_hWnd, cursor_pos); | 1448 HWND child_window = ::RealChildWindowFromPoint(m_hWnd, cursor_pos); |
| 1449 if (::IsWindow(child_window) && child_window != m_hWnd) { | 1449 if (::IsWindow(child_window) && child_window != m_hWnd) { |
| 1450 if (win_util::GetClassName(child_window) == | 1450 if (win_util::GetClassName(child_window) == kWrapperNativeWindowClassName) |
| 1451 webkit::npapi::kWrapperNativeWindowClassName) | |
| 1452 child_window = ::GetWindow(child_window, GW_CHILD); | 1451 child_window = ::GetWindow(child_window, GW_CHILD); |
| 1453 | 1452 |
| 1454 ::SetFocus(child_window); | 1453 ::SetFocus(child_window); |
| 1455 return MA_NOACTIVATE; | 1454 return MA_NOACTIVATE; |
| 1456 } | 1455 } |
| 1457 } | 1456 } |
| 1458 handled = FALSE; | 1457 handled = FALSE; |
| 1459 render_widget_host_->OnMouseActivate(); | 1458 render_widget_host_->OnMouseActivate(); |
| 1460 return MA_ACTIVATE; | 1459 return MA_ACTIVATE; |
| 1461 } | 1460 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 } | 1805 } |
| 1807 | 1806 |
| 1808 // static | 1807 // static |
| 1809 RenderWidgetHostView* | 1808 RenderWidgetHostView* |
| 1810 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1809 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 1811 gfx::NativeView native_view) { | 1810 gfx::NativeView native_view) { |
| 1812 return ::IsWindow(native_view) ? | 1811 return ::IsWindow(native_view) ? |
| 1813 reinterpret_cast<RenderWidgetHostView*>( | 1812 reinterpret_cast<RenderWidgetHostView*>( |
| 1814 ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; | 1813 ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; |
| 1815 } | 1814 } |
| OLD | NEW |