Skip to content

Commit

Permalink
Revert "Fix Slider semantic node size (flutter#115285)" (flutter#11…
Browse files Browse the repository at this point in the history
…6294)

This reverts commit 8473da2.
  • Loading branch information
Casey Hillers authored and shogohida committed Dec 7, 2022
1 parent 925bfcc commit 5e71622
Show file tree
Hide file tree
Showing 4 changed files with 504 additions and 233 deletions.
132 changes: 57 additions & 75 deletions packages/flutter/lib/src/material/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,22 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
// in range_slider.dart.
Size screenSize() => MediaQuery.of(context).size;

void handleDidGainAccessibilityFocus() {
// Automatically activate the slider when it receives a11y focus.
if (!focusNode.hasFocus && focusNode.canRequestFocus) {
focusNode.requestFocus();
}
VoidCallback? handleDidGainAccessibilityFocus;
switch (theme.platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
break;
case TargetPlatform.windows:
handleDidGainAccessibilityFocus = () {
// Automatically activate the slider when it receives a11y focus.
if (!focusNode.hasFocus && focusNode.canRequestFocus) {
focusNode.requestFocus();
}
};
break;
}

final Map<ShortcutActivator, Intent> shortcutMap;
Expand All @@ -846,35 +857,38 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
? math.min(MediaQuery.of(context).textScaleFactor, 1.3)
: MediaQuery.of(context).textScaleFactor;

return FocusableActionDetector(
actions: _actionMap,
shortcuts: shortcutMap,
focusNode: focusNode,
autofocus: widget.autofocus,
enabled: _enabled,
onShowFocusHighlight: _handleFocusHighlightChanged,
onShowHoverHighlight: _handleHoverChanged,
mouseCursor: effectiveMouseCursor,
includeFocusSemantics: false,
child: CompositedTransformTarget(
link: _layerLink,
child: _SliderRenderObjectWidget(
key: _renderObjectKey,
value: _convert(widget.value),
secondaryTrackValue: (widget.secondaryTrackValue != null) ? _convert(widget.secondaryTrackValue!) : null,
divisions: widget.divisions,
label: widget.label,
sliderTheme: sliderTheme,
textScaleFactor: textScaleFactor,
screenSize: screenSize(),
onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null,
onChangeStart: _handleDragStart,
onChangeEnd: _handleDragEnd,
state: this,
semanticFormatterCallback: widget.semanticFormatterCallback,
onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,
hasFocus: _focused,
hovering: _hovering,
return Semantics(
container: true,
slider: true,
onDidGainAccessibilityFocus: handleDidGainAccessibilityFocus,
child: FocusableActionDetector(
actions: _actionMap,
shortcuts: shortcutMap,
focusNode: focusNode,
autofocus: widget.autofocus,
enabled: _enabled,
onShowFocusHighlight: _handleFocusHighlightChanged,
onShowHoverHighlight: _handleHoverChanged,
mouseCursor: effectiveMouseCursor,
child: CompositedTransformTarget(
link: _layerLink,
child: _SliderRenderObjectWidget(
key: _renderObjectKey,
value: _convert(widget.value),
secondaryTrackValue: (widget.secondaryTrackValue != null) ? _convert(widget.secondaryTrackValue!) : null,
divisions: widget.divisions,
label: widget.label,
sliderTheme: sliderTheme,
textScaleFactor: textScaleFactor,
screenSize: screenSize(),
onChanged: (widget.onChanged != null) && (widget.max > widget.min) ? _handleChanged : null,
onChangeStart: _handleDragStart,
onChangeEnd: _handleDragEnd,
state: this,
semanticFormatterCallback: widget.semanticFormatterCallback,
hasFocus: _focused,
hovering: _hovering,
),
),
),
);
Expand Down Expand Up @@ -935,7 +949,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
required this.onChangeEnd,
required this.state,
required this.semanticFormatterCallback,
required this.onDidGainAccessibilityFocus,
required this.hasFocus,
required this.hovering,
});
Expand All @@ -951,7 +964,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
final ValueChanged<double>? onChangeStart;
final ValueChanged<double>? onChangeEnd;
final SemanticFormatterCallback? semanticFormatterCallback;
final VoidCallback? onDidGainAccessibilityFocus;
final _SliderState state;
final bool hasFocus;
final bool hovering;
Expand All @@ -972,7 +984,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
state: state,
textDirection: Directionality.of(context),
semanticFormatterCallback: semanticFormatterCallback,
onDidGainAccessibilityFocus: onDidGainAccessibilityFocus,
platform: Theme.of(context).platform,
hasFocus: hasFocus,
hovering: hovering,
Expand All @@ -997,7 +1008,6 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
..onChangeEnd = onChangeEnd
..textDirection = Directionality.of(context)
..semanticFormatterCallback = semanticFormatterCallback
..onDidGainAccessibilityFocus = onDidGainAccessibilityFocus
..platform = Theme.of(context).platform
..hasFocus = hasFocus
..hovering = hovering
Expand All @@ -1019,7 +1029,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
required TargetPlatform platform,
required ValueChanged<double>? onChanged,
required SemanticFormatterCallback? semanticFormatterCallback,
required this.onDidGainAccessibilityFocus,
required this.onChangeStart,
required this.onChangeEnd,
required _SliderState state,
Expand Down Expand Up @@ -1105,7 +1114,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
bool _active = false;
double _currentDragValue = 0.0;
Rect? overlayRect;
late Offset _thumbCenter;

// This rect is used in gesture calculations, where the gesture coordinates
// are relative to the sliders origin. Therefore, the offset is passed as
Expand Down Expand Up @@ -1251,7 +1259,6 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
}
}

VoidCallback? onDidGainAccessibilityFocus;
ValueChanged<double>? onChangeStart;
ValueChanged<double>? onChangeEnd;

Expand Down Expand Up @@ -1575,10 +1582,10 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
sliderTheme: _sliderTheme,
isDiscrete: isDiscrete,
);
_thumbCenter = Offset(trackRect.left + visualPosition * trackRect.width, trackRect.center.dy);
final Offset thumbCenter = Offset(trackRect.left + visualPosition * trackRect.width, trackRect.center.dy);
if (isInteractive) {
final Size overlaySize = sliderTheme.overlayShape!.getPreferredSize(isInteractive, false);
overlayRect = Rect.fromCircle(center: _thumbCenter, radius: overlaySize.width / 2.0);
overlayRect = Rect.fromCircle(center: thumbCenter, radius: overlaySize.width / 2.0);
}
final Offset? secondaryOffset = (secondaryVisualPosition != null) ? Offset(trackRect.left + secondaryVisualPosition * trackRect.width, trackRect.center.dy) : null;

Expand All @@ -1589,7 +1596,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
sliderTheme: _sliderTheme,
enableAnimation: _enableAnimation,
textDirection: _textDirection,
thumbCenter: _thumbCenter,
thumbCenter: thumbCenter,
secondaryOffset: secondaryOffset,
isDiscrete: isDiscrete,
isEnabled: isInteractive,
Expand All @@ -1598,7 +1605,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
if (!_overlayAnimation.isDismissed) {
_sliderTheme.overlayShape!.paint(
context,
_thumbCenter,
thumbCenter,
activationAnimation: _overlayAnimation,
enableAnimation: _enableAnimation,
isDiscrete: isDiscrete,
Expand Down Expand Up @@ -1635,7 +1642,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
sliderTheme: _sliderTheme,
enableAnimation: _enableAnimation,
textDirection: _textDirection,
thumbCenter: _thumbCenter,
thumbCenter: thumbCenter,
isEnabled: isInteractive,
);
}
Expand All @@ -1648,7 +1655,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
if (attached) {
_sliderTheme.valueIndicatorShape!.paint(
context,
offset + _thumbCenter,
offset + thumbCenter,
activationAnimation: _valueIndicatorAnimation,
enableAnimation: _enableAnimation,
isDiscrete: isDiscrete,
Expand All @@ -1667,7 +1674,7 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {

_sliderTheme.thumbShape!.paint(
context,
_thumbCenter,
thumbCenter,
activationAnimation: _overlayAnimation,
enableAnimation: _enableAnimation,
isDiscrete: isDiscrete,
Expand All @@ -1681,47 +1688,22 @@ class _RenderSlider extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
);
}

@override
void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, Iterable<SemanticsNode> children) {
node.rect = Rect.fromCenter(
center: _thumbCenter,
width: kMinInteractiveDimension,
height: kMinInteractiveDimension,
);

node.updateWith(config: config);
}

@override
void describeSemanticsConfiguration(SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);

// The Slider widget has its own Focus widget with semantics information,
// and want that semantics node to collect the semantics information here
// and we want that semantics node to collect the semantics information here
// so that it's all in the same node: otherwise Talkback sees that the node
// has focusable children, and it won't focus the Slider's Focus widget
// because it thinks the Focus widget's node doesn't have anything to say
// (which it doesn't, but this child does). Aggregating the semantic
// information into one node means that Talkback will recognize that it has
// something to say and focus it when it receives keyboard focus.
// (See https://github.com/flutter/flutter/issues/57038 for context).
config.isSemanticBoundary = true;
config.isSemanticBoundary = false;

config.isEnabled = isInteractive;
config.isSlider = true;
config.isFocusable = isInteractive;
config.isFocused = hasFocus;
switch (_platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
case TargetPlatform.linux:
case TargetPlatform.macOS:
break;
case TargetPlatform.windows:
config.onDidGainAccessibilityFocus = onDidGainAccessibilityFocus;
break;
}
config.textDirection = textDirection;
if (isInteractive) {
config.onIncrease = increaseAction;
Expand Down
Loading

0 comments on commit 5e71622

Please sign in to comment.