Chromium Code Reviews| Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp | 
| diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp | 
| index 1c92df5400c91c95558a8266871c7923bbed128c..058d4add2704d1e20dd34ab92e2543cd160229b4 100644 | 
| --- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp | 
| +++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp | 
| @@ -37,7 +37,6 @@ | 
| #include "bindings/v8/ExceptionMessages.h" | 
| #include "bindings/v8/ExceptionState.h" | 
| #include "bindings/v8/ExceptionStatePlaceholder.h" | 
| -#include "core/accessibility/AXObjectCache.h" | 
| #include "core/css/CSSFontSelector.h" | 
| #include "core/css/parser/BisonCSSParser.h" | 
| #include "core/css/StylePropertySet.h" | 
| @@ -86,6 +85,7 @@ static bool contextLostRestoredEventsEnabled() | 
| CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, const Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode) | 
| : CanvasRenderingContext(canvas) | 
| + , m_hitRegionManager(HitRegionManager::create()) | 
| , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode) | 
| , m_hasAlpha(!attrs || attrs->alpha()) | 
| , m_isContextLost(false) | 
| @@ -168,6 +168,7 @@ void CanvasRenderingContext2D::trace(Visitor* visitor) | 
| #if ENABLE(OILPAN) | 
| visitor->trace(m_stateStack); | 
| visitor->trace(m_fetchedFonts); | 
| + visitor->trace(m_hitRegionManager); | 
| #endif | 
| CanvasRenderingContext::trace(visitor); | 
| } | 
| @@ -1244,6 +1245,7 @@ void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he | 
| context->setCompositeOperation(CompositeSourceOver); | 
| } | 
| context->clearRect(rect); | 
| + m_hitRegionManager->removeHitRegionsInRect(rect, state().m_transform); | 
| if (saved) | 
| context->restore(); | 
| @@ -2356,4 +2358,69 @@ void CanvasRenderingContext2D::drawFocusRing(const Path& path) | 
| didDraw(dirtyRect); | 
| } | 
| +void CanvasRenderingContext2D::addHitRegion(ExceptionState& exceptionState) | 
| +{ | 
| + addHitRegion(Dictionary(), exceptionState); | 
| +} | 
| + | 
| +void CanvasRenderingContext2D::addHitRegion(const Dictionary& options, ExceptionState& exceptionState) | 
| +{ | 
| + HitRegionOptions passOptions; | 
| + | 
| + bool hasId = options.getWithUndefinedOrNullCheck("id", passOptions.id) && !passOptions.id.isEmpty(); | 
| + bool hasControl = options.getWithUndefinedOrNullCheck("control", passOptions.control) && passOptions.control; | 
| + | 
| + if (!(hasId || hasControl)) { | 
| + exceptionState.throwDOMException(NotSupportedError, "Both id and control are null."); | 
| + return; | 
| + } | 
| + | 
| + FloatRect clipBounds; | 
| + GraphicsContext* context = drawingContext(); | 
| + | 
| + if (m_path.isEmpty() || !context || !state().m_invertibleCTM | 
| + || !context->getTransformedClipBounds(&clipBounds)) { | 
| + exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels."); | 
| + return; | 
| + } | 
| + | 
| + // This clipPath isn't always empty. | 
| + Path clipPath; | 
| + clipPath.addRect(clipBounds); | 
| 
 
fs
2014/06/04 08:13:40
clipBounds vs. CRC2D.clip()
(i.e. what if it is a
 
zino
2014/06/06 06:35:17
Done.
But I didn't add some tests yet.
I'll upload
 
 | 
| + | 
| + Path specifiedPath = m_path; | 
| + specifiedPath.transform(state().m_transform); | 
| + specifiedPath.intersectPath(clipPath); | 
| + | 
| + passOptions.path = specifiedPath; | 
| + | 
| + addHitRegionInternal(passOptions, exceptionState); | 
| +} | 
| + | 
| +void CanvasRenderingContext2D::addHitRegionInternal(const HitRegionOptions& options, ExceptionState& exceptionState) | 
| +{ | 
| + // Remove previous region (with id or control) | 
| + m_hitRegionManager->removeHitRegionById(options.id); | 
| + m_hitRegionManager->removeHitRegionByControl(options.control.get()); | 
| + | 
| + RefPtrWillBeRawPtr<HitRegion> hitRegion = HitRegion::create(options); | 
| + hitRegion->updateAccessibility(canvas()); | 
| + m_hitRegionManager->addHitRegion(hitRegion.release()); | 
| +} | 
| + | 
| +void CanvasRenderingContext2D::removeHitRegion(const String& id) | 
| +{ | 
| + m_hitRegionManager->removeHitRegionById(id); | 
| +} | 
| + | 
| +void CanvasRenderingContext2D::clearHitRegions() | 
| +{ | 
| + m_hitRegionManager->removeAllHitRegions(); | 
| +} | 
| + | 
| +HitRegion* CanvasRenderingContext2D::hitRegionAtPoint(const LayoutPoint& point) | 
| +{ | 
| + return m_hitRegionManager->getHitRegionAtPoint(point); | 
| +} | 
| + | 
| } // namespace WebCore |