summaryrefslogtreecommitdiff
path: root/content/content.h
blob: c9fa9870bb7b05edb34901d64975661905f78757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
 * $Id: content.h,v 1.11 2003/06/05 13:17:55 philpem Exp $
 */

#ifndef _NETSURF_DESKTOP_CONTENT_H_
#define _NETSURF_DESKTOP_CONTENT_H_

#include "libxml/HTMLparser.h"
#include "libpng/png.h"
#include "libungif/gif_lib.h"
#include "oslib/osspriteop.h"
#include "netsurf/content/cache.h"
#include "netsurf/css/css.h"
#include "netsurf/render/box.h"
#include "netsurf/riscos/font.h"


/**
 * A struct content corresponds to a single url.
 *
 * It is in one of the following states:
 *   CONTENT_FETCHING - the data is being fetched and/or converted
 *                      for use by the browser
 *   CONTENT_READY - the content has been processed and is ready
 *                      to display
 *
 * The converted data is stored in the cache, not the source data.
 * Users of the structure are counted in use_count; when use_count = 0
 * the content may be removed from the memory cache.
 */

typedef enum {
	CONTENT_HTML,
	CONTENT_TEXTPLAIN,
	CONTENT_JPEG,
	CONTENT_CSS,
	CONTENT_PNG,
	CONTENT_GIF,
	CONTENT_OTHER
} content_type;

struct box_position
{
  struct box* box;
  int actual_box_x;
  int actual_box_y;
  int plot_index;
  int pixel_offset;
  int char_offset;
};

struct content
{
  char *url;
  content_type type;
  enum {
	  CONTENT_LOADING,  /* content is being fetched or converted
			       and is not safe to display */
	  CONTENT_PENDING,  /* some parts of content still being
			       loaded, but can be displayed */
	  CONTENT_DONE      /* all finished */
  } status;
  unsigned long width, height;
  unsigned long available_width;

  union
  {
    struct
    {
      htmlParserCtxt* parser;
      struct box* layout;
      unsigned int stylesheet_count;
      struct content **stylesheet_content;
      struct css_style* style;
      struct {
        struct box_position start;
        struct box_position end;
        enum {alter_UNKNOWN, alter_START, alter_END} altering;
        int selected; /* 0 = unselected, 1 = selected */
      } text_selection;
      struct font_set* fonts;
      struct page_elements elements;
      unsigned int object_count;  /* images etc. */
      struct {
        char *url;
        struct content *content;
	struct box *box;
      } *object;
    } html;

    struct
    {
      struct css_stylesheet *css;
      unsigned int import_count;
      char **import_url;
      struct content **import_content;
    } css;

    struct
    {
      char * data;
      unsigned long length;
    } jpeg;

    struct
    {
      png_structp png;
      png_infop info;
      unsigned long rowbytes;
      osspriteop_area *sprite_area;
      char *sprite_image;
      enum { PNG_PALETTE, PNG_DITHER, PNG_DEEP } type;
    } png;

    // Structure for the GIF handler
    struct
    {
      GifFileType *giffile;               // GIF file handler
      char *data;                         // GIF data
      unsigned long length;               // Length of GIF data
      unsigned long buffer_pos;           // Position in the buffer
      osspriteop_area *sprite_area;       // Sprite area
      char *sprite_image;                 // Sprite image
    } gif;

  } data;

  struct cache_entry *cache;
  unsigned long size;
  char *title;
  unsigned int active;
  int error;
  void (*status_callback)(void *p, const char *status);
  void *status_p;
  char status_message[80];
};


content_type content_lookup(const char *mime_type);
struct content * content_create(content_type type, char *url);
void content_process_data(struct content *c, char *data, unsigned long size);
int content_convert(struct content *c, unsigned long width, unsigned long height);
void content_revive(struct content *c, unsigned long width, unsigned long height);
void content_reformat(struct content *c, unsigned long width, unsigned long height);
void content_destroy(struct content *c);
void content_redraw(struct content *c, long x, long y,
		unsigned long width, unsigned long height);

#endif