OLD | NEW |
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 #include "core/paint/BoxBorderPainter.h" | 5 #include "core/paint/BoxBorderPainter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include "core/paint/BoxPainter.h" | 8 #include "core/paint/BoxPainter.h" |
9 #include "core/paint/ObjectPainter.h" | 9 #include "core/paint/ObjectPainter.h" |
10 #include "core/paint/PaintInfo.h" | 10 #include "core/paint/PaintInfo.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 inline bool IncludesAdjacentEdges(BorderEdgeFlags flags) { | 39 inline bool IncludesAdjacentEdges(BorderEdgeFlags flags) { |
40 // The set includes adjacent edges iff it contains at least one horizontal and | 40 // The set includes adjacent edges iff it contains at least one horizontal and |
41 // one vertical edge. | 41 // one vertical edge. |
42 return (flags & (kTopBorderEdge | kBottomBorderEdge)) && | 42 return (flags & (kTopBorderEdge | kBottomBorderEdge)) && |
43 (flags & (kLeftBorderEdge | kRightBorderEdge)); | 43 (flags & (kLeftBorderEdge | kRightBorderEdge)); |
44 } | 44 } |
45 | 45 |
46 inline bool StyleRequiresClipPolygon(EBorderStyle style) { | 46 inline bool StyleRequiresClipPolygon(EBorderStyle style) { |
47 // These are drawn with a stroke, so we have to clip to get corner miters. | 47 // These are drawn with a stroke, so we have to clip to get corner miters. |
48 return style == kBorderStyleDotted || style == kBorderStyleDashed; | 48 return style == EBorderStyle::kDotted || style == EBorderStyle::kDashed; |
49 } | 49 } |
50 | 50 |
51 inline bool BorderStyleFillsBorderArea(EBorderStyle style) { | 51 inline bool BorderStyleFillsBorderArea(EBorderStyle style) { |
52 return !(style == kBorderStyleDotted || style == kBorderStyleDashed || | 52 return !(style == EBorderStyle::kDotted || style == EBorderStyle::kDashed || |
53 style == kBorderStyleDouble); | 53 style == EBorderStyle::kDouble); |
54 } | 54 } |
55 | 55 |
56 inline bool BorderStyleHasInnerDetail(EBorderStyle style) { | 56 inline bool BorderStyleHasInnerDetail(EBorderStyle style) { |
57 return style == kBorderStyleGroove || style == kBorderStyleRidge || | 57 return style == EBorderStyle::kGroove || style == EBorderStyle::kRidge || |
58 style == kBorderStyleDouble; | 58 style == EBorderStyle::kDouble; |
59 } | 59 } |
60 | 60 |
61 inline bool BorderStyleIsDottedOrDashed(EBorderStyle style) { | 61 inline bool BorderStyleIsDottedOrDashed(EBorderStyle style) { |
62 return style == kBorderStyleDotted || style == kBorderStyleDashed; | 62 return style == EBorderStyle::kDotted || style == EBorderStyle::kDashed; |
63 } | 63 } |
64 | 64 |
65 // BorderStyleOutset darkens the bottom and right (and maybe lightens the top | 65 // BorderStyleOutset darkens the bottom and right (and maybe lightens the top |
66 // and left) BorderStyleInset darkens the top and left (and maybe lightens the | 66 // and left) BorderStyleInset darkens the top and left (and maybe lightens the |
67 // bottom and right). | 67 // bottom and right). |
68 inline bool BorderStyleHasUnmatchedColorsAtCorner(EBorderStyle style, | 68 inline bool BorderStyleHasUnmatchedColorsAtCorner(EBorderStyle style, |
69 BoxSide side, | 69 BoxSide side, |
70 BoxSide adjacent_side) { | 70 BoxSide adjacent_side) { |
71 // These styles match at the top/left and bottom/right. | 71 // These styles match at the top/left and bottom/right. |
72 if (style == kBorderStyleInset || style == kBorderStyleGroove || | 72 if (style == EBorderStyle::kInset || style == EBorderStyle::kGroove || |
73 style == kBorderStyleRidge || style == kBorderStyleOutset) { | 73 style == EBorderStyle::kRidge || style == EBorderStyle::kOutset) { |
74 const BorderEdgeFlags top_right_flags = | 74 const BorderEdgeFlags top_right_flags = |
75 EdgeFlagForSide(kBSTop) | EdgeFlagForSide(kBSRight); | 75 EdgeFlagForSide(kBSTop) | EdgeFlagForSide(kBSRight); |
76 const BorderEdgeFlags bottom_left_flags = | 76 const BorderEdgeFlags bottom_left_flags = |
77 EdgeFlagForSide(kBSBottom) | EdgeFlagForSide(kBSLeft); | 77 EdgeFlagForSide(kBSBottom) | EdgeFlagForSide(kBSLeft); |
78 | 78 |
79 BorderEdgeFlags flags = | 79 BorderEdgeFlags flags = |
80 EdgeFlagForSide(side) | EdgeFlagForSide(adjacent_side); | 80 EdgeFlagForSide(side) | EdgeFlagForSide(adjacent_side); |
81 return flags == top_right_flags || flags == bottom_left_flags; | 81 return flags == top_right_flags || flags == bottom_left_flags; |
82 } | 82 } |
83 return false; | 83 return false; |
(...skipping 27 matching lines...) Expand all Loading... |
111 | 111 |
112 // The side is still to be drawn. It overdraws the current edge iff it has a | 112 // The side is still to be drawn. It overdraws the current edge iff it has a |
113 // solid fill style. | 113 // solid fill style. |
114 return BorderStyleFillsBorderArea(style); | 114 return BorderStyleFillsBorderArea(style); |
115 } | 115 } |
116 | 116 |
117 inline bool BorderStylesRequireMiter(BoxSide side, | 117 inline bool BorderStylesRequireMiter(BoxSide side, |
118 BoxSide adjacent_side, | 118 BoxSide adjacent_side, |
119 EBorderStyle style, | 119 EBorderStyle style, |
120 EBorderStyle adjacent_style) { | 120 EBorderStyle adjacent_style) { |
121 if (style == kBorderStyleDouble || adjacent_style == kBorderStyleDouble || | 121 if (style == EBorderStyle::kDouble || |
122 adjacent_style == kBorderStyleGroove || | 122 adjacent_style == EBorderStyle::kDouble || |
123 adjacent_style == kBorderStyleRidge) | 123 adjacent_style == EBorderStyle::kGroove || |
| 124 adjacent_style == EBorderStyle::kRidge) |
124 return true; | 125 return true; |
125 | 126 |
126 if (BorderStyleIsDottedOrDashed(style) != | 127 if (BorderStyleIsDottedOrDashed(style) != |
127 BorderStyleIsDottedOrDashed(adjacent_style)) | 128 BorderStyleIsDottedOrDashed(adjacent_style)) |
128 return true; | 129 return true; |
129 | 130 |
130 if (style != adjacent_style) | 131 if (style != adjacent_style) |
131 return true; | 132 return true; |
132 | 133 |
133 return BorderStyleHasUnmatchedColorsAtCorner(style, side, adjacent_side); | 134 return BorderStyleHasUnmatchedColorsAtCorner(style, side, adjacent_side); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 break; | 329 break; |
329 } | 330 } |
330 // fall through | 331 // fall through |
331 default: | 332 default: |
332 context.FillDRRect(outer, inner, color); | 333 context.FillDRRect(outer, inner, color); |
333 break; | 334 break; |
334 } | 335 } |
335 } | 336 } |
336 | 337 |
337 // The LUTs below assume specific enum values. | 338 // The LUTs below assume specific enum values. |
338 static_assert(kBorderStyleNone == 0, "unexpected EBorderStyle value"); | 339 static_assert(EBorderStyle::kNone == static_cast<EBorderStyle>(0), |
339 static_assert(kBorderStyleHidden == 1, "unexpected EBorderStyle value"); | 340 "unexpected EBorderStyle value"); |
340 static_assert(kBorderStyleInset == 2, "unexpected EBorderStyle value"); | 341 static_assert(EBorderStyle::kHidden == static_cast<EBorderStyle>(1), |
341 static_assert(kBorderStyleGroove == 3, "unexpected EBorderStyle value"); | 342 "unexpected EBorderStyle value"); |
342 static_assert(kBorderStyleOutset == 4, "unexpected EBorderStyle value"); | 343 static_assert(EBorderStyle::kInset == static_cast<EBorderStyle>(2), |
343 static_assert(kBorderStyleRidge == 5, "unexpected EBorderStyle value"); | 344 "unexpected EBorderStyle value"); |
344 static_assert(kBorderStyleDotted == 6, "unexpected EBorderStyle value"); | 345 static_assert(EBorderStyle::kGroove == static_cast<EBorderStyle>(3), |
345 static_assert(kBorderStyleDashed == 7, "unexpected EBorderStyle value"); | 346 "unexpected EBorderStyle value"); |
346 static_assert(kBorderStyleSolid == 8, "unexpected EBorderStyle value"); | 347 static_assert(EBorderStyle::kOutset == static_cast<EBorderStyle>(4), |
347 static_assert(kBorderStyleDouble == 9, "unexpected EBorderStyle value"); | 348 "unexpected EBorderStyle value"); |
| 349 static_assert(EBorderStyle::kRidge == static_cast<EBorderStyle>(5), |
| 350 "unexpected EBorderStyle value"); |
| 351 static_assert(EBorderStyle::kDotted == static_cast<EBorderStyle>(6), |
| 352 "unexpected EBorderStyle value"); |
| 353 static_assert(EBorderStyle::kDashed == static_cast<EBorderStyle>(7), |
| 354 "unexpected EBorderStyle value"); |
| 355 static_assert(EBorderStyle::kSolid == static_cast<EBorderStyle>(8), |
| 356 "unexpected EBorderStyle value"); |
| 357 static_assert(EBorderStyle::kDouble == static_cast<EBorderStyle>(9), |
| 358 "unexpected EBorderStyle value"); |
348 | 359 |
349 static_assert(kBSTop == 0, "unexpected BoxSide value"); | 360 static_assert(kBSTop == 0, "unexpected BoxSide value"); |
350 static_assert(kBSRight == 1, "unexpected BoxSide value"); | 361 static_assert(kBSRight == 1, "unexpected BoxSide value"); |
351 static_assert(kBSBottom == 2, "unexpected BoxSide value"); | 362 static_assert(kBSBottom == 2, "unexpected BoxSide value"); |
352 static_assert(kBSLeft == 3, "unexpected BoxSide value"); | 363 static_assert(kBSLeft == 3, "unexpected BoxSide value"); |
353 | 364 |
354 // Style-based paint order: non-solid edges (dashed/dotted/double) are painted | 365 // Style-based paint order: non-solid edges (dashed/dotted/double) are painted |
355 // before solid edges (inset/outset/groove/ridge/solid) to maximize overdraw | 366 // before solid edges (inset/outset/groove/ridge/solid) to maximize overdraw |
356 // opportunities. | 367 // opportunities. |
357 const unsigned kStylePriority[] = { | 368 const unsigned kStylePriority[] = { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 [&border_painter](BoxSide a, BoxSide b) -> bool { | 427 [&border_painter](BoxSide a, BoxSide b) -> bool { |
417 const BorderEdge& edge_a = border_painter.edges_[a]; | 428 const BorderEdge& edge_a = border_painter.edges_[a]; |
418 const BorderEdge& edge_b = border_painter.edges_[b]; | 429 const BorderEdge& edge_b = border_painter.edges_[b]; |
419 | 430 |
420 const unsigned alpha_a = edge_a.color.Alpha(); | 431 const unsigned alpha_a = edge_a.color.Alpha(); |
421 const unsigned alpha_b = edge_b.color.Alpha(); | 432 const unsigned alpha_b = edge_b.color.Alpha(); |
422 if (alpha_a != alpha_b) | 433 if (alpha_a != alpha_b) |
423 return alpha_a < alpha_b; | 434 return alpha_a < alpha_b; |
424 | 435 |
425 const unsigned style_priority_a = | 436 const unsigned style_priority_a = |
426 kStylePriority[edge_a.BorderStyle()]; | 437 kStylePriority[static_cast<unsigned>(edge_a.BorderStyle())]; |
427 const unsigned style_priority_b = | 438 const unsigned style_priority_b = |
428 kStylePriority[edge_b.BorderStyle()]; | 439 kStylePriority[static_cast<unsigned>(edge_b.BorderStyle())]; |
429 if (style_priority_a != style_priority_b) | 440 if (style_priority_a != style_priority_b) |
430 return style_priority_a < style_priority_b; | 441 return style_priority_a < style_priority_b; |
431 | 442 |
432 return kSidePriority[a] < kSidePriority[b]; | 443 return kSidePriority[a] < kSidePriority[b]; |
433 }); | 444 }); |
434 | 445 |
435 // Finally, build the opacity group structures. | 446 // Finally, build the opacity group structures. |
436 BuildOpacityGroups(border_painter, sorted_sides); | 447 BuildOpacityGroups(border_painter, sorted_sides); |
437 | 448 |
438 if (border_painter.is_rounded_) | 449 if (border_painter.is_rounded_) |
(...skipping 29 matching lines...) Expand all Loading... |
468 } | 479 } |
469 | 480 |
470 DCHECK(!opacity_groups.IsEmpty()); | 481 DCHECK(!opacity_groups.IsEmpty()); |
471 } | 482 } |
472 }; | 483 }; |
473 | 484 |
474 void BoxBorderPainter::DrawDoubleBorder(GraphicsContext& context, | 485 void BoxBorderPainter::DrawDoubleBorder(GraphicsContext& context, |
475 const LayoutRect& border_rect) const { | 486 const LayoutRect& border_rect) const { |
476 DCHECK(is_uniform_color_); | 487 DCHECK(is_uniform_color_); |
477 DCHECK(is_uniform_style_); | 488 DCHECK(is_uniform_style_); |
478 DCHECK(FirstEdge().BorderStyle() == kBorderStyleDouble); | 489 DCHECK(FirstEdge().BorderStyle() == EBorderStyle::kDouble); |
479 DCHECK(visible_edge_set_ == kAllBorderEdges); | 490 DCHECK(visible_edge_set_ == kAllBorderEdges); |
480 | 491 |
481 const Color color = FirstEdge().color; | 492 const Color color = FirstEdge().color; |
482 | 493 |
483 // outer stripe | 494 // outer stripe |
484 const LayoutRectOutsets outer_third_insets = | 495 const LayoutRectOutsets outer_third_insets = |
485 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeOuter); | 496 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeOuter); |
486 const FloatRoundedRect outer_third_rect = style_.GetRoundedInnerBorderFor( | 497 const FloatRoundedRect outer_third_rect = style_.GetRoundedInnerBorderFor( |
487 border_rect, outer_third_insets, include_logical_left_edge_, | 498 border_rect, outer_third_insets, include_logical_left_edge_, |
488 include_logical_right_edge_); | 499 include_logical_right_edge_); |
489 DrawBleedAdjustedDRRect(context, bleed_avoidance_, outer_, outer_third_rect, | 500 DrawBleedAdjustedDRRect(context, bleed_avoidance_, outer_, outer_third_rect, |
490 color); | 501 color); |
491 | 502 |
492 // inner stripe | 503 // inner stripe |
493 const LayoutRectOutsets inner_third_insets = | 504 const LayoutRectOutsets inner_third_insets = |
494 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeInner); | 505 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeInner); |
495 const FloatRoundedRect inner_third_rect = style_.GetRoundedInnerBorderFor( | 506 const FloatRoundedRect inner_third_rect = style_.GetRoundedInnerBorderFor( |
496 border_rect, inner_third_insets, include_logical_left_edge_, | 507 border_rect, inner_third_insets, include_logical_left_edge_, |
497 include_logical_right_edge_); | 508 include_logical_right_edge_); |
498 context.FillDRRect(inner_third_rect, inner_, color); | 509 context.FillDRRect(inner_third_rect, inner_, color); |
499 } | 510 } |
500 | 511 |
501 bool BoxBorderPainter::PaintBorderFastPath( | 512 bool BoxBorderPainter::PaintBorderFastPath( |
502 GraphicsContext& context, | 513 GraphicsContext& context, |
503 const LayoutRect& border_rect) const { | 514 const LayoutRect& border_rect) const { |
504 if (!is_uniform_color_ || !is_uniform_style_ || !inner_.IsRenderable()) | 515 if (!is_uniform_color_ || !is_uniform_style_ || !inner_.IsRenderable()) |
505 return false; | 516 return false; |
506 | 517 |
507 if (FirstEdge().BorderStyle() != kBorderStyleSolid && | 518 if (FirstEdge().BorderStyle() != EBorderStyle::kSolid && |
508 FirstEdge().BorderStyle() != kBorderStyleDouble) | 519 FirstEdge().BorderStyle() != EBorderStyle::kDouble) |
509 return false; | 520 return false; |
510 | 521 |
511 if (visible_edge_set_ == kAllBorderEdges) { | 522 if (visible_edge_set_ == kAllBorderEdges) { |
512 if (FirstEdge().BorderStyle() == kBorderStyleSolid) { | 523 if (FirstEdge().BorderStyle() == EBorderStyle::kSolid) { |
513 if (is_uniform_width_ && !outer_.IsRounded()) { | 524 if (is_uniform_width_ && !outer_.IsRounded()) { |
514 // 4-side, solid, uniform-width, rectangular border => one drawRect() | 525 // 4-side, solid, uniform-width, rectangular border => one drawRect() |
515 DrawSolidBorderRect(context, outer_.Rect(), FirstEdge().Width(), | 526 DrawSolidBorderRect(context, outer_.Rect(), FirstEdge().Width(), |
516 FirstEdge().color); | 527 FirstEdge().color); |
517 } else { | 528 } else { |
518 // 4-side, solid border => one drawDRRect() | 529 // 4-side, solid border => one drawDRRect() |
519 DrawBleedAdjustedDRRect(context, bleed_avoidance_, outer_, inner_, | 530 DrawBleedAdjustedDRRect(context, bleed_avoidance_, outer_, inner_, |
520 FirstEdge().color); | 531 FirstEdge().color); |
521 } | 532 } |
522 } else { | 533 } else { |
523 // 4-side, double border => 2x drawDRRect() | 534 // 4-side, double border => 2x drawDRRect() |
524 DCHECK(FirstEdge().BorderStyle() == kBorderStyleDouble); | 535 DCHECK(FirstEdge().BorderStyle() == EBorderStyle::kDouble); |
525 DrawDoubleBorder(context, border_rect); | 536 DrawDoubleBorder(context, border_rect); |
526 } | 537 } |
527 | 538 |
528 return true; | 539 return true; |
529 } | 540 } |
530 | 541 |
531 // This is faster than the normal complex border path only if it avoids | 542 // This is faster than the normal complex border path only if it avoids |
532 // creating transparency layers (when the border is translucent). | 543 // creating transparency layers (when the border is translucent). |
533 if (FirstEdge().BorderStyle() == kBorderStyleSolid && !outer_.IsRounded() && | 544 if (FirstEdge().BorderStyle() == EBorderStyle::kSolid && |
534 has_alpha_) { | 545 !outer_.IsRounded() && has_alpha_) { |
535 DCHECK(visible_edge_set_ != kAllBorderEdges); | 546 DCHECK(visible_edge_set_ != kAllBorderEdges); |
536 // solid, rectangular border => one drawPath() | 547 // solid, rectangular border => one drawPath() |
537 Path path; | 548 Path path; |
538 path.SetWindRule(RULE_NONZERO); | 549 path.SetWindRule(RULE_NONZERO); |
539 | 550 |
540 for (int i = kBSTop; i <= kBSLeft; ++i) { | 551 for (int i = kBSTop; i <= kBSLeft; ++i) { |
541 const BorderEdge& curr_edge = edges_[i]; | 552 const BorderEdge& curr_edge = edges_[i]; |
542 if (curr_edge.ShouldRender()) | 553 if (curr_edge.ShouldRender()) |
543 path.AddRect(CalculateSideRect(outer_, curr_edge, i)); | 554 path.AddRect(CalculateSideRect(outer_, curr_edge, i)); |
544 } | 555 } |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 const LayoutRect& border_rect, | 969 const LayoutRect& border_rect, |
959 const Path& border_path, | 970 const Path& border_path, |
960 float thickness, | 971 float thickness, |
961 float draw_thickness, | 972 float draw_thickness, |
962 BoxSide side, | 973 BoxSide side, |
963 Color color, | 974 Color color, |
964 EBorderStyle border_style) const { | 975 EBorderStyle border_style) const { |
965 if (thickness <= 0) | 976 if (thickness <= 0) |
966 return; | 977 return; |
967 | 978 |
968 if (border_style == kBorderStyleDouble && thickness < 3) | 979 if (border_style == EBorderStyle::kDouble && thickness < 3) |
969 border_style = kBorderStyleSolid; | 980 border_style = EBorderStyle::kSolid; |
970 | 981 |
971 switch (border_style) { | 982 switch (border_style) { |
972 case kBorderStyleNone: | 983 case EBorderStyle::kNone: |
973 case kBorderStyleHidden: | 984 case EBorderStyle::kHidden: |
974 return; | 985 return; |
975 case kBorderStyleDotted: | 986 case EBorderStyle::kDotted: |
976 case kBorderStyleDashed: { | 987 case EBorderStyle::kDashed: { |
977 DrawDashedDottedBoxSideFromPath(graphics_context, border_rect, thickness, | 988 DrawDashedDottedBoxSideFromPath(graphics_context, border_rect, thickness, |
978 draw_thickness, color, border_style); | 989 draw_thickness, color, border_style); |
979 return; | 990 return; |
980 } | 991 } |
981 case kBorderStyleDouble: { | 992 case EBorderStyle::kDouble: { |
982 DrawDoubleBoxSideFromPath(graphics_context, border_rect, border_path, | 993 DrawDoubleBoxSideFromPath(graphics_context, border_rect, border_path, |
983 thickness, draw_thickness, side, color); | 994 thickness, draw_thickness, side, color); |
984 return; | 995 return; |
985 } | 996 } |
986 case kBorderStyleRidge: | 997 case EBorderStyle::kRidge: |
987 case kBorderStyleGroove: { | 998 case EBorderStyle::kGroove: { |
988 DrawRidgeGrooveBoxSideFromPath(graphics_context, border_rect, border_path, | 999 DrawRidgeGrooveBoxSideFromPath(graphics_context, border_rect, border_path, |
989 thickness, draw_thickness, side, color, | 1000 thickness, draw_thickness, side, color, |
990 border_style); | 1001 border_style); |
991 return; | 1002 return; |
992 } | 1003 } |
993 case kBorderStyleInset: | 1004 case EBorderStyle::kInset: |
994 if (side == kBSTop || side == kBSLeft) | 1005 if (side == kBSTop || side == kBSLeft) |
995 color = color.Dark(); | 1006 color = color.Dark(); |
996 break; | 1007 break; |
997 case kBorderStyleOutset: | 1008 case EBorderStyle::kOutset: |
998 if (side == kBSBottom || side == kBSRight) | 1009 if (side == kBSBottom || side == kBSRight) |
999 color = color.Dark(); | 1010 color = color.Dark(); |
1000 break; | 1011 break; |
1001 default: | 1012 default: |
1002 break; | 1013 break; |
1003 } | 1014 } |
1004 | 1015 |
1005 graphics_context.SetStrokeStyle(kNoStroke); | 1016 graphics_context.SetStrokeStyle(kNoStroke); |
1006 graphics_context.SetFillColor(color); | 1017 graphics_context.SetFillColor(color); |
1007 graphics_context.DrawRect(PixelSnappedIntRect(border_rect)); | 1018 graphics_context.DrawRect(PixelSnappedIntRect(border_rect)); |
(...skipping 10 matching lines...) Expand all Loading... |
1018 const LayoutRectOutsets center_offsets( | 1029 const LayoutRectOutsets center_offsets( |
1019 -edges_[kBSTop].UsedWidth() * 0.5, -edges_[kBSRight].UsedWidth() * 0.5, | 1030 -edges_[kBSTop].UsedWidth() * 0.5, -edges_[kBSRight].UsedWidth() * 0.5, |
1020 -edges_[kBSBottom].UsedWidth() * 0.5, -edges_[kBSLeft].UsedWidth() * 0.5); | 1031 -edges_[kBSBottom].UsedWidth() * 0.5, -edges_[kBSLeft].UsedWidth() * 0.5); |
1021 Path centerline_path; | 1032 Path centerline_path; |
1022 centerline_path.AddRoundedRect(style_.GetRoundedInnerBorderFor( | 1033 centerline_path.AddRoundedRect(style_.GetRoundedInnerBorderFor( |
1023 border_rect, center_offsets, include_logical_left_edge_, | 1034 border_rect, center_offsets, include_logical_left_edge_, |
1024 include_logical_right_edge_)); | 1035 include_logical_right_edge_)); |
1025 | 1036 |
1026 graphics_context.SetStrokeColor(color); | 1037 graphics_context.SetStrokeColor(color); |
1027 | 1038 |
1028 if (!StrokeData::StrokeIsDashed(thickness, border_style == kBorderStyleDashed | 1039 if (!StrokeData::StrokeIsDashed( |
1029 ? kDashedStroke | 1040 thickness, border_style == EBorderStyle::kDashed ? kDashedStroke |
1030 : kDottedStroke)) { | 1041 : kDottedStroke)) { |
1031 DrawWideDottedBoxSideFromPath(graphics_context, centerline_path, thickness); | 1042 DrawWideDottedBoxSideFromPath(graphics_context, centerline_path, thickness); |
1032 return; | 1043 return; |
1033 } | 1044 } |
1034 | 1045 |
1035 // The extra multiplier is so that the clipping mask can antialias | 1046 // The extra multiplier is so that the clipping mask can antialias |
1036 // the edges to prevent jaggies. | 1047 // the edges to prevent jaggies. |
1037 graphics_context.SetStrokeThickness(draw_thickness * 1.1f); | 1048 graphics_context.SetStrokeThickness(draw_thickness * 1.1f); |
1038 graphics_context.SetStrokeStyle( | 1049 graphics_context.SetStrokeStyle( |
1039 border_style == kBorderStyleDashed ? kDashedStroke : kDottedStroke); | 1050 border_style == EBorderStyle::kDashed ? kDashedStroke : kDottedStroke); |
1040 | 1051 |
1041 // TODO(schenney): This code for setting up the dash effect is trying to | 1052 // TODO(schenney): This code for setting up the dash effect is trying to |
1042 // do the same thing as StrokeData::setupPaintDashPathEffect and should be | 1053 // do the same thing as StrokeData::setupPaintDashPathEffect and should be |
1043 // refactored to re-use that code. It would require | 1054 // refactored to re-use that code. It would require |
1044 // GraphicsContext::strokePath to take a length parameter. | 1055 // GraphicsContext::strokePath to take a length parameter. |
1045 float dash_length = draw_thickness; | 1056 float dash_length = draw_thickness; |
1046 float gap_length = dash_length; | 1057 float gap_length = dash_length; |
1047 if (border_style == kBorderStyleDashed) { | 1058 if (border_style == EBorderStyle::kDashed) { |
1048 dash_length *= StrokeData::DashLengthRatio(draw_thickness); | 1059 dash_length *= StrokeData::DashLengthRatio(draw_thickness); |
1049 gap_length *= StrokeData::DashGapRatio(draw_thickness); | 1060 gap_length *= StrokeData::DashGapRatio(draw_thickness); |
1050 } | 1061 } |
1051 float path_length = centerline_path.length(); | 1062 float path_length = centerline_path.length(); |
1052 // Don't try to show dashes if we have less than 2 dashes + 2 gaps. | 1063 // Don't try to show dashes if we have less than 2 dashes + 2 gaps. |
1053 // TODO(schenney): should do this test per side. | 1064 // TODO(schenney): should do this test per side. |
1054 if (path_length >= 2 * dash_length + gap_length) { | 1065 if (path_length >= 2 * dash_length + gap_length) { |
1055 float gap = gap_length; | 1066 float gap = gap_length; |
1056 if (border_style == kBorderStyleDashed) | 1067 if (border_style == EBorderStyle::kDashed) |
1057 gap = StrokeData::SelectBestDashGap(path_length, dash_length, gap_length); | 1068 gap = StrokeData::SelectBestDashGap(path_length, dash_length, gap_length); |
1058 DashArray line_dash; | 1069 DashArray line_dash; |
1059 line_dash.push_back(dash_length); | 1070 line_dash.push_back(dash_length); |
1060 line_dash.push_back(gap); | 1071 line_dash.push_back(gap); |
1061 graphics_context.SetLineDash(line_dash, dash_length); | 1072 graphics_context.SetLineDash(line_dash, dash_length); |
1062 } else if (path_length > dash_length) { | 1073 } else if (path_length > dash_length) { |
1063 // Exactly 2 dashes proportionally sized | 1074 // Exactly 2 dashes proportionally sized |
1064 float multiplier = path_length / (2 * dash_length + gap_length); | 1075 float multiplier = path_length / (2 * dash_length + gap_length); |
1065 DashArray line_dash; | 1076 DashArray line_dash; |
1066 line_dash.push_back(dash_length * multiplier); | 1077 line_dash.push_back(dash_length * multiplier); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 { | 1135 { |
1125 GraphicsContextStateSaver state_saver(graphics_context); | 1136 GraphicsContextStateSaver state_saver(graphics_context); |
1126 const LayoutRectOutsets inner_insets = | 1137 const LayoutRectOutsets inner_insets = |
1127 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeInner); | 1138 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeInner); |
1128 FloatRoundedRect inner_clip = style_.GetRoundedInnerBorderFor( | 1139 FloatRoundedRect inner_clip = style_.GetRoundedInnerBorderFor( |
1129 border_rect, inner_insets, include_logical_left_edge_, | 1140 border_rect, inner_insets, include_logical_left_edge_, |
1130 include_logical_right_edge_); | 1141 include_logical_right_edge_); |
1131 | 1142 |
1132 graphics_context.ClipRoundedRect(inner_clip); | 1143 graphics_context.ClipRoundedRect(inner_clip); |
1133 DrawBoxSideFromPath(graphics_context, border_rect, border_path, thickness, | 1144 DrawBoxSideFromPath(graphics_context, border_rect, border_path, thickness, |
1134 draw_thickness, side, color, kBorderStyleSolid); | 1145 draw_thickness, side, color, EBorderStyle::kSolid); |
1135 } | 1146 } |
1136 | 1147 |
1137 // Draw outer border line | 1148 // Draw outer border line |
1138 { | 1149 { |
1139 GraphicsContextStateSaver state_saver(graphics_context); | 1150 GraphicsContextStateSaver state_saver(graphics_context); |
1140 LayoutRect outer_rect = border_rect; | 1151 LayoutRect outer_rect = border_rect; |
1141 LayoutRectOutsets outer_insets = | 1152 LayoutRectOutsets outer_insets = |
1142 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeOuter); | 1153 DoubleStripeInsets(edges_, BorderEdge::kDoubleBorderStripeOuter); |
1143 | 1154 |
1144 if (BleedAvoidanceIsClipping(bleed_avoidance_)) { | 1155 if (BleedAvoidanceIsClipping(bleed_avoidance_)) { |
1145 outer_rect.Inflate(1); | 1156 outer_rect.Inflate(1); |
1146 outer_insets.SetTop(outer_insets.Top() - 1); | 1157 outer_insets.SetTop(outer_insets.Top() - 1); |
1147 outer_insets.SetRight(outer_insets.Right() - 1); | 1158 outer_insets.SetRight(outer_insets.Right() - 1); |
1148 outer_insets.SetBottom(outer_insets.Bottom() - 1); | 1159 outer_insets.SetBottom(outer_insets.Bottom() - 1); |
1149 outer_insets.SetLeft(outer_insets.Left() - 1); | 1160 outer_insets.SetLeft(outer_insets.Left() - 1); |
1150 } | 1161 } |
1151 | 1162 |
1152 FloatRoundedRect outer_clip = style_.GetRoundedInnerBorderFor( | 1163 FloatRoundedRect outer_clip = style_.GetRoundedInnerBorderFor( |
1153 outer_rect, outer_insets, include_logical_left_edge_, | 1164 outer_rect, outer_insets, include_logical_left_edge_, |
1154 include_logical_right_edge_); | 1165 include_logical_right_edge_); |
1155 graphics_context.ClipOutRoundedRect(outer_clip); | 1166 graphics_context.ClipOutRoundedRect(outer_clip); |
1156 DrawBoxSideFromPath(graphics_context, border_rect, border_path, thickness, | 1167 DrawBoxSideFromPath(graphics_context, border_rect, border_path, thickness, |
1157 draw_thickness, side, color, kBorderStyleSolid); | 1168 draw_thickness, side, color, EBorderStyle::kSolid); |
1158 } | 1169 } |
1159 } | 1170 } |
1160 | 1171 |
1161 void BoxBorderPainter::DrawRidgeGrooveBoxSideFromPath( | 1172 void BoxBorderPainter::DrawRidgeGrooveBoxSideFromPath( |
1162 GraphicsContext& graphics_context, | 1173 GraphicsContext& graphics_context, |
1163 const LayoutRect& border_rect, | 1174 const LayoutRect& border_rect, |
1164 const Path& border_path, | 1175 const Path& border_path, |
1165 float thickness, | 1176 float thickness, |
1166 float draw_thickness, | 1177 float draw_thickness, |
1167 BoxSide side, | 1178 BoxSide side, |
1168 Color color, | 1179 Color color, |
1169 EBorderStyle border_style) const { | 1180 EBorderStyle border_style) const { |
1170 EBorderStyle s1; | 1181 EBorderStyle s1; |
1171 EBorderStyle s2; | 1182 EBorderStyle s2; |
1172 if (border_style == kBorderStyleGroove) { | 1183 if (border_style == EBorderStyle::kGroove) { |
1173 s1 = kBorderStyleInset; | 1184 s1 = EBorderStyle::kInset; |
1174 s2 = kBorderStyleOutset; | 1185 s2 = EBorderStyle::kOutset; |
1175 } else { | 1186 } else { |
1176 s1 = kBorderStyleOutset; | 1187 s1 = EBorderStyle::kOutset; |
1177 s2 = kBorderStyleInset; | 1188 s2 = EBorderStyle::kInset; |
1178 } | 1189 } |
1179 | 1190 |
1180 // Paint full border | 1191 // Paint full border |
1181 DrawBoxSideFromPath(graphics_context, border_rect, border_path, thickness, | 1192 DrawBoxSideFromPath(graphics_context, border_rect, border_path, thickness, |
1182 draw_thickness, side, color, s1); | 1193 draw_thickness, side, color, s1); |
1183 | 1194 |
1184 // Paint inner only | 1195 // Paint inner only |
1185 GraphicsContextStateSaver state_saver(graphics_context); | 1196 GraphicsContextStateSaver state_saver(graphics_context); |
1186 int top_width = edges_[kBSTop].UsedWidth() / 2; | 1197 int top_width = edges_[kBSTop].UsedWidth() / 2; |
1187 int bottom_width = edges_[kBSBottom].UsedWidth() / 2; | 1198 int bottom_width = edges_[kBSBottom].UsedWidth() / 2; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 FindIntersection(edge_quad[2], edge_quad[3], bound_quad1, bound_quad2, | 1471 FindIntersection(edge_quad[2], edge_quad[3], bound_quad1, bound_quad2, |
1461 clipping_quad[2]); | 1472 clipping_quad[2]); |
1462 clipping_quad[2] -= extension_offset; | 1473 clipping_quad[2] -= extension_offset; |
1463 clipping_quad[3] = edge_quad[3] - extension_offset; | 1474 clipping_quad[3] = edge_quad[3] - extension_offset; |
1464 | 1475 |
1465 ClipQuad(graphics_context, clipping_quad, second_miter == kSoftMiter); | 1476 ClipQuad(graphics_context, clipping_quad, second_miter == kSoftMiter); |
1466 } | 1477 } |
1467 } | 1478 } |
1468 | 1479 |
1469 } // namespace blink | 1480 } // namespace blink |
OLD | NEW |