Bug 966591 - Part 3: Compute bounds of current path and set them as the accessible region. r=roc
☠☠ backed out by fb8597ff68ea ☠ ☠
authorRik Cabanier <cabanier@adobe.com>
Fri, 21 Feb 2014 08:35:58 -0500
changeset 170249 0c66968c2edde8fee83222f4b39f26033fabf64e
parent 170248 261a1ca9045cc6ca3379fcd0e6d8fc1bc7938db3
child 170250 81ba9bddd84e9ff432d81b4a4bf82f26d4e573bb
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersroc
bugs966591
milestone30.0a1
Bug 966591 - Part 3: Compute bounds of current path and set them as the accessible region. r=roc
content/base/src/nsGkAtomList.h
content/canvas/src/CanvasRenderingContext2D.cpp
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -2156,16 +2156,17 @@ GK_ATOM(containerLiveRole, "container-li
 GK_ATOM(containerRelevant, "container-relevant")
 GK_ATOM(cycles, "cycles")
 GK_ATOM(datatable, "datatable")
 GK_ATOM(directory, "directory")
 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")
 GK_ATOM(item, "item")
 GK_ATOM(itemset, "itemset")
 GK_ATOM(lineNumber, "line-number")
 GK_ATOM(linkedPanel, "linkedpanel")
 GK_ATOM(live, "live")
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -2350,16 +2350,28 @@ CanvasRenderingContext2D::MeasureText(co
   error = DrawOrMeasureText(rawText, 0, 0, maxWidth, TEXT_DRAW_OPERATION_MEASURE, &width);
   if (error.Failed()) {
     return nullptr;
   }
 
   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)
 {
   // remove old hit region first
   RemoveHitRegion(options.mId);
 
   // for now, we require a fallback element
   if (options.mControl == NULL) {
@@ -2369,16 +2381,28 @@ CanvasRenderingContext2D::AddHitRegion(c
 
   // check if the control is a descendant of our canvas
   HTMLCanvasElement* canvas = GetCanvas();
   if (!canvas || !nsContentUtils::ContentIsDescendantOf(options.mControl, canvas)) {
     error.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     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;
   }
 }
 
 void
 CanvasRenderingContext2D::RemoveHitRegion(const nsAString& id)