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