113 if (
key == 0)
return 0;
115 for (; *
key != 0;
key++) {
138 assert(
list != NULL);
143 map = calloc(1,
sizeof(*map));
148 map->
key = strdup(dom_string_data(
key));
149 if (map->
key == NULL) {
173 assert(list != NULL);
177 while (entry != NULL) {
214 while (map != NULL) {
247 while (map != NULL) {
248 NSLOG(netsurf, INFO,
"Imagemap: %s", map->
key);
250 for (entry = map->
list; entry; entry = entry->
next) {
251 switch (entry->
type) {
253 NSLOG(netsurf, INFO,
"\tDefault: %s",
258 "\tRectangle: %s: [(%d,%d),(%d,%d)]",
267 "\tCircle: %s: [(%d,%d),%d]",
279 fprintf(stderr,
"(%d,%d) ",
283 fprintf(stderr,
"\n");
310 dom_string *href = NULL, *
target = NULL, *shape = NULL;
311 dom_string *coords = NULL;
315 if (dom_string_caseless_isequal(tagtype, corestring_dom_area)) {
317 exc = dom_element_has_attribute(n,
318 corestring_dom_nohref, &nohref);
319 if ((exc != DOM_NO_ERR) || nohref)
324 exc = dom_element_get_attribute(n, corestring_dom_href, &href);
325 if (exc != DOM_NO_ERR || href == NULL) {
330 exc = dom_element_get_attribute(n, corestring_dom_target, &
target);
331 if (exc != DOM_NO_ERR) {
335 exc = dom_element_get_attribute(n, corestring_dom_shape, &shape);
336 if (exc != DOM_NO_ERR) {
342 shape = dom_string_ref(corestring_dom_rect);
344 if (!dom_string_caseless_lwc_isequal(shape, corestring_lwc_default)) {
346 exc = dom_element_get_attribute(n, corestring_dom_coords,
348 if (exc != DOM_NO_ERR || coords == NULL) {
353 new_map = calloc(1,
sizeof(*new_map));
354 if (new_map == NULL) {
358 if (dom_string_caseless_lwc_isequal(shape, corestring_lwc_rect) ||
359 dom_string_caseless_lwc_isequal(shape, corestring_lwc_rectangle))
361 else if (dom_string_caseless_lwc_isequal(shape, corestring_lwc_circle))
363 else if (dom_string_caseless_lwc_isequal(shape, corestring_lwc_poly) ||
364 dom_string_caseless_lwc_isequal(shape, corestring_lwc_polygon))
366 else if (dom_string_caseless_lwc_isequal(shape, corestring_lwc_default))
374 if (new_map->
url == NULL) {
376 goto ok_free_map_out;
381 new_map->
target = malloc(dom_string_byte_length(
target) + 1);
382 if (new_map->
target == NULL)
387 dom_string_byte_length(
target));
396 char *val = strtok((
char *)dom_string_data(coords),
",");
399 switch (new_map->
type) {
402 while (val != NULL &&
num <= 4) {
419 val = strtok(NULL,
",");
424 while (val != NULL &&
num <= 3) {
438 val = strtok(NULL,
",");
445 while (val != NULL) {
448 val = strtok(NULL,
",");
455 num *
sizeof(
float));
462 num *
sizeof(
float));
472 val = strtok(NULL,
",");
483 new_map->
next = NULL;
487 for (temp = (*entry); temp->
next != NULL; temp = temp->
next)
489 temp->
next = new_map;
500 if (new_map != NULL) {
501 if (new_map->
url != NULL)
509 if (new_map->
target != NULL)
516 dom_string_unref(href);
520 dom_string_unref(shape);
522 dom_string_unref(coords);
538 struct mapentry **entry, dom_string *tname)
545 exc = dom_element_get_elements_by_tag_name(node, tname, &nlist);
546 if (exc != DOM_NO_ERR) {
550 exc = dom_nodelist_get_length(nlist, &tag_count);
551 if (exc != DOM_NO_ERR) {
552 dom_nodelist_unref(nlist);
556 for (ent = 0; ent < tag_count; ++ent) {
559 exc = dom_nodelist_item(nlist, ent, &subnode);
560 if (exc != DOM_NO_ERR) {
561 dom_nodelist_unref(nlist);
565 entry, tname) ==
false) {
566 dom_node_unref(subnode);
567 dom_nodelist_unref(nlist);
570 dom_node_unref(subnode);
573 dom_nodelist_unref(nlist);
590 corestring_dom_area) ==
false)
611 exc = dom_document_get_elements_by_tag_name(c->
document,
614 if (exc != DOM_NO_ERR) {
618 exc = dom_nodelist_get_length(nlist, &maybe_maps);
619 if (exc != DOM_NO_ERR) {
624 for (mapnr = 0; mapnr < maybe_maps; ++mapnr) {
627 exc = dom_nodelist_item(nlist, mapnr, &node);
628 if (exc != DOM_NO_ERR) {
633 exc = dom_element_get_attribute(node, corestring_dom_id,
635 if (exc != DOM_NO_ERR) {
636 dom_node_unref(node);
642 exc = dom_element_get_attribute(node,
645 if (exc != DOM_NO_ERR) {
646 dom_node_unref(node);
659 dom_string_unref(name);
660 dom_node_unref(node);
670 if ((entry != NULL) &&
674 dom_string_unref(name);
675 dom_node_unref(node);
681 dom_string_unref(name);
682 dom_node_unref(node);
687 dom_nodelist_unref(nlist);
707 unsigned long y,
unsigned long click_x,
unsigned long click_y)
714 for (i = 0, j =
num - 1; i <
num; j = i++) {
715 if ((((ypt[i] +
y <= click_y) && (click_y < ypt[j] +
y)) ||
716 ((ypt[j] +
y <= click_y) && (click_y < ypt[i] +
y))) &&
717 (click_x < (xpt[j] - xpt[i]) *
718 (click_y - (ypt[i] +
y)) / (ypt[j] - ypt[i]) + xpt[i] +
x))
738 unsigned long x,
unsigned long y,
739 unsigned long click_x,
unsigned long click_y,
742 unsigned int slot = 0;
745 unsigned long cx, cy;
757 for (map = c->
imagemaps[slot]; map != NULL; map = map->
next) {
758 if (map->
key != NULL && strcasecmp(map->
key, key) == 0)
762 if (map == NULL || map->
list == NULL)
765 for (entry = map->
list; entry; entry = entry->
next) {
766 switch (entry->
type) {
775 click_x <= x + entry->
bounds.rect.x1 &&
777 click_y <= y + entry->
bounds.rect.y1) {
786 if ((cx * cx + cy * cy) <=
bool box_extract_link(const html_content *content, const dom_string *dsrel, nsurl *base, nsurl **result)
HTML Box tree construction interface.
Protected interface to Content handling.
Useful interned string pointers (interface).
nserror
Enumeration of error codes.
@ NSERROR_DOM
DOM call returned error.
@ NSERROR_NOMEM
Memory exhaustion.
High-level resource cache interface.
static bool imagemap_extract_map_entries(dom_node *node, html_content *c, struct mapentry **entry, dom_string *tname)
Extract an imagemap from html source.
nsurl * imagemap_get(struct html_content *c, const char *key, unsigned long x, unsigned long y, unsigned long click_x, unsigned long click_y, const char **target)
Retrieve url associated with imagemap entry.
void imagemap_dump(html_content *c)
Dump imagemap data to the log.
static bool imagemap_extract_map(dom_node *node, html_content *c, struct mapentry **entry)
Extract an imagemap from html source.
static unsigned int imagemap_hash(const char *key)
Hash function.
static void imagemap_freelist(struct mapentry *list)
Free list of imagemap entries.
static bool imagemap_add(html_content *c, dom_string *key, struct mapentry *list)
Add an imagemap to the hashtable, creating it if it doesn't exist.
static bool imagemap_create(html_content *c)
Create hashtable of imagemaps.
void imagemap_destroy(html_content *c)
Destroy hashtable of imagemaps.
nserror imagemap_extract(html_content *c)
Extract all imagemaps from a document tree.
static bool imagemap_addtolist(const struct html_content *c, dom_node *n, nsurl *base_url, struct mapentry **entry, dom_string *tagtype)
Adds an imagemap entry to the list.
static int imagemap_point_in_poly(int num, float *xpt, float *ypt, unsigned long x, unsigned long y, unsigned long click_x, unsigned long click_y)
Test if a point lies within an arbitrary polygon Modified from comp.graphics.algorithms FAQ 2....
Interface to HTML imagemap.
#define NSLOG(catname, level, logmsg, args...)
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
Private data for text/html content.
Interface to utility string handling.
Data specific to CONTENT_HTML.
struct imagemap ** imagemaps
Hash table of imagemaps.
dom_document * document
Document tree.
struct nsurl * base_url
Base URL (may be a copy of content->url).
struct imagemap * next
next entry in this hash chain
char * key
key for this entry
struct mapentry * list
pointer to linked list of entries
struct mapentry::@137::@138 circle
struct mapentry * next
next entry in list
float * ycoords
y coordinates
char * target
target frame (if any)
struct mapentry::@137::@139 rect
int y
y coordinate of center
union mapentry::@137 bounds
float * xcoords
x coordinates
imagemap_entry_type type
type of shape
nsurl * url
absolute url to go to
struct mapentry::@137::@140 poly
int x
x coordinate of centre