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

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: pointer validation check Created 6 years, 10 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 981 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 clipInternal(m_path, windingRuleString); 992 clipInternal(m_path, windingRuleString);
993 } 993 }
994 994
995 void CanvasRenderingContext2D::clip(DOMPath* domPath, const String& windingRuleS tring) 995 void CanvasRenderingContext2D::clip(DOMPath* domPath, const String& windingRuleS tring)
996 { 996 {
997 clipInternal(domPath->path(), windingRuleString); 997 clipInternal(domPath->path(), windingRuleString);
998 } 998 }
999 999
1000 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString) 1000 bool CanvasRenderingContext2D::isPointInPath(const float x, const float y, const String& windingRuleString)
1001 { 1001 {
1002 return isPointInPathInternal(m_path, x, y, windingRuleString);
1003 }
1004
1005 bool CanvasRenderingContext2D::isPointInPath(DOMPath* domPath, const float x, co nst float y, const String& windingRuleString)
1006 {
1007 if (!domPath)
Justin Novosad 2014/02/25 16:45:08 Shouldn't this case throw a type mismatch DOM exce
1008 return false;
1009
1010 return isPointInPathInternal(domPath->path(), x, y, windingRuleString);
1011 }
1012
1013 bool CanvasRenderingContext2D::isPointInPathInternal(const Path& path, const flo at x, const float y, const String& windingRuleString)
1014 {
1002 GraphicsContext* c = drawingContext(); 1015 GraphicsContext* c = drawingContext();
1003 if (!c) 1016 if (!c)
1004 return false; 1017 return false;
1005 if (!state().m_invertibleCTM) 1018 if (!state().m_invertibleCTM)
1006 return false; 1019 return false;
1007 1020
1008 FloatPoint point(x, y); 1021 FloatPoint point(x, y);
1009 AffineTransform ctm = state().m_transform; 1022 AffineTransform ctm = state().m_transform;
1010 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); 1023 FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
1011 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y())) 1024 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y()))
1012 return false; 1025 return false;
1013 1026
1014 WindRule windRule = RULE_NONZERO; 1027 WindRule windRule = RULE_NONZERO;
1015 if (!parseWinding(windingRuleString, windRule)) 1028 if (!parseWinding(windingRuleString, windRule))
1016 return false; 1029 return false;
1017 1030
1018 return m_path.contains(transformedPoint, windRule); 1031 return path.contains(transformedPoint, windRule);
1019 } 1032 }
1020 1033
1034 bool CanvasRenderingContext2D::isPointInStroke(const float x, const float y)
1035 {
1036 return isPointInStrokeInternal(m_path, x, y);
1037 }
1021 1038
1022 bool CanvasRenderingContext2D::isPointInStroke(const float x, const float y) 1039 bool CanvasRenderingContext2D::isPointInStroke(DOMPath* domPath, const float x, const float y)
1040 {
1041 if (!domPath)
Justin Novosad 2014/02/25 16:45:08 DOM exception?
Rik 2014/02/25 17:37:54 Shouldn't that be called by blink's IDL preprocess
jcgregorio 2014/02/25 17:48:31 It should be caught by the code generated from the
1042 return false;
1043
1044 return isPointInStrokeInternal(domPath->path(), x, y);
1045 }
1046
1047 bool CanvasRenderingContext2D::isPointInStrokeInternal(const Path& path, const f loat x, const float y)
1023 { 1048 {
1024 GraphicsContext* c = drawingContext(); 1049 GraphicsContext* c = drawingContext();
1025 if (!c) 1050 if (!c)
1026 return false; 1051 return false;
1027 if (!state().m_invertibleCTM) 1052 if (!state().m_invertibleCTM)
1028 return false; 1053 return false;
1029 1054
1030 FloatPoint point(x, y); 1055 FloatPoint point(x, y);
1031 AffineTransform ctm = state().m_transform; 1056 AffineTransform ctm = state().m_transform;
1032 FloatPoint transformedPoint = ctm.inverse().mapPoint(point); 1057 FloatPoint transformedPoint = ctm.inverse().mapPoint(point);
1033 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y())) 1058 if (!std::isfinite(transformedPoint.x()) || !std::isfinite(transformedPoint. y()))
1034 return false; 1059 return false;
1035 1060
1036 StrokeData strokeData; 1061 StrokeData strokeData;
1037 strokeData.setThickness(lineWidth()); 1062 strokeData.setThickness(lineWidth());
1038 strokeData.setLineCap(getLineCap()); 1063 strokeData.setLineCap(getLineCap());
1039 strokeData.setLineJoin(getLineJoin()); 1064 strokeData.setLineJoin(getLineJoin());
1040 strokeData.setMiterLimit(miterLimit()); 1065 strokeData.setMiterLimit(miterLimit());
1041 strokeData.setLineDash(getLineDash(), lineDashOffset()); 1066 strokeData.setLineDash(getLineDash(), lineDashOffset());
1042 return m_path.strokeContains(transformedPoint, strokeData); 1067 return path.strokeContains(transformedPoint, strokeData);
1043 } 1068 }
1044 1069
1045 void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he ight) 1070 void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he ight)
1046 { 1071 {
1047 if (!validateRectForCanvas(x, y, width, height)) 1072 if (!validateRectForCanvas(x, y, width, height))
1048 return; 1073 return;
1049 GraphicsContext* context = drawingContext(); 1074 GraphicsContext* context = drawingContext();
1050 if (!context) 1075 if (!context)
1051 return; 1076 return;
1052 if (!state().m_invertibleCTM) 1077 if (!state().m_invertibleCTM)
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 const int focusRingWidth = 5; 2462 const int focusRingWidth = 5;
2438 const int focusRingOutline = 0; 2463 const int focusRingOutline = 0;
2439 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2464 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2440 2465
2441 c->restore(); 2466 c->restore();
2442 2467
2443 didDraw(dirtyRect); 2468 didDraw(dirtyRect);
2444 } 2469 }
2445 2470
2446 } // namespace WebCore 2471 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698