From d1b8fff123afbdf9b7f0238a42cad053a61fb5ef Mon Sep 17 00:00:00 2001 From: Rik Cabanier Date: Fri, 21 Feb 2014 08:37:41 -0500 Subject: [PATCH] Bug 966591 - Part 6: Some bug fixes to match spec. r=roc --- .../canvas/src/CanvasRenderingContext2D.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/content/canvas/src/CanvasRenderingContext2D.cpp b/content/canvas/src/CanvasRenderingContext2D.cpp index c0dc01ff5d8..d6f88d51fbd 100755 --- a/content/canvas/src/CanvasRenderingContext2D.cpp +++ b/content/canvas/src/CanvasRenderingContext2D.cpp @@ -2381,9 +2381,9 @@ CanvasRenderingContext2D::AddHitRegion(const HitRegionOptions& options, ErrorRes // check if the control is a descendant of our canvas HTMLCanvasElement* canvas = GetCanvas(); + bool isDescendant = true; if (!canvas || !nsContentUtils::ContentIsDescendantOf(options.mControl, canvas)) { - error.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return; + isDescendant = false; } // check if the path is valid @@ -2395,10 +2395,19 @@ CanvasRenderingContext2D::AddHitRegion(const HitRegionOptions& options, ErrorRes // get the bounds of the current path. They are relative to the canvas mgfx::Rect bounds(mPath->GetBounds(mTarget->GetTransform())); - gfxRect rect(bounds.x, bounds.y, bounds.width, bounds.height); - nsRect* nsBounds = new nsRect(); - *nsBounds = nsLayoutUtils::RoundGfxRectToAppRect(rect, AppUnitsPerCSSPixel()); - options.mControl->SetProperty(nsGkAtoms::hitregion, nsBounds, ReleaseBBoxPropertyValue, true); + if ((bounds.width == 0) || (bounds.height == 0) || !bounds.IsFinite()) { + // The specified region has no pixels. + error.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); + return; + } + + if (isDescendant) { + nsRect* nsBounds = new nsRect(); + gfxRect rect(bounds.x, bounds.y, bounds.width, bounds.height); + *nsBounds = nsLayoutUtils::RoundGfxRectToAppRect(rect, AppUnitsPerCSSPixel()); + 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) {