OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
All rights reserved. |
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
10 * | 10 * |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 if (!c) | 855 if (!c) |
856 return; | 856 return; |
857 | 857 |
858 if (!std::isfinite(m11) | !std::isfinite(m21) | !std::isfinite(dx) | !std::i
sfinite(m12) | !std::isfinite(m22) | !std::isfinite(dy)) | 858 if (!std::isfinite(m11) | !std::isfinite(m21) | !std::isfinite(dx) | !std::i
sfinite(m12) | !std::isfinite(m22) | !std::isfinite(dy)) |
859 return; | 859 return; |
860 | 860 |
861 resetTransform(); | 861 resetTransform(); |
862 transform(m11, m12, m21, m22, dx, dy); | 862 transform(m11, m12, m21, m22, dx, dy); |
863 } | 863 } |
864 | 864 |
865 void CanvasRenderingContext2D::setStrokeColor(const String& color) | 865 void CanvasRenderingContext2D::setStrokeColor(const String& color, Optional<floa
t> alpha) |
866 { | 866 { |
| 867 if (!alpha.isMissing()) { |
| 868 setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alp
ha)); |
| 869 return; |
| 870 } |
867 if (color == state().m_unparsedStrokeColor) | 871 if (color == state().m_unparsedStrokeColor) |
868 return; | 872 return; |
869 realizeSaves(); | 873 realizeSaves(); |
870 setStrokeStyle(CanvasStyle::createFromString(color)); | 874 setStrokeStyle(CanvasStyle::createFromString(color)); |
871 modifiableState().m_unparsedStrokeColor = color; | 875 modifiableState().m_unparsedStrokeColor = color; |
872 } | 876 } |
873 | 877 |
874 void CanvasRenderingContext2D::setStrokeColor(float grayLevel) | |
875 { | |
876 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(grayLev
el, grayLevel, grayLevel, 1.0f)) | |
877 return; | |
878 setStrokeStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, 1.0f)); | |
879 } | |
880 | |
881 void CanvasRenderingContext2D::setStrokeColor(const String& color, float alpha) | |
882 { | |
883 setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha))
; | |
884 } | |
885 | |
886 void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha) | 878 void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha) |
887 { | 879 { |
888 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(grayLev
el, grayLevel, grayLevel, alpha)) | 880 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(grayLev
el, grayLevel, grayLevel, alpha)) |
889 return; | 881 return; |
890 setStrokeStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, alpha)); | 882 setStrokeStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, alpha)); |
891 } | 883 } |
892 | 884 |
893 void CanvasRenderingContext2D::setStrokeColor(float r, float g, float b, float a
) | 885 void CanvasRenderingContext2D::setStrokeColor(float r, float g, float b, float a
) |
894 { | 886 { |
895 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(r, g, b
, a)) | 887 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentRGBA(r, g, b
, a)) |
896 return; | 888 return; |
897 setStrokeStyle(CanvasStyle::createFromRGBAChannels(r, g, b, a)); | 889 setStrokeStyle(CanvasStyle::createFromRGBAChannels(r, g, b, a)); |
898 } | 890 } |
899 | 891 |
900 void CanvasRenderingContext2D::setStrokeColor(float c, float m, float y, float k
, float a) | 892 void CanvasRenderingContext2D::setStrokeColor(float c, float m, float y, float k
, float a) |
901 { | 893 { |
902 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentCMYKA(c, m,
y, k, a)) | 894 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentCMYKA(c, m,
y, k, a)) |
903 return; | 895 return; |
904 setStrokeStyle(CanvasStyle::createFromCMYKAChannels(c, m, y, k, a)); | 896 setStrokeStyle(CanvasStyle::createFromCMYKAChannels(c, m, y, k, a)); |
905 } | 897 } |
906 | 898 |
907 void CanvasRenderingContext2D::setFillColor(const String& color) | 899 void CanvasRenderingContext2D::setFillColor(const String& color, Optional<float>
alpha) |
908 { | 900 { |
| 901 if (!alpha.isMissing()) { |
| 902 setFillStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha
)); |
| 903 return; |
| 904 } |
909 if (color == state().m_unparsedFillColor) | 905 if (color == state().m_unparsedFillColor) |
910 return; | 906 return; |
911 realizeSaves(); | 907 realizeSaves(); |
912 setFillStyle(CanvasStyle::createFromString(color)); | 908 setFillStyle(CanvasStyle::createFromString(color)); |
913 modifiableState().m_unparsedFillColor = color; | 909 modifiableState().m_unparsedFillColor = color; |
914 } | 910 } |
915 | 911 |
916 void CanvasRenderingContext2D::setFillColor(float grayLevel) | |
917 { | |
918 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(grayLevel,
grayLevel, grayLevel, 1.0f)) | |
919 return; | |
920 setFillStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, 1.0f)); | |
921 } | |
922 | |
923 void CanvasRenderingContext2D::setFillColor(const String& color, float alpha) | |
924 { | |
925 setFillStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha)); | |
926 } | |
927 | |
928 void CanvasRenderingContext2D::setFillColor(float grayLevel, float alpha) | 912 void CanvasRenderingContext2D::setFillColor(float grayLevel, float alpha) |
929 { | 913 { |
930 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(grayLevel,
grayLevel, grayLevel, alpha)) | 914 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(grayLevel,
grayLevel, grayLevel, alpha)) |
931 return; | 915 return; |
932 setFillStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, alpha)); | 916 setFillStyle(CanvasStyle::createFromGrayLevelWithAlpha(grayLevel, alpha)); |
933 } | 917 } |
934 | 918 |
935 void CanvasRenderingContext2D::setFillColor(float r, float g, float b, float a) | 919 void CanvasRenderingContext2D::setFillColor(float r, float g, float b, float a) |
936 { | 920 { |
937 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(r, g, b, a)
) | 921 if (state().m_fillStyle && state().m_fillStyle->isEquivalentRGBA(r, g, b, a)
) |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 | 1157 |
1174 StrokeData strokeData; | 1158 StrokeData strokeData; |
1175 strokeData.setThickness(lineWidth()); | 1159 strokeData.setThickness(lineWidth()); |
1176 strokeData.setLineCap(getLineCap()); | 1160 strokeData.setLineCap(getLineCap()); |
1177 strokeData.setLineJoin(getLineJoin()); | 1161 strokeData.setLineJoin(getLineJoin()); |
1178 strokeData.setMiterLimit(miterLimit()); | 1162 strokeData.setMiterLimit(miterLimit()); |
1179 strokeData.setLineDash(getLineDash(), lineDashOffset()); | 1163 strokeData.setLineDash(getLineDash(), lineDashOffset()); |
1180 return path.strokeContains(transformedPoint, strokeData); | 1164 return path.strokeContains(transformedPoint, strokeData); |
1181 } | 1165 } |
1182 | 1166 |
1183 void CanvasRenderingContext2D::scrollPathIntoView() | |
1184 { | |
1185 scrollPathIntoViewInternal(m_path); | |
1186 } | |
1187 | |
1188 void CanvasRenderingContext2D::scrollPathIntoView(Path2D* path2d) | 1167 void CanvasRenderingContext2D::scrollPathIntoView(Path2D* path2d) |
1189 { | 1168 { |
1190 scrollPathIntoViewInternal(path2d->path()); | 1169 scrollPathIntoViewInternal(path2d ? path2d->path() : m_path); |
1191 } | 1170 } |
1192 | 1171 |
1193 void CanvasRenderingContext2D::scrollPathIntoViewInternal(const Path& path) | 1172 void CanvasRenderingContext2D::scrollPathIntoViewInternal(const Path& path) |
1194 { | 1173 { |
1195 RenderObject* renderer = canvas()->renderer(); | 1174 RenderObject* renderer = canvas()->renderer(); |
1196 RenderBox* renderBox = canvas()->renderBox(); | 1175 RenderBox* renderBox = canvas()->renderBox(); |
1197 if (!renderer || !renderBox || !state().m_invertibleCTM || path.isEmpty()) | 1176 if (!renderer || !renderBox || !state().m_invertibleCTM || path.isEmpty()) |
1198 return; | 1177 return; |
1199 | 1178 |
1200 canvas()->document().updateLayoutIgnorePendingStylesheets(); | 1179 canvas()->document().updateLayoutIgnorePendingStylesheets(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 FloatRect boundingRect = rect; | 1316 FloatRect boundingRect = rect; |
1338 boundingRect.inflate(state().m_lineWidth / 2); | 1317 boundingRect.inflate(state().m_lineWidth / 2); |
1339 FloatRect dirtyRect; | 1318 FloatRect dirtyRect; |
1340 if (computeDirtyRect(boundingRect, clipBounds, &dirtyRect)) { | 1319 if (computeDirtyRect(boundingRect, clipBounds, &dirtyRect)) { |
1341 c->strokeRect(rect); | 1320 c->strokeRect(rect); |
1342 didDraw(dirtyRect); | 1321 didDraw(dirtyRect); |
1343 } | 1322 } |
1344 } | 1323 } |
1345 } | 1324 } |
1346 | 1325 |
1347 void CanvasRenderingContext2D::setShadow(float width, float height, float blur) | 1326 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
const Optional<String>& color, Optional<float> alpha) |
1348 { | |
1349 setShadow(FloatSize(width, height), blur, Color::transparent); | |
1350 } | |
1351 | |
1352 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
const String& color) | |
1353 { | 1327 { |
1354 RGBA32 rgba; | 1328 RGBA32 rgba; |
1355 if (!parseColorOrCurrentColor(rgba, color, canvas())) | 1329 if (color.isMissing()) |
| 1330 rgba = Color::transparent; |
| 1331 else if (!parseColorOrCurrentColor(rgba, color, canvas())) |
1356 return; | 1332 return; |
| 1333 if (!alpha.isMissing()) |
| 1334 rgba = colorWithOverrideAlpha(rgba, alpha); |
1357 setShadow(FloatSize(width, height), blur, rgba); | 1335 setShadow(FloatSize(width, height), blur, rgba); |
1358 } | 1336 } |
1359 | 1337 |
1360 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float grayLevel) | |
1361 { | |
1362 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(grayLevel, gr
ayLevel, grayLevel, 1)); | |
1363 } | |
1364 | |
1365 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
const String& color, float alpha) | |
1366 { | |
1367 RGBA32 rgba; | |
1368 if (!parseColorOrCurrentColor(rgba, color, canvas())) | |
1369 return; | |
1370 setShadow(FloatSize(width, height), blur, colorWithOverrideAlpha(rgba, alpha
)); | |
1371 } | |
1372 | |
1373 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float grayLevel, float alpha) | 1338 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float grayLevel, float alpha) |
1374 { | 1339 { |
1375 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(grayLevel, gr
ayLevel, grayLevel, alpha)); | 1340 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(grayLevel, gr
ayLevel, grayLevel, alpha)); |
1376 } | 1341 } |
1377 | 1342 |
1378 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float r, float g, float b, float a) | 1343 void CanvasRenderingContext2D::setShadow(float width, float height, float blur,
float r, float g, float b, float a) |
1379 { | 1344 { |
1380 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(r, g, b, a)); | 1345 setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(r, g, b, a)); |
1381 } | 1346 } |
1382 | 1347 |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 { | 1974 { |
2010 TextBaseline baseline; | 1975 TextBaseline baseline; |
2011 if (!parseTextBaseline(s, baseline)) | 1976 if (!parseTextBaseline(s, baseline)) |
2012 return; | 1977 return; |
2013 if (state().m_textBaseline == baseline) | 1978 if (state().m_textBaseline == baseline) |
2014 return; | 1979 return; |
2015 realizeSaves(); | 1980 realizeSaves(); |
2016 modifiableState().m_textBaseline = baseline; | 1981 modifiableState().m_textBaseline = baseline; |
2017 } | 1982 } |
2018 | 1983 |
2019 void CanvasRenderingContext2D::fillText(const String& text, float x, float y) | 1984 void CanvasRenderingContext2D::fillText(const String& text, float x, float y, Op
tional<float> maxWidth) |
2020 { | 1985 { |
2021 drawTextInternal(text, x, y, true); | 1986 drawTextInternal(text, x, y, true, maxWidth.get(), !maxWidth.isMissing()); |
2022 } | 1987 } |
2023 | 1988 |
2024 void CanvasRenderingContext2D::fillText(const String& text, float x, float y, fl
oat maxWidth) | 1989 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y,
Optional<float> maxWidth) |
2025 { | 1990 { |
2026 drawTextInternal(text, x, y, true, maxWidth, true); | 1991 drawTextInternal(text, x, y, false, maxWidth.get(), !maxWidth.isMissing()); |
2027 } | |
2028 | |
2029 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y) | |
2030 { | |
2031 drawTextInternal(text, x, y, false); | |
2032 } | |
2033 | |
2034 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y,
float maxWidth) | |
2035 { | |
2036 drawTextInternal(text, x, y, false, maxWidth, true); | |
2037 } | 1992 } |
2038 | 1993 |
2039 static inline bool isSpaceCharacter(UChar c) | 1994 static inline bool isSpaceCharacter(UChar c) |
2040 { | 1995 { |
2041 // According to specification all space characters should be replaced with 0
x0020 space character. | 1996 // According to specification all space characters should be replaced with 0
x0020 space character. |
2042 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-el
ement.html#text-preparation-algorithm | 1997 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-el
ement.html#text-preparation-algorithm |
2043 // The space characters according to specification are : U+0020, U+0009, U+0
00A, U+000C, and U+000D. | 1998 // The space characters according to specification are : U+0020, U+0009, U+0
00A, U+000C, and U+000D. |
2044 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-micros
yntaxes.html#space-character | 1999 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-micros
yntaxes.html#space-character |
2045 // This function returns true for 0x000B also, so that this is backward comp
atible. | 2000 // This function returns true for 0x000B also, so that this is backward comp
atible. |
2046 // Otherwise, the test LayoutTests/canvas/philip/tests/2d.text.draw.space.co
llapse.space.html will fail | 2001 // Otherwise, the test LayoutTests/canvas/philip/tests/2d.text.draw.space.co
llapse.space.html will fail |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2444 | 2399 |
2445 unsigned CanvasRenderingContext2D::hitRegionsCount() const | 2400 unsigned CanvasRenderingContext2D::hitRegionsCount() const |
2446 { | 2401 { |
2447 if (m_hitRegionManager) | 2402 if (m_hitRegionManager) |
2448 return m_hitRegionManager->getHitRegionsCount(); | 2403 return m_hitRegionManager->getHitRegionsCount(); |
2449 | 2404 |
2450 return 0; | 2405 return 0; |
2451 } | 2406 } |
2452 | 2407 |
2453 } // namespace blink | 2408 } // namespace blink |
OLD | NEW |