From eb17f4ab37cd47a12f97f0ab37b92d5297bd6743 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 18 Oct 2015 10:53:49 +0100 Subject: Implement basic browsing context name property --- desktop/browser.c | 37 ++++++++++++++++++++++++++++++++++++- desktop/browser.h | 30 +++++++++++++++++++++++++++++- javascript/duktape/Window.bnd | 16 ++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index 21b6c8815..8df59eee7 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -106,7 +106,6 @@ static inline void browser_window_get_scrollbar_pos(struct browser_window *bw, * \param horizontal Whether to get length of horizontal scrollbar * \return the scrollbar's length */ - static inline int browser_window_get_scrollbar_len(struct browser_window *bw, bool horizontal) { @@ -116,6 +115,42 @@ static inline int browser_window_get_scrollbar_len(struct browser_window *bw, return bw->height; } + +/* exported interface, documented in browser.h */ +nserror +browser_window_get_name(struct browser_window *bw, const char **out_name) +{ + assert(bw != NULL); + + *out_name = bw->name; + + return NSERROR_OK; +} + +/* exported interface, documented in browser.h */ +nserror +browser_window_set_name(struct browser_window *bw, const char *name) +{ + char *nname = NULL; + + assert(bw != NULL); + + if (name != NULL) { + nname = strdup(name); + if (nname == NULL) { + return NSERROR_NOMEM; + } + } + + if (bw->name != NULL) { + free(bw->name); + } + + bw->name = nname; + + return NSERROR_OK; +} + /* exported interface, documented in browser.h */ bool browser_window_redraw(struct browser_window *bw, int x, int y, const struct rect *clip, const struct redraw_context *ctx) diff --git a/desktop/browser.h b/desktop/browser.h index 07faf10dc..a1ec37a4b 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -677,11 +677,39 @@ int browser_get_dpi(void); nserror browser_window_debug_dump(struct browser_window *bw, FILE *f, enum content_debug op); /** - * set debug options on a window + * Set debug options on a window + * * \param bw The browser window. * \param op The debug operation type. * \return NSERROR_OK on success or error code on faliure. */ nserror browser_window_debug(struct browser_window *bw, enum content_debug op); +/** + * Obtain a browsing contexts name. + * + * The returned pointer is owned bu the browsing context and is only + * valid untill the next operation on that context. + * The returned name may be NULL if no name has been set. + * \todo This does not consider behaviour wrt frames + * + * \param bw The browser window. + * \param name recives result string. + * \return NSERROR_OK + */ +nserror browser_window_get_name(struct browser_window *bw, const char **name); + +/** + * Set a browsing contexts name. + * + * Changes a browsing contexts name to a copy of that passed and the + * value is not subsequently referenced. + * + * \param bw The browser window. + * \param name The name string to set. + * \return NSERROR_OK and the name is updated or NSERROR_NOMEM and the + * original name is untouched. + */ +nserror browser_window_set_name(struct browser_window *bw, const char *name); + #endif diff --git a/javascript/duktape/Window.bnd b/javascript/duktape/Window.bnd index af62eb711..a6355fb2c 100644 --- a/javascript/duktape/Window.bnd +++ b/javascript/duktape/Window.bnd @@ -116,3 +116,19 @@ getter Window::navigator() } return 1; %} + +getter Window::name() +%{ + const char *name; + browser_window_get_name(priv->win, &name); + duk_push_string(ctx, name); + return 1; +%} + +setter Window::name() +%{ + const char *name; + name = duk_to_string(ctx, -1); + browser_window_set_name(priv->win, name); + return 0; +%} -- cgit v1.2.3