Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
  3.  * Copyright 2003 Philip Pemberton <philpem@users.sourceforge.net>
  4.  *
  5.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  6.  *
  7.  * NetSurf is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; version 2 of the License.
  10.  *
  11.  * NetSurf is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19.  
  20. /** \file
  21.  * Content handling (interface).
  22.  *
  23.  * The content functions manipulate struct contents, which correspond to URLs.
  24.  */
  25.  
  26. #ifndef _NETSURF_CONTENT_CONTENT_H_
  27. #define _NETSURF_CONTENT_CONTENT_H_
  28.  
  29. #include <stdbool.h>
  30. #include <stdio.h>
  31.  
  32. #include <libwapcaplet/libwapcaplet.h>
  33.  
  34. #include "utils/config.h"
  35. #include "utils/errors.h"
  36. #include "utils/http.h"
  37. #include "utils/nsurl.h"
  38. #include "utils/types.h"
  39. #include "content/content_factory.h"
  40. #include "content/content_type.h"
  41. #include "desktop/mouse.h"
  42. #include "desktop/plot_style.h"
  43.  
  44. struct browser_window;
  45. struct content;
  46. struct llcache_handle;
  47. struct hlcache_handle;
  48. struct object_params;
  49. struct rect;
  50. struct redraw_context;
  51.  
  52.  
  53. /** Status of a content */
  54. typedef enum {
  55.         CONTENT_STATUS_LOADING, /**< Content is being fetched or
  56.                                   converted and is not safe to display. */
  57.         CONTENT_STATUS_READY,   /**< Some parts of content still being
  58.                                   loaded, but can be displayed. */
  59.         CONTENT_STATUS_DONE,    /**< All finished. */
  60.         CONTENT_STATUS_ERROR    /**< Error occurred, content will be
  61.                                   destroyed imminently. */
  62. } content_status;
  63.  
  64. /** Used in callbacks to indicate what has occurred. */
  65. typedef enum {
  66.         CONTENT_MSG_LOADING,   /**< fetching or converting */
  67.         CONTENT_MSG_READY,     /**< may be displayed */
  68.         CONTENT_MSG_DONE,      /**< finished */
  69.         CONTENT_MSG_ERROR,     /**< error occurred */
  70.         CONTENT_MSG_ERRORCODE, /**< error occurred return nserror */
  71.         CONTENT_MSG_STATUS,    /**< new status string */
  72.         CONTENT_MSG_REFORMAT,  /**< content_reformat done */
  73.         CONTENT_MSG_REDRAW,    /**< needs redraw (eg. new animation frame) */
  74.         CONTENT_MSG_REFRESH,   /**< wants refresh */
  75.         CONTENT_MSG_DOWNLOAD,  /**< download, not for display */
  76.         CONTENT_MSG_LINK,      /**< RFC5988 link */
  77.         CONTENT_MSG_GETCTX,    /**< Javascript context */
  78.         CONTENT_MSG_SCROLL,    /**< Request to scroll content */
  79.         CONTENT_MSG_DRAGSAVE,  /**< Allow drag saving of content */
  80.         CONTENT_MSG_SAVELINK,  /**< Allow URL to be saved */
  81.         CONTENT_MSG_POINTER    /**< Wants a specific mouse pointer set */
  82. } content_msg;
  83.  
  84. /** RFC5988 metadata link */
  85. struct content_rfc5988_link {
  86.         struct content_rfc5988_link *next; /**< next rfc5988_link in list */
  87.  
  88.         lwc_string *rel; /**< the link relationship - must be present */
  89.         nsurl *href; /**< the link href - must be present */
  90.         lwc_string *hreflang;
  91.         lwc_string *type;
  92.         lwc_string *media;
  93.         lwc_string *sizes;
  94. };
  95.  
  96. /** Extra data for some content_msg messages. */
  97. union content_msg_data {
  98.         /** CONTENT_MSG_ERROR - Error message */
  99.         const char *error;
  100.         /** CONTENT_MSG_ERRORCODE - Error code */
  101.         nserror errorcode;
  102.         /** CONTENT_MSG_REDRAW - Area of content which needs redrawing */
  103.         struct {
  104.                 int x, y, width, height;
  105.                 /** Redraw the area fully. If false, object must be set,
  106.                  * and only the object will be redrawn. */
  107.                 bool full_redraw;
  108.                 /** Object to redraw if full_redraw is false. */
  109.                 struct content *object;
  110.                 /** Coordinates to plot object at. */
  111.                 int object_x, object_y;
  112.                 /** Dimensions to plot object with. */
  113.                 int object_width, object_height;
  114.         } redraw;
  115.         /** CONTENT_MSG_REFRESH - Minimum delay  */
  116.         int delay;
  117.         /** CONTENT_MSG_REFORMAT - Reformat should not cause a redraw */
  118.         bool background;
  119.         /** CONTENT_MSG_STATUS - Status message update.  If NULL, the content's
  120.          * internal status text has been updated, and listener should use
  121.          * content_get_status_message() */
  122.         const char *explicit_status_text;
  123.         /** CONTENT_MSG_DOWNLOAD - Low-level cache handle */
  124.         struct llcache_handle *download;
  125.         /** CONTENT_MSG_RFC5988_LINK - rfc5988 link data   */
  126.         struct content_rfc5988_link *rfc5988_link;
  127.         /** CONTENT_MSG_GETCTX - Javascript context */
  128.         struct jscontext **jscontext;
  129.         /** CONTENT_MSG_SCROLL - Part of content to scroll to show */
  130.         struct {
  131.                 /** if true, scroll to show area given by (x0, y0) and (x1,y1).
  132.                  * if false, scroll point (x0, y0) to top left of viewport */
  133.                 bool area;
  134.                 int x0, y0;
  135.                 int x1, y1;
  136.         } scroll;
  137.         /** CONTENT_MSG_DRAGSAVE - Drag save a content */
  138.         struct {
  139.                 enum {
  140.                         CONTENT_SAVE_ORIG,
  141.                         CONTENT_SAVE_NATIVE,
  142.                         CONTENT_SAVE_COMPLETE,
  143.                         CONTENT_SAVE_SOURCE
  144.                 } type;
  145.                  /** if NULL, save the content generating the message */
  146.                 struct hlcache_handle *content;
  147.         } dragsave;
  148.         /** CONTENT_MSG_SAVELINK - Save a URL */
  149.         struct {
  150.                 const char *url;
  151.                 const char *title;
  152.         } savelink;
  153.         /** CONTENT_MSG_POINTER - Mouse pointer to set */
  154.         browser_pointer_shape pointer;
  155.         /** CONTENT_MSG_PASTE - Content requests that clipboard is pasted */
  156.         struct {
  157.                 /* TODO: Get rid of these coords.
  158.                  *       browser_window_paste_text doesn't take coords, but
  159.                  *       RISC OS front end is doing something different. */
  160.                 int x;
  161.                 int y;
  162.         } paste;
  163. };
  164.  
  165. /** parameters to content redraw */
  166. struct content_redraw_data {
  167.         int x; /**< coordinate for top-left of redraw */
  168.         int y; /**< coordinate for top-left of redraw */
  169.  
  170.         /** dimensions to render content at
  171.          *  (for scaling contents with intrinsic dimensions) */
  172.         int width; /**< horizontal dimension */
  173.         int height; /**< vertical dimension */
  174.  
  175.         /** The background colour */
  176.         colour background_colour;
  177.  
  178.         /** Scale for redraw
  179.          *  (for scaling contents without intrinsic dimensions) */
  180.         float scale; /**< Scale factor for redraw */
  181.  
  182.         bool repeat_x; /**< whether content is tiled in x direction */
  183.         bool repeat_y; /**< whether content is tiled in y direction */
  184. };
  185.  
  186. /* The following are for hlcache */
  187. void content_destroy(struct content *c);
  188.  
  189. bool content_add_user(struct content *h,
  190.                 void (*callback)(struct content *c, content_msg msg,
  191.                         union content_msg_data data, void *pw),
  192.                 void *pw);
  193. void content_remove_user(struct content *c,
  194.                 void (*callback)(struct content *c, content_msg msg,
  195.                         union content_msg_data data, void *pw),
  196.                 void *pw);
  197.  
  198. uint32_t content_count_users(struct content *c);
  199. bool content_matches_quirks(struct content *c, bool quirks);
  200. bool content_is_shareable(struct content *c);
  201. content_status content__get_status(struct content *c);
  202.  
  203. const struct llcache_handle *content_get_llcache_handle(struct content *c);
  204. nsurl *content_get_url(struct content *c);
  205.  
  206. struct content *content_clone(struct content *c);
  207.  
  208. nserror content_abort(struct content *c);
  209.  
  210. /* Client functions */
  211. bool content_can_reformat(struct hlcache_handle *h);
  212. void content_reformat(struct hlcache_handle *h, bool background,
  213.                 int width, int height);
  214. void content_request_redraw(struct hlcache_handle *h,
  215.                 int x, int y, int width, int height);
  216. void content_mouse_track(struct hlcache_handle *h, struct browser_window *bw,
  217.                 browser_mouse_state mouse, int x, int y);
  218. void content_mouse_action(struct hlcache_handle *h, struct browser_window *bw,
  219.                 browser_mouse_state mouse, int x, int y);
  220. bool content_redraw(struct hlcache_handle *h, struct content_redraw_data *data,
  221.                 const struct rect *clip, const struct redraw_context *ctx);
  222. void content_open(struct hlcache_handle *h, struct browser_window *bw,
  223.                 struct content *page, struct object_params *params);
  224. void content_close(struct hlcache_handle *h);
  225. struct selection *content_get_selection(struct hlcache_handle *h);
  226. void content_get_contextual_content(struct hlcache_handle *h,
  227.                 int x, int y, struct contextual_content *data);
  228. bool content_scroll_at_point(struct hlcache_handle *h,
  229.                 int x, int y, int scrx, int scry);
  230. bool content_drop_file_at_point(struct hlcache_handle *h,
  231.                 int x, int y, char *file);
  232. void content_debug_dump(struct hlcache_handle *h, FILE *f);
  233. struct content_rfc5988_link *content_find_rfc5988_link(struct hlcache_handle *c,
  234.                 lwc_string *rel);
  235.  
  236. /* Member accessors */
  237. content_type content_get_type(struct hlcache_handle *c);
  238. lwc_string *content_get_mime_type(struct hlcache_handle *c);
  239. const char *content_get_title(struct hlcache_handle *c);
  240. content_status content_get_status(struct hlcache_handle *c);
  241. const char *content_get_status_message(struct hlcache_handle *c);
  242. int content_get_width(struct hlcache_handle *c);
  243. int content_get_height(struct hlcache_handle *c);
  244. int content_get_available_width(struct hlcache_handle *c);
  245. const char *content_get_source_data(struct hlcache_handle *c,
  246.                 unsigned long *size);
  247. void content_invalidate_reuse_data(struct hlcache_handle *c);
  248. nsurl *content_get_refresh_url(struct hlcache_handle *c);
  249. struct bitmap *content_get_bitmap(struct hlcache_handle *c);
  250. bool content_get_opaque(struct hlcache_handle *h);
  251. bool content_get_quirks(struct hlcache_handle *c);
  252.  
  253. bool content_is_locked(struct hlcache_handle *h);
  254.  
  255. #endif
  256.