19
19
20
20
import io .flutter .embedding .engine .dart .DartExecutor ;
21
21
import io .flutter .embedding .engine .systemchannels .PlatformViewsChannel ;
22
- import io .flutter .plugin .common .BinaryMessenger ;
23
- import io .flutter .plugin .common .MethodCall ;
24
- import io .flutter .plugin .common .MethodChannel ;
25
- import io .flutter .plugin .common .StandardMethodCodec ;
26
22
import io .flutter .plugin .editing .TextInputPlugin ;
27
23
import io .flutter .view .AccessibilityBridge ;
28
24
import io .flutter .view .TextureRegistry ;
29
25
30
- import java .lang .reflect .Method ;
31
- import java .nio .ByteBuffer ;
32
26
import java .util .ArrayList ;
33
27
import java .util .HashMap ;
34
- import java .util .HashSet ;
35
28
import java .util .List ;
36
29
37
30
/**
@@ -64,10 +57,10 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
64
57
65
58
private final HashMap <Integer , VirtualDisplayController > vdControllers ;
66
59
67
- // The set of root views for all active virtual displays managed by this controller .
68
- // This allows an O(1) check whether a view is managed by this controller(by checking if it's root view is in this
69
- // set). This is used by isPlatformView .
70
- private final HashSet < View > vdRootViews ;
60
+ // Maps a virtual display's context to the platform view hosted in this virtual display .
61
+ // Since each virtual display has it's unique context this allows associating any view with the platform view that
62
+ // it is associated with(e.g if a platform view creates other views in the same virtual display .
63
+ private final HashMap < Context , View > contextToPlatformView ;
71
64
72
65
private final PlatformViewsChannel .PlatformViewsHandler channelHandler = new PlatformViewsChannel .PlatformViewsHandler () {
73
66
@ TargetApi (Build .VERSION_CODES .JELLY_BEAN_MR1 )
@@ -125,7 +118,7 @@ public long createPlatformView(@NonNull PlatformViewsChannel.PlatformViewCreatio
125
118
vdControllers .put (request .viewId , vdController );
126
119
View platformView = vdController .getView ();
127
120
platformView .setLayoutDirection (request .direction );
128
- vdRootViews . add (platformView .getRootView () );
121
+ contextToPlatformView . put (platformView .getContext (), platformView );
129
122
130
123
// TODO(amirh): copy accessibility nodes to the FlutterView's accessibility tree.
131
124
@@ -142,8 +135,7 @@ public void disposePlatformView(int viewId) {
142
135
+ viewId );
143
136
}
144
137
145
- View rootView = vdController .getView ().getRootView ();
146
- vdRootViews .remove (rootView );
138
+ contextToPlatformView .remove (vdController .getView ().getContext ());
147
139
148
140
vdController .dispose ();
149
141
vdControllers .remove (viewId );
@@ -170,7 +162,6 @@ public void resizePlatformView(@NonNull PlatformViewsChannel.PlatformViewResizeR
170
162
// and unlock after the resize is complete.
171
163
textInputPlugin .lockPlatformViewInputConnection ();
172
164
}
173
- vdRootViews .remove (vdController .getView ().getRootView ());
174
165
vdController .resize (
175
166
physicalWidth ,
176
167
physicalHeight ,
@@ -184,7 +175,6 @@ public void run() {
184
175
}
185
176
}
186
177
);
187
- vdRootViews .add (vdController .getView ().getRootView ());
188
178
}
189
179
190
180
@ Override
@@ -264,7 +254,7 @@ public PlatformViewsController() {
264
254
registry = new PlatformViewRegistryImpl ();
265
255
vdControllers = new HashMap <>();
266
256
accessibilityEventsDelegate = new AccessibilityEventsDelegate ();
267
- vdRootViews = new HashSet <>();
257
+ contextToPlatformView = new HashMap <>();
268
258
}
269
259
270
260
/**
@@ -335,10 +325,22 @@ public void detachTextInputPlugin() {
335
325
}
336
326
337
327
/**
338
- * Returns true if the view is a platform view managed by this controller.
328
+ * Returns true if Flutter should perform input connection proxying for the view.
329
+ *
330
+ * If the view is a platform view managed by this platform views controller returns true.
331
+ * Else if the view was created in a platform view's VD, delegates the decision to the platform view's
332
+ * {@link View#checkInputConnectionProxy(View)} method.
333
+ * Else returns false.
339
334
*/
340
- public boolean isPlatformView (View view ) {
341
- return vdRootViews .contains (view .getRootView ());
335
+ public boolean checkInputConnectionProxy (View view ) {
336
+ if (!contextToPlatformView .containsKey (view .getContext ())) {
337
+ return false ;
338
+ }
339
+ View platformView = contextToPlatformView .get (view .getContext ());
340
+ if (platformView == view ) {
341
+ return true ;
342
+ }
343
+ return platformView .checkInputConnectionProxy (view );
342
344
}
343
345
344
346
public PlatformViewRegistry getRegistry () {
0 commit comments