| Index: Source/core/html/canvas/CanvasRenderingContext2D.cpp
|
| diff --git a/Source/core/html/canvas/CanvasRenderingContext2D.cpp b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
|
| index 8456aba1db2b4de549857a809bf166dec4e1618a..19a827eaa1f77788a8b4b23128a3d546d2f060b3 100644
|
| --- a/Source/core/html/canvas/CanvasRenderingContext2D.cpp
|
| +++ b/Source/core/html/canvas/CanvasRenderingContext2D.cpp
|
| @@ -52,6 +52,7 @@
|
| #include "core/html/ImageData.h"
|
| #include "core/html/TextMetrics.h"
|
| #include "core/html/canvas/CanvasGradient.h"
|
| +#include "core/html/canvas/CanvasHitRegion.h"
|
| #include "core/html/canvas/CanvasPattern.h"
|
| #include "core/html/canvas/CanvasStyle.h"
|
| #include "core/html/canvas/Path2D.h"
|
| @@ -86,6 +87,7 @@ static bool contextLostRestoredEventsEnabled()
|
|
|
| CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, const Canvas2DContextAttributes* attrs, bool usesCSSCompatibilityParseMode)
|
| : CanvasRenderingContext(canvas)
|
| + , m_hitRegionManager(CanvasHitRegionManager::create())
|
| , m_usesCSSCompatibilityParseMode(usesCSSCompatibilityParseMode)
|
| , m_hasAlpha(!attrs || attrs->alpha())
|
| , m_isContextLost(false)
|
| @@ -166,6 +168,7 @@ void CanvasRenderingContext2D::trace(Visitor* visitor)
|
| {
|
| #if ENABLE(OILPAN)
|
| visitor->trace(m_stateStack);
|
| + visitor->trace(m_hitRegionManager);
|
| visitor->trace(m_fetchedFonts);
|
| #endif
|
| CanvasRenderingContext::trace(visitor);
|
| @@ -230,6 +233,7 @@ void CanvasRenderingContext2D::reset()
|
| m_stateStack.resize(1);
|
| m_stateStack.first() = adoptPtrWillBeNoop(new State());
|
| m_path.clear();
|
| + m_hitRegionManager->clear();
|
| }
|
|
|
| // Important: Several of these properties are also stored in GraphicsContext's
|
| @@ -1216,6 +1220,8 @@ void CanvasRenderingContext2D::clearRect(float x, float y, float width, float he
|
| if (!computeDirtyRect(rect, &dirtyRect))
|
| return;
|
|
|
| + m_hitRegionManager->removeEnclosed(rect, state().m_transform);
|
| +
|
| bool saved = false;
|
| if (shouldDrawShadows()) {
|
| context->save();
|
| @@ -2266,6 +2272,45 @@ PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib
|
| return attributes.release();
|
| }
|
|
|
| +void CanvasRenderingContext2D::addHitRegion(ExceptionState& exceptionState)
|
| +{
|
| + DecodedHitRegionOptions decodedOptions;
|
| + decodedOptions.resolvePath(m_path, state().m_transform);
|
| + // parentId / id will be null here, so no need to resolve them.
|
| +
|
| + addHitRegionInternal(decodedOptions, exceptionState);
|
| +}
|
| +
|
| +void CanvasRenderingContext2D::addHitRegion(const Dictionary& options, ExceptionState& exceptionState)
|
| +{
|
| + DecodedHitRegionOptions decodedOptions(options);
|
| + decodedOptions.resolvePath(m_path, state().m_transform);
|
| + decodedOptions.resolveIds(m_hitRegionManager.get());
|
| +
|
| + addHitRegionInternal(decodedOptions, exceptionState);
|
| +}
|
| +
|
| +void CanvasRenderingContext2D::removeHitRegion(const String& id)
|
| +{
|
| + if (CanvasHitRegion* hitRegion = m_hitRegionManager->getHitRegionById(id))
|
| + m_hitRegionManager->remove(hitRegion);
|
| +}
|
| +
|
| +CanvasHitRegion* CanvasRenderingContext2D::hitRegionAtPoint(const LayoutPoint& point)
|
| +{
|
| + return m_hitRegionManager->getHitRegionAtPoint(point);
|
| +}
|
| +
|
| +void CanvasRenderingContext2D::addHitRegionInternal(const DecodedHitRegionOptions& options, ExceptionState& exceptionState)
|
| +{
|
| + if (!options.validate(exceptionState))
|
| + return;
|
| +
|
| + RefPtrWillBeRawPtr<CanvasHitRegion> hitRegion = CanvasHitRegion::create(options);
|
| + m_hitRegionManager->remove(options.previousHitRegion.get());
|
| + m_hitRegionManager->add(hitRegion.release());
|
| +}
|
| +
|
| void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element)
|
| {
|
| drawFocusIfNeededInternal(m_path, element);
|
|
|