Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Unified Diff: sky/sdk/lib/rendering/box.dart

Issue 1233623007: Provide some debug-mode time hooks to visually debug painting and layout. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/lib/base/debug.dart ('k') | sky/sdk/lib/rendering/object.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/rendering/box.dart
diff --git a/sky/sdk/lib/rendering/box.dart b/sky/sdk/lib/rendering/box.dart
index fca4f7f0398b1ff7e705975d0ffc1c6a9c9cb84d..2c5a228658f6c7b7d46dfae72ea260c3f2c1df4b 100644
--- a/sky/sdk/lib/rendering/box.dart
+++ b/sky/sdk/lib/rendering/box.dart
@@ -301,29 +301,30 @@ abstract class RenderBox extends RenderObject {
// the first given baseline in the box's contents. This is used by
// certain layout models to align adjacent boxes on a common
// baseline, regardless of padding, font size differences, etc. If
- // there is no baseline, then it returns the distance from the
- // y-coordinate of the position of the box to the y-coordinate of
- // the bottom of the box, i.e., the height of the box. Only call
- // this after layout has been performed. You are only allowed to
- // call this from the parent of this node during that parent's
- // performLayout() or paint().
- double getDistanceToBaseline(TextBaseline baseline) {
+ // there is no baseline, and the 'onlyReal' argument was not set to
+ // true, then it returns the distance from the y-coordinate of the
+ // position of the box to the y-coordinate of the bottom of the box,
+ // i.e., the height of the box. Only call this after layout has been
+ // performed. You are only allowed to call this from the parent of
+ // this node during that parent's performLayout() or paint().
+ double getDistanceToBaseline(TextBaseline baseline, { bool onlyReal: false }) {
assert(!needsLayout);
assert(!_debugDoingBaseline);
final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer
assert(parent is RenderObject);
assert(() {
if (RenderObject.debugDoingLayout)
- return (parent == RenderObject.debugActiveLayout) && parent.debugDoingThisLayout;
+ return (RenderObject.debugActiveLayout == parent) && parent.debugDoingThisLayout;
if (RenderObject.debugDoingPaint)
- return (parent == RenderObject.debugActivePaint) && parent.debugDoingThisPaint;
+ return ((RenderObject.debugActivePaint == parent) && parent.debugDoingThisPaint) ||
+ ((RenderObject.debugActivePaint == this) && debugDoingThisPaint);
return false;
});
assert(_debugSetDoingBaseline(true));
double result = getDistanceToActualBaseline(baseline);
assert(_debugSetDoingBaseline(false));
assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer
- if (result == null)
+ if (result == null && !onlyReal)
return size.height;
return result;
}
@@ -434,6 +435,43 @@ abstract class RenderBox extends RenderObject {
}
Rect get paintBounds => Point.origin & size;
+ void debugPaint(PaintingCanvas canvas, Offset offset) {
+ if (debugPaintSizeEnabled)
+ debugPaintSize(canvas, offset);
+ if (debugPaintBaselinesEnabled)
+ debugPaintBaselines(canvas, offset);
+ }
+ void debugPaintSize(PaintingCanvas canvas, Offset offset) {
+ Paint paint = new Paint();
+ paint.setStyle(sky.PaintingStyle.stroke);
+ paint.strokeWidth = 1.0;
+ paint.color = debugPaintSizeColor;
+ canvas.drawRect(offset & size, paint);
+ }
+ void debugPaintBaselines(PaintingCanvas canvas, Offset offset) {
+ Paint paint = new Paint();
+ paint.setStyle(sky.PaintingStyle.stroke);
+ paint.strokeWidth = 0.25;
+ Path path;
+ // ideographic baseline
+ double baselineI = getDistanceToBaseline(TextBaseline.ideographic, onlyReal: true);
+ if (baselineI != null) {
+ paint.color = debugPaintIdeographicBaselineColor;
+ path = new Path();
+ path.moveTo(offset.dx, offset.dy + baselineI);
+ path.lineTo(offset.dx + size.width, offset.dy + baselineI);
+ canvas.drawPath(path, paint);
+ }
+ // alphabetic baseline
+ double baselineA = getDistanceToBaseline(TextBaseline.alphabetic, onlyReal: true);
+ if (baselineA != null) {
+ paint.color = debugPaintAlphabeticBaselineColor;
+ path = new Path();
+ path.moveTo(offset.dx, offset.dy + baselineA);
+ path.lineTo(offset.dx + size.width, offset.dy + baselineA);
+ canvas.drawPath(path, paint);
+ }
+ }
String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}size: ${size}\n';
}
« no previous file with comments | « sky/sdk/lib/base/debug.dart ('k') | sky/sdk/lib/rendering/object.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698