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

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

Issue 299823003: Enable canvas.drawFocusIfNeeded() by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: remove test Created 6 years, 7 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 2263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2274 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen t) 2274 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen t)
2275 { 2275 {
2276 drawFocusIfNeededInternal(path2d->path(), element); 2276 drawFocusIfNeededInternal(path2d->path(), element);
2277 } 2277 }
2278 2278
2279 void CanvasRenderingContext2D::drawFocusIfNeededInternal(const Path& path, Eleme nt* element) 2279 void CanvasRenderingContext2D::drawFocusIfNeededInternal(const Path& path, Eleme nt* element)
2280 { 2280 {
2281 if (!focusRingCallIsValid(path, element)) 2281 if (!focusRingCallIsValid(path, element))
2282 return; 2282 return;
2283 2283
2284 updateFocusRingAccessibility(path, element);
2285 // Note: we need to check document->focusedElement() rather than just callin g 2284 // Note: we need to check document->focusedElement() rather than just callin g
2286 // element->focused(), because element->focused() isn't updated until after 2285 // element->focused(), because element->focused() isn't updated until after
2287 // focus events fire. 2286 // focus events fire.
2288 if (element->document().focusedElement() == element) 2287 if (element->document().focusedElement() == element)
2289 drawFocusRing(path); 2288 drawFocusRing(path);
2290 } 2289 }
2291 2290
2292 bool CanvasRenderingContext2D::drawCustomFocusRing(Element* element) 2291 bool CanvasRenderingContext2D::drawCustomFocusRing(Element* element)
2293 { 2292 {
2294 if (!focusRingCallIsValid(m_path, element)) 2293 if (!focusRingCallIsValid(m_path, element))
2295 return false; 2294 return false;
2296 2295
2297 updateFocusRingAccessibility(m_path, element);
2298
2299 // Return true if the application should draw the focus ring. The spec allow s us to 2296 // Return true if the application should draw the focus ring. The spec allow s us to
2300 // override this for accessibility, but currently Blink doesn't take advanta ge of this. 2297 // override this for accessibility, but currently Blink doesn't take advanta ge of this.
2301 return element->focused(); 2298 return element->focused();
2302 } 2299 }
2303 2300
2304 bool CanvasRenderingContext2D::focusRingCallIsValid(const Path& path, Element* e lement) 2301 bool CanvasRenderingContext2D::focusRingCallIsValid(const Path& path, Element* e lement)
2305 { 2302 {
2306 ASSERT(element); 2303 ASSERT(element);
2307 if (!state().m_invertibleCTM) 2304 if (!state().m_invertibleCTM)
2308 return false; 2305 return false;
2309 if (path.isEmpty()) 2306 if (path.isEmpty())
2310 return false; 2307 return false;
2311 if (!element->isDescendantOf(canvas())) 2308 if (!element->isDescendantOf(canvas()))
2312 return false; 2309 return false;
2313 2310
2314 return true; 2311 return true;
2315 } 2312 }
2316 2313
2317 void CanvasRenderingContext2D::updateFocusRingAccessibility(const Path& path, El ement* element)
2318 {
2319 if (!canvas()->renderer())
2320 return;
2321
2322 // If accessibility is already enabled in this frame, associate this path's
2323 // bounding box with the accessible object. Do this even if the element
2324 // isn't focused because assistive technology might try to explore the objec t's
2325 // location before it gets focus.
2326 if (AXObjectCache* axObjectCache = element->document().existingAXObjectCache ()) {
2327 if (AXObject* obj = axObjectCache->getOrCreate(element)) {
2328 // Get the bounding rect and apply transformations.
2329 FloatRect bounds = path.boundingRect();
2330 AffineTransform ctm = state().m_transform;
2331 FloatRect transformedBounds = ctm.mapRect(bounds);
2332 LayoutRect elementRect = LayoutRect(transformedBounds);
2333
2334 // Offset by the canvas rect and set the bounds of the accessible el ement.
2335 IntRect canvasRect = canvas()->renderer()->absoluteBoundingBoxRect() ;
2336 elementRect.moveBy(canvasRect.location());
2337 obj->setElementRect(elementRect);
2338
2339 // Set the bounds of any ancestor accessible elements, up to the can vas element,
2340 // otherwise this element will appear to not be within its parent el ement.
2341 obj = obj->parentObject();
2342 while (obj && obj->node() != canvas()) {
2343 obj->setElementRect(elementRect);
2344 obj = obj->parentObject();
2345 }
2346 }
2347 }
2348 }
2349
2350 void CanvasRenderingContext2D::drawFocusRing(const Path& path) 2314 void CanvasRenderingContext2D::drawFocusRing(const Path& path)
2351 { 2315 {
2352 GraphicsContext* c = drawingContext(); 2316 GraphicsContext* c = drawingContext();
2353 if (!c) 2317 if (!c)
2354 return; 2318 return;
2355 2319
2356 // These should match the style defined in html.css. 2320 // These should match the style defined in html.css.
2357 Color focusRingColor = RenderTheme::theme().focusRingColor(); 2321 Color focusRingColor = RenderTheme::theme().focusRingColor();
2358 const int focusRingWidth = 5; 2322 const int focusRingWidth = 5;
2359 const int focusRingOutline = 0; 2323 const int focusRingOutline = 0;
(...skipping 10 matching lines...) Expand all
2370 c->setAlphaAsFloat(1.0); 2334 c->setAlphaAsFloat(1.0);
2371 c->clearShadow(); 2335 c->clearShadow();
2372 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal); 2336 c->setCompositeOperation(CompositeSourceOver, blink::WebBlendModeNormal);
2373 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor); 2337 c->drawFocusRing(path, focusRingWidth, focusRingOutline, focusRingColor);
2374 c->restore(); 2338 c->restore();
2375 2339
2376 didDraw(dirtyRect); 2340 didDraw(dirtyRect);
2377 } 2341 }
2378 2342
2379 } // namespace WebCore 2343 } // 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