| 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/l10n_util_win.h" | 8 #include "app/l10n_util_win.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "app/view_prop.h" |
| 10 #include "app/win/scoped_prop.h" | 11 #include "app/win/scoped_prop.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/process_util.h" | 15 #include "base/process_util.h" |
| 15 #include "base/scoped_comptr_win.h" | 16 #include "base/scoped_comptr_win.h" |
| 16 #include "base/thread.h" | 17 #include "base/thread.h" |
| 17 #include "base/win_util.h" | 18 #include "base/win_util.h" |
| 18 #include "chrome/browser/accessibility/browser_accessibility_win.h" | 19 #include "chrome/browser/accessibility/browser_accessibility_win.h" |
| 19 #include "chrome/browser/accessibility/browser_accessibility_manager.h" | 20 #include "chrome/browser/accessibility/browser_accessibility_manager.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 44 #include "views/focus/focus_manager.h" | 45 #include "views/focus/focus_manager.h" |
| 45 #include "views/focus/focus_util_win.h" | 46 #include "views/focus/focus_util_win.h" |
| 46 // 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! |
| 47 #include "views/widget/widget_win.h" | 48 #include "views/widget/widget_win.h" |
| 48 #include "webkit/glue/plugins/plugin_constants_win.h" | 49 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 49 #include "webkit/glue/plugins/webplugin_delegate_impl.h" | 50 #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
| 50 #include "webkit/glue/plugins/webplugin.h" | 51 #include "webkit/glue/plugins/webplugin.h" |
| 51 #include "webkit/glue/webaccessibility.h" | 52 #include "webkit/glue/webaccessibility.h" |
| 52 #include "webkit/glue/webcursor.h" | 53 #include "webkit/glue/webcursor.h" |
| 53 | 54 |
| 55 using app::ViewProp; |
| 54 using base::TimeDelta; | 56 using base::TimeDelta; |
| 55 using base::TimeTicks; | 57 using base::TimeTicks; |
| 56 using WebKit::WebInputEvent; | 58 using WebKit::WebInputEvent; |
| 57 using WebKit::WebInputEventFactory; | 59 using WebKit::WebInputEventFactory; |
| 58 using WebKit::WebMouseEvent; | 60 using WebKit::WebMouseEvent; |
| 59 using WebKit::WebTextDirection; | 61 using WebKit::WebTextDirection; |
| 60 using webkit_glue::WebPluginGeometry; | 62 using webkit_glue::WebPluginGeometry; |
| 61 | 63 |
| 62 namespace { | 64 namespace { |
| 63 | 65 |
| 64 // Tooltips will wrap after this width. Yes, wrap. Imagine that! | 66 // Tooltips will wrap after this width. Yes, wrap. Imagine that! |
| 65 const int kTooltipMaxWidthPixels = 300; | 67 const int kTooltipMaxWidthPixels = 300; |
| 66 | 68 |
| 67 // Maximum number of characters we allow in a tooltip. | 69 // Maximum number of characters we allow in a tooltip. |
| 68 const int kMaxTooltipLength = 1024; | 70 const int kMaxTooltipLength = 1024; |
| 69 | 71 |
| 70 // A custom MSAA object id used to determine if a screen reader is actively | 72 // A custom MSAA object id used to determine if a screen reader is actively |
| 71 // listening for MSAA events. | 73 // listening for MSAA events. |
| 72 const int kIdCustom = 1; | 74 const int kIdCustom = 1; |
| 73 | 75 |
| 74 const wchar_t* kRenderWidgetHostViewKey = L"__RENDER_WIDGET_HOST_VIEW__"; | 76 const char* const kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
| 75 | 77 |
| 76 // A callback function for EnumThreadWindows to enumerate and dismiss | 78 // A callback function for EnumThreadWindows to enumerate and dismiss |
| 77 // any owned popop windows | 79 // any owned popop windows |
| 78 BOOL CALLBACK DismissOwnedPopups(HWND window, LPARAM arg) { | 80 BOOL CALLBACK DismissOwnedPopups(HWND window, LPARAM arg) { |
| 79 const HWND toplevel_hwnd = reinterpret_cast<HWND>(arg); | 81 const HWND toplevel_hwnd = reinterpret_cast<HWND>(arg); |
| 80 | 82 |
| 81 if (::IsWindowVisible(window)) { | 83 if (::IsWindowVisible(window)) { |
| 82 const HWND owner = ::GetWindow(window, GW_OWNER); | 84 const HWND owner = ::GetWindow(window, GW_OWNER); |
| 83 if (toplevel_hwnd == owner) { | 85 if (toplevel_hwnd == owner) { |
| 84 ::PostMessage(window, WM_CANCELMODE, 0, 0); | 86 ::PostMessage(window, WM_CANCELMODE, 0, 0); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 303 |
| 302 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { | 304 RenderWidgetHostViewWin::~RenderWidgetHostViewWin() { |
| 303 ResetTooltip(); | 305 ResetTooltip(); |
| 304 } | 306 } |
| 305 | 307 |
| 306 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { | 308 void RenderWidgetHostViewWin::CreateWnd(HWND parent) { |
| 307 Create(parent); // ATL function to create the window. | 309 Create(parent); // ATL function to create the window. |
| 308 | 310 |
| 309 // Add a property indicating that a particular renderer is associated with | 311 // Add a property indicating that a particular renderer is associated with |
| 310 // this window. Used by the GPU process to validate window handles it | 312 // this window. Used by the GPU process to validate window handles it |
| 311 // receives from renderer processes. | 313 // receives from renderer processes. As this is used by a separate process we |
| 314 // have to use ScopedProp here instead of ViewProp. |
| 312 int renderer_id = render_widget_host_->process()->id(); | 315 int renderer_id = render_widget_host_->process()->id(); |
| 313 props_.push_back( | 316 renderer_id_prop_.reset( |
| 314 new app::win::ScopedProp(m_hWnd, | 317 new app::win::ScopedProp(m_hWnd, |
| 315 chrome::kChromiumRendererIdProperty, | 318 chrome::kChromiumRendererIdProperty, |
| 316 reinterpret_cast<HANDLE>(renderer_id))); | 319 reinterpret_cast<HANDLE>(renderer_id))); |
| 317 } | 320 } |
| 318 | 321 |
| 319 /////////////////////////////////////////////////////////////////////////////// | 322 /////////////////////////////////////////////////////////////////////////////// |
| 320 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: | 323 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: |
| 321 | 324 |
| 322 void RenderWidgetHostViewWin::InitAsPopup( | 325 void RenderWidgetHostViewWin::InitAsPopup( |
| 323 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { | 326 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 794 |
| 792 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { | 795 LRESULT RenderWidgetHostViewWin::OnCreate(CREATESTRUCT* create_struct) { |
| 793 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale | 796 // Call the WM_INPUTLANGCHANGE message handler to initialize the input locale |
| 794 // of a browser process. | 797 // of a browser process. |
| 795 OnInputLangChange(0, 0); | 798 OnInputLangChange(0, 0); |
| 796 // Marks that window as supporting mouse-wheel messages rerouting so it is | 799 // Marks that window as supporting mouse-wheel messages rerouting so it is |
| 797 // scrolled when under the mouse pointer even if inactive. | 800 // scrolled when under the mouse pointer even if inactive. |
| 798 props_.push_back(views::SetWindowSupportsRerouteMouseWheel(m_hWnd)); | 801 props_.push_back(views::SetWindowSupportsRerouteMouseWheel(m_hWnd)); |
| 799 // Save away our HWND in the parent window as a property so that the | 802 // Save away our HWND in the parent window as a property so that the |
| 800 // accessibility code can find it. | 803 // accessibility code can find it. |
| 801 props_.push_back(new app::win::ScopedProp( | 804 props_.push_back(new ViewProp(GetParent(), |
| 802 GetParent(), kViewsNativeHostPropForAccessibility, | 805 kViewsNativeHostPropForAccessibility, |
| 803 m_hWnd)); | 806 m_hWnd)); |
| 804 props_.push_back(new app::win::ScopedProp( | 807 props_.push_back(new ViewProp(m_hWnd, kRenderWidgetHostViewKey, |
| 805 m_hWnd, kRenderWidgetHostViewKey, | 808 static_cast<RenderWidgetHostView*>(this))); |
| 806 static_cast<RenderWidgetHostView*>(this))); | |
| 807 return 0; | 809 return 0; |
| 808 } | 810 } |
| 809 | 811 |
| 810 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, | 812 void RenderWidgetHostViewWin::OnActivate(UINT action, BOOL minimized, |
| 811 HWND window) { | 813 HWND window) { |
| 812 // If the container is a popup, clicking elsewhere on screen should close the | 814 // If the container is a popup, clicking elsewhere on screen should close the |
| 813 // popup. | 815 // popup. |
| 814 if (close_on_deactivate_ && action == WA_INACTIVE) { | 816 if (close_on_deactivate_ && action == WA_INACTIVE) { |
| 815 // Send a windows message so that any derived classes | 817 // Send a windows message so that any derived classes |
| 816 // will get a change to override the default handling | 818 // will get a change to override the default handling |
| (...skipping 10 matching lines...) Expand all Loading... |
| 827 // as they have plugin instances active. Quicktime crashes in this case | 829 // as they have plugin instances active. Quicktime crashes in this case |
| 828 // because its windowing code cleans up an internal data structure that the | 830 // because its windowing code cleans up an internal data structure that the |
| 829 // handler for NPP_DestroyStream relies on. | 831 // handler for NPP_DestroyStream relies on. |
| 830 // | 832 // |
| 831 // The fix is to detach plugin windows from web contents when it is going | 833 // The fix is to detach plugin windows from web contents when it is going |
| 832 // away. This will prevent the plugin windows from getting destroyed | 834 // away. This will prevent the plugin windows from getting destroyed |
| 833 // automatically. The detached plugin windows will get cleaned up in proper | 835 // automatically. The detached plugin windows will get cleaned up in proper |
| 834 // sequence as part of the usual cleanup when the plugin instance goes away. | 836 // sequence as part of the usual cleanup when the plugin instance goes away. |
| 835 EnumChildWindows(m_hWnd, DetachPluginWindowsCallback, NULL); | 837 EnumChildWindows(m_hWnd, DetachPluginWindowsCallback, NULL); |
| 836 | 838 |
| 839 renderer_id_prop_.reset(); |
| 837 props_.reset(); | 840 props_.reset(); |
| 838 | 841 |
| 839 ResetTooltip(); | 842 ResetTooltip(); |
| 840 TrackMouseLeave(false); | 843 TrackMouseLeave(false); |
| 841 } | 844 } |
| 842 | 845 |
| 843 void RenderWidgetHostViewWin::OnPaint(HDC unused_dc) { | 846 void RenderWidgetHostViewWin::OnPaint(HDC unused_dc) { |
| 844 DCHECK(render_widget_host_->process()->HasConnection()); | 847 DCHECK(render_widget_host_->process()->HasConnection()); |
| 845 | 848 |
| 846 // If the GPU process is rendering directly into the View, | 849 // If the GPU process is rendering directly into the View, |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 shutdown_factory_.RevokeAll(); | 1631 shutdown_factory_.RevokeAll(); |
| 1629 if (render_widget_host_) | 1632 if (render_widget_host_) |
| 1630 render_widget_host_->Shutdown(); | 1633 render_widget_host_->Shutdown(); |
| 1631 // Do not touch any members at this point, |this| has been deleted. | 1634 // Do not touch any members at this point, |this| has been deleted. |
| 1632 } | 1635 } |
| 1633 | 1636 |
| 1634 // static | 1637 // static |
| 1635 RenderWidgetHostView* | 1638 RenderWidgetHostView* |
| 1636 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 1639 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 1637 gfx::NativeView native_view) { | 1640 gfx::NativeView native_view) { |
| 1638 if (::IsWindow(native_view)) { | 1641 return ::IsWindow(native_view) ? |
| 1639 HANDLE raw_render_host_view = ::GetProp(native_view, | 1642 reinterpret_cast<RenderWidgetHostView*>( |
| 1640 kRenderWidgetHostViewKey); | 1643 ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; |
| 1641 if (raw_render_host_view) | |
| 1642 return reinterpret_cast<RenderWidgetHostView*>(raw_render_host_view); | |
| 1643 } | |
| 1644 return NULL; | |
| 1645 } | 1644 } |
| OLD | NEW |