NetSurf
Data Structures | Macros | Enumerations | Functions
imagemap.c File Reference

Implementation of HTML image maps. More...

#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <dom/dom.h>
#include "utils/log.h"
#include "utils/corestrings.h"
#include "content/content_protected.h"
#include "content/hlcache.h"
#include "html/box.h"
#include "html/box_construct.h"
#include "html/private.h"
#include "html/imagemap.h"
Include dependency graph for imagemap.c:

Go to the source code of this file.

Data Structures

struct  mapentry
 
struct  imagemap
 

Macros

#define HASH_SIZE   31 /* fixed size hash table */
 

Enumerations

enum  imagemap_entry_type { IMAGEMAP_DEFAULT , IMAGEMAP_RECT , IMAGEMAP_CIRCLE , IMAGEMAP_POLY }
 

Functions

static bool imagemap_create (html_content *c)
 Create hashtable of imagemaps. More...
 
static unsigned int imagemap_hash (const char *key)
 Hash function. More...
 
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. More...
 
static void imagemap_freelist (struct mapentry *list)
 Free list of imagemap entries. More...
 
void imagemap_destroy (html_content *c)
 Destroy hashtable of imagemaps. More...
 
void imagemap_dump (html_content *c)
 Dump imagemap data to the log. More...
 
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. More...
 
static bool imagemap_extract_map_entries (dom_node *node, html_content *c, struct mapentry **entry, dom_string *tname)
 Extract an imagemap from html source. More...
 
static bool imagemap_extract_map (dom_node *node, html_content *c, struct mapentry **entry)
 Extract an imagemap from html source. More...
 
nserror imagemap_extract (html_content *c)
 Extract all imagemaps from a document tree. More...
 
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.03. More...
 
nsurlimagemap_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. More...
 

Detailed Description

Implementation of HTML image maps.

Todo:
should this should use the general hashmap instead of its own

Definition in file imagemap.c.

Macro Definition Documentation

◆ HASH_SIZE

#define HASH_SIZE   31 /* fixed size hash table */

Definition at line 43 of file imagemap.c.

Enumeration Type Documentation

◆ imagemap_entry_type

Enumerator
IMAGEMAP_DEFAULT 
IMAGEMAP_RECT 
IMAGEMAP_CIRCLE 
IMAGEMAP_POLY 

Definition at line 45 of file imagemap.c.

Function Documentation

◆ imagemap_add()

static bool imagemap_add ( html_content c,
dom_string *  key,
struct mapentry list 
)
static

Add an imagemap to the hashtable, creating it if it doesn't exist.

Parameters
cThe containing content
keyThe name of the imagemap
listList of map regions
Returns
true on succes, false otherwise

Definition at line 131 of file imagemap.c.

References imagemap_create(), imagemap_hash(), html_content::imagemaps, imagemap::key, imagemap::list, and imagemap::next.

Referenced by imagemap_extract().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_addtolist()

static bool imagemap_addtolist ( const struct html_content c,
dom_node *  n,
nsurl base_url,
struct mapentry **  entry,
dom_string *  tagtype 
)
static

Adds an imagemap entry to the list.

Parameters
cThe html content that the imagemap belongs to
nThe xmlNode representing the entry to add
base_urlBase URL for resolving relative URLs
entryPointer to list of entries
tagtypeThe type of tag
Returns
false on memory exhaustion, true otherwise

Definition at line 303 of file imagemap.c.

References mapentry::bounds, box_extract_link(), mapentry::circle, IMAGEMAP_CIRCLE, IMAGEMAP_DEFAULT, IMAGEMAP_POLY, IMAGEMAP_RECT, mapentry::next, nsurl_unref(), mapentry::num, mapentry::poly, mapentry::r, mapentry::rect, mapentry::target, mapentry::type, mapentry::url, mapentry::x, mapentry::x0, mapentry::x1, mapentry::xcoords, mapentry::y, mapentry::y0, mapentry::y1, and mapentry::ycoords.

Referenced by imagemap_extract_map_entries().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_create()

static bool imagemap_create ( html_content c)
static

Create hashtable of imagemaps.

Parameters
cThe containing content
Returns
true on success, false otherwise

Definition at line 89 of file imagemap.c.

References HASH_SIZE, and html_content::imagemaps.

Referenced by imagemap_add().

Here is the caller graph for this function:

◆ imagemap_destroy()

void imagemap_destroy ( html_content c)

Destroy hashtable of imagemaps.

Parameters
cThe containing content

Definition at line 200 of file imagemap.c.

References HASH_SIZE, imagemap_freelist(), html_content::imagemaps, imagemap::key, imagemap::list, and imagemap::next.

Referenced by html_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_dump()

