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

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: Use default style rather than from element, move behind flag 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 16248369b57dc383f2cd44936d60dd3f857e28a3..162d55685b8c9a754ba09eaeb05ff51ce4754469 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"
#include "core/css/CSSFontSelector.h"
#include "core/css/CSSParser.h"
#include "core/css/StylePropertySet.h"
@@ -60,6 +61,7 @@
#include "core/platform/graphics/TextRun.h"
#include "core/platform/graphics/transforms/AffineTransform.h"
#include "core/rendering/RenderLayer.h"
+#include "core/rendering/RenderTheme.h"
#include "weborigin/SecurityOrigin.h"
#include "wtf/CheckedArithmetic.h"
@@ -2337,4 +2339,56 @@ PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib
return attributes.release();
}
+void CanvasRenderingContext2D::drawSystemFocusRing(Element* element)
+{
+ drawFocusRing(m_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;
+}
+
+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;
+
+ c->save();
+ c->setAlpha(1.0);
+ c->clearShadow();
+ c->setCompositeOperation(CompositeSourceOver, BlendModeNormal);
+
+ RefPtr<RenderStyle> style(RenderStyle::createDefaultStyle());
+ Color focusRingColor = RenderTheme::focusRingColor();
+ Vector<IntRect> rects;
+ rects.append(pixelSnappedIntRect(LayoutRect(boundingRect)));
+ c->drawFocusRing(rects, style->outlineWidth(), style->outlineOffset(), focusRingColor);
jbroman 2013/07/29 17:25:08 Why not draw the path itself? GraphicsContext::dra
Rik 2013/07/29 20:10:00 I'm unsure this is true. The spec is confusing her
dmazzoni 2013/07/29 21:44:21 It's unclear to me too. Since this is behind a fl
+
+ 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