Flutter Engine
The Flutter Engine
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
13namespace flutter {
14
15class FlutterWindow;
16class WindowBindingHandlerDelegate;
17
18class DirectManipulationEventHandler;
19
20// Owner for a DirectManipulation event handler, contains the link between
21// DirectManipulation and WindowBindingHandlerDelegate.
23 public:
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.
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 {
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.
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_
ULONG STDMETHODCALLTYPE Release() override
HRESULT STDMETHODCALLTYPE OnViewportUpdated(IDirectManipulationViewport *viewport) override
STDMETHODIMP QueryInterface(REFIID iid, void **ppv) override
HRESULT STDMETHODCALLTYPE OnInteraction(IDirectManipulationViewport2 *viewport, DIRECTMANIPULATION_INTERACTION_TYPE interaction) override
ULONG STDMETHODCALLTYPE AddRef() override
DirectManipulationEventHandler(DirectManipulationOwner *owner)
HRESULT STDMETHODCALLTYPE OnViewportStatusChanged(IDirectManipulationViewport *viewport, DIRECTMANIPULATION_STATUS current, DIRECTMANIPULATION_STATUS previous) override
HRESULT STDMETHODCALLTYPE OnContentUpdated(IDirectManipulationViewport *viewport, IDirectManipulationContent *content) override
virtual void SetContact(UINT contactId)
void SetBindingHandlerDelegate(WindowBindingHandlerDelegate *binding_handler_delegate)
virtual ~DirectManipulationOwner()=default
WindowBindingHandlerDelegate * binding_handler_delegate
int Init(unsigned int width, unsigned int height)
void ResizeViewport(unsigned int width, unsigned int height)
DirectManipulationOwner(FlutterWindow *window)
GLFWwindow * window
Definition: main.cc:45
union flutter::testing::@2836::KeyboardChange::@76 content
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
#define FML_FRIEND_REF_COUNTED_THREAD_SAFE(T)
Definition: ref_counted.h:126
#define FML_FRIEND_MAKE_REF_COUNTED(T)
Definition: ref_counted.h:132
int32_t height
int32_t width
const Scalar scale
unsigned int UINT
Definition: windows_types.h:32
DWORD ULONG
Definition: windows_types.h:40
unsigned long DWORD
Definition: windows_types.h:22