Commit 6016f8b0 authored by chaopeng's avatar chaopeng Committed by Commit Bot

Set WindowEventTarget when DirectManipulationHelper create

Currently, we only set WindowEventTarget to DirectManipulationHelper
when receive DM_POINTERHITTEST. But the crash shows OnContentUpdate
may come before DM_POINTERHITTEST. To prevent the crash we set the
WindowEventTarget when DirectManipulationHelper create.

Bug: 839338
Change-Id: I2921277178771f9124a37325a8dff47196500322
Reviewed-on: https://chromium-review.googlesource.com/1042381Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Jianpeng Chao <chaopeng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555904}
parent 215258fb
......@@ -191,7 +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(hwnd());
ui::win::DirectManipulationHelper::CreateInstance(
hwnd(), GetWindowEventTarget(GetParent()));
// Disable pen flicks (http://crbug.com/506977)
base::win::DisableFlicks(hwnd());
......
......@@ -18,7 +18,8 @@ namespace win {
// static
std::unique_ptr<DirectManipulationHelper>
DirectManipulationHelper::CreateInstance(HWND window) {
DirectManipulationHelper::CreateInstance(HWND window,
WindowEventTarget* event_target) {
if (!::IsWindow(window))
return nullptr;
......@@ -33,7 +34,7 @@ DirectManipulationHelper::CreateInstance(HWND window) {
base::WrapUnique(new DirectManipulationHelper());
instance->window_ = window;
if (instance->Initialize())
if (instance->Initialize(event_target))
return instance;
return nullptr;
......@@ -54,9 +55,8 @@ DirectManipulationHelper::CreateInstanceForTesting(
std::unique_ptr<DirectManipulationHelper> instance =
base::WrapUnique(new DirectManipulationHelper());
instance->event_handler_ =
Microsoft::WRL::Make<DirectManipulationHandler>(instance.get());
instance->event_handler_->SetWindowEventTarget(event_target);
instance->event_handler_ = Microsoft::WRL::Make<DirectManipulationHandler>(
instance.get(), event_target);
instance->viewport_ = viewport;
......@@ -74,7 +74,7 @@ DirectManipulationHelper::DirectManipulationHelper() {}
// the fake viewport.
const RECT VIEWPORT_DEFAULT_RECT = {0, 0, 1000, 1000};
bool DirectManipulationHelper::Initialize() {
bool DirectManipulationHelper::Initialize(WindowEventTarget* event_target) {
// IDirectManipulationUpdateManager is the first COM object created by the
// application to retrieve other objects in the Direct Manipulation API.
// It also serves to activate and deactivate Direct Manipulation functionality
......@@ -115,7 +115,8 @@ bool DirectManipulationHelper::Initialize() {
if (!SUCCEEDED(hr))
return false;
event_handler_ = Microsoft::WRL::Make<DirectManipulationHandler>(this);
event_handler_ =
Microsoft::WRL::Make<DirectManipulationHandler>(this, event_target);
if (!SUCCEEDED(hr))
return false;
......@@ -208,8 +209,9 @@ DirectManipulationHandler::DirectManipulationHandler() {
}
DirectManipulationHandler::DirectManipulationHandler(
DirectManipulationHelper* helper)
: helper_(helper) {}
DirectManipulationHelper* helper,
WindowEventTarget* event_target)
: helper_(helper), event_target_(event_target) {}
DirectManipulationHandler::~DirectManipulationHandler() {}
......
......@@ -40,7 +40,8 @@ class DirectManipulationHandler
Microsoft::WRL::FtmBase,
IDirectManipulationViewportEventHandler>> {
public:
explicit DirectManipulationHandler(DirectManipulationHelper* helper);
explicit DirectManipulationHandler(DirectManipulationHelper* helper,
WindowEventTarget* event_target);
// WindowEventTarget updates for every DM_POINTERHITTEST in case window
// hierarchy changed.
......@@ -99,7 +100,9 @@ class UI_BASE_EXPORT DirectManipulationHelper {
// Creates and initializes an instance of this class if Direct Manipulation is
// enabled on the platform. Returns nullptr if it disabled or failed on
// initialization.
static std::unique_ptr<DirectManipulationHelper> CreateInstance(HWND window);
static std::unique_ptr<DirectManipulationHelper> CreateInstance(
HWND window,
WindowEventTarget* event_target);
// Creates and initializes an instance for testing.
static std::unique_ptr<DirectManipulationHelper> CreateInstanceForTesting(
......@@ -135,7 +138,7 @@ class UI_BASE_EXPORT DirectManipulationHelper {
// This function instantiates Direct Manipulation and creates a viewport for
// the passed in |window|. Return false if initialize failed.
bool Initialize();
bool Initialize(WindowEventTarget* event_target);
void SetDeviceScaleFactorForTesting(float factor);
......
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