OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "core/paint/ObjectPainter.h" | 5 #include "core/paint/ObjectPainter.h" |
6 | 6 |
7 #include "core/layout/LayoutBlock.h" | 7 #include "core/layout/LayoutBlock.h" |
8 #include "core/layout/LayoutInline.h" | 8 #include "core/layout/LayoutInline.h" |
9 #include "core/layout/LayoutObject.h" | 9 #include "core/layout/LayoutObject.h" |
10 #include "core/layout/LayoutTheme.h" | 10 #include "core/layout/LayoutTheme.h" |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 thickness = x2 - x1; | 360 thickness = x2 - x1; |
361 length = y2 - y1; | 361 length = y2 - y1; |
362 } | 362 } |
363 | 363 |
364 // We would like this check to be an ASSERT as we don't want to draw empty | 364 // We would like this check to be an ASSERT as we don't want to draw empty |
365 // borders. However nothing guarantees that the following recursive calls to | 365 // borders. However nothing guarantees that the following recursive calls to |
366 // drawLineForBoxSide will have positive thickness and length. | 366 // drawLineForBoxSide will have positive thickness and length. |
367 if (length <= 0 || thickness <= 0) | 367 if (length <= 0 || thickness <= 0) |
368 return; | 368 return; |
369 | 369 |
370 if (style == kBorderStyleDouble && thickness < 3) | 370 if (style == EBorderStyle::kDouble && thickness < 3) |
371 style = kBorderStyleSolid; | 371 style = EBorderStyle::kSolid; |
372 | 372 |
373 switch (style) { | 373 switch (style) { |
374 case kBorderStyleNone: | 374 case EBorderStyle::kNone: |
375 case kBorderStyleHidden: | 375 case EBorderStyle::kHidden: |
376 return; | 376 return; |
377 case kBorderStyleDotted: | 377 case EBorderStyle::kDotted: |
378 case kBorderStyleDashed: | 378 case EBorderStyle::kDashed: |
379 DrawDashedOrDottedBoxSide(graphics_context, x1, y1, x2, y2, side, color, | 379 DrawDashedOrDottedBoxSide(graphics_context, x1, y1, x2, y2, side, color, |
380 thickness, style, antialias); | 380 thickness, style, antialias); |
381 break; | 381 break; |
382 case kBorderStyleDouble: | 382 case EBorderStyle::kDouble: |
383 DrawDoubleBoxSide(graphics_context, x1, y1, x2, y2, length, side, color, | 383 DrawDoubleBoxSide(graphics_context, x1, y1, x2, y2, length, side, color, |
384 thickness, adjacent_width1, adjacent_width2, antialias); | 384 thickness, adjacent_width1, adjacent_width2, antialias); |
385 break; | 385 break; |
386 case kBorderStyleRidge: | 386 case EBorderStyle::kRidge: |
387 case kBorderStyleGroove: | 387 case EBorderStyle::kGroove: |
388 DrawRidgeOrGrooveBoxSide(graphics_context, x1, y1, x2, y2, side, color, | 388 DrawRidgeOrGrooveBoxSide(graphics_context, x1, y1, x2, y2, side, color, |
389 style, adjacent_width1, adjacent_width2, | 389 style, adjacent_width1, adjacent_width2, |
390 antialias); | 390 antialias); |
391 break; | 391 break; |
392 case kBorderStyleInset: | 392 case EBorderStyle::kInset: |
393 // FIXME: Maybe we should lighten the colors on one side like Firefox. | 393 // FIXME: Maybe we should lighten the colors on one side like Firefox. |
394 // https://bugs.webkit.org/show_bug.cgi?id=58608 | 394 // https://bugs.webkit.org/show_bug.cgi?id=58608 |
395 if (side == kBSTop || side == kBSLeft) | 395 if (side == kBSTop || side == kBSLeft) |
396 color = color.Dark(); | 396 color = color.Dark(); |
397 // fall through | 397 // fall through |
398 case kBorderStyleOutset: | 398 case EBorderStyle::kOutset: |
399 if (style == kBorderStyleOutset && | 399 if (style == EBorderStyle::kOutset && |
400 (side == kBSBottom || side == kBSRight)) | 400 (side == kBSBottom || side == kBSRight)) |
401 color = color.Dark(); | 401 color = color.Dark(); |
402 // fall through | 402 // fall through |
403 case kBorderStyleSolid: | 403 case EBorderStyle::kSolid: |
404 DrawSolidBoxSide(graphics_context, x1, y1, x2, y2, side, color, | 404 DrawSolidBoxSide(graphics_context, x1, y1, x2, y2, side, color, |
405 adjacent_width1, adjacent_width2, antialias); | 405 adjacent_width1, adjacent_width2, antialias); |
406 break; | 406 break; |
407 } | 407 } |
408 } | 408 } |
409 | 409 |
410 void ObjectPainter::DrawDashedOrDottedBoxSide(GraphicsContext& graphics_context, | 410 void ObjectPainter::DrawDashedOrDottedBoxSide(GraphicsContext& graphics_context, |
411 int x1, | 411 int x1, |
412 int y1, | 412 int y1, |
413 int x2, | 413 int x2, |
414 int y2, | 414 int y2, |
415 BoxSide side, | 415 BoxSide side, |
416 Color color, | 416 Color color, |
417 int thickness, | 417 int thickness, |
418 EBorderStyle style, | 418 EBorderStyle style, |
419 bool antialias) { | 419 bool antialias) { |
420 DCHECK_GT(thickness, 0); | 420 DCHECK_GT(thickness, 0); |
421 | 421 |
422 GraphicsContextStateSaver state_saver(graphics_context); | 422 GraphicsContextStateSaver state_saver(graphics_context); |
423 graphics_context.SetShouldAntialias(antialias); | 423 graphics_context.SetShouldAntialias(antialias); |
424 graphics_context.SetStrokeColor(color); | 424 graphics_context.SetStrokeColor(color); |
425 graphics_context.SetStrokeThickness(thickness); | 425 graphics_context.SetStrokeThickness(thickness); |
426 graphics_context.SetStrokeStyle(style == kBorderStyleDashed ? kDashedStroke | 426 graphics_context.SetStrokeStyle( |
427 : kDottedStroke); | 427 style == EBorderStyle::kDashed ? kDashedStroke : kDottedStroke); |
428 | 428 |
429 switch (side) { | 429 switch (side) { |
430 case kBSBottom: | 430 case kBSBottom: |
431 case kBSTop: { | 431 case kBSTop: { |
432 int mid_y = y1 + thickness / 2; | 432 int mid_y = y1 + thickness / 2; |
433 graphics_context.DrawLine(IntPoint(x1, mid_y), IntPoint(x2, mid_y)); | 433 graphics_context.DrawLine(IntPoint(x1, mid_y), IntPoint(x2, mid_y)); |
434 break; | 434 break; |
435 } | 435 } |
436 case kBSRight: | 436 case kBSRight: |
437 case kBSLeft: { | 437 case kBSLeft: { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 int adjacent1_big_third = | 488 int adjacent1_big_third = |
489 ((adjacent_width1 > 0) ? adjacent_width1 + 1 : adjacent_width1 - 1) / 3; | 489 ((adjacent_width1 > 0) ? adjacent_width1 + 1 : adjacent_width1 - 1) / 3; |
490 int adjacent2_big_third = | 490 int adjacent2_big_third = |
491 ((adjacent_width2 > 0) ? adjacent_width2 + 1 : adjacent_width2 - 1) / 3; | 491 ((adjacent_width2 > 0) ? adjacent_width2 + 1 : adjacent_width2 - 1) / 3; |
492 | 492 |
493 switch (side) { | 493 switch (side) { |
494 case kBSTop: | 494 case kBSTop: |
495 DrawLineForBoxSide( | 495 DrawLineForBoxSide( |
496 graphics_context, x1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), | 496 graphics_context, x1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), |
497 y1, x2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), | 497 y1, x2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), |
498 y1 + third_of_thickness, side, color, kBorderStyleSolid, | 498 y1 + third_of_thickness, side, color, EBorderStyle::kSolid, |
499 adjacent1_big_third, adjacent2_big_third, antialias); | 499 adjacent1_big_third, adjacent2_big_third, antialias); |
500 DrawLineForBoxSide(graphics_context, | 500 DrawLineForBoxSide(graphics_context, |
501 x1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), | 501 x1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), |
502 y2 - third_of_thickness, | 502 y2 - third_of_thickness, |
503 x2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), y2, | 503 x2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), y2, |
504 side, color, kBorderStyleSolid, adjacent1_big_third, | 504 side, color, EBorderStyle::kSolid, adjacent1_big_third, |
505 adjacent2_big_third, antialias); | 505 adjacent2_big_third, antialias); |
506 break; | 506 break; |
507 case kBSLeft: | 507 case kBSLeft: |
508 DrawLineForBoxSide(graphics_context, x1, | 508 DrawLineForBoxSide(graphics_context, x1, |
509 y1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), | 509 y1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), |
510 x1 + third_of_thickness, | 510 x1 + third_of_thickness, |
511 y2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), side, | 511 y2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), side, |
512 color, kBorderStyleSolid, adjacent1_big_third, | 512 color, EBorderStyle::kSolid, adjacent1_big_third, |
513 adjacent2_big_third, antialias); | 513 adjacent2_big_third, antialias); |
514 DrawLineForBoxSide(graphics_context, x2 - third_of_thickness, | 514 DrawLineForBoxSide(graphics_context, x2 - third_of_thickness, |
515 y1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), x2, | 515 y1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), x2, |
516 y2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), side, | 516 y2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), side, |
517 color, kBorderStyleSolid, adjacent1_big_third, | 517 color, EBorderStyle::kSolid, adjacent1_big_third, |
518 adjacent2_big_third, antialias); | 518 adjacent2_big_third, antialias); |
519 break; | 519 break; |
520 case kBSBottom: | 520 case kBSBottom: |
521 DrawLineForBoxSide( | 521 DrawLineForBoxSide( |
522 graphics_context, x1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), y1, | 522 graphics_context, x1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), y1, |
523 x2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), | 523 x2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), |
524 y1 + third_of_thickness, side, color, kBorderStyleSolid, | 524 y1 + third_of_thickness, side, color, EBorderStyle::kSolid, |
525 adjacent1_big_third, adjacent2_big_third, antialias); | 525 adjacent1_big_third, adjacent2_big_third, antialias); |
526 DrawLineForBoxSide(graphics_context, | 526 DrawLineForBoxSide(graphics_context, |
527 x1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), | 527 x1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), |
528 y2 - third_of_thickness, | 528 y2 - third_of_thickness, |
529 x2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), y2, | 529 x2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), y2, |
530 side, color, kBorderStyleSolid, adjacent1_big_third, | 530 side, color, EBorderStyle::kSolid, adjacent1_big_third, |
531 adjacent2_big_third, antialias); | 531 adjacent2_big_third, antialias); |
532 break; | 532 break; |
533 case kBSRight: | 533 case kBSRight: |
534 DrawLineForBoxSide(graphics_context, x1, | 534 DrawLineForBoxSide(graphics_context, x1, |
535 y1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), | 535 y1 + std::max((adjacent_width1 * 2 + 1) / 3, 0), |
536 x1 + third_of_thickness, | 536 x1 + third_of_thickness, |
537 y2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), side, | 537 y2 - std::max((adjacent_width2 * 2 + 1) / 3, 0), side, |
538 color, kBorderStyleSolid, adjacent1_big_third, | 538 color, EBorderStyle::kSolid, adjacent1_big_third, |
539 adjacent2_big_third, antialias); | 539 adjacent2_big_third, antialias); |
540 DrawLineForBoxSide(graphics_context, x2 - third_of_thickness, | 540 DrawLineForBoxSide(graphics_context, x2 - third_of_thickness, |
541 y1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), x2, | 541 y1 + std::max((-adjacent_width1 * 2 + 1) / 3, 0), x2, |
542 y2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), side, | 542 y2 - std::max((-adjacent_width2 * 2 + 1) / 3, 0), side, |
543 color, kBorderStyleSolid, adjacent1_big_third, | 543 color, EBorderStyle::kSolid, adjacent1_big_third, |
544 adjacent2_big_third, antialias); | 544 adjacent2_big_third, antialias); |
545 break; | 545 break; |
546 default: | 546 default: |
547 break; | 547 break; |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 void ObjectPainter::DrawRidgeOrGrooveBoxSide(GraphicsContext& graphics_context, | 551 void ObjectPainter::DrawRidgeOrGrooveBoxSide(GraphicsContext& graphics_context, |
552 int x1, | 552 int x1, |
553 int y1, | 553 int y1, |
554 int x2, | 554 int x2, |
555 int y2, | 555 int y2, |
556 BoxSide side, | 556 BoxSide side, |
557 Color color, | 557 Color color, |
558 EBorderStyle style, | 558 EBorderStyle style, |
559 int adjacent_width1, | 559 int adjacent_width1, |
560 int adjacent_width2, | 560 int adjacent_width2, |
561 bool antialias) { | 561 bool antialias) { |
562 EBorderStyle s1; | 562 EBorderStyle s1; |
563 EBorderStyle s2; | 563 EBorderStyle s2; |
564 if (style == kBorderStyleGroove) { | 564 if (style == EBorderStyle::kGroove) { |
565 s1 = kBorderStyleInset; | 565 s1 = EBorderStyle::kInset; |
566 s2 = kBorderStyleOutset; | 566 s2 = EBorderStyle::kOutset; |
567 } else { | 567 } else { |
568 s1 = kBorderStyleOutset; | 568 s1 = EBorderStyle::kOutset; |
569 s2 = kBorderStyleInset; | 569 s2 = EBorderStyle::kInset; |
570 } | 570 } |
571 | 571 |
572 int adjacent1_big_half = | 572 int adjacent1_big_half = |
573 ((adjacent_width1 > 0) ? adjacent_width1 + 1 : adjacent_width1 - 1) / 2; | 573 ((adjacent_width1 > 0) ? adjacent_width1 + 1 : adjacent_width1 - 1) / 2; |
574 int adjacent2_big_half = | 574 int adjacent2_big_half = |
575 ((adjacent_width2 > 0) ? adjacent_width2 + 1 : adjacent_width2 - 1) / 2; | 575 ((adjacent_width2 > 0) ? adjacent_width2 + 1 : adjacent_width2 - 1) / 2; |
576 | 576 |
577 switch (side) { | 577 switch (side) { |
578 case kBSTop: | 578 case kBSTop: |
579 DrawLineForBoxSide( | 579 DrawLineForBoxSide( |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 adjusted_paint_offset += ToLayoutBox(layout_object_).Location(); | 716 adjusted_paint_offset += ToLayoutBox(layout_object_).Location(); |
717 DCHECK(layout_object_.PaintOffset() == adjusted_paint_offset) | 717 DCHECK(layout_object_.PaintOffset() == adjusted_paint_offset) |
718 << " Paint offset mismatch: " << layout_object_.DebugName() | 718 << " Paint offset mismatch: " << layout_object_.DebugName() |
719 << " from PaintPropertyTreeBuilder: " | 719 << " from PaintPropertyTreeBuilder: " |
720 << layout_object_.PaintOffset().ToString() | 720 << layout_object_.PaintOffset().ToString() |
721 << " from painter: " << adjusted_paint_offset.ToString(); | 721 << " from painter: " << adjusted_paint_offset.ToString(); |
722 } | 722 } |
723 #endif | 723 #endif |
724 | 724 |
725 } // namespace blink | 725 } // namespace blink |
OLD | NEW |