stop system colours being anything to do with frontends

This commit is contained in:
Vincent Sanders 2014-01-10 14:32:29 +00:00
parent b415c2f9ff
commit 277bcec7c6
9 changed files with 87 additions and 44 deletions

View File

@ -26,7 +26,7 @@
#include "content/hlcache.h" #include "content/hlcache.h"
#include "css/css.h" #include "css/css.h"
#include "css/internal.h" #include "css/internal.h"
#include "desktop/gui.h" #include "desktop/system_colour.h"
#include "render/html.h" #include "render/html.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "utils/http.h" #include "utils/http.h"
@ -221,7 +221,7 @@ static nserror nscss_create_css_data(struct content_css_data *c,
params.resolve_pw = NULL; params.resolve_pw = NULL;
params.import = nscss_handle_import; params.import = nscss_handle_import;
params.import_pw = c; params.import_pw = c;
params.color = gui_system_colour; params.color = ns_system_colour;
params.color_pw = NULL; params.color_pw = NULL;
params.font = NULL; params.font = NULL;
params.font_pw = NULL; params.font_pw = NULL;
@ -767,7 +767,7 @@ css_error nscss_register_import(struct content_css_data *c,
params.resolve_pw = NULL; params.resolve_pw = NULL;
params.import = NULL; params.import = NULL;
params.import_pw = NULL; params.import_pw = NULL;
params.color = gui_system_colour; params.color = ns_system_colour;
params.color_pw = NULL; params.color_pw = NULL;
params.font = NULL; params.font = NULL;
params.font_pw = NULL; params.font_pw = NULL;

View File

@ -26,7 +26,7 @@
#include "css/internal.h" #include "css/internal.h"
#include "css/select.h" #include "css/select.h"
#include "css/utils.h" #include "css/utils.h"
#include "desktop/gui.h" #include "desktop/system_colour.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "utils/corestrings.h" #include "utils/corestrings.h"
#include "utils/log.h" #include "utils/log.h"
@ -185,7 +185,7 @@ css_stylesheet *nscss_create_inline_style(const uint8_t *data, size_t len,
params.resolve_pw = NULL; params.resolve_pw = NULL;
params.import = NULL; params.import = NULL;
params.import_pw = NULL; params.import_pw = NULL;
params.color = gui_system_colour; params.color = ns_system_colour;
params.color_pw = NULL; params.color_pw = NULL;
params.font = NULL; params.font = NULL;
params.font_pw = NULL; params.font_pw = NULL;

View File

@ -169,13 +169,4 @@ void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
*/ */
nsurl* gui_get_resource_url(const char *path); nsurl* gui_get_resource_url(const char *path);
/** css callback to obtain named system colours from a frontend. */
css_error gui_system_colour(void *pw, lwc_string *name, css_color *color);
/** Obtain a named system colour from a frontend. */
colour gui_system_colour_char(const char *name);
bool gui_system_colour_init(void);
void gui_system_colour_finalize(void);
#endif #endif

View File

@ -39,6 +39,7 @@
#include "desktop/netsurf.h" #include "desktop/netsurf.h"
#include "desktop/401login.h" #include "desktop/401login.h"
#include "desktop/browser.h" #include "desktop/browser.h"
#include "desktop/system_colour.h"
#include "desktop/gui.h" #include "desktop/gui.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#include "desktop/searchweb.h" #include "desktop/searchweb.h"
@ -211,7 +212,9 @@ nserror netsurf_init(const char *messages)
hlcache_initialise(&hlcache_parameters); hlcache_initialise(&hlcache_parameters);
/* Initialize system colours */ /* Initialize system colours */
gui_system_colour_init(); error = ns_system_colour_init();
if (error != NSERROR_OK)
return error;
js_initialise(); js_initialise();
@ -270,7 +273,7 @@ void netsurf_exit(void)
urldb_destroy(); urldb_destroy();
LOG(("Destroying System colours")); LOG(("Destroying System colours"));
gui_system_colour_finalize(); ns_system_colour_finalize();
corestrings_fini(); corestrings_fini();
LOG(("Remaining lwc strings:")); LOG(("Remaining lwc strings:"));

View File

@ -28,8 +28,14 @@ extern const char * const netsurf_version;
extern const int netsurf_version_major; extern const int netsurf_version_major;
extern const int netsurf_version_minor; extern const int netsurf_version_minor;
/** Initialise netsurf core */
nserror netsurf_init(const char *messages); nserror netsurf_init(const char *messages);
extern void netsurf_exit(void);
/** Run primary event loop */
extern int netsurf_main_loop(void); extern int netsurf_main_loop(void);
/** finalise NetSurf core */
extern void netsurf_exit(void);
#endif #endif

View File

@ -25,6 +25,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "desktop/system_colour.h"
#include "desktop/mouse.h" #include "desktop/mouse.h"
#include "desktop/scrollbar.h" #include "desktop/scrollbar.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
@ -190,9 +191,9 @@ bool scrollbar_redraw(struct scrollbar *s, int x, int y,
int v[6]; /* array of triangle vertices */ int v[6]; /* array of triangle vertices */
int x0, y0, x1, y1; int x0, y0, x1, y1;
colour bg_fill_colour = gui_system_colour_char("Scrollbar"); colour bg_fill_colour = ns_system_colour_char("Scrollbar");
colour fg_fill_colour = gui_system_colour_char("ButtonFace"); colour fg_fill_colour = ns_system_colour_char("ButtonFace");
colour arrow_fill_colour = gui_system_colour_char("ButtonText"); colour arrow_fill_colour = ns_system_colour_char("ButtonText");
plot_style_t bg_fill_style = { plot_style_t bg_fill_style = {
.fill_type = PLOT_OP_TYPE_SOLID, .fill_type = PLOT_OP_TYPE_SOLID,

View File

@ -21,45 +21,47 @@
* *
*/ */
#include <string.h>
#include "utils/config.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "utils/log.h" #include "utils/log.h"
#include "css/utils.h" #include "css/utils.h"
#include "desktop/gui.h" #include "desktop/system_colour.h"
#include "utils/nsoption.h" #include "utils/nsoption.h"
#define colour_list_len ((NSOPTION_SYS_COLOUR_END - NSOPTION_SYS_COLOUR_START) + 1) #define colour_list_len ((NSOPTION_SYS_COLOUR_END - NSOPTION_SYS_COLOUR_START) + 1)
static lwc_string *colour_list[colour_list_len]; static lwc_string *colour_list[colour_list_len];
static lwc_string **gui_system_colour_pw = NULL; static lwc_string **ns_system_colour_pw = NULL;
bool gui_system_colour_init(void) nserror ns_system_colour_init(void)
{ {
unsigned int ccount; unsigned int ccount;
if (gui_system_colour_pw != NULL) if (ns_system_colour_pw != NULL)
return false; return NSERROR_INIT_FAILED;
/* Intern colour strings */ /* Intern colour strings */
for (ccount = 0; ccount < colour_list_len; ccount++) { for (ccount = 0; ccount < colour_list_len; ccount++) {
struct nsoption_s *opt; struct nsoption_s *opt;
opt = &nsoptions[ccount + NSOPTION_SYS_COLOUR_START]; opt = &nsoptions[ccount + NSOPTION_SYS_COLOUR_START];
if (lwc_intern_string(opt->key + SLEN("sys_colour_"), if (lwc_intern_string(opt->key + SLEN("sys_colour_"),
opt->key_len - SLEN("sys_colour_"), opt->key_len - SLEN("sys_colour_"),
&(colour_list[ccount])) != lwc_error_ok) { &(colour_list[ccount])) != lwc_error_ok) {
return false; return NSERROR_NOMEM;
} }
} }
gui_system_colour_pw = colour_list; ns_system_colour_pw = colour_list;
return true; return NSERROR_OK;
} }
void gui_system_colour_finalize(void) void ns_system_colour_finalize(void)
{ {
unsigned int ccount; unsigned int ccount;
@ -68,7 +70,7 @@ void gui_system_colour_finalize(void)
} }
} }
colour gui_system_colour_char(const char *name) colour ns_system_colour_char(const char *name)
{ {
colour ret = 0; colour ret = 0;
unsigned int ccount; unsigned int ccount;
@ -83,19 +85,19 @@ colour gui_system_colour_char(const char *name)
return ret; return ret;
} }
css_error gui_system_colour(void *pw, lwc_string *name, css_color *colour) css_error ns_system_colour(void *pw, lwc_string *name, css_color *colour)
{ {
unsigned int ccount; unsigned int ccount;
bool match; bool match;
for (ccount = 0; ccount < colour_list_len; ccount++) { for (ccount = 0; ccount < colour_list_len; ccount++) {
if (lwc_string_caseless_isequal(name, if (lwc_string_caseless_isequal(name,
colour_list[ccount], colour_list[ccount],
&match) == lwc_error_ok && match) { &match) == lwc_error_ok && match) {
*colour = ns_color_to_nscss(nsoptions[ccount + NSOPTION_SYS_COLOUR_START].value.c); *colour = ns_color_to_nscss(nsoptions[ccount + NSOPTION_SYS_COLOUR_START].value.c);
return CSS_OK; return CSS_OK;
} }
} }
return CSS_INVALID; return CSS_INVALID;
} }

40
desktop/system_colour.h Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright 2014 vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Interface to system colour values.
*/
#ifndef _NETSURF_DESKTOP_SYSTEM_COLOUR_H_
#define _NETSURF_DESKTOP_SYSTEM_COLOUR_H_
#include <libcss/libcss.h>
#include "utils/errors.h"
#include "desktop/plot_style.h"
/** css callback to obtain named system colours. */
css_error ns_system_colour(void *pw, lwc_string *name, css_color *color);
/** Obtain a named system colour from a frontend. */
colour ns_system_colour_char(const char *name);
nserror ns_system_colour_init(void);
void ns_system_colour_finalize(void);
#endif

View File

@ -21,7 +21,7 @@
*/ */
#include "css/utils.h" #include "css/utils.h"
#include "desktop/gui.h" #include "desktop/system_colour.h"
#include "desktop/knockout.h" #include "desktop/knockout.h"
#include "desktop/plotters.h" #include "desktop/plotters.h"
#include "desktop/textarea.h" #include "desktop/textarea.h"
@ -3466,15 +3466,15 @@ static void treeview_init_plot_styles(int font_pt_size)
plot_style_even.bg.stroke_width = 0; plot_style_even.bg.stroke_width = 0;
plot_style_even.bg.stroke_colour = 0; plot_style_even.bg.stroke_colour = 0;
plot_style_even.bg.fill_type = PLOT_OP_TYPE_SOLID; plot_style_even.bg.fill_type = PLOT_OP_TYPE_SOLID;
plot_style_even.bg.fill_colour = gui_system_colour_char("Window"); plot_style_even.bg.fill_colour = ns_system_colour_char("Window");
/* Text colour */ /* Text colour */
plot_style_even.text.family = PLOT_FONT_FAMILY_SANS_SERIF; 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 * FONT_SIZE_SCALE;
plot_style_even.text.weight = 400; plot_style_even.text.weight = 400;
plot_style_even.text.flags = FONTF_NONE; plot_style_even.text.flags = FONTF_NONE;
plot_style_even.text.foreground = gui_system_colour_char("WindowText"); plot_style_even.text.foreground = ns_system_colour_char("WindowText");
plot_style_even.text.background = gui_system_colour_char("Window"); plot_style_even.text.background = ns_system_colour_char("Window");
/* Entry field text colour */ /* Entry field text colour */
plot_style_even.itext = plot_style_even.text; plot_style_even.itext = plot_style_even.text;
@ -3484,13 +3484,13 @@ static void treeview_init_plot_styles(int font_pt_size)
/* Selected background colour */ /* Selected background colour */
plot_style_even.sbg = plot_style_even.bg; plot_style_even.sbg = plot_style_even.bg;
plot_style_even.sbg.fill_colour = gui_system_colour_char("Highlight"); plot_style_even.sbg.fill_colour = ns_system_colour_char("Highlight");
/* Selected text colour */ /* Selected text colour */
plot_style_even.stext = plot_style_even.text; plot_style_even.stext = plot_style_even.text;
plot_style_even.stext.foreground = plot_style_even.stext.foreground =
gui_system_colour_char("HighlightText"); ns_system_colour_char("HighlightText");
plot_style_even.stext.background = gui_system_colour_char("Highlight"); plot_style_even.stext.background = ns_system_colour_char("Highlight");
/* Selected entry field text colour */ /* Selected entry field text colour */
plot_style_even.sitext = plot_style_even.stext; plot_style_even.sitext = plot_style_even.stext;