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

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

Issue 196243007: Implement CRC2D.scrollPathIntoView() on Canvas (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: update and layout test 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 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1102
1103 StrokeData strokeData; 1103 StrokeData strokeData;
1104 strokeData.setThickness(lineWidth()); 1104 strokeData.setThickness(lineWidth());
1105 strokeData.setLineCap(getLineCap()); 1105 strokeData.setLineCap(getLineCap());
1106 strokeData.setLineJoin(getLineJoin()); 1106 strokeData.setLineJoin(getLineJoin());
1107 strokeData.setMiterLimit(miterLimit()); 1107 strokeData.setMiterLimit(miterLimit());
1108 strokeData.setLineDash(getLineDash(), lineDashOffset()); 1108 strokeData.setLineDash(getLineDash(), lineDashOffset());
1109 return path.strokeContains(transformedPoint, strokeData); 1109 return path.strokeContains(transformedPoint, strokeData);
1110 } 1110 }
1111 1111
1112 void CanvasRenderingContext2D::scrollPathIntoView()
1113 {
1114 scrollPathIntoViewInternal(m_path);
Rik 2014/03/20 16:22:19 Does this take the current CTM into account? I bel
1115 }
1116
1117 void CanvasRenderingContext2D::scrollPathIntoView(Path2D* path2d, ExceptionState & exceptionState)
1118 {
1119 if (!path2d) {
1120 exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::a rgumentNullOrIncorrectType(1, "Path2D"));
1121 return;
1122 }
1123
1124 scrollPathIntoViewInternal(path2d->path());
1125 }
1126
1127 void CanvasRenderingContext2D::scrollPathIntoViewInternal(const Path& path)
1128 {
1129 if (!state().m_invertibleCTM || !canvas() || path.isEmpty())
Rik 2014/03/20 16:22:19 scrollPathIntoView() should take ctm into account.
Justin Novosad 2014/03/20 20:03:12 I agree, all the other methods on CanvasRenderingC
1130 return;
1131
1132 canvas()->document().updateLayoutIgnorePendingStylesheets();
1133
1134 LayoutRect pathRect;
1135 absoluteBoundingPathRect(path, pathRect);
1136
1137 if (canvas()->renderer()) {
1138 canvas()->renderer()->scrollRectToVisible(
1139 pathRect, ScrollAlignment::alignCenterAlways, ScrollAlignment::align TopAlways);
1140 }
1141
1142 // TODO: should implement "inform the user" that the caret and/or
1143 // selection the specified rectangle of the canvas.
1144 }
1145
1112 void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he ight) 1146 void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he ight)
1113 { 1147 {
1114 if (!validateRectForCanvas(x, y, width, height)) 1148 if (!validateRectForCanvas(x, y, width, height))
1115 return; 1149 return;
1116 GraphicsContext* context = drawingContext(); 1150 GraphicsContext* context = drawingContext();
1117 if (!context) 1151 if (!context)
1118 return; 1152 return;
1119 if (!state().m_invertibleCTM) 1153 if (!state().m_invertibleCTM)
1120 return; 1154 return;
1121 FloatRect rect(x, y, width, height); 1155 FloatRect rect(x, y, width, height);
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 static const float root2 = sqrtf(2); 2174 static const float root2 = sqrtf(2);
2141 float delta = state().m_lineWidth / 2; 2175 float delta = state().m_lineWidth / 2;
2142 if (state().m_lineJoin == MiterJoin) 2176 if (state().m_lineJoin == MiterJoin)
2143 delta *= state().m_miterLimit; 2177 delta *= state().m_miterLimit;
2144 else if (state().m_lineCap == SquareCap) 2178 else if (state().m_lineCap == SquareCap)
2145 delta *= root2; 2179 delta *= root2;
2146 2180
2147 rect.inflate(delta); 2181 rect.inflate(delta);
2148 } 2182 }
2149 2183
2184 void CanvasRenderingContext2D::absoluteBoundingPathRect(const Path& path, Layout Rect& rect) const
2185 {
2186 // Get the bounding rect and apply transformations.
2187 FloatRect bounds = path.boundingRect();
2188 AffineTransform ctm = state().m_transform;
2189 FloatRect transformedBounds = ctm.mapRect(bounds);
2190 rect = LayoutRect(transformedBounds);
Justin Novosad 2014/03/20 20:03:12 This works if the transform has only translation a
2191
2192 // Offset by the canvas rect (We should take border and padding into account ).
2193 IntRect canvasRect = canvas()->renderer()->absoluteBoundingBoxRect();
2194 RenderBoxModelObject* rbmo = canvas()->renderBoxModelObject();
2195 canvasRect.move(rbmo->borderLeft() + rbmo->paddingLeft(),
2196 rbmo->borderTop() + rbmo->paddingTop());
2197 rect.moveBy(canvasRect.location());
2198 }
2199
2150 const Font& CanvasRenderingContext2D::accessFont() 2200 const Font& CanvasRenderingContext2D::accessFont()
2151 { 2201 {
2152 // This needs style to be up to date, but can't assert so because drawTextIn ternal 2202 // This needs style to be up to date, but can't assert so because drawTextIn ternal
2153 // can invalidate style before this is called (e.g. drawingContext invalidat es style). 2203 // can invalidate style before this is called (e.g. drawingContext invalidat es style).
2154 if (!state().m_realizedFont) 2204 if (!state().m_realizedFont)
2155 setFont(state().m_unparsedFont); 2205 setFont(state().m_unparsedFont);
2156 return state().m_font; 2206 return state().m_font;
2157 } 2207 }
2158 2208
2159 int CanvasRenderingContext2D::getFontBaseline(const FontMetrics& fontMetrics) co nst 2209 int CanvasRenderingContext2D::getFontBaseline(const FontMetrics& fontMetrics) co nst
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 { 2298 {
2249 if (!canvas()->renderer()) 2299 if (!canvas()->renderer())
2250 return; 2300 return;
2251 2301
2252 // If accessibility is already enabled in this frame, associate this path's 2302 // If accessibility is already enabled in this frame, associate this path's
2253 // bounding box with the accessible object. Do this even if the element 2303 // bounding box with the accessible object. Do this even if the element
2254 // isn't focused because assistive technology might try to explore the objec t's 2304 // isn't focused because assistive technology might try to explore the objec t's
2255 // location before it gets focus. 2305 // location before it gets focus.
2256 if (AXObjectCache* axObjectCache = element->document().existingAXObjectCache ()) { 2306 if (AXObjectCache* axObjectCache = element->document().existingAXObjectCache ()) {
2257 if (AXObject* obj = axObjectCache->getOrCreate(element)) { 2307 if (AXObject* obj = axObjectCache->getOrCreate(element)) {
2258 // Get the bounding rect and apply transformations. 2308 // set the bounds of the accessible element.
2259 FloatRect bounds = m_path.boundingRect(); 2309 LayoutRect elementRect;
2260 AffineTransform ctm = state().m_transform; 2310 absoluteBoundingPathRect(path, elementRect);
2261 FloatRect transformedBounds = ctm.mapRect(bounds);
2262 LayoutRect elementRect = LayoutRect(transformedBounds);
2263
2264 // Offset by the canvas rect and set the bounds of the accessible el ement.
2265 IntRect canvasRect = canvas()->renderer()->absoluteBoundingBoxRect() ;
2266 elementRect.moveBy(canvasRect.location());
2267 obj->setElementRect(elementRect); 2311 obj->setElementRect(elementRect);
2268 2312
2269 // Set the bounds of any ancestor accessible elements, up to the can vas element, 2313 // Set the bounds of any ancestor accessible elements, up to the can vas element,
2270 // otherwise this element will appear to not be within its parent el ement. 2314 // otherwise this element will appear to not be within its parent el ement.
2271 obj = obj->parentObject(); 2315 obj = obj->parentObject();
2272 while (obj && obj->node() != canvas()) { 2316 while (obj && obj->node() != canvas()) {
2273 obj->setElementRect(elementRect); 2317 obj->setElementRect(elementRect);
2274 obj = obj->parentObject(); 2318 obj = obj->parentObject();
2275 } 2319 }
2276 } 2320 }
(...skipping 20 matching lines...) Expand all
2297 const int focusRingWidth = 5; 2341 const int focusRingWidth = 5;
2298 const int focusRingOutline = 0; 2342 const int focusRingOutline = 0;
2299 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2343 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2300 2344
2301 c->restore(); 2345 c->restore();
2302 2346
2303 didDraw(dirtyRect); 2347 didDraw(dirtyRect);
2304 } 2348 }
2305 2349
2306 } // namespace WebCore 2350 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698