Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 179383002: Add versions of isPointIn*() that take a Path parameter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase again Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 if (!domPath) { 1024 if (!domPath) {
1025 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "Path")); 1025 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "Path"));
1026 return; 1026 return;
1027 } 1027 }
1028 1028
1029 clipInternal(domPath->path(), windingRuleString); 1029 clipInternal(domPath->path(), windingRuleString);
1030 } 1030 }
1031 1031
1032 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString) 1032 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString)
1033 { 1033 {
1034 return isPointInPathInternal(m_path, x, y, windingRuleString);
1035 }
1036
1037 bool CanvasRenderingContext2D::isPointInPath(DOMPath* domPath, const float x, co nst float y, ExceptionState& exceptionState)
1038 {
1039 return isPointInPath(domPath, x, y, "nonzero", exceptionState);
1040 }
1041
1042 bool CanvasRenderingContext2D::isPointInPath(DOMPath* domPath, const float x, co nst float y, const String& windingRuleString, ExceptionState& exceptionState)
1043 {
1044 if (!domPath) {
1045 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "Path"));
1046 return false;
1047 }
1048
1049 return isPointInPathInternal(domPath->path(), x, y, windingRuleString);
1050 }
1051
1052 bool CanvasRenderingContext2D::isPointInPathInternal(const Path& path, const flo at x, const float y, const String& windingRuleString)
1053 {
1034 GraphicsContext* c = drawingContext(); 1054 GraphicsContext* c = drawingContext();
1035 if (!c) 1055 if (!c)
1036 return false; 1056 return false;
1037 if (!state().m_invertibleCTM) 1057 if (!state().m_invertibleCTM)
1038 return false; 1058 return false;
1039 1059
1040 FloatPoint point(x, y); 1060 FloatPoint point(x, y);
1041 AffineTransform ctm = state().m_transform; 1061 AffineTransform ctm = state().m_transform;
1042 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); 1062 FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
1043 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y())) 1063 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y()))
1044 return false; 1064 return false;
1045 1065
1046 WindRule windRule = RULE_NONZERO; 1066 WindRule windRule = RULE_NONZERO;
1047 if (!parseWinding(windingRuleString, windRule)) 1067 if (!parseWinding(windingRuleString, windRule))
1048 return false; 1068 return false;
1049 1069
1050 return m_path.contains(transformedPoint, windRule); 1070 return path.contains(transformedPoint, windRule);
1051 } 1071 }
1052 1072
1073 bool CanvasRenderingContext2D::isPointInStroke(const float x, const float y)
1074 {
1075 return isPointInStrokeInternal(m_path, x, y);
1076 }
1053 1077
1054 bool CanvasRenderingContext2D::isPointInStroke(const float x, const float y) 1078 bool CanvasRenderingContext2D::isPointInStroke(DOMPath* domPath, const float x, const float y, ExceptionState& exceptionState)
1079 {
1080 if (!domPath) {
1081 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "Path"));
1082 return false;
1083 }
1084
1085 return isPointInStrokeInternal(domPath->path(), x, y);
1086 }
1087
1088 bool CanvasRenderingContext2D::isPointInStrokeInternal(const Path& path, const f loat x, const float y)
1055 { 1089 {
1056 GraphicsContext* c = drawingContext(); 1090 GraphicsContext* c = drawingContext();
1057 if (!c) 1091 if (!c)
1058 return false; 1092 return false;
1059 if (!state().m_invertibleCTM) 1093 if (!state().m_invertibleCTM)
1060 return false; 1094 return false;
1061 1095
1062 FloatPoint point(x, y); 1096 FloatPoint point(x, y);
1063 AffineTransform ctm = state().m_transform; 1097 AffineTransform ctm = state().m_transform;
1064 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); 1098 FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
1065 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y())) 1099 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y()))
1066 return false; 1100 return false;
1067 1101
1068 StrokeData strokeData; 1102 StrokeData strokeData;
1069 strokeData.setThickness(lineWidth()); 1103 strokeData.setThickness(lineWidth());
1070 strokeData.setLineCap(getLineCap()); 1104 strokeData.setLineCap(getLineCap());
1071 strokeData.setLineJoin(getLineJoin()); 1105 strokeData.setLineJoin(getLineJoin());
1072 strokeData.setMiterLimit(miterLimit()); 1106 strokeData.setMiterLimit(miterLimit());
1073 strokeData.setLineDash(getLineDash(), lineDashOffset()); 1107 strokeData.setLineDash(getLineDash(), lineDashOffset());
1074 return m_path.strokeContains(transformedPoint, strokeData); 1108 return path.strokeContains(transformedPoint, strokeData);
1075 } 1109 }
1076 1110
1077 void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he ight) 1111 void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he ight)
1078 { 1112 {
1079 if (!validateRectForCanvas(x, y, width, height)) 1113 if (!validateRectForCanvas(x, y, width, height))
1080 return; 1114 return;
1081 GraphicsContext* context = drawingContext(); 1115 GraphicsContext* context = drawingContext();
1082 if (!context) 1116 if (!context)
1083 return; 1117 return;
1084 if (!state().m_invertibleCTM) 1118 if (!state().m_invertibleCTM)
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
2469 const int focusRingWidth = 5; 2503 const int focusRingWidth = 5;
2470 const int focusRingOutline = 0; 2504 const int focusRingOutline = 0;
2471 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2505 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2472 2506
2473 c->restore(); 2507 c->restore();
2474 2508
2475 didDraw(dirtyRect); 2509 didDraw(dirtyRect);
2476 } 2510 }
2477 2511
2478 } // namespace WebCore 2512 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/canvas/CanvasRenderingContext2D.h ('k') | Source/core/html/canvas/CanvasRenderingContext2D.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698