1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GFX_WIN_DIRECT_MANIPULATION_H_
6 #define UI_GFX_WIN_DIRECT_MANIPULATION_H_
8 #include <directmanipulation.h>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/win/scoped_comptr.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/gfx_export.h"
18 // Windows 10 provides a new API called Direct Manipulation which generates
19 // smooth scroll events via WM_MOUSEWHEEL messages with predictable deltas
20 // on high precision touch pads. This basically requires the application window
21 // to register as a Direct Manipulation consumer. The way mouse wheel messages
23 // 1. The foreground window is checked to see if it is a Direct Manipulation
25 // 2. If it is then Direct Manipulation takes over and sends the following
26 // messages. WM_POINTERACTIVATE, WM_POINTERDOWN and DM_POINTERHITTEST.
27 // 3. It then posts WM_MOUSEWHEEL messages with precision deltas which vary
28 // based on the amount of the scroll.
29 // 4. If the foreground window is not a Direct Manipulation consumer, it
30 // then takes a fallback route where it posts WM_MOUSEWHEEL messages
31 // with precision but varying deltas to the window. There is a also
32 // a slight delay in receiving the first set of mouse wheel messages.
33 // This causes scrolling to appear janky and jumpy.
34 // Our approach for addressing this is to do the absolute minimum to
35 // register our window as a Direct Manipulation consumer. This class
36 // provides the necessary functionality to register the passed in HWND as a
37 // Direct Manipulation consumer. We don't rely on Direct manipulation
38 // to do the smooth scrolling in the background thread as documented on
40 class GFX_EXPORT DirectManipulationHelper
{
42 // Creates an instance of this class if Direct Manipulation is enabled on
43 // the platform. If not returns NULL.
44 static scoped_ptr
<DirectManipulationHelper
> CreateInstance();
46 // This function instantiates Direct Manipulation and creates a viewport for
47 // the passed in |window|.
48 // consumer. Most of the code is boiler plate and is based on the sample.
49 void Initialize(HWND window
);
51 // Sets the bounds of the fake Direct manipulation viewport to match those
52 // of the legacy window.
53 void SetBounds(const gfx::Rect
& bounds
);
55 // Registers and activates the passed in |window| as a Direct Manipulation
57 void Activate(HWND window
);
59 // Deactivates Direct Manipulation processing on the passed in |window|.
60 void Deactivate(HWND window
);
62 // Passes the WM_MOUSEWHEEL messages to Direct Manipulation. This is for
63 // logistics purposes.
64 void HandleMouseWheel(HWND window
, UINT message
, WPARAM w_param
,
67 ~DirectManipulationHelper();
70 DirectManipulationHelper();
72 base::win::ScopedComPtr
<IDirectManipulationManager2
> manager_
;
73 base::win::ScopedComPtr
<IDirectManipulationCompositor
> compositor_
;
74 base::win::ScopedComPtr
<IDirectManipulationUpdateManager
> update_manager_
;
75 base::win::ScopedComPtr
<IDirectManipulationFrameInfoProvider
> frame_info_
;
76 base::win::ScopedComPtr
<IDirectManipulationViewport2
> view_port_outer_
;
78 DISALLOW_COPY_AND_ASSIGN(DirectManipulationHelper
);
84 #endif // UI_GFX_WIN_DIRECT_MANIPULATION_H_