Skip to content

Commit

Permalink
[web] Librarify semantics files (flutter#27151)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdebbar authored Jul 6, 2021
1 parent 82015df commit edc6797
Show file tree
Hide file tree
Showing 24 changed files with 156 additions and 47 deletions.
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/pointer_binding.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/pointer_converter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/profiler.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/rrect_renderer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/accessibility.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/checkable.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/semantics/image.dart
Expand Down
38 changes: 24 additions & 14 deletions lib/web_ui/lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import 'package:meta/meta.dart';

import '../ui.dart' as ui;

import 'engine/alarm_clock.dart';
export 'engine/alarm_clock.dart';

export 'engine/assets.dart';
Expand Down Expand Up @@ -131,8 +130,30 @@ export 'engine/pointer_converter.dart';
import 'engine/profiler.dart';
export 'engine/profiler.dart';

// This import is intentionally commented out because the analyzer says it's unused.
// import 'engine/services/buffers.dart';
import 'engine/semantics/accessibility.dart';
export 'engine/semantics/accessibility.dart';

export 'engine/semantics/checkable.dart';

export 'engine/semantics/image.dart';

export 'engine/semantics/incrementable.dart';

export 'engine/semantics/label_and_value.dart';

export 'engine/semantics/live_region.dart';

export 'engine/semantics/scrollable.dart';

import 'engine/semantics/semantics.dart';
export 'engine/semantics/semantics.dart';

export 'engine/semantics/semantics_helper.dart';

export 'engine/semantics/tappable.dart';

export 'engine/semantics/text_field.dart';

export 'engine/services/buffers.dart';

import 'engine/services/message_codec.dart';
Expand Down Expand Up @@ -302,17 +323,6 @@ part 'engine/platform_views/content_manager.dart';
part 'engine/platform_views/message_handler.dart';
part 'engine/platform_views/slots.dart';
part 'engine/rrect_renderer.dart';
part 'engine/semantics/accessibility.dart';
part 'engine/semantics/checkable.dart';
part 'engine/semantics/image.dart';
part 'engine/semantics/incrementable.dart';
part 'engine/semantics/label_and_value.dart';
part 'engine/semantics/live_region.dart';
part 'engine/semantics/scrollable.dart';
part 'engine/semantics/semantics.dart';
part 'engine/semantics/semantics_helper.dart';
part 'engine/semantics/tappable.dart';
part 'engine/semantics/text_field.dart';
part 'engine/window.dart';

// The mode the app is running in.
Expand Down
8 changes: 8 additions & 0 deletions lib/web_ui/lib/src/engine/browser_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ bool get isDesktop => _desktopOperatingSystems.contains(operatingSystem);
/// See [isDesktop].
bool get isMobile => !isDesktop;

/// Whether the browser is running on macOS or iOS.
///
/// - See [operatingSystem].
/// - See [OperatingSystem].
bool get isMacOrIOS =>
operatingSystem == OperatingSystem.iOs ||
operatingSystem == OperatingSystem.macOs;

int? _cachedWebGLVersion;

/// The highest WebGL version supported by the current browser, or -1 if WebGL
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/dom_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class DomRenderer {

// When debugging semantics, make the scene semi-transparent so that the
// semantics tree is visible.
if (_debugShowSemanticsNodes) {
if (debugShowSemanticsNodes) {
_sceneHostElement!.style.opacity = '0.3';
}

Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/lib/src/engine/keyboard_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import 'dart:html' as html;

import 'package:ui/src/engine.dart' show EnginePlatformDispatcher, EngineSemanticsOwner, registerHotRestartListener;
import 'package:ui/src/engine.dart' show EnginePlatformDispatcher, registerHotRestartListener;
import 'package:ui/ui.dart' as ui;

import 'browser_detection.dart';
import 'key_map.dart';
import 'semantics.dart';

typedef _VoidCallback = void Function();
typedef ValueGetter<T> = T Function();
Expand Down
9 changes: 9 additions & 0 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,15 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
invoke(_onTextScaleFactorChanged, _onTextScaleFactorChangedZone);
}

void updateSemanticsEnabled(bool semanticsEnabled) {
if (semanticsEnabled != this.semanticsEnabled) {
_configuration = _configuration.copyWith(semanticsEnabled: semanticsEnabled);
if (_onSemanticsEnabledChanged != null) {
invokeOnSemanticsEnabledChanged();
}
}
}

/// The setting indicating the current brightness mode of the host platform.
/// If the platform has no preference, [platformBrightness] defaults to [Brightness.light].
ui.Brightness get platformBrightness => configuration.platformBrightness;
Expand Down
15 changes: 15 additions & 0 deletions lib/web_ui/lib/src/engine/semantics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'semantics/accessibility.dart';
export 'semantics/checkable.dart';
export 'semantics/image.dart';
export 'semantics/incrementable.dart';
export 'semantics/label_and_value.dart';
export 'semantics/live_region.dart';
export 'semantics/scrollable.dart';
export 'semantics/semantics_helper.dart';
export 'semantics/semantics.dart';
export 'semantics/tappable.dart';
export 'semantics/text_field.dart';
8 changes: 7 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/accessibility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:async';
import 'dart:html' as html;
import 'dart:typed_data';

import 'package:ui/src/engine.dart' show registerHotRestartListener;

import '../services.dart';

/// Singleton for accessing accessibility announcements from the platform.
final AccessibilityAnnouncements accessibilityAnnouncements =
Expand Down
6 changes: 5 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/checkable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
// framework. Currently the framework does not report the
// grouping of radio buttons.

part of engine;
import 'dart:html' as html;

import 'package:ui/ui.dart' as ui;

import 'semantics.dart';

/// The specific type of checkable control.
enum _CheckableKind {
Expand Down
4 changes: 3 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:html' as html;

import 'semantics.dart';

/// Represents semantic objects that deliver information in a visual manner.
///
Expand Down
7 changes: 6 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/incrementable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:html' as html;

import 'package:ui/src/engine.dart' show EnginePlatformDispatcher;
import 'package:ui/ui.dart' as ui;

import 'semantics.dart';

/// Adds increment/decrement event handling to a semantics object.
///
Expand Down
8 changes: 6 additions & 2 deletions lib/web_ui/lib/src/engine/semantics/label_and_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:html' as html;

import 'package:ui/ui.dart' as ui;

import 'semantics.dart';

/// Renders [_label] and [_value] to the semantics DOM.
///
Expand Down Expand Up @@ -96,7 +100,7 @@ class LabelAndValue extends RoleManager {
// Normally use a small font size so that text doesn't leave the scope
// of the semantics node. When debugging semantics, use a font size
// that's reasonably visible.
_auxiliaryValueElement!.style.fontSize = _debugShowSemanticsNodes ? '12px' : '6px';
_auxiliaryValueElement!.style.fontSize = debugShowSemanticsNodes ? '12px' : '6px';
semanticsObject.element.append(_auxiliaryValueElement!);
}
_auxiliaryValueElement!.text = combinedValue.toString();
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/semantics/live_region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'semantics.dart';

/// Manages semantics configurations that represent live regions.
///
Expand Down
7 changes: 6 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/scrollable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:html' as html;

import 'package:ui/src/engine.dart' show EnginePlatformDispatcher;
import 'package:ui/ui.dart' as ui;

import 'semantics.dart';

/// Implements vertical and horizontal scrolling functionality for semantics
/// objects.
Expand Down
35 changes: 24 additions & 11 deletions lib/web_ui/lib/src/engine/semantics/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:html' as html;
import 'dart:math' as math;
import 'dart:typed_data';

import 'package:ui/src/engine.dart' show domRenderer, EnginePlatformDispatcher, registerHotRestartListener;
import 'package:ui/ui.dart' as ui;

import '../alarm_clock.dart';
import '../browser_detection.dart';
import '../util.dart';
import '../vector_math.dart';
import 'checkable.dart';
import 'image.dart';
import 'incrementable.dart';
import 'label_and_value.dart';
import 'live_region.dart';
import 'scrollable.dart';
import 'semantics_helper.dart';
import 'tappable.dart';
import 'text_field.dart';

/// Set this flag to `true` to cause the engine to visualize the semantics tree
/// on the screen for debugging.
Expand All @@ -15,7 +34,7 @@ part of engine;
/// ```
/// flutter run -d chrome --profile --dart-define=FLUTTER_WEB_DEBUG_SHOW_SEMANTICS=true
/// ```
const bool _debugShowSemanticsNodes = bool.fromEnvironment(
const bool debugShowSemanticsNodes = bool.fromEnvironment(
'FLUTTER_WEB_DEBUG_SHOW_SEMANTICS',
defaultValue: false,
);
Expand Down Expand Up @@ -266,7 +285,7 @@ class SemanticsObject {
element.style.position = 'absolute';

// The root node has some properties that other nodes do not.
if (id == 0 && !_debugShowSemanticsNodes) {
if (id == 0 && !debugShowSemanticsNodes) {
// Make all semantics transparent. We use `filter` instead of `opacity`
// attribute because `filter` is stronger. `opacity` does not apply to
// some elements, particularly on iOS, such as the slider thumb and track.
Expand All @@ -283,7 +302,7 @@ class SemanticsObject {
// Make semantic elements visible for debugging by outlining them using a
// green border. We do not use `border` attribute because it affects layout
// (`outline` does not).
if (_debugShowSemanticsNodes) {
if (debugShowSemanticsNodes) {
element.style.outline = '1px solid green';
}
}
Expand Down Expand Up @@ -1353,13 +1372,7 @@ class EngineSemanticsOwner {
_rootSemanticsElement = null;
_gestureModeClock?.datetime = null;
}
if (_semanticsEnabled != EnginePlatformDispatcher.instance.semanticsEnabled) {
EnginePlatformDispatcher.instance._configuration =
EnginePlatformDispatcher.instance._configuration.copyWith(semanticsEnabled: _semanticsEnabled);
if (EnginePlatformDispatcher.instance._onSemanticsEnabledChanged != null) {
EnginePlatformDispatcher.instance.invokeOnSemanticsEnabledChanged();
}
}
EnginePlatformDispatcher.instance.updateSemanticsEnabled(_semanticsEnabled);
}

/// Controls how pointer events and browser-detected gestures are treated by
Expand Down
8 changes: 7 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/semantics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:async';
import 'dart:html' as html;

import 'package:meta/meta.dart';

import '../browser_detection.dart';
import 'semantics.dart';

/// The maximum [semanticsActivationAttempts] before we give up waiting for
/// the user to enable semantics.
Expand Down
7 changes: 6 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/tappable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:html' as html;

import 'package:ui/src/engine.dart' show EnginePlatformDispatcher;
import 'package:ui/ui.dart' as ui;

import 'semantics.dart';

/// Listens to HTML "click" gestures detected by the browser.
///
Expand Down
9 changes: 8 additions & 1 deletion lib/web_ui/lib/src/engine/semantics/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of engine;
import 'dart:html' as html;

import 'package:ui/src/engine.dart' show EnginePlatformDispatcher;
import 'package:ui/ui.dart' as ui;

import '../text_editing/text_editing.dart';
import '../browser_detection.dart';
import 'semantics.dart';

/// Text editing used by accesibility mode.
///
Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import 'dart:math' as math;
import 'dart:typed_data';

import 'package:meta/meta.dart';
import 'package:ui/src/engine.dart' show domRenderer, EnginePlatformDispatcher, EngineSemanticsOwner, SemanticsTextEditingStrategy;
import 'package:ui/src/engine.dart' show domRenderer, EnginePlatformDispatcher;
import 'package:ui/ui.dart' as ui;

import '../browser_detection.dart';
import '../host_node.dart';
import '../semantics.dart';
import '../services.dart';
import '../text/paragraph.dart';
import '../util.dart';
Expand Down
4 changes: 0 additions & 4 deletions lib/web_ui/lib/src/engine/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,6 @@ const Set<String> _genericFontFamilies = <String>{
final String _fallbackFontFamily =
isMacOrIOS ? '-apple-system, BlinkMacSystemFont' : 'Arial';

bool get isMacOrIOS =>
operatingSystem == OperatingSystem.iOs ||
operatingSystem == OperatingSystem.macOs;

/// Create a font-family string appropriate for CSS.
///
/// If the given [fontFamily] is a generic font-family, then just return it.
Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/test/engine/semantics/accessibility_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'dart:html';

import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
import 'package:ui/src/engine/semantics.dart';
import 'package:ui/src/engine/services.dart';

const StandardMessageCodec codec = StandardMessageCodec();
const String testMessage = 'This is an tooltip.';
Expand Down
4 changes: 3 additions & 1 deletion lib/web_ui/test/engine/semantics/semantics_helper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'dart:html' as html;

import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
import 'package:ui/src/engine/browser_detection.dart';
import 'package:ui/src/engine/pointer_binding.dart';
import 'package:ui/src/engine/semantics.dart';

const PointerSupportDetector _defaultSupportDetector = PointerSupportDetector();

Expand Down
Loading

0 comments on commit edc6797

Please sign in to comment.