Commit 8c535ad7 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Update use of `@protected` (#4805)

Now that protected can be accessed from inside the same library, we can
use protected in a number of new places and we can remove some
trampolines we were using to work around its previous semantics.
parent e0f37027
...@@ -932,6 +932,7 @@ abstract class RenderBox extends RenderObject { ...@@ -932,6 +932,7 @@ abstract class RenderBox extends RenderObject {
/// This function must only be called from [getDistanceToBaseline] and /// This function must only be called from [getDistanceToBaseline] and
/// [computeDistanceToActualBaseline]. Do not call this function directly from /// [computeDistanceToActualBaseline]. Do not call this function directly from
/// outside those two methods. /// outside those two methods.
@protected
@mustCallSuper @mustCallSuper
double getDistanceToActualBaseline(TextBaseline baseline) { double getDistanceToActualBaseline(TextBaseline baseline) {
assert(_debugDoingBaseline); assert(_debugDoingBaseline);
......
...@@ -52,6 +52,7 @@ class AbstractNode { ...@@ -52,6 +52,7 @@ class AbstractNode {
int get depth => _depth; int get depth => _depth;
/// Call only from overrides of [redepthChildren] /// Call only from overrides of [redepthChildren]
@protected
void redepthChild(AbstractNode child) { void redepthChild(AbstractNode child) {
assert(child.owner == owner); assert(child.owner == owner);
if (child._depth <= _depth) { if (child._depth <= _depth) {
...@@ -97,6 +98,7 @@ class AbstractNode { ...@@ -97,6 +98,7 @@ class AbstractNode {
AbstractNode get parent => _parent; AbstractNode get parent => _parent;
/// Subclasses should call this function when they acquire a new child. /// Subclasses should call this function when they acquire a new child.
@protected
@mustCallSuper @mustCallSuper
void adoptChild(AbstractNode child) { void adoptChild(AbstractNode child) {
assert(child != null); assert(child != null);
...@@ -115,6 +117,7 @@ class AbstractNode { ...@@ -115,6 +117,7 @@ class AbstractNode {
} }
/// Subclasses should call this function when they lose a child. /// Subclasses should call this function when they lose a child.
@protected
@mustCallSuper @mustCallSuper
void dropChild(AbstractNode child) { void dropChild(AbstractNode child) {
assert(child != null); assert(child != null);
......
...@@ -30,6 +30,7 @@ export 'package:flutter/foundation.dart' show FlutterError, InformationCollector ...@@ -30,6 +30,7 @@ export 'package:flutter/foundation.dart' show FlutterError, InformationCollector
/// to other children. /// to other children.
class ParentData { class ParentData {
/// Called when the RenderObject is removed from the tree. /// Called when the RenderObject is removed from the tree.
@protected
@mustCallSuper @mustCallSuper
void detach() { } void detach() { }
...@@ -1139,7 +1140,6 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { ...@@ -1139,7 +1140,6 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
@override @override
PipelineOwner get owner => super.owner; PipelineOwner get owner => super.owner;
// Workaround for https://github.com/dart-lang/sdk/issues/25232
@override @override
void attach(PipelineOwner owner) { void attach(PipelineOwner owner) {
super.attach(owner); super.attach(owner);
......
...@@ -133,7 +133,7 @@ class ImageStream { ...@@ -133,7 +133,7 @@ class ImageStream {
} else { } else {
result.write('${_completer.runtimeType}; '); result.write('${_completer.runtimeType}; ');
final List<String> description = <String>[]; final List<String> description = <String>[];
_completer._debugFillDescription(description); _completer.debugFillDescription(description);
result.write(description.join('; ')); result.write(description.join('; '));
} }
result.write(')'); result.write(')');
...@@ -213,9 +213,6 @@ class ImageStreamCompleter { ...@@ -213,9 +213,6 @@ class ImageStreamCompleter {
description.add('$_current'); description.add('$_current');
description.add('${_listeners.length} listener${_listeners.length == 1 ? "" : "s" }'); description.add('${_listeners.length} listener${_listeners.length == 1 ? "" : "s" }');
} }
// TODO(ianh): remove once @protected allows in-file references
void _debugFillDescription(List<String> description) => debugFillDescription(description);
} }
/// Manages the loading of [ui.Image] objects for static [ImageStream]s (those /// Manages the loading of [ui.Image] objects for static [ImageStream]s (those
......
...@@ -368,6 +368,7 @@ abstract class Widget { ...@@ -368,6 +368,7 @@ abstract class Widget {
/// is placed in the tree, it is inflated into an [Element], which means a /// is placed in the tree, it is inflated into an [Element], which means a
/// widget that is incorporated into the tree multiple times will be inflated /// widget that is incorporated into the tree multiple times will be inflated
/// multiple times. /// multiple times.
@protected
Element createElement(); Element createElement();
/// A short, textual description of this widget. /// A short, textual description of this widget.
...@@ -394,13 +395,6 @@ abstract class Widget { ...@@ -394,13 +395,6 @@ abstract class Widget {
@mustCallSuper @mustCallSuper
void debugFillDescription(List<String> description) { } void debugFillDescription(List<String> description) { }
/// Lets [Element.debugFillDescription] call the @protected method
/// [debugFillDescription]. This pattern prevents other unwanted callers
/// outside this library.
void _debugFillDescription(List<String> description) {
debugFillDescription(description);
}
/// Whether the `newWidget` can be used to update an [Element] that currently /// Whether the `newWidget` can be used to update an [Element] that currently
/// has the `oldWidget` as its configuration. /// has the `oldWidget` as its configuration.
/// ///
...@@ -540,6 +534,7 @@ abstract class StatefulWidget extends Widget { ...@@ -540,6 +534,7 @@ abstract class StatefulWidget extends Widget {
/// later inserted into the tree again, the framework will call [createState] /// later inserted into the tree again, the framework will call [createState]
/// again to create a fresh [State] object, simplifying the lifecycle of /// again to create a fresh [State] object, simplifying the lifecycle of
/// [State] objects. /// [State] objects.
@protected
State createState(); State createState();
} }
...@@ -706,6 +701,7 @@ abstract class State<T extends StatefulWidget> { ...@@ -706,6 +701,7 @@ abstract class State<T extends StatefulWidget> {
/// ///
/// If you override this, make sure your method starts with a call to /// If you override this, make sure your method starts with a call to
/// super.initState(). /// super.initState().
@protected
@mustCallSuper @mustCallSuper
void initState() { void initState() {
assert(_debugLifecycleState == _StateLifecycle.created); assert(_debugLifecycleState == _StateLifecycle.created);
...@@ -729,6 +725,7 @@ abstract class State<T extends StatefulWidget> { ...@@ -729,6 +725,7 @@ abstract class State<T extends StatefulWidget> {
/// If you override this, make sure your method starts with a call to /// If you override this, make sure your method starts with a call to
/// super.didUpdateConfig(oldConfig). /// super.didUpdateConfig(oldConfig).
// TODO(abarth): Add @mustCallSuper. // TODO(abarth): Add @mustCallSuper.
@protected
void didUpdateConfig(T oldConfig) { } void didUpdateConfig(T oldConfig) { }
/// Notify the framework that the internal state of this object has changed. /// Notify the framework that the internal state of this object has changed.
...@@ -813,6 +810,7 @@ abstract class State<T extends StatefulWidget> { ...@@ -813,6 +810,7 @@ abstract class State<T extends StatefulWidget> {
/// ///
/// If you override this, make sure to end your method with a call to /// If you override this, make sure to end your method with a call to
/// super.deactivate(). /// super.deactivate().
@protected
@mustCallSuper @mustCallSuper
void deactivate() { } void deactivate() { }
...@@ -829,6 +827,7 @@ abstract class State<T extends StatefulWidget> { ...@@ -829,6 +827,7 @@ abstract class State<T extends StatefulWidget> {
/// ///
/// If you override this, make sure to end your method with a call to /// If you override this, make sure to end your method with a call to
/// super.dispose(). /// super.dispose().
@protected
@mustCallSuper @mustCallSuper
void dispose() { void dispose() {
assert(_debugLifecycleState == _StateLifecycle.ready); assert(_debugLifecycleState == _StateLifecycle.ready);
...@@ -878,6 +877,7 @@ abstract class State<T extends StatefulWidget> { ...@@ -878,6 +877,7 @@ abstract class State<T extends StatefulWidget> {
/// this method because they need to do some expensive work (e.g., network /// this method because they need to do some expensive work (e.g., network
/// fetches) when their dependencies change, and that work would be too /// fetches) when their dependencies change, and that work would be too
/// expensive to do for every build. /// expensive to do for every build.
@protected
@mustCallSuper @mustCallSuper
void dependenciesChanged() { } void dependenciesChanged() { }
...@@ -965,6 +965,7 @@ abstract class ParentDataWidget<T extends RenderObjectWidget> extends _ProxyWidg ...@@ -965,6 +965,7 @@ abstract class ParentDataWidget<T extends RenderObjectWidget> extends _ProxyWidg
return result; return result;
} }
@protected
void applyParentData(RenderObject renderObject); void applyParentData(RenderObject renderObject);
} }
...@@ -975,6 +976,7 @@ abstract class InheritedWidget extends _ProxyWidget { ...@@ -975,6 +976,7 @@ abstract class InheritedWidget extends _ProxyWidget {
@override @override
InheritedElement createElement() => new InheritedElement(this); InheritedElement createElement() => new InheritedElement(this);
@protected
bool updateShouldNotify(InheritedWidget oldWidget); bool updateShouldNotify(InheritedWidget oldWidget);
} }
...@@ -991,13 +993,16 @@ abstract class RenderObjectWidget extends Widget { ...@@ -991,13 +993,16 @@ abstract class RenderObjectWidget extends Widget {
/// Creates an instance of the [RenderObject] class that this /// Creates an instance of the [RenderObject] class that this
/// [RenderObjectWidget] represents, using the configuration described by this /// [RenderObjectWidget] represents, using the configuration described by this
/// [RenderObjectWidget]. /// [RenderObjectWidget].
@protected
RenderObject createRenderObject(BuildContext context); RenderObject createRenderObject(BuildContext context);
/// Copies the configuration described by this [RenderObjectWidget] to the /// Copies the configuration described by this [RenderObjectWidget] to the
/// given [RenderObject], which will be of the same type as returned by this /// given [RenderObject], which will be of the same type as returned by this
/// object's [createRenderObject]. /// object's [createRenderObject].
@protected
void updateRenderObject(BuildContext context, RenderObject renderObject) { } void updateRenderObject(BuildContext context, RenderObject renderObject) { }
@protected
void didUnmountRenderObject(RenderObject renderObject) { } void didUnmountRenderObject(RenderObject renderObject) { }
} }
...@@ -1730,7 +1735,7 @@ abstract class Element implements BuildContext { ...@@ -1730,7 +1735,7 @@ abstract class Element implements BuildContext {
} else { } else {
if (widget.key != null) if (widget.key != null)
description.add('${widget.key}'); description.add('${widget.key}');
widget._debugFillDescription(description); widget.debugFillDescription(description);
} }
} }
...@@ -2212,7 +2217,7 @@ class ParentDataElement<T extends RenderObjectWidget> extends _ProxyElement { ...@@ -2212,7 +2217,7 @@ class ParentDataElement<T extends RenderObjectWidget> extends _ProxyElement {
void notifyClients(ParentDataWidget<T> oldWidget) { void notifyClients(ParentDataWidget<T> oldWidget) {
void notifyChildren(Element child) { void notifyChildren(Element child) {
if (child is RenderObjectElement) { if (child is RenderObjectElement) {
child.updateParentData(widget); child._updateParentData(widget);
} else { } else {
assert(child is! ParentDataElement<RenderObjectWidget>); assert(child is! ParentDataElement<RenderObjectWidget>);
child.visitChildren(notifyChildren); child.visitChildren(notifyChildren);
...@@ -2514,7 +2519,7 @@ abstract class RenderObjectElement extends BuildableElement { ...@@ -2514,7 +2519,7 @@ abstract class RenderObjectElement extends BuildableElement {
widget.didUnmountRenderObject(renderObject); widget.didUnmountRenderObject(renderObject);
} }
void updateParentData(ParentDataWidget<RenderObjectWidget> parentData) { void _updateParentData(ParentDataWidget<RenderObjectWidget> parentData) {
parentData.applyParentData(renderObject); parentData.applyParentData(renderObject);
} }
...@@ -2534,7 +2539,7 @@ abstract class RenderObjectElement extends BuildableElement { ...@@ -2534,7 +2539,7 @@ abstract class RenderObjectElement extends BuildableElement {
_ancestorRenderObjectElement?.insertChildRenderObject(renderObject, newSlot); _ancestorRenderObjectElement?.insertChildRenderObject(renderObject, newSlot);
ParentDataElement<RenderObjectWidget> parentDataElement = _findAncestorParentDataElement(); ParentDataElement<RenderObjectWidget> parentDataElement = _findAncestorParentDataElement();
if (parentDataElement != null) if (parentDataElement != null)
updateParentData(parentDataElement.widget); _updateParentData(parentDataElement.widget);
} }
@override @override
......
...@@ -393,7 +393,8 @@ class RawGestureDetectorState extends State<RawGestureDetector> { ...@@ -393,7 +393,8 @@ class RawGestureDetectorState extends State<RawGestureDetector> {
if (!config.excludeFromSemantics) { if (!config.excludeFromSemantics) {
RenderSemanticsGestureHandler semanticsGestureHandler = context.findRenderObject(); RenderSemanticsGestureHandler semanticsGestureHandler = context.findRenderObject();
context.visitChildElements((RenderObjectElement element) { context.visitChildElements((RenderObjectElement element) {
element.widget.updateRenderObject(context, semanticsGestureHandler); _GestureSemantics widget = element.widget;
widget._updateHandlers(semanticsGestureHandler, _recognizers);
}); });
} }
} }
...@@ -558,9 +559,7 @@ class _GestureSemantics extends SingleChildRenderObjectWidget { ...@@ -558,9 +559,7 @@ class _GestureSemantics extends SingleChildRenderObjectWidget {
return result; return result;
} }
@override void _updateHandlers(RenderSemanticsGestureHandler renderObject, Map<Type, GestureRecognizer> recognizers) {
void updateRenderObject(BuildContext context, RenderSemanticsGestureHandler renderObject) {
Map<Type, GestureRecognizer> recognizers = owner._recognizers;
renderObject renderObject
..onTap = recognizers.containsKey(TapGestureRecognizer) ? _handleTap : null ..onTap = recognizers.containsKey(TapGestureRecognizer) ? _handleTap : null
..onLongPress = recognizers.containsKey(LongPressGestureRecognizer) ? _handleLongPress : null ..onLongPress = recognizers.containsKey(LongPressGestureRecognizer) ? _handleLongPress : null
...@@ -569,4 +568,9 @@ class _GestureSemantics extends SingleChildRenderObjectWidget { ...@@ -569,4 +568,9 @@ class _GestureSemantics extends SingleChildRenderObjectWidget {
..onVerticalDragUpdate = recognizers.containsKey(VerticalDragGestureRecognizer) || ..onVerticalDragUpdate = recognizers.containsKey(VerticalDragGestureRecognizer) ||
recognizers.containsKey(PanGestureRecognizer) ? _handleVerticalDragUpdate : null; recognizers.containsKey(PanGestureRecognizer) ? _handleVerticalDragUpdate : null;
} }
@override
void updateRenderObject(BuildContext context, RenderSemanticsGestureHandler renderObject) {
_updateHandlers(renderObject, owner._recognizers);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment