Commit 07da8ba6 authored by chaopeng's avatar chaopeng Committed by Commit Bot

Reland "Recreate DirectManipulationHelper when every LRWHH UpdateParent"

This is a reland of 61450bbc

Original change's description:
> Recreate DirectManipulationHelper when every LRWHH UpdateParent
>
> Compositor and window event target is associated with window's parent. We call
> LRWHH UpdateParent when window's parent update, includes window's parent
> actually update and window initialize. Recreate DirectManipulationHelper on
> every window's parent update helps keep DirectManipulationHelper lifecycle
> tracking simpler. We also make CompositorAnimationObserver owned by
> DirectManipulationHelper.
>
> With this changes, we start the DirectManipulation event polling when
> DirectManipulationHelper created and stop when it destroyed. The issue should be
> fix since event polling start no more depends on DM_POINTERHITTEST.
>
>
> This also includes 2 refactoring changes:
>
> 1. Move CompositorAnimationObserver into DirectManipulationHelper.
> 2. Call ZoomToRect to reset viewport of DirectManipulation when viewport is
>    actually transformed in RUNNING - READAY sequence.
>
> Bug: 914914
> Change-Id: I0a63f9a407e0231d631e64f2b22a9975471f2fd9
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547049
> Reviewed-by: Scott Violet <sky@chromium.org>
> Commit-Queue: Jianpeng Chao <chaopeng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#649342}

TBR=sky@chromium.org

