diff options
| author | mrmr1993 | 2014-12-17 12:27:40 +0000 | 
|---|---|---|
| committer | mrmr1993 | 2014-12-17 12:27:40 +0000 | 
| commit | 5f9290693ab0f35c46cea6cea0a9f5c06b4ee0ad (patch) | |
| tree | 06aa6fb072fa39cd5bc1ca5c050389072d873355 /lib | |
| parent | 28c275ae4128f0a2907c7ad3d27cedc81efe129a (diff) | |
| download | vimium-5f9290693ab0f35c46cea6cea0a9f5c06b4ee0ad.tar.bz2 | |
Combine rectangle calculation and clickable element detection
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/dom_utils.coffee | 28 | 
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index a0ac0bd3..3d7e805f 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -90,6 +90,34 @@ DomUtils =            return childClientRect      null +  getClientRectsForAreas: (imgClientRect, areas) -> +    rects = [] +    for area in areas +      coords = area.coords.split(",").map((coord) -> parseInt(coord, 10)) +      shape = area.shape.toLowerCase() +      if shape == "rect" +        [x1, y1, x2, y2] = coords +      else if shape == "circle" +        [x, y, r] = coords +        x1 = x - r +        x2 = x + r +        y1 = y - r +        y2 = y + r +      else # For polygons and unknown shapes, don't return a rectangle. +        # TODO(mrmr1993): revisit this. +        continue + +      rect = +        top: imgClientRect.top + y1 +        left: imgClientRect.left + x1 +        right: imgClientRect.left + x2 +        bottom: imgClientRect.top + y2 +        width: x2 - x1 +        height: y2 - y1 + +      rects.push {element: area, rect: rect} unless isNaN rect.top +    rects +    #    # Selectable means that we should use the simulateSelect method to activate the element instead of a click.    #  | 
