OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 { | 371 { |
372 drawPlatformFocusRing(rect, m_canvas, color.rgb(), width); | 372 drawPlatformFocusRing(rect, m_canvas, color.rgb(), width); |
373 } | 373 } |
374 | 374 |
375 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of
fset, const Color& color) | 375 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of
fset, const Color& color) |
376 { | 376 { |
377 // FIXME: Implement support for offset. | 377 // FIXME: Implement support for offset. |
378 if (contextDisabled()) | 378 if (contextDisabled()) |
379 return; | 379 return; |
380 | 380 |
381 drawFocusRingPath(focusRingPath.skPath(), color, width); | 381 drawFocusRingPath(focusRingPath.getSkPath(), color, width); |
382 } | 382 } |
383 | 383 |
384 void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
offset, const Color& color) | 384 void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
offset, const Color& color) |
385 { | 385 { |
386 if (contextDisabled()) | 386 if (contextDisabled()) |
387 return; | 387 return; |
388 | 388 |
389 unsigned rectCount = rects.size(); | 389 unsigned rectCount = rects.size(); |
390 if (!rectCount) | 390 if (!rectCount) |
391 return; | 391 return; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0
.0f) + shadowBlur); | 450 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0
.0f) + shadowBlur); |
451 } | 451 } |
452 if (clippedEdges & RightEdge) | 452 if (clippedEdges & RightEdge) |
453 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0.0f
) + shadowBlur); | 453 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0.0f
) + shadowBlur); |
454 if (clippedEdges & BottomEdge) | 454 if (clippedEdges & BottomEdge) |
455 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0
.0f) + shadowBlur); | 455 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0
.0f) + shadowBlur); |
456 | 456 |
457 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(),
255); | 457 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(),
255); |
458 | 458 |
459 FloatRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shado
wSpread, shadowOffset); | 459 FloatRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shado
wSpread, shadowOffset); |
460 FloatRoundedRect roundedHole(holeRect, rect.radii()); | 460 FloatRoundedRect roundedHole(holeRect, rect.getRadii()); |
461 | 461 |
462 GraphicsContextStateSaver stateSaver(*this); | 462 GraphicsContextStateSaver stateSaver(*this); |
463 if (rect.isRounded()) { | 463 if (rect.isRounded()) { |
464 clipRoundedRect(rect); | 464 clipRoundedRect(rect); |
465 if (shadowSpread < 0) | 465 if (shadowSpread < 0) |
466 roundedHole.expandRadii(-shadowSpread); | 466 roundedHole.expandRadii(-shadowSpread); |
467 else | 467 else |
468 roundedHole.shrinkRadii(shadowSpread); | 468 roundedHole.shrinkRadii(shadowSpread); |
469 } else { | 469 } else { |
470 clip(rect.rect()); | 470 clip(rect.rect()); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 | 700 |
701 ASSERT(!rect.isEmpty()); | 701 ASSERT(!rect.isEmpty()); |
702 if (rect.isEmpty()) | 702 if (rect.isEmpty()) |
703 return; | 703 return; |
704 | 704 |
705 SkRect skRect = rect; | 705 SkRect skRect = rect; |
706 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000
00; | 706 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000
00; |
707 if (fillcolorNotTransparent) | 707 if (fillcolorNotTransparent) |
708 drawRect(skRect, immutableState()->fillPaint()); | 708 drawRect(skRect, immutableState()->fillPaint()); |
709 | 709 |
710 if (immutableState()->strokeData().style() != NoStroke | 710 if (immutableState()->getStrokeData().style() != NoStroke |
711 && immutableState()->strokeColor().alpha()) { | 711 && immutableState()->strokeColor().alpha()) { |
712 // Stroke a width: 1 inset border | 712 // Stroke a width: 1 inset border |
713 SkPaint paint(immutableState()->fillPaint()); | 713 SkPaint paint(immutableState()->fillPaint()); |
714 paint.setColor(strokeColor().rgb()); | 714 paint.setColor(strokeColor().rgb()); |
715 paint.setStyle(SkPaint::kStroke_Style); | 715 paint.setStyle(SkPaint::kStroke_Style); |
716 paint.setStrokeWidth(1); | 716 paint.setStrokeWidth(1); |
717 | 717 |
718 skRect.inset(0.5f, 0.5f); | 718 skRect.inset(0.5f, 0.5f); |
719 drawRect(skRect, paint); | 719 drawRect(skRect, paint); |
720 } | 720 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 ASSERT(m_canvas); | 894 ASSERT(m_canvas); |
895 | 895 |
896 m_canvas->drawRRect(rrect, paint); | 896 m_canvas->drawRRect(rrect, paint); |
897 } | 897 } |
898 | 898 |
899 void GraphicsContext::fillPath(const Path& pathToFill) | 899 void GraphicsContext::fillPath(const Path& pathToFill) |
900 { | 900 { |
901 if (contextDisabled() || pathToFill.isEmpty()) | 901 if (contextDisabled() || pathToFill.isEmpty()) |
902 return; | 902 return; |
903 | 903 |
904 drawPath(pathToFill.skPath(), immutableState()->fillPaint()); | 904 drawPath(pathToFill.getSkPath(), immutableState()->fillPaint()); |
905 } | 905 } |
906 | 906 |
907 void GraphicsContext::fillRect(const FloatRect& rect) | 907 void GraphicsContext::fillRect(const FloatRect& rect) |
908 { | 908 { |
909 if (contextDisabled()) | 909 if (contextDisabled()) |
910 return; | 910 return; |
911 | 911 |
912 drawRect(rect, immutableState()->fillPaint()); | 912 drawRect(rect, immutableState()->fillPaint()); |
913 } | 913 } |
914 | 914 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 // A DRRect is "simple" (i.e. can be drawn as a rrect stroke) if | 952 // A DRRect is "simple" (i.e. can be drawn as a rrect stroke) if |
953 // 1) all sides have the same width | 953 // 1) all sides have the same width |
954 const FloatSize strokeSize = inner.rect().minXMinYCorner() - outer.rect().mi
nXMinYCorner(); | 954 const FloatSize strokeSize = inner.rect().minXMinYCorner() - outer.rect().mi
nXMinYCorner(); |
955 if (!WebCoreFloatNearlyEqual(strokeSize.aspectRatio(), 1) | 955 if (!WebCoreFloatNearlyEqual(strokeSize.aspectRatio(), 1) |
956 || !WebCoreFloatNearlyEqual(strokeSize.width(), outer.rect().maxX() - in
ner.rect().maxX()) | 956 || !WebCoreFloatNearlyEqual(strokeSize.width(), outer.rect().maxX() - in
ner.rect().maxX()) |
957 || !WebCoreFloatNearlyEqual(strokeSize.height(), outer.rect().maxY() - i
nner.rect().maxY())) | 957 || !WebCoreFloatNearlyEqual(strokeSize.height(), outer.rect().maxY() - i
nner.rect().maxY())) |
958 return false; | 958 return false; |
959 | 959 |
960 // and | 960 // and |
961 // 2) the inner radii are not constrained | 961 // 2) the inner radii are not constrained |
962 const FloatRoundedRect::Radii& oRadii = outer.radii(); | 962 const FloatRoundedRect::Radii& oRadii = outer.getRadii(); |
963 const FloatRoundedRect::Radii& iRadii = inner.radii(); | 963 const FloatRoundedRect::Radii& iRadii = inner.getRadii(); |
964 if (!WebCoreFloatNearlyEqual(oRadii.topLeft().width() - strokeSize.width(),
iRadii.topLeft().width()) | 964 if (!WebCoreFloatNearlyEqual(oRadii.topLeft().width() - strokeSize.width(),
iRadii.topLeft().width()) |
965 || !WebCoreFloatNearlyEqual(oRadii.topLeft().height() - strokeSize.heigh
t(), iRadii.topLeft().height()) | 965 || !WebCoreFloatNearlyEqual(oRadii.topLeft().height() - strokeSize.heigh
t(), iRadii.topLeft().height()) |
966 || !WebCoreFloatNearlyEqual(oRadii.topRight().width() - strokeSize.width
(), iRadii.topRight().width()) | 966 || !WebCoreFloatNearlyEqual(oRadii.topRight().width() - strokeSize.width
(), iRadii.topRight().width()) |
967 || !WebCoreFloatNearlyEqual(oRadii.topRight().height() - strokeSize.heig
ht(), iRadii.topRight().height()) | 967 || !WebCoreFloatNearlyEqual(oRadii.topRight().height() - strokeSize.heig
ht(), iRadii.topRight().height()) |
968 || !WebCoreFloatNearlyEqual(oRadii.bottomRight().width() - strokeSize.wi
dth(), iRadii.bottomRight().width()) | 968 || !WebCoreFloatNearlyEqual(oRadii.bottomRight().width() - strokeSize.wi
dth(), iRadii.bottomRight().width()) |
969 || !WebCoreFloatNearlyEqual(oRadii.bottomRight().height() - strokeSize.h
eight(), iRadii.bottomRight().height()) | 969 || !WebCoreFloatNearlyEqual(oRadii.bottomRight().height() - strokeSize.h
eight(), iRadii.bottomRight().height()) |
970 || !WebCoreFloatNearlyEqual(oRadii.bottomLeft().width() - strokeSize.wid
th(), iRadii.bottomLeft().width()) | 970 || !WebCoreFloatNearlyEqual(oRadii.bottomLeft().width() - strokeSize.wid
th(), iRadii.bottomLeft().width()) |
971 || !WebCoreFloatNearlyEqual(oRadii.bottomLeft().height() - strokeSize.he
ight(), iRadii.bottomLeft().height())) | 971 || !WebCoreFloatNearlyEqual(oRadii.bottomLeft().height() - strokeSize.he
ight(), iRadii.bottomLeft().height())) |
972 return false; | 972 return false; |
973 | 973 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 return; | 1022 return; |
1023 | 1023 |
1024 drawOval(ellipse, immutableState()->fillPaint()); | 1024 drawOval(ellipse, immutableState()->fillPaint()); |
1025 } | 1025 } |
1026 | 1026 |
1027 void GraphicsContext::strokePath(const Path& pathToStroke) | 1027 void GraphicsContext::strokePath(const Path& pathToStroke) |
1028 { | 1028 { |
1029 if (contextDisabled() || pathToStroke.isEmpty()) | 1029 if (contextDisabled() || pathToStroke.isEmpty()) |
1030 return; | 1030 return; |
1031 | 1031 |
1032 drawPath(pathToStroke.skPath(), immutableState()->strokePaint()); | 1032 drawPath(pathToStroke.getSkPath(), immutableState()->strokePaint()); |
1033 } | 1033 } |
1034 | 1034 |
1035 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) | 1035 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) |
1036 { | 1036 { |
1037 if (contextDisabled()) | 1037 if (contextDisabled()) |
1038 return; | 1038 return; |
1039 | 1039 |
1040 SkPaint paint(immutableState()->strokePaint()); | 1040 SkPaint paint(immutableState()->strokePaint()); |
1041 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); | 1041 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); |
1042 // Reset the dash effect to account for the width | 1042 // Reset the dash effect to account for the width |
1043 immutableState()->strokeData().setupPaintDashPathEffect(&paint, 0); | 1043 immutableState()->getStrokeData().setupPaintDashPathEffect(&paint, 0); |
1044 // strokerect has special rules for CSS when the rect is degenerate: | 1044 // strokerect has special rules for CSS when the rect is degenerate: |
1045 // if width==0 && height==0, do nothing | 1045 // if width==0 && height==0, do nothing |
1046 // if width==0 || height==0, then just draw line for the other dimension | 1046 // if width==0 || height==0, then just draw line for the other dimension |
1047 SkRect r(rect); | 1047 SkRect r(rect); |
1048 bool validW = r.width() > 0; | 1048 bool validW = r.width() > 0; |
1049 bool validH = r.height() > 0; | 1049 bool validH = r.height() > 0; |
1050 if (validW && validH) { | 1050 if (validW && validH) { |
1051 drawRect(r, paint); | 1051 drawRect(r, paint); |
1052 } else if (validW || validH) { | 1052 } else if (validW || validH) { |
1053 // we are expected to respect the lineJoin, so we can't just call | 1053 // we are expected to respect the lineJoin, so we can't just call |
(...skipping 26 matching lines...) Expand all Loading... |
1080 | 1080 |
1081 clipRRect(rrect, shouldAntialias, regionOp); | 1081 clipRRect(rrect, shouldAntialias, regionOp); |
1082 } | 1082 } |
1083 | 1083 |
1084 void GraphicsContext::clipOut(const Path& pathToClip) | 1084 void GraphicsContext::clipOut(const Path& pathToClip) |
1085 { | 1085 { |
1086 if (contextDisabled()) | 1086 if (contextDisabled()) |
1087 return; | 1087 return; |
1088 | 1088 |
1089 // Use const_cast and temporarily toggle the inverse fill type instead of co
pying the path. | 1089 // Use const_cast and temporarily toggle the inverse fill type instead of co
pying the path. |
1090 SkPath& path = const_cast<SkPath&>(pathToClip.skPath()); | 1090 SkPath& path = const_cast<SkPath&>(pathToClip.getSkPath()); |
1091 path.toggleInverseFillType(); | 1091 path.toggleInverseFillType(); |
1092 clipPath(path, AntiAliased); | 1092 clipPath(path, AntiAliased); |
1093 path.toggleInverseFillType(); | 1093 path.toggleInverseFillType(); |
1094 } | 1094 } |
1095 | 1095 |
1096 void GraphicsContext::clipPolygon(size_t numPoints, const FloatPoint* points, bo
ol antialiased) | 1096 void GraphicsContext::clipPolygon(size_t numPoints, const FloatPoint* points, bo
ol antialiased) |
1097 { | 1097 { |
1098 if (contextDisabled()) | 1098 if (contextDisabled()) |
1099 return; | 1099 return; |
1100 | 1100 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 static const SkPMColor colors[] = { | 1360 static const SkPMColor colors[] = { |
1361 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1361 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
1362 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1362 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
1363 }; | 1363 }; |
1364 | 1364 |
1365 return colors[index]; | 1365 return colors[index]; |
1366 } | 1366 } |
1367 #endif | 1367 #endif |
1368 | 1368 |
1369 } // namespace blink | 1369 } // namespace blink |
OLD | NEW |