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

Side by Side Diff: sky/sdk/lib/framework/rendering/box.dart

Issue 1154903006: Borders. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: now with no broken tests Created 5 years, 6 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/examples/raw/borders.dart ('k') | sky/tests/raw/padding_deflate.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 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 import 'node.dart'; 8 import 'node.dart';
9 import 'package:vector_math/vector_math.dart'; 9 import 'package:vector_math/vector_math.dart';
10 import 'package:sky/framework/net/image_cache.dart' as image_cache; 10 import 'package:sky/framework/net/image_cache.dart' as image_cache;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 canvas.save(); 343 canvas.save();
344 canvas.scale(widthScale, heightScale); 344 canvas.scale(widthScale, heightScale);
345 } 345 }
346 sky.Paint paint = new sky.Paint(); 346 sky.Paint paint = new sky.Paint();
347 canvas.drawImage(_image, 0.0, 0.0, paint); 347 canvas.drawImage(_image, 0.0, 0.0, paint);
348 if (needsScale) 348 if (needsScale)
349 canvas.restore(); 349 canvas.restore();
350 } 350 }
351 } 351 }
352 352
353 class BorderSide {
354 const BorderSide({
355 this.color: const sky.Color(0xFF000000),
356 this.width: 1.0
357 });
358 final sky.Color color;
359 final double width;
360
361 static const None = const BorderSide(width: 0.0);
Matt Perry 2015/06/04 16:58:33 what's our naming scheme for class constants? I've
Matt Perry 2015/06/04 17:59:43 Still curious what the decision was here. Should w
362
363 int get hashCode {
364 int value = 373;
365 value = 37 * value * color.hashCode;
366 value = 37 * value * width.hashCode;
367 return value;
368 }
369 String toString() => 'BorderSide($color, $width)';
370 }
371
372 class Border {
373 const Border({
374 this.top: BorderSide.None,
375 this.right: BorderSide.None,
376 this.bottom: BorderSide.None,
377 this.left: BorderSide.None
378 });
379 const Border.all(BorderSide side) :
380 top = side,
381 right = side,
382 bottom = side,
383 left = side;
384 final BorderSide top;
385 final BorderSide right;
386 final BorderSide bottom;
387 final BorderSide left;
388
389 int get hashCode {
390 int value = 373;
391 value = 37 * value * top.hashCode;
392 value = 37 * value * right.hashCode;
393 value = 37 * value * bottom.hashCode;
394 value = 37 * value * left.hashCode;
395 return value;
396 }
397 String toString() => 'Border($top, $right, $bottom, $left)';
398 }
399
353 // This must be immutable, because we won't notice when it changes 400 // This must be immutable, because we won't notice when it changes
354 class BoxDecoration { 401 class BoxDecoration {
355 const BoxDecoration({this.backgroundColor}); 402 const BoxDecoration({
403 this.backgroundColor,
404 this.border
405 });
356 406
357 final sky.Color backgroundColor; 407 final sky.Color backgroundColor;
408 final Border border;
358 } 409 }
359 410
360 class RenderDecoratedBox extends RenderProxyBox { 411 class RenderDecoratedBox extends RenderProxyBox {
361 412
362 RenderDecoratedBox({ 413 RenderDecoratedBox({
363 BoxDecoration decoration, 414 BoxDecoration decoration,
364 RenderBox child 415 RenderBox child
365 }) : _decoration = decoration, super(child); 416 }) : _decoration = decoration, super(child) {
417 assert(_decoration != null);
418 }
366 419
367 BoxDecoration _decoration; 420 BoxDecoration _decoration;
368 BoxDecoration get decoration => _decoration; 421 BoxDecoration get decoration => _decoration;
369 void set decoration (BoxDecoration value) { 422 void set decoration (BoxDecoration value) {
423 assert(value != null);
370 if (value == _decoration) 424 if (value == _decoration)
371 return; 425 return;
372 _decoration = value; 426 _decoration = value;
373 markNeedsPaint(); 427 markNeedsPaint();
374 } 428 }
375 429
376 void paint(RenderNodeDisplayList canvas) { 430 void paint(RenderNodeDisplayList canvas) {
377 assert(size.width != null); 431 assert(size.width != null);
378 assert(size.height != null); 432 assert(size.height != null);
379 433
380 if (_decoration == null)
381 return;
382
383 if (_decoration.backgroundColor != null) { 434 if (_decoration.backgroundColor != null) {
384 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; 435 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor;
385 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint); 436 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint);
386 } 437 }
438
439 if (_decoration.border != null) {
440 assert(_decoration.border.top != null);
441 assert(_decoration.border.right != null);
442 assert(_decoration.border.bottom != null);
443 assert(_decoration.border.left != null);
444
445 sky.Paint paint = new sky.Paint();
446 sky.Path path;
447
448 paint.color = _decoration.border.top.color;
449 path = new sky.Path();
450 path.moveTo(0.0,0.0);
Matt Perry 2015/06/04 16:58:33 nit: space after ,
451 path.lineTo(_decoration.border.left.width, _decoration.border.top.width);
452 path.lineTo(size.width - _decoration.border.right.width, _decoration.borde r.top.width);
453 path.lineTo(size.width, 0.0);
454 path.close();
455 canvas.drawPath(path, paint);
456
457 paint.color = _decoration.border.right.color;
458 path = new sky.Path();
459 path.moveTo(size.width, 0.0);
460 path.lineTo(size.width - _decoration.border.right.width, _decoration.borde r.top.width);
461 path.lineTo(size.width - _decoration.border.right.width, size.height - _de coration.border.bottom.width);
462 path.lineTo(size.width, size.height);
463 path.close();
464 canvas.drawPath(path, paint);
465
466 paint.color = _decoration.border.bottom.color;
467 path = new sky.Path();
468 path.moveTo(size.width, size.height);
469 path.lineTo(size.width - _decoration.border.right.width, size.height - _de coration.border.bottom.width);
470 path.lineTo(_decoration.border.left.width, size.height - _decoration.borde r.bottom.width);
471 path.lineTo(0.0, size.height);
472 path.close();
473 canvas.drawPath(path, paint);
474
475 paint.color = _decoration.border.left.color;
476 path = new sky.Path();
477 path.moveTo(0.0, size.height);
478 path.lineTo(_decoration.border.left.width, size.height - _decoration.borde r.bottom.width);
479 path.lineTo(_decoration.border.left.width, _decoration.border.top.width);
480 path.lineTo(0.0,0.0);
481 path.close();
482 canvas.drawPath(path, paint);
483 }
484
387 super.paint(canvas); 485 super.paint(canvas);
388 } 486 }
389 } 487 }
390 488
391 class RenderTransform extends RenderProxyBox { 489 class RenderTransform extends RenderProxyBox {
392 RenderTransform({ 490 RenderTransform({
393 Matrix4 transform, 491 Matrix4 transform,
394 RenderBox child 492 RenderBox child
395 }) : super(child) { 493 }) : super(child) {
396 assert(transform != null); 494 assert(transform != null);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 656
559 void defaultPaint(RenderNodeDisplayList canvas) { 657 void defaultPaint(RenderNodeDisplayList canvas) {
560 RenderBox child = firstChild; 658 RenderBox child = firstChild;
561 while (child != null) { 659 while (child != null) {
562 assert(child.parentData is ParentDataType); 660 assert(child.parentData is ParentDataType);
563 canvas.paintChild(child, child.parentData.position); 661 canvas.paintChild(child, child.parentData.position);
564 child = child.parentData.nextSibling; 662 child = child.parentData.nextSibling;
565 } 663 }
566 } 664 }
567 } 665 }
OLDNEW
« no previous file with comments | « sky/examples/raw/borders.dart ('k') | sky/tests/raw/padding_deflate.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698