r8213 paulblokus - in /branches/paulblokus/treeview: desktop/options.c desktop/options.h desktop/tree.c desktop/tree.h desktop/tree_url_node.c desktop/tree_url_node.h gtk/gtk_gui.c gtk/gtk_treeview.c
by netsurf@semichrome.net
Author: paulblokus
Date: Tue Jun 30 18:59:14 2009
New Revision: 8213
URL: http://source.netsurf-browser.org?rev=8213&view=rev
Log:
simplify icon requiring
Modified:
branches/paulblokus/treeview/desktop/options.c
branches/paulblokus/treeview/desktop/options.h
branches/paulblokus/treeview/desktop/tree.c
branches/paulblokus/treeview/desktop/tree.h
branches/paulblokus/treeview/desktop/tree_url_node.c
branches/paulblokus/treeview/desktop/tree_url_node.h
branches/paulblokus/treeview/gtk/gtk_gui.c
branches/paulblokus/treeview/gtk/gtk_treeview.c
Modified: branches/paulblokus/treeview/desktop/options.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/op...
==============================================================================
--- branches/paulblokus/treeview/desktop/options.c (original)
+++ branches/paulblokus/treeview/desktop/options.c Tue Jun 30 18:59:14 2009
@@ -146,6 +146,7 @@
unsigned int option_min_reflow_period = 25; /* time in cs */
#endif
char *option_recent_file = 0;
+char *option_tree_icons_dir = 0;
/** top margin of exported page*/
int option_margin_top = DEFAULT_MARGIN_TOP_MM;
/** bottom margin of exported page*/
@@ -246,6 +247,7 @@
{ "incremental_reflow", OPTION_BOOL, &option_incremental_reflow },
{ "min_reflow_period", OPTION_INTEGER, &option_min_reflow_period },
{ "recent_file", OPTION_STRING, &option_recent_file },
+ { "tree_icons_dir", OPTION_STRING, &option_tree_icons_dir },
/* Fetcher options */
{ "max_fetchers", OPTION_INTEGER, &option_max_fetchers },
{ "max_fetchers_per_host",
Modified: branches/paulblokus/treeview/desktop/options.h
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/op...
==============================================================================
--- branches/paulblokus/treeview/desktop/options.h (original)
+++ branches/paulblokus/treeview/desktop/options.h Tue Jun 30 18:59:14 2009
@@ -84,6 +84,7 @@
extern bool option_incremental_reflow;
extern unsigned int option_min_reflow_period;
extern char *option_recent_file;
+extern char *option_tree_icons_dir;
extern int option_margin_top;
extern int option_margin_bottom;
Modified: branches/paulblokus/treeview/desktop/tree.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.c (original)
+++ branches/paulblokus/treeview/desktop/tree.c Tue Jun 30 18:59:14 2009
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include "content/content.h"
+#include "content/fetchcache.h"
#include "desktop/browser.h"
#include "desktop/tree.h"
#include "desktop/options.h"
@@ -46,10 +47,13 @@
TREE_MOVE_DRAG
} tree_drag_type;
+
+#define MAXIMUM_URL_LENGTH 1024
+
#define NODE_INSTEP 20
#define TREE_TEXT_HEIGHT 20
-
#define FURNITURE_COLOUR 0x888888
+#define ICON_SIZE 16
struct toolbar;
struct node;
@@ -129,7 +133,9 @@
static void tree_delete_node_internal(struct tree *tree, struct node *node,
bool siblings);
-static void tree_sort_insert(struct node *parent, struct node *node);
+static void tree_node_icon_callback(content_msg msg, struct content *c,
+ intptr_t p1, intptr_t p2, union content_msg_data data);
+static void tree_sort_insert(struct node *parent, struct node *node);
static void tree_set_node_expanded_all(struct tree *tree, struct node *node,
bool expanded);
static bool tree_set_node_expanded_internal(struct tree *tree,
@@ -250,7 +256,6 @@
bool deleted, unsigned int flag)
{
struct node *node;
- struct content *bm;
assert(title);
@@ -268,8 +273,7 @@
node->sort = NULL;
node->user_callback = NULL;
- bm = tree_get_icon(tree, node, "small_dir", false);
- tree_set_node_icon(tree, node, bm);
+ tree_set_node_named_icon(tree, node, "small_dir", false);
if (parent != NULL)
tree_link_node(tree, parent, node, false);
else
@@ -456,10 +460,10 @@
*/
void tree_delete_node(struct tree *tree, struct node *node, bool siblings)
{
+ int y = node->box.y;
tree_delete_node_internal(tree, node, siblings);
tree_recalculate_node_positions(tree, tree->root);
- /* \todo correct area */
- tree_draw(tree, 0, 0, tree->width, tree->height);
+ tree_draw(tree, 0, y, tree->width, tree->height);
tree_recalculate_size(tree);
}
@@ -517,7 +521,6 @@
e->flag);
/* TODO the type of this field is platform
dependent */
- /* \todo platform specific bits */
if (!handled)
free(e->bitmap);
e->bitmap = NULL;
@@ -536,25 +539,39 @@
/**
- * Sets a node element as having a specific icon.
- *
- * \param tree the tree to which 'node' belongs, may be NULL
- * \param node the node to update
- * \param icon the icon to use
- */
-void tree_set_node_icon(struct tree *tree, struct node *node,
- struct content *icon)
-{
-
- assert(node);
- assert(icon);
-
- // this is done in tree_callback at the moment
- /*node->data.bitmap = icon;
- if (node->data.bitmap == NULL) return;*/
+ * Acquires a specific icon from the front end specified directory.
+ *
+ * \param tree The tree to which node belongs, may be NULL
+ * \param node The node for which the icon bitmap gets acquired. This
+ * is necessary at the moment as the pointer gets passed
+ * to tree_callback which actually sets the icon.
+ * \param icon the bitmap to use
+ * \param path If true 'icon' contains the full path under which the
+ * icon can be found
+ */
+void tree_set_node_named_icon(struct tree *tree, struct node *node,
+ const char *icon, bool path)
+{
+ /* TODO: something like bitmap_from_disk is needed here */
+
+ char icon_path[MAXIMUM_URL_LENGTH];
+
+ struct content *c;
+
+ if (path) {
+ sprintf(icon_path, icon);
+ }
+ else {
+ sprintf(icon_path, "%s%s%s%s", "file://", option_tree_icons_dir,
+ icon, ".bmp");
+ }
+ c = fetchcache(icon_path, tree_node_icon_callback, (intptr_t) tree,
+ (intptr_t) node, ICON_SIZE, ICON_SIZE, true, 0, 0, true,
+ false);
+ fetchcache_go(c, 0, tree_node_icon_callback, (intptr_t) tree,
+ (intptr_t) node, ICON_SIZE, ICON_SIZE, 0, 0, true, 0);
node->data.type = NODE_ELEMENT_TEXT_PLUS_ICON;
- tree_handle_node_element_changed(tree, &(node->data));
}
@@ -1094,12 +1111,14 @@
switch (element->type) {
case NODE_ELEMENT_TEXT_PLUS_ICON:
- /*TODO: the if is necessary as long as the bitmap gets fetched
- as a content*/
- //assert(element->bitmap);
+ /* TODO: the if is necessary as long as the bitmap gets fetched
+ as a content */
+ /* assert(element->bitmap); */
if (element->bitmap != NULL)
- content_redraw(element->bitmap, x, y + 3, 16,
- 16, x, y, x + 16, y + 16, 1, 0);
+ content_redraw(element->bitmap, x, y + 3,
+ ICON_SIZE, ICON_SIZE, x, y,
+ x + ICON_SIZE, y + ICON_SIZE, 1,
+ 0);
x += NODE_INSTEP;
/* fall through */
@@ -1269,7 +1288,7 @@
element = tree_get_node_element_at(tree->root->child, x, y, &furniture);
/* stop editing for anything but a drag */
-// if ((tree->editing) && /*(pointer->i != tree->edit_handle) &&*/
+// if ((tree->editing) && /* (pointer->i != tree->edit_handle) && */
// !(mouse & BROWSER_MOUSE_DRAG_1))
// ro_gui_tree_stop_edit(tree);
@@ -1490,7 +1509,7 @@
* Callback for fetchcache(). Should be removed once bitmaps get loaded directly
* from disc
*/
-void tree_callback(content_msg msg, struct content *c,
+void tree_node_icon_callback(content_msg msg, struct content *c,
intptr_t p1, intptr_t p2, union content_msg_data data)
{
struct tree *tree = (struct tree *) p1;
@@ -1598,9 +1617,10 @@
switch (element->type) {
case NODE_ELEMENT_TEXT_PLUS_ICON:
- /*TODO: This assert can't be used as long as the bitmap
- gets fetched as a content*/
-// assert(element->bitmap);
+ /* TODO: This assert can't be used as long as the bitmap
+ gets fetched as a content */
+ /* assert(element->bitmap); */
+ /* fall through */
case NODE_ELEMENT_TEXT:
assert(element->text);
nsfont.font_width(&css_base_style, element->text,
Modified: branches/paulblokus/treeview/desktop/tree.h
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.h (original)
+++ branches/paulblokus/treeview/desktop/tree.h Tue Jun 30 18:59:14 2009
@@ -42,14 +42,14 @@
struct cookie_data;
typedef enum {
- NODE_ELEMENT_TEXT, /* <-- Text only */
- NODE_ELEMENT_TEXT_PLUS_ICON, /* <-- Text and icon */
- NODE_ELEMENT_BITMAP /* <-- Bitmap only */
+ NODE_ELEMENT_TEXT, /* Text only */
+ NODE_ELEMENT_TEXT_PLUS_ICON, /* Text and icon */
+ NODE_ELEMENT_BITMAP /* Bitmap only */
} node_element_type;
typedef enum {
- NODE_DELETE_ELEMENT,
- NODE_LAUNCH
+ NODE_DELETE_ELEMENT, /* An element of the node is deleted */
+ NODE_LAUNCH /* The node has been launched */
} node_msg;
typedef void (*tree_start_redraw_callback)(void *data);
@@ -60,8 +60,8 @@
/* Non-platform specific code */
-/* functions for creating/deleting tree primitives and tree structure
- manipulation*/
+/* Functions for creating/deleting tree primitives and for tree structure
+ manipulation */
struct tree *tree_create(unsigned int flags, int x, int y,
tree_start_redraw_callback start_redraw,
tree_end_redraw_callback end_redraw, void *redraw_data,
@@ -79,9 +79,9 @@
void tree_delink_node(struct tree *tree, struct node *node);
void tree_delete_node(struct tree *tree, struct node *node, bool siblings);
-/* setters and getters for properties and data*/
-void tree_set_node_icon(struct tree *tree, struct node *node,
- struct content *icon);
+/* setters and getters for properties and data */
+void tree_set_node_named_icon(struct tree *tree, struct node *node,
+ const char *icon, bool path);
void tree_set_node_expanded(struct tree *tree, struct node *node, bool expanded,
bool folder, bool leaf);
void tree_set_node_selected(struct tree *tree, struct node *node, bool all,
@@ -119,15 +119,10 @@
void tree_drag_end(struct tree *tree, browser_mouse_state mouse, int x0, int y0,
int x1, int y1);
-int tree_alphabetical_sort(struct node *, struct node *);
-void tree_callback(content_msg msg, struct content *c,
- intptr_t p1, intptr_t p2, union content_msg_data data);
+int tree_alphabetical_sort(struct node *, struct node *);
/* Platform specific code */
void tree_resized(struct tree *tree, int width, int height, void *data);
-struct content *tree_get_icon(struct tree *tree, struct node *node,
- const char *icon, bool path);
-void tree_icon_name_from_content_type(char *buffer, content_type type);
void tree_scroll_visible(struct tree *tree, struct node_element *element,
void *data);
#endif
Modified: branches/paulblokus/treeview/desktop/tree_url_node.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.c (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.c Tue Jun 30 18:59:14 2009
@@ -131,7 +131,6 @@
{
struct node_element *element;
char buffer[256];
- struct content *bm;
struct bitmap *bitmap = NULL;
assert(node);
@@ -157,9 +156,7 @@
tree_icon_name_from_content_type(buffer, data->type);
- bm = tree_get_icon(tree, node, buffer, false);
- tree_set_node_icon(tree, node, bm);
-
+ tree_set_node_named_icon(tree, node, buffer, false);
element = tree_node_find_element(node, TREE_ELEMENT_LAST_VISIT);
if (element != NULL) {
Modified: branches/paulblokus/treeview/desktop/tree_url_node.h
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.h (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.h Tue Jun 30 18:59:14 2009
@@ -44,4 +44,7 @@
void tree_update_URL_node(struct tree *tree,struct node *node,
const char *url, const struct url_data *data);
+/* front end specific */
+void tree_icon_name_from_content_type(char *buffer, content_type type);
+
#endif
Modified: branches/paulblokus/treeview/gtk/gtk_gui.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/gtk/gtk_gu...
==============================================================================
--- branches/paulblokus/treeview/gtk/gtk_gui.c (original)
+++ branches/paulblokus/treeview/gtk/gtk_gui.c Tue Jun 30 18:59:14 2009
@@ -299,6 +299,16 @@
LOG(("Using '%s' as Recent file", buf));
option_recent_file = strdup(buf);
}
+ if (!option_recent_file)
+ die("Failed initialising recent URLs file option");
+
+ if (!option_tree_icons_dir) {
+ option_tree_icons_dir = strdup(res_dir_location);
+ LOG(("Using '%s' as Tree icons dir", option_tree_icons_dir));
+ }
+ if (!option_tree_icons_dir)
+ die("Failed initialising tree icons option");
+
find_resource(buf, "messages", "./gtk/res/messages");
LOG(("Using '%s' as Messages file", buf));
Modified: branches/paulblokus/treeview/gtk/gtk_treeview.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/gtk/gtk_tr...
==============================================================================
--- branches/paulblokus/treeview/gtk/gtk_treeview.c (original)
+++ branches/paulblokus/treeview/gtk/gtk_treeview.c Tue Jun 30 18:59:14 2009
@@ -24,52 +24,13 @@
#include <gtk/gtk.h>
#include <stdio.h>
-#include "content/fetchcache.h"
-#include "desktop/gui.h"
#include "desktop/tree.h"
+#include "desktop/tree_url_node.h"
#include "desktop/plotters.h"
-#include "gtk/gtk_gui.h"
#include "gtk/gtk_plotters.h"
#include "gtk/gtk_treeview.h"
-#define MAXIMUM_URL_LENGTH 1024
-
static bool set = false;
-
-/**
- * Acquires a specific front end specified icon.
- *
- * \param tree The tree to which node belongs, may be NULL
- * \param node The node for which the icon bitmap gets acquired. This
- * is necessary at the moment as the pointer gets passed
- * to tree_callback which actually sets the icon.
- * \param icon the bitmap to use
- * \param path If true 'icon' contains the full path under which the
- * icon can be found
- */
-struct content *tree_get_icon(struct tree *tree, struct node *node,
- const char *icon, bool path)
-{
- /* TODO: something like bitmap_from_disk is needed here*/
-
- char icon_path[MAXIMUM_URL_LENGTH];
-
- struct content *c;
-
- if (path) {
- sprintf(icon_path, icon);
- }
- else {
- sprintf(icon_path, "%s%s%s%s", "file://", res_dir_location,
- icon, ".bmp");
- }
- c = fetchcache(icon_path, tree_callback, (intptr_t) tree,
- (intptr_t) node, 16, 16, true, 0, 0, true, false);
- fetchcache_go(c, 0, tree_callback, (intptr_t) tree, (intptr_t) node, 16,
- 16, 0, 0, true, 0);
-
- return c;
-}
/**
* Updates the tree owner following a tree resize
14 years, 2 months
r8212 jmb - /branches/jmb/ns-libcss/css/select.c
by netsurf@semichrome.net
Author: jmb
Date: Tue Jun 30 18:44:32 2009
New Revision: 8212
URL: http://source.netsurf-browser.org?rev=8212&view=rev
Log:
Stop running over the end of lwc string data.
Modified:
branches/jmb/ns-libcss/css/select.c
Modified: branches/jmb/ns-libcss/css/select.c
URL: http://source.netsurf-browser.org/branches/jmb/ns-libcss/css/select.c?rev...
==============================================================================
--- branches/jmb/ns-libcss/css/select.c (original)
+++ branches/jmb/ns-libcss/css/select.c Tue Jun 30 18:44:32 2009
@@ -1,3 +1,4 @@
+#include <alloca.h>
#include <string.h>
#include "css/select.h"
@@ -168,8 +169,11 @@
for (n = n->parent; n != NULL && n->type == XML_ELEMENT_NODE;
n = n->parent) {
- bool match = strcasecmp((const char *) n->name,
- lwc_string_data(name)) == 0;
+ bool match = strlen((const char *) n->name) ==
+ lwc_string_length(name) &&
+ strncasecmp((const char *) n->name,
+ lwc_string_data(name),
+ lwc_string_length(name)) == 0;
if (match)
break;
@@ -187,8 +191,11 @@
*parent = NULL;
if (n->parent != NULL && n->parent->type == XML_ELEMENT_NODE &&
- strcasecmp((const char *) n->name,
- lwc_string_data(name)) == 0)
+ strlen((const char *) n->parent->name) ==
+ lwc_string_length(name) &&
+ strncasecmp((const char *) n->parent->name,
+ lwc_string_data(name),
+ lwc_string_length(name)) == 0)
*parent = (void *) n->parent;
return CSS_OK;
@@ -201,8 +208,11 @@
*sibling = NULL;
if (n->prev != NULL && n->prev->type == XML_ELEMENT_NODE &&
- strcasecmp((const char *) n->name,
- lwc_string_data(name)) == 0)
+ strlen((const char *) n->prev->name) ==
+ lwc_string_length(name) &&
+ strncasecmp((const char *) n->prev->name,
+ lwc_string_data(name),
+ lwc_string_length(name)) == 0)
*sibling = (void *) n->prev;
return CSS_OK;
@@ -242,7 +252,11 @@
class = xmlGetProp(n, (const xmlChar *) "class");
if (class != NULL) {
- *match = strcmp((char *) class, lwc_string_data(name)) == 0;
+ *match = strlen((const char *) class) ==
+ lwc_string_length(name) &&
+ strncmp((const char *) class,
+ lwc_string_data(name),
+ lwc_string_length(name)) == 0;
xmlFree(class);
}
@@ -259,7 +273,11 @@
id = xmlGetProp(n, (const xmlChar *) "id");
if (id != NULL) {
- *match = strcmp((char *) id, lwc_string_data(name)) == 0;
+ *match = strlen((const char *) id) ==
+ lwc_string_length(name) &&
+ strncmp((const char *) id,
+ lwc_string_data(name),
+ lwc_string_length(name)) == 0;
xmlFree(id);
}
@@ -271,8 +289,12 @@
{
xmlNode *n = node;
xmlAttr *attr;
-
- attr = xmlHasProp(n, (const xmlChar *) lwc_string_data(name));
+ char *buf = alloca(lwc_string_length(name) + 1);
+
+ memcpy(buf, lwc_string_data(name), lwc_string_length(name));
+ buf[lwc_string_length(name)] = '\0';
+
+ attr = xmlHasProp(n, (const xmlChar *) buf);
*match = attr != NULL;
return CSS_OK;
@@ -285,12 +307,20 @@
{
xmlNode *n = node;
xmlChar *attr;
+ char *buf = alloca(lwc_string_length(name) + 1);
+
+ memcpy(buf, lwc_string_data(name), lwc_string_length(name));
+ buf[lwc_string_length(name)] = '\0';
*match = false;
- attr = xmlGetProp(n, (const xmlChar *) lwc_string_data(name));
+ attr = xmlGetProp(n, (const xmlChar *) buf);
if (attr != NULL) {
- *match = strcmp((char *) attr, lwc_string_data(value)) == 0;
+ *match = strlen((const char *) attr) ==
+ lwc_string_length(value) &&
+ strncmp((const char *) attr,
+ lwc_string_data(value),
+ lwc_string_length(value)) == 0;
xmlFree(attr);
}
@@ -304,11 +334,15 @@
{
xmlNode *n = node;
xmlChar *attr;
+ char *buf = alloca(lwc_string_length(name) + 1);
size_t vlen = lwc_string_length(value);
+ memcpy(buf, lwc_string_data(name), lwc_string_length(name));
+ buf[lwc_string_length(name)] = '\0';
+
*match = false;
- attr = xmlGetProp(n, (const xmlChar *) lwc_string_data(name));
+ attr = xmlGetProp(n, (const xmlChar *) buf);
if (attr != NULL) {
const char *p;
const char *start = (const char *) attr;
@@ -340,11 +374,15 @@
{
xmlNode *n = node;
xmlChar *attr;
+ char *buf = alloca(lwc_string_length(name) + 1);
size_t vlen = lwc_string_length(value);
+ memcpy(buf, lwc_string_data(name), lwc_string_length(name));
+ buf[lwc_string_length(name)] = '\0';
+
*match = false;
- attr = xmlGetProp(n, (const xmlChar *) lwc_string_data(name));
+ attr = xmlGetProp(n, (const xmlChar *) buf);
if (attr != NULL) {
const char *p;
const char *start = (const char *) attr;
14 years, 2 months
r8211 jmb - in /branches/jmb/ns-libcss/css: css.c css.h
by netsurf@semichrome.net
Author: jmb
Date: Tue Jun 30 18:31:28 2009
New Revision: 8211
URL: http://source.netsurf-browser.org?rev=8211&view=rev
Log:
Copy specified URL to ensure it's NUL terminated.
Correctly handle sheets we failed to fetch (replace them with a blank one)
Modified:
branches/jmb/ns-libcss/css/css.c
branches/jmb/ns-libcss/css/css.h
Modified: branches/jmb/ns-libcss/css/css.c
URL: http://source.netsurf-browser.org/branches/jmb/ns-libcss/css/css.c?rev=82...
==============================================================================
--- branches/jmb/ns-libcss/css/css.c (original)
+++ branches/jmb/ns-libcss/css/css.c Tue Jun 30 18:31:28 2009
@@ -44,6 +44,7 @@
c->data.css.import_count = 0;
c->data.css.imports = NULL;
+ c->data.css.blank = NULL;
return true;
}
@@ -69,7 +70,7 @@
uint32_t i;
lwc_string *uri;
uint64_t media;
- char *abs_url, *norm_url;
+ char *rel_url, *abs_url, *norm_url;
url_func_result res;
error = css_stylesheet_next_pending_import(c->data.css.sheet,
@@ -95,12 +96,24 @@
}
c->data.css.imports = imports;
+ /* Copy specified URL and ensure it's NUL terminated */
+ rel_url = malloc(lwc_string_length(uri) + 1);
+ if (rel_url == NULL) {
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+ memcpy(rel_url, lwc_string_data(uri), lwc_string_length(uri));
+ rel_url[lwc_string_length(uri)] = '\0';
+
/* Resolve URI */
- res = url_join(lwc_string_data(uri), c->url, &abs_url);
+ res = url_join(rel_url, c->url, &abs_url);
if (res != URL_FUNC_OK) {
- c->status = CONTENT_STATUS_ERROR;
- return false;
- }
+ free(rel_url);
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+
+ free(rel_url);
/* Normalise it */
res = url_normalize(abs_url, &norm_url);
@@ -139,8 +152,29 @@
gui_multitask();
}
- error = css_stylesheet_register_import(c->data.css.sheet,
- c->data.css.imports[i]->data.css.sheet);
+ if (c->data.css.imports[i] != NULL) {
+ error = css_stylesheet_register_import(
+ c->data.css.sheet,
+ c->data.css.imports[i]->data.css.sheet);
+ } else {
+ if (c->data.css.blank == NULL) {
+ error = css_stylesheet_create(CSS_LEVEL_DEFAULT,
+ NULL, "", "", CSS_ORIGIN_AUTHOR,
+ media, false, false, dict,
+ myrealloc, NULL, &c->data.css.blank);
+ if (error != CSS_OK) {
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+ }
+
+ c->data.css.imports[i] =
+ (struct content *) c->data.css.blank;
+
+ error = css_stylesheet_register_import(
+ c->data.css.sheet,
+ (css_stylesheet *) c->data.css.imports[i]);
+ }
if (error != CSS_OK) {
c->status = CONTENT_STATUS_ERROR;
return false;
@@ -156,6 +190,22 @@
void css_destroy(struct content *c)
{
+ uint32_t i;
+
+ for (i = 0; i < c->data.css.import_count; i++) {
+ if (c->data.css.imports[i] !=
+ (struct content *) c->data.css.blank) {
+ content_remove_user(c->data.css.imports[i],
+ css_import, (uintptr_t) c, i);
+ }
+ c->data.css.imports[i] = NULL;
+ }
+
+ free(c->data.css.imports);
+
+ if (c->data.css.blank != NULL)
+ css_stylesheet_destroy(c->data.css.blank);
+
css_stylesheet_destroy(c->data.css.sheet);
}
Modified: branches/jmb/ns-libcss/css/css.h
URL: http://source.netsurf-browser.org/branches/jmb/ns-libcss/css/css.h?rev=82...
==============================================================================
--- branches/jmb/ns-libcss/css/css.h (original)
+++ branches/jmb/ns-libcss/css/css.h Tue Jun 30 18:31:28 2009
@@ -11,6 +11,8 @@
uint32_t import_count;
struct content **imports;
+
+ css_stylesheet *blank;
};
/** \todo This needs moving somewhere more sane */
14 years, 2 months
r8210 jmb - /trunk/libcss/test/data/select/tests1.dat
by netsurf@semichrome.net
Author: jmb
Date: Tue Jun 30 17:55:46 2009
New Revision: 8210
URL: http://source.netsurf-browser.org?rev=8210&view=rev
Log:
Fix test data:
Test 4 is testing the root node, so needs to compare against a fully computed style.
The paragraph node in test 5 is the first child of its parent, so the background colour is expected to be as specified.
Modified:
trunk/libcss/test/data/select/tests1.dat
Modified: trunk/libcss/test/data/select/tests1.dat
URL: http://source.netsurf-browser.org/trunk/libcss/test/data/select/tests1.da...
==============================================================================
--- trunk/libcss/test/data/select/tests1.dat (original)
+++ trunk/libcss/test/data/select/tests1.dat Tue Jun 30 17:55:46 2009
@@ -320,11 +320,12 @@
background-image: none
background-position: 0% 0%
background-repeat: repeat
-border-spacing: 0px 0px
-border-top-color: #00000000
-border-right-color: #00000000
-border-bottom-color: #00000000
-border-left-color: #00000000
+border-collapse: separate
+border-spacing: 0px 0px
+border-top-color: initial
+border-right-color: initial
+border-bottom-color: initial
+border-left-color: initial
border-top-style: none
border-right-style: none
border-bottom-style: none
@@ -334,41 +335,59 @@
border-bottom-width: medium
border-left-width: medium
bottom: auto
-clear: none
-clip: auto
-content: normal
-counter-increment: none
-counter-reset: none
-cursor: auto
+caption_side: top
+clear: none
+clip: auto
+color: #00000000
+content: normal
+counter-increment: none
+counter-reset: none
+cursor: auto
+direction: ltr
display: inline
-float: none
-height: auto
-left: auto
-letter-spacing: normal
-margin-top: 0px
-margin-right: 0px
-margin-bottom: 0px
-margin-left: 0px
-max-height: none
-max-width: none
-min-height: 0px
-min-width: 0px
-outline-color: invert
-outline-style: none
-outline-width: medium
-overflow: visible
-padding-top: 0px
-padding-right: 0px
-padding-bottom: 0px
-padding-left: 0px
-position: static
-quotes: default
-right: auto
-table-layout: auto
-text-decoration: none
-top: auto
-unicode-bidi: normal
-vertical-align: baseline
+empty-cells: show
+float: none
+font-family: default
+font-size: medium
+font-style: normal
+font-variant: normal
+font-weight: normal
+height: auto
+left: auto
+letter-spacing: normal
+line-height: normal
+list-style-image: none
+list-style-position: outside
+list-style-type: disc
+margin-top: 0px
+margin-right: 0px
+margin-bottom: 0px
+margin-left: 0px
+max-height: none
+max-width: none
+min-height: 0px
+min-width: 0px
+outline-color: invert
+outline-style: none
+outline-width: medium
+overflow: visible
+padding-top: 0px
+padding-right: 0px
+padding-bottom: 0px
+padding-left: 0px
+position: static
+quotes: default
+right: auto
+table-layout: auto
+text-align: default
+text-decoration: none
+text-indent: 0px
+text-transform: none
+top: auto
+unicode-bidi: normal
+vertical-align: baseline
+visibility: visible
+white-space: normal
width: auto
word-spacing: normal
z-index: auto
@@ -382,7 +401,7 @@
#errors
#expected
background-attachment: scroll
-background-color: transparent
+background-color: #bbbbcc00
background-image: none
background-position: 0% 0%
background-repeat: repeat
@@ -402,7 +421,6 @@
bottom: auto
clear: none
clip: auto
-color: #00000000
content: normal
counter-increment: none
counter-reset: none
14 years, 2 months
r8209 paulblokus - in /branches/paulblokus/treeview: desktop/history_global_core.c desktop/tree.c desktop/tree.h desktop/tree_url_node.c desktop/tree_url_node.h gtk/gtk_treeview.c
by netsurf@semichrome.net
Author: paulblokus
Date: Tue Jun 30 17:01:51 2009
New Revision: 8209
URL: http://source.netsurf-browser.org?rev=8209&view=rev
Log:
launch action and node element deletion handled by one user callback
Modified:
branches/paulblokus/treeview/desktop/history_global_core.c
branches/paulblokus/treeview/desktop/tree.c
branches/paulblokus/treeview/desktop/tree.h
branches/paulblokus/treeview/desktop/tree_url_node.c
branches/paulblokus/treeview/desktop/tree_url_node.h
branches/paulblokus/treeview/gtk/gtk_treeview.c
Modified: branches/paulblokus/treeview/desktop/history_global_core.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/hi...
==============================================================================
--- branches/paulblokus/treeview/desktop/history_global_core.c (original)
+++ branches/paulblokus/treeview/desktop/history_global_core.c Tue Jun 30 17:01:51 2009
@@ -33,6 +33,7 @@
#define MAXIMUM_BASE_NODES 16
#define GLOBAL_HISTORY_RECENT_URLS 16
+#define MAXIMUM_URL_LENGTH 1024
static struct node *global_history_base_node[MAXIMUM_BASE_NODES];
static int global_history_base_node_time[MAXIMUM_BASE_NODES];
@@ -54,8 +55,8 @@
const struct url_data *data);
static struct node *history_global_find(const char *url);
-static bool history_global_callback(void *user_data, void *element_data,
- unsigned int flag);
+static bool history_global_callback(node_msg msg, void *user_data,
+ void *element_data, unsigned int flag);
bool history_global_initialise(void *data,
void (*start_redraw)(void *data),
@@ -383,18 +384,35 @@
return global_history_recent_url;
}
-bool history_global_callback(void *user_data, void *element_data,
+bool history_global_callback(node_msg msg, void *user_data, void *node_data,
unsigned int flag)
{
-
- switch (flag) {
- case TREE_ELEMENT_URL:
- /* reset URL characteristics */
- urldb_reset_url_visit_data((char *)element_data);
- return true;
- case TREE_ELEMENT_TITLE:
- case TREE_ELEMENT_THUMBNAIL:
- return true;
+ struct node_element *element;
+ const char *text;
+
+ switch (msg) {
+ case NODE_DELETE_ELEMENT:
+ switch (flag) {
+ case TREE_ELEMENT_URL:
+ /* reset URL characteristics */
+ urldb_reset_url_visit_data(
+ (char *)node_data);
+ return true;
+ case TREE_ELEMENT_TITLE:
+ case TREE_ELEMENT_THUMBNAIL:
+ return true;
+ }
+ break;
+ case NODE_LAUNCH:
+ element = tree_node_find_element(node_data,
+ TREE_ELEMENT_URL);
+ if (element != NULL) {
+ text = tree_node_element_get_text(element);
+ browser_window_create(text, NULL, 0,
+ true, false);
+ return true;
+ }
+ break;
}
return false;
}
Modified: branches/paulblokus/treeview/desktop/tree.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.c (original)
+++ branches/paulblokus/treeview/desktop/tree.c Tue Jun 30 17:01:51 2009
@@ -93,10 +93,8 @@
/* Sorting function for the node (for folder nodes only) */
int (*sort) (struct node *, struct node *);
- /* Action to be taken on node launch */
- void (*action) (struct tree *tree, struct node *node);
- /* Gets called for each deleted node_element */
- tree_node_delete_callback delete_callback;
+ /* Gets called for each deleted node_element and on node launch */
+ tree_node_user_callback user_callback;
/* User data to be passed to delete_callback */
void *callback_data;
@@ -174,7 +172,6 @@
void tree_clear_processing(struct node *node);
static struct node *tree_move_processing_node(struct tree *tree,
struct node *node, struct node *link, bool before, bool first);
-static bool tree_launch_node(struct tree *tree, struct node *node);
/**
@@ -269,8 +266,7 @@
node->retain_in_memory = retain_in_memory;
node->deleted = deleted;
node->sort = NULL;
- node->action = NULL;
- node->delete_callback = NULL;
+ node->user_callback = NULL;
bm = tree_get_icon(tree, node, "small_dir", false);
tree_set_node_icon(tree, node, bm);
@@ -313,8 +309,7 @@
node->retain_in_memory = retain_in_memory;
node->deleted = deleted;
node->sort = NULL;
- node->action = NULL;
- node->delete_callback = NULL;
+ node->user_callback = NULL;
if (parent != NULL)
tree_link_node(tree, parent, node, false);
else
@@ -502,8 +497,9 @@
for (e = &node->data; e; e = f) {
if (e->text != NULL) {
handled = false;
- if (node->delete_callback != NULL)
- handled = node->delete_callback(
+ if (node->user_callback != NULL)
+ handled = node->user_callback(
+ NODE_DELETE_ELEMENT,
node->callback_data,
(void *)e->text,
e->flag);
@@ -513,8 +509,9 @@
}
if (e->bitmap != NULL) {
handled = false;
- if (node->delete_callback != NULL)
- handled = node->delete_callback(
+ if (node->user_callback != NULL)
+ handled = node->user_callback(
+ NODE_DELETE_ELEMENT,
node->callback_data,
e->bitmap,
e->flag);
@@ -714,10 +711,10 @@
* \param callback the callback functions to be set
* \param data user data to be passed to callback
*/
-void tree_set_node_delete_callback(struct node *node,
- tree_node_delete_callback callback, void *data)
-{
- node->delete_callback = callback;
+void tree_set_node_user_callback(struct node *node,
+ tree_node_user_callback callback, void *data)
+{
+ node->user_callback = callback;
node->callback_data = data;
}
@@ -842,8 +839,9 @@
element->type == NODE_ELEMENT_TEXT_PLUS_ICON)) {
if (element->text != NULL) {
handled = false;
- if (element->parent->delete_callback != NULL)
- handled = element->parent->delete_callback(
+ if (element->parent->user_callback != NULL)
+ handled = element->parent->user_callback(
+ NODE_DELETE_ELEMENT,
element->parent->callback_data,
(void *)element->text,
element->flag);
@@ -857,8 +855,9 @@
element->type == NODE_ELEMENT_TEXT_PLUS_ICON)) {
if (element->bitmap != NULL) {
handled = false;
- if (element->parent->delete_callback != NULL)
- handled = element->parent->delete_callback(
+ if (element->parent->user_callback != NULL)
+ handled = element->parent->user_callback(
+ NODE_DELETE_ELEMENT,
element->parent->callback_data,
element->bitmap,
element->flag);
@@ -1359,9 +1358,11 @@
return true;
}
- /* double click starts launches the leaf */
+ /* double click launches the leaf */
if (mouse & BROWSER_MOUSE_DOUBLE_CLICK) {
- if (!tree_launch_node(tree, node))
+ if (node->user_callback == NULL ||
+ !node->user_callback(NODE_LAUNCH,
+ node->callback_data, node, 0))
return false;
return true;
}
@@ -1429,34 +1430,6 @@
return true;
}
-
- return false;
-}
-
-
-/**
- * Launches a node using all known methods.
- *
- * \param tree the tree to which 'node' belongs
- * \param node the node to launch
- * \return whether the node could be launched
- */
-bool tree_launch_node(struct tree *tree, struct node *node)
-{
- struct node_element *element;
-
- assert(node);
-
- if (node->action) {
- node->action(tree, node);
- return true;
- }
-
- element = tree_node_find_element(node, TREE_ELEMENT_URL);
- if (element) {
- browser_window_create(element->text, NULL, 0, true, false);
- return true;
- }
return false;
}
Modified: branches/paulblokus/treeview/desktop/tree.h
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.h (original)
+++ branches/paulblokus/treeview/desktop/tree.h Tue Jun 30 17:01:51 2009
@@ -36,12 +36,6 @@
#define TREE_SINGLE_SELECT 0x04
#define TREE_MOVABLE 0x08
-/* globally known flag for node_elements, all user defined flags should have
- numbers above 0x01 */
-#define TREE_ELEMENT_URL 0x01
-
-#define MAXIMUM_URL_LENGTH 1024
-
struct tree;
struct node;
struct node_element;
@@ -50,14 +44,19 @@
typedef enum {
NODE_ELEMENT_TEXT, /* <-- Text only */
NODE_ELEMENT_TEXT_PLUS_ICON, /* <-- Text and icon */
- NODE_ELEMENT_BITMAP, /* <-- Bitmap only */
+ NODE_ELEMENT_BITMAP /* <-- Bitmap only */
} node_element_type;
+
+typedef enum {
+ NODE_DELETE_ELEMENT,
+ NODE_LAUNCH
+} node_msg;
typedef void (*tree_start_redraw_callback)(void *data);
typedef void (*tree_end_redraw_callback)(void *data);
/* TODO: where do I document callbacks? */
-typedef bool (*tree_node_delete_callback)(void *user_data, void *element_data,
- unsigned int flag);
+typedef bool (*tree_node_user_callback)(node_msg msg, void *user_data,
+ void *node_data, unsigned int flag);
/* Non-platform specific code */
@@ -89,8 +88,8 @@
bool selected);
void tree_set_node_sort_function(struct tree *tree, struct node *node,
int (*sort) (struct node *, struct node *));
-void tree_set_node_delete_callback(struct node *node,
- tree_node_delete_callback callback, void *data);
+void tree_set_node_user_callback(struct node *node,
+ tree_node_user_callback callback, void *data);
void tree_set_redraw(struct tree *tree, bool redraw);
bool tree_node_has_selection(struct node *node);
bool tree_node_is_deleted(struct node *node);
Modified: branches/paulblokus/treeview/desktop/tree_url_node.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.c (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.c Tue Jun 30 17:01:51 2009
@@ -40,7 +40,7 @@
*/
struct node *tree_create_URL_node(struct tree *tree, struct node *parent,
const char *url, const struct url_data *data, const char *title,
- tree_node_delete_callback delete_callback, void *callback_data)
+ tree_node_user_callback user_callback, void *callback_data)
{
struct node *node;
struct node_element *element;
@@ -54,8 +54,8 @@
if (!node)
return NULL;
- if (delete_callback != NULL)
- tree_set_node_delete_callback(node, delete_callback,
+ if (user_callback != NULL)
+ tree_set_node_user_callback(node, user_callback,
callback_data);
tree_create_node_element(node, NODE_ELEMENT_BITMAP,
@@ -86,7 +86,7 @@
*/
struct node *tree_create_URL_node_shared(struct tree *tree, struct node *parent,
const char *url, const struct url_data *data,
- tree_node_delete_callback delete_callback, void *callback_data)
+ tree_node_user_callback user_callback, void *callback_data)
{
struct node *node;
struct node_element *element;
@@ -103,8 +103,8 @@
if (!node)
return NULL;
- if (delete_callback != NULL)
- tree_set_node_delete_callback(node, delete_callback,
+ if (user_callback != NULL)
+ tree_set_node_user_callback(node, user_callback,
callback_data);
tree_create_node_element(node, NODE_ELEMENT_BITMAP,
Modified: branches/paulblokus/treeview/desktop/tree_url_node.h
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.h (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.h Tue Jun 30 17:01:51 2009
@@ -27,6 +27,7 @@
#include "desktop/tree.h"
+#define TREE_ELEMENT_URL 0x01
#define TREE_ELEMENT_LAST_VISIT 0x02
#define TREE_ELEMENT_VISITS 0x03
#define TREE_ELEMENT_TITLE 0x04
@@ -35,11 +36,11 @@
struct node *tree_create_URL_node(struct tree *tree,
struct node *parent, const char *url,
const struct url_data *data, const char *title,
- tree_node_delete_callback, void *callback_data);
+ tree_node_user_callback, void *callback_data);
struct node *tree_create_URL_node_shared(struct tree *tree,
struct node *parent, const char *url,
const struct url_data *data,
- tree_node_delete_callback, void *callback_data);
+ tree_node_user_callback, void *callback_data);
void tree_update_URL_node(struct tree *tree,struct node *node,
const char *url, const struct url_data *data);
Modified: branches/paulblokus/treeview/gtk/gtk_treeview.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/gtk/gtk_tr...
==============================================================================
--- branches/paulblokus/treeview/gtk/gtk_treeview.c (original)
+++ branches/paulblokus/treeview/gtk/gtk_treeview.c Tue Jun 30 17:01:51 2009
@@ -31,6 +31,8 @@
#include "gtk/gtk_gui.h"
#include "gtk/gtk_plotters.h"
#include "gtk/gtk_treeview.h"
+
+#define MAXIMUM_URL_LENGTH 1024
static bool set = false;
14 years, 2 months
r8208 paulblokus - in /branches/paulblokus/treeview: desktop/history_global_core.c desktop/options.c desktop/tree.c desktop/tree.h desktop/tree_url_node.c desktop/tree_url_node.h gtk/gtk_treeview.c
by netsurf@semichrome.net
Author: paulblokus
Date: Tue Jun 30 16:22:24 2009
New Revision: 8208
URL: http://source.netsurf-browser.org?rev=8208&view=rev
Log:
use delete_callback on node_element update
history_global_callback cares for shared data not to be removed
remove urldb calls from tree.c
user can set any bitmap now (not only thumbnails from urldb)
Modified:
branches/paulblokus/treeview/desktop/history_global_core.c
branches/paulblokus/treeview/desktop/options.c
branches/paulblokus/treeview/desktop/tree.c
branches/paulblokus/treeview/desktop/tree.h
branches/paulblokus/treeview/desktop/tree_url_node.c
branches/paulblokus/treeview/desktop/tree_url_node.h
branches/paulblokus/treeview/gtk/gtk_treeview.c
Modified: branches/paulblokus/treeview/desktop/history_global_core.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/hi...
==============================================================================
--- branches/paulblokus/treeview/desktop/history_global_core.c (original)
+++ branches/paulblokus/treeview/desktop/history_global_core.c Tue Jun 30 16:22:24 2009
@@ -288,8 +288,7 @@
/* Add the node at the bottom */
node = tree_create_URL_node_shared(global_history_tree,
- parent, url, data);
- tree_set_node_delete_callback(node, history_global_callback, NULL);
+ parent, url, data, history_global_callback, NULL);
return true;
}
@@ -387,8 +386,15 @@
bool history_global_callback(void *user_data, void *element_data,
unsigned int flag)
{
- /* reset URL characteristics */
- if (flag == TREE_ELEMENT_URL)
- urldb_reset_url_visit_data((char *)element_data);
- return true;
-}
+
+ switch (flag) {
+ case TREE_ELEMENT_URL:
+ /* reset URL characteristics */
+ urldb_reset_url_visit_data((char *)element_data);
+ return true;
+ case TREE_ELEMENT_TITLE:
+ case TREE_ELEMENT_THUMBNAIL:
+ return true;
+ }
+ return false;
+}
Modified: branches/paulblokus/treeview/desktop/options.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/op...
==============================================================================
--- branches/paulblokus/treeview/desktop/options.c (original)
+++ branches/paulblokus/treeview/desktop/options.c Tue Jun 30 16:22:24 2009
@@ -599,7 +599,8 @@
if (!data->title)
urldb_set_url_title(url, title);
- entry = tree_create_URL_node(NULL, directory, url, data, title);
+ entry = tree_create_URL_node(NULL, directory, url, data, title, NULL,
+ NULL);
if (entry == NULL) {
/** \todo why isn't this fatal? */
warn_user("NoMemory", 0);
Modified: branches/paulblokus/treeview/desktop/tree.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.c (original)
+++ branches/paulblokus/treeview/desktop/tree.c Tue Jun 30 16:22:24 2009
@@ -26,7 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "content/urldb.h"
+#include "content/content.h"
#include "desktop/browser.h"
#include "desktop/tree.h"
#include "desktop/options.h"
@@ -48,8 +48,6 @@
#define NODE_INSTEP 20
#define TREE_TEXT_HEIGHT 20
-#define THUMBNAIL_WIDTH 100
-#define THUMBNAIL_HEIGHT 86
#define FURNITURE_COLOUR 0x888888
@@ -69,7 +67,7 @@
node_element_type type; /* Element type */
struct node_element_box box; /* Element bounding box */
const char *text; /* Text for the element */
- struct content *bitmap; /* Bitmap for the element */
+ void *bitmap; /* Bitmap for the element */
struct node_element *next; /* Next node element */
unsigned int flag; /* Client specified flag for data
being represented */
@@ -131,13 +129,6 @@
callbacks */
};
-/* callback update */
-struct node_update {
- struct tree *tree;
- struct node *node;
-};
-
-
static void tree_delete_node_internal(struct tree *tree, struct node *node,
bool siblings);
static void tree_sort_insert(struct node *parent, struct node *node);
@@ -154,7 +145,6 @@
static void tree_handle_node_changed(struct tree *tree, struct node *node,
bool recalculate_sizes, bool expansion);
-static void tree_handle_node_changed_callback(void *p);
static void tree_handle_node_element_changed(struct tree *tree,
struct node_element *element);
@@ -282,7 +272,7 @@
node->action = NULL;
node->delete_callback = NULL;
- bm = tree_get_icon(node, "small_dir", false);
+ bm = tree_get_icon(tree, node, "small_dir", false);
tree_set_node_icon(tree, node, bm);
if (parent != NULL)
tree_link_node(tree, parent, node, false);
@@ -510,7 +500,7 @@
if (!node->retain_in_memory) {
node->retain_in_memory = true;
for (e = &node->data; e; e = f) {
- if (e->text) {
+ if (e->text != NULL) {
handled = false;
if (node->delete_callback != NULL)
handled = node->delete_callback(
@@ -521,7 +511,7 @@
free((void *)e->text);
e->text = NULL;
}
- if (e->bitmap) {
+ if (e->bitmap != NULL) {
handled = false;
if (node->delete_callback != NULL)
handled = node->delete_callback(
@@ -843,19 +833,38 @@
* \param free_mem if true, the old values of text/bitmap will be freed
*/
void tree_update_node_element(struct tree *tree, struct node_element *element,
- const char *text, struct content *bitmap, bool free_mem)
-{
+ const char *text, void *bitmap)
+{
+
+ bool handled;
if (text != NULL && (element->type == NODE_ELEMENT_TEXT ||
element->type == NODE_ELEMENT_TEXT_PLUS_ICON)) {
- if (free_mem)
- free((void *)element->text);
+ if (element->text != NULL) {
+ handled = false;
+ if (element->parent->delete_callback != NULL)
+ handled = element->parent->delete_callback(
+ element->parent->callback_data,
+ (void *)element->text,
+ element->flag);
+ if (!handled)
+ free((void *)element->text);
+ }
element->text = text;
}
- if (bitmap != NULL && (element->type == NODE_ELEMENT_BITMAP)) {
- if (free_mem)
- free(element->bitmap);
+ if (bitmap != NULL && (element->type == NODE_ELEMENT_BITMAP ||
+ element->type == NODE_ELEMENT_TEXT_PLUS_ICON)) {
+ if (element->bitmap != NULL) {
+ handled = false;
+ if (element->parent->delete_callback != NULL)
+ handled = element->parent->delete_callback(
+ element->parent->callback_data,
+ element->bitmap,
+ element->flag);
+ if (!handled)
+ free(element->bitmap);
+ }
element->bitmap = bitmap;
}
@@ -1068,10 +1077,7 @@
void tree_draw_node_element(struct tree *tree, struct node_element *element)
{
- struct node_element *url_element;
struct bitmap *bitmap = NULL;
- struct node_update *update;
- const uint8_t *frame;
int x, y;
bool selected = false;
colour bg, c;
@@ -1092,10 +1098,9 @@
/*TODO: the if is necessary as long as the bitmap gets fetched
as a content*/
//assert(element->bitmap);
- if (element->bitmap)
+ if (element->bitmap != NULL)
content_redraw(element->bitmap, x, y + 3, 16,
- 16, x, y, x + 16, y + 16, 1,
- 0);
+ 16, x, y, x + 16, y + 16, 1, 0);
x += NODE_INSTEP;
/* fall through */
@@ -1120,36 +1125,17 @@
strlen(element->text), bg, c);
break;
case NODE_ELEMENT_BITMAP:
- url_element = tree_node_find_element(element->parent,
- TREE_ELEMENT_URL);
- if (url_element)
- bitmap = urldb_get_thumbnail(url_element->text);
-
+ bitmap = element->bitmap;
if (bitmap == NULL)
- break;
- frame = bitmap_get_buffer((struct bitmap *) bitmap);
- if (frame == NULL)
- urldb_set_thumbnail(url_element->text,
- NULL);
- if ((frame == NULL) || (element->box.width == 0)) {
- update = calloc(sizeof(struct node_update), 1);
- if (update == NULL)
- return;
- update->tree = tree;
- update->node = element->parent;
- schedule(0, tree_handle_node_changed_callback,
- update);
- return;
- }
- plot.bitmap(x, y, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
+ break;
+ plot.bitmap(x, y, element->box.width - 1,
+ element->box.height - 2,
bitmap, 0xFFFFFF, NULL);
- if (!(tree->flags & TREE_NO_FURNITURE)) {
-
+ if (!(tree->flags & TREE_NO_FURNITURE))
plot.rectangle(x, y, element->box.width - 1,
element->box.height - 3,
1, FURNITURE_COLOUR,
false, false);
- }
break;
}
@@ -1534,11 +1520,12 @@
void tree_callback(content_msg msg, struct content *c,
intptr_t p1, intptr_t p2, union content_msg_data data)
{
- struct node *node = (struct node *) p1;
+ struct tree *tree = (struct tree *) p1;
+ struct node *node = (struct node *) p2;
switch (msg) {
case CONTENT_MSG_READY:
- node->data.bitmap = c;
+ tree_update_node_element(tree, &(node->data), NULL, c);
break;
default:
break;
@@ -1587,15 +1574,6 @@
}
-void tree_handle_node_changed_callback(void *p)
-{
- struct node_update *update = p;
-
- tree_handle_node_changed(update->tree, update->node, true, false);
- free(update);
-}
-
-
/**
* Recalculate the node element and redraw the relevant section of the tree.
* The tree size is not updated.
@@ -1640,8 +1618,8 @@
*/
void tree_recalculate_node_element(struct node_element *element)
{
- const struct bitmap *bitmap = NULL;
- struct node_element *url_element;
+ struct bitmap *bitmap = NULL;
+ int width, height;
assert(element);
@@ -1661,18 +1639,12 @@
element->box.width += NODE_INSTEP;
break;
case NODE_ELEMENT_BITMAP:
- url_element = tree_node_find_element(element->parent,
- TREE_ELEMENT_URL);
- if (url_element)
- bitmap = urldb_get_thumbnail(url_element->text);
- if (bitmap) {
-/* if ((bitmap->width == 0) &&
- (bitmap->height == 0))
- frame = bitmap_get_buffer(bitmap);
- element->box.width = bitmap->width * 2 + 1;
- element->box.height = bitmap->height * 2 + 2;
-*/ element->box.width = THUMBNAIL_WIDTH + 1;
- element->box.height = THUMBNAIL_HEIGHT + 2;
+ bitmap = element->bitmap;
+ if (bitmap != NULL) {
+ width = bitmap_get_width(bitmap);
+ height = bitmap_get_height(bitmap);
+ element->box.width = width + 1;
+ element->box.height = height + 2;
} else {
element->box.width = 0;
element->box.height = 0;
Modified: branches/paulblokus/treeview/desktop/tree.h
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree.h (original)
+++ branches/paulblokus/treeview/desktop/tree.h Tue Jun 30 16:22:24 2009
@@ -96,7 +96,7 @@
bool tree_node_is_deleted(struct node *node);
bool tree_node_is_folder(struct node *node);
void tree_update_node_element(struct tree *tree, struct node_element *element,
- const char *text, struct content *bitmap, bool free);
+ const char *text, void *bitmap);
const char *tree_node_element_get_text(struct node_element *element);
struct node *tree_get_root(struct tree *tree);
@@ -126,8 +126,8 @@
/* Platform specific code */
void tree_resized(struct tree *tree, int width, int height, void *data);
-struct content *tree_get_icon(struct node *node, const char *icon,
- bool path);
+struct content *tree_get_icon(struct tree *tree, struct node *node,
+ const char *icon, bool path);
void tree_icon_name_from_content_type(char *buffer, content_type type);
void tree_scroll_visible(struct tree *tree, struct node_element *element,
void *data);
Modified: branches/paulblokus/treeview/desktop/tree_url_node.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.c (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.c Tue Jun 30 16:22:24 2009
@@ -39,7 +39,8 @@
* \return the node created, or NULL for failure
*/
struct node *tree_create_URL_node(struct tree *tree, struct node *parent,
- const char *url, const struct url_data *data, const char *title)
+ const char *url, const struct url_data *data, const char *title,
+ tree_node_delete_callback delete_callback, void *callback_data)
{
struct node *node;
struct node_element *element;
@@ -53,15 +54,19 @@
if (!node)
return NULL;
- tree_create_node_element(node, NODE_ELEMENT_BITMAP, 0);
+ if (delete_callback != NULL)
+ tree_set_node_delete_callback(node, delete_callback,
+ callback_data);
+
+ tree_create_node_element(node, NODE_ELEMENT_BITMAP,
+ TREE_ELEMENT_THUMBNAIL);
tree_create_node_element(node, NODE_ELEMENT_TEXT, TREE_ELEMENT_VISITS);
tree_create_node_element(node, NODE_ELEMENT_TEXT,
TREE_ELEMENT_LAST_VISIT);
element = tree_create_node_element(node, NODE_ELEMENT_TEXT,
TREE_ELEMENT_URL);
if (element)
- tree_update_node_element(tree,
- element, strdup(url), NULL, true);
+ tree_update_node_element(tree, element, strdup(url), NULL);
tree_update_URL_node(tree, node, url, NULL);
return node;
@@ -79,9 +84,9 @@
* \param data the URL data to use
* \return the node created, or NULL for failure
*/
- struct node *tree_create_URL_node_shared(struct tree *tree,
- struct node *parent, const char *url,
- const struct url_data *data)
+struct node *tree_create_URL_node_shared(struct tree *tree, struct node *parent,
+ const char *url, const struct url_data *data,
+ tree_node_delete_callback delete_callback, void *callback_data)
{
struct node *node;
struct node_element *element;
@@ -97,16 +102,20 @@
TREE_ELEMENT_TITLE);
if (!node)
return NULL;
-
- element = tree_create_node_element(node, NODE_ELEMENT_BITMAP, 0);
+
+ if (delete_callback != NULL)
+ tree_set_node_delete_callback(node, delete_callback,
+ callback_data);
+
+ tree_create_node_element(node, NODE_ELEMENT_BITMAP,
+ TREE_ELEMENT_THUMBNAIL);
tree_create_node_element(node, NODE_ELEMENT_TEXT, TREE_ELEMENT_VISITS);
tree_create_node_element(node, NODE_ELEMENT_TEXT,
TREE_ELEMENT_LAST_VISIT);
element = tree_create_node_element(node, NODE_ELEMENT_TEXT,
TREE_ELEMENT_URL);
if (element)
- tree_update_node_element(tree, element, url,
- NULL, true);
+ tree_update_node_element(tree, element, url, NULL);
tree_update_URL_node(tree, node, url, data);
return node;
@@ -120,54 +129,62 @@
void tree_update_URL_node(struct tree *tree, struct node *node,
const char *url, const struct url_data *data)
{
- struct node_element *element, *element2;
+ struct node_element *element;
char buffer[256];
struct content *bm;
-
+ struct bitmap *bitmap = NULL;
+
assert(node);
element = tree_node_find_element(node, TREE_ELEMENT_URL);
- if (!element)
+ if (element == NULL)
return;
+
if (data) {
- if (!data->title)
+ if (data->title == NULL)
urldb_set_url_title(url, url);
- if (!data->title)
+ if (data->title == NULL)
return;
- element2 = tree_node_find_element(node, TREE_ELEMENT_TITLE);
- tree_update_node_element(tree, element2, data->title, NULL,
- false);
+ element = tree_node_find_element(node, TREE_ELEMENT_TITLE);
+ tree_update_node_element(tree, element, data->title, NULL);
} else {
data = urldb_get_url_data(tree_node_element_get_text(element));
- if (!data)
+ if (data == NULL)
return;
}
- if (element) {
- tree_icon_name_from_content_type(buffer, data->type);
- bm = tree_get_icon(node, buffer, false);
- tree_set_node_icon(tree, node, bm);
- }
+
+ tree_icon_name_from_content_type(buffer, data->type);
+ bm = tree_get_icon(tree, node, buffer, false);
+ tree_set_node_icon(tree, node, bm);
+
element = tree_node_find_element(node, TREE_ELEMENT_LAST_VISIT);
- if (element) {
+ if (element != NULL) {
snprintf(buffer, 256, messages_get("TreeLast"),
(data->last_visit > 0) ?
ctime((time_t *)&data->last_visit) :
messages_get("TreeUnknown"));
if (data->last_visit > 0)
buffer[strlen(buffer) - 1] = '\0';
- tree_update_node_element(tree,
- element, strdup(buffer), NULL, true);
+ tree_update_node_element(tree, element, strdup(buffer), NULL);
}
element = tree_node_find_element(node, TREE_ELEMENT_VISITS);
- if (element) {
+ if (element != NULL) {
snprintf(buffer, 256, messages_get("TreeVisits"),
data->visits);
- tree_update_node_element(tree, element,
- strdup(buffer), NULL, true);
+ tree_update_node_element(tree, element, strdup(buffer), NULL);
+ }
+
+ element = tree_node_find_element(node, TREE_ELEMENT_THUMBNAIL);
+ if (element != NULL) {
+ bitmap = urldb_get_thumbnail(url);
+
+ if (bitmap != NULL) {
+ tree_update_node_element(tree, element, NULL, bitmap);
+ }
}
}
Modified: branches/paulblokus/treeview/desktop/tree_url_node.h
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/desktop/tr...
==============================================================================
--- branches/paulblokus/treeview/desktop/tree_url_node.h (original)
+++ branches/paulblokus/treeview/desktop/tree_url_node.h Tue Jun 30 16:22:24 2009
@@ -30,13 +30,16 @@
#define TREE_ELEMENT_LAST_VISIT 0x02
#define TREE_ELEMENT_VISITS 0x03
#define TREE_ELEMENT_TITLE 0x04
+#define TREE_ELEMENT_THUMBNAIL 0x05
struct node *tree_create_URL_node(struct tree *tree,
struct node *parent, const char *url,
- const struct url_data *data, const char *title);
+ const struct url_data *data, const char *title,
+ tree_node_delete_callback, void *callback_data);
struct node *tree_create_URL_node_shared(struct tree *tree,
struct node *parent, const char *url,
- const struct url_data *data);
+ const struct url_data *data,
+ tree_node_delete_callback, void *callback_data);
void tree_update_URL_node(struct tree *tree,struct node *node,
const char *url, const struct url_data *data);
Modified: branches/paulblokus/treeview/gtk/gtk_treeview.c
URL: http://source.netsurf-browser.org/branches/paulblokus/treeview/gtk/gtk_tr...
==============================================================================
--- branches/paulblokus/treeview/gtk/gtk_treeview.c (original)
+++ branches/paulblokus/treeview/gtk/gtk_treeview.c Tue Jun 30 16:22:24 2009
@@ -37,6 +37,7 @@
/**
* Acquires a specific front end specified icon.
*
+ * \param tree The tree to which node belongs, may be NULL
* \param node The node for which the icon bitmap gets acquired. This
* is necessary at the moment as the pointer gets passed
* to tree_callback which actually sets the icon.
@@ -44,8 +45,8 @@
* \param path If true 'icon' contains the full path under which the
* icon can be found
*/
-struct content *tree_get_icon(struct node *node, const char *icon,
- bool path)
+struct content *tree_get_icon(struct tree *tree, struct node *node,
+ const char *icon, bool path)
{
/* TODO: something like bitmap_from_disk is needed here*/
@@ -60,10 +61,10 @@
sprintf(icon_path, "%s%s%s%s", "file://", res_dir_location,
icon, ".bmp");
}
- c = fetchcache(icon_path, tree_callback, (intptr_t) node, 0, 16, 16, true,
- 0, 0, true, false);
- fetchcache_go(c, 0, tree_callback, (intptr_t) node, 0, 16, 16, 0, 0,
- true, 0);
+ c = fetchcache(icon_path, tree_callback, (intptr_t) tree,
+ (intptr_t) node, 16, 16, true, 0, 0, true, false);
+ fetchcache_go(c, 0, tree_callback, (intptr_t) tree, (intptr_t) node, 16,
+ 16, 0, 0, true, 0);
return c;
}
14 years, 2 months
r8207 jmb - in /branches/jmb/ns-libcss/css: css.c css.h
by netsurf@semichrome.net
Author: jmb
Date: Tue Jun 30 14:00:05 2009
New Revision: 8207
URL: http://source.netsurf-browser.org?rev=8207&view=rev
Log:
Process @import list. This approach may well have a negative impact on page load times.
Modified:
branches/jmb/ns-libcss/css/css.c
branches/jmb/ns-libcss/css/css.h
Modified: branches/jmb/ns-libcss/css/css.c
URL: http://source.netsurf-browser.org/branches/jmb/ns-libcss/css/css.c?rev=82...
==============================================================================
--- branches/jmb/ns-libcss/css/css.c (original)
+++ branches/jmb/ns-libcss/css/css.c Tue Jun 30 14:00:05 2009
@@ -1,9 +1,18 @@
+#include <assert.h>
+
#include <libwapcaplet/libwapcaplet.h>
#include "content/content.h"
+#include "content/fetch.h"
+#include "content/fetchcache.h"
#include "css/css.h"
+#include "desktop/gui.h"
+#include "utils/url.h"
static lwc_context *dict;
+
+static void css_import(content_msg msg, struct content *c,
+ intptr_t p1, intptr_t p2, union content_msg_data data);
static void *myrealloc(void *ptr, size_t size, void *pw)
{
@@ -33,6 +42,9 @@
if (error != CSS_OK)
return false;
+ c->data.css.import_count = 0;
+ c->data.css.imports = NULL;
+
return true;
}
@@ -52,9 +64,89 @@
error = css_stylesheet_data_done(c->data.css.sheet);
- if (error == CSS_IMPORTS_PENDING) {
- /** \todo process pending imports */
- error = CSS_OK;
+ while (error == CSS_IMPORTS_PENDING) {
+ struct content **imports;
+ uint32_t i;
+ lwc_string *uri;
+ uint64_t media;
+ char *abs_url, *norm_url;
+ url_func_result res;
+
+ error = css_stylesheet_next_pending_import(c->data.css.sheet,
+ &uri, &media);
+ if (error != CSS_OK && error != CSS_INVALID) {
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+
+ /* Give up if there are no more imports */
+ if (error == CSS_INVALID) {
+ error = CSS_OK;
+ break;
+ }
+
+ /* Increase space in table */
+ imports = realloc(c->data.css.imports,
+ (c->data.css.import_count + 1) *
+ sizeof(struct content *));
+ if (imports == NULL) {
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+ c->data.css.imports = imports;
+
+ /* Resolve URI */
+ res = url_join(lwc_string_data(uri), c->url, &abs_url);
+ if (res != URL_FUNC_OK) {
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+
+ /* Normalise it */
+ res = url_normalize(abs_url, &norm_url);
+ if (res != URL_FUNC_OK) {
+ free(abs_url);
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+
+ free(abs_url);
+
+ /* Create content */
+ i = c->data.css.import_count;
+ c->data.css.imports[c->data.css.import_count++] =
+ fetchcache(norm_url,
+ css_import, (intptr_t) c, i,
+ c->width, c->height, true, NULL, NULL,
+ false, false);
+ if (c->data.css.imports[i] == NULL) {
+ free(norm_url);
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+
+ /* Fetch content */
+ c->active++;
+ fetchcache_go(c->data.css.imports[i], c->url,
+ css_import, (intptr_t) c, i,
+ c->width, c->height, NULL, NULL, false, c->url);
+
+ free(norm_url);
+
+ /* Wait for import to fetch + convert */
+ while (c->active > 0) {
+ fetch_poll();
+ gui_multitask();
+ }
+
+ error = css_stylesheet_register_import(c->data.css.sheet,
+ c->data.css.imports[i]->data.css.sheet);
+ if (error != CSS_OK) {
+ c->status = CONTENT_STATUS_ERROR;
+ return false;
+ }
+
+ error = CSS_IMPORTS_PENDING;
}
c->status = CONTENT_STATUS_DONE;
@@ -67,3 +159,48 @@
css_stylesheet_destroy(c->data.css.sheet);
}
+void css_import(content_msg msg, struct content *c,
+ intptr_t p1, intptr_t p2, union content_msg_data data)
+{
+ struct content *parent = (struct content *) p1;
+ uint32_t i = (uint32_t) p2;
+
+ switch (msg) {
+ case CONTENT_MSG_LOADING:
+ if (c->type != CONTENT_CSS) {
+ content_remove_user(c, css_import, p1, p2);
+ if (c->user_list->next == NULL) {
+ fetch_abort(c->fetch);
+ c->fetch = NULL;
+ c->status = CONTENT_STATUS_ERROR;
+ }
+
+ parent->data.css.imports[i] = NULL;
+ parent->active--;
+ content_add_error(parent, "NotCSS", 0);
+ }
+ break;
+ case CONTENT_MSG_READY:
+ break;
+ case CONTENT_MSG_DONE:
+ parent->active--;
+ break;
+ case CONTENT_MSG_AUTH:
+ case CONTENT_MSG_SSL:
+ case CONTENT_MSG_LAUNCH:
+ case CONTENT_MSG_ERROR:
+ if (parent->data.css.imports[i] == c) {
+ parent->data.css.imports[i] = NULL;
+ parent->active--;
+ }
+ break;
+ case CONTENT_MSG_STATUS:
+ break;
+ case CONTENT_MSG_NEWPTR:
+ parent->data.css.imports[i] = c;
+ break;
+ default:
+ assert(0);
+ }
+}
+
Modified: branches/jmb/ns-libcss/css/css.h
URL: http://source.netsurf-browser.org/branches/jmb/ns-libcss/css/css.h?rev=82...
==============================================================================
--- branches/jmb/ns-libcss/css/css.h (original)
+++ branches/jmb/ns-libcss/css/css.h Tue Jun 30 14:00:05 2009
@@ -8,6 +8,9 @@
struct content_css_data
{
css_stylesheet *sheet;
+
+ uint32_t import_count;
+ struct content **imports;
};
/** \todo This needs moving somewhere more sane */
14 years, 2 months
r8206 jmb - /branches/jmb/ns-libcss/render/layout.c
by netsurf@semichrome.net
Author: jmb
Date: Tue Jun 30 13:58:06 2009
New Revision: 8206
URL: http://source.netsurf-browser.org?rev=8206&view=rev
Log:
Make line-height calculation use css_used_font_size()
Modified:
branches/jmb/ns-libcss/render/layout.c
Modified: branches/jmb/ns-libcss/render/layout.c
URL: http://source.netsurf-browser.org/branches/jmb/ns-libcss/render/layout.c?...
==============================================================================
--- branches/jmb/ns-libcss/render/layout.c (original)
+++ branches/jmb/ns-libcss/render/layout.c Tue Jun 30 13:58:06 2009
@@ -1728,10 +1728,11 @@
int line_height(const css_computed_style *style)
{
enum css_line_height lhtype;
- enum css_font_size fstype;
css_fixed lhvalue = 0, fsvalue = 0;
css_unit lhunit = CSS_UNIT_PX, fsunit = CSS_UNIT_PX;
- float font_len;
+ css_fixed font_len;
+ css_fixed min_font_size;
+ css_fixed line_height;
assert(style);
@@ -1746,29 +1747,27 @@
lhtype == CSS_LINE_HEIGHT_DIMENSION);
#endif
- fstype = css_computed_font_size(style, &fsvalue, &fsunit);
-
-#warning CSSport
- /** \todo Handle keyword font sizes correctly -- ideally make it so
- * layout.c never sees them. */
+ css_used_font_size(style, &fsvalue, &fsunit);
+
+ min_font_size = FDIV(FMULI(css_screen_dpi, option_font_min_size),
+ FLTTOFIX(720.0));
/* take account of minimum font size option */
- if ((font_len = FIXTOFLT(css_len2px(fsvalue, fsunit, 0))) <
- option_font_min_size * FIXTOFLT(css_screen_dpi) / 720.0)
- font_len = option_font_min_size *
- FIXTOFLT(css_screen_dpi) / 720.0;
+ if ((font_len = css_len2px(fsvalue, fsunit, 0)) < min_font_size)
+ font_len = min_font_size;
if (lhtype == CSS_LINE_HEIGHT_DIMENSION) {
if (lhunit == CSS_UNIT_PCT) {
- return FIXTOFLT(lhvalue) * font_len / 100.0;
+ line_height = FDIV(FMUL(lhvalue, font_len),
+ FLTTOFIX(100.0));
} else {
- return FIXTOINT(css_len2px(lhvalue, lhunit, style));
+ line_height = css_len2px(lhvalue, lhunit, style);
}
} else if (lhtype == CSS_LINE_HEIGHT_NUMBER) {
- return FIXTOFLT(lhvalue) * font_len;
- }
-
- return 0;
+ line_height = FMUL(lhvalue, font_len);
+ }
+
+ return FIXTOINT(line_height);
}
14 years, 2 months
r8205 jmb - /branches/jmb/ns-libcss/css/utils.c
by netsurf@semichrome.net
Author: jmb
Date: Tue Jun 30 13:57:33 2009
New Revision: 8205
URL: http://source.netsurf-browser.org?rev=8205&view=rev
Log:
Hack for percentage font sizes
Modified:
branches/jmb/ns-libcss/css/utils.c
Modified: branches/jmb/ns-libcss/css/utils.c
URL: http://source.netsurf-browser.org/branches/jmb/ns-libcss/css/utils.c?rev=...
==============================================================================
--- branches/jmb/ns-libcss/css/utils.c (original)
+++ branches/jmb/ns-libcss/css/utils.c Tue Jun 30 13:57:33 2009
@@ -3,6 +3,7 @@
#include "css/utils.h"
#include "desktop/options.h"
+#include "utils/log.h"
/** Screen DPI */
css_fixed css_screen_dpi;
@@ -131,5 +132,12 @@
option_font_size / 10);
*unit = CSS_UNIT_PT;
}
+
+#warning CSSport
+ /** \todo filthy hack for percentage sizes */
+ if (*unit == CSS_UNIT_PCT) {
+ *length = FDIVI(FMULI(*length, option_font_size / 10), 100);
+ *unit = CSS_UNIT_PT;
+ }
}
14 years, 2 months
r8204 jmb - /trunk/libcss/src/select/properties.c
by netsurf@semichrome.net
Author: jmb
Date: Tue Jun 30 12:22:13 2009
New Revision: 8204
URL: http://source.netsurf-browser.org?rev=8204&view=rev
Log:
It somewhat helps to ensure that you convert units to their external representation. Oddly enough, not doing so causes comedy breakage.
Modified:
trunk/libcss/src/select/properties.c
Modified: trunk/libcss/src/select/properties.c
URL: http://source.netsurf-browser.org/trunk/libcss/src/select/properties.c?re...
==============================================================================
--- trunk/libcss/src/select/properties.c (original)
+++ trunk/libcss/src/select/properties.c Tue Jun 30 12:22:13 2009
@@ -13,6 +13,7 @@
#include "select/propset.h"
#include "utils/utils.h"
+static css_unit to_css_unit(uint32_t u);
static css_error cascade_bg_border_color(uint32_t opv, css_style *style,
css_select_state *state,
css_error (*fun)(css_computed_style *, uint8_t, css_color));
@@ -54,12 +55,36 @@
css_error (*fun)(css_computed_style *, uint8_t,
css_computed_counter *));
+css_unit to_css_unit(uint32_t u)
+{
+ switch (u) {
+ case UNIT_PX: return CSS_UNIT_PX;
+ case UNIT_EX: return CSS_UNIT_EX;
+ case UNIT_EM: return CSS_UNIT_EM;
+ case UNIT_IN: return CSS_UNIT_IN;
+ case UNIT_CM: return CSS_UNIT_CM;
+ case UNIT_MM: return CSS_UNIT_MM;
+ case UNIT_PT: return CSS_UNIT_PT;
+ case UNIT_PC: return CSS_UNIT_PC;
+ case UNIT_PCT: return CSS_UNIT_PCT;
+ case UNIT_DEG: return CSS_UNIT_DEG;
+ case UNIT_GRAD: return CSS_UNIT_GRAD;
+ case UNIT_RAD: return CSS_UNIT_RAD;
+ case UNIT_MS: return CSS_UNIT_MS;
+ case UNIT_S: return CSS_UNIT_S;
+ case UNIT_HZ: return CSS_UNIT_HZ;
+ case UNIT_KHZ: return CSS_UNIT_KHZ;
+ }
+
+ return 0;
+}
+
css_error cascade_azimuth(uint32_t opv, css_style *style,
css_select_state *state)
{
uint16_t value = 0;
css_fixed val = 0;
- uint32_t unit = CSS_UNIT_DEG;
+ uint32_t unit = UNIT_DEG;
if (isInherit(opv) == false) {
switch (getValue(opv) & ~AZIMUTH_BEHIND) {
@@ -89,6 +114,8 @@
/** \todo azimuth behind */
}
+ unit = to_css_unit(unit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
/** \todo set computed azimuth */
}
@@ -245,8 +272,8 @@
uint16_t value = CSS_BACKGROUND_POSITION_INHERIT;
css_fixed hlength = 0;
css_fixed vlength = 0;
- uint32_t hunit = CSS_UNIT_PX;
- uint32_t vunit = CSS_UNIT_PX;
+ uint32_t hunit = UNIT_PX;
+ uint32_t vunit = UNIT_PX;
if (isInherit(opv) == false) {
value = CSS_BACKGROUND_POSITION_SET;
@@ -260,15 +287,15 @@
break;
case BACKGROUND_POSITION_HORZ_CENTER:
hlength = INTTOFIX(50);
- hunit = CSS_UNIT_PCT;
+ hunit = UNIT_PCT;
break;
case BACKGROUND_POSITION_HORZ_RIGHT:
hlength = INTTOFIX(100);
- hunit = CSS_UNIT_PCT;
+ hunit = UNIT_PCT;
break;
case BACKGROUND_POSITION_HORZ_LEFT:
hlength = INTTOFIX(0);
- hunit = CSS_UNIT_PCT;
+ hunit = UNIT_PCT;
break;
}
@@ -281,18 +308,21 @@
break;
case BACKGROUND_POSITION_VERT_CENTER:
vlength = INTTOFIX(50);
- vunit = CSS_UNIT_PCT;
+ vunit = UNIT_PCT;
break;
case BACKGROUND_POSITION_VERT_BOTTOM:
vlength = INTTOFIX(100);
- vunit = CSS_UNIT_PCT;
+ vunit = UNIT_PCT;
break;
case BACKGROUND_POSITION_VERT_TOP:
vlength = INTTOFIX(0);
- vunit = CSS_UNIT_PCT;
- break;
- }
- }
+ vunit = UNIT_PCT;
+ break;
+ }
+ }
+
+ hunit = to_css_unit(hunit);
+ vunit = to_css_unit(vunit);
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return set_background_position(state->result, value,
@@ -446,8 +476,8 @@
uint16_t value = CSS_BORDER_SPACING_INHERIT;
css_fixed hlength = 0;
css_fixed vlength = 0;
- uint32_t hunit = CSS_UNIT_PX;
- uint32_t vunit = CSS_UNIT_PX;
+ uint32_t hunit = UNIT_PX;
+ uint32_t vunit = UNIT_PX;
if (isInherit(opv) == false) {
value = CSS_BORDER_SPACING_SET;
@@ -461,6 +491,9 @@
vunit = *((uint32_t *) style->bytecode);
advance_bytecode(style, sizeof(vunit));
}
+
+ hunit = to_css_unit(hunit);
+ vunit = to_css_unit(vunit);
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return set_border_spacing(state->result, value,
@@ -1050,7 +1083,7 @@
{
uint16_t value = CSS_CLIP_INHERIT;
css_computed_clip_rect rect = { 0, 0, 0, 0,
- CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX, CSS_UNIT_PX,
+ UNIT_PX, UNIT_PX, UNIT_PX, UNIT_PX,
false, false, false, false };
if (isInherit(opv) == false) {
@@ -1095,6 +1128,11 @@
}
}
+ rect.tunit = to_css_unit(rect.tunit);
+ rect.runit = to_css_unit(rect.runit);
+ rect.bunit = to_css_unit(rect.bunit);
+ rect.lunit = to_css_unit(rect.lunit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return set_clip(state->result, value, &rect);
}
@@ -1973,7 +2011,7 @@
{
uint16_t value = 0;
css_fixed val = 0;
- uint32_t unit = CSS_UNIT_DEG;
+ uint32_t unit = UNIT_DEG;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -1995,6 +2033,8 @@
break;
}
}
+
+ unit = to_css_unit(unit);
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
/** \todo set computed elevation */
@@ -2309,7 +2349,7 @@
{
uint16_t value = CSS_FONT_SIZE_INHERIT;
css_fixed size = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -2351,6 +2391,8 @@
break;
}
}
+
+ unit = to_css_unit(unit);
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return set_font_size(state->result, value, size, unit);
@@ -2678,7 +2720,7 @@
{
uint16_t value = CSS_LINE_HEIGHT_INHERIT;
css_fixed val = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -2700,6 +2742,8 @@
}
}
+ unit = to_css_unit(unit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return set_line_height(state->result, value, val, unit);
}
@@ -3759,7 +3803,7 @@
{
uint16_t value = 0;
css_fixed freq = 0;
- uint32_t unit = CSS_UNIT_HZ;
+ uint32_t unit = UNIT_HZ;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -3780,6 +3824,8 @@
break;
}
}
+
+ unit = to_css_unit(unit);
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
/** \todo pitch */
@@ -4777,7 +4823,7 @@
{
uint16_t value = CSS_VERTICAL_ALIGN_INHERIT;
css_fixed length = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -4815,6 +4861,8 @@
break;
}
}
+
+ unit = to_css_unit(unit);
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return set_vertical_align(state->result, value, length, unit);
@@ -5027,7 +5075,7 @@
{
uint16_t value = 0;
css_fixed val = 0;
- uint32_t unit = CSS_UNIT_PCT;
+ uint32_t unit = UNIT_PCT;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -5056,6 +5104,8 @@
}
}
+ unit = to_css_unit(unit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
/** \todo volume */
}
@@ -5426,7 +5476,7 @@
{
uint16_t value = CSS_BORDER_WIDTH_INHERIT;
css_fixed length = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -5449,6 +5499,8 @@
}
}
+ unit = to_css_unit(unit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return fun(state->result, value, length, unit);
}
@@ -5463,7 +5515,7 @@
{
uint16_t value = CSS_BOTTOM_INHERIT;
css_fixed length = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -5480,6 +5532,8 @@
}
}
+ unit = to_css_unit(unit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return fun(state->result, value, length, unit);
}
@@ -5494,7 +5548,7 @@
{
uint16_t value = CSS_LETTER_SPACING_INHERIT;
css_fixed length = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -5511,6 +5565,8 @@
}
}
+ unit = to_css_unit(unit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return fun(state->result, value, length, unit);
}
@@ -5525,7 +5581,7 @@
{
uint16_t value = CSS_MAX_HEIGHT_INHERIT;
css_fixed length = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
switch (getValue(opv)) {
@@ -5542,6 +5598,8 @@
}
}
+ unit = to_css_unit(unit);
+
if (outranks_existing(getOpcode(opv), isImportant(opv), state)) {
return fun(state->result, value, length, unit);
}
@@ -5556,7 +5614,7 @@
{
uint16_t value = CSS_MIN_HEIGHT_INHERIT;
css_fixed length = 0;
- uint32_t unit = CSS_UNIT_PX;
+ uint32_t unit = UNIT_PX;
if (isInherit(opv) == false) {
value = CSS_MIN_HEIGHT_SET;
@@ -5565,6 +5623,8 @@
unit = *((uint32_t *) style->bytecode);
advance_bytecode(style, sizeof(unit));
}
+
+ unit = to_css_unit(unit);
/** \todo lose fun != NULL once all properties have set routines */
if (fun != NULL && outranks_existing(getOpcode(opv),
14 years, 2 months