Commit 76772608 authored by Adam Barth's avatar Adam Barth

Remove OverlayPainter mechanism (#4264)

We used to use this mechanism to paint scrollbars, but it's awkward. The
new approach to scrollbars is much cleaner. This mechanism has no other
clients, so we should remove it.
parent 7c47837c
......@@ -401,12 +401,10 @@ class RenderGrid extends RenderVirtualViewport<GridParentData> {
int virtualChildBase: 0,
int virtualChildCount,
Offset paintOffset: Offset.zero,
RenderObjectPainter overlayPainter,
LayoutCallback callback
}) : _delegate = delegate, _virtualChildBase = virtualChildBase, super(
virtualChildCount: virtualChildCount,
paintOffset: paintOffset,
overlayPainter: overlayPainter,
callback: callback
) {
assert(delegate != null);
......
......@@ -33,7 +33,6 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
Offset paintOffset: Offset.zero,
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
RenderObjectPainter overlayPainter,
LayoutCallback callback
}) : _itemExtent = itemExtent,
_padding = padding,
......@@ -42,7 +41,6 @@ class RenderList extends RenderVirtualViewport<ListParentData> {
paintOffset: paintOffset,
mainAxis: mainAxis,
anchor: anchor,
overlayPainter: overlayPainter,
callback: callback
) {
addAll(children);
......
......@@ -397,28 +397,6 @@ class PaintingContext {
}
}
/// An encapsulation of a renderer and a paint() method.
///
/// A renderer may allow its paint() method to be augmented or redefined by
/// providing a Painter. See for example overlayPainter in BlockViewport.
abstract class RenderObjectPainter {
RenderObject get renderObject => _renderObject;
RenderObject _renderObject;
void attach(RenderObject renderObject) {
assert(_renderObject == null);
assert(renderObject != null);
_renderObject = renderObject;
}
void detach() {
assert(_renderObject != null);
_renderObject = null;
}
void paint(PaintingContext context, Offset offset);
}
/// An abstract set of layout constraints.
///
/// Concrete layout models (such as box) will create concrete subclasses to
......
......@@ -85,12 +85,10 @@ class RenderViewportBase extends RenderBox {
RenderViewportBase(
Offset paintOffset,
Axis mainAxis,
ViewportAnchor anchor,
RenderObjectPainter overlayPainter
ViewportAnchor anchor
) : _paintOffset = paintOffset,
_mainAxis = mainAxis,
_anchor = anchor,
_overlayPainter = overlayPainter {
_anchor = anchor {
assert(paintOffset != null);
assert(mainAxis != null);
assert(_offsetIsSane(_paintOffset, mainAxis));
......@@ -150,31 +148,6 @@ class RenderViewportBase extends RenderBox {
markNeedsSemanticsUpdate();
}
RenderObjectPainter get overlayPainter => _overlayPainter;
RenderObjectPainter _overlayPainter;
set overlayPainter(RenderObjectPainter value) {
if (_overlayPainter == value)
return;
if (attached)
_overlayPainter?.detach();
_overlayPainter = value;
if (attached)
_overlayPainter?.attach(this);
markNeedsPaint();
}
@override
void attach(PipelineOwner owner) {
super.attach(owner);
_overlayPainter?.attach(this);
}
@override
void detach() {
super.detach();
_overlayPainter?.detach();
}
ViewportDimensions get dimensions => _dimensions;
ViewportDimensions _dimensions = ViewportDimensions.zero;
set dimensions(ViewportDimensions value) {
......@@ -204,8 +177,6 @@ class RenderViewportBase extends RenderBox {
description.add('paintOffset: $paintOffset');
description.add('mainAxis: $mainAxis');
description.add('anchor: $anchor');
if (overlayPainter != null)
description.add('overlay painter: $overlayPainter');
}
}
......@@ -224,9 +195,8 @@ class RenderViewport extends RenderViewportBase with RenderObjectWithChildMixin<
Offset paintOffset: Offset.zero,
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
RenderObjectPainter overlayPainter,
this.onPaintOffsetUpdateNeeded
}) : super(paintOffset, mainAxis, anchor, overlayPainter) {
}) : super(paintOffset, mainAxis, anchor) {
this.child = child;
}
......@@ -314,7 +284,6 @@ class RenderViewport extends RenderViewportBase with RenderObjectWithChildMixin<
void paintContents(PaintingContext context, Offset offset) {
context.paintChild(child, offset + effectivePaintOffset);
_overlayPainter?.paint(context, offset);
}
if (_shouldClipAtPaintOffset(effectivePaintOffset)) {
......@@ -357,11 +326,10 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende
LayoutCallback callback,
Offset paintOffset: Offset.zero,
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
RenderObjectPainter overlayPainter
ViewportAnchor anchor: ViewportAnchor.start
}) : _virtualChildCount = virtualChildCount,
_callback = callback,
super(paintOffset, mainAxis, anchor, overlayPainter);
super(paintOffset, mainAxis, anchor);
int get virtualChildCount => _virtualChildCount;
int _virtualChildCount;
......@@ -392,7 +360,6 @@ abstract class RenderVirtualViewport<T extends ContainerBoxParentDataMixin<Rende
void _paintContents(PaintingContext context, Offset offset) {
defaultPaint(context, offset + _effectivePaintOffset);
_overlayPainter?.paint(context, offset);
}
@override
......
......@@ -42,7 +42,6 @@ export 'package:flutter/rendering.dart' show
PointerUpEvent,
PointerUpEventListener,
RelativeRect,
RenderObjectPainter,
ShaderCallback,
SingleChildLayoutDelegate,
TextOverflow,
......@@ -1147,7 +1146,6 @@ class Viewport extends SingleChildRenderObjectWidget {
this.paintOffset: Offset.zero,
this.mainAxis: Axis.vertical,
this.anchor: ViewportAnchor.start,
this.overlayPainter,
this.onPaintOffsetUpdateNeeded,
Widget child
}) : super(key: key, child: child) {
......@@ -1169,11 +1167,6 @@ class Viewport extends SingleChildRenderObjectWidget {
final ViewportAnchor anchor;
/// Paints an overlay over the viewport.
///
/// Often used to paint scroll bars.
final RenderObjectPainter overlayPainter;
/// Called when the interior or exterior dimensions of the viewport change.
final ViewportDimensionsChangeCallback onPaintOffsetUpdateNeeded;
......@@ -1183,8 +1176,7 @@ class Viewport extends SingleChildRenderObjectWidget {
paintOffset: paintOffset,
mainAxis: mainAxis,
anchor: anchor,
onPaintOffsetUpdateNeeded: onPaintOffsetUpdateNeeded,
overlayPainter: overlayPainter
onPaintOffsetUpdateNeeded: onPaintOffsetUpdateNeeded
);
}
......@@ -1195,8 +1187,7 @@ class Viewport extends SingleChildRenderObjectWidget {
..mainAxis = mainAxis
..anchor = anchor
..paintOffset = paintOffset
..onPaintOffsetUpdateNeeded = onPaintOffsetUpdateNeeded
..overlayPainter = overlayPainter;
..onPaintOffsetUpdateNeeded = onPaintOffsetUpdateNeeded;
}
}
......
......@@ -318,8 +318,7 @@ class _VirtualPageViewport extends VirtualViewport {
this.startOffset,
this.mainAxis,
this.anchor,
this.itemsWrap,
this.overlayPainter
this.itemsWrap
) {
assert(mainAxis != null);
}
......@@ -330,7 +329,6 @@ class _VirtualPageViewport extends VirtualViewport {
final Axis mainAxis;
final ViewportAnchor anchor;
final bool itemsWrap;
final RenderObjectPainter overlayPainter;
@override
RenderList createRenderObject(BuildContext context) => new RenderList();
......@@ -374,8 +372,7 @@ class _VirtualPageViewportElement extends VirtualViewportElement {
@override
void updateRenderObject(_VirtualPageViewport oldWidget) {
renderObject
..mainAxis = widget.mainAxis
..overlayPainter = widget.overlayPainter;
..mainAxis = widget.mainAxis;
super.updateRenderObject(oldWidget);
}
......@@ -442,14 +439,12 @@ class PageViewport extends _VirtualPageViewport with VirtualViewportFromIterable
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
bool itemsWrap: false,
RenderObjectPainter overlayPainter,
this.children
}) : super(
startOffset,
mainAxis,
anchor,
itemsWrap,
overlayPainter
itemsWrap
);
@override
......@@ -461,15 +456,13 @@ class LazyPageViewport extends _VirtualPageViewport with VirtualViewportFromBuil
double startOffset: 0.0,
Axis mainAxis: Axis.vertical,
ViewportAnchor anchor: ViewportAnchor.start,
RenderObjectPainter overlayPainter,
this.itemCount,
this.itemBuilder
}) : super(
startOffset,
mainAxis,
anchor,
false, // Don't support wrapping yet.
overlayPainter
false // Don't support wrapping yet.
);
@override
......
......@@ -155,8 +155,7 @@ class _VirtualListViewport extends VirtualViewport {
this.anchor,
this.itemExtent,
this.itemsWrap,
this.padding,
this.overlayPainter
this.padding
) {
assert(mainAxis != null);
assert(itemExtent != null);
......@@ -169,7 +168,6 @@ class _VirtualListViewport extends VirtualViewport {
final double itemExtent;
final bool itemsWrap;
final EdgeInsets padding;
final RenderObjectPainter overlayPainter;
double get _leadingPadding {
switch (mainAxis) {
......@@ -237,8 +235,7 @@ class _VirtualListViewportElement extends VirtualViewportElement {
..mainAxis = widget.mainAxis
..anchor = widget.anchor
..itemExtent = widget.itemExtent
..padding = widget.padding
..overlayPainter = widget.overlayPainter;
..padding = widget.padding;
super.updateRenderObject(oldWidget);
}
......@@ -320,7 +317,6 @@ class ListViewport extends _VirtualListViewport with VirtualViewportFromIterable
double itemExtent,
bool itemsWrap: false,
EdgeInsets padding,
RenderObjectPainter overlayPainter,
this.children
}) : super(
onExtentsChanged,
......@@ -329,8 +325,7 @@ class ListViewport extends _VirtualListViewport with VirtualViewportFromIterable
anchor,
itemExtent,
itemsWrap,
padding,
overlayPainter
padding
);
@override
......@@ -486,7 +481,6 @@ class LazyListViewport extends _VirtualListViewport with VirtualViewportFromBuil
ViewportAnchor anchor: ViewportAnchor.start,
double itemExtent,
EdgeInsets padding,
RenderObjectPainter overlayPainter,
this.itemCount,
this.itemBuilder
}) : super(
......@@ -496,8 +490,7 @@ class LazyListViewport extends _VirtualListViewport with VirtualViewportFromBuil
anchor,
itemExtent,
false, // Don't support wrapping yet.
padding,
overlayPainter
padding
);
@override
......
// Copyright 2015 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 'package:flutter/rendering.dart';
import 'package:test/test.dart';
import 'rendering_tester.dart';
class TestBlockPainter extends RenderObjectPainter {
@override
void paint(PaintingContext context, Offset offset) { }
}
void main() {
test('overlay painters can attach and detach', () {
TestBlockPainter first = new TestBlockPainter();
TestBlockPainter second = new TestBlockPainter();
RenderList list = new RenderList(overlayPainter: first);
// The first painter isn't attached because we haven't attached block.
expect(first.renderObject, isNull);
expect(second.renderObject, isNull);
list.overlayPainter = second;
expect(first.renderObject, isNull);
expect(second.renderObject, isNull);
layout(list);
expect(first.renderObject, isNull);
expect(second.renderObject, equals(list));
list.overlayPainter = first;
expect(first.renderObject, equals(list));
expect(second.renderObject, isNull);
});
}
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