OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef UI_GFX_WIN_DIRECT_MANIPULATION_H_ |
| 6 #define UI_GFX_WIN_DIRECT_MANIPULATION_H_ |
| 7 |
| 8 #include <directmanipulation.h> |
| 9 |
| 10 #include "base/win/scoped_comptr.h" |
| 11 #include "ui/gfx/geometry/rect.h" |
| 12 #include "ui/gfx/gfx_export.h" |
| 13 |
| 14 namespace gfx { |
| 15 namespace win { |
| 16 |
| 17 // Windows 10 provides a new API called Direct Manipulation which generates |
| 18 // smooth scroll events via WM_MOUSEWHEEL messages with predictable deltas |
| 19 // on high precision touch pads. This basically requires the application window |
| 20 // to register as a Direct Manipulation consumer. The way mouse wheel messages |
| 21 // are dispatched is |
| 22 // 1. The foreground window is checked to see if it is a Direct Manipulation |
| 23 // consumer. |
| 24 // 2. If it is then Direct Manipulation takes over and sends the following |
| 25 // messages. WM_POINTERACTIVATE, WM_POINTERDOWN and DM_POINTERHITTEST. |
| 26 // 3. It then posts WM_MOUSEWHEEL messages with precision deltas which vary |
| 27 // based on the amount of the scroll. |
| 28 // 4. If the foreground window is not a Direct Manipulation consumer, it |
| 29 // then takes a fallback route where it posts WM_MOUSEWHEEL messages |
| 30 // with precision but varying deltas to the window. There is a also |
| 31 // a slight delay in receiving the first set of mouse wheel messages. |
| 32 // This causes scrolling to appear janky and jumpy. |
| 33 // Our approach for addressing this is to do the absolute minimum to |
| 34 // register our window as a Direct Manipulation consumer. This class |
| 35 // provides the necessary functionality to register the passed in HWND as a |
| 36 // Direct Manipulation consumer. We don't rely on Direct manipulation |
| 37 // to do the smooth scrolling in the background thread as documented on |
| 38 // msdn. |
| 39 class GFX_EXPORT DirectManipulationHelper { |
| 40 public: |
| 41 // Creates an instance of this class if Direct Manipulation is enabled on |
| 42 // the platform. If not returns NULL. |
| 43 static DirectManipulationHelper* CreateInstance(); |
| 44 |
| 45 // This function instantiates Direct Manipulation and creates a viewport for |
| 46 // the passed in |window|. |
| 47 // consumer. Most of the code is boiler plate and is based on the sample. |
| 48 void Initialize(HWND window); |
| 49 |
| 50 // Sets the bounds of the fake Direct manipulation viewport to match those |
| 51 // of the legacy window. |
| 52 void SetBounds(const gfx::Rect& bounds); |
| 53 |
| 54 // Registers the passed in |window| as a Direct Manipulation consumer. |
| 55 void Activate(HWND window); |
| 56 |
| 57 // Passes the WM_MOUSEWHEEL messages to Direct Manipulation. This is for |
| 58 // logistics purposes. |
| 59 void HandleMouseWheel(HWND window, UINT message, WPARAM w_param, |
| 60 LPARAM l_param); |
| 61 |
| 62 private: |
| 63 DirectManipulationHelper() {} |
| 64 |
| 65 base::win::ScopedComPtr<IDirectManipulationManager2> manager_; |
| 66 base::win::ScopedComPtr<IDirectManipulationCompositor> compositor_; |
| 67 base::win::ScopedComPtr<IDirectManipulationUpdateManager> update_manager_; |
| 68 base::win::ScopedComPtr<IDirectManipulationFrameInfoProvider> frame_info_; |
| 69 base::win::ScopedComPtr<IDirectManipulationViewport2> view_port_outer_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(DirectManipulationHelper); |
| 72 }; |
| 73 |
| 74 } // namespace win |
| 75 } // namespace gfx |
| 76 |
| 77 #endif // UI_GFX_WIN_DIRECT_WRITE_H_ |
OLD | NEW |