Bug: 914914
Change-Id: Ic0c8aa84d21fe7a88fd9d3552dbd5ffdb6adcc4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1562582
Commit-Queue: Jianpeng Chao <chaopeng@chromium.org>
Reviewed-by: default avatarJianpeng Chao <chaopeng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649682}
parent e01759d6
...@@ -175,19 +175,24 @@ HRESULT DirectManipulationEventHandler::OnViewportStatusChanged( ...@@ -175,19 +175,24 @@ HRESULT DirectManipulationEventHandler::OnViewportStatusChanged(
if (current != DIRECTMANIPULATION_READY) if (current != DIRECTMANIPULATION_READY)
return S_OK; return S_OK;
// Reset the viewport when we're idle, so the content transforms always start // Normally gesture sequence will receive 2 READY message, the first one is
// at identity. // gesture end, the second one is from viewport reset. We don't have content
// Every animation will receive 2 ready message, we should stop request // transform in the second RUNNING -> READY. We should not reset on an empty
// compositor animation at the second ready. // RUNNING -> READY sequence.
first_ready_ = !first_ready_; if (!FloatEquals(1.0f, last_scale_) || last_x_offset_ != 0 ||
HRESULT hr = helper_->Reset(first_ready_); last_y_offset_ != 0) {
HRESULT hr = helper_->Reset();
if (!SUCCEEDED(hr))
return hr;
}
last_scale_ = 1.0f; last_scale_ = 1.0f;
last_x_offset_ = 0.0f; last_x_offset_ = 0.0f;
last_y_offset_ = 0.0f; last_y_offset_ = 0.0f;
TransitionToState(GestureState::kNone); TransitionToState(GestureState::kNone);
return hr; return S_OK;
} }
HRESULT DirectManipulationEventHandler::OnViewportUpdated( HRESULT DirectManipulationEventHandler::OnViewportUpdated(
......
...@@ -71,7 +71,6 @@ class DirectManipulationEventHandler ...@@ -71,7 +71,6 @@ class DirectManipulationEventHandler
float last_scale_ = 1.0f; float last_scale_ = 1.0f;
int last_x_offset_ = 0; int last_x_offset_ = 0;
int last_y_offset_ = 0; int last_y_offset_ = 0;
bool first_ready_ = false;
bool should_send_scroll_begin_ = false; bool should_send_scroll_begin_ = false;
// Current recognized gesture from Direct Manipulation. // Current recognized gesture from Direct Manipulation.
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/base/win/window_event_target.h" #include "ui/base/win/window_event_target.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_animation_observer.h"
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -38,8 +40,9 @@ void DebugLogging(const std::string& s, HRESULT hr) { ...@@ -38,8 +40,9 @@ void DebugLogging(const std::string& s, HRESULT hr) {
// static // static
std::unique_ptr<DirectManipulationHelper> std::unique_ptr<DirectManipulationHelper>
DirectManipulationHelper::CreateInstance(HWND window, DirectManipulationHelper::CreateInstance(HWND window,
ui::Compositor* compositor,
ui::WindowEventTarget* event_target) { ui::WindowEventTarget* event_target) {
if (!::IsWindow(window)) if (!::IsWindow(window) || !compositor || !event_target)
return nullptr; return nullptr;
if (!base::FeatureList::IsEnabled(features::kPrecisionTouchpad)) if (!base::FeatureList::IsEnabled(features::kPrecisionTouchpad))
...@@ -50,8 +53,7 @@ DirectManipulationHelper::CreateInstance(HWND window, ...@@ -50,8 +53,7 @@ DirectManipulationHelper::CreateInstance(HWND window,
return nullptr; return nullptr;
std::unique_ptr<DirectManipulationHelper> instance = std::unique_ptr<DirectManipulationHelper> instance =
base::WrapUnique(new DirectManipulationHelper()); base::WrapUnique(new DirectManipulationHelper(window, compositor));
instance->window_ = window;
if (instance->Initialize(event_target)) if (instance->Initialize(event_target))
return instance; return instance;
...@@ -72,7 +74,7 @@ DirectManipulationHelper::CreateInstanceForTesting( ...@@ -72,7 +74,7 @@ DirectManipulationHelper::CreateInstanceForTesting(
return nullptr; return nullptr;
std::unique_ptr<DirectManipulationHelper> instance = std::unique_ptr<DirectManipulationHelper> instance =
base::WrapUnique(new DirectManipulationHelper()); base::WrapUnique(new DirectManipulationHelper(0, nullptr));
instance->event_handler_ = instance->event_handler_ =
Microsoft::WRL::Make<DirectManipulationEventHandler>(instance.get()); Microsoft::WRL::Make<DirectManipulationEventHandler>(instance.get());
...@@ -84,11 +86,25 @@ DirectManipulationHelper::CreateInstanceForTesting( ...@@ -84,11 +86,25 @@ DirectManipulationHelper::CreateInstanceForTesting(
} }
DirectManipulationHelper::~DirectManipulationHelper() { DirectManipulationHelper::~DirectManipulationHelper() {
if (viewport_) Destroy();
viewport_->Abandon();
} }
DirectManipulationHelper::DirectManipulationHelper() {} DirectManipulationHelper::DirectManipulationHelper(HWND window,
ui::Compositor* compositor)
: window_(window), compositor_(compositor) {}
void DirectManipulationHelper::OnAnimationStep(base::TimeTicks timestamp) {
// Simulate 1 frame in update_manager_.
HRESULT hr = update_manager_->Update(nullptr);
if (!SUCCEEDED(hr))
DebugLogging("UpdateManager update failed.", hr);
}
void DirectManipulationHelper::OnCompositingShuttingDown(
ui::Compositor* compositor) {
DCHECK_EQ(compositor, compositor_);
Destroy();
}
bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) { bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) {
// IDirectManipulationUpdateManager is the first COM object created by the // IDirectManipulationUpdateManager is the first COM object created by the
...@@ -180,34 +196,13 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) { ...@@ -180,34 +196,13 @@ bool DirectManipulationHelper::Initialize(ui::WindowEventTarget* event_target) {
return false; return false;
} }
DCHECK(compositor_);
compositor_->AddAnimationObserver(this);
DebugLogging("DirectManipulation initialization complete", S_OK); DebugLogging("DirectManipulation initialization complete", S_OK);
return true; return true;
} }
void DirectManipulationHelper::Activate() {
HRESULT hr = viewport_->Stop();
if (!SUCCEEDED(hr)) {
DebugLogging("Viewport stop failed.", hr);
return;
}
hr = manager_->Activate(window_);
if (!SUCCEEDED(hr))
DebugLogging("DirectManipulationManager activate failed.", hr);
}
void DirectManipulationHelper::Deactivate() {
HRESULT hr = viewport_->Stop();
if (!SUCCEEDED(hr)) {
DebugLogging("Viewport stop failed.", hr);
return;
}
hr = manager_->Deactivate(window_);
if (!SUCCEEDED(hr))
DebugLogging("DirectManipulationManager deactivate failed.", hr);
}
void DirectManipulationHelper::SetSizeInPixels( void DirectManipulationHelper::SetSizeInPixels(
const gfx::Size& size_in_pixels) { const gfx::Size& size_in_pixels) {
if (viewport_size_in_pixels_ == size_in_pixels) if (viewport_size_in_pixels_ == size_in_pixels)
...@@ -226,9 +221,7 @@ void DirectManipulationHelper::SetSizeInPixels( ...@@ -226,9 +221,7 @@ void DirectManipulationHelper::SetSizeInPixels(
DebugLogging("Viewport set rect failed.", hr); DebugLogging("Viewport set rect failed.", hr);
} }
bool DirectManipulationHelper::OnPointerHitTest( void DirectManipulationHelper::OnPointerHitTest(WPARAM w_param) {
WPARAM w_param,
ui::WindowEventTarget* event_target) {
// Update the device scale factor. // Update the device scale factor.
event_handler_->SetDeviceScaleFactor( event_handler_->SetDeviceScaleFactor(
display::win::ScreenWin::GetScaleFactorForHWND(window_)); display::win::ScreenWin::GetScaleFactorForHWND(window_));
...@@ -239,28 +232,20 @@ bool DirectManipulationHelper::OnPointerHitTest( ...@@ -239,28 +232,20 @@ bool DirectManipulationHelper::OnPointerHitTest(
// For WM_POINTER, the pointer type will show the event from mouse. // For WM_POINTER, the pointer type will show the event from mouse.
// For WM_POINTERACTIVATE, the pointer id will be different with the following // For WM_POINTERACTIVATE, the pointer id will be different with the following
// message. // message.
event_handler_->SetWindowEventTarget(event_target);
using GetPointerTypeFn = BOOL(WINAPI*)(UINT32, POINTER_INPUT_TYPE*); using GetPointerTypeFn = BOOL(WINAPI*)(UINT32, POINTER_INPUT_TYPE*);
UINT32 pointer_id = GET_POINTERID_WPARAM(w_param); UINT32 pointer_id = GET_POINTERID_WPARAM(w_param);
POINTER_INPUT_TYPE pointer_type; POINTER_INPUT_TYPE pointer_type;
static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>( static GetPointerTypeFn get_pointer_type = reinterpret_cast<GetPointerTypeFn>(
GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType")); GetProcAddress(GetModuleHandleA("user32.dll"), "GetPointerType"));
if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) && if (get_pointer_type && get_pointer_type(pointer_id, &pointer_type) &&
pointer_type == PT_TOUCHPAD && event_target) { pointer_type == PT_TOUCHPAD) {
HRESULT hr = viewport_->SetContact(pointer_id); HRESULT hr = viewport_->SetContact(pointer_id);
if (!SUCCEEDED(hr)) { if (!SUCCEEDED(hr))
DebugLogging("Viewport set contact failed.", hr); DebugLogging("Viewport set contact failed.", hr);
return false;
}
// Request begin frame for fake viewport.
need_poll_events_ = true;
} }
return need_poll_events_;
} }
HRESULT DirectManipulationHelper::Reset(bool need_poll_events) { HRESULT DirectManipulationHelper::Reset() {
// By zooming the primary content to a rect that match the viewport rect, we // By zooming the primary content to a rect that match the viewport rect, we
// reset the content's transform to identity. // reset the content's transform to identity.
HRESULT hr = viewport_->ZoomToRect( HRESULT hr = viewport_->ZoomToRect(
...@@ -272,20 +257,40 @@ HRESULT DirectManipulationHelper::Reset(bool need_poll_events) { ...@@ -272,20 +257,40 @@ HRESULT DirectManipulationHelper::Reset(bool need_poll_events) {
return hr; return hr;
} }
need_poll_events_ = need_poll_events;
return S_OK; return S_OK;
} }
bool DirectManipulationHelper::PollForNextEvent() {
// Simulate 1 frame in update_manager_.
HRESULT hr = update_manager_->Update(nullptr);
if (!SUCCEEDED(hr))
DebugLogging("UpdateManager update failed.", hr);
return need_poll_events_;
}
void DirectManipulationHelper::SetDeviceScaleFactorForTesting(float factor) { void DirectManipulationHelper::SetDeviceScaleFactorForTesting(float factor) {
event_handler_->SetDeviceScaleFactor(factor); event_handler_->SetDeviceScaleFactor(factor);
} }
void DirectManipulationHelper::Destroy() {
if (!compositor_)
return;
compositor_->RemoveAnimationObserver(this);
compositor_ = nullptr;
HRESULT hr;
if (viewport_) {
hr = viewport_->Stop();
if (!SUCCEEDED(hr))
DebugLogging("Viewport stop failed.", hr);
hr = viewport_->RemoveEventHandler(view_port_handler_cookie_);
if (!SUCCEEDED(hr))
DebugLogging("Viewport remove event handler failed.", hr);
hr = viewport_->Abandon();
if (!SUCCEEDED(hr))
DebugLogging("Viewport abandon failed.", hr);
}
if (manager_) {
hr = manager_->Deactivate(window_);
if (!SUCCEEDED(hr))
DebugLogging("DirectManipulationManager deactivate failed.", hr);
}
}
} // namespace content } // namespace content
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
#include "base/macros.h" #include "base/macros.h"
#include "content/browser/renderer_host/direct_manipulation_event_handler_win.h" #include "content/browser/renderer_host/direct_manipulation_event_handler_win.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "ui/compositor/compositor_animation_observer.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
namespace ui { namespace ui {
class Compositor;
class WindowEventTarget; class WindowEventTarget;
} // namespace ui } // namespace ui
...@@ -44,13 +46,15 @@ bool LoggingEnabled(); ...@@ -44,13 +46,15 @@ bool LoggingEnabled();
// when DM_POINTERHITTEST. // when DM_POINTERHITTEST.
// 3. OnViewportStatusChanged will be called when the gesture phase change. // 3. OnViewportStatusChanged will be called when the gesture phase change.
// OnContentUpdated will be called when the gesture update. // OnContentUpdated will be called when the gesture update.
class CONTENT_EXPORT DirectManipulationHelper { class CONTENT_EXPORT DirectManipulationHelper
: public ui::CompositorAnimationObserver {
public: public:
// Creates and initializes an instance of this class if Direct Manipulation is // Creates and initializes an instance of this class if Direct Manipulation is
// enabled on the platform. Returns nullptr if it disabled or failed on // enabled on the platform. Returns nullptr if it disabled or failed on
// initialization. // initialization.
static std::unique_ptr<DirectManipulationHelper> CreateInstance( static std::unique_ptr<DirectManipulationHelper> CreateInstance(
HWND window, HWND window,
ui::Compositor* compositor,
ui::WindowEventTarget* event_target); ui::WindowEventTarget* event_target);
// Creates and initializes an instance for testing. // Creates and initializes an instance for testing.
...@@ -58,48 +62,44 @@ class CONTENT_EXPORT DirectManipulationHelper { ...@@ -58,48 +62,44 @@ class CONTENT_EXPORT DirectManipulationHelper {
ui::WindowEventTarget* event_target, ui::WindowEventTarget* event_target,
Microsoft::WRL::ComPtr<IDirectManipulationViewport> viewport); Microsoft::WRL::ComPtr<IDirectManipulationViewport> viewport);
~DirectManipulationHelper(); ~DirectManipulationHelper() override;
// Actives Direct Manipulation, call when window show. // CompositorAnimationObserver implements.
void Activate(); // DirectManipulation needs to poll for new events every frame while finger
// gesturing on touchpad.
// Deactivates Direct Manipulation, call when window show. void OnAnimationStep(base::TimeTicks timestamp) override;
void Deactivate(); void OnCompositingShuttingDown(ui::Compositor* compositor) override;
// Updates viewport size. Call it when window bounds updated. // Updates viewport size. Call it when window bounds updated.
void SetSizeInPixels(const gfx::Size& size_in_pixels); void SetSizeInPixels(const gfx::Size& size_in_pixels);
// Reset for gesture end. // Reset for gesture end.
HRESULT Reset(bool need_animtation); HRESULT Reset();
// Pass the pointer hit test to Direct Manipulation. Return true indicated we
// need poll for new events every frame from here.
bool OnPointerHitTest(WPARAM w_param, ui::WindowEventTarget* event_target);
// On each frame poll new Direct Manipulation events. Return true if we still // Pass the pointer hit test to Direct Manipulation.
// need poll for new events on next frame, otherwise stop request need begin void OnPointerHitTest(WPARAM w_param);
// frame.
bool PollForNextEvent();
private: private:
friend class content::DirectManipulationBrowserTest; friend class content::DirectManipulationBrowserTest;
friend class DirectManipulationUnitTest; friend class DirectManipulationUnitTest;
DirectManipulationHelper(); DirectManipulationHelper(HWND window, ui::Compositor* compositor);
// This function instantiates Direct Manipulation and creates a viewport for // This function instantiates Direct Manipulation and creates a viewport for
// the passed in |window|. Return false if initialize failed. // |window_|. Return false if initialize failed.
bool Initialize(ui::WindowEventTarget* event_target); bool Initialize(ui::WindowEventTarget* event_target);
void SetDeviceScaleFactorForTesting(float factor); void SetDeviceScaleFactorForTesting(float factor);
void Destroy();
Microsoft::WRL::ComPtr<IDirectManipulationManager> manager_; Microsoft::WRL::ComPtr<IDirectManipulationManager> manager_;
Microsoft::WRL::ComPtr<IDirectManipulationUpdateManager> update_manager_; Microsoft::WRL::ComPtr<IDirectManipulationUpdateManager> update_manager_;
Microsoft::WRL::ComPtr<IDirectManipulationViewport> viewport_; Microsoft::WRL::ComPtr<IDirectManipulationViewport> viewport_;
Microsoft::WRL::ComPtr<DirectManipulationEventHandler> event_handler_; Microsoft::WRL::ComPtr<DirectManipulationEventHandler> event_handler_;
HWND window_; HWND window_;
ui::Compositor* compositor_ = nullptr;
DWORD view_port_handler_cookie_; DWORD view_port_handler_cookie_;
bool need_poll_events_ = false;
gfx::Size viewport_size_in_pixels_; gfx::Size viewport_size_in_pixels_;
DISALLOW_COPY_AND_ASSIGN(DirectManipulationHelper); DISALLOW_COPY_AND_ASSIGN(DirectManipulationHelper);
......
...@@ -49,35 +49,12 @@ class DirectManipulationBrowserTest : public ContentBrowserTest, ...@@ -49,35 +49,12 @@ class DirectManipulationBrowserTest : public ContentBrowserTest,
return rwhva->legacy_render_widget_host_HWND_; return rwhva->legacy_render_widget_host_HWND_;
} }
HWND GetSubWindowHWND() {
LegacyRenderWidgetHostHWND* lrwhh = GetLegacyRenderWidgetHostHWND();
return lrwhh->hwnd();
}
ui::WindowEventTarget* GetWindowEventTarget() { ui::WindowEventTarget* GetWindowEventTarget() {
LegacyRenderWidgetHostHWND* lrwhh = GetLegacyRenderWidgetHostHWND(); LegacyRenderWidgetHostHWND* lrwhh = GetLegacyRenderWidgetHostHWND();
return lrwhh->GetWindowEventTarget(lrwhh->GetParent()); return lrwhh->GetWindowEventTarget(lrwhh->GetParent());
} }
void SimulatePointerHitTest() {
LegacyRenderWidgetHostHWND* lrwhh = GetLegacyRenderWidgetHostHWND();
lrwhh->direct_manipulation_helper_->need_poll_events_ = true;
lrwhh->CreateAnimationObserver();
}
void UpdateParent(HWND hwnd) {
LegacyRenderWidgetHostHWND* lrwhh = GetLegacyRenderWidgetHostHWND();
lrwhh->UpdateParent(hwnd);
}
bool HasCompositorAnimationObserver(LegacyRenderWidgetHostHWND* lrwhh) {
return lrwhh->compositor_animation_observer_ != nullptr;
}
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
...@@ -88,37 +65,6 @@ INSTANTIATE_TEST_SUITE_P(WithScrollEventPhase, ...@@ -88,37 +65,6 @@ INSTANTIATE_TEST_SUITE_P(WithScrollEventPhase,
DirectManipulationBrowserTest, DirectManipulationBrowserTest,
testing::Bool()); testing::Bool());
// Ensure the AnimationObserver destroy when hwnd reparent to other hwnd.
IN_PROC_BROWSER_TEST_P(DirectManipulationBrowserTest, HWNDReparent) {
if (base::win::GetVersion() < base::win::VERSION_WIN10)
return;
NavigateToURL(shell(), GURL(url::kAboutBlankURL));
LegacyRenderWidgetHostHWND* lrwhh = GetLegacyRenderWidgetHostHWND();
ASSERT_TRUE(lrwhh);
// The observer should not create before it needed.
ASSERT_TRUE(!HasCompositorAnimationObserver(lrwhh));
// Add AnimationObserver to tab to simulate direct manipulation start.
SimulatePointerHitTest();
ASSERT_TRUE(HasCompositorAnimationObserver(lrwhh));
// Create another browser.
Shell* shell2 = CreateBrowser();
NavigateToURL(shell2, GURL(url::kAboutBlankURL));
// Move to the tab to browser2.
UpdateParent(
shell2->window()->GetRootWindow()->GetHost()->GetAcceleratedWidget());
// The animation observer should be removed.
EXPECT_FALSE(HasCompositorAnimationObserver(lrwhh));
shell2->Close();
}
// EventLogger is to observe the events sent from WindowEventTarget (the root // EventLogger is to observe the events sent from WindowEventTarget (the root
// window). // window).
class EventLogger : public ui::EventRewriter { class EventLogger : public ui::EventRewriter {
......
...@@ -31,6 +31,12 @@ class MockDirectManipulationViewport ...@@ -31,6 +31,12 @@ class MockDirectManipulationViewport
~MockDirectManipulationViewport() override {} ~MockDirectManipulationViewport() override {}
bool IsZoomToRectCalled() {
bool called = zoom_to_rect_called_;
zoom_to_rect_called_ = false;
return called;
}
HRESULT STDMETHODCALLTYPE Enable() override { return S_OK; } HRESULT STDMETHODCALLTYPE Enable() override { return S_OK; }
HRESULT STDMETHODCALLTYPE Disable() override { return S_OK; } HRESULT STDMETHODCALLTYPE Disable() override { return S_OK; }
...@@ -75,6 +81,7 @@ class MockDirectManipulationViewport ...@@ -75,6 +81,7 @@ class MockDirectManipulationViewport
_In_ const float right, _In_ const float right,
_In_ const float bottom, _In_ const float bottom,
_In_ BOOL animate) override { _In_ BOOL animate) override {
zoom_to_rect_called_ = true;
return S_OK; return S_OK;
} }
...@@ -161,6 +168,8 @@ class MockDirectManipulationViewport ...@@ -161,6 +168,8 @@ class MockDirectManipulationViewport
HRESULT STDMETHODCALLTYPE Abandon() override { return S_OK; } HRESULT STDMETHODCALLTYPE Abandon() override { return S_OK; }
private: private:
bool zoom_to_rect_called_ = false;
DISALLOW_COPY_AND_ASSIGN(MockDirectManipulationViewport); DISALLOW_COPY_AND_ASSIGN(MockDirectManipulationViewport);
}; };
...@@ -397,13 +406,7 @@ class DirectManipulationUnitTest : public testing::Test { ...@@ -397,13 +406,7 @@ class DirectManipulationUnitTest : public testing::Test {
viewport_.Get(), content_.Get()); viewport_.Get(), content_.Get());
} }
void SetNeedAnimation(bool need_poll_events) { bool IsZoomToRectCalled() { return viewport_->IsZoomToRectCalled(); }
direct_manipulation_helper_->need_poll_events_ = need_poll_events;
}
bool NeedAnimation() {
return direct_manipulation_helper_->need_poll_events_;
}
void SetDeviceScaleFactor(float factor) { void SetDeviceScaleFactor(float factor) {
direct_manipulation_helper_->SetDeviceScaleFactorForTesting(factor); direct_manipulation_helper_->SetDeviceScaleFactorForTesting(factor);
...@@ -721,21 +724,19 @@ TEST_F(DirectManipulationUnitTest, ...@@ -721,21 +724,19 @@ TEST_F(DirectManipulationUnitTest,
} }
TEST_F(DirectManipulationUnitTest, TEST_F(DirectManipulationUnitTest,
NeedAnimtationShouldBeFalseAfterSecondReset) { ZoomToRectShouldNotBeCalledInEmptyRunningReadySequence) {
if (!GetDirectManipulationHelper()) if (!GetDirectManipulationHelper())
return; return;
// Direct Manipulation will set need_poll_events_ true when DM_POINTERTEST ContentUpdated(1.0f, 5, 0);
// from touchpad.
SetNeedAnimation(true);
// Receive first ready when gesture end. // Receive first ready when gesture end.
ViewportStatusChanged(DIRECTMANIPULATION_READY, DIRECTMANIPULATION_RUNNING); ViewportStatusChanged(DIRECTMANIPULATION_READY, DIRECTMANIPULATION_RUNNING);
EXPECT_TRUE(NeedAnimation()); EXPECT_TRUE(IsZoomToRectCalled());
// Receive second ready from ZoomToRect. // Receive second ready from ZoomToRect.
ViewportStatusChanged(DIRECTMANIPULATION_READY, DIRECTMANIPULATION_RUNNING); ViewportStatusChanged(DIRECTMANIPULATION_READY, DIRECTMANIPULATION_RUNNING);
EXPECT_FALSE(NeedAnimation()); EXPECT_FALSE(IsZoomToRectCalled());
} }
TEST_F(DirectManipulationUnitTest, HiDPIScroll) { TEST_F(DirectManipulationUnitTest, HiDPIScroll) {
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "ui/base/view_prop.h" #include "ui/base/view_prop.h"
#include "ui/base/win/internal_constants.h" #include "ui/base/win/internal_constants.h"
#include "ui/base/win/window_event_target.h" #include "ui/base/win/window_event_target.h"
#include "ui/compositor/compositor.h"
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -38,47 +37,6 @@ namespace content { ...@@ -38,47 +37,6 @@ namespace content {
// accessibility support. // accessibility support.
const int kIdScreenReaderHoneyPot = 1; 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);
DebugLogging("Add AnimationObserverForDirectManipulation.");
}
~CompositorAnimationObserverForDirectManipulation() override {
if (compositor_) {
compositor_->RemoveAnimationObserver(this);
DebugLogging("Remove AnimationObserverForDirectManipulation.");
}
}
// ui::CompositorAnimationObserver
void OnAnimationStep(base::TimeTicks timestamp) override {
render_widget_host_hwnd_->PollForNextEvent();
}
// ui::CompositorAnimationObserver
void OnCompositingShuttingDown(ui::Compositor* compositor) override {
DebugLogging("OnCompositingShuttingDown.");
compositor->RemoveAnimationObserver(this);
compositor_ = nullptr;
}
private:
LegacyRenderWidgetHostHWND* render_widget_host_hwnd_;
ui::Compositor* compositor_;
DISALLOW_COPY_AND_ASSIGN(CompositorAnimationObserverForDirectManipulation);
};
// static // static
LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create( LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create(
HWND parent) { HWND parent) {
...@@ -103,8 +61,6 @@ LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create( ...@@ -103,8 +61,6 @@ LegacyRenderWidgetHostHWND* LegacyRenderWidgetHostHWND::Create(
} }
void LegacyRenderWidgetHostHWND::Destroy() { void LegacyRenderWidgetHostHWND::Destroy() {
// Stop the AnimationObserver when window close.
DestroyAnimationObserver();
host_ = nullptr; host_ = nullptr;
if (::IsWindow(hwnd())) if (::IsWindow(hwnd()))
::DestroyWindow(hwnd()); ::DestroyWindow(hwnd());
...@@ -113,10 +69,16 @@ void LegacyRenderWidgetHostHWND::Destroy() { ...@@ -113,10 +69,16 @@ void LegacyRenderWidgetHostHWND::Destroy() {
void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) { void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) {
if (GetWindowEventTarget(GetParent())) if (GetWindowEventTarget(GetParent()))
GetWindowEventTarget(GetParent())->HandleParentChanged(); GetWindowEventTarget(GetParent())->HandleParentChanged();
// Stop the AnimationObserver when window hide. eg. tab switch, move tab to
// another window.
DestroyAnimationObserver();
::SetParent(hwnd(), parent); ::SetParent(hwnd(), parent);
// Direct Manipulation is enabled on Windows 10+. The CreateInstance function
// returns NULL if Direct Manipulation is not available. Recreate
// |direct_manipulation_helper_| when parent changed (compositor and window
// event target updated).
direct_manipulation_helper_ = DirectManipulationHelper::CreateInstance(
hwnd(), host_->GetNativeView()->GetHost()->compositor(),
GetWindowEventTarget(GetParent()));
} }
HWND LegacyRenderWidgetHostHWND::GetParent() { HWND LegacyRenderWidgetHostHWND::GetParent() {
...@@ -125,14 +87,10 @@ HWND LegacyRenderWidgetHostHWND::GetParent() { ...@@ -125,14 +87,10 @@ HWND LegacyRenderWidgetHostHWND::GetParent() {
void LegacyRenderWidgetHostHWND::Show() { void LegacyRenderWidgetHostHWND::Show() {
::ShowWindow(hwnd(), SW_SHOW); ::ShowWindow(hwnd(), SW_SHOW);
if (direct_manipulation_helper_)
direct_manipulation_helper_->Activate();
} }
void LegacyRenderWidgetHostHWND::Hide() { void LegacyRenderWidgetHostHWND::Hide() {
::ShowWindow(hwnd(), SW_HIDE); ::ShowWindow(hwnd(), SW_HIDE);
if (direct_manipulation_helper_)
direct_manipulation_helper_->Deactivate();
} }
void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) { void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) {
...@@ -191,11 +149,6 @@ bool LegacyRenderWidgetHostHWND::Init() { ...@@ -191,11 +149,6 @@ bool LegacyRenderWidgetHostHWND::Init() {
CHILDID_SELF); CHILDID_SELF);
} }
// Direct Manipulation is enabled on Windows 10+. The CreateInstance function
// returns NULL if Direct Manipulation is not available.
direct_manipulation_helper_ = DirectManipulationHelper::CreateInstance(
hwnd(), GetWindowEventTarget(GetParent()));
// Disable pen flicks (http://crbug.com/506977) // Disable pen flicks (http://crbug.com/506977)
base::win::DisableFlicks(hwnd()); base::win::DisableFlicks(hwnd());
...@@ -501,21 +454,6 @@ LRESULT LegacyRenderWidgetHostHWND::OnSize(UINT message, ...@@ -501,21 +454,6 @@ LRESULT LegacyRenderWidgetHostHWND::OnSize(UINT message,
return 0; return 0;
} }
LRESULT LegacyRenderWidgetHostHWND::OnWindowPosChanged(UINT message,
WPARAM w_param,
LPARAM l_param) {
WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(l_param);
if (direct_manipulation_helper_) {
if (window_pos->flags & SWP_SHOWWINDOW) {
direct_manipulation_helper_->Activate();
} else if (window_pos->flags & SWP_HIDEWINDOW) {
direct_manipulation_helper_->Deactivate();
}
}
SetMsgHandled(FALSE);
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnDestroy(UINT message, LRESULT LegacyRenderWidgetHostHWND::OnDestroy(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
...@@ -534,30 +472,12 @@ LRESULT LegacyRenderWidgetHostHWND::OnPointerHitTest(UINT message, ...@@ -534,30 +472,12 @@ LRESULT LegacyRenderWidgetHostHWND::OnPointerHitTest(UINT message,
return 0; return 0;
DebugLogging("Receive DM_POINTERHITTEST."); DebugLogging("Receive DM_POINTERHITTEST.");
// 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.
DebugLogging("AnimationObserverForDirectManipulation exists.");
return 0;
}
CreateAnimationObserver(); direct_manipulation_helper_->OnPointerHitTest(w_param);
}
return 0; return 0;
} }
void LegacyRenderWidgetHostHWND::PollForNextEvent() {
DCHECK(direct_manipulation_helper_);
if (!direct_manipulation_helper_->PollForNextEvent())
DestroyAnimationObserver();
}
gfx::NativeViewAccessible gfx::NativeViewAccessible
LegacyRenderWidgetHostHWND::GetOrCreateWindowRootAccessible() { LegacyRenderWidgetHostHWND::GetOrCreateWindowRootAccessible() {
if (!host_) if (!host_)
...@@ -589,20 +509,4 @@ LegacyRenderWidgetHostHWND::GetOrCreateWindowRootAccessible() { ...@@ -589,20 +509,4 @@ LegacyRenderWidgetHostHWND::GetOrCreateWindowRootAccessible() {
return root->GetNativeViewAccessible(); return root->GetNativeViewAccessible();
} }
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() {
DebugLogging("DestroyAnimationObserver.");
compositor_animation_observer_.reset();
}
} // namespace content } // namespace content
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/win/atl.h" #include "base/win/atl.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "ui/compositor/compositor_animation_observer.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
...@@ -96,7 +95,6 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND ...@@ -96,7 +95,6 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND
OnMouseRange) OnMouseRange)
MESSAGE_HANDLER_EX(WM_NCCALCSIZE, OnNCCalcSize) MESSAGE_HANDLER_EX(WM_NCCALCSIZE, OnNCCalcSize)
MESSAGE_HANDLER_EX(WM_SIZE, OnSize) MESSAGE_HANDLER_EX(WM_SIZE, OnSize)
MESSAGE_HANDLER_EX(WM_WINDOWPOSCHANGED, OnWindowPosChanged)
MESSAGE_HANDLER_EX(WM_DESTROY, OnDestroy) MESSAGE_HANDLER_EX(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER_EX(DM_POINTERHITTEST, OnPointerHitTest) MESSAGE_HANDLER_EX(DM_POINTERHITTEST, OnPointerHitTest)
END_MSG_MAP() END_MSG_MAP()
...@@ -123,10 +121,6 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND ...@@ -123,10 +121,6 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND
host_ = host; host_ = host;
} }
// DirectManipulation needs to poll for new events every frame while finger
// gesturing on touchpad.
void PollForNextEvent();
// Return the root accessible object for either MSAA or UI Automation. // Return the root accessible object for either MSAA or UI Automation.
gfx::NativeViewAccessible GetOrCreateWindowRootAccessible(); gfx::NativeViewAccessible GetOrCreateWindowRootAccessible();
...@@ -163,15 +157,10 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND ...@@ -163,15 +157,10 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND
LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnNCCalcSize(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnNCCalcSize(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnSize(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnSize(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnWindowPosChanged(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnDestroy(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnDestroy(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnPointerHitTest(UINT message, WPARAM w_param, LPARAM l_param); LRESULT OnPointerHitTest(UINT message, WPARAM w_param, LPARAM l_param);
void CreateAnimationObserver();
void DestroyAnimationObserver();
Microsoft::WRL::ComPtr<IAccessible> window_accessible_; Microsoft::WRL::ComPtr<IAccessible> window_accessible_;
// Set to true if we turned on mouse tracking. // Set to true if we turned on mouse tracking.
...@@ -190,9 +179,6 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND ...@@ -190,9 +179,6 @@ class CONTENT_EXPORT LegacyRenderWidgetHostHWND
// in Chrome on Windows 10. // in Chrome on Windows 10.
std::unique_ptr<DirectManipulationHelper> direct_manipulation_helper_; std::unique_ptr<DirectManipulationHelper> direct_manipulation_helper_;
std::unique_ptr<ui::CompositorAnimationObserver>
compositor_animation_observer_;
DISALLOW_COPY_AND_ASSIGN(LegacyRenderWidgetHostHWND); DISALLOW_COPY_AND_ASSIGN(LegacyRenderWidgetHostHWND);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment