| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // - needs a positive adjacent joint width (required by drawLineForBoxSide). | 53 // - needs a positive adjacent joint width (required by drawLineForBoxSide). |
| 54 // A counterclockwise joint: | 54 // A counterclockwise joint: |
| 55 // - needs to increase the edge length to include the joint; | 55 // - needs to increase the edge length to include the joint; |
| 56 // - needs a negative adjacent joint width (required by drawLineForBoxSide). | 56 // - needs a negative adjacent joint width (required by drawLineForBoxSide). |
| 57 switch (edge1.side) { | 57 switch (edge1.side) { |
| 58 case BSTop: | 58 case BSTop: |
| 59 switch (edge2.side) { | 59 switch (edge2.side) { |
| 60 case BSRight: // Clockwise | 60 case BSRight: // Clockwise |
| 61 return outlineWidth; | 61 return outlineWidth; |
| 62 case BSLeft: // Counterclockwise | 62 case BSLeft: // Counterclockwise |
| 63 edge1.x2 = saturatedAddition(edge1.x2, outlineWidth); | 63 edge1.x2 += outlineWidth; |
| 64 edge2.y2 = saturatedAddition(edge2.y2, outlineWidth); | 64 edge2.y2 += outlineWidth; |
| 65 return -outlineWidth; | 65 return -outlineWidth; |
| 66 default: // Same side or no joint. | 66 default: // Same side or no joint. |
| 67 return 0; | 67 return 0; |
| 68 } | 68 } |
| 69 case BSRight: | 69 case BSRight: |
| 70 switch (edge2.side) { | 70 switch (edge2.side) { |
| 71 case BSBottom: // Clockwise | 71 case BSBottom: // Clockwise |
| 72 return outlineWidth; | 72 return outlineWidth; |
| 73 case BSTop: // Counterclockwise | 73 case BSTop: // Counterclockwise |
| 74 edge1.y2 = saturatedAddition(edge1.y2, outlineWidth); | 74 edge1.y2 += outlineWidth; |
| 75 edge2.x1 = saturatedSubtraction(edge2.x1, outlineWidth); | 75 edge2.x1 -= outlineWidth; |
| 76 return -outlineWidth; | 76 return -outlineWidth; |
| 77 default: // Same side or no joint. | 77 default: // Same side or no joint. |
| 78 return 0; | 78 return 0; |
| 79 } | 79 } |
| 80 case BSBottom: | 80 case BSBottom: |
| 81 switch (edge2.side) { | 81 switch (edge2.side) { |
| 82 case BSLeft: // Clockwise | 82 case BSLeft: // Clockwise |
| 83 return outlineWidth; | 83 return outlineWidth; |
| 84 case BSRight: // Counterclockwise | 84 case BSRight: // Counterclockwise |
| 85 edge1.x1 = saturatedSubtraction(edge1.x1, outlineWidth); | 85 edge1.x1 -= outlineWidth; |
| 86 edge2.y1 = saturatedSubtraction(edge2.y1, outlineWidth); | 86 edge2.y1 -= outlineWidth; |
| 87 return -outlineWidth; | 87 return -outlineWidth; |
| 88 default: // Same side or no joint. | 88 default: // Same side or no joint. |
| 89 return 0; | 89 return 0; |
| 90 } | 90 } |
| 91 case BSLeft: | 91 case BSLeft: |
| 92 switch (edge2.side) { | 92 switch (edge2.side) { |
| 93 case BSTop: // Clockwise | 93 case BSTop: // Clockwise |
| 94 return outlineWidth; | 94 return outlineWidth; |
| 95 case BSBottom: // Counterclockwise | 95 case BSBottom: // Counterclockwise |
| 96 edge1.y1 = saturatedSubtraction(edge1.y1, outlineWidth); | 96 edge1.y1 -= outlineWidth; |
| 97 edge2.x2 = saturatedAddition(edge2.x2, outlineWidth); | 97 edge2.x2 += outlineWidth; |
| 98 return -outlineWidth; | 98 return -outlineWidth; |
| 99 default: // Same side or no joint. | 99 default: // Same side or no joint. |
| 100 return 0; | 100 return 0; |
| 101 } | 101 } |
| 102 default: | 102 default: |
| 103 ASSERT_NOT_REACHED(); | 103 ASSERT_NOT_REACHED(); |
| 104 return 0; | 104 return 0; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 135 continue; | 135 continue; |
| 136 | 136 |
| 137 edges.grow(++count); | 137 edges.grow(++count); |
| 138 OutlineEdgeInfo& edge = edges.last(); | 138 OutlineEdgeInfo& edge = edges.last(); |
| 139 edge.x1 = SkScalarTruncToInt(points[0].x()); | 139 edge.x1 = SkScalarTruncToInt(points[0].x()); |
| 140 edge.y1 = SkScalarTruncToInt(points[0].y()); | 140 edge.y1 = SkScalarTruncToInt(points[0].y()); |
| 141 edge.x2 = SkScalarTruncToInt(points[1].x()); | 141 edge.x2 = SkScalarTruncToInt(points[1].x()); |
| 142 edge.y2 = SkScalarTruncToInt(points[1].y()); | 142 edge.y2 = SkScalarTruncToInt(points[1].y()); |
| 143 if (edge.x1 == edge.x2) { | 143 if (edge.x1 == edge.x2) { |
| 144 if (edge.y1 < edge.y2) { | 144 if (edge.y1 < edge.y2) { |
| 145 edge.x1 = saturatedSubtraction(edge.x1, width); | 145 edge.x1 -= width; |
| 146 edge.side = BSRight; | 146 edge.side = BSRight; |
| 147 } else { | 147 } else { |
| 148 std::swap(edge.y1, edge.y2); | 148 std::swap(edge.y1, edge.y2); |
| 149 edge.x2 = saturatedAddition(edge.x2, width); | 149 edge.x2 += width; |
| 150 edge.side = BSLeft; | 150 edge.side = BSLeft; |
| 151 } | 151 } |
| 152 } else { | 152 } else { |
| 153 ASSERT(edge.y1 == edge.y2); | 153 ASSERT(edge.y1 == edge.y2); |
| 154 if (edge.x1 < edge.x2) { | 154 if (edge.x1 < edge.x2) { |
| 155 edge.y2 = saturatedAddition(edge.y2, width); | 155 edge.y2 += width; |
| 156 edge.side = BSTop; | 156 edge.side = BSTop; |
| 157 } else { | 157 } else { |
| 158 std::swap(edge.x1, edge.x2); | 158 std::swap(edge.x1, edge.x2); |
| 159 edge.y1 = saturatedSubtraction(edge.y1, width); | 159 edge.y1 -= width; |
| 160 edge.side = BSBottom; | 160 edge.side = BSBottom; |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 if (!count) | 165 if (!count) |
| 166 return; | 166 return; |
| 167 | 167 |
| 168 Color outlineColor = color; | 168 Color outlineColor = color; |
| 169 bool useTransparencyLayer = color.hasAlpha(); | 169 bool useTransparencyLayer = color.hasAlpha(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 path.lineTo(quad[1]); | 208 path.lineTo(quad[1]); |
| 209 path.lineTo(quad[2]); | 209 path.lineTo(quad[2]); |
| 210 path.lineTo(quad[3]); | 210 path.lineTo(quad[3]); |
| 211 SkPaint paint(context.fillPaint()); | 211 SkPaint paint(context.fillPaint()); |
| 212 paint.setAntiAlias(antialias); | 212 paint.setAntiAlias(antialias); |
| 213 paint.setColor(color.rgb()); | 213 paint.setColor(color.rgb()); |
| 214 | 214 |
| 215 context.drawPath(path, paint); | 215 context.drawPath(path, paint); |
| 216 } | 216 } |
| 217 | 217 |
| 218 int thirdOfDouble(int width) { | |
| 219 return std::max((width * 2 + 1) / 3, 0); | |
| 220 } | |
| 221 | |
| 222 } // namespace | 218 } // namespace |
| 223 | 219 |
| 224 void ObjectPainter::paintOutline(const PaintInfo& paintInfo, | 220 void ObjectPainter::paintOutline(const PaintInfo& paintInfo, |
| 225 const LayoutPoint& paintOffset) { | 221 const LayoutPoint& paintOffset) { |
| 226 ASSERT(shouldPaintSelfOutline(paintInfo.phase)); | 222 ASSERT(shouldPaintSelfOutline(paintInfo.phase)); |
| 227 | 223 |
| 228 const ComputedStyle& styleToUse = m_layoutObject.styleRef(); | 224 const ComputedStyle& styleToUse = m_layoutObject.styleRef(); |
| 229 if (!styleToUse.hasOutline() || | 225 if (!styleToUse.hasOutline() || |
| 230 styleToUse.visibility() != EVisibility::Visible) | 226 styleToUse.visibility() != EVisibility::Visible) |
| 231 return; | 227 return; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 int y2, | 343 int y2, |
| 348 BoxSide side, | 344 BoxSide side, |
| 349 Color color, | 345 Color color, |
| 350 EBorderStyle style, | 346 EBorderStyle style, |
| 351 int adjacentWidth1, | 347 int adjacentWidth1, |
| 352 int adjacentWidth2, | 348 int adjacentWidth2, |
| 353 bool antialias) { | 349 bool antialias) { |
| 354 int thickness; | 350 int thickness; |
| 355 int length; | 351 int length; |
| 356 if (side == BSTop || side == BSBottom) { | 352 if (side == BSTop || side == BSBottom) { |
| 357 thickness = saturatedSubtraction(y2, y1); | 353 thickness = y2 - y1; |
| 358 length = saturatedSubtraction(x2, x1); | 354 length = x2 - x1; |
| 359 } else { | 355 } else { |
| 360 thickness = saturatedSubtraction(x2, x1); | 356 thickness = x2 - x1; |
| 361 length = saturatedSubtraction(y2, y1); | 357 length = y2 - y1; |
| 362 } | 358 } |
| 363 | 359 |
| 364 // We would like this check to be an ASSERT as we don't want to draw empty | 360 // 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 | 361 // borders. However nothing guarantees that the following recursive calls to |
| 366 // drawLineForBoxSide will have positive thickness and length. | 362 // drawLineForBoxSide will have positive thickness and length. |
| 367 if (length <= 0 || thickness <= 0) | 363 if (length <= 0 || thickness <= 0) |
| 368 return; | 364 return; |
| 369 | 365 |
| 370 if (style == BorderStyleDouble && thickness < 3) | 366 if (style == BorderStyleDouble && thickness < 3) |
| 371 style = BorderStyleSolid; | 367 style = BorderStyleSolid; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 StrokeStyle oldStrokeStyle = graphicsContext.getStrokeStyle(); | 418 StrokeStyle oldStrokeStyle = graphicsContext.getStrokeStyle(); |
| 423 graphicsContext.setShouldAntialias(antialias); | 419 graphicsContext.setShouldAntialias(antialias); |
| 424 graphicsContext.setStrokeColor(color); | 420 graphicsContext.setStrokeColor(color); |
| 425 graphicsContext.setStrokeThickness(thickness); | 421 graphicsContext.setStrokeThickness(thickness); |
| 426 graphicsContext.setStrokeStyle(style == BorderStyleDashed ? DashedStroke | 422 graphicsContext.setStrokeStyle(style == BorderStyleDashed ? DashedStroke |
| 427 : DottedStroke); | 423 : DottedStroke); |
| 428 | 424 |
| 429 switch (side) { | 425 switch (side) { |
| 430 case BSBottom: | 426 case BSBottom: |
| 431 case BSTop: { | 427 case BSTop: { |
| 432 int midY = saturatedAddition(y1, thickness / 2); | 428 int midY = y1 + thickness / 2; |
| 433 graphicsContext.drawLine(IntPoint(x1, midY), IntPoint(x2, midY)); | 429 graphicsContext.drawLine(IntPoint(x1, midY), IntPoint(x2, midY)); |
| 434 break; | 430 break; |
| 435 } | 431 } |
| 436 case BSRight: | 432 case BSRight: |
| 437 case BSLeft: { | 433 case BSLeft: { |
| 438 int midX = saturatedAddition(x1, thickness / 2); | 434 int midX = x1 + thickness / 2; |
| 439 graphicsContext.drawLine(IntPoint(midX, y1), IntPoint(midX, y2)); | 435 graphicsContext.drawLine(IntPoint(midX, y1), IntPoint(midX, y2)); |
| 440 break; | 436 break; |
| 441 } | 437 } |
| 442 } | 438 } |
| 443 graphicsContext.setShouldAntialias(wasAntialiased); | 439 graphicsContext.setShouldAntialias(wasAntialiased); |
| 444 graphicsContext.setStrokeStyle(oldStrokeStyle); | 440 graphicsContext.setStrokeStyle(oldStrokeStyle); |
| 445 } | 441 } |
| 446 | 442 |
| 447 void ObjectPainter::drawDoubleBoxSide(GraphicsContext& graphicsContext, | 443 void ObjectPainter::drawDoubleBoxSide(GraphicsContext& graphicsContext, |
| 448 int x1, | 444 int x1, |
| 449 int y1, | 445 int y1, |
| 450 int x2, | 446 int x2, |
| 451 int y2, | 447 int y2, |
| 452 int length, | 448 int length, |
| 453 BoxSide side, | 449 BoxSide side, |
| 454 Color color, | 450 Color color, |
| 455 int thickness, | 451 int thickness, |
| 456 int adjacentWidth1, | 452 int adjacentWidth1, |
| 457 int adjacentWidth2, | 453 int adjacentWidth2, |
| 458 bool antialias) { | 454 bool antialias) { |
| 459 int thirdOfThickness = saturatedAddition(thickness, 1) / 3; | 455 int thirdOfThickness = (thickness + 1) / 3; |
| 460 ASSERT(thirdOfThickness > 0); | 456 ASSERT(thirdOfThickness > 0); |
| 461 | 457 |
| 462 if (!adjacentWidth1 && !adjacentWidth2) { | 458 if (!adjacentWidth1 && !adjacentWidth2) { |
| 463 StrokeStyle oldStrokeStyle = graphicsContext.getStrokeStyle(); | 459 StrokeStyle oldStrokeStyle = graphicsContext.getStrokeStyle(); |
| 464 graphicsContext.setStrokeStyle(NoStroke); | 460 graphicsContext.setStrokeStyle(NoStroke); |
| 465 graphicsContext.setFillColor(color); | 461 graphicsContext.setFillColor(color); |
| 466 | 462 |
| 467 bool wasAntialiased = graphicsContext.shouldAntialias(); | 463 bool wasAntialiased = graphicsContext.shouldAntialias(); |
| 468 graphicsContext.setShouldAntialias(antialias); | 464 graphicsContext.setShouldAntialias(antialias); |
| 469 | 465 |
| 470 switch (side) { | 466 switch (side) { |
| 471 case BSTop: | 467 case BSTop: |
| 472 case BSBottom: | 468 case BSBottom: |
| 473 graphicsContext.drawRect(IntRect(x1, y1, length, thirdOfThickness)); | 469 graphicsContext.drawRect(IntRect(x1, y1, length, thirdOfThickness)); |
| 474 graphicsContext.drawRect( | 470 graphicsContext.drawRect( |
| 475 IntRect(x1, saturatedSubtraction(y2, thirdOfThickness), length, | 471 IntRect(x1, y2 - thirdOfThickness, length, thirdOfThickness)); |
| 476 thirdOfThickness)); | |
| 477 break; | 472 break; |
| 478 case BSLeft: | 473 case BSLeft: |
| 479 case BSRight: | 474 case BSRight: |
| 480 graphicsContext.drawRect(IntRect(x1, y1, thirdOfThickness, length)); | 475 graphicsContext.drawRect(IntRect(x1, y1, thirdOfThickness, length)); |
| 481 graphicsContext.drawRect( | 476 graphicsContext.drawRect( |
| 482 IntRect(saturatedSubtraction(x2, thirdOfThickness), y1, | 477 IntRect(x2 - thirdOfThickness, y1, thirdOfThickness, length)); |
| 483 thirdOfThickness, length)); | |
| 484 break; | 478 break; |
| 485 } | 479 } |
| 486 | 480 |
| 487 graphicsContext.setShouldAntialias(wasAntialiased); | 481 graphicsContext.setShouldAntialias(wasAntialiased); |
| 488 graphicsContext.setStrokeStyle(oldStrokeStyle); | 482 graphicsContext.setStrokeStyle(oldStrokeStyle); |
| 489 return; | 483 return; |
| 490 } | 484 } |
| 491 | 485 |
| 492 int adjacent1BigThird = | 486 int adjacent1BigThird = |
| 493 ((adjacentWidth1 > 0) ? saturatedAddition(adjacentWidth1, 1) | 487 ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 3; |
| 494 : saturatedSubtraction(adjacentWidth1, 1)) / | |
| 495 3; | |
| 496 int adjacent2BigThird = | 488 int adjacent2BigThird = |
| 497 ((adjacentWidth2 > 0) ? saturatedAddition(adjacentWidth2, 1) | 489 ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 3; |
| 498 : saturatedSubtraction(adjacentWidth2, 1)) / | |
| 499 3; | |
| 500 | 490 |
| 501 switch (side) { | 491 switch (side) { |
| 502 case BSTop: | 492 case BSTop: |
| 493 drawLineForBoxSide(graphicsContext, |
| 494 x1 + std::max((-adjacentWidth1 * 2 + 1) / 3, 0), y1, |
| 495 x2 - std::max((-adjacentWidth2 * 2 + 1) / 3, 0), |
| 496 y1 + thirdOfThickness, side, color, BorderStyleSolid, |
| 497 adjacent1BigThird, adjacent2BigThird, antialias); |
| 503 drawLineForBoxSide( | 498 drawLineForBoxSide( |
| 504 graphicsContext, | 499 graphicsContext, x1 + std::max((adjacentWidth1 * 2 + 1) / 3, 0), |
| 505 saturatedAddition(x1, thirdOfDouble(-adjacentWidth1)), y1, | 500 y2 - thirdOfThickness, x2 - std::max((adjacentWidth2 * 2 + 1) / 3, 0), |
| 506 saturatedSubtraction(x2, thirdOfDouble(-adjacentWidth2)), | 501 y2, side, color, BorderStyleSolid, adjacent1BigThird, |
| 507 saturatedAddition(y1, thirdOfThickness), side, color, | 502 adjacent2BigThird, antialias); |
| 508 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); | |
| 509 drawLineForBoxSide( | |
| 510 graphicsContext, saturatedAddition(x1, thirdOfDouble(adjacentWidth1)), | |
| 511 saturatedSubtraction(y2, thirdOfThickness), | |
| 512 saturatedSubtraction(x2, thirdOfDouble(adjacentWidth2)), y2, side, | |
| 513 color, BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, | |
| 514 antialias); | |
| 515 break; | 503 break; |
| 516 case BSLeft: | 504 case BSLeft: |
| 517 drawLineForBoxSide( | 505 drawLineForBoxSide( |
| 518 graphicsContext, x1, | 506 graphicsContext, x1, y1 + std::max((-adjacentWidth1 * 2 + 1) / 3, 0), |
| 519 saturatedAddition(y1, thirdOfDouble(-adjacentWidth1)), | 507 x1 + thirdOfThickness, |
| 520 saturatedAddition(x1, thirdOfThickness), | 508 y2 - std::max((-adjacentWidth2 * 2 + 1) / 3, 0), side, color, |
| 521 saturatedSubtraction(y2, thirdOfDouble(-adjacentWidth2)), side, color, | |
| 522 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); | 509 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); |
| 523 drawLineForBoxSide( | 510 drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, |
| 524 graphicsContext, saturatedSubtraction(x2, thirdOfThickness), | 511 y1 + std::max((adjacentWidth1 * 2 + 1) / 3, 0), x2, |
| 525 saturatedAddition(y1, thirdOfDouble(adjacentWidth1)), x2, | 512 y2 - std::max((adjacentWidth2 * 2 + 1) / 3, 0), side, |
| 526 saturatedSubtraction(y2, thirdOfDouble(adjacentWidth2)), side, color, | 513 color, BorderStyleSolid, adjacent1BigThird, |
| 527 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); | 514 adjacent2BigThird, antialias); |
| 528 break; | 515 break; |
| 529 case BSBottom: | 516 case BSBottom: |
| 517 drawLineForBoxSide(graphicsContext, |
| 518 x1 + std::max((adjacentWidth1 * 2 + 1) / 3, 0), y1, |
| 519 x2 - std::max((adjacentWidth2 * 2 + 1) / 3, 0), |
| 520 y1 + thirdOfThickness, side, color, BorderStyleSolid, |
| 521 adjacent1BigThird, adjacent2BigThird, antialias); |
| 530 drawLineForBoxSide( | 522 drawLineForBoxSide( |
| 531 graphicsContext, saturatedAddition(x1, thirdOfDouble(adjacentWidth1)), | 523 graphicsContext, x1 + std::max((-adjacentWidth1 * 2 + 1) / 3, 0), |
| 532 y1, saturatedSubtraction(x2, thirdOfDouble(adjacentWidth2)), | 524 y2 - thirdOfThickness, |
| 533 saturatedAddition(y1, thirdOfThickness), side, color, | 525 x2 - std::max((-adjacentWidth2 * 2 + 1) / 3, 0), y2, side, color, |
| 534 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); | 526 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); |
| 535 drawLineForBoxSide( | |
| 536 graphicsContext, | |
| 537 saturatedAddition(x1, thirdOfDouble(-adjacentWidth1)), | |
| 538 saturatedSubtraction(y2, thirdOfThickness), | |
| 539 saturatedSubtraction(x2, thirdOfDouble(-adjacentWidth2)), y2, side, | |
| 540 color, BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, | |
| 541 antialias); | |
| 542 break; | 527 break; |
| 543 case BSRight: | 528 case BSRight: |
| 544 drawLineForBoxSide( | 529 drawLineForBoxSide( |
| 545 graphicsContext, x1, | 530 graphicsContext, x1, y1 + std::max((adjacentWidth1 * 2 + 1) / 3, 0), |
| 546 saturatedAddition(y1, thirdOfDouble(adjacentWidth1)), | 531 x1 + thirdOfThickness, y2 - std::max((adjacentWidth2 * 2 + 1) / 3, 0), |
| 547 saturatedAddition(x1, thirdOfThickness), | 532 side, color, BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, |
| 548 saturatedSubtraction(y2, thirdOfDouble(adjacentWidth2)), side, color, | 533 antialias); |
| 549 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); | 534 drawLineForBoxSide(graphicsContext, x2 - thirdOfThickness, |
| 550 drawLineForBoxSide( | 535 y1 + std::max((-adjacentWidth1 * 2 + 1) / 3, 0), x2, |
| 551 graphicsContext, saturatedSubtraction(x2, thirdOfThickness), | 536 y2 - std::max((-adjacentWidth2 * 2 + 1) / 3, 0), side, |
| 552 saturatedAddition(y1, thirdOfDouble(-adjacentWidth1)), x2, | 537 color, BorderStyleSolid, adjacent1BigThird, |
| 553 saturatedSubtraction(y2, thirdOfDouble(-adjacentWidth2)), side, color, | 538 adjacent2BigThird, antialias); |
| 554 BorderStyleSolid, adjacent1BigThird, adjacent2BigThird, antialias); | |
| 555 break; | 539 break; |
| 556 default: | 540 default: |
| 557 break; | 541 break; |
| 558 } | 542 } |
| 559 } | 543 } |
| 560 | 544 |
| 561 void ObjectPainter::drawRidgeOrGrooveBoxSide(GraphicsContext& graphicsContext, | 545 void ObjectPainter::drawRidgeOrGrooveBoxSide(GraphicsContext& graphicsContext, |
| 562 int x1, | 546 int x1, |
| 563 int y1, | 547 int y1, |
| 564 int x2, | 548 int x2, |
| 565 int y2, | 549 int y2, |
| 566 BoxSide side, | 550 BoxSide side, |
| 567 Color color, | 551 Color color, |
| 568 EBorderStyle style, | 552 EBorderStyle style, |
| 569 int adjacentWidth1, | 553 int adjacentWidth1, |
| 570 int adjacentWidth2, | 554 int adjacentWidth2, |
| 571 bool antialias) { | 555 bool antialias) { |
| 572 EBorderStyle s1; | 556 EBorderStyle s1; |
| 573 EBorderStyle s2; | 557 EBorderStyle s2; |
| 574 if (style == BorderStyleGroove) { | 558 if (style == BorderStyleGroove) { |
| 575 s1 = BorderStyleInset; | 559 s1 = BorderStyleInset; |
| 576 s2 = BorderStyleOutset; | 560 s2 = BorderStyleOutset; |
| 577 } else { | 561 } else { |
| 578 s1 = BorderStyleOutset; | 562 s1 = BorderStyleOutset; |
| 579 s2 = BorderStyleInset; | 563 s2 = BorderStyleInset; |
| 580 } | 564 } |
| 581 | 565 |
| 582 int adjacent1BigHalf = | 566 int adjacent1BigHalf = |
| 583 ((adjacentWidth1 > 0) ? saturatedAddition(adjacentWidth1, 1) | 567 ((adjacentWidth1 > 0) ? adjacentWidth1 + 1 : adjacentWidth1 - 1) / 2; |
| 584 : saturatedSubtraction(adjacentWidth1, 1)) / | |
| 585 2; | |
| 586 int adjacent2BigHalf = | 568 int adjacent2BigHalf = |
| 587 ((adjacentWidth2 > 0) ? saturatedAddition(adjacentWidth2, 1) | 569 ((adjacentWidth2 > 0) ? adjacentWidth2 + 1 : adjacentWidth2 - 1) / 2; |
| 588 : saturatedSubtraction(adjacentWidth2, 1)) / | |
| 589 2; | |
| 590 | 570 |
| 591 switch (side) { | 571 switch (side) { |
| 592 case BSTop: | 572 case BSTop: |
| 573 drawLineForBoxSide(graphicsContext, x1 + std::max(-adjacentWidth1, 0) / 2, |
| 574 y1, x2 - std::max(-adjacentWidth2, 0) / 2, |
| 575 (y1 + y2 + 1) / 2, side, color, s1, adjacent1BigHalf, |
| 576 adjacent2BigHalf, antialias); |
| 593 drawLineForBoxSide( | 577 drawLineForBoxSide( |
| 594 graphicsContext, | 578 graphicsContext, x1 + std::max(adjacentWidth1 + 1, 0) / 2, |
| 595 saturatedAddition(x1, std::max(-adjacentWidth1, 0) / 2), y1, | 579 (y1 + y2 + 1) / 2, x2 - std::max(adjacentWidth2 + 1, 0) / 2, y2, side, |
| 596 saturatedSubtraction(x2, std::max(-adjacentWidth2, 0) / 2), | 580 color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias); |
| 597 saturatedAddition(y1, saturatedAddition(y2, 1)) / 2, side, color, s1, | |
| 598 adjacent1BigHalf, adjacent2BigHalf, antialias); | |
| 599 drawLineForBoxSide( | |
| 600 graphicsContext, | |
| 601 saturatedAddition( | |
| 602 x1, std::max(saturatedAddition(adjacentWidth1, 1), 0) / 2), | |
| 603 saturatedAddition(y1, saturatedAddition(y2, 1)) / 2, | |
| 604 saturatedSubtraction( | |
| 605 x2, std::max(saturatedAddition(adjacentWidth2, 1), 0) / 2), | |
| 606 y2, side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, | |
| 607 antialias); | |
| 608 break; | 581 break; |
| 609 case BSLeft: | 582 case BSLeft: |
| 610 drawLineForBoxSide( | 583 drawLineForBoxSide( |
| 611 graphicsContext, x1, | 584 graphicsContext, x1, y1 + std::max(-adjacentWidth1, 0) / 2, |
| 612 saturatedAddition(y1, std::max(-adjacentWidth1, 0) / 2), | 585 (x1 + x2 + 1) / 2, y2 - std::max(-adjacentWidth2, 0) / 2, side, color, |
| 613 saturatedAddition(x1, saturatedAddition(x2, 1)) / 2, | 586 s1, adjacent1BigHalf, adjacent2BigHalf, antialias); |
| 614 saturatedSubtraction(y2, std::max(-adjacentWidth2, 0) / 2), side, | 587 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, |
| 615 color, s1, adjacent1BigHalf, adjacent2BigHalf, antialias); | 588 y1 + std::max(adjacentWidth1 + 1, 0) / 2, x2, |
| 616 drawLineForBoxSide( | 589 y2 - std::max(adjacentWidth2 + 1, 0) / 2, side, color, |
| 617 graphicsContext, saturatedAddition(x1, saturatedAddition(x2, 1)) / 2, | 590 s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias); |
| 618 saturatedAddition( | |
| 619 y1, std::max(saturatedAddition(adjacentWidth1, 1), 0) / 2), | |
| 620 x2, saturatedSubtraction( | |
| 621 y2, std::max(saturatedAddition(adjacentWidth2, 1), 0) / 2), | |
| 622 side, color, s2, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias); | |
| 623 break; | 591 break; |
| 624 case BSBottom: | 592 case BSBottom: |
| 593 drawLineForBoxSide(graphicsContext, x1 + std::max(adjacentWidth1, 0) / 2, |
| 594 y1, x2 - std::max(adjacentWidth2, 0) / 2, |
| 595 (y1 + y2 + 1) / 2, side, color, s2, adjacent1BigHalf, |
| 596 adjacent2BigHalf, antialias); |
| 625 drawLineForBoxSide( | 597 drawLineForBoxSide( |
| 626 graphicsContext, | 598 graphicsContext, x1 + std::max(-adjacentWidth1 + 1, 0) / 2, |
| 627 saturatedAddition(x1, std::max(adjacentWidth1, 0) / 2), y1, | 599 (y1 + y2 + 1) / 2, x2 - std::max(-adjacentWidth2 + 1, 0) / 2, y2, |
| 628 saturatedSubtraction(x2, std::max(adjacentWidth2, 0) / 2), | 600 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias); |
| 629 saturatedAddition(y1, saturatedAddition(y2, 1)) / 2, side, color, s2, | |
| 630 adjacent1BigHalf, adjacent2BigHalf, antialias); | |
| 631 drawLineForBoxSide( | |
| 632 graphicsContext, | |
| 633 saturatedAddition( | |
| 634 x1, std::max(saturatedAddition(-adjacentWidth1, 1), 0) / 2), | |
| 635 saturatedAddition(y1, saturatedAddition(y2, 1)) / 2, | |
| 636 saturatedSubtraction( | |
| 637 x2, std::max(saturatedAddition(-adjacentWidth2, 1), 0) / 2), | |
| 638 y2, side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, | |
| 639 antialias); | |
| 640 break; | 601 break; |
| 641 case BSRight: | 602 case BSRight: |
| 642 drawLineForBoxSide( | 603 drawLineForBoxSide( |
| 643 graphicsContext, x1, | 604 graphicsContext, x1, y1 + std::max(adjacentWidth1, 0) / 2, |
| 644 saturatedAddition(y1, std::max(adjacentWidth1, 0) / 2), | 605 (x1 + x2 + 1) / 2, y2 - std::max(adjacentWidth2, 0) / 2, side, color, |
| 645 saturatedAddition(x1, saturatedAddition(x2, 1)) / 2, | 606 s2, adjacent1BigHalf, adjacent2BigHalf, antialias); |
| 646 saturatedSubtraction(y2, std::max(adjacentWidth2, 0) / 2), side, | 607 drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, |
| 647 color, s2, adjacent1BigHalf, adjacent2BigHalf, antialias); | 608 y1 + std::max(-adjacentWidth1 + 1, 0) / 2, x2, |
| 648 drawLineForBoxSide( | 609 y2 - std::max(-adjacentWidth2 + 1, 0) / 2, side, color, |
| 649 graphicsContext, saturatedAddition(x1, saturatedAddition(x2, 1)) / 2, | 610 s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias); |
| 650 saturatedAddition( | |
| 651 y1, std::max(saturatedAddition(-adjacentWidth1, 1), 0) / 2), | |
| 652 x2, saturatedSubtraction( | |
| 653 y2, std::max(saturatedAddition(-adjacentWidth2, 1), 0) / 2), | |
| 654 side, color, s1, adjacentWidth1 / 2, adjacentWidth2 / 2, antialias); | |
| 655 break; | 611 break; |
| 656 } | 612 } |
| 657 } | 613 } |
| 658 | 614 |
| 659 void ObjectPainter::drawSolidBoxSide(GraphicsContext& graphicsContext, | 615 void ObjectPainter::drawSolidBoxSide(GraphicsContext& graphicsContext, |
| 660 int x1, | 616 int x1, |
| 661 int y1, | 617 int y1, |
| 662 int x2, | 618 int x2, |
| 663 int y2, | 619 int y2, |
| 664 BoxSide side, | 620 BoxSide side, |
| 665 Color color, | 621 Color color, |
| 666 int adjacentWidth1, | 622 int adjacentWidth1, |
| 667 int adjacentWidth2, | 623 int adjacentWidth2, |
| 668 bool antialias) { | 624 bool antialias) { |
| 669 ASSERT(x2 >= x1); | 625 ASSERT(x2 >= x1); |
| 670 ASSERT(y2 >= y1); | 626 ASSERT(y2 >= y1); |
| 671 | 627 |
| 672 if (!adjacentWidth1 && !adjacentWidth2) { | 628 if (!adjacentWidth1 && !adjacentWidth2) { |
| 673 // Tweak antialiasing to match the behavior of fillQuad(); | 629 // Tweak antialiasing to match the behavior of fillQuad(); |
| 674 // this matters for rects in transformed contexts. | 630 // this matters for rects in transformed contexts. |
| 675 bool wasAntialiased = graphicsContext.shouldAntialias(); | 631 bool wasAntialiased = graphicsContext.shouldAntialias(); |
| 676 if (antialias != wasAntialiased) | 632 if (antialias != wasAntialiased) |
| 677 graphicsContext.setShouldAntialias(antialias); | 633 graphicsContext.setShouldAntialias(antialias); |
| 678 graphicsContext.fillRect(IntRect(x1, y1, saturatedSubtraction(x2, x1), | 634 graphicsContext.fillRect(IntRect(x1, y1, x2 - x1, y2 - y1), color); |
| 679 saturatedSubtraction(y2, y1)), | |
| 680 color); | |
| 681 if (antialias != wasAntialiased) | 635 if (antialias != wasAntialiased) |
| 682 graphicsContext.setShouldAntialias(wasAntialiased); | 636 graphicsContext.setShouldAntialias(wasAntialiased); |
| 683 return; | 637 return; |
| 684 } | 638 } |
| 685 | 639 |
| 686 FloatPoint quad[4]; | 640 FloatPoint quad[4]; |
| 687 switch (side) { | 641 switch (side) { |
| 688 case BSTop: | 642 case BSTop: |
| 689 quad[0] = | 643 quad[0] = FloatPoint(x1 + std::max(-adjacentWidth1, 0), y1); |
| 690 FloatPoint(saturatedAddition(x1, std::max(-adjacentWidth1, 0)), y1); | 644 quad[1] = FloatPoint(x1 + std::max(adjacentWidth1, 0), y2); |
| 691 quad[1] = | 645 quad[2] = FloatPoint(x2 - std::max(adjacentWidth2, 0), y2); |
| 692 FloatPoint(saturatedAddition(x1, std::max(adjacentWidth1, 0)), y2); | 646 quad[3] = FloatPoint(x2 - std::max(-adjacentWidth2, 0), y1); |
| 693 quad[2] = | |
| 694 FloatPoint(saturatedSubtraction(x2, std::max(adjacentWidth2, 0)), y2); | |
| 695 quad[3] = FloatPoint( | |
| 696 saturatedSubtraction(x2, std::max(-adjacentWidth2, 0)), y1); | |
| 697 break; | 647 break; |
| 698 case BSBottom: | 648 case BSBottom: |
| 699 quad[0] = | 649 quad[0] = FloatPoint(x1 + std::max(adjacentWidth1, 0), y1); |
| 700 FloatPoint(saturatedAddition(x1, std::max(adjacentWidth1, 0)), y1); | 650 quad[1] = FloatPoint(x1 + std::max(-adjacentWidth1, 0), y2); |
| 701 quad[1] = | 651 quad[2] = FloatPoint(x2 - std::max(-adjacentWidth2, 0), y2); |
| 702 FloatPoint(saturatedAddition(x1, std::max(-adjacentWidth1, 0)), y2); | 652 quad[3] = FloatPoint(x2 - std::max(adjacentWidth2, 0), y1); |
| 703 quad[2] = FloatPoint( | |
| 704 saturatedSubtraction(x2, std::max(-adjacentWidth2, 0)), y2); | |
| 705 quad[3] = | |
| 706 FloatPoint(saturatedSubtraction(x2, std::max(adjacentWidth2, 0)), y1); | |
| 707 break; | 653 break; |
| 708 case BSLeft: | 654 case BSLeft: |
| 709 quad[0] = | 655 quad[0] = FloatPoint(x1, y1 + std::max(-adjacentWidth1, 0)); |
| 710 FloatPoint(x1, saturatedAddition(y1, std::max(-adjacentWidth1, 0))); | 656 quad[1] = FloatPoint(x1, y2 - std::max(-adjacentWidth2, 0)); |
| 711 quad[1] = FloatPoint( | 657 quad[2] = FloatPoint(x2, y2 - std::max(adjacentWidth2, 0)); |
| 712 x1, saturatedSubtraction(y2, std::max(-adjacentWidth2, 0))); | 658 quad[3] = FloatPoint(x2, y1 + std::max(adjacentWidth1, 0)); |
| 713 quad[2] = | |
| 714 FloatPoint(x2, saturatedSubtraction(y2, std::max(adjacentWidth2, 0))); | |
| 715 quad[3] = | |
| 716 FloatPoint(x2, saturatedAddition(y1, std::max(adjacentWidth1, 0))); | |
| 717 break; | 659 break; |
| 718 case BSRight: | 660 case BSRight: |
| 719 quad[0] = | 661 quad[0] = FloatPoint(x1, y1 + std::max(adjacentWidth1, 0)); |
| 720 FloatPoint(x1, saturatedAddition(y1, std::max(adjacentWidth1, 0))); | 662 quad[1] = FloatPoint(x1, y2 - std::max(adjacentWidth2, 0)); |
| 721 quad[1] = | 663 quad[2] = FloatPoint(x2, y2 - std::max(-adjacentWidth2, 0)); |
| 722 FloatPoint(x1, saturatedSubtraction(y2, std::max(adjacentWidth2, 0))); | 664 quad[3] = FloatPoint(x2, y1 + std::max(-adjacentWidth1, 0)); |
| 723 quad[2] = FloatPoint( | |
| 724 x2, saturatedSubtraction(y2, std::max(-adjacentWidth2, 0))); | |
| 725 quad[3] = | |
| 726 FloatPoint(x2, saturatedAddition(y1, std::max(-adjacentWidth1, 0))); | |
| 727 break; | 665 break; |
| 728 } | 666 } |
| 729 | 667 |
| 730 fillQuad(graphicsContext, quad, color, antialias); | 668 fillQuad(graphicsContext, quad, color, antialias); |
| 731 } | 669 } |
| 732 | 670 |
| 733 void ObjectPainter::paintAllPhasesAtomically(const PaintInfo& paintInfo, | 671 void ObjectPainter::paintAllPhasesAtomically(const PaintInfo& paintInfo, |
| 734 const LayoutPoint& paintOffset) { | 672 const LayoutPoint& paintOffset) { |
| 735 // Pass PaintPhaseSelection and PaintPhaseTextClip to the descendants so that | 673 // Pass PaintPhaseSelection and PaintPhaseTextClip to the descendants so that |
| 736 // they will paint for selection and text clip respectively. We don't need | 674 // they will paint for selection and text clip respectively. We don't need |
| (...skipping 12 matching lines...) Expand all Loading... |
| 749 m_layoutObject.paint(info, paintOffset); | 687 m_layoutObject.paint(info, paintOffset); |
| 750 info.phase = PaintPhaseFloat; | 688 info.phase = PaintPhaseFloat; |
| 751 m_layoutObject.paint(info, paintOffset); | 689 m_layoutObject.paint(info, paintOffset); |
| 752 info.phase = PaintPhaseForeground; | 690 info.phase = PaintPhaseForeground; |
| 753 m_layoutObject.paint(info, paintOffset); | 691 m_layoutObject.paint(info, paintOffset); |
| 754 info.phase = PaintPhaseOutline; | 692 info.phase = PaintPhaseOutline; |
| 755 m_layoutObject.paint(info, paintOffset); | 693 m_layoutObject.paint(info, paintOffset); |
| 756 } | 694 } |
| 757 | 695 |
| 758 } // namespace blink | 696 } // namespace blink |
| OLD | NEW |