| Flutter iOS Embedder |

FlutterPlatformViews_Internal.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_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_
7
8 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
9
10 #include <Metal/Metal.h>
11
12 #include "flutter/flow/surface.h"
13 #include "flutter/fml/memory/weak_ptr.h"
14 #include "flutter/fml/task_runner.h"
15 #include "flutter/fml/trace_event.h"
16 #include "flutter/impeller/base/thread_safety.h"
17 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
18 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h"
19 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.h"
20 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h"
21 #include "flutter/shell/platform/darwin/ios/ios_context.h"
22
23 // A UIView that acts as a clipping mask for the |ChildClippingView|.
24 //
25 // On the [UIView drawRect:] method, this view performs a series of clipping operations and sets the
26 // alpha channel to the final resulting area to be 1; it also sets the "clipped out" area's alpha
27 // channel to be 0.
28 //
29 // When a UIView sets a |FlutterClippingMaskView| as its `maskView`, the alpha channel of the UIView
30 // is replaced with the alpha channel of the |FlutterClippingMaskView|.
31 @interface FlutterClippingMaskView : UIView
32
33 - (instancetype)initWithFrame:(CGRect)frame screenScale:(CGFloat)screenScale;
34
35 - (void)reset;
36
37 // Adds a clip rect operation to the queue.
38 //
39 // The `clipSkRect` is transformed with the `matrix` before adding to the queue.
40 - (void)clipRect:(const flutter::DlRect&)clipDlRect matrix:(const flutter::DlMatrix&)matrix;
41
42 // Adds a clip rrect operation to the queue.
43 //
44 // The `clipSkRRect` is transformed with the `matrix` before adding to the queue.
45 - (void)clipRRect:(const flutter::DlRoundRect&)clipDlRRect matrix:(const flutter::DlMatrix&)matrix;
46
47 // Adds a clip path operation to the queue.
48 //
49 // The `path` is transformed with the `matrix` before adding to the queue.
50 - (void)clipPath:(const flutter::DlPath&)path matrix:(const flutter::DlMatrix&)matrix;
51
52 @end
53
54 // A pool that provides |FlutterClippingMaskView|s.
55 //
56 // The pool has a capacity that can be set in the initializer.
57 // When requesting a FlutterClippingMaskView, the pool will first try to reuse an available maskView
58 // in the pool. If there are none available, a new FlutterClippingMaskView is constructed. If the
59 // capacity is reached, the newly constructed FlutterClippingMaskView is not added to the pool.
60 //
61 // Call |insertViewToPoolIfNeeded:| to return a maskView to the pool.
62 @interface FlutterClippingMaskViewPool : NSObject
63
64 // Initialize the pool with `capacity`. When the `capacity` is reached, a FlutterClippingMaskView is
65 // constructed when requested, and it is not added to the pool.
66 - (instancetype)initWithCapacity:(NSInteger)capacity;
67
68 // Reuse a maskView from the pool, or allocate a new one.
69 - (FlutterClippingMaskView*)getMaskViewWithFrame:(CGRect)frame;
70
71 // Insert the `maskView` into the pool.
72 - (void)insertViewToPoolIfNeeded:(FlutterClippingMaskView*)maskView;
73
74 @end
75
76 // An object represents a blur filter.
77 //
78 // This object produces a `backdropFilterView`.
79 // To blur a View, add `backdropFilterView` as a subView of the View.
80 @interface PlatformViewFilter : NSObject
81
82 // Determines the rect of the blur effect in the coordinate system of `backdropFilterView`'s
83 // parentView.
84 @property(nonatomic, readonly) CGRect frame;
85
86 // Determines the blur intensity.
87 //
88 // It is set as the value of `inputRadius` of the `gaussianFilter` that is internally used.
89 @property(nonatomic, readonly) CGFloat blurRadius;
90
91 // This is the view to use to blur the PlatformView.
92 //
93 // It is a modified version of UIKit's `UIVisualEffectView`.
94 // The inputRadius can be customized and it doesn't add any color saturation to the blurred view.
95 @property(nonatomic, readonly) UIVisualEffectView* backdropFilterView;
96
97 // For testing only.
98 + (void)resetPreparation;
99
100 - (instancetype)init NS_UNAVAILABLE;
101
102 // Initialize the filter object.
103 //
104 // The `frame` determines the rect of the blur effect in the coordinate system of
105 // `backdropFilterView`'s parentView. The `blurRadius` determines the blur intensity. It is set as
106 // the value of `inputRadius` of the `gaussianFilter` that is internally used. The
107 // `UIVisualEffectView` is the view that is used to add the blur effects. It is modified to become
108 // `backdropFilterView`, which better supports the need of Flutter.
109 //
110 // Note: if the implementation of UIVisualEffectView changes in a way that affects the
111 // implementation in `PlatformViewFilter`, this method will return nil.
112 - (instancetype)initWithFrame:(CGRect)frame
113 blurRadius:(CGFloat)blurRadius
114 visualEffectView:(UIVisualEffectView*)visualEffectView NS_DESIGNATED_INITIALIZER;
115
116 @end
117
118 // The parent view handles clipping to its subViews.
119 @interface ChildClippingView : UIView
120
121 // Applies blur backdrop filters to the ChildClippingView with blur values from
122 // filters.
123 - (void)applyBlurBackdropFilters:(NSArray<PlatformViewFilter*>*)filters;
124
125 // For testing only.
126 - (NSMutableArray*)backdropFilterSubviews;
127 @end
128
129 // A UIView that is used as the parent for embedded UIViews.
130 //
131 // This view has 2 roles:
132 // 1. Delay or prevent touch events from arriving the embedded view.
133 // 2. Dispatching all events that are hittested to the embedded view to the FlutterView.
134 @interface FlutterTouchInterceptingView : UIView
135 - (instancetype)initWithEmbeddedView:(UIView*)embeddedView
136 platformViewsController:(FlutterPlatformViewsController*)platformViewsController
137 gestureRecognizersBlockingPolicy:
138 (FlutterPlatformViewGestureRecognizersBlockingPolicy)blockingPolicy;
139
140 // Stop delaying any active touch sequence (and let it arrive the embedded view).
141 - (void)releaseGesture;
142
143 // Prevent the touch sequence from ever arriving to the embedded view.
144 - (void)blockGesture;
145
146 // Get embedded view
147 - (UIView*)embeddedView;
148
149 // Sets flutterAccessibilityContainer as this view's accessibilityContainer.
150 @property(nonatomic, retain) id flutterAccessibilityContainer;
151 @end
152
153 @interface UIView (FirstResponder)
154 // Returns YES if a view or any of its descendant view is the first responder. Returns NO otherwise.
155 @property(nonatomic, readonly) BOOL flt_hasFirstResponderInViewHierarchySubtree;
156 @end
157
158 // This recognizer delays touch events from being dispatched to the responder chain until it failed
159 // recognizing a gesture.
160 //
161 // We only fail this recognizer when asked to do so by the Flutter framework (which does so by
162 // invoking an acceptGesture method on the platform_views channel). And this is how we allow the
163 // Flutter framework to delay or prevent the embedded view from getting a touch sequence.
164 @interface FlutterDelayingGestureRecognizer : UIGestureRecognizer <UIGestureRecognizerDelegate>
165
166 // Indicates that if the `FlutterDelayingGestureRecognizer`'s state should be set to
167 // `UIGestureRecognizerStateEnded` during next `touchesEnded` call.
168 @property(nonatomic) BOOL shouldEndInNextTouchesEnded;
169
170 // Indicates that the `FlutterDelayingGestureRecognizer`'s `touchesEnded` has been invoked without
171 // setting the state to `UIGestureRecognizerStateEnded`.
172 @property(nonatomic) BOOL touchedEndedWithoutBlocking;
173
174 @property(nonatomic) UIGestureRecognizer* forwardingRecognizer;
175
176 - (instancetype)initWithTarget:(id)target
177 action:(SEL)action
178 forwardingRecognizer:(UIGestureRecognizer*)forwardingRecognizer;
179 @end
180
181 // While the FlutterDelayingGestureRecognizer is preventing touches from hitting the responder chain
182 // the touch events are not arriving to the FlutterView (and thus not arriving to the Flutter
183 // framework). We use this gesture recognizer to dispatch the events directly to the FlutterView
184 // while during this phase.
185 //
186 // If the Flutter framework decides to dispatch events to the embedded view, we fail the
187 // FlutterDelayingGestureRecognizer which sends the events up the responder chain. But since the
188 // events are handled by the embedded view they are not delivered to the Flutter framework in this
189 // phase as well. So during this phase as well the ForwardingGestureRecognizer dispatched the events
190 // directly to the FlutterView.
191 @interface ForwardingGestureRecognizer : UIGestureRecognizer <UIGestureRecognizerDelegate>
192 - (instancetype)initWithTarget:(id)target
193 platformViewsController:(FlutterPlatformViewsController*)platformViewsController;
194 - (ForwardingGestureRecognizer*)recreateRecognizerWithTarget:(id)target;
195 @end
196
197 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_
FlutterChannels.h
FlutterPlatformViews.h
FlutterPlatformViewsController.h
FlutterPlugin.h
FlutterPlatformViewGestureRecognizersBlockingPolicy
FlutterPlatformViewGestureRecognizersBlockingPolicy
Definition: FlutterPlugin.h:252
initWithFrame
instancetype initWithFrame
Definition: FlutterTextInputPlugin.h:172
FlutterViewResponder.h
UIView(FirstResponder)
Definition: FlutterPlatformViews.mm:495
UIView(FirstResponder)::flt_hasFirstResponderInViewHierarchySubtree
BOOL flt_hasFirstResponderInViewHierarchySubtree
Definition: FlutterPlatformViews_Internal.h:155
ChildClippingView
Definition: FlutterPlatformViews.mm:183
-[ChildClippingView backdropFilterSubviews]
NSMutableArray * backdropFilterSubviews()
Definition: FlutterPlatformViews.mm:221
FlutterClippingMaskView
Definition: FlutterPlatformViews.mm:246
-[FlutterClippingMaskView reset]
void reset()
Definition: FlutterPlatformViews.mm:274
FlutterClippingMaskViewPool
Definition: FlutterPlatformViews.mm:458
FlutterDelayingGestureRecognizer
Definition: FlutterPlatformViews.mm:645
FlutterTouchInterceptingView
Definition: FlutterPlatformViews.mm:515
-[FlutterTouchInterceptingView releaseGesture]
void releaseGesture()
Definition: FlutterPlatformViews.mm:559
-[FlutterTouchInterceptingView blockGesture]
void blockGesture()
Definition: FlutterPlatformViews.mm:578
-[FlutterTouchInterceptingView embeddedView]
UIView * embeddedView()
FlutterTouchInterceptingView::flutterAccessibilityContainer
id flutterAccessibilityContainer
Definition: FlutterPlatformViews_Internal.h:150
ForwardingGestureRecognizer
Definition: FlutterPlatformViews.mm:694
PlatformViewFilter
Definition: FlutterPlatformViews.mm:91
-[PlatformViewFilter NS_UNAVAILABLE]
instancetype NS_UNAVAILABLE()
PlatformViewFilter::backdropFilterView
UIVisualEffectView * backdropFilterView
Definition: FlutterPlatformViews_Internal.h:95
+[PlatformViewFilter resetPreparation]
void resetPreparation()
Definition: FlutterPlatformViews.mm:118
PlatformViewFilter::blurRadius
CGFloat blurRadius
Definition: FlutterPlatformViews_Internal.h:89
PlatformViewFilter::frame
CGRect frame
Definition: FlutterPlatformViews_Internal.h:84
FlutterPlatformViewsController
Definition: FlutterPlatformViewsController.h:31
ios_context.h
flutter
Definition: accessibility_bridge.h:26