changeset 198:37febdaa9a71

- Fix: shape=default is the background in a client-side image map.
author jcid
date Wed, 30 Apr 2008 16:10:13 +0200
parents 04b72811e28f
children 7f033b2328e2
files ChangeLog src/html.cc
diffstat 2 files changed, 49 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Apr 29 22:44:49 2008 +0200
+++ b/ChangeLog	Wed Apr 30 16:10:13 2008 +0200
@@ -95,6 +95,7 @@
  - Added input image for FORMS.
  - Added button for FORMS.
  - Added nesting checks for BUTTON, SELECT and FORM.
+ - Fix: shape=default is the background in a client-side image map.
    Patches: place
 +- Fixed a problem with locally-installed dpis.
  - Added code for optional image loading (nice interface) very advanced!
--- a/src/html.cc	Tue Apr 29 22:44:49 2008 +0200
+++ b/src/html.cc	Wed Apr 30 16:10:13 2008 +0200
@@ -3017,7 +3017,9 @@
  */
 static void Html_tag_open_area(DilloHtml *html, const char *tag, int tagsize)
 {
-   misc::SimpleVector<int> *coords;
+   enum types {UNKNOWN, RECTANGLE, CIRCLE, POLYGON, BACKGROUND};
+   types type;
+   misc::SimpleVector<int> *coords = NULL;
    DilloUrl* url;
    const char *attrbuf;
    int link = -1;
@@ -3027,56 +3029,58 @@
       MSG_HTML("<area> element not inside <map>\n");
       return;
    }
-
-   /* todo: add support for coords in % */
-   if ((attrbuf = Html_get_attr(html, tag, tagsize, "coords"))) {
-      coords = Html_read_coords(html, attrbuf);
-   } else
-      return;
-  
    attrbuf = Html_get_attr(html, tag, tagsize, "shape");
 
    if (!attrbuf || !*attrbuf || !dStrcasecmp(attrbuf, "rect")) {
       /* the default shape is a rectangle */
-      if (coords->size() != 4)
-         MSG_HTML("<area> rectangle must have four coordinate values\n");
-      if (coords->size() >= 4)
-         shape = new Rectangle(coords->get(0),
-                               coords->get(1),
-                               coords->get(2) - coords->get(0),
-                               coords->get(3) - coords->get(1));
+      type = RECTANGLE;
    } else if (dStrcasecmp(attrbuf, "default") == 0) {
-      /* "Specifies the entire region." "default" is not the default shape. */
-      MSG("<area> shape=default not implemented.\n");
+      /* "default" is the background */
+      type = BACKGROUND;
    } else if (dStrcasecmp(attrbuf, "circle") == 0) {
-      if (coords->size() != 3)
-         MSG_HTML("<area> circle must have three coordinate values\n");
-      if (coords->size() >= 3)
-         shape = new Circle(coords->get(0), coords->get(1), coords->get(2));
+      type = CIRCLE;
    } else if (dStrncasecmp(attrbuf, "poly", 4) == 0) {
-      Polygon *poly;
-      int i;
-      if (coords->size() % 2)
-         MSG_HTML("<area> polygon with odd number of coordinates\n");
-      shape = poly = new Polygon();
-      for (i = 0; i < (coords->size() / 2); i++)
-         poly->addPoint(coords->get(2*i), coords->get(2*i + 1));
-      if (i) {
-         /* be sure to close it */
-         poly->addPoint(coords->get(0), coords->get(1));
-      }
+      type = POLYGON;
    } else {
       MSG_HTML("<area> unknown shape: \"%s\"\n", attrbuf);
+      type = UNKNOWN;
    }
-
-   if (coords)
-      delete(coords);
-
-   if (shape) {
-      if (Html_get_attr(html, tag, tagsize, "nohref")) {
-         link = -1;
-         _MSG("nohref");
+   if (type == RECTANGLE || type == CIRCLE || type == POLYGON) {
+      /* todo: add support for coords in % */
+      if ((attrbuf = Html_get_attr(html, tag, tagsize, "coords"))) {
+         coords = Html_read_coords(html, attrbuf);
+
+         if (type == RECTANGLE) {
+            if (coords->size() != 4)
+               MSG_HTML("<area> rectangle must have four coordinate values\n");
+            if (coords->size() >= 4)
+               shape = new Rectangle(coords->get(0),
+                                     coords->get(1),
+                                     coords->get(2) - coords->get(0),
+                                     coords->get(3) - coords->get(1));
+         } else if (type == CIRCLE) {
+            if (coords->size() != 3)
+               MSG_HTML("<area> circle must have three coordinate values\n");
+            if (coords->size() >= 3)
+               shape = new Circle(coords->get(0), coords->get(1),
+                                  coords->get(2));
+         } else if (type == POLYGON) {
+            Polygon *poly;
+            int i;
+            if (coords->size() % 2)
+               MSG_HTML("<area> polygon with odd number of coordinates\n");
+            shape = poly = new Polygon();
+            for (i = 0; i < (coords->size() / 2); i++)
+               poly->addPoint(coords->get(2*i), coords->get(2*i + 1));
+            if (i) {
+               /* be sure to close it */
+               poly->addPoint(coords->get(0), coords->get(1));
+            }
+         }
+         delete(coords);
       }
+   }
+   if (shape != NULL || type == BACKGROUND) {
       if ((attrbuf = Html_get_attr(html, tag, tagsize, "href"))) {
          url = Html_url_new(html, attrbuf, NULL, 0, 0, 0, 0);
          dReturn_if_fail ( url != NULL );
@@ -3085,7 +3089,10 @@
   
          link = Html_set_new_link(html, &url);
       }
-      html->maps.addShapeToCurrentMap(shape, link);
+      if (type == BACKGROUND)
+         html->maps.setCurrentMapDefaultLink(link);
+      else
+         html->maps.addShapeToCurrentMap(shape, link);
    }
 }