• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package io.flutter.plugin.platform;
6 
7 import android.support.annotation.NonNull;
8 import android.support.annotation.Nullable;
9 import android.view.View;
10 import android.view.accessibility.AccessibilityEvent;
11 import io.flutter.view.AccessibilityBridge;
12 
13 /**
14  * Delegates accessibility events to the currently attached accessibility bridge if one is attached.
15  */
16 class AccessibilityEventsDelegate {
17     private AccessibilityBridge accessibilityBridge;
18 
19     /**
20      * Delegates handling of {@link android.view.ViewParent#requestSendAccessibilityEvent} to the accessibility bridge.
21      *
22      * This is a no-op if there is no accessibility delegate set.
23      *
24      * This is used by embedded platform views to propagate accessibility events from their view hierarchy to the
25      * accessibility bridge.
26      *
27      * As the embedded view doesn't have to be the only View in the embedded hierarchy (it can have child views) and the
28      * event might have been originated from any view in this hierarchy, this method gets both a reference to the
29      * embedded platform view, and a reference to the view from its hierarchy that sent the event.
30      *
31      * @param embeddedView the embedded platform view for which the event is delegated
32      * @param eventOrigin the view in the embedded view's hierarchy that sent the event.
33      * @return True if the event was sent.
34      */
requestSendAccessibilityEvent(@onNull View embeddedView, @NonNull View eventOrigin, @NonNull AccessibilityEvent event)35     public boolean requestSendAccessibilityEvent(@NonNull View embeddedView, @NonNull View eventOrigin, @NonNull AccessibilityEvent event) {
36         if (accessibilityBridge == null) {
37             return false;
38         }
39         return accessibilityBridge.externalViewRequestSendAccessibilityEvent(embeddedView, eventOrigin, event);
40     }
41 
42     /*
43      * This setter should only be used directly in PlatformViewsController when attached/detached to an accessibility
44      * bridge.
45      */
setAccessibilityBridge(@ullable AccessibilityBridge accessibilityBridge)46     void setAccessibilityBridge(@Nullable AccessibilityBridge accessibilityBridge) {
47         this.accessibilityBridge = accessibilityBridge;
48     }
49 }
50