summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2016-08-10 18:36:41 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2016-08-10 18:57:36 +0100
commit9aecf47408f22f4f0a01e41648f25e1a7307b332 (patch)
tree4a351d67f53edb81096bd8720b79b07179919532 /desktop
parentb63443b243bec435c1650aef2068299674b2a209 (diff)
downloadnetsurf-9aecf47408f22f4f0a01e41648f25e1a7307b332.tar.gz
netsurf-9aecf47408f22f4f0a01e41648f25e1a7307b332.tar.bz2
Treeview: Rationalise initialisation and finalisation.
Previously the expected behaviour for front ends using the correct API for hotlist, global history, cookie manager, and ssl cert viewer was that the front end would initialise the treeview module on startup and finalise it on application exit. However, this meant that the front ends had to include the core treeview header, which they didn't otherwise need. Since the tree module provided access to the new treeview utilities through the old tree API, and was used by front ends with no changes for the new treeview API, the tree layer refcounted initialisations of treeview-based widgets, and only called the underlying treeview init/fini functions when needed. This change moves that refcounting into the treeview module. Now the hotlist, global history, cookie manager, and ssl cert viewer widgets call call treeview init/fini as part of their own initialisation and finalisation. This means that front ends using the correct APIs for treeview-based widgets don't need to know anything about the underlying treeview, and the tree module compatibility layer has had its treeview refcounting removed. Finally, the treeview_init function took a font size parameter. Now it does not and lit gets font size from config. We probably want to add a new `treeview_font_size` option to nsoptions, and have differnent defaults on different platforms. 12pt on RISC OS, and 11pt elsewhere, most likely.
Diffstat (limited to 'desktop')
-rw-r--r--desktop/cookie_manager.c10
-rw-r--r--desktop/global_history.c10
-rw-r--r--desktop/hotlist.c10
-rw-r--r--desktop/sslcert_viewer.c10
-rw-r--r--desktop/tree.c10
-rw-r--r--desktop/treeview.c42
-rw-r--r--desktop/treeview.h3
7 files changed, 72 insertions, 23 deletions
diff --git a/desktop/cookie_manager.c b/desktop/cookie_manager.c
index 082a14a75..b0c48a7fc 100644
--- a/desktop/cookie_manager.c
+++ b/desktop/cookie_manager.c
@@ -756,6 +756,11 @@ nserror cookie_manager_init(struct core_window_callback_table *cw_t,
{
nserror err;
+ err = treeview_init();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Generating cookie manager data");
/* Init. cookie manager treeview entry fields */
@@ -822,6 +827,11 @@ nserror cookie_manager_fini(void)
if (cm_ctx.values[i].value != NULL)
free((void *) cm_ctx.values[i].value);
+ err = treeview_fini();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Finalised cookie manager");
return err;
diff --git a/desktop/global_history.c b/desktop/global_history.c
index d60874c67..b6f488228 100644
--- a/desktop/global_history.c
+++ b/desktop/global_history.c
@@ -724,6 +724,11 @@ nserror global_history_init(struct core_window_callback_table *cw_t,
{
nserror err;
+ err = treeview_init();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Loading global history");
/* Init. global history treeview time */
@@ -804,6 +809,11 @@ nserror global_history_fini(void)
if (gh_ctx.fields[i].field != NULL)
lwc_string_unref(gh_ctx.fields[i].field);
+ err = treeview_fini();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Finalised global history");
return err;
diff --git a/desktop/hotlist.c b/desktop/hotlist.c
index cce69be8e..e344b3b57 100644
--- a/desktop/hotlist.c
+++ b/desktop/hotlist.c
@@ -1232,6 +1232,11 @@ nserror hotlist_init(struct core_window_callback_table *cw_t,
{
nserror err;
+ err = treeview_init();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Loading hotlist");
hl_ctx.tree = NULL;
@@ -1298,6 +1303,11 @@ nserror hotlist_fini(const char *path)
if (hl_ctx.fields[i].field != NULL)
lwc_string_unref(hl_ctx.fields[i].field);
+ err = treeview_fini();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Finalised hotlist");
return err;
diff --git a/desktop/sslcert_viewer.c b/desktop/sslcert_viewer.c
index 93d6919e6..09a281c1c 100644
--- a/desktop/sslcert_viewer.c
+++ b/desktop/sslcert_viewer.c
@@ -353,6 +353,11 @@ nserror sslcert_viewer_init(struct core_window_callback_table *cw_t,
assert(ssl_d != NULL);
+ err = treeview_init();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Building certificate viewer");
/* Init. certificate chain treeview entry fields */
@@ -427,6 +432,11 @@ nserror sslcert_viewer_fini(struct sslcert_session_data *ssl_d)
/* Destroy the sslcert_session_data */
sslcert_cleanup_session(ssl_d);
+ err = treeview_fini();
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
LOG("Finalised ssl certificate viewer");
return err;
diff --git a/desktop/tree.c b/desktop/tree.c
index bfe8e9874..a5c97c33c 100644
--- a/desktop/tree.c
+++ b/desktop/tree.c
@@ -55,7 +55,6 @@ struct tree {
struct sslcert_session_data *ssl_current_session = NULL;
const char *tree_hotlist_path = NULL;
-int treeview_inits;
static void treeview_test_redraw_request(struct core_window *cw,
const struct rect *r)
@@ -128,11 +127,6 @@ static bool treeview_test_init(struct tree *tree)
{
nserror err;
- treeview_inits++;
-
- if (treeview_inits == 1)
- treeview_init(0);
-
switch (tree->flags) {
case TREE_COOKIES:
assert(ssl_current_session == NULL &&
@@ -195,10 +189,6 @@ static bool treeview_test_fini(struct tree *tree)
break;
}
- if (treeview_inits == 1)
- treeview_fini();
- treeview_inits--;
-
return true;
}
diff --git a/desktop/treeview.c b/desktop/treeview.c
index f2af5e8a1..5e4ceed12 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -24,6 +24,7 @@
#include "utils/log.h"
#include "utils/nsurl.h"
+#include "utils/nsoption.h"
#include "netsurf/bitmap.h"
#include "netsurf/content.h"
#include "netsurf/plotters.h"
@@ -44,7 +45,7 @@
#define REDRAW_MAX 8000
struct treeview_globals {
- bool initialised;
+ unsigned initialised;
int line_height;
int furniture_width;
int step_width;
@@ -3588,7 +3589,7 @@ static void treeview_init_plot_styles(int font_pt_size)
/* Text colour */
plot_style_even.text.family = PLOT_FONT_FAMILY_SANS_SERIF;
- plot_style_even.text.size = font_pt_size * FONT_SIZE_SCALE;
+ plot_style_even.text.size = font_pt_size;
plot_style_even.text.weight = 400;
plot_style_even.text.flags = FONTF_NONE;
plot_style_even.text.foreground = ns_system_colour_char("WindowText");
@@ -3948,23 +3949,33 @@ static nserror treeview_init_furniture(void)
/* Exported interface, documented in treeview.h */
-nserror treeview_init(int font_pt_size)
+nserror treeview_init(void)
{
- int font_px_size;
+ long long font_px_size;
+ long long font_pt_size;
nserror err;
- if (tree_g.initialised == true)
+ if (tree_g.initialised > 0) {
+ tree_g.initialised++;
return NSERROR_OK;
+ }
LOG("Initialising treeview module");
- if (font_pt_size <= 0)
- font_pt_size = 11;
+ /* TODO: Should we add an extra `treeview_font_size` option for
+ * treeviews instead of reusing the html rendering default
+ * font size?
+ */
+ font_pt_size = nsoption_int(font_size);
+ if (font_pt_size <= 0) {
+ font_pt_size = 11 * 10;
+ }
- font_px_size = (font_pt_size * FIXTOINT(nscss_screen_dpi) + 36) / 72;
+ font_px_size = (font_pt_size * FIXTOINT(nscss_screen_dpi) /
+ 10 + 36) / 72;
tree_g.line_height = (font_px_size * 8 + 3) / 6;
- treeview_init_plot_styles(font_pt_size);
+ treeview_init_plot_styles(font_pt_size * FONT_SIZE_SCALE / 10);
treeview_init_resources();
err = treeview_init_furniture();
if (err != NSERROR_OK)
@@ -3976,7 +3987,7 @@ nserror treeview_init(int font_pt_size)
tree_g.icon_step = 23;
tree_g.move_offset = 18;
- tree_g.initialised = true;
+ tree_g.initialised++;
LOG("Initialised treeview module");
@@ -3989,6 +4000,15 @@ nserror treeview_fini(void)
{
int i;
+ if (tree_g.initialised > 1) {
+ tree_g.initialised--;
+ return NSERROR_OK;
+
+ } else if (tree_g.initialised == 0) {
+ LOG("Warning: tried to finalise uninitialised treeview module");
+ return NSERROR_OK;
+ }
+
LOG("Finalising treeview module");
for (i = 0; i < TREE_RES_LAST; i++) {
@@ -4004,7 +4024,7 @@ nserror treeview_fini(void)
guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_CONTRACT].bmp);
guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_CONTRACT].sel);
- tree_g.initialised = false;
+ tree_g.initialised--;
LOG("Finalised treeview module");
diff --git a/desktop/treeview.h b/desktop/treeview.h
index 25349ad36..abe0e568d 100644
--- a/desktop/treeview.h
+++ b/desktop/treeview.h
@@ -112,10 +112,9 @@ struct treeview_callback_table {
/**
* Prepare treeview module for treeview usage
*
- * \param font_pt_size Treeview text size in pt. Set to <= 0 for default.
* \return NSERROR_OK on success, appropriate error otherwise
*/
-nserror treeview_init(int font_pt_size);
+nserror treeview_init(void);
/**
* Finalise the treeview module (all treeviews must have been destroyed first)