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

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

Issue 19786002: Implement canvas focus ring methods. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove unused IntRect array Created 7 years, 4 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 | Annotate | Revision Log
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 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012 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 16 matching lines...) Expand all
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 #include "config.h" 33 #include "config.h"
34 #include "core/html/canvas/CanvasRenderingContext2D.h" 34 #include "core/html/canvas/CanvasRenderingContext2D.h"
35 35
36 #include "CSSPropertyNames.h" 36 #include "CSSPropertyNames.h"
37 #include "core/accessibility/AXObjectCache.h"
37 #include "core/css/CSSFontSelector.h" 38 #include "core/css/CSSFontSelector.h"
38 #include "core/css/CSSParser.h" 39 #include "core/css/CSSParser.h"
39 #include "core/css/StylePropertySet.h" 40 #include "core/css/StylePropertySet.h"
40 #include "core/css/resolver/StyleResolver.h" 41 #include "core/css/resolver/StyleResolver.h"
41 #include "core/dom/ExceptionCode.h" 42 #include "core/dom/ExceptionCode.h"
42 #include "core/dom/ExceptionCodePlaceholder.h" 43 #include "core/dom/ExceptionCodePlaceholder.h"
43 #include "core/html/HTMLCanvasElement.h" 44 #include "core/html/HTMLCanvasElement.h"
44 #include "core/html/HTMLImageElement.h" 45 #include "core/html/HTMLImageElement.h"
45 #include "core/html/HTMLMediaElement.h" 46 #include "core/html/HTMLMediaElement.h"
46 #include "core/html/HTMLVideoElement.h" 47 #include "core/html/HTMLVideoElement.h"
47 #include "core/html/ImageData.h" 48 #include "core/html/ImageData.h"
48 #include "core/html/TextMetrics.h" 49 #include "core/html/TextMetrics.h"
49 #include "core/html/canvas/Canvas2DContextAttributes.h" 50 #include "core/html/canvas/Canvas2DContextAttributes.h"
50 #include "core/html/canvas/CanvasGradient.h" 51 #include "core/html/canvas/CanvasGradient.h"
51 #include "core/html/canvas/CanvasPattern.h" 52 #include "core/html/canvas/CanvasPattern.h"
52 #include "core/html/canvas/CanvasStyle.h" 53 #include "core/html/canvas/CanvasStyle.h"
53 #include "core/html/canvas/DOMPath.h" 54 #include "core/html/canvas/DOMPath.h"
54 #include "core/loader/cache/CachedImage.h" 55 #include "core/loader/cache/CachedImage.h"
55 #include "core/page/ImageBitmap.h" 56 #include "core/page/ImageBitmap.h"
56 #include "core/platform/graphics/DrawLooper.h" 57 #include "core/platform/graphics/DrawLooper.h"
57 #include "core/platform/graphics/FloatQuad.h" 58 #include "core/platform/graphics/FloatQuad.h"
58 #include "core/platform/graphics/FontCache.h" 59 #include "core/platform/graphics/FontCache.h"
59 #include "core/platform/graphics/GraphicsContextStateSaver.h" 60 #include "core/platform/graphics/GraphicsContextStateSaver.h"
60 #include "core/platform/graphics/TextRun.h" 61 #include "core/platform/graphics/TextRun.h"
61 #include "core/platform/graphics/transforms/AffineTransform.h" 62 #include "core/platform/graphics/transforms/AffineTransform.h"
62 #include "core/rendering/RenderLayer.h" 63 #include "core/rendering/RenderLayer.h"
64 #include "core/rendering/RenderTheme.h"
63 #include "weborigin/SecurityOrigin.h" 65 #include "weborigin/SecurityOrigin.h"
64 66
65 #include "wtf/CheckedArithmetic.h" 67 #include "wtf/CheckedArithmetic.h"
66 #include "wtf/MathExtras.h" 68 #include "wtf/MathExtras.h"
67 #include "wtf/OwnPtr.h" 69 #include "wtf/OwnPtr.h"
68 #include "wtf/Uint8ClampedArray.h" 70 #include "wtf/Uint8ClampedArray.h"
69 #include "wtf/text/StringBuilder.h" 71 #include "wtf/text/StringBuilder.h"
70 72
71 using namespace std; 73 using namespace std;
72 74
(...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after
2330 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality : InterpolationNone); 2332 c->setImageInterpolationQuality(enabled ? DefaultInterpolationQuality : InterpolationNone);
2331 } 2333 }
2332 2334
2333 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const 2335 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const
2334 { 2336 {
2335 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); 2337 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate();
2336 attributes->setAlpha(m_hasAlpha); 2338 attributes->setAlpha(m_hasAlpha);
2337 return attributes.release(); 2339 return attributes.release();
2338 } 2340 }
2339 2341
2342 void CanvasRenderingContext2D::drawSystemFocusRing(Element* element)
2343 {
2344 if (!focusRingCallIsValid(m_path, element))
2345 return;
2346
2347 updateFocusRingAccessibility(m_path, element);
2348 if (element->focused())
2349 drawFocusRing(m_path, element);
2350 }
2351
2352 bool CanvasRenderingContext2D::drawCustomFocusRing(Element* element)
2353 {
2354 if (!focusRingCallIsValid(m_path, element))
2355 return false;
2356
2357 updateFocusRingAccessibility(m_path, element);
2358
2359 // Return true if the application should draw the focus ring. The spec allow s us to
2360 // override this for accessibility, but currently Blink doesn't take advanta ge of this.
2361 return element->focused();
2362 }
2363
2364 bool CanvasRenderingContext2D::focusRingCallIsValid(const Path& path, Element* e lement)
2365 {
2366 if (!state().m_invertibleCTM)
2367 return false;
2368 if (path.isEmpty())
2369 return false;
2370 if (!element->isDescendantOf(canvas()))
2371 return false;
2372
2373 return true;
2374 }
2375
2376 void CanvasRenderingContext2D::updateFocusRingAccessibility(const Path& path, El ement* element)
2377 {
2378 // If accessibility is already enabled in this frame, associate this path's
2379 // bounding box with the accessible object. Do this even if the element
2380 // isn't focused because assistive technology might try to explore the objec t's
2381 // location before it gets focus.
2382 if (AXObjectCache* axObjectCache = element->document()->existingAXObjectCach e()) {
2383 if (AccessibilityObject* obj = axObjectCache->getOrCreate(element)) {
2384 IntRect canvasRect = canvas()->renderer()->absoluteBoundingBoxRect() ;
2385 LayoutRect rect = LayoutRect(path.boundingRect());
2386 rect.moveBy(canvasRect.location());
2387 obj->setElementRect(rect);
2388 }
2389 }
2390 }
2391
2392 void CanvasRenderingContext2D::drawFocusRing(const Path& path, Element* element)
2393 {
2394 GraphicsContext* c = drawingContext();
2395 if (!c)
2396 return;
2397
2398 c->save();
2399 c->setAlpha(1.0);
2400 c->clearShadow();
2401 c->setCompositeOperation(CompositeSourceOver, BlendModeNormal);
2402
2403 RefPtr<RenderStyle> style(RenderStyle::createDefaultStyle());
2404 Color focusRingColor = RenderTheme::focusRingColor();
2405 c->drawFocusRing(path, style->outlineWidth(), style->outlineOffset(), focusR ingColor);
2406 didDraw(path.boundingRect());
2407
2408 c->restore();
2409 }
2410
2340 } // namespace WebCore 2411 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698