Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Rename _*Marker classes to be _*Scope, for consistency (#118070)
Browse files Browse the repository at this point in the history
* Rename _*Marker classes to be _*Scope, for consistency

* [EMPTY] Commit to refresh the tree that is currently red (#118062)

* Fix remaining tests

Co-authored-by: Drew Roen <102626803+drewroengoogle@users.noreply.github.com>
  • Loading branch information
gspencergoog and drewroengoogle committed Jan 17, 2023
1 parent a3629a2 commit ae7b99e
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 67 deletions.
12 changes: 6 additions & 6 deletions packages/flutter/lib/src/material/menu_anchor.dart
Expand Up @@ -362,7 +362,7 @@ class _MenuAnchorState extends State<MenuAnchor> {
);
}

return _MenuAnchorMarker(
return _MenuAnchorScope(
anchorKey: _anchorKey,
anchor: this,
isOpen: _isOpen,
Expand Down Expand Up @@ -511,7 +511,7 @@ class _MenuAnchorState extends State<MenuAnchor> {
// Copy all the themes from the supplied outer context to the
// overlay.
outerContext,
_MenuAnchorMarker(
_MenuAnchorScope(
// Re-advertize the anchor here in the overlay, since
// otherwise a search for the anchor by descendants won't find
// it.
Expand Down Expand Up @@ -571,7 +571,7 @@ class _MenuAnchorState extends State<MenuAnchor> {
// dependency relationship that will rebuild the context when the node
// changes.
static _MenuAnchorState? _maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<_MenuAnchorMarker>()?.anchor;
return context.dependOnInheritedWidgetOfExactType<_MenuAnchorScope>()?.anchor;
}
}

Expand Down Expand Up @@ -2195,8 +2195,8 @@ class _LocalizedShortcutLabeler {
}
}

class _MenuAnchorMarker extends InheritedWidget {
const _MenuAnchorMarker({
class _MenuAnchorScope extends InheritedWidget {
const _MenuAnchorScope({
required super.child,
required this.anchorKey,
required this.anchor,
Expand All @@ -2208,7 +2208,7 @@ class _MenuAnchorMarker extends InheritedWidget {
final bool isOpen;

@override
bool updateShouldNotify(_MenuAnchorMarker oldWidget) {
bool updateShouldNotify(_MenuAnchorScope oldWidget) {
return anchorKey != oldWidget.anchorKey
|| anchor != oldWidget.anchor
|| isOpen != oldWidget.isOpen;
Expand Down
28 changes: 14 additions & 14 deletions packages/flutter/lib/src/widgets/actions.dart
Expand Up @@ -681,7 +681,7 @@ class Actions extends StatefulWidget {
// getElementForInheritedWidgetOfExactType. Returns true if the visitor found
// what it was looking for.
static bool _visitActionsAncestors(BuildContext context, bool Function(InheritedElement element) visitor) {
InheritedElement? actionsElement = context.getElementForInheritedWidgetOfExactType<_ActionsMarker>();
InheritedElement? actionsElement = context.getElementForInheritedWidgetOfExactType<_ActionsScope>();
while (actionsElement != null) {
if (visitor(actionsElement) == true) {
break;
Expand All @@ -690,7 +690,7 @@ class Actions extends StatefulWidget {
// context.getElementForInheritedWidgetOfExactType will return itself if it
// happens to be of the correct type.
final BuildContext parent = _getParent(actionsElement);
actionsElement = parent.getElementForInheritedWidgetOfExactType<_ActionsMarker>();
actionsElement = parent.getElementForInheritedWidgetOfExactType<_ActionsScope>();
}
return actionsElement != null;
}
Expand All @@ -700,7 +700,7 @@ class Actions extends StatefulWidget {
static ActionDispatcher _findDispatcher(BuildContext context) {
ActionDispatcher? dispatcher;
_visitActionsAncestors(context, (InheritedElement element) {
final ActionDispatcher? found = (element.widget as _ActionsMarker).dispatcher;
final ActionDispatcher? found = (element.widget as _ActionsScope).dispatcher;
if (found != null) {
dispatcher = found;
return true;
Expand Down Expand Up @@ -807,7 +807,7 @@ class Actions extends StatefulWidget {
);

_visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null) {
context.dependOnInheritedElement(element);
Expand Down Expand Up @@ -836,7 +836,7 @@ class Actions extends StatefulWidget {
);

_visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null) {
action = result;
Expand All @@ -849,8 +849,8 @@ class Actions extends StatefulWidget {
}

// Find the [Action] that handles the given `intent` in the given
// `_ActionsMarker`, and verify it has the right type parameter.
static Action<T>? _castAction<T extends Intent>(_ActionsMarker actionsMarker, { T? intent }) {
// `_ActionsScope`, and verify it has the right type parameter.
static Action<T>? _castAction<T extends Intent>(_ActionsScope actionsMarker, { T? intent }) {
final Action<Intent>? mappedAction = actionsMarker.actions[intent?.runtimeType ?? T];
if (mappedAction is Action<T>?) {
return mappedAction;
Expand All @@ -870,7 +870,7 @@ class Actions extends StatefulWidget {
/// widget is found.
static ActionDispatcher of(BuildContext context) {
assert(context != null);
final _ActionsMarker? marker = context.dependOnInheritedWidgetOfExactType<_ActionsMarker>();
final _ActionsScope? marker = context.dependOnInheritedWidgetOfExactType<_ActionsScope>();
return marker?.dispatcher ?? _findDispatcher(context);
}

Expand All @@ -897,7 +897,7 @@ class Actions extends StatefulWidget {
Object? returnValue;

final bool actionFound = _visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null && result.isEnabled(intent)) {
// Invoke the action we found using the relevant dispatcher from the Actions
Expand Down Expand Up @@ -950,7 +950,7 @@ class Actions extends StatefulWidget {
Object? returnValue;

_visitActionsAncestors(context, (InheritedElement element) {
final _ActionsMarker actions = element.widget as _ActionsMarker;
final _ActionsScope actions = element.widget as _ActionsScope;
final Action<T>? result = _castAction(actions, intent: intent);
if (result != null && result.isEnabled(intent)) {
// Invoke the action we found using the relevant dispatcher from the Actions
Expand Down Expand Up @@ -1024,7 +1024,7 @@ class _ActionsState extends State<Actions> {

@override
Widget build(BuildContext context) {
return _ActionsMarker(
return _ActionsScope(
actions: widget.actions,
dispatcher: widget.dispatcher,
rebuildKey: rebuildKey,
Expand All @@ -1035,8 +1035,8 @@ class _ActionsState extends State<Actions> {

// An inherited widget used by Actions widget for fast lookup of the Actions
// widget information.
class _ActionsMarker extends InheritedWidget {
const _ActionsMarker({
class _ActionsScope extends InheritedWidget {
const _ActionsScope({
required this.dispatcher,
required this.actions,
required this.rebuildKey,
Expand All @@ -1049,7 +1049,7 @@ class _ActionsMarker extends InheritedWidget {
final Object rebuildKey;

@override
bool updateShouldNotify(_ActionsMarker oldWidget) {
bool updateShouldNotify(_ActionsScope oldWidget) {
return rebuildKey != oldWidget.rebuildKey
|| oldWidget.dispatcher != dispatcher
|| !mapEquals<Type, Action<Intent>>(oldWidget.actions, actions);
Expand Down
16 changes: 8 additions & 8 deletions packages/flutter/lib/src/widgets/focus_scope.dart
Expand Up @@ -388,7 +388,7 @@ class Focus extends StatefulWidget {
static FocusNode of(BuildContext context, { bool scopeOk = false }) {
assert(context != null);
assert(scopeOk != null);
final _FocusMarker? marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
final _FocusInheritedScope? marker = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>();
final FocusNode? node = marker?.notifier;
assert(() {
if (node == null) {
Expand Down Expand Up @@ -440,7 +440,7 @@ class Focus extends StatefulWidget {
static FocusNode? maybeOf(BuildContext context, { bool scopeOk = false }) {
assert(context != null);
assert(scopeOk != null);
final _FocusMarker? marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
final _FocusInheritedScope? marker = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>();
final FocusNode? node = marker?.notifier;
if (node == null) {
return null;
Expand Down Expand Up @@ -686,7 +686,7 @@ class _FocusState extends State<Focus> {
child: widget.child,
);
}
return _FocusMarker(
return _FocusInheritedScope(
node: focusNode,
child: child,
);
Expand Down Expand Up @@ -798,7 +798,7 @@ class FocusScope extends Focus {
/// The [context] argument must not be null.
static FocusScopeNode of(BuildContext context) {
assert(context != null);
final _FocusMarker? marker = context.dependOnInheritedWidgetOfExactType<_FocusMarker>();
final _FocusInheritedScope? marker = context.dependOnInheritedWidgetOfExactType<_FocusInheritedScope>();
return marker?.notifier?.nearestScope ?? context.owner!.focusManager.rootScope;
}

Expand Down Expand Up @@ -853,17 +853,17 @@ class _FocusScopeState extends _FocusState {
_focusAttachment!.reparent(parent: widget.parentNode);
return Semantics(
explicitChildNodes: true,
child: _FocusMarker(
child: _FocusInheritedScope(
node: focusNode,
child: widget.child,
),
);
}
}

// The InheritedWidget marker for Focus and FocusScope.
class _FocusMarker extends InheritedNotifier<FocusNode> {
const _FocusMarker({
// The InheritedWidget for Focus and FocusScope.
class _FocusInheritedScope extends InheritedNotifier<FocusNode> {
const _FocusInheritedScope({
required FocusNode node,
required super.child,
}) : assert(node != null),
Expand Down
22 changes: 11 additions & 11 deletions packages/flutter/lib/src/widgets/focus_traversal.dart
Expand Up @@ -47,7 +47,7 @@ void _focusAndEnsureVisible(
// sorting their contents.
class _FocusTraversalGroupInfo {
_FocusTraversalGroupInfo(
_FocusTraversalGroupMarker? marker, {
_FocusTraversalGroupScope? marker, {
FocusTraversalPolicy? defaultPolicy,
List<FocusNode>? members,
}) : groupNode = marker?.focusNode,
Expand Down Expand Up @@ -319,20 +319,20 @@ abstract class FocusTraversalPolicy with Diagnosticable {
@protected
Iterable<FocusNode> sortDescendants(Iterable<FocusNode> descendants, FocusNode currentNode);

_FocusTraversalGroupMarker? _getMarker(BuildContext? context) {
return context?.getElementForInheritedWidgetOfExactType<_FocusTraversalGroupMarker>()?.widget as _FocusTraversalGroupMarker?;
_FocusTraversalGroupScope? _getMarker(BuildContext? context) {
return context?.getElementForInheritedWidgetOfExactType<_FocusTraversalGroupScope>()?.widget as _FocusTraversalGroupScope?;
}

// Sort all descendants, taking into account the FocusTraversalGroup
// that they are each in, and filtering out non-traversable/focusable nodes.
List<FocusNode> _sortAllDescendants(FocusScopeNode scope, FocusNode currentNode) {
assert(scope != null);
final _FocusTraversalGroupMarker? scopeGroupMarker = _getMarker(scope.context);
final _FocusTraversalGroupScope? scopeGroupMarker = _getMarker(scope.context);
final FocusTraversalPolicy defaultPolicy = scopeGroupMarker?.policy ?? ReadingOrderTraversalPolicy();
// Build the sorting data structure, separating descendants into groups.
final Map<FocusNode?, _FocusTraversalGroupInfo> groups = <FocusNode?, _FocusTraversalGroupInfo>{};
for (final FocusNode node in scope.descendants) {
final _FocusTraversalGroupMarker? groupMarker = _getMarker(node.context);
final _FocusTraversalGroupScope? groupMarker = _getMarker(node.context);
final FocusNode? groupNode = groupMarker?.focusNode;
// Group nodes need to be added to their parent's node, or to the "null"
// node if no parent is found. This creates the hierarchy of group nodes
Expand All @@ -344,7 +344,7 @@ abstract class FocusTraversalPolicy with Diagnosticable {
// looking with that node's parent, since _getMarker will return the
// context it was called on if it matches the type.
final BuildContext? parentContext = _getAncestor(groupNode!.context!, count: 2);
final _FocusTraversalGroupMarker? parentMarker = _getMarker(parentContext);
final _FocusTraversalGroupScope? parentMarker = _getMarker(parentContext);
final FocusNode? parentNode = parentMarker?.focusNode;
groups[parentNode] ??= _FocusTraversalGroupInfo(parentMarker, members: <FocusNode>[], defaultPolicy: defaultPolicy);
assert(!groups[parentNode]!.members.contains(node));
Expand Down Expand Up @@ -1586,7 +1586,7 @@ class FocusTraversalGroup extends StatefulWidget {
/// [FocusTraversalGroup] ancestor is found.
static FocusTraversalPolicy of(BuildContext context) {
assert(context != null);
final _FocusTraversalGroupMarker? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupMarker>();
final _FocusTraversalGroupScope? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupScope>();
assert(() {
if (inherited == null) {
throw FlutterError(
Expand Down Expand Up @@ -1621,7 +1621,7 @@ class FocusTraversalGroup extends StatefulWidget {
/// ancestor is found.
static FocusTraversalPolicy? maybeOf(BuildContext context) {
assert(context != null);
final _FocusTraversalGroupMarker? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupMarker>();
final _FocusTraversalGroupScope? inherited = context.dependOnInheritedWidgetOfExactType<_FocusTraversalGroupScope>();
return inherited?.policy;
}

Expand Down Expand Up @@ -1659,7 +1659,7 @@ class _FocusTraversalGroupState extends State<FocusTraversalGroup> {

@override
Widget build(BuildContext context) {
return _FocusTraversalGroupMarker(
return _FocusTraversalGroupScope(
policy: widget.policy,
focusNode: focusNode,
child: Focus(
Expand All @@ -1676,8 +1676,8 @@ class _FocusTraversalGroupState extends State<FocusTraversalGroup> {
}

// A "marker" inherited widget to make the group faster to find.
class _FocusTraversalGroupMarker extends InheritedWidget {
const _FocusTraversalGroupMarker({
class _FocusTraversalGroupScope extends InheritedWidget {
const _FocusTraversalGroupScope({
required this.policy,
required this.focusNode,
required super.child,
Expand Down
16 changes: 8 additions & 8 deletions packages/flutter/lib/src/widgets/shortcuts.dart
Expand Up @@ -1277,8 +1277,8 @@ class ShortcutRegistry with ChangeNotifier {
/// it doesn't find a [ShortcutRegistrar] ancestor.
static ShortcutRegistry of(BuildContext context) {
assert(context != null);
final _ShortcutRegistrarMarker? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarMarker>();
final _ShortcutRegistrarScope? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarScope>();
assert(() {
if (inherited == null) {
throw FlutterError(
Expand Down Expand Up @@ -1313,8 +1313,8 @@ class ShortcutRegistry with ChangeNotifier {
/// [ShortcutRegistrar] ancestor.
static ShortcutRegistry? maybeOf(BuildContext context) {
assert(context != null);
final _ShortcutRegistrarMarker? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarMarker>();
final _ShortcutRegistrarScope? inherited =
context.dependOnInheritedWidgetOfExactType<_ShortcutRegistrarScope>();
return inherited?.registry;
}

Expand Down Expand Up @@ -1431,7 +1431,7 @@ class _ShortcutRegistrarState extends State<ShortcutRegistrar> {

@override
Widget build(BuildContext context) {
return _ShortcutRegistrarMarker(
return _ShortcutRegistrarScope(
registry: registry,
child: Shortcuts.manager(
manager: manager,
Expand All @@ -1441,16 +1441,16 @@ class _ShortcutRegistrarState extends State<ShortcutRegistrar> {
}
}

class _ShortcutRegistrarMarker extends InheritedWidget {
const _ShortcutRegistrarMarker({
class _ShortcutRegistrarScope extends InheritedWidget {
const _ShortcutRegistrarScope({
required this.registry,
required super.child,
});

final ShortcutRegistry registry;

@override
bool updateShouldNotify(covariant _ShortcutRegistrarMarker oldWidget) {
bool updateShouldNotify(covariant _ShortcutRegistrarScope oldWidget) {
return registry != oldWidget.registry;
}
}

0 comments on commit ae7b99e

Please sign in to comment.