Flutter Windows Embedder
direct_manipulation.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_WINDOWS_DIRECT_MANIPULATION_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_DIRECT_MANIPULATION_H_
7 
8 #include "flutter/fml/memory/ref_counted.h"
9 
10 #include <wrl/client.h>
11 #include "directmanipulation.h"
12 
13 namespace flutter {
14 
15 class FlutterWindow;
16 class WindowBindingHandlerDelegate;
17 
18 class DirectManipulationEventHandler;
19 
20 // Owner for a DirectManipulation event handler, contains the link between
21 // DirectManipulation and WindowBindingHandlerDelegate.
23  public:
24  explicit DirectManipulationOwner(FlutterWindow* window);
25  virtual ~DirectManipulationOwner() = default;
26  // Initialize a DirectManipulation viewport with specified width and height.
27  // These should match the width and height of the application window.
28  int Init(unsigned int width, unsigned int height);
29  // Resize the DirectManipulation viewport. Should be called when the
30  // application window is resized.
31  void ResizeViewport(unsigned int width, unsigned int height);
32  // Set the WindowBindingHandlerDelegate which will receive callbacks based on
33  // DirectManipulation updates.
36  // Called when DM_POINTERHITTEST occurs with an acceptable pointer type. Will
37  // start DirectManipulation for that interaction.
38  virtual void SetContact(UINT contactId);
39  // Called to get updates from DirectManipulation. Should be called frequently
40  // to provide smooth updates.
41  void Update();
42  // Release child event handler and OS resources.
43  void Destroy();
44  // The target that should be updated when DirectManipulation provides a new
45  // pan/zoom transformation.
47 
48  private:
49  // The window gesture input is occuring on.
50  FlutterWindow* window_;
51  // Cookie needed to register child event handler with viewport.
52  DWORD viewportHandlerCookie_;
53  // Object needed for operation of the DirectManipulation API.
54  Microsoft::WRL::ComPtr<IDirectManipulationManager> manager_;
55  // Object needed for operation of the DirectManipulation API.
56  Microsoft::WRL::ComPtr<IDirectManipulationUpdateManager> updateManager_;
57  // Object needed for operation of the DirectManipulation API.
58  Microsoft::WRL::ComPtr<IDirectManipulationViewport> viewport_;
59  // Child needed for operation of the DirectManipulation API.
60  fml::RefPtr<DirectManipulationEventHandler> handler_;
61 
62  FML_DISALLOW_COPY_AND_ASSIGN(DirectManipulationOwner);
63 };
64 
65 // Implements DirectManipulation event handling interfaces, receives calls from
66 // system when gesture events occur.
68  : public fml::RefCountedThreadSafe<DirectManipulationEventHandler>,
69  public IDirectManipulationViewportEventHandler,
70  public IDirectManipulationInteractionEventHandler {
72  FML_FRIEND_REF_COUNTED_THREAD_SAFE(DirectManipulationEventHandler);
73  FML_FRIEND_MAKE_REF_COUNTED(DirectManipulationEventHandler);
74 
75  public:
77  : owner_(owner) {}
78 
79  // |IUnknown|
80  STDMETHODIMP QueryInterface(REFIID iid, void** ppv) override;
81 
82  // |IUnknown|
83  ULONG STDMETHODCALLTYPE AddRef() override;
84 
85  // |IUnknown|
86  ULONG STDMETHODCALLTYPE Release() override;
87 
88  // |IDirectManipulationViewportEventHandler|
89  HRESULT STDMETHODCALLTYPE OnViewportStatusChanged(
90  IDirectManipulationViewport* viewport,
91  DIRECTMANIPULATION_STATUS current,
92  DIRECTMANIPULATION_STATUS previous) override;
93 
94  // |IDirectManipulationViewportEventHandler|
95  HRESULT STDMETHODCALLTYPE OnViewportUpdated(
96  IDirectManipulationViewport* viewport) override;
97 
98  // |IDirectManipulationViewportEventHandler|
99  HRESULT STDMETHODCALLTYPE OnContentUpdated(
100  IDirectManipulationViewport* viewport,
101  IDirectManipulationContent* content) override;
102 
103  // |IDirectManipulationInteractionEventHandler|
104  HRESULT STDMETHODCALLTYPE OnInteraction(
105  IDirectManipulationViewport2* viewport,
106  DIRECTMANIPULATION_INTERACTION_TYPE interaction) override;
107 
108  private:
109  struct GestureData {
110  float scale;
111  float pan_x;
112  float pan_y;
113  };
114  // Convert transform array to Flutter-usable values.
115  GestureData ConvertToGestureData(float transform[6]);
116  // Unique identifier to associate with all gesture event updates.
117  int32_t GetDeviceId();
118  // Parent object, used to store the target for gesture event updates.
119  DirectManipulationOwner* owner_;
120  // We need to reset some parts of DirectManipulation after each gesture
121  // A flag is needed to ensure that false events created as the reset occurs
122  // are not sent to the flutter framework.
123  bool during_synthesized_reset_ = false;
124  // Store whether current events are from synthetic inertia rather than user
125  // input.
126  bool during_inertia_ = false;
127  // The transform might not be able to be reset before the next gesture, so
128  // the initial state needs to be stored for reference.
129  GestureData initial_gesture_data_ = {
130  1, // scale
131  0, // pan_x
132  0, // pan_y
133  };
134  // Store the difference between the last pan offsets to determine if inertia
135  // has been cancelled in the middle of an animation.
136  float last_pan_x_ = 0.0;
137  float last_pan_y_ = 0.0;
138  float last_pan_delta_x_ = 0.0;
139  float last_pan_delta_y_ = 0.0;
140 };
141 
142 } // namespace flutter
143 
144 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_DIRECT_MANIPULATION_H_
flutter::DirectManipulationEventHandler::QueryInterface
STDMETHODIMP QueryInterface(REFIID iid, void **ppv) override
Definition: direct_manipulation.cc:33
flutter::DirectManipulationOwner::SetContact
virtual void SetContact(UINT contactId)
Definition: direct_manipulation.cc:238
flutter::DirectManipulationEventHandler
Definition: direct_manipulation.h:67
flutter::DirectManipulationEventHandler::DirectManipulationOwner
friend class DirectManipulationOwner
Definition: direct_manipulation.h:71
flutter::DirectManipulationEventHandler::Release
ULONG STDMETHODCALLTYPE Release() override
Definition: direct_manipulation.cc:170
flutter::DirectManipulationEventHandler::OnViewportUpdated
HRESULT STDMETHODCALLTYPE OnViewportUpdated(IDirectManipulationViewport *viewport) override
Definition: direct_manipulation.cc:128
flutter::DirectManipulationEventHandler::OnInteraction
HRESULT STDMETHODCALLTYPE OnInteraction(IDirectManipulationViewport2 *viewport, DIRECTMANIPULATION_INTERACTION_TYPE interaction) override
Definition: direct_manipulation.cc:159
flutter::DirectManipulationOwner::SetBindingHandlerDelegate
void SetBindingHandlerDelegate(WindowBindingHandlerDelegate *binding_handler_delegate)
Definition: direct_manipulation.cc:244
flutter::WindowBindingHandlerDelegate
Definition: window_binding_handler_delegate.h:18
flutter::DirectManipulationOwner::DirectManipulationOwner
DirectManipulationOwner(FlutterWindow *window)
Definition: direct_manipulation.cc:175
flutter::DirectManipulationOwner::~DirectManipulationOwner
virtual ~DirectManipulationOwner()=default
flutter::DirectManipulationOwner::Update
void Update()
Definition: direct_manipulation.cc:249
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::DirectManipulationEventHandler::DirectManipulationEventHandler
DirectManipulationEventHandler(DirectManipulationOwner *owner)
Definition: direct_manipulation.h:76
flutter::DirectManipulationOwner::binding_handler_delegate
WindowBindingHandlerDelegate * binding_handler_delegate
Definition: direct_manipulation.h:46
flutter::DirectManipulationEventHandler::AddRef
ULONG STDMETHODCALLTYPE AddRef() override
Definition: direct_manipulation.cc:165
content
union flutter::testing::@87::KeyboardChange::@0 content
flutter::DirectManipulationEventHandler::OnViewportStatusChanged
HRESULT STDMETHODCALLTYPE OnViewportStatusChanged(IDirectManipulationViewport *viewport, DIRECTMANIPULATION_STATUS current, DIRECTMANIPULATION_STATUS previous) override
Definition: direct_manipulation.cc:64
flutter::DirectManipulationOwner::Init
int Init(unsigned int width, unsigned int height)
Definition: direct_manipulation.cc:178
flutter::DirectManipulationOwner::Destroy
void Destroy()
Definition: direct_manipulation.cc:215
flutter::FlutterWindow
Definition: flutter_window.h:35
flutter::DirectManipulationEventHandler::OnContentUpdated
HRESULT STDMETHODCALLTYPE OnContentUpdated(IDirectManipulationViewport *viewport, IDirectManipulationContent *content) override
Definition: direct_manipulation.cc:133
flutter::DirectManipulationOwner::ResizeViewport
void ResizeViewport(unsigned int width, unsigned int height)
Definition: direct_manipulation.cc:207
flutter::DirectManipulationOwner
Definition: direct_manipulation.h:22