void imagemap_dump ( html_content c)

Dump imagemap data to the log.

Parameters
cThe containing content

Definition at line 231 of file imagemap.c.

References mapentry::bounds, mapentry::circle, HASH_SIZE, IMAGEMAP_CIRCLE, IMAGEMAP_DEFAULT, IMAGEMAP_POLY, IMAGEMAP_RECT, html_content::imagemaps, imagemap::key, imagemap::list, mapentry::next, imagemap::next, NSLOG, nsurl_access(), mapentry::num, mapentry::poly, mapentry::r, mapentry::rect, mapentry::type, mapentry::url, mapentry::x, mapentry::x0, mapentry::x1, mapentry::xcoords, mapentry::y, mapentry::y0, mapentry::y1, and mapentry::ycoords.

Here is the call graph for this function:

◆ imagemap_extract()

nserror imagemap_extract ( html_content c)

Extract all imagemaps from a document tree.

Parameters
cThe content to extract imagemaps from.
Returns
false on memory exhaustion, true otherwise
Todo:
check this
Todo:
check this

Definition at line 603 of file imagemap.c.

References html_content::document, imagemap_add(), imagemap_extract_map(), imagemap_freelist(), NSERROR_DOM, NSERROR_NOMEM, and NSERROR_OK.

Referenced by html_box_convert_done().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_extract_map()

static bool imagemap_extract_map ( dom_node *  node,
html_content c,
struct mapentry **  entry 
)
static

Extract an imagemap from html source.

Parameters
nodeXML node containing map
cContent containing document
entryList of map entries
Returns
false on memory exhaustion, true otherwise

Definition at line 586 of file imagemap.c.

References imagemap_extract_map_entries().

Referenced by imagemap_extract().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_extract_map_entries()

static bool imagemap_extract_map_entries ( dom_node *  node,
html_content c,
struct mapentry **  entry,
dom_string *  tname 
)
static

Extract an imagemap from html source.

Parameters
nodeXML node containing map
cContent containing document
entryList of map entries
tnameThe sub-tags to consider on this pass
Returns
false on memory exhaustion, true otherwise

Definition at line 537 of file imagemap.c.

References html_content::base_url, and imagemap_addtolist().

Referenced by imagemap_extract_map().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_freelist()

static void imagemap_freelist ( struct mapentry list)
static

Free list of imagemap entries.

Parameters
listPointer to head of list

Definition at line 169 of file imagemap.c.

References mapentry::bounds, IMAGEMAP_POLY, mapentry::next, nsurl_unref(), mapentry::poly, mapentry::target, mapentry::type, mapentry::url, mapentry::xcoords, and mapentry::ycoords.

Referenced by imagemap_destroy(), and imagemap_extract().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_get()

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.

Parameters
cThe containing content
keyThe map name to search for
xThe left edge of the containing box
yThe top edge of the containing box
click_xThe horizontal location of the click
click_yThe vertical location of the click
targetPointer to location to receive target pointer (if any)
Returns
The url associated with this area, or NULL if not found

Definition at line 737 of file imagemap.c.

References mapentry::bounds, mapentry::circle, IMAGEMAP_CIRCLE, IMAGEMAP_DEFAULT, imagemap_hash(), imagemap_point_in_poly(), IMAGEMAP_POLY, IMAGEMAP_RECT, html_content::imagemaps, imagemap::key, imagemap::list, mapentry::next, imagemap::next, mapentry::num, mapentry::poly, mapentry::r, mapentry::rect, mapentry::target, mapentry::type, mapentry::url, mapentry::x, mapentry::x0, mapentry::xcoords, mapentry::y, mapentry::y0, and mapentry::ycoords.

Referenced by get_mouse_action_node(), and html_get_contextual_content().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagemap_hash()

static unsigned int imagemap_hash ( const char *  key)
static

Hash function.

Parameters
keyThe key to hash.
Returns
The hashed value.

Definition at line 109 of file imagemap.c.

References HASH_SIZE, and imagemap::key.

Referenced by imagemap_add(), and imagemap_get().

Here is the caller graph for this function:

◆ imagemap_point_in_poly()

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 
)
static

Test if a point lies within an arbitrary polygon Modified from comp.graphics.algorithms FAQ 2.03.

Parameters
numNumber of vertices
xptArray of x coordinates
yptArray of y coordinates
xLeft hand edge of containing box
yTop edge of containing box
click_xX coordinate of click
click_yY coordinate of click
Returns
1 if point is in polygon, 0 if outside. 0 or 1 if on boundary

Definition at line 706 of file imagemap.c.

References mapentry::num, mapentry::x, and mapentry::y.

Referenced by imagemap_get().

Here is the caller graph for this function: