binding.dart 2.07 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' as ui show AccessibilityFeatures, window;

import 'package:flutter/foundation.dart';

9 10
import 'debug.dart';

11
export 'dart:ui' show AccessibilityFeatures;
12 13 14

/// The glue between the semantics layer and the Flutter engine.
// TODO(jonahwilliams): move the remaining semantic related bindings here.
15 16 17 18 19
class SemanticsBinding extends BindingBase {
  // This class is intended to be used as a mixin, and should not be
  // extended directly.
  factory SemanticsBinding._() => null;

20 21 22 23 24 25 26 27
  /// The current [SemanticsBinding], if one has been created.
  static SemanticsBinding get instance => _instance;
  static SemanticsBinding _instance;

  @override
  void initInstances() {
    super.initInstances();
    _instance = this;
28
    _accessibilityFeatures = ui.window.accessibilityFeatures;
29 30 31 32 33 34 35
  }

  /// Called when the platform accessibility features change.
  ///
  /// See [Window.onAccessibilityFeaturesChanged].
  @protected
  void handleAccessibilityFeaturesChanged() {
36
    _accessibilityFeatures = ui.window.accessibilityFeatures;
37 38 39 40 41 42 43 44 45
  }

  /// The currently active set of [AccessibilityFeatures].
  ///
  /// This is initialized the first time [runApp] is called and updated whenever
  /// a flag is changed.
  ///
  /// To listen to changes to accessibility features, create a
  /// [WidgetsBindingObserver] and listen to [didChangeAccessibilityFeatures].
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  ui.AccessibilityFeatures get accessibilityFeatures => _accessibilityFeatures;
  ui.AccessibilityFeatures _accessibilityFeatures;

  /// The platform is requesting that animations be disabled or simplified.
  ///
  /// This setting can be overriden for testing or debugging by setting
  /// [debugSemanticsDisableAnimations].
  bool get disableAnimations {
    bool value = _accessibilityFeatures.disableAnimations;
    assert(() {
      if (debugSemanticsDisableAnimations != null)
          value = debugSemanticsDisableAnimations;
      return true;
    }());
    return value;
  }
}