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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:math' as math; 5 import 'dart:math' as math;
6 import 'dart:sky' as sky; 6 import 'dart:sky' as sky;
7 7
8 import 'package:sky/base/debug.dart'; 8 import 'package:sky/base/debug.dart';
9 import 'package:sky/painting/box_painter.dart'; 9 import 'package:sky/painting/box_painter.dart';
10 import 'package:sky/rendering/object.dart'; 10 import 'package:sky/rendering/object.dart';
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 static bool _debugDoingBaseline = false; 294 static bool _debugDoingBaseline = false;
295 static bool _debugSetDoingBaseline(bool value) { 295 static bool _debugSetDoingBaseline(bool value) {
296 _debugDoingBaseline = value; 296 _debugDoingBaseline = value;
297 return true; 297 return true;
298 } 298 }
299 // getDistanceToBaseline() returns the distance from the 299 // getDistanceToBaseline() returns the distance from the
300 // y-coordinate of the position of the box to the y-coordinate of 300 // y-coordinate of the position of the box to the y-coordinate of
301 // the first given baseline in the box's contents. This is used by 301 // the first given baseline in the box's contents. This is used by
302 // certain layout models to align adjacent boxes on a common 302 // certain layout models to align adjacent boxes on a common
303 // baseline, regardless of padding, font size differences, etc. If 303 // baseline, regardless of padding, font size differences, etc. If
304 // there is no baseline, then it returns the distance from the 304 // there is no baseline, and the 'onlyReal' argument was not set to
305 // y-coordinate of the position of the box to the y-coordinate of 305 // true, then it returns the distance from the y-coordinate of the
306 // the bottom of the box, i.e., the height of the box. Only call 306 // position of the box to the y-coordinate of the bottom of the box,
307 // this after layout has been performed. You are only allowed to 307 // i.e., the height of the box. Only call this after layout has been
308 // call this from the parent of this node during that parent's 308 // performed. You are only allowed to call this from the parent of
309 // performLayout() or paint(). 309 // this node during that parent's performLayout() or paint().
310 double getDistanceToBaseline(TextBaseline baseline) { 310 double getDistanceToBaseline(TextBaseline baseline, { bool onlyReal: false }) {
311 assert(!needsLayout); 311 assert(!needsLayout);
312 assert(!_debugDoingBaseline); 312 assert(!_debugDoingBaseline);
313 final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer 313 final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer
314 assert(parent is RenderObject); 314 assert(parent is RenderObject);
315 assert(() { 315 assert(() {
316 if (RenderObject.debugDoingLayout) 316 if (RenderObject.debugDoingLayout)
317 return (parent == RenderObject.debugActiveLayout) && parent.debugDoingTh isLayout; 317 return (RenderObject.debugActiveLayout == parent) && parent.debugDoingTh isLayout;
318 if (RenderObject.debugDoingPaint) 318 if (RenderObject.debugDoingPaint)
319 return (parent == RenderObject.debugActivePaint) && parent.debugDoingThi sPaint; 319 return ((RenderObject.debugActivePaint == parent) && parent.debugDoingTh isPaint) ||
320 ((RenderObject.debugActivePaint == this) && debugDoingThisPaint);
320 return false; 321 return false;
321 }); 322 });
322 assert(_debugSetDoingBaseline(true)); 323 assert(_debugSetDoingBaseline(true));
323 double result = getDistanceToActualBaseline(baseline); 324 double result = getDistanceToActualBaseline(baseline);
324 assert(_debugSetDoingBaseline(false)); 325 assert(_debugSetDoingBaseline(false));
325 assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer 326 assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer
326 if (result == null) 327 if (result == null && !onlyReal)
327 return size.height; 328 return size.height;
328 return result; 329 return result;
329 } 330 }
330 // getDistanceToActualBaseline() must only be called from 331 // getDistanceToActualBaseline() must only be called from
331 // getDistanceToBaseline() and computeDistanceToActualBaseline(). Do 332 // getDistanceToBaseline() and computeDistanceToActualBaseline(). Do
332 // not call it directly from outside those two methods. It just 333 // not call it directly from outside those two methods. It just
333 // calls computeDistanceToActualBaseline() and caches the result. 334 // calls computeDistanceToActualBaseline() and caches the result.
334 double getDistanceToActualBaseline(TextBaseline baseline) { 335 double getDistanceToActualBaseline(TextBaseline baseline) {
335 assert(_debugDoingBaseline); 336 assert(_debugDoingBaseline);
336 _ancestorUsesBaseline = true; 337 _ancestorUsesBaseline = true;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 assert((sizedByParent && debugDoingThisResize) || 428 assert((sizedByParent && debugDoingThisResize) ||
428 (!sizedByParent && debugDoingThisLayout)); 429 (!sizedByParent && debugDoingThisLayout));
429 if (value is _DebugSize) { 430 if (value is _DebugSize) {
430 assert(value._canBeUsedByParent); 431 assert(value._canBeUsedByParent);
431 assert(value._owner.parent == this); 432 assert(value._owner.parent == this);
432 } 433 }
433 _size = inDebugBuild ? new _DebugSize(value, this, debugCanParentUseSize) : value; 434 _size = inDebugBuild ? new _DebugSize(value, this, debugCanParentUseSize) : value;
434 } 435 }
435 436
436 Rect get paintBounds => Point.origin & size; 437 Rect get paintBounds => Point.origin & size;
438 void debugPaint(PaintingCanvas canvas, Offset offset) {
439 if (debugPaintSizeEnabled)
440 debugPaintSize(canvas, offset);
441 if (debugPaintBaselinesEnabled)
442 debugPaintBaselines(canvas, offset);
443 }
444 void debugPaintSize(PaintingCanvas canvas, Offset offset) {
445 Paint paint = new Paint();
446 paint.setStyle(sky.PaintingStyle.stroke);
447 paint.strokeWidth = 1.0;
448 paint.color = debugPaintSizeColor;
449 canvas.drawRect(offset & size, paint);
450 }
451 void debugPaintBaselines(PaintingCanvas canvas, Offset offset) {
452 Paint paint = new Paint();
453 paint.setStyle(sky.PaintingStyle.stroke);
454 paint.strokeWidth = 0.25;
455 Path path;
456 // ideographic baseline
457 double baselineI = getDistanceToBaseline(TextBaseline.ideographic, onlyReal: true);
458 if (baselineI != null) {
459 paint.color = debugPaintIdeographicBaselineColor;
460 path = new Path();
461 path.moveTo(offset.dx, offset.dy + baselineI);
462 path.lineTo(offset.dx + size.width, offset.dy + baselineI);
463 canvas.drawPath(path, paint);
464 }
465 // alphabetic baseline
466 double baselineA = getDistanceToBaseline(TextBaseline.alphabetic, onlyReal: true);
467 if (baselineA != null) {
468 paint.color = debugPaintAlphabeticBaselineColor;
469 path = new Path();
470 path.moveTo(offset.dx, offset.dy + baselineA);
471 path.lineTo(offset.dx + size.width, offset.dy + baselineA);
472 canvas.drawPath(path, paint);
473 }
474 }
437 475
438 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}size: ${size}\n'; 476 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}size: ${size}\n';
439 } 477 }
440 478
441 class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox > { 479 class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox > {
442 480
443 // ProxyBox assumes the child will be at 0,0 and will have the same size 481 // ProxyBox assumes the child will be at 0,0 and will have the same size
444 482
445 RenderProxyBox([RenderBox child = null]) { 483 RenderProxyBox([RenderBox child = null]) {
446 this.child = child; 484 this.child = child;
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 1622
1585 void defaultPaint(PaintingCanvas canvas, Offset offset) { 1623 void defaultPaint(PaintingCanvas canvas, Offset offset) {
1586 RenderBox child = firstChild; 1624 RenderBox child = firstChild;
1587 while (child != null) { 1625 while (child != null) {
1588 assert(child.parentData is ParentDataType); 1626 assert(child.parentData is ParentDataType);
1589 canvas.paintChild(child, child.parentData.position + offset); 1627 canvas.paintChild(child, child.parentData.position + offset);
1590 child = child.parentData.nextSibling; 1628 child = child.parentData.nextSibling;
1591 } 1629 }
1592 } 1630 }
1593 } 1631 }
OLDNEW
« 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