Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/9062ae3c7073ea354e688755b407bb91ac0e8ade
...commit
http://git.netsurf-browser.org/netsurf.git/commit/9062ae3c7073ea354e688755b407bb91ac0e8ade
...tree
http://git.netsurf-browser.org/netsurf.git/tree/9062ae3c7073ea354e688755b407bb91ac0e8ade
The branch, master has been updated
via 9062ae3c7073ea354e688755b407bb91ac0e8ade (commit)
via 66c069816a33158b013d138d3d20228edcf6850d (commit)
via 0e4f09db0fd92c6fc07c7e26c53d78124184b937 (commit)
via 7a3f86494049fcfddaf00331d8bdbc746b4bbecb (commit)
via 1149a1304d56a0fe758eba5686b156f5006f16f8 (commit)
via 4b2697c989e6bb33f60ca2b53ac1dfefaa08fc04 (commit)
via c32e1bb340d2d40d0a5b61e37e6fd55f84953633 (commit)
via 3940918b6830aa8273d0860d5d1d49706f969d3e (commit)
via 9198c9958afedc8104858979ec949c72933cbf91 (commit)
via 8da6252f5024aa1de3d4d9018d2ff32f96d22cd8 (commit)
via a39b651620272d240c40a9ff056eb50a758350f7 (commit)
via d23a7b4c8ffda7448bdb05591655954655a3cfe0 (commit)
via 475d397b8c3aa5ca672b7ec984a41302449b7727 (commit)
via 6783deba4e209461fd8105b9b46dbcacefed6b6f (commit)
from 8a834918e30cd1924b2a3a4840a94445d55b5965 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=9062ae3c7073ea354e688755b407bb91ac0e8ade
commit 9062ae3c7073ea354e688755b407bb91ac0e8ade
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
GTK: Page info: Change crtvrfy to pi throughout.
diff --git a/frontends/gtk/page_info.c b/frontends/gtk/page_info.c
index 1401fdc..2892788 100644
--- a/frontends/gtk/page_info.c
+++ b/frontends/gtk/page_info.c
@@ -41,7 +41,7 @@
/**
* GTK certificate viewing window context
*/
-struct nsgtk_crtvrfy_window {
+struct nsgtk_pi_window {
/** GTK core window context */
struct nsgtk_corewindow core;
/** GTK builder for window */
@@ -56,46 +56,46 @@ struct nsgtk_crtvrfy_window {
/**
* destroy a previously created certificate view
*/
-static nserror nsgtk_crtvrfy_destroy(struct nsgtk_crtvrfy_window *crtvrfy_win)
+static nserror nsgtk_pi_destroy(struct nsgtk_pi_window *pi_win)
{
nserror res;
- res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+ res = sslcert_viewer_fini(pi_win->ssl_data);
if (res == NSERROR_OK) {
- res = nsgtk_corewindow_fini(&crtvrfy_win->core);
- gtk_widget_destroy(GTK_WIDGET(crtvrfy_win->dlg));
- g_object_unref(G_OBJECT(crtvrfy_win->builder));
- free(crtvrfy_win);
+ res = nsgtk_corewindow_fini(&pi_win->core);
+ gtk_widget_destroy(GTK_WIDGET(pi_win->dlg));
+ g_object_unref(G_OBJECT(pi_win->builder));
+ free(pi_win);
}
return res;
}
static void
-nsgtk_crtvrfy_accept(GtkButton *w, gpointer data)
+nsgtk_pi_accept(GtkButton *w, gpointer data)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)data;
+ struct nsgtk_pi_window *pi_win;
+ pi_win = (struct nsgtk_pi_window *)data;
- sslcert_viewer_accept(crtvrfy_win->ssl_data);
+ sslcert_viewer_accept(pi_win->ssl_data);
- nsgtk_crtvrfy_destroy(crtvrfy_win);
+ nsgtk_pi_destroy(pi_win);
}
static void
-nsgtk_crtvrfy_reject(GtkWidget *w, gpointer data)
+nsgtk_pi_reject(GtkWidget *w, gpointer data)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)data;
+ struct nsgtk_pi_window *pi_win;
+ pi_win = (struct nsgtk_pi_window *)data;
- sslcert_viewer_reject(crtvrfy_win->ssl_data);
+ sslcert_viewer_reject(pi_win->ssl_data);
- nsgtk_crtvrfy_destroy(crtvrfy_win);
+ nsgtk_pi_destroy(pi_win);
}
static gboolean
-nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
+nsgtk_pi_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
{
- nsgtk_crtvrfy_reject(w, data);
+ nsgtk_pi_reject(w, data);
return FALSE;
}
@@ -109,15 +109,15 @@ nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent
*event, gpointer data)
* \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
-nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
+nsgtk_pi_mouse(struct nsgtk_corewindow *nsgtk_cw,
browser_mouse_state mouse_state,
int x, int y)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
+ struct nsgtk_pi_window *pi_win;
/* technically degenerate container of */
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw;
+ pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
- sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
+ sslcert_viewer_mouse_action(pi_win->ssl_data, mouse_state, x, y);
return NSERROR_OK;
}
@@ -130,14 +130,14 @@ nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
* \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
-nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
+nsgtk_pi_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
+ struct nsgtk_pi_window *pi_win;
/* technically degenerate container of */
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw;
+ pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
- if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+ if (sslcert_viewer_keypress(pi_win->ssl_data, nskey)) {
return NSERROR_OK;
}
return NSERROR_NOT_IMPLEMENTED;
@@ -151,19 +151,19 @@ nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw,
uint32_t nskey)
* \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
-nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
+nsgtk_pi_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
{
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &nsgtk_plotters
};
- struct nsgtk_crtvrfy_window *crtvrfy_win;
+ struct nsgtk_pi_window *pi_win;
/* technically degenerate container of */
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw;
+ pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
- sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx);
+ sslcert_viewer_redraw(pi_win->ssl_data, 0, 0, r, &ctx);
return NSERROR_OK;
}
@@ -176,7 +176,7 @@ static nserror dummy_cb(bool proceed, void *pw)
/* exported interface documented in gtk/page_info.h */
nserror nsgtk_page_info(struct browser_window *bw)
{
- struct nsgtk_crtvrfy_window *ncwin;
+ struct nsgtk_pi_window *ncwin;
nserror res;
struct cert_chain *chain;
@@ -189,7 +189,7 @@ nserror nsgtk_page_info(struct browser_window *bw)
}
url = browser_window_access_url(bw);
- ncwin = malloc(sizeof(struct nsgtk_crtvrfy_window));
+ ncwin = malloc(sizeof(struct nsgtk_pi_window));
if (ncwin == NULL) {
return NSERROR_NOMEM;
}
@@ -219,27 +219,27 @@ nserror nsgtk_page_info(struct browser_window *bw)
/* make the delete event call our destructor */
g_signal_connect(G_OBJECT(ncwin->dlg),
"delete_event",
- G_CALLBACK(nsgtk_crtvrfy_delete_event),
+ G_CALLBACK(nsgtk_pi_delete_event),
ncwin);
/* accept button */
g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder,
"sslaccept")),
"clicked",
- G_CALLBACK(nsgtk_crtvrfy_accept),
+ G_CALLBACK(nsgtk_pi_accept),
ncwin);
/* reject button */
g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder,
"sslreject")),
"clicked",
- G_CALLBACK(nsgtk_crtvrfy_reject),
+ G_CALLBACK(nsgtk_pi_reject),
ncwin);
/* initialise GTK core window */
- ncwin->core.draw = nsgtk_crtvrfy_draw;
- ncwin->core.key = nsgtk_crtvrfy_key;
- ncwin->core.mouse = nsgtk_crtvrfy_mouse;
+ ncwin->core.draw = nsgtk_pi_draw;
+ ncwin->core.key = nsgtk_pi_key;
+ ncwin->core.mouse = nsgtk_pi_mouse;
res = nsgtk_corewindow_init(&ncwin->core);
if (res != NSERROR_OK) {
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=66c069816a33158b013d138d3d20228edcf6850d
commit 66c069816a33158b013d138d3d20228edcf6850d
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
NetSurf: Init/fini the page-info module on browser startup/quit.
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index e3babd8..7577e1f 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -49,6 +49,7 @@
#include "netsurf/browser_window.h"
#include "desktop/system_colour.h"
+#include "desktop/page-info.h"
#include "desktop/searchweb.h"
#include "netsurf/misc.h"
#include "desktop/gui_internal.h"
@@ -206,6 +207,11 @@ nserror netsurf_init(const char *store_path)
js_initialise();
+ ret = page_info_init();
+ if (ret != NSERROR_OK) {
+ return ret;
+ }
+
return NSERROR_OK;
}
@@ -220,7 +226,10 @@ void netsurf_exit(void)
NSLOG(netsurf, INFO, "Closing GUI");
guit->misc->quit();
-
+
+ NSLOG(netsurf, INFO, "Finalising page-info module");
+ page_info_fini();
+
NSLOG(netsurf, INFO, "Finalising JavaScript");
js_finalise();
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=0e4f09db0fd92c6fc07c7e26c53d78124184b937
commit 0e4f09db0fd92c6fc07c7e26c53d78124184b937
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Buildsystem: Build the page-info module.
diff --git a/desktop/Makefile b/desktop/Makefile
index 0d88b2b..3e40449 100644
--- a/desktop/Makefile
+++ b/desktop/Makefile
@@ -3,7 +3,7 @@
S_DESKTOP := cookie_manager.c knockout.c hotlist.c mouse.c \
plot_style.c print.c search.c searchweb.c scrollbar.c \
sslcert_viewer.c textarea.c version.c system_colour.c \
- local_history.c global_history.c treeview.c
+ local_history.c global_history.c treeview.c page-info.c
S_DESKTOP := $(addprefix desktop/,$(S_DESKTOP))
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=7a3f86494049fcfddaf00331d8bdbc746b4bbecb
commit 7a3f86494049fcfddaf00331d8bdbc746b4bbecb
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Page info: Add core window size getter, and stub for keypresses.
diff --git a/desktop/page-info.c b/desktop/page-info.c
index bbbbbb5..51784c4 100644
--- a/desktop/page-info.c
+++ b/desktop/page-info.c
@@ -766,3 +766,23 @@ nserror page_info_mouse_action(
return NSERROR_OK;
}
+
+/* Exported interface documented in desktop/page_info.h */
+bool page_info_keypress(
+ struct page_info *pi,
+ int32_t key)
+{
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_get_size(
+ struct page_info *pi,
+ int *width,
+ int *height)
+{
+ *width = pi->width;
+ *height = pi->height;
+
+ return NSERROR_OK;
+}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=1149a1304d56a0fe758eba5686b156f5006f16f8
commit 1149a1304d56a0fe758eba5686b156f5006f16f8
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Page info: Implement mouse action handling.
diff --git a/desktop/page-info.c b/desktop/page-info.c
index c7827f3..bbbbbb5 100644
--- a/desktop/page-info.c
+++ b/desktop/page-info.c
@@ -675,3 +675,94 @@ cleanup:
return NSERROR_OK;
}
+
+/**
+ * Handle any clicks on an item.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] mouse The current mouse state.
+ * \param[in] clicked The page info window entry to consider clicks on.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__handle_item_click(
+ struct page_info *pi,
+ enum browser_mouse_state mouse,
+ enum pi_entry clicked)
+{
+ nserror err;
+
+ if (!(mouse & BROWSER_MOUSE_CLICK_1)) {
+ return NSERROR_OK;
+ }
+
+ switch (clicked) {
+ case PI_ENTRY_CERT:
+ err = browser_window_show_certificates(pi->bw);
+ break;
+ case PI_ENTRY_COOKIES:
+ err = browser_window_show_cookies(pi->bw);
+ break;
+ default:
+ err = NSERROR_OK;
+ break;
+ }
+
+ return err;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_mouse_action(
+ struct page_info *pi,
+ enum browser_mouse_state mouse,
+ int x,
+ int y)
+{
+ int cur_y = 0;
+ nserror err;
+
+ cur_y += pi->window_padding;
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ struct page_info_entry *entry = pi->entries + i;
+ bool hovering = false;
+ int height;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ cur_y += entry->text.height;
+ cur_y += entry->text.padding_bottom;
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ height = entry->item.padding_top +
+ entry->item.item.height +
+ entry->item.padding_bottom;
+
+ if (y >= cur_y && y < cur_y + height) {
+ hovering = true;
+ err = page_info__handle_item_click(
+ pi, mouse, i);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ }
+ if (entry->item.hover != hovering) {
+ int w, h;
+ struct rect r = {
+ .x0 = 0,
+ .y0 = cur_y,
+ .y1 = cur_y + height,
+ };
+ pi->cw_t->get_window_dimensions(
+ pi->cw_h, &w, &h);
+ r.x1 = (pi->width > w) ? pi->width : w;
+
+ pi->cw_t->invalidate(pi->cw_h, &r);
+ }
+ entry->item.hover = hovering;
+ cur_y += height;
+ break;
+ }
+ }
+
+ return NSERROR_OK;
+}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=4b2697c989e6bb33f60ca2b53ac1dfefaa08fc04
commit 4b2697c989e6bb33f60ca2b53ac1dfefaa08fc04
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Page info: Implement redraw.
diff --git a/desktop/page-info.c b/desktop/page-info.c
index 0666aaf..c7827f3 100644
--- a/desktop/page-info.c
+++ b/desktop/page-info.c
@@ -561,3 +561,117 @@ void page_info_destroy(
}
free(pi);
}
+
+/**
+ * Render a text entry.
+ *
+ * \param[in] pit The page info window handle.
+ * \param[in] x X-coordinate to plot at.
+ * \param[in] y Y-coordinate to plot at.
+ * \param[in] ctx Current redraw context.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__redraw_text_entry(
+ const struct page_info_text *pit,
+ int x,
+ int y,
+ const struct redraw_context *ctx)
+{
+ int baseline = (pit->height * 3 + 2) / 4;
+
+ ctx->plot->text(ctx, pit->style, x, y + baseline,
+ pit->text, strlen(pit->text));
+
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_redraw(
+ const struct page_info *pi,
+ int x,
+ int y,
+ const struct rect *clip,
+ const struct redraw_context *ctx)
+{
+ struct redraw_context new_ctx = *ctx;
+ struct rect r = {
+ .x0 = clip->x0 + x,
+ .y0 = clip->y0 + y,
+ .x1 = clip->x1 + x,
+ .y1 = clip->y1 + y,
+ };
+ int cur_y = 0;
+ nserror err;
+
+ /* Start knockout rendering if it's available for this plotter. */
+ if (ctx->plot->option_knockout) {
+ bool res = knockout_plot_start(ctx, &new_ctx);
+ if (res == false) {
+ return NSERROR_UNKNOWN;
+ }
+ }
+
+ /* Set up clip rectangle and draw background. */
+ new_ctx.plot->clip(&new_ctx, &r);
+ new_ctx.plot->rectangle(&new_ctx, &pi__bg, &r);
+
+ cur_y += pi->window_padding;
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ const struct page_info_entry *entry = pi->entries + i;
+ int cur_x = pi->window_padding;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ err = page_info__redraw_text_entry(
+ &entry->text,
+ cur_x, cur_y,
+ &new_ctx);
+ if (err != NSERROR_OK) {
+ goto cleanup;
+ }
+ cur_y += entry->text.height;
+ cur_y += entry->text.padding_bottom;
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ if (entry->item.hover) {
+ r.y0 = cur_y;
+ r.y1 = cur_y + entry->item.padding_top +
+ entry->item.item.height +
+ entry->item.padding_bottom;
+ new_ctx.plot->rectangle(&new_ctx,
+ &pi__hover, &r);
+ }
+ cur_y += entry->item.padding_top;
+ err = page_info__redraw_text_entry(
+ &entry->item.item,
+ cur_x, cur_y,
+ &new_ctx);
+ if (err != NSERROR_OK) {
+ goto cleanup;
+ }
+ cur_x += entry->item.item.width;
+ err = page_info__redraw_text_entry(
+ &entry->item.detail,
+ cur_x, cur_y,
+ &new_ctx);
+ if (err != NSERROR_OK) {
+ goto cleanup;
+ }
+ cur_y += entry->item.item.height;
+ cur_y += entry->item.padding_bottom;
+ break;
+ }
+ }
+
+cleanup:
+ /* Rendering complete */
+ if (ctx->plot->option_knockout) {
+ bool res = knockout_plot_end(ctx);
+ if (res == false) {
+ return NSERROR_UNKNOWN;
+ }
+ }
+
+ return NSERROR_OK;
+}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=c32e1bb340d2d40d0a5b61e37e6fd55f84953633
commit c32e1bb340d2d40d0a5b61e37e6fd55f84953633
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Page info: Implement page info window creation and destruction.
diff --git a/desktop/page-info.c b/desktop/page-info.c
index ad0a71a..0666aaf 100644
--- a/desktop/page-info.c
+++ b/desktop/page-info.c
@@ -311,3 +311,253 @@ nserror page_info_fini(void)
{
return NSERROR_OK;
}
+
+/**
+ * Measure the text in the page_info window.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__measure_text_entry(
+ struct page_info_text *pit)
+{
+ nserror err;
+ int height_px;
+
+ err = guit->layout->width(pit->style,
+ pit->text, strlen(pit->text),
+ &pit->width);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ /* \todo: This needs to be a helper in plot style or in nscss. */
+ height_px = ((pit->style->size / PLOT_STYLE_SCALE) *
+ FIXTOINT(nscss_screen_dpi) + 36) / 72;
+
+ pit->height = (height_px * 8 + 3) / 6;
+
+ return NSERROR_OK;
+}
+
+/**
+ * Measure the text in the page_info window.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__measure_text(
+ struct page_info *pi)
+{
+ nserror err;
+
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ struct page_info_entry *entry = pi->entries + i;
+ int padding;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ err = page_info__measure_text_entry(
+ &entry->text);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ if (i == PI_ENTRY_DOMAIN) {
+ entry->text.padding_bottom =
+ entry->text.height * 3 / 2;
+ }
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ err = page_info__measure_text_entry(
+ &entry->item.item);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ err = page_info__measure_text_entry(
+ &entry->item.detail);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ padding = entry->item.item.height / 4;
+ entry->item.padding_top = padding;
+ entry->item.padding_bottom = padding;
+
+ break;
+ }
+ }
+
+ pi->window_padding = pi->entries[PI_ENTRY_DOMAIN].item.item.height / 2;
+
+ return NSERROR_OK;
+}
+
+/**
+ * Set the text for the page_info window.
+ *
+ * \todo Use messages for internationalisation.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__set_text(
+ struct page_info *pi)
+{
+ int printed;
+ static const char *header[PAGE_STATE__COUNT] = {
+ [PAGE_STATE_UNKNOWN] = "Provenience unknown",
+ [PAGE_STATE_INTERNAL] = "NetSurf data",
+ [PAGE_STATE_LOCAL] = "Local data",
+ [PAGE_STATE_INSECURE] = "Connection not secure",
+ [PAGE_STATE_SECURE_OVERRIDE] = "Connection not secure",
+ [PAGE_STATE_SECURE_ISSUES] = "Connection not secure",
+ [PAGE_STATE_SECURE] = "Connection is secure",
+ };
+ static const char *certificate[PAGE_STATE__COUNT] = {
+ [PAGE_STATE_UNKNOWN] = "Missing",
+ [PAGE_STATE_INTERNAL] = "None",
+ [PAGE_STATE_LOCAL] = "None",
+ [PAGE_STATE_INSECURE] = "Not valid",
+ [PAGE_STATE_SECURE_OVERRIDE] = "Not valid",
+ [PAGE_STATE_SECURE_ISSUES] = "Not valid",
+ [PAGE_STATE_SECURE] = "Valid",
+ };
+
+ assert(pi != NULL);
+ assert(pi->state < PAGE_STATE__COUNT);
+
+ pi->entries[PI_ENTRY_HEADER].text.style = &pi__heading[pi->state];
+ pi->entries[PI_ENTRY_HEADER].text.text = header[pi->state];
+ pi->entries[PI_ENTRY_DOMAIN].text.text = (pi->domain) ?
+ lwc_string_data(pi->domain) : "<No domain>";
+
+ pi->entries[PI_ENTRY_CERT].item.item.text = "Certificate: ";
+ pi->entries[PI_ENTRY_CERT].item.detail.text = certificate[pi->state];
+
+ printed = snprintf(pi->cookie_text, sizeof(pi->cookie_text),
+ "(%u in use)", pi->cookies);
+ if (printed < 0) {
+ return NSERROR_UNKNOWN;
+
+ } else if ((unsigned) printed >= sizeof(pi->cookie_text)) {
+ return NSERROR_NOSPACE;
+ }
+ pi->entries[PI_ENTRY_COOKIES].item.item.text = "Cookies: ";
+ pi->entries[PI_ENTRY_COOKIES].item.detail.text = pi->cookie_text;
+
+ return page_info__measure_text(pi);
+}
+
+/**
+ * Create page info from a browser window.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] bw Browser window to show page info for.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__create_from_bw(
+ struct page_info *pi,
+ const struct browser_window *bw)
+{
+ nsurl *url = browser_window_access_url(bw);
+
+ pi->bw = bw;
+ pi->state = browser_window_get_page_info_state(bw);
+ pi->cookies = browser_window_get_cookie_count(bw);
+ pi->domain = nsurl_get_component(url, NSURL_HOST);
+
+ return page_info__set_text(pi);
+}
+
+/**
+ * Lay out the page info window.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__layout(
+ struct page_info *pi)
+{
+ int cur_y = 0;
+ int max_x = 0;
+
+ cur_y += pi->window_padding;
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ struct page_info_entry *entry = pi->entries + i;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ cur_y += entry->text.height;
+ if (max_x < entry->text.width) {
+ max_x = entry->text.width;
+ }
+ cur_y += entry->text.padding_bottom;
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ {
+ int full_width = entry->item.item.width +
+ entry->item.detail.width;
+ cur_y += entry->item.padding_top;
+ cur_y += entry->item.item.height;
+ if (max_x < full_width) {
+ max_x = full_width;
+ }
+ cur_y += entry->item.padding_bottom;
+ }
+ break;
+ }
+ }
+ cur_y += pi->window_padding;
+ max_x += pi->window_padding * 2;
+
+ pi->width = max_x;
+ pi->height = cur_y;
+ return pi->cw_t->update_size(pi->cw_h, max_x, cur_y);
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_create(
+ const struct core_window_callback_table *cw_t,
+ struct core_window *cw_h,
+ const struct browser_window *bw,
+ struct page_info **pi_out)
+{
+ struct page_info *pi;
+ nserror err;
+
+ pi = calloc(1, sizeof(*pi));
+ if (pi == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ pi->cw_t = cw_t;
+ pi->cw_h = cw_h;
+
+ memcpy(pi->entries, pi__entries, sizeof(pi__entries));
+
+ err = page_info__create_from_bw(pi, bw);
+ if (err != NSERROR_OK) {
+ page_info_destroy(pi);
+ return err;
+ }
+
+ err = page_info__layout(pi);
+ if (err != NSERROR_OK) {
+ page_info_destroy(pi);
+ return err;
+ }
+
+ *pi_out = pi;
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+void page_info_destroy(
+ struct page_info *pi)
+{
+ if (pi->domain != NULL) {
+ lwc_string_unref(pi->domain);
+ }
+ free(pi);
+}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=3940918b6830aa8273d0860d5d1d49706f969d3e
commit 3940918b6830aa8273d0860d5d1d49706f969d3e
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Page info: Add data structures and module init/fini.
diff --git a/desktop/page-info.c b/desktop/page-info.c
new file mode 100644
index 0000000..ad0a71a
--- /dev/null
+++ b/desktop/page-info.c
@@ -0,0 +1,313 @@
+/*
+ * Copyright 2020 Michael Drake <[email protected]>
+ *
+ * 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
+ * Pave info viewer window implementation
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "css/utils.h"
+
+#include "utils/nsurl.h"
+
+#include "netsurf/mouse.h"
+#include "netsurf/layout.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
+#include "netsurf/core_window.h"
+#include "netsurf/browser_window.h"
+
+#include "desktop/knockout.h"
+#include "desktop/page-info.h"
+#include "desktop/gui_internal.h"
+#include "desktop/system_colour.h"
+
+/**
+ * Plot style for heading font.
+ */
+static plot_font_style_t pi__heading[PAGE_STATE__COUNT] = {
+ [PAGE_STATE_UNKNOWN] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_INTERNAL] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_LOCAL] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_INSECURE] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_SECURE_OVERRIDE] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_SECURE_ISSUES] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_SECURE] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+};
+
+/**
+ * Plot style for domain font.
+ */
+static plot_font_style_t pi__domain = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 8 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 700,
+};
+
+/**
+ * Plot style for item font.
+ */
+static plot_font_style_t pi__item = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 11 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+};
+
+/**
+ * Plot style for item detail font.
+ */
+static plot_font_style_t pi__item_detail = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 11 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+};
+
+/**
+ * Plot style for window background.
+ */
+static plot_style_t pi__bg = {
+ .fill_type = PLOT_OP_TYPE_SOLID,
+};
+
+/**
+ * Plot style for hover background.
+ */
+static plot_style_t pi__hover = {
+ .fill_type = PLOT_OP_TYPE_SOLID,
+};
+
+/**
+ * An "text" type page info entry.
+ */
+struct page_info_text {
+ const char *text;
+ const plot_font_style_t *style;
+ int width;
+ int height;
+ int padding_bottom;
+};
+
+/**
+ * An "item" type page info entry.
+ */
+struct page_info_item {
+ struct page_info_text item;
+ struct page_info_text detail;
+ const plot_style_t *hover_bg;
+ int padding_bottom;
+ int padding_top;
+ bool hover;
+};
+
+/**
+ * List of page info window entries.
+ */
+enum pi_entry {
+ PI_ENTRY_HEADER,
+ PI_ENTRY_DOMAIN,
+ PI_ENTRY_CERT,
+ PI_ENTRY_COOKIES,
+ PI_ENTRY__COUNT,
+};
+
+/**
+ * An entry on a page info window.
+ */
+struct page_info_entry {
+ /**
+ * List of page info entry types.
+ */
+ enum page_info_entry_type {
+ PAGE_INFO_ENTRY_TYPE_TEXT,
+ PAGE_INFO_ENTRY_TYPE_ITEM,
+ } type;
+ /**
+ * Type-specific page info entry data.
+ */
+ union {
+ struct page_info_text text;
+ struct page_info_item item;
+ };
+};
+
+/**
+ * The default page info window data.
+ */
+struct page_info_entry pi__entries[PI_ENTRY__COUNT] = {
+ [PI_ENTRY_HEADER] = {
+ .type = PAGE_INFO_ENTRY_TYPE_TEXT,
+ },
+ [PI_ENTRY_DOMAIN] = {
+ .type = PAGE_INFO_ENTRY_TYPE_TEXT,
+ .text = {
+ .style = &pi__domain,
+ },
+ },
+ [PI_ENTRY_CERT] = {
+ .type = PAGE_INFO_ENTRY_TYPE_ITEM,
+ .item = {
+ .item = {
+ .style = &pi__item,
+ },
+ .detail = {
+ .style = &pi__item_detail,
+ },
+ .hover_bg = &pi__hover,
+ },
+ },
+ [PI_ENTRY_COOKIES] = {
+ .type = PAGE_INFO_ENTRY_TYPE_ITEM,
+ .item = {
+ .item = {
+ .style = &pi__item,
+ },
+ .detail = {
+ .style = &pi__item_detail,
+ },
+ .hover_bg = &pi__hover,
+ },
+ },
+};
+
+/**
+ * The page info window structure.
+ */
+struct page_info {
+ const struct core_window_callback_table *cw_t;
+ struct core_window *cw_h;
+
+ const struct browser_window *bw;
+ lwc_string *domain;
+
+ browser_window_page_info_state state;
+ unsigned cookies;
+
+ char cookie_text[64];
+ struct page_info_entry entries[PI_ENTRY__COUNT];
+
+ int width;
+ int height;
+
+ int window_padding;
+};
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_init(void)
+{
+ bool dark_on_light;
+ nserror err;
+ colour good;
+ colour bad;
+ colour bg;
+ colour fg;
+
+ err = ns_system_colour_char("Window", &bg);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ err = ns_system_colour_char("WindowText", &fg);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ dark_on_light = colour_lightness(bg) > colour_lightness(fg);
+
+ pi__bg.fill_colour = bg;
+ pi__hover.fill_colour = dark_on_light?
+ darken_colour(bg) :
+ lighten_colour(bg);
+
+ pi__domain.background = bg;
+ pi__domain.foreground = fg;
+
+ pi__item.background = bg;
+ pi__item.foreground = fg;
+
+ pi__item_detail.background = bg;
+ pi__item_detail.foreground = blend_colour(bg, fg);
+
+ good = colour_engorge_component(fg,
+ dark_on_light, PLOT_COLOUR_COMPONENT_GREEN);
+ bad = colour_engorge_component(fg,
+ dark_on_light, PLOT_COLOUR_COMPONENT_RED);
+
+ pi__heading[PAGE_STATE_UNKNOWN].background = bg;
+ pi__heading[PAGE_STATE_UNKNOWN].foreground = bad;
+ pi__heading[PAGE_STATE_INTERNAL].background = bg;
+ pi__heading[PAGE_STATE_INTERNAL].foreground = fg;
+ pi__heading[PAGE_STATE_LOCAL].background = bg;
+ pi__heading[PAGE_STATE_LOCAL].foreground = fg;
+ pi__heading[PAGE_STATE_INSECURE].background = bg;
+ pi__heading[PAGE_STATE_INSECURE].foreground = bad;
+ pi__heading[PAGE_STATE_SECURE_OVERRIDE].background = bg;
+ pi__heading[PAGE_STATE_SECURE_OVERRIDE].foreground = bad;
+ pi__heading[PAGE_STATE_SECURE_ISSUES].background = bg;
+ pi__heading[PAGE_STATE_SECURE_ISSUES].foreground = bad;
+ pi__heading[PAGE_STATE_SECURE].background = bg;
+ pi__heading[PAGE_STATE_SECURE].foreground = good;
+
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_fini(void)
+{
+ return NSERROR_OK;
+}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=9198c9958afedc8104858979ec949c72933cbf91
commit 9198c9958afedc8104858979ec949c72933cbf91
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Desktop: Add page-info API.
This will be a core window intended to show information about the
page currently shown in the associated browser window.
diff --git a/desktop/page-info.h b/desktop/page-info.h
new file mode 100644
index 0000000..89b82e0
--- /dev/null
+++ b/desktop/page-info.h
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2020 Michael Drake <[email protected]>
+ *
+ * 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
+ * Pave info viewer window interface
+ */
+
+#ifndef NETSURF_DESKTOP_PAGE_INFO_H
+#define NETSURF_DESKTOP_PAGE_INFO_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "utils/errors.h"
+#include "netsurf/mouse.h"
+
+struct rect;
+struct nsurl;
+struct page_info;
+struct core_window;
+struct browser_window;
+struct redraw_context;
+struct core_window_callback_table;
+
+/**
+ * Initialise the page_info module.
+ *
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_init(void);
+
+/**
+ * Finalise the page_info module.
+ *
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_fini(void);
+
+/**
+ * Create a page info corewindow.
+ *
+ * The page info window is opened for a particular browser window.
+ * It can be destroyed before the browser window is destroyed by calling
+ * \ref page_info_destroy.
+ *
+ * \param[in] cw_t Callback table for the containing core_window.
+ * \param[in] cw_h Handle for the containing core_window.
+ * \param[in] bw Browser window to show page info for.
+ * \param[out] pi_out The created page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_create(
+ const struct core_window_callback_table *cw_t,
+ struct core_window *cw_h,
+ const struct browser_window *bw,
+ struct page_info **pi_out);
+
+/**
+ * Destroy a page info corewindow.
+ *
+ * \param[in] pi The page info window handle.
+ */
+void page_info_destroy(
+ struct page_info *pi);
+
+/**
+ * Redraw the page info window.
+ *
+ * Causes the page info window to issue plot operations to redraw
+ * the specified area of the viewport.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] x X coordinate to render page_info at.
+ * \param[in] y Y coordinate to render page_info at.
+ * \param[in] clip Current clip rectangle.
+ * \param[in] ctx Current redraw context.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_redraw(
+ const struct page_info *pi,
+ int x,
+ int y,
+ const struct rect *clip,
+ const struct redraw_context *ctx);
+
+/**
+ * Mouse action handling.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] mouse The current mouse state
+ * \param[in] x The current mouse X coordinate
+ * \param[in] y The current mouse Y coordinate
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_mouse_action(
+ struct page_info *pi,
+ enum browser_mouse_state mouse,
+ int x,
+ int y);
+
+/**
+ * Key press handling.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] key The ucs4 character codepoint.
+ * \return true if the keypress is dealt with, false otherwise.
+ */
+bool page_info_keypress(
+ struct page_info *pi,
+ int32_t key);
+
+/**
+ * Get size of page info content area.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[out] width On success, return the page info content width.
+ * \param[out] height On success, return the page info content height.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_get_size(
+ struct page_info *pi,
+ int *width,
+ int *height);
+
+#endif
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=8da6252f5024aa1de3d4d9018d2ff32f96d22cd8
commit 8da6252f5024aa1de3d4d9018d2ff32f96d22cd8
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Browser window API: Add count for page state enum.
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index cc63f6e..e463dfa 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -70,6 +70,7 @@ typedef enum {
PAGE_STATE_SECURE_OVERRIDE, /**< Secure load, but had to override */
PAGE_STATE_SECURE_ISSUES, /**< Secure load, but has insecure
elements */
PAGE_STATE_SECURE, /**< Secure load */
+ PAGE_STATE__COUNT, /**< Count of number of valid page
states */
} browser_window_page_info_state;
typedef enum {
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=a39b651620272d240c40a9ff056eb50a758350f7
commit a39b651620272d240c40a9ff056eb50a758350f7
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Browser window: Add stubs for new interfaces for page-info dialogue.
diff --git a/desktop/browser_window.c b/desktop/browser_window.c
index 2b0e314..59ab73d 100644
--- a/desktop/browser_window.c
+++ b/desktop/browser_window.c
@@ -4721,3 +4721,27 @@ browser_window_get_ssl_chain(struct browser_window *bw,
return NSERROR_OK;
}
+
+/* Exported interface, documented in browser_window.h */
+int browser_window_get_cookie_count(
+ const struct browser_window *bw)
+{
+ /** \todo Implement cookie count */
+ return 0;
+}
+
+/* Exported interface, documented in browser_window.h */
+nserror browser_window_show_cookies(
+ const struct browser_window *bw)
+{
+ /** \todo Implement show cookies */
+ return NSERROR_OK;
+}
+
+/* Exported interface, documented in browser_window.h */
+nserror browser_window_show_certificates(
+ const struct browser_window *bw)
+{
+ /** \todo Implement show certificates */
+ return NSERROR_OK;
+}
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index eb2bd7c..cc63f6e 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -789,4 +789,33 @@ browser_window_page_info_state
browser_window_get_page_info_state(
*/
nserror browser_window_get_ssl_chain(struct browser_window *bw, struct
cert_chain **chain);
+/**
+ * Get the number of cookies in use for the current page.
+ *
+ * \param bw A browser window.
+ * \return Number of cookies in use, or 0 on error.
+ */
+int browser_window_get_cookie_count(
+ const struct browser_window *bw);
+
+/**
+ * Open cookie viewer for the current page.
+ *
+ * \param bw A browser window.
+ * \return NSERROR_OK, or appropriate error otherwise.
+ */
+nserror browser_window_show_cookies(
+ const struct browser_window *bw);
+
+/**
+ * Show the certificate page for the current page.
+ *
+ * Does nothing for a page without certificates.
+ *
+ * \param bw A browser window.
+ * \return NSERROR_OK, or appropriate error otherwise.
+ */
+nserror browser_window_show_certificates(
+ const struct browser_window *bw);
+
#endif
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=d23a7b4c8ffda7448bdb05591655954655a3cfe0
commit d23a7b4c8ffda7448bdb05591655954655a3cfe0
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Browser window: Constify bw through page_info_state getter.
diff --git a/desktop/browser_window.c b/desktop/browser_window.c
index 6defe01..2b0e314 100644
--- a/desktop/browser_window.c
+++ b/desktop/browser_window.c
@@ -4644,7 +4644,7 @@ browser_window__reload_current_parameters(struct
browser_window *bw)
/* Exported interface, documented in browser_window.h */
browser_window_page_info_state browser_window_get_page_info_state(
- struct browser_window *bw)
+ const struct browser_window *bw)
{
lwc_string *scheme;
bool match;
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index e8faa18..eb2bd7c 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -774,7 +774,7 @@ nserror browser_window_console_log(struct browser_window
*bw,
* \return The state of the browser window
*/
browser_window_page_info_state browser_window_get_page_info_state(
- struct browser_window *bw);
+ const struct browser_window *bw);
/**
* Request the current browser window SSL certificate chain.
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=475d397b8c3aa5ca672b7ec984a41302449b7727
commit 475d397b8c3aa5ca672b7ec984a41302449b7727
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Plot style: Add function to engorge a colour channel.
This can be used to exaggerate the red, green, or blue component.
diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h
index 692192f..bc86041 100644
--- a/include/netsurf/plot_style.h
+++ b/include/netsurf/plot_style.h
@@ -188,6 +188,39 @@ typedef struct plot_font_style {
#define blue_from_colour(c) \
((c >> 16) & 0xff)
+/** Colour components */
+enum plot_colour_component {
+ PLOT_COLOUR_COMPONENT_RED,
+ PLOT_COLOUR_COMPONENT_GREEN,
+ PLOT_COLOUR_COMPONENT_BLUE,
+ PLOT_COLOUR_COMPONENT_ALPHA,
+};
+
+/**
+ * Engorge a particular colour channel.
+ *
+ * \param[in] col The colour to engorge a component of.
+ * \param[in] dark Whether col is a dark colour.
+ * \param[in] comp Colour component to engorge.
+ */
+static inline colour colour_engorge_component(
+ colour col,
+ bool dark,
+ enum plot_colour_component comp)
+{
+ static const colour mask[PLOT_COLOUR_COMPONENT_ALPHA] = {
+ [PLOT_COLOUR_COMPONENT_RED] = 0x0000ff,
+ [PLOT_COLOUR_COMPONENT_GREEN] = 0x00ff00,
+ [PLOT_COLOUR_COMPONENT_BLUE] = 0xff0000,
+ };
+ colour d = dark ? darken_colour(col) : double_darken_colour(col);
+ colour l = dark ? double_lighten_colour(col) : lighten_colour(col);
+
+ assert(comp < PLOT_COLOUR_COMPONENT_ALPHA);
+
+ return (mask[comp] & l) | (~mask[comp] & d);
+}
+
/* global fill styles */
extern plot_style_t *plot_style_fill_white;
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=6783deba4e209461fd8105b9b46dbcacefed6b6f
commit 6783deba4e209461fd8105b9b46dbcacefed6b6f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
Plot style: Split lightness calc out of colour_to_bw_furthest macro.
diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h
index f1b6172..692192f 100644
--- a/include/netsurf/plot_style.h
+++ b/include/netsurf/plot_style.h
@@ -153,13 +153,16 @@ typedef struct plot_font_style {
(((((c0 & 0xff00ff) + (c1 & 0xff00ff)) >> 1) & 0xff00ff) | \
((((c0 & 0x00ff00) + (c1 & 0x00ff00)) >> 1) & 0x00ff00))
+/* Get the percieved lightness of the supplied colour, c0. */
+#define colour_lightness(c0) \
+ ((((c0 & 0x0000ff) * 77) >> 8) + \
+ (((c0 & 0x00ff00) * 151) >> 16) + \
+ (((c0 & 0xff0000) * 28) >> 24))
+
/* Choose either black or white, depending on which is furthest from the
* percieved lightness of the supplied colour, c0. */
#define colour_to_bw_furthest(c0) \
- ((((((c0 & 0x0000ff) * 77) >> 8) + \
- (((c0 & 0x00ff00) * 151) >> 16) + \
- (((c0 & 0xff0000) * 28) >> 24)) > \
- (0xff / 2)) ? 0x000000 : 0xffffff)
+ ((colour_lightness(c0) > (0xff / 2)) ? 0x000000 : 0xffffff)
/* Mix two colours according to the proportion given by p, where 0 <= p <= 255
* p = 0 gives result ==> c1, p = 255 gives result ==> c0 */
-----------------------------------------------------------------------
Summary of changes:
desktop/Makefile | 2 +-
desktop/browser_window.c | 26 +-
desktop/netsurf.c | 11 +-
desktop/page-info.c | 788 ++++++++++++++++++++++++++++++++++++++
desktop/page-info.h | 141 +++++++
frontends/gtk/page_info.c | 78 ++--
include/netsurf/browser_window.h | 32 +-
include/netsurf/plot_style.h | 44 ++-
8 files changed, 1075 insertions(+), 47 deletions(-)
create mode 100644 desktop/page-info.c
create mode 100644 desktop/page-info.h
diff --git a/desktop/Makefile b/desktop/Makefile
index 0d88b2b..3e40449 100644
--- a/desktop/Makefile
+++ b/desktop/Makefile
@@ -3,7 +3,7 @@
S_DESKTOP := cookie_manager.c knockout.c hotlist.c mouse.c \
plot_style.c print.c search.c searchweb.c scrollbar.c \
sslcert_viewer.c textarea.c version.c system_colour.c \
- local_history.c global_history.c treeview.c
+ local_history.c global_history.c treeview.c page-info.c
S_DESKTOP := $(addprefix desktop/,$(S_DESKTOP))
diff --git a/desktop/browser_window.c b/desktop/browser_window.c
index 6defe01..59ab73d 100644
--- a/desktop/browser_window.c
+++ b/desktop/browser_window.c
@@ -4644,7 +4644,7 @@ browser_window__reload_current_parameters(struct
browser_window *bw)
/* Exported interface, documented in browser_window.h */
browser_window_page_info_state browser_window_get_page_info_state(
- struct browser_window *bw)
+ const struct browser_window *bw)
{
lwc_string *scheme;
bool match;
@@ -4721,3 +4721,27 @@ browser_window_get_ssl_chain(struct browser_window *bw,
return NSERROR_OK;
}
+
+/* Exported interface, documented in browser_window.h */
+int browser_window_get_cookie_count(
+ const struct browser_window *bw)
+{
+ /** \todo Implement cookie count */
+ return 0;
+}
+
+/* Exported interface, documented in browser_window.h */
+nserror browser_window_show_cookies(
+ const struct browser_window *bw)
+{
+ /** \todo Implement show cookies */
+ return NSERROR_OK;
+}
+
+/* Exported interface, documented in browser_window.h */
+nserror browser_window_show_certificates(
+ const struct browser_window *bw)
+{
+ /** \todo Implement show certificates */
+ return NSERROR_OK;
+}
diff --git a/desktop/netsurf.c b/desktop/netsurf.c
index e3babd8..7577e1f 100644
--- a/desktop/netsurf.c
+++ b/desktop/netsurf.c
@@ -49,6 +49,7 @@
#include "netsurf/browser_window.h"
#include "desktop/system_colour.h"
+#include "desktop/page-info.h"
#include "desktop/searchweb.h"
#include "netsurf/misc.h"
#include "desktop/gui_internal.h"
@@ -206,6 +207,11 @@ nserror netsurf_init(const char *store_path)
js_initialise();
+ ret = page_info_init();
+ if (ret != NSERROR_OK) {
+ return ret;
+ }
+
return NSERROR_OK;
}
@@ -220,7 +226,10 @@ void netsurf_exit(void)
NSLOG(netsurf, INFO, "Closing GUI");
guit->misc->quit();
-
+
+ NSLOG(netsurf, INFO, "Finalising page-info module");
+ page_info_fini();
+
NSLOG(netsurf, INFO, "Finalising JavaScript");
js_finalise();
diff --git a/desktop/page-info.c b/desktop/page-info.c
new file mode 100644
index 0000000..51784c4
--- /dev/null
+++ b/desktop/page-info.c
@@ -0,0 +1,788 @@
+/*
+ * Copyright 2020 Michael Drake <[email protected]>
+ *
+ * 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
+ * Pave info viewer window implementation
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "css/utils.h"
+
+#include "utils/nsurl.h"
+
+#include "netsurf/mouse.h"
+#include "netsurf/layout.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
+#include "netsurf/core_window.h"
+#include "netsurf/browser_window.h"
+
+#include "desktop/knockout.h"
+#include "desktop/page-info.h"
+#include "desktop/gui_internal.h"
+#include "desktop/system_colour.h"
+
+/**
+ * Plot style for heading font.
+ */
+static plot_font_style_t pi__heading[PAGE_STATE__COUNT] = {
+ [PAGE_STATE_UNKNOWN] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_INTERNAL] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_LOCAL] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_INSECURE] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_SECURE_OVERRIDE] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_SECURE_ISSUES] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+ [PAGE_STATE_SECURE] = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 14 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+ },
+};
+
+/**
+ * Plot style for domain font.
+ */
+static plot_font_style_t pi__domain = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 8 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 700,
+};
+
+/**
+ * Plot style for item font.
+ */
+static plot_font_style_t pi__item = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 11 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+};
+
+/**
+ * Plot style for item detail font.
+ */
+static plot_font_style_t pi__item_detail = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = 11 * PLOT_STYLE_SCALE,
+ .flags = FONTF_NONE,
+ .weight = 400,
+};
+
+/**
+ * Plot style for window background.
+ */
+static plot_style_t pi__bg = {
+ .fill_type = PLOT_OP_TYPE_SOLID,
+};
+
+/**
+ * Plot style for hover background.
+ */
+static plot_style_t pi__hover = {
+ .fill_type = PLOT_OP_TYPE_SOLID,
+};
+
+/**
+ * An "text" type page info entry.
+ */
+struct page_info_text {
+ const char *text;
+ const plot_font_style_t *style;
+ int width;
+ int height;
+ int padding_bottom;
+};
+
+/**
+ * An "item" type page info entry.
+ */
+struct page_info_item {
+ struct page_info_text item;
+ struct page_info_text detail;
+ const plot_style_t *hover_bg;
+ int padding_bottom;
+ int padding_top;
+ bool hover;
+};
+
+/**
+ * List of page info window entries.
+ */
+enum pi_entry {
+ PI_ENTRY_HEADER,
+ PI_ENTRY_DOMAIN,
+ PI_ENTRY_CERT,
+ PI_ENTRY_COOKIES,
+ PI_ENTRY__COUNT,
+};
+
+/**
+ * An entry on a page info window.
+ */
+struct page_info_entry {
+ /**
+ * List of page info entry types.
+ */
+ enum page_info_entry_type {
+ PAGE_INFO_ENTRY_TYPE_TEXT,
+ PAGE_INFO_ENTRY_TYPE_ITEM,
+ } type;
+ /**
+ * Type-specific page info entry data.
+ */
+ union {
+ struct page_info_text text;
+ struct page_info_item item;
+ };
+};
+
+/**
+ * The default page info window data.
+ */
+struct page_info_entry pi__entries[PI_ENTRY__COUNT] = {
+ [PI_ENTRY_HEADER] = {
+ .type = PAGE_INFO_ENTRY_TYPE_TEXT,
+ },
+ [PI_ENTRY_DOMAIN] = {
+ .type = PAGE_INFO_ENTRY_TYPE_TEXT,
+ .text = {
+ .style = &pi__domain,
+ },
+ },
+ [PI_ENTRY_CERT] = {
+ .type = PAGE_INFO_ENTRY_TYPE_ITEM,
+ .item = {
+ .item = {
+ .style = &pi__item,
+ },
+ .detail = {
+ .style = &pi__item_detail,
+ },
+ .hover_bg = &pi__hover,
+ },
+ },
+ [PI_ENTRY_COOKIES] = {
+ .type = PAGE_INFO_ENTRY_TYPE_ITEM,
+ .item = {
+ .item = {
+ .style = &pi__item,
+ },
+ .detail = {
+ .style = &pi__item_detail,
+ },
+ .hover_bg = &pi__hover,
+ },
+ },
+};
+
+/**
+ * The page info window structure.
+ */
+struct page_info {
+ const struct core_window_callback_table *cw_t;
+ struct core_window *cw_h;
+
+ const struct browser_window *bw;
+ lwc_string *domain;
+
+ browser_window_page_info_state state;
+ unsigned cookies;
+
+ char cookie_text[64];
+ struct page_info_entry entries[PI_ENTRY__COUNT];
+
+ int width;
+ int height;
+
+ int window_padding;
+};
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_init(void)
+{
+ bool dark_on_light;
+ nserror err;
+ colour good;
+ colour bad;
+ colour bg;
+ colour fg;
+
+ err = ns_system_colour_char("Window", &bg);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ err = ns_system_colour_char("WindowText", &fg);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ dark_on_light = colour_lightness(bg) > colour_lightness(fg);
+
+ pi__bg.fill_colour = bg;
+ pi__hover.fill_colour = dark_on_light?
+ darken_colour(bg) :
+ lighten_colour(bg);
+
+ pi__domain.background = bg;
+ pi__domain.foreground = fg;
+
+ pi__item.background = bg;
+ pi__item.foreground = fg;
+
+ pi__item_detail.background = bg;
+ pi__item_detail.foreground = blend_colour(bg, fg);
+
+ good = colour_engorge_component(fg,
+ dark_on_light, PLOT_COLOUR_COMPONENT_GREEN);
+ bad = colour_engorge_component(fg,
+ dark_on_light, PLOT_COLOUR_COMPONENT_RED);
+
+ pi__heading[PAGE_STATE_UNKNOWN].background = bg;
+ pi__heading[PAGE_STATE_UNKNOWN].foreground = bad;
+ pi__heading[PAGE_STATE_INTERNAL].background = bg;
+ pi__heading[PAGE_STATE_INTERNAL].foreground = fg;
+ pi__heading[PAGE_STATE_LOCAL].background = bg;
+ pi__heading[PAGE_STATE_LOCAL].foreground = fg;
+ pi__heading[PAGE_STATE_INSECURE].background = bg;
+ pi__heading[PAGE_STATE_INSECURE].foreground = bad;
+ pi__heading[PAGE_STATE_SECURE_OVERRIDE].background = bg;
+ pi__heading[PAGE_STATE_SECURE_OVERRIDE].foreground = bad;
+ pi__heading[PAGE_STATE_SECURE_ISSUES].background = bg;
+ pi__heading[PAGE_STATE_SECURE_ISSUES].foreground = bad;
+ pi__heading[PAGE_STATE_SECURE].background = bg;
+ pi__heading[PAGE_STATE_SECURE].foreground = good;
+
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_fini(void)
+{
+ return NSERROR_OK;
+}
+
+/**
+ * Measure the text in the page_info window.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__measure_text_entry(
+ struct page_info_text *pit)
+{
+ nserror err;
+ int height_px;
+
+ err = guit->layout->width(pit->style,
+ pit->text, strlen(pit->text),
+ &pit->width);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
+ /* \todo: This needs to be a helper in plot style or in nscss. */
+ height_px = ((pit->style->size / PLOT_STYLE_SCALE) *
+ FIXTOINT(nscss_screen_dpi) + 36) / 72;
+
+ pit->height = (height_px * 8 + 3) / 6;
+
+ return NSERROR_OK;
+}
+
+/**
+ * Measure the text in the page_info window.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__measure_text(
+ struct page_info *pi)
+{
+ nserror err;
+
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ struct page_info_entry *entry = pi->entries + i;
+ int padding;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ err = page_info__measure_text_entry(
+ &entry->text);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ if (i == PI_ENTRY_DOMAIN) {
+ entry->text.padding_bottom =
+ entry->text.height * 3 / 2;
+ }
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ err = page_info__measure_text_entry(
+ &entry->item.item);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ err = page_info__measure_text_entry(
+ &entry->item.detail);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ padding = entry->item.item.height / 4;
+ entry->item.padding_top = padding;
+ entry->item.padding_bottom = padding;
+
+ break;
+ }
+ }
+
+ pi->window_padding = pi->entries[PI_ENTRY_DOMAIN].item.item.height / 2;
+
+ return NSERROR_OK;
+}
+
+/**
+ * Set the text for the page_info window.
+ *
+ * \todo Use messages for internationalisation.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__set_text(
+ struct page_info *pi)
+{
+ int printed;
+ static const char *header[PAGE_STATE__COUNT] = {
+ [PAGE_STATE_UNKNOWN] = "Provenience unknown",
+ [PAGE_STATE_INTERNAL] = "NetSurf data",
+ [PAGE_STATE_LOCAL] = "Local data",
+ [PAGE_STATE_INSECURE] = "Connection not secure",
+ [PAGE_STATE_SECURE_OVERRIDE] = "Connection not secure",
+ [PAGE_STATE_SECURE_ISSUES] = "Connection not secure",
+ [PAGE_STATE_SECURE] = "Connection is secure",
+ };
+ static const char *certificate[PAGE_STATE__COUNT] = {
+ [PAGE_STATE_UNKNOWN] = "Missing",
+ [PAGE_STATE_INTERNAL] = "None",
+ [PAGE_STATE_LOCAL] = "None",
+ [PAGE_STATE_INSECURE] = "Not valid",
+ [PAGE_STATE_SECURE_OVERRIDE] = "Not valid",
+ [PAGE_STATE_SECURE_ISSUES] = "Not valid",
+ [PAGE_STATE_SECURE] = "Valid",
+ };
+
+ assert(pi != NULL);
+ assert(pi->state < PAGE_STATE__COUNT);
+
+ pi->entries[PI_ENTRY_HEADER].text.style = &pi__heading[pi->state];
+ pi->entries[PI_ENTRY_HEADER].text.text = header[pi->state];
+ pi->entries[PI_ENTRY_DOMAIN].text.text = (pi->domain) ?
+ lwc_string_data(pi->domain) : "<No domain>";
+
+ pi->entries[PI_ENTRY_CERT].item.item.text = "Certificate: ";
+ pi->entries[PI_ENTRY_CERT].item.detail.text = certificate[pi->state];
+
+ printed = snprintf(pi->cookie_text, sizeof(pi->cookie_text),
+ "(%u in use)", pi->cookies);
+ if (printed < 0) {
+ return NSERROR_UNKNOWN;
+
+ } else if ((unsigned) printed >= sizeof(pi->cookie_text)) {
+ return NSERROR_NOSPACE;
+ }
+ pi->entries[PI_ENTRY_COOKIES].item.item.text = "Cookies: ";
+ pi->entries[PI_ENTRY_COOKIES].item.detail.text = pi->cookie_text;
+
+ return page_info__measure_text(pi);
+}
+
+/**
+ * Create page info from a browser window.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] bw Browser window to show page info for.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__create_from_bw(
+ struct page_info *pi,
+ const struct browser_window *bw)
+{
+ nsurl *url = browser_window_access_url(bw);
+
+ pi->bw = bw;
+ pi->state = browser_window_get_page_info_state(bw);
+ pi->cookies = browser_window_get_cookie_count(bw);
+ pi->domain = nsurl_get_component(url, NSURL_HOST);
+
+ return page_info__set_text(pi);
+}
+
+/**
+ * Lay out the page info window.
+ *
+ * \param[in] pi The page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__layout(
+ struct page_info *pi)
+{
+ int cur_y = 0;
+ int max_x = 0;
+
+ cur_y += pi->window_padding;
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ struct page_info_entry *entry = pi->entries + i;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ cur_y += entry->text.height;
+ if (max_x < entry->text.width) {
+ max_x = entry->text.width;
+ }
+ cur_y += entry->text.padding_bottom;
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ {
+ int full_width = entry->item.item.width +
+ entry->item.detail.width;
+ cur_y += entry->item.padding_top;
+ cur_y += entry->item.item.height;
+ if (max_x < full_width) {
+ max_x = full_width;
+ }
+ cur_y += entry->item.padding_bottom;
+ }
+ break;
+ }
+ }
+ cur_y += pi->window_padding;
+ max_x += pi->window_padding * 2;
+
+ pi->width = max_x;
+ pi->height = cur_y;
+ return pi->cw_t->update_size(pi->cw_h, max_x, cur_y);
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_create(
+ const struct core_window_callback_table *cw_t,
+ struct core_window *cw_h,
+ const struct browser_window *bw,
+ struct page_info **pi_out)
+{
+ struct page_info *pi;
+ nserror err;
+
+ pi = calloc(1, sizeof(*pi));
+ if (pi == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ pi->cw_t = cw_t;
+ pi->cw_h = cw_h;
+
+ memcpy(pi->entries, pi__entries, sizeof(pi__entries));
+
+ err = page_info__create_from_bw(pi, bw);
+ if (err != NSERROR_OK) {
+ page_info_destroy(pi);
+ return err;
+ }
+
+ err = page_info__layout(pi);
+ if (err != NSERROR_OK) {
+ page_info_destroy(pi);
+ return err;
+ }
+
+ *pi_out = pi;
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+void page_info_destroy(
+ struct page_info *pi)
+{
+ if (pi->domain != NULL) {
+ lwc_string_unref(pi->domain);
+ }
+ free(pi);
+}
+
+/**
+ * Render a text entry.
+ *
+ * \param[in] pit The page info window handle.
+ * \param[in] x X-coordinate to plot at.
+ * \param[in] y Y-coordinate to plot at.
+ * \param[in] ctx Current redraw context.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__redraw_text_entry(
+ const struct page_info_text *pit,
+ int x,
+ int y,
+ const struct redraw_context *ctx)
+{
+ int baseline = (pit->height * 3 + 2) / 4;
+
+ ctx->plot->text(ctx, pit->style, x, y + baseline,
+ pit->text, strlen(pit->text));
+
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_redraw(
+ const struct page_info *pi,
+ int x,
+ int y,
+ const struct rect *clip,
+ const struct redraw_context *ctx)
+{
+ struct redraw_context new_ctx = *ctx;
+ struct rect r = {
+ .x0 = clip->x0 + x,
+ .y0 = clip->y0 + y,
+ .x1 = clip->x1 + x,
+ .y1 = clip->y1 + y,
+ };
+ int cur_y = 0;
+ nserror err;
+
+ /* Start knockout rendering if it's available for this plotter. */
+ if (ctx->plot->option_knockout) {
+ bool res = knockout_plot_start(ctx, &new_ctx);
+ if (res == false) {
+ return NSERROR_UNKNOWN;
+ }
+ }
+
+ /* Set up clip rectangle and draw background. */
+ new_ctx.plot->clip(&new_ctx, &r);
+ new_ctx.plot->rectangle(&new_ctx, &pi__bg, &r);
+
+ cur_y += pi->window_padding;
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ const struct page_info_entry *entry = pi->entries + i;
+ int cur_x = pi->window_padding;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ err = page_info__redraw_text_entry(
+ &entry->text,
+ cur_x, cur_y,
+ &new_ctx);
+ if (err != NSERROR_OK) {
+ goto cleanup;
+ }
+ cur_y += entry->text.height;
+ cur_y += entry->text.padding_bottom;
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ if (entry->item.hover) {
+ r.y0 = cur_y;
+ r.y1 = cur_y + entry->item.padding_top +
+ entry->item.item.height +
+ entry->item.padding_bottom;
+ new_ctx.plot->rectangle(&new_ctx,
+ &pi__hover, &r);
+ }
+ cur_y += entry->item.padding_top;
+ err = page_info__redraw_text_entry(
+ &entry->item.item,
+ cur_x, cur_y,
+ &new_ctx);
+ if (err != NSERROR_OK) {
+ goto cleanup;
+ }
+ cur_x += entry->item.item.width;
+ err = page_info__redraw_text_entry(
+ &entry->item.detail,
+ cur_x, cur_y,
+ &new_ctx);
+ if (err != NSERROR_OK) {
+ goto cleanup;
+ }
+ cur_y += entry->item.item.height;
+ cur_y += entry->item.padding_bottom;
+ break;
+ }
+ }
+
+cleanup:
+ /* Rendering complete */
+ if (ctx->plot->option_knockout) {
+ bool res = knockout_plot_end(ctx);
+ if (res == false) {
+ return NSERROR_UNKNOWN;
+ }
+ }
+
+ return NSERROR_OK;
+}
+
+/**
+ * Handle any clicks on an item.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] mouse The current mouse state.
+ * \param[in] clicked The page info window entry to consider clicks on.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+static nserror page_info__handle_item_click(
+ struct page_info *pi,
+ enum browser_mouse_state mouse,
+ enum pi_entry clicked)
+{
+ nserror err;
+
+ if (!(mouse & BROWSER_MOUSE_CLICK_1)) {
+ return NSERROR_OK;
+ }
+
+ switch (clicked) {
+ case PI_ENTRY_CERT:
+ err = browser_window_show_certificates(pi->bw);
+ break;
+ case PI_ENTRY_COOKIES:
+ err = browser_window_show_cookies(pi->bw);
+ break;
+ default:
+ err = NSERROR_OK;
+ break;
+ }
+
+ return err;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_mouse_action(
+ struct page_info *pi,
+ enum browser_mouse_state mouse,
+ int x,
+ int y)
+{
+ int cur_y = 0;
+ nserror err;
+
+ cur_y += pi->window_padding;
+ for (unsigned i = 0; i < PI_ENTRY__COUNT; i++) {
+ struct page_info_entry *entry = pi->entries + i;
+ bool hovering = false;
+ int height;
+
+ switch (entry->type) {
+ case PAGE_INFO_ENTRY_TYPE_TEXT:
+ cur_y += entry->text.height;
+ cur_y += entry->text.padding_bottom;
+ break;
+
+ case PAGE_INFO_ENTRY_TYPE_ITEM:
+ height = entry->item.padding_top +
+ entry->item.item.height +
+ entry->item.padding_bottom;
+
+ if (y >= cur_y && y < cur_y + height) {
+ hovering = true;
+ err = page_info__handle_item_click(
+ pi, mouse, i);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+ }
+ if (entry->item.hover != hovering) {
+ int w, h;
+ struct rect r = {
+ .x0 = 0,
+ .y0 = cur_y,
+ .y1 = cur_y + height,
+ };
+ pi->cw_t->get_window_dimensions(
+ pi->cw_h, &w, &h);
+ r.x1 = (pi->width > w) ? pi->width : w;
+
+ pi->cw_t->invalidate(pi->cw_h, &r);
+ }
+ entry->item.hover = hovering;
+ cur_y += height;
+ break;
+ }
+ }
+
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+bool page_info_keypress(
+ struct page_info *pi,
+ int32_t key)
+{
+ return NSERROR_OK;
+}
+
+/* Exported interface documented in desktop/page_info.h */
+nserror page_info_get_size(
+ struct page_info *pi,
+ int *width,
+ int *height)
+{
+ *width = pi->width;
+ *height = pi->height;
+
+ return NSERROR_OK;
+}
diff --git a/desktop/page-info.h b/desktop/page-info.h
new file mode 100644
index 0000000..89b82e0
--- /dev/null
+++ b/desktop/page-info.h
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2020 Michael Drake <[email protected]>
+ *
+ * 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
+ * Pave info viewer window interface
+ */
+
+#ifndef NETSURF_DESKTOP_PAGE_INFO_H
+#define NETSURF_DESKTOP_PAGE_INFO_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "utils/errors.h"
+#include "netsurf/mouse.h"
+
+struct rect;
+struct nsurl;
+struct page_info;
+struct core_window;
+struct browser_window;
+struct redraw_context;
+struct core_window_callback_table;
+
+/**
+ * Initialise the page_info module.
+ *
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_init(void);
+
+/**
+ * Finalise the page_info module.
+ *
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_fini(void);
+
+/**
+ * Create a page info corewindow.
+ *
+ * The page info window is opened for a particular browser window.
+ * It can be destroyed before the browser window is destroyed by calling
+ * \ref page_info_destroy.
+ *
+ * \param[in] cw_t Callback table for the containing core_window.
+ * \param[in] cw_h Handle for the containing core_window.
+ * \param[in] bw Browser window to show page info for.
+ * \param[out] pi_out The created page info window handle.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_create(
+ const struct core_window_callback_table *cw_t,
+ struct core_window *cw_h,
+ const struct browser_window *bw,
+ struct page_info **pi_out);
+
+/**
+ * Destroy a page info corewindow.
+ *
+ * \param[in] pi The page info window handle.
+ */
+void page_info_destroy(
+ struct page_info *pi);
+
+/**
+ * Redraw the page info window.
+ *
+ * Causes the page info window to issue plot operations to redraw
+ * the specified area of the viewport.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] x X coordinate to render page_info at.
+ * \param[in] y Y coordinate to render page_info at.
+ * \param[in] clip Current clip rectangle.
+ * \param[in] ctx Current redraw context.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_redraw(
+ const struct page_info *pi,
+ int x,
+ int y,
+ const struct rect *clip,
+ const struct redraw_context *ctx);
+
+/**
+ * Mouse action handling.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] mouse The current mouse state
+ * \param[in] x The current mouse X coordinate
+ * \param[in] y The current mouse Y coordinate
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_mouse_action(
+ struct page_info *pi,
+ enum browser_mouse_state mouse,
+ int x,
+ int y);
+
+/**
+ * Key press handling.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[in] key The ucs4 character codepoint.
+ * \return true if the keypress is dealt with, false otherwise.
+ */
+bool page_info_keypress(
+ struct page_info *pi,
+ int32_t key);
+
+/**
+ * Get size of page info content area.
+ *
+ * \param[in] pi The page info window handle.
+ * \param[out] width On success, return the page info content width.
+ * \param[out] height On success, return the page info content height.
+ * \return NSERROR_OK on success, appropriate error code otherwise.
+ */
+nserror page_info_get_size(
+ struct page_info *pi,
+ int *width,
+ int *height);
+
+#endif
diff --git a/frontends/gtk/page_info.c b/frontends/gtk/page_info.c
index 1401fdc..2892788 100644
--- a/frontends/gtk/page_info.c
+++ b/frontends/gtk/page_info.c
@@ -41,7 +41,7 @@
/**
* GTK certificate viewing window context
*/
-struct nsgtk_crtvrfy_window {
+struct nsgtk_pi_window {
/** GTK core window context */
struct nsgtk_corewindow core;
/** GTK builder for window */
@@ -56,46 +56,46 @@ struct nsgtk_crtvrfy_window {
/**
* destroy a previously created certificate view
*/
-static nserror nsgtk_crtvrfy_destroy(struct nsgtk_crtvrfy_window *crtvrfy_win)
+static nserror nsgtk_pi_destroy(struct nsgtk_pi_window *pi_win)
{
nserror res;
- res = sslcert_viewer_fini(crtvrfy_win->ssl_data);
+ res = sslcert_viewer_fini(pi_win->ssl_data);
if (res == NSERROR_OK) {
- res = nsgtk_corewindow_fini(&crtvrfy_win->core);
- gtk_widget_destroy(GTK_WIDGET(crtvrfy_win->dlg));
- g_object_unref(G_OBJECT(crtvrfy_win->builder));
- free(crtvrfy_win);
+ res = nsgtk_corewindow_fini(&pi_win->core);
+ gtk_widget_destroy(GTK_WIDGET(pi_win->dlg));
+ g_object_unref(G_OBJECT(pi_win->builder));
+ free(pi_win);
}
return res;
}
static void
-nsgtk_crtvrfy_accept(GtkButton *w, gpointer data)
+nsgtk_pi_accept(GtkButton *w, gpointer data)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)data;
+ struct nsgtk_pi_window *pi_win;
+ pi_win = (struct nsgtk_pi_window *)data;
- sslcert_viewer_accept(crtvrfy_win->ssl_data);
+ sslcert_viewer_accept(pi_win->ssl_data);
- nsgtk_crtvrfy_destroy(crtvrfy_win);
+ nsgtk_pi_destroy(pi_win);
}
static void
-nsgtk_crtvrfy_reject(GtkWidget *w, gpointer data)
+nsgtk_pi_reject(GtkWidget *w, gpointer data)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)data;
+ struct nsgtk_pi_window *pi_win;
+ pi_win = (struct nsgtk_pi_window *)data;
- sslcert_viewer_reject(crtvrfy_win->ssl_data);
+ sslcert_viewer_reject(pi_win->ssl_data);
- nsgtk_crtvrfy_destroy(crtvrfy_win);
+ nsgtk_pi_destroy(pi_win);
}
static gboolean
-nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
+nsgtk_pi_delete_event(GtkWidget *w, GdkEvent *event, gpointer data)
{
- nsgtk_crtvrfy_reject(w, data);
+ nsgtk_pi_reject(w, data);
return FALSE;
}
@@ -109,15 +109,15 @@ nsgtk_crtvrfy_delete_event(GtkWidget *w, GdkEvent
*event, gpointer data)
* \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
-nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
+nsgtk_pi_mouse(struct nsgtk_corewindow *nsgtk_cw,
browser_mouse_state mouse_state,
int x, int y)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
+ struct nsgtk_pi_window *pi_win;
/* technically degenerate container of */
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw;
+ pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
- sslcert_viewer_mouse_action(crtvrfy_win->ssl_data, mouse_state, x, y);
+ sslcert_viewer_mouse_action(pi_win->ssl_data, mouse_state, x, y);
return NSERROR_OK;
}
@@ -130,14 +130,14 @@ nsgtk_crtvrfy_mouse(struct nsgtk_corewindow *nsgtk_cw,
* \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
-nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
+nsgtk_pi_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
{
- struct nsgtk_crtvrfy_window *crtvrfy_win;
+ struct nsgtk_pi_window *pi_win;
/* technically degenerate container of */
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw;
+ pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
- if (sslcert_viewer_keypress(crtvrfy_win->ssl_data, nskey)) {
+ if (sslcert_viewer_keypress(pi_win->ssl_data, nskey)) {
return NSERROR_OK;
}
return NSERROR_NOT_IMPLEMENTED;
@@ -151,19 +151,19 @@ nsgtk_crtvrfy_key(struct nsgtk_corewindow *nsgtk_cw,
uint32_t nskey)
* \return NSERROR_OK on success otherwise appropriate error code
*/
static nserror
-nsgtk_crtvrfy_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
+nsgtk_pi_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
{
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &nsgtk_plotters
};
- struct nsgtk_crtvrfy_window *crtvrfy_win;
+ struct nsgtk_pi_window *pi_win;
/* technically degenerate container of */
- crtvrfy_win = (struct nsgtk_crtvrfy_window *)nsgtk_cw;
+ pi_win = (struct nsgtk_pi_window *)nsgtk_cw;
- sslcert_viewer_redraw(crtvrfy_win->ssl_data, 0, 0, r, &ctx);
+ sslcert_viewer_redraw(pi_win->ssl_data, 0, 0, r, &ctx);
return NSERROR_OK;
}
@@ -176,7 +176,7 @@ static nserror dummy_cb(bool proceed, void *pw)
/* exported interface documented in gtk/page_info.h */
nserror nsgtk_page_info(struct browser_window *bw)
{
- struct nsgtk_crtvrfy_window *ncwin;
+ struct nsgtk_pi_window *ncwin;
nserror res;
struct cert_chain *chain;
@@ -189,7 +189,7 @@ nserror nsgtk_page_info(struct browser_window *bw)
}
url = browser_window_access_url(bw);
- ncwin = malloc(sizeof(struct nsgtk_crtvrfy_window));
+ ncwin = malloc(sizeof(struct nsgtk_pi_window));
if (ncwin == NULL) {
return NSERROR_NOMEM;
}
@@ -219,27 +219,27 @@ nserror nsgtk_page_info(struct browser_window *bw)
/* make the delete event call our destructor */
g_signal_connect(G_OBJECT(ncwin->dlg),
"delete_event",
- G_CALLBACK(nsgtk_crtvrfy_delete_event),
+ G_CALLBACK(nsgtk_pi_delete_event),
ncwin);
/* accept button */
g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder,
"sslaccept")),
"clicked",
- G_CALLBACK(nsgtk_crtvrfy_accept),
+ G_CALLBACK(nsgtk_pi_accept),
ncwin);
/* reject button */
g_signal_connect(G_OBJECT(gtk_builder_get_object(ncwin->builder,
"sslreject")),
"clicked",
- G_CALLBACK(nsgtk_crtvrfy_reject),
+ G_CALLBACK(nsgtk_pi_reject),
ncwin);
/* initialise GTK core window */
- ncwin->core.draw = nsgtk_crtvrfy_draw;
- ncwin->core.key = nsgtk_crtvrfy_key;
- ncwin->core.mouse = nsgtk_crtvrfy_mouse;
+ ncwin->core.draw = nsgtk_pi_draw;
+ ncwin->core.key = nsgtk_pi_key;
+ ncwin->core.mouse = nsgtk_pi_mouse;
res = nsgtk_corewindow_init(&ncwin->core);
if (res != NSERROR_OK) {
diff --git a/include/netsurf/browser_window.h b/include/netsurf/browser_window.h
index e8faa18..e463dfa 100644
--- a/include/netsurf/browser_window.h
+++ b/include/netsurf/browser_window.h
@@ -70,6 +70,7 @@ typedef enum {
PAGE_STATE_SECURE_OVERRIDE, /**< Secure load, but had to override */
PAGE_STATE_SECURE_ISSUES, /**< Secure load, but has insecure
elements */
PAGE_STATE_SECURE, /**< Secure load */
+ PAGE_STATE__COUNT, /**< Count of number of valid page
states */
} browser_window_page_info_state;
typedef enum {
@@ -774,7 +775,7 @@ nserror browser_window_console_log(struct browser_window
*bw,
* \return The state of the browser window
*/
browser_window_page_info_state browser_window_get_page_info_state(
- struct browser_window *bw);
+ const struct browser_window *bw);
/**
* Request the current browser window SSL certificate chain.
@@ -789,4 +790,33 @@ browser_window_page_info_state
browser_window_get_page_info_state(
*/
nserror browser_window_get_ssl_chain(struct browser_window *bw, struct
cert_chain **chain);
+/**
+ * Get the number of cookies in use for the current page.
+ *
+ * \param bw A browser window.
+ * \return Number of cookies in use, or 0 on error.
+ */
+int browser_window_get_cookie_count(
+ const struct browser_window *bw);
+
+/**
+ * Open cookie viewer for the current page.
+ *
+ * \param bw A browser window.
+ * \return NSERROR_OK, or appropriate error otherwise.
+ */
+nserror browser_window_show_cookies(
+ const struct browser_window *bw);
+
+/**
+ * Show the certificate page for the current page.
+ *
+ * Does nothing for a page without certificates.
+ *
+ * \param bw A browser window.
+ * \return NSERROR_OK, or appropriate error otherwise.
+ */
+nserror browser_window_show_certificates(
+ const struct browser_window *bw);
+
#endif
diff --git a/include/netsurf/plot_style.h b/include/netsurf/plot_style.h
index f1b6172..bc86041 100644
--- a/include/netsurf/plot_style.h
+++ b/include/netsurf/plot_style.h
@@ -153,13 +153,16 @@ typedef struct plot_font_style {
(((((c0 & 0xff00ff) + (c1 & 0xff00ff)) >> 1) & 0xff00ff) | \
((((c0 & 0x00ff00) + (c1 & 0x00ff00)) >> 1) & 0x00ff00))
+/* Get the percieved lightness of the supplied colour, c0. */
+#define colour_lightness(c0) \
+ ((((c0 & 0x0000ff) * 77) >> 8) + \
+ (((c0 & 0x00ff00) * 151) >> 16) + \
+ (((c0 & 0xff0000) * 28) >> 24))
+
/* Choose either black or white, depending on which is furthest from the
* percieved lightness of the supplied colour, c0. */
#define colour_to_bw_furthest(c0) \
- ((((((c0 & 0x0000ff) * 77) >> 8) + \
- (((c0 & 0x00ff00) * 151) >> 16) + \
- (((c0 & 0xff0000) * 28) >> 24)) > \
- (0xff / 2)) ? 0x000000 : 0xffffff)
+ ((colour_lightness(c0) > (0xff / 2)) ? 0x000000 : 0xffffff)
/* Mix two colours according to the proportion given by p, where 0 <= p <= 255
* p = 0 gives result ==> c1, p = 255 gives result ==> c0 */
@@ -185,6 +188,39 @@ typedef struct plot_font_style {
#define blue_from_colour(c) \
((c >> 16) & 0xff)
+/** Colour components */
+enum plot_colour_component {
+ PLOT_COLOUR_COMPONENT_RED,
+ PLOT_COLOUR_COMPONENT_GREEN,
+ PLOT_COLOUR_COMPONENT_BLUE,
+ PLOT_COLOUR_COMPONENT_ALPHA,
+};
+
+/**
+ * Engorge a particular colour channel.
+ *
+ * \param[in] col The colour to engorge a component of.
+ * \param[in] dark Whether col is a dark colour.
+ * \param[in] comp Colour component to engorge.
+ */
+static inline colour colour_engorge_component(
+ colour col,
+ bool dark,
+ enum plot_colour_component comp)
+{
+ static const colour mask[PLOT_COLOUR_COMPONENT_ALPHA] = {
+ [PLOT_COLOUR_COMPONENT_RED] = 0x0000ff,
+ [PLOT_COLOUR_COMPONENT_GREEN] = 0x00ff00,
+ [PLOT_COLOUR_COMPONENT_BLUE] = 0xff0000,
+ };
+ colour d = dark ? darken_colour(col) : double_darken_colour(col);
+ colour l = dark ? double_lighten_colour(col) : lighten_colour(col);
+
+ assert(comp < PLOT_COLOUR_COMPONENT_ALPHA);
+
+ return (mask[comp] & l) | (~mask[comp] & d);
+}
+
/* global fill styles */
extern plot_style_t *plot_style_fill_white;
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org