2011-03-12 18:08:07 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Browser-related callbacks */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2016-04-22 00:36:21 +03:00
|
|
|
#include <stdlib.h>
|
2016-06-06 17:14:29 +03:00
|
|
|
#include <string.h>
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2016-04-20 01:20:29 +03:00
|
|
|
#include "utils/utils.h"
|
2011-03-12 18:08:07 +03:00
|
|
|
#include "utils/ring.h"
|
2011-03-12 20:27:18 +03:00
|
|
|
#include "utils/log.h"
|
2013-02-18 16:24:49 +04:00
|
|
|
#include "utils/messages.h"
|
2016-06-06 17:14:29 +03:00
|
|
|
#include "utils/nsurl.h"
|
2016-05-30 14:07:16 +03:00
|
|
|
#include "netsurf/mouse.h"
|
2016-05-30 13:01:40 +03:00
|
|
|
#include "netsurf/window.h"
|
2016-05-30 19:32:57 +03:00
|
|
|
#include "netsurf/browser_window.h"
|
2016-05-30 23:05:57 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2018-11-03 18:12:27 +03:00
|
|
|
#include "monkey/output.h"
|
2011-03-12 18:08:07 +03:00
|
|
|
#include "monkey/browser.h"
|
2011-06-30 19:48:07 +04:00
|
|
|
#include "monkey/plot.h"
|
2011-03-12 18:08:07 +03:00
|
|
|
|
|
|
|
static uint32_t win_ctr = 0;
|
|
|
|
|
|
|
|
static struct gui_window *gw_ring = NULL;
|
|
|
|
|
2016-04-29 12:53:31 +03:00
|
|
|
/* exported function documented in monkey/browser.h */
|
|
|
|
nserror monkey_warn_user(const char *warning, const char *detail)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WARNING, "%s %s", warning, detail);
|
2017-06-10 00:04:58 +03:00
|
|
|
return NSERROR_OK;
|
2016-04-29 12:53:31 +03:00
|
|
|
}
|
|
|
|
|
2011-03-12 18:08:07 +03:00
|
|
|
struct gui_window *
|
|
|
|
monkey_find_window_by_num(uint32_t win_num)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
struct gui_window *ret = NULL;
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
RING_ITERATE_START(struct gui_window, gw_ring, c_ring) {
|
|
|
|
if (c_ring->win_num == win_num) {
|
|
|
|
ret = c_ring;
|
|
|
|
RING_ITERATE_STOP(gw_ring, c_ring);
|
|
|
|
}
|
|
|
|
} RING_ITERATE_END(gw_ring, c_ring);
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
return ret;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2011-03-12 20:54:02 +03:00
|
|
|
void
|
|
|
|
monkey_kill_browser_windows(void)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
while (gw_ring != NULL) {
|
|
|
|
browser_window_destroy(gw_ring->bw);
|
|
|
|
}
|
2011-03-12 20:54:02 +03:00
|
|
|
}
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static struct gui_window *
|
2014-01-12 02:34:12 +04:00
|
|
|
gui_window_create(struct browser_window *bw,
|
2017-06-10 00:04:58 +03:00
|
|
|
struct gui_window *existing,
|
|
|
|
gui_window_create_flags flags)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
struct gui_window *ret = calloc(sizeof(*ret), 1);
|
|
|
|
if (ret == NULL)
|
|
|
|
return NULL;
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
ret->win_num = win_ctr++;
|
|
|
|
ret->bw = bw;
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
ret->width = 800;
|
|
|
|
ret->height = 600;
|
2018-11-03 18:12:27 +03:00
|
|
|
|
|
|
|
moutf(MOUT_WINDOW,
|
|
|
|
"NEW WIN %u FOR %p EXISTING %p NEWTAB %s CLONE %s",
|
|
|
|
ret->win_num, bw, existing,
|
|
|
|
flags & GW_CREATE_TAB ? "TRUE" : "FALSE",
|
|
|
|
flags & GW_CREATE_CLONE ? "TRUE" : "FALSE");
|
|
|
|
moutf(MOUT_WINDOW,
|
|
|
|
"SIZE WIN %u WIDTH %d HEIGHT %d",
|
|
|
|
ret->win_num, ret->width, ret->height);
|
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
RING_INSERT(gw_ring, ret);
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
return ret;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_destroy(struct gui_window *g)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "DESTROY WIN %u", g->win_num);
|
2017-06-10 00:04:58 +03:00
|
|
|
RING_REMOVE(gw_ring, g);
|
|
|
|
free(g);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_set_title(struct gui_window *g, const char *title)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "TITLE WIN %u STR %s", g->win_num, title);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 12:02:24 +03:00
|
|
|
/**
|
|
|
|
* Find the current dimensions of a monkey browser window content area.
|
|
|
|
*
|
2017-04-27 00:25:23 +03:00
|
|
|
* \param g The gui window to measure content area of.
|
2017-04-26 12:02:24 +03:00
|
|
|
* \param width receives width of window
|
|
|
|
* \param height receives height of window
|
|
|
|
* \return NSERROR_OK on sucess and width and height updated.
|
|
|
|
*/
|
|
|
|
static nserror
|
2019-08-02 14:25:35 +03:00
|
|
|
gui_window_get_dimensions(struct gui_window *g, int *width, int *height)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
*width = g->width;
|
|
|
|
*height = g->height;
|
2017-04-26 12:02:24 +03:00
|
|
|
|
2019-08-02 14:25:35 +03:00
|
|
|
moutf(MOUT_WINDOW,
|
|
|
|
"GET_DIMENSIONS WIN %u WIDTH %d HEIGHT %d",
|
|
|
|
g->win_num, *width, *height);
|
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 02:55:26 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_new_content(struct gui_window *g)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "NEW_CONTENT WIN %u", g->win_num);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static void
|
2016-06-06 17:14:29 +03:00
|
|
|
gui_window_set_icon(struct gui_window *g, struct hlcache_handle *icon)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "NEW_ICON WIN %u", g->win_num);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_start_throbber(struct gui_window *g)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "START_THROBBER WIN %u", g->win_num);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_stop_throbber(struct gui_window *g)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "STOP_THROBBER WIN %u", g->win_num);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-04-27 00:25:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scroll position of a monkey browser window.
|
|
|
|
*
|
|
|
|
* Scrolls the viewport to ensure the specified rectangle of the
|
|
|
|
* content is shown.
|
|
|
|
*
|
|
|
|
* \param gw gui window to scroll
|
|
|
|
* \param rect The rectangle to ensure is shown.
|
|
|
|
* \return NSERROR_OK on success or apropriate error code.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
gui_window_set_scroll(struct gui_window *gw, const struct rect *rect)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
gw->scrollx = rect->x0;
|
|
|
|
gw->scrolly = rect->y0;
|
2017-04-27 00:25:23 +03:00
|
|
|
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "SET_SCROLL WIN %u X %d Y %d",
|
2017-06-10 14:21:48 +03:00
|
|
|
gw->win_num, rect->x0, rect->y0);
|
2017-06-10 00:04:58 +03:00
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-04-27 00:25:23 +03:00
|
|
|
|
2017-04-23 22:29:22 +03:00
|
|
|
/**
|
|
|
|
* Invalidates an area of a monkey browser window
|
|
|
|
*
|
|
|
|
* \param gw gui_window
|
|
|
|
* \param rect area to redraw or NULL for the entire window area
|
|
|
|
* \return NSERROR_OK on success or appropriate error code
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
monkey_window_invalidate_area(struct gui_window *gw, const struct rect *rect)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-04-23 22:29:22 +03:00
|
|
|
if (rect != NULL) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW,
|
|
|
|
"INVALIDATE_AREA WIN %u X %d Y %d WIDTH %d HEIGHT %d",
|
|
|
|
gw->win_num,
|
|
|
|
rect->x0, rect->y0,
|
|
|
|
(rect->x1 - rect->x0), (rect->y1 - rect->y0));
|
2017-04-23 22:29:22 +03:00
|
|
|
} else {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "INVALIDATE_AREA WIN %u ALL", gw->win_num);
|
2017-04-23 22:29:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 15:38:35 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_update_extent(struct gui_window *g)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
int width, height;
|
2014-10-16 00:35:14 +04:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (browser_window_get_extents(g->bw, false, &width, &height) != NSERROR_OK)
|
|
|
|
return;
|
2011-03-12 18:08:07 +03:00
|
|
|
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "UPDATE_EXTENT WIN %u WIDTH %d HEIGHT %d",
|
|
|
|
g->win_num, width, height);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_set_status(struct gui_window *g, const char *text)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "SET_STATUS WIN %u STR %s", g->win_num, text);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
const char *ptr_name = "UNKNOWN";
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
switch (shape) {
|
|
|
|
case GUI_POINTER_POINT:
|
|
|
|
ptr_name = "POINT";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_CARET:
|
|
|
|
ptr_name = "CARET";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_UP:
|
|
|
|
ptr_name = "UP";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_DOWN:
|
|
|
|
ptr_name = "DOWN";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_LEFT:
|
|
|
|
ptr_name = "LEFT";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_RIGHT:
|
|
|
|
ptr_name = "RIGHT";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_LD:
|
|
|
|
ptr_name = "LD";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_RD:
|
|
|
|
ptr_name = "RD";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_LU:
|
|
|
|
ptr_name = "LU";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_RU:
|
|
|
|
ptr_name = "RU";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_CROSS:
|
|
|
|
ptr_name = "CROSS";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_MOVE:
|
|
|
|
ptr_name = "MOVE";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_WAIT:
|
|
|
|
ptr_name = "WAIT";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_HELP:
|
|
|
|
ptr_name = "HELP";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_MENU:
|
|
|
|
ptr_name = "MENU";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_PROGRESS:
|
|
|
|
ptr_name = "PROGRESS";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_NO_DROP:
|
|
|
|
ptr_name = "NO_DROP";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_NOT_ALLOWED:
|
|
|
|
ptr_name = "NOT_ALLOWED";
|
|
|
|
break;
|
|
|
|
case GUI_POINTER_DEFAULT:
|
|
|
|
ptr_name = "DEFAULT";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-11-03 18:12:27 +03:00
|
|
|
|
|
|
|
moutf(MOUT_WINDOW, "SET_POINTER WIN %u POINTER %s",
|
|
|
|
g->win_num, ptr_name);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-10-29 03:17:11 +03:00
|
|
|
static nserror
|
2014-11-03 01:30:45 +03:00
|
|
|
gui_window_set_url(struct gui_window *g, nsurl *url)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "SET_URL WIN %u URL %s",
|
|
|
|
g->win_num, nsurl_access(url));
|
2017-06-10 00:04:58 +03:00
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 05:08:15 +04:00
|
|
|
static bool
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "GET_SCROLL WIN %u X %d Y %d",
|
|
|
|
g->win_num, g->scrollx, g->scrolly);
|
2017-06-10 00:04:58 +03:00
|
|
|
*sx = g->scrollx;
|
|
|
|
*sy = g->scrolly;
|
|
|
|
return true;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 02:55:26 +04:00
|
|
|
static bool
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_scroll_start(struct gui_window *g)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "SCROLL_START WIN %u", g->win_num);
|
2017-06-10 00:04:58 +03:00
|
|
|
g->scrollx = g->scrolly = 0;
|
|
|
|
return true;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void
|
2013-03-06 02:53:33 +04:00
|
|
|
gui_window_place_caret(struct gui_window *g, int x, int y, int height,
|
2017-06-10 00:04:58 +03:00
|
|
|
const struct rect *clip)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "PLACE_CARET WIN %u X %d Y %d HEIGHT %d",
|
|
|
|
g->win_num, x, y, height);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void
|
2011-03-12 18:08:07 +03:00
|
|
|
gui_window_remove_caret(struct gui_window *g)
|
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "REMOVE_CARET WIN %u", g->win_num);
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static bool
|
2012-01-11 18:20:26 +04:00
|
|
|
gui_window_drag_start(struct gui_window *g, gui_drag_type type,
|
2018-11-03 18:12:27 +03:00
|
|
|
const struct rect *rect)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "SCROLL_START WIN %u TYPE %i", g->win_num, type);
|
2017-06-10 00:04:58 +03:00
|
|
|
return false;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2014-11-04 02:05:59 +03:00
|
|
|
static nserror
|
|
|
|
gui_window_save_link(struct gui_window *g, nsurl *url, const char *title)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "SAVE_LINK WIN %u URL %s TITLE %s",
|
2017-06-10 00:04:58 +03:00
|
|
|
g->win_num, nsurl_access(url), title);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
2011-03-12 20:27:18 +03:00
|
|
|
|
2019-05-06 12:04:48 +03:00
|
|
|
static void
|
|
|
|
gui_window_console_log(struct gui_window *g,
|
|
|
|
browser_window_console_source src,
|
|
|
|
const char *msg,
|
|
|
|
size_t msglen,
|
|
|
|
browser_window_console_flags flags)
|
|
|
|
{
|
|
|
|
bool foldable = !!(flags & BW_CS_FLAG_FOLDABLE);
|
|
|
|
const char *src_text;
|
|
|
|
const char *level_text;
|
2014-01-05 20:01:03 +04:00
|
|
|
|
2019-05-06 12:04:48 +03:00
|
|
|
switch (src) {
|
|
|
|
case BW_CS_INPUT:
|
|
|
|
src_text = "client-input";
|
|
|
|
break;
|
|
|
|
case BW_CS_SCRIPT_ERROR:
|
|
|
|
src_text = "scripting-error";
|
|
|
|
break;
|
|
|
|
case BW_CS_SCRIPT_CONSOLE:
|
|
|
|
src_text = "scripting-console";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknown scripting source");
|
|
|
|
src_text = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (flags & BW_CS_FLAG_LEVEL_MASK) {
|
2019-05-06 12:16:48 +03:00
|
|
|
case BW_CS_FLAG_LEVEL_DEBUG:
|
|
|
|
level_text = "DEBUG";
|
|
|
|
break;
|
2019-05-06 12:04:48 +03:00
|
|
|
case BW_CS_FLAG_LEVEL_LOG:
|
|
|
|
level_text = "LOG";
|
|
|
|
break;
|
|
|
|
case BW_CS_FLAG_LEVEL_INFO:
|
|
|
|
level_text = "INFO";
|
|
|
|
break;
|
|
|
|
case BW_CS_FLAG_LEVEL_WARN:
|
|
|
|
level_text = "WARN";
|
|
|
|
break;
|
|
|
|
case BW_CS_FLAG_LEVEL_ERROR:
|
|
|
|
level_text = "ERROR";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknown console logging level");
|
|
|
|
level_text = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
moutf(MOUT_WINDOW, "CONSOLE_LOG WIN %u SOURCE %s %sFOLDABLE %s %.*s",
|
|
|
|
g->win_num, src_text, foldable ? "" : "NOT-", level_text,
|
|
|
|
(int)msglen, msg);
|
|
|
|
}
|
2011-03-12 20:27:18 +03:00
|
|
|
|
2019-12-01 20:05:08 +03:00
|
|
|
static void
|
|
|
|
gui_window_report_page_info(struct gui_window *g)
|
|
|
|
{
|
|
|
|
const char *state = "***WAH***";
|
|
|
|
|
|
|
|
switch (browser_window_get_page_info_state(g->bw)) {
|
|
|
|
case PAGE_STATE_UNKNOWN:
|
|
|
|
state = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAGE_STATE_INTERNAL:
|
|
|
|
state = "INTERNAL";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAGE_STATE_LOCAL:
|
|
|
|
state = "LOCAL";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAGE_STATE_INSECURE:
|
|
|
|
state = "INSECURE";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAGE_STATE_SECURE_OVERRIDE:
|
|
|
|
state = "SECURE_OVERRIDE";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAGE_STATE_SECURE_ISSUES:
|
|
|
|
state = "SECURE_ISSUES";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAGE_STATE_SECURE:
|
|
|
|
state = "SECURE";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0 && "Monkey needs some lovin' here");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
moutf(MOUT_WINDOW, "PAGE_STATUS WIN %u STATUS %s",
|
|
|
|
g->win_num, state);
|
|
|
|
}
|
|
|
|
|
2011-03-12 20:27:18 +03:00
|
|
|
/**** Handlers ****/
|
|
|
|
|
|
|
|
static void
|
|
|
|
monkey_window_handle_new(int argc, char **argv)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
nsurl *url = NULL;
|
|
|
|
nserror error = NSERROR_OK;
|
|
|
|
|
|
|
|
if (argc > 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (argc == 3) {
|
|
|
|
error = nsurl_create(argv[2], &url);
|
|
|
|
}
|
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
error = browser_window_create(BW_CREATE_HISTORY,
|
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (url != NULL) {
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
monkey_warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
2011-03-12 20:27:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monkey_window_handle_destroy(int argc, char **argv)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
struct gui_window *gw;
|
|
|
|
uint32_t nr = atoi((argc > 2) ? argv[2] : "-1");
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
gw = monkey_find_window_by_num(nr);
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (gw == NULL) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW NUM BAD");
|
2017-06-10 00:04:58 +03:00
|
|
|
} else {
|
|
|
|
browser_window_destroy(gw->bw);
|
|
|
|
}
|
2011-03-12 20:27:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monkey_window_handle_go(int argc, char **argv)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
struct gui_window *gw;
|
|
|
|
nsurl *url;
|
|
|
|
nsurl *ref_url = NULL;
|
|
|
|
nserror error;
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (argc < 4 || argc > 5) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW GO ARGS BAD");
|
2017-06-10 00:04:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
gw = monkey_find_window_by_num(atoi(argv[2]));
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (gw == NULL) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW NUM BAD");
|
2017-06-10 00:04:58 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = nsurl_create(argv[3], &url);
|
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
if (argc == 5) {
|
|
|
|
error = nsurl_create(argv[4], &ref_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error == NSERROR_OK) {
|
|
|
|
error = browser_window_navigate(gw->bw,
|
|
|
|
url,
|
|
|
|
ref_url,
|
|
|
|
BW_NAVIGATE_HISTORY,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (ref_url != NULL) {
|
|
|
|
nsurl_unref(ref_url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
monkey_warn_user(messages_get_errorcode(error), 0);
|
|
|
|
}
|
2011-03-12 20:27:18 +03:00
|
|
|
}
|
|
|
|
|
2019-06-06 17:44:52 +03:00
|
|
|
/**
|
|
|
|
* handle WINDOW STOP command
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
monkey_window_handle_stop(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct gui_window *gw;
|
|
|
|
if (argc != 3) {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW STOP ARGS BAD\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gw = monkey_find_window_by_num(atoi(argv[2]));
|
|
|
|
|
|
|
|
if (gw == NULL) {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW NUM BAD");
|
|
|
|
} else {
|
|
|
|
browser_window_stop(gw->bw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-12 20:54:02 +03:00
|
|
|
static void
|
|
|
|
monkey_window_handle_redraw(int argc, char **argv)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
struct gui_window *gw;
|
|
|
|
struct rect clip;
|
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
|
|
|
.background_images = true,
|
|
|
|
.plot = monkey_plotters
|
|
|
|
};
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (argc != 3 && argc != 7) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW REDRAW ARGS BAD");
|
2017-06-10 00:04:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-03-12 20:54:02 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
gw = monkey_find_window_by_num(atoi(argv[2]));
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (gw == NULL) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW NUM BAD");
|
2017-06-10 00:04:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
clip.x0 = 0;
|
|
|
|
clip.y0 = 0;
|
|
|
|
clip.x1 = gw->width;
|
|
|
|
clip.y1 = gw->height;
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (argc == 7) {
|
|
|
|
clip.x0 = atoi(argv[3]);
|
|
|
|
clip.y0 = atoi(argv[4]);
|
|
|
|
clip.x1 = atoi(argv[5]);
|
|
|
|
clip.y1 = atoi(argv[6]);
|
|
|
|
}
|
2018-11-03 18:12:27 +03:00
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Issue redraw");
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_WINDOW, "REDRAW WIN %d START", atoi(argv[2]));
|
|
|
|
browser_window_redraw(gw->bw, gw->scrollx, gw->scrolly, &clip, &ctx);
|
2018-11-03 18:27:58 +03:00
|
|
|
moutf(MOUT_WINDOW, "REDRAW WIN %d STOP", atoi(argv[2]));
|
2011-03-12 20:54:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
monkey_window_handle_reload(int argc, char **argv)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
struct gui_window *gw;
|
|
|
|
if (argc != 3 && argc != 4) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW RELOAD ARGS BAD\n");
|
2019-06-06 17:44:52 +03:00
|
|
|
return;
|
2017-06-10 00:04:58 +03:00
|
|
|
}
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
gw = monkey_find_window_by_num(atoi(argv[2]));
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (gw == NULL) {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW NUM BAD");
|
2017-06-10 00:04:58 +03:00
|
|
|
} else {
|
|
|
|
browser_window_reload(gw->bw, argc == 4);
|
|
|
|
}
|
2011-03-12 20:54:02 +03:00
|
|
|
}
|
|
|
|
|
2019-05-05 17:59:30 +03:00
|
|
|
static void
|
|
|
|
monkey_window_handle_exec(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct gui_window *gw;
|
|
|
|
if (argc < 5) {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW EXEC ARGS BAD\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
gw = monkey_find_window_by_num(atoi(argv[2]));
|
|
|
|
|
|
|
|
if (gw == NULL) {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW NUM BAD");
|
|
|
|
} else {
|
|
|
|
/* Gather argv[4] onward into a string to pass to js_exec */
|
|
|
|
int total = 0;
|
|
|
|
for (int i = 4; i < argc; ++i) {
|
|
|
|
total += strlen(argv[i]) + 1;
|
|
|
|
}
|
|
|
|
char *cmd = calloc(total, 1);
|
2019-08-01 11:23:58 +03:00
|
|
|
if (cmd == NULL) {
|
|
|
|
moutf(MOUT_ERROR, "JS WIN %d RET ENOMEM", atoi(argv[2]));
|
|
|
|
return;
|
|
|
|
}
|
2019-05-05 17:59:30 +03:00
|
|
|
strcpy(cmd, argv[4]);
|
|
|
|
for (int i = 5; i < argc; ++i) {
|
|
|
|
strcat(cmd, " ");
|
|
|
|
strcat(cmd, argv[i]);
|
|
|
|
}
|
|
|
|
/* Now execute the JS */
|
|
|
|
|
|
|
|
moutf(MOUT_WINDOW, "JS WIN %d RET %s", atoi(argv[2]),
|
|
|
|
browser_window_exec(gw->bw, cmd, total - 1) ? "TRUE" : "FALSE");
|
|
|
|
|
|
|
|
free(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-12 20:54:02 +03:00
|
|
|
|
2019-08-03 14:31:02 +03:00
|
|
|
static void
|
|
|
|
monkey_window_handle_click(int argc, char **argv)
|
|
|
|
{
|
|
|
|
/* `WINDOW CLICK WIN` _%id%_ `X` _%num%_ `Y` _%num%_ `BUTTON` _%str%_ `KIND` _%str%_ */
|
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 10 11 */
|
|
|
|
struct gui_window *gw;
|
|
|
|
if (argc != 12) {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW CLICK ARGS BAD\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
gw = monkey_find_window_by_num(atoi(argv[2]));
|
|
|
|
|
|
|
|
if (gw == NULL) {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW NUM BAD");
|
|
|
|
} else {
|
|
|
|
int x = atoi(argv[5]);
|
|
|
|
int y = atoi(argv[7]);
|
|
|
|
browser_mouse_state mouse;
|
|
|
|
const char *button = argv[9];
|
|
|
|
const char *kind = argv[11];
|
|
|
|
if (strcmp(button, "LEFT") == 0) {
|
|
|
|
mouse = BROWSER_MOUSE_CLICK_1;
|
|
|
|
} else if (strcmp(button, "RIGHT") == 0) {
|
|
|
|
mouse = BROWSER_MOUSE_CLICK_2;
|
|
|
|
} else {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW BUTTON BAD");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strcmp(kind, "SINGLE") == 0) {
|
|
|
|
/* Nothing */
|
|
|
|
} else if (strcmp(kind, "DOUBLE") == 0) {
|
|
|
|
mouse |= BROWSER_MOUSE_DOUBLE_CLICK;
|
|
|
|
} else if (strcmp(kind, "TRIPLE") == 0) {
|
|
|
|
mouse |= BROWSER_MOUSE_TRIPLE_CLICK;
|
|
|
|
} else {
|
|
|
|
moutf(MOUT_ERROR, "WINDOW KIND BAD");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
browser_window_mouse_click(gw->bw, mouse, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-12 20:27:18 +03:00
|
|
|
void
|
|
|
|
monkey_window_handle_command(int argc, char **argv)
|
|
|
|
{
|
2017-06-10 00:04:58 +03:00
|
|
|
if (argc == 1)
|
|
|
|
return;
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2017-06-10 00:04:58 +03:00
|
|
|
if (strcmp(argv[1], "NEW") == 0) {
|
|
|
|
monkey_window_handle_new(argc, argv);
|
|
|
|
} else if (strcmp(argv[1], "DESTROY") == 0) {
|
|
|
|
monkey_window_handle_destroy(argc, argv);
|
|
|
|
} else if (strcmp(argv[1], "GO") == 0) {
|
|
|
|
monkey_window_handle_go(argc, argv);
|
2019-06-06 17:44:52 +03:00
|
|
|
} else if (strcmp(argv[1], "STOP") == 0) {
|
|
|
|
monkey_window_handle_stop(argc, argv);
|
2017-06-10 00:04:58 +03:00
|
|
|
} else if (strcmp(argv[1], "REDRAW") == 0) {
|
|
|
|
monkey_window_handle_redraw(argc, argv);
|
|
|
|
} else if (strcmp(argv[1], "RELOAD") == 0) {
|
|
|
|
monkey_window_handle_reload(argc, argv);
|
2019-05-05 17:59:30 +03:00
|
|
|
} else if (strcmp(argv[1], "EXEC") == 0) {
|
|
|
|
monkey_window_handle_exec(argc, argv);
|
2019-08-03 14:31:02 +03:00
|
|
|
} else if (strcmp(argv[1], "CLICK") == 0) {
|
|
|
|
monkey_window_handle_click(argc, argv);
|
2017-06-10 00:04:58 +03:00
|
|
|
} else {
|
2018-11-03 18:12:27 +03:00
|
|
|
moutf(MOUT_ERROR, "WINDOW COMMAND UNKNOWN %s\n", argv[1]);
|
2017-06-10 00:04:58 +03:00
|
|
|
}
|
2018-11-03 18:12:27 +03:00
|
|
|
|
2011-03-12 20:27:18 +03:00
|
|
|
}
|
2014-01-12 21:07:34 +04:00
|
|
|
|
2019-08-20 02:16:52 +03:00
|
|
|
/**
|
|
|
|
* process miscellaneous window events
|
|
|
|
*
|
|
|
|
* \param gw The window receiving the event.
|
|
|
|
* \param event The event code.
|
|
|
|
* \return NSERROR_OK when processed ok
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
gui_window_event(struct gui_window *gw, enum gui_window_event event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case GW_EVENT_UPDATE_EXTENT:
|
|
|
|
gui_window_update_extent(gw);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GW_EVENT_REMOVE_CARET:
|
|
|
|
gui_window_remove_caret(gw);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GW_EVENT_SCROLL_START:
|
|
|
|
gui_window_scroll_start(gw);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GW_EVENT_NEW_CONTENT:
|
|
|
|
gui_window_new_content(gw);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GW_EVENT_START_THROBBER:
|
|
|
|
gui_window_start_throbber(gw);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GW_EVENT_STOP_THROBBER:
|
|
|
|
gui_window_stop_throbber(gw);
|
|
|
|
break;
|
|
|
|
|
2019-12-01 20:05:08 +03:00
|
|
|
case GW_EVENT_PAGE_INFO_CHANGE:
|
|
|
|
gui_window_report_page_info(gw);
|
|
|
|
break;
|
|
|
|
|
2019-08-20 02:16:52 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
static struct gui_window_table window_table = {
|
2014-01-12 21:07:34 +04:00
|
|
|
.create = gui_window_create,
|
|
|
|
.destroy = gui_window_destroy,
|
2017-04-23 22:29:22 +03:00
|
|
|
.invalidate = monkey_window_invalidate_area,
|
2014-01-13 05:08:15 +04:00
|
|
|
.get_scroll = gui_window_get_scroll,
|
|
|
|
.set_scroll = gui_window_set_scroll,
|
2014-01-13 15:38:35 +04:00
|
|
|
.get_dimensions = gui_window_get_dimensions,
|
2019-08-20 02:16:52 +03:00
|
|
|
.event = gui_window_event,
|
2014-01-12 21:07:34 +04:00
|
|
|
|
|
|
|
.set_title = gui_window_set_title,
|
|
|
|
.set_url = gui_window_set_url,
|
|
|
|
.set_icon = gui_window_set_icon,
|
2014-01-13 18:51:27 +04:00
|
|
|
.set_status = gui_window_set_status,
|
|
|
|
.set_pointer = gui_window_set_pointer,
|
|
|
|
.place_caret = gui_window_place_caret,
|
2014-01-12 21:07:34 +04:00
|
|
|
.drag_start = gui_window_drag_start,
|
|
|
|
.save_link = gui_window_save_link,
|
2019-05-06 12:04:48 +03:00
|
|
|
|
|
|
|
.console_log = gui_window_console_log,
|
2014-01-12 21:07:34 +04:00
|
|
|
};
|
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
struct gui_window_table *monkey_window_table = &window_table;
|