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

Unified 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: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp
diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
index b2701331d1dffccff104b5be49378965be011792..6aa11cc8f3c779c16b73352258768bb6f29fbf9d 100644
--- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp
+++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
@@ -34,6 +34,7 @@
#include "core/html/canvas/CanvasRenderingContext2D.h"
#include "CSSPropertyNames.h"
+#include "core/accessibility/AXObjectCache.h"
Stephen White 2013/07/19 14:37:11 It seems unfortunate to add this dependency direct
#include "core/css/CSSFontSelector.h"
#include "core/css/CSSParser.h"
#include "core/css/StylePropertySet.h"
@@ -2307,4 +2308,68 @@ PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib
return attributes.release();
}
+void CanvasRenderingContext2D::drawSystemFocusRing(Element* element)
+{
+ drawFocusRing(m_path, element, false);
+}
+
+void CanvasRenderingContext2D::drawSystemFocusRing(DOMPath* path, Element* element)
+{
+ drawFocusRing(path->path(), element, false);
+}
+
+bool CanvasRenderingContext2D::drawCustomFocusRing(Element* element)
+{
+ drawFocusRing(m_path, element, true);
+ // Blink doesn't draw a custom focus ring; we always return false to inform the web app it should draw it.
+ return false;
+}
+
+bool CanvasRenderingContext2D::drawCustomFocusRing(DOMPath* path, Element* element)
+{
+ drawFocusRing(path->path(), element, true);
+ // Blink doesn't draw a custom focus ring; we always return false to inform the web app it should draw it.
+ return false;
+}
+
+void CanvasRenderingContext2D::drawFocusRing(const Path& path, Element* element, bool custom)
+{
+ GraphicsContext* c = drawingContext();
+ if (!c)
+ return;
+ if (!state().m_invertibleCTM)
+ return;
+ if (path.isEmpty())
+ return;
+ FloatRect boundingRect = path.boundingRect();
+
+ // If accessibility is enabled, associate this bounding box with the element.
+ if (AXObjectCache* axObjectCache = element->document()->existingAXObjectCache()) {
+ if (AccessibilityObject* obj = axObjectCache->getOrCreate(element)) {
+ IntRect canvasRect = canvas()->renderer()->absoluteBoundingBoxRect();
+ LayoutRect rect = LayoutRect(boundingRect);
+ rect.moveBy(canvasRect.location());
+ obj->setElementRect(rect);
+ }
+ }
+
+ // Only draw if the element is focused and if the function called wasn't drawCustomFocusRing.
+ if (custom || !element->focused())
+ return;
+
+ // Get the outline style from the element and use it to draw the focus ring on the canvas.
+ RenderStyle* style = element->computedStyle();
+ if (!style)
+ return;
+
+ c->save();
+ c->setAlpha(1.0);
+ c->clearShadow();
+ Vector<IntRect> rects;
+ rects.append(pixelSnappedIntRect(LayoutRect(boundingRect)));
+ c->drawFocusRing(rects, style->outlineWidth(), style->outlineOffset(), style->visitedDependentColor(CSSPropertyOutlineColor));
+ c->restore();
+ didDraw(boundingRect);
+}
+
} // namespace WebCore
« 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