Bug 966591 - Part 3: Compute bounds of current path and set them as the accessible region. r=roc

This commit is contained in:
Rik Cabanier 2014-02-21 08:35:58 -05:00
parent bdca28a308
commit 8ba62aa1e9
2 changed files with 25 additions and 0 deletions

View File

@ -2162,6 +2162,7 @@ GK_ATOM(eventFromInput, "event-from-input")
GK_ATOM(grammar, "grammar")
GK_ATOM(gridcell, "gridcell")
GK_ATOM(heading, "heading")
GK_ATOM(hitregion, "hitregion")
GK_ATOM(InlineBlockFrame, "InlineBlockFrame")
GK_ATOM(inlinevalue, "inline")
GK_ATOM(invalid, "invalid")

View File

@ -2355,6 +2355,18 @@ CanvasRenderingContext2D::MeasureText(const nsAString& rawText,
return new TextMetrics(width);
}
// Callback function, for freeing hit regions bounds values stored in property table
static void
ReleaseBBoxPropertyValue(void* aObject, /* unused */
nsIAtom* aPropertyName, /* unused */
void* aPropertyValue,
void* aData /* unused */)
{
nsRect* valPtr =
static_cast<nsRect*>(aPropertyValue);
delete valPtr;
}
void
CanvasRenderingContext2D::AddHitRegion(const HitRegionOptions& options, ErrorResult& error)
{
@ -2374,6 +2386,18 @@ CanvasRenderingContext2D::AddHitRegion(const HitRegionOptions& options, ErrorRes
return;
}
// check if the path is valid
EnsureUserSpacePath(CanvasWindingRule::Nonzero);
if(!mPath) {
error.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
// get the bounds of the current path. They are relative to the canvas
mgfx::Rect bounds(mPath->GetBounds(mTarget->GetTransform()));
nsRect* nsBounds = new nsRect(bounds.x, bounds.y, bounds.width, bounds.height);
options.mControl->SetProperty(nsGkAtoms::hitregion, nsBounds, ReleaseBBoxPropertyValue, true);
// finally, add the region to the list if it has an ID
if (options.mId.Length() != 0) {
mHitRegionsOptions.PutEntry(options.mId)->mElement = options.mControl;