Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2.  * This file is part of LibCSS.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
  6.  */
  7.  
  8. #ifndef libcss_stylesheet_h_
  9. #define libcss_stylesheet_h_
  10.  
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15.  
  16. #include <libcss/errors.h>
  17. #include <libcss/types.h>
  18. #include <libcss/properties.h>
  19.  
  20. /**
  21.  * Callback to resolve an URL
  22.  *
  23.  * \param pw    Client data
  24.  * \param dict  String internment context
  25.  * \param base  Base URI (absolute)
  26.  * \param rel   URL to resolve, either absolute or relative to base
  27.  * \param abs   Pointer to location to receive result
  28.  * \return CSS_OK on success, appropriate error otherwise.
  29.  */
  30. typedef css_error (*css_url_resolution_fn)(void *pw,
  31.                 const char *base, lwc_string *rel, lwc_string **abs);
  32.  
  33. /**
  34.  * Callback to be notified of the need for an imported stylesheet
  35.  *
  36.  * \param pw      Client data
  37.  * \param parent  Stylesheet requesting the import
  38.  * \param url     URL of the imported sheet
  39.  * \param media   Applicable media for the imported sheet
  40.  * \return CSS_OK on success, appropriate error otherwise
  41.  *
  42.  * \note This function will be invoked for notification purposes
  43.  *       only. The client may use this to trigger a parallel fetch
  44.  *       of the imported stylesheet. The imported sheet must be
  45.  *       registered with its parent using the post-parse import
  46.  *       registration API.
  47.  */
  48. typedef css_error (*css_import_notification_fn)(void *pw,
  49.                 css_stylesheet *parent, lwc_string *url, uint64_t media);
  50.  
  51. /**
  52.  * Callback use to resolve system colour names to RGB values
  53.  *
  54.  * \param pw     Client data
  55.  * \param name   System colour name
  56.  * \param color  Pointer to location to receive color value
  57.  * \return CSS_OK       on success,
  58.  *         CSS_INVALID  if the name is unknown.
  59.  */
  60. typedef css_error (*css_color_resolution_fn)(void *pw,
  61.                 lwc_string *name, css_color *color);
  62.  
  63. /** System font callback result data. */
  64. typedef struct css_system_font {
  65.         enum css_font_style_e style;
  66.         enum css_font_variant_e variant;
  67.         enum css_font_weight_e weight;
  68.         struct {                  
  69.                 css_fixed size;          
  70.                 css_unit unit;
  71.         } size;
  72.         struct {                  
  73.                 css_fixed size;          
  74.                 css_unit unit;
  75.         } line_height;
  76.         /* Note: must be a single family name only */
  77.         lwc_string *family;
  78. } css_system_font;
  79.  
  80. /**
  81.  * Callback use to resolve system font names to font values
  82.  *
  83.  * \param pw           Client data
  84.  * \param name         System font identifier
  85.  * \param system_font  Pointer to system font descriptor to be filled
  86.  * \return CSS_OK       on success,
  87.  *         CSS_INVALID  if the name is unknown.
  88.  */
  89. typedef css_error (*css_font_resolution_fn)(void *pw,
  90.                 lwc_string *name, css_system_font *system_font);
  91.  
  92. typedef enum css_stylesheet_params_version {
  93.         CSS_STYLESHEET_PARAMS_VERSION_1 = 1
  94. } css_stylesheet_params_version;
  95.  
  96. /**
  97.  * Parameter block for css_stylesheet_create()
  98.  */
  99. typedef struct css_stylesheet_params {
  100.         /** ABI version of this structure */
  101.         uint32_t params_version;
  102.  
  103.         /** The language level of the stylesheet */
  104.         css_language_level level;
  105.  
  106.         /** The charset of the stylesheet data, or NULL to detect */
  107.         const char *charset;
  108.         /** URL of stylesheet */
  109.         const char *url;
  110.         /** Title of stylesheet */
  111.         const char *title;
  112.  
  113.         /** Permit quirky parsing of stylesheet */
  114.         bool allow_quirks;
  115.         /** This stylesheet is an inline style */
  116.         bool inline_style;
  117.  
  118.         /** URL resolution function */
  119.         css_url_resolution_fn resolve;
  120.         /** Client private data for resolve */
  121.         void *resolve_pw;
  122.  
  123.         /** Import notification function */
  124.         css_import_notification_fn import;
  125.         /** Client private data for import */
  126.         void *import_pw;
  127.  
  128.         /** Colour resolution function */
  129.         css_color_resolution_fn color;
  130.         /** Client private data for color */
  131.         void *color_pw;
  132.  
  133.         /** Font resolution function */
  134.         css_font_resolution_fn font;
  135.         /** Client private data for font */
  136.         void *font_pw;
  137. } css_stylesheet_params;
  138.  
  139. css_error css_stylesheet_create(const css_stylesheet_params *params,
  140.                 css_allocator_fn alloc, void *alloc_pw,
  141.                 css_stylesheet **stylesheet);
  142. css_error css_stylesheet_destroy(css_stylesheet *sheet);
  143.  
  144. css_error css_stylesheet_append_data(css_stylesheet *sheet,
  145.                 const uint8_t *data, size_t len);
  146. css_error css_stylesheet_data_done(css_stylesheet *sheet);
  147.  
  148. css_error css_stylesheet_next_pending_import(css_stylesheet *parent,
  149.                 lwc_string **url, uint64_t *media);
  150. css_error css_stylesheet_register_import(css_stylesheet *parent,
  151.                 css_stylesheet *child);
  152.  
  153. css_error css_stylesheet_get_language_level(css_stylesheet *sheet,
  154.                 css_language_level *level);
  155. css_error css_stylesheet_get_url(css_stylesheet *sheet, const char **url);
  156. css_error css_stylesheet_get_title(css_stylesheet *sheet, const char **title);
  157. css_error css_stylesheet_quirks_allowed(css_stylesheet *sheet, bool *allowed);
  158. css_error css_stylesheet_used_quirks(css_stylesheet *sheet, bool *quirks);
  159.  
  160. css_error css_stylesheet_get_disabled(css_stylesheet *sheet, bool *disabled);
  161. css_error css_stylesheet_set_disabled(css_stylesheet *sheet, bool disabled);
  162.  
  163. css_error css_stylesheet_size(css_stylesheet *sheet, size_t *size);
  164.  
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168.  
  169. #endif
  170.  
  171.