diff options
Diffstat (limited to 'chromium/content/browser/renderer_host/legacy_render_widget_host_win.cc')
-rw-r--r-- | chromium/content/browser/renderer_host/legacy_render_widget_host_win.cc | 111 |
1 files changed, 98 insertions, 13 deletions
diff --git a/chromium/content/browser/renderer_host/legacy_render_widget_host_win.cc b/chromium/content/browser/renderer_host/legacy_render_widget_host_win.cc index 7b880c4bee0..e09ded934c1 100644 --- a/chromium/content/browser/renderer_host/legacy_render_widget_host_win.cc +++ b/chromium/content/browser/renderer_host/legacy_render_widget_host_win.cc @@ -18,11 +18,14 @@ #include "content/browser/renderer_host/render_widget_host_view_aura.h" #include "content/public/common/content_switches.h" #include "ui/accessibility/platform/ax_system_caret_win.h" +#include "ui/aura/window.h" +#include "ui/aura/window_tree_host.h" #include "ui/base/ui_base_features.h" #include "ui/base/view_prop.h" #include "ui/base/win/direct_manipulation.h" #include "ui/base/win/internal_constants.h" #include "ui/base/win/window_event_target.h" +#include "ui/compositor/compositor.h" #include "ui/display/win/screen_win.h" #include "ui/gfx/geometry/rect.h" @@ -33,6 +36,43 @@ namespace content { // accessibility support. const int kIdScreenReaderHoneyPot = 1; +// DirectManipulation needs to poll for new events every frame while finger +// gesturing on touchpad. +class CompositorAnimationObserverForDirectManipulation + : public ui::CompositorAnimationObserver { + public: + CompositorAnimationObserverForDirectManipulation( + LegacyRenderWidgetHostHWND* render_widget_host_hwnd, + ui::Compositor* compositor) + : render_widget_host_hwnd_(render_widget_host_hwnd), + compositor_(compositor) { + DCHECK(compositor_); + compositor_->AddAnimationObserver(this); + } + + ~CompositorAnimationObserverForDirectManipulation() override { + if (compositor_) + compositor_->RemoveAnimationObserver(this); + } + + // ui::CompositorAnimationObserver + void OnAnimationStep(base::TimeTicks timestamp) override { + render_widget_host_hwnd_->PollForNextEvent(); + } + + // ui::CompositorAnimationObserver + void OnCompositingShuttingDown(ui::Compositor* compositor) override { + compositor->RemoveAnimationObserver(this); + compositor_ = nullptr; + } + + private: + LegacyRenderWidgetHostHWND* render_widget_host_hwnd_; + ui::Compositor* compositor_; + + DISALLOW_COPY_AND_ASSIGN(CompositorAnimationObserverForDirectManipulation); +}; + // static LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create( HWND parent) { @@ -57,6 +97,9 @@ LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create( } void LegacyRenderWidgetHostHWND::Destroy() { + // Stop the AnimationObserver when window close. + DestroyAnimationObserver(); + host_ = nullptr; if (::IsWindow(hwnd())) ::DestroyWindow(hwnd()); } @@ -64,6 +107,9 @@ void LegacyRenderWidgetHostHWND::Destroy() { void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) { if (GetWindowEventTarget(GetParent())) GetWindowEventTarget(GetParent())->HandleParentChanged(); + // Stop the AnimationObserver when window hide. eg. tab switch, move tab to + // another window. + DestroyAnimationObserver(); ::SetParent(hwnd(), parent); } @@ -73,10 +119,14 @@ HWND LegacyRenderWidgetHostHWND::GetParent() { void LegacyRenderWidgetHostHWND::Show() { ::ShowWindow(hwnd(), SW_SHOW); + if (direct_manipulation_helper_) + direct_manipulation_helper_->Activate(); } void LegacyRenderWidgetHostHWND::Hide() { ::ShowWindow(hwnd(), SW_HIDE); + if (direct_manipulation_helper_) + direct_manipulation_helper_->Deactivate(); } void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { @@ -85,8 +135,6 @@ void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { ::SetWindowPos(hwnd(), NULL, bounds_in_pixel.x(), bounds_in_pixel.y(), bounds_in_pixel.width(), bounds_in_pixel.height(), SWP_NOREDRAW); - if (direct_manipulation_helper_) - direct_manipulation_helper_->SetBounds(bounds_in_pixel); } void LegacyRenderWidgetHostHWND::MoveCaretTo(const gfx::Rect& bounds) { @@ -143,9 +191,8 @@ bool LegacyRenderWidgetHostHWND::Init() { // Direct Manipulation is enabled on Windows 10+. The CreateInstance function // returns NULL if Direct Manipulation is not available. direct_manipulation_helper_ = - ui::win::DirectManipulationHelper::CreateInstance(); - if (direct_manipulation_helper_) - direct_manipulation_helper_->Initialize(hwnd()); + ui::win::DirectManipulationHelper::CreateInstance( + hwnd(), GetWindowEventTarget(GetParent())); // Disable pen flicks (http://crbug.com/506977) base::win::DisableFlicks(hwnd()); @@ -280,12 +327,6 @@ LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message, handled = TRUE; } } - - if (direct_manipulation_helper_ && - (message == WM_MOUSEWHEEL || message == WM_MOUSEHWHEEL)) { - direct_manipulation_helper_->HandleMouseWheel(hwnd(), message, w_param, - l_param); - } return ret; } @@ -442,13 +483,57 @@ LRESULT LegacyRenderWidgetHostHWND::OnWindowPosChanged(UINT message, WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(l_param); if (direct_manipulation_helper_) { if (window_pos->flags & SWP_SHOWWINDOW) { - direct_manipulation_helper_->Activate(hwnd()); + direct_manipulation_helper_->Activate(); } else if (window_pos->flags & SWP_HIDEWINDOW) { - direct_manipulation_helper_->Deactivate(hwnd()); + direct_manipulation_helper_->Deactivate(); } } SetMsgHandled(FALSE); return 0; } +LRESULT LegacyRenderWidgetHostHWND::OnPointerHitTest(UINT message, + WPARAM w_param, + LPARAM l_param) { + if (!direct_manipulation_helper_) + return 0; + + // Update window event target for each DM_POINTERHITTEST. + if (direct_manipulation_helper_->OnPointerHitTest( + w_param, GetWindowEventTarget(GetParent()))) { + if (compositor_animation_observer_) { + // This is reach if Windows send a DM_POINTERHITTEST before the last + // DM_POINTERHITTEST receive READY status. We never see this but still + // worth to handle it. + return 0; + } + + CreateAnimationObserver(); + } + + return 0; +} + +void LegacyRenderWidgetHostHWND::PollForNextEvent() { + DCHECK(direct_manipulation_helper_); + + if (!direct_manipulation_helper_->PollForNextEvent()) + DestroyAnimationObserver(); +} + +void LegacyRenderWidgetHostHWND::CreateAnimationObserver() { + DCHECK(!compositor_animation_observer_); + DCHECK(host_); + DCHECK(host_->GetNativeView()->GetHost()); + DCHECK(host_->GetNativeView()->GetHost()->compositor()); + + compositor_animation_observer_ = + std::make_unique<CompositorAnimationObserverForDirectManipulation>( + this, host_->GetNativeView()->GetHost()->compositor()); +} + +void LegacyRenderWidgetHostHWND::DestroyAnimationObserver() { + compositor_animation_observer_.reset(); +} + } // namespace content |