2003-06-30 16:44:03 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2004-02-25 18:12:58 +03:00
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
2004-07-27 00:13:45 +04:00
|
|
|
* Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk>
|
2004-08-14 16:16:45 +04:00
|
|
|
* Copyright 2004 John Tytgat <John.Tytgat@aaug.net>
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Browser window creation and manipulation (implementation).
|
2002-09-11 18:24:02 +04:00
|
|
|
*/
|
|
|
|
|
2003-07-18 03:01:02 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
2003-10-09 19:23:10 +04:00
|
|
|
#include <stdbool.h>
|
2003-07-18 03:01:02 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2004-01-05 05:10:59 +03:00
|
|
|
#include "netsurf/utils/config.h"
|
2004-04-02 19:16:15 +04:00
|
|
|
#include "netsurf/content/fetch.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/content/fetchcache.h"
|
2003-10-11 18:33:35 +04:00
|
|
|
#include "netsurf/css/css.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_AUTH
|
2003-10-25 23:20:13 +04:00
|
|
|
#include "netsurf/desktop/401login.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/desktop/browser.h"
|
2004-05-05 02:23:44 +04:00
|
|
|
#include "netsurf/desktop/gui.h"
|
2004-03-27 01:16:31 +03:00
|
|
|
#include "netsurf/desktop/imagemap.h"
|
2004-10-02 01:31:55 +04:00
|
|
|
#include "netsurf/desktop/options.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
#include "netsurf/render/box.h"
|
2003-07-18 03:01:02 +04:00
|
|
|
#include "netsurf/render/font.h"
|
2003-10-25 04:35:49 +04:00
|
|
|
#include "netsurf/render/form.h"
|
2003-09-23 22:35:44 +04:00
|
|
|
#include "netsurf/render/layout.h"
|
2002-12-23 23:06:21 +03:00
|
|
|
#include "netsurf/utils/log.h"
|
2003-10-02 02:48:39 +04:00
|
|
|
#include "netsurf/utils/messages.h"
|
2004-03-02 21:02:41 +03:00
|
|
|
#include "netsurf/utils/url.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
#include "netsurf/utils/utils.h"
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
static void browser_window_callback(content_msg msg, struct content *c,
|
2004-04-25 03:42:32 +04:00
|
|
|
void *p1, void *p2, union content_msg_data data);
|
2004-06-28 03:24:11 +04:00
|
|
|
static void browser_window_convert_to_download(struct browser_window *bw);
|
2004-02-25 18:12:58 +03:00
|
|
|
static void browser_window_start_throbber(struct browser_window *bw);
|
|
|
|
static void browser_window_stop_throbber(struct browser_window *bw);
|
|
|
|
static void browser_window_update(struct browser_window *bw,
|
|
|
|
bool scroll_to_top);
|
|
|
|
static void browser_window_set_status(struct browser_window *bw,
|
|
|
|
const char *text);
|
2004-04-01 04:26:05 +04:00
|
|
|
static void browser_window_set_pointer(gui_pointer_shape shape);
|
2004-06-28 03:24:11 +04:00
|
|
|
static void download_window_callback(fetch_msg msg, void *p, const char *data,
|
|
|
|
unsigned long size);
|
2004-07-18 03:32:09 +04:00
|
|
|
static void browser_window_mouse_click_html(struct browser_window *bw,
|
|
|
|
browser_mouse_click click, int x, int y);
|
2004-10-18 01:11:29 +04:00
|
|
|
static void browser_window_mouse_drag_html(struct browser_window *bw,
|
|
|
|
int x, int y);
|
2004-11-20 03:02:56 +03:00
|
|
|
static const char *browser_window_scrollbar_click(struct browser_window *bw,
|
|
|
|
browser_mouse_click click, struct box *box,
|
|
|
|
int box_x, int box_y, int x, int y);
|
2004-07-18 21:38:01 +04:00
|
|
|
static void browser_radio_set(struct content *content,
|
|
|
|
struct form_control *radio);
|
|
|
|
static void browser_redraw_box(struct content *c, struct box *box);
|
2004-07-19 18:31:31 +04:00
|
|
|
static void browser_window_textarea_click(struct browser_window *bw,
|
|
|
|
struct box *textarea,
|
|
|
|
int box_x, int box_y,
|
|
|
|
int x, int y);
|
|
|
|
static void browser_window_textarea_callback(struct browser_window *bw,
|
2004-10-23 00:58:11 +04:00
|
|
|
wchar_t key, void *p);
|
2003-09-29 03:41:07 +04:00
|
|
|
static void browser_window_input_click(struct browser_window* bw,
|
2004-07-19 18:31:31 +04:00
|
|
|
struct box *input,
|
|
|
|
int box_x, int box_y,
|
|
|
|
int x, int y);
|
|
|
|
static void browser_window_input_callback(struct browser_window *bw,
|
2004-08-14 16:16:45 +04:00
|
|
|
wchar_t key, void *p);
|
2004-07-19 18:31:31 +04:00
|
|
|
static void browser_window_place_caret(struct browser_window *bw,
|
|
|
|
int x, int y, int height,
|
|
|
|
void (*callback)(struct browser_window *bw,
|
2004-08-14 16:16:45 +04:00
|
|
|
wchar_t key, void *p),
|
2004-07-19 18:31:31 +04:00
|
|
|
void *p);
|
2004-07-21 18:20:43 +04:00
|
|
|
static void browser_window_remove_caret(struct browser_window *bw);
|
2004-04-03 03:12:26 +04:00
|
|
|
static gui_pointer_shape get_pointer_shape(css_cursor cursor);
|
2004-07-19 18:31:31 +04:00
|
|
|
static void browser_form_submit(struct browser_window *bw, struct form *form,
|
|
|
|
struct form_control *submit_button);
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Create and open a new browser window with the given page.
|
|
|
|
*
|
2004-10-02 01:31:55 +04:00
|
|
|
* \param url URL to start fetching in the new window (copied)
|
|
|
|
* \param clone The browser window to clone
|
|
|
|
* \param referer The referring uri
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
2002-10-15 14:41:12 +04:00
|
|
|
|
2004-10-02 01:31:55 +04:00
|
|
|
void browser_window_create(const char *url, struct browser_window *clone,
|
|
|
|
char *referer)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
struct browser_window *bw;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-08-14 16:16:45 +04:00
|
|
|
if ((bw = malloc(sizeof *bw)) == NULL) {
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("NoMemory", 0);
|
2004-05-05 04:19:51 +04:00
|
|
|
return;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-08-14 16:16:45 +04:00
|
|
|
bw->current_content = NULL;
|
|
|
|
bw->loading_content = NULL;
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->history = history_create();
|
|
|
|
bw->throbbing = false;
|
2004-08-14 16:16:45 +04:00
|
|
|
bw->caret_callback = NULL;
|
|
|
|
bw->frag_id = NULL;
|
2004-10-18 01:11:29 +04:00
|
|
|
bw->drag_type = DRAGGING_NONE;
|
2004-08-26 03:56:49 +04:00
|
|
|
bw->scrolling_box = NULL;
|
2004-10-02 03:19:08 +04:00
|
|
|
bw->referer = NULL;
|
2004-08-14 16:16:45 +04:00
|
|
|
if ((bw->window = gui_create_browser_window(bw, clone)) == NULL) {
|
2004-02-25 18:12:58 +03:00
|
|
|
free(bw);
|
2004-05-05 04:19:51 +04:00
|
|
|
return;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2004-10-02 01:31:55 +04:00
|
|
|
browser_window_go(bw, url, referer);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start fetching a page in a browser window.
|
|
|
|
*
|
2004-10-01 04:06:49 +04:00
|
|
|
* \param bw browser window
|
|
|
|
* \param url URL to start fetching (copied)
|
2004-10-02 01:31:55 +04:00
|
|
|
* \param referer the referring uri
|
2004-02-25 18:12:58 +03:00
|
|
|
*
|
|
|
|
* Any existing fetches in the window are aborted.
|
|
|
|
*/
|
|
|
|
|
2004-10-01 04:06:49 +04:00
|
|
|
void browser_window_go(struct browser_window *bw, const char *url,
|
2004-10-02 01:31:55 +04:00
|
|
|
char* referer)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2004-10-01 04:06:49 +04:00
|
|
|
browser_window_go_post(bw, url, 0, 0, true, referer);
|
2002-10-15 14:41:12 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start fetching a page in a browser window, POSTing form data.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param url URL to start fetching (copied)
|
|
|
|
* \param post_urlenc url encoded post data, or 0 if none
|
|
|
|
* \param post_multipart multipart post data, or 0 if none
|
|
|
|
* \param history_add add to window history
|
2004-10-02 01:31:55 +04:00
|
|
|
* \param referer the referring uri
|
2004-02-25 18:12:58 +03:00
|
|
|
*
|
|
|
|
* Any existing fetches in the window are aborted.
|
|
|
|
*
|
|
|
|
* If post_urlenc and post_multipart are 0 the url is fetched using GET.
|
|
|
|
*
|
|
|
|
* The page is not added to the window history if add_history is false. This
|
|
|
|
* should be used when returning to a page in the window history.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_go_post(struct browser_window *bw, const char *url,
|
|
|
|
char *post_urlenc,
|
|
|
|
struct form_successful_control *post_multipart,
|
2004-10-02 01:31:55 +04:00
|
|
|
bool history_add, char *referer)
|
2002-10-15 14:41:12 +04:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
struct content *c;
|
2004-03-10 23:45:27 +03:00
|
|
|
char *url2;
|
2004-08-07 02:19:13 +04:00
|
|
|
char *hash;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2004-06-11 03:55:23 +04:00
|
|
|
|
|
|
|
LOG(("bw %p, url %s", bw, url));
|
2004-03-10 23:45:27 +03:00
|
|
|
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_normalize(url, &url2);
|
|
|
|
if (res != URL_FUNC_OK) {
|
2004-03-10 23:45:27 +03:00
|
|
|
LOG(("failed to normalize url %s", url));
|
|
|
|
return;
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2004-11-23 02:29:50 +03:00
|
|
|
browser_window_stop(bw);
|
|
|
|
browser_window_remove_caret(bw);
|
|
|
|
|
|
|
|
/* check we can actually handle this URL */
|
|
|
|
if (!fetch_can_fetch(url2)) {
|
|
|
|
gui_launch_url(url2);
|
|
|
|
free(url2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
hash = strchr(url2, '#');
|
|
|
|
if (bw->frag_id) {
|
|
|
|
free(bw->frag_id);
|
|
|
|
bw->frag_id = 0;
|
|
|
|
}
|
|
|
|
if (hash) {
|
|
|
|
bw->frag_id = strdup(hash+1);
|
|
|
|
}
|
|
|
|
|
2004-02-27 20:45:19 +03:00
|
|
|
browser_window_set_status(bw, messages_get("Loading"));
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->history_add = history_add;
|
|
|
|
bw->time0 = clock();
|
2004-06-11 03:55:23 +04:00
|
|
|
c = fetchcache(url2, browser_window_callback, bw, 0,
|
|
|
|
gui_window_get_width(bw->window), 0,
|
|
|
|
false,
|
|
|
|
post_urlenc, post_multipart, true);
|
2004-03-10 23:45:27 +03:00
|
|
|
free(url2);
|
2004-02-25 18:12:58 +03:00
|
|
|
if (!c) {
|
2004-06-11 03:55:23 +04:00
|
|
|
browser_window_set_status(bw, messages_get("NoMemory"));
|
|
|
|
warn_user("NoMemory", 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->loading_content = c;
|
|
|
|
browser_window_start_throbber(bw);
|
|
|
|
|
2004-10-02 03:19:08 +04:00
|
|
|
if (referer && referer != bw->referer) {
|
|
|
|
free(bw->referer);
|
|
|
|
bw->referer = strdup(referer);
|
|
|
|
}
|
|
|
|
|
2004-10-02 01:31:55 +04:00
|
|
|
fetchcache_go(c, option_send_referer ? referer : 0,
|
2004-10-01 04:06:49 +04:00
|
|
|
browser_window_callback, bw, 0,
|
2004-06-11 03:55:23 +04:00
|
|
|
post_urlenc, post_multipart, true);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Callback for fetchcache() for browser window fetches.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_callback(content_msg msg, struct content *c,
|
2004-07-20 00:40:11 +04:00
|
|
|
void *p1, void *p2, union content_msg_data data)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
struct browser_window *bw = p1;
|
|
|
|
char status[40];
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
switch (msg) {
|
|
|
|
case CONTENT_MSG_LOADING:
|
2004-06-28 03:24:11 +04:00
|
|
|
assert(bw->loading_content == c);
|
|
|
|
|
|
|
|
if (c->type == CONTENT_OTHER)
|
|
|
|
browser_window_convert_to_download(bw);
|
2004-09-30 20:48:04 +04:00
|
|
|
else
|
|
|
|
gui_window_set_url(bw->window, c->url);
|
2004-02-25 18:12:58 +03:00
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
case CONTENT_MSG_READY:
|
|
|
|
assert(bw->loading_content == c);
|
|
|
|
|
|
|
|
if (bw->current_content) {
|
|
|
|
if (bw->current_content->status ==
|
2004-08-12 02:08:26 +04:00
|
|
|
CONTENT_STATUS_READY ||
|
|
|
|
bw->current_content->status ==
|
2004-02-25 18:12:58 +03:00
|
|
|
CONTENT_STATUS_DONE)
|
2004-08-12 02:08:26 +04:00
|
|
|
content_close(bw->current_content);
|
2004-02-25 18:12:58 +03:00
|
|
|
content_remove_user(bw->current_content,
|
|
|
|
browser_window_callback,
|
|
|
|
bw, 0);
|
|
|
|
}
|
|
|
|
bw->current_content = c;
|
2004-08-14 16:16:45 +04:00
|
|
|
bw->loading_content = NULL;
|
|
|
|
bw->caret_callback = NULL;
|
2004-08-26 03:56:49 +04:00
|
|
|
bw->scrolling_box = NULL;
|
2004-07-16 20:33:45 +04:00
|
|
|
gui_window_new_content(bw->window);
|
2004-02-25 18:12:58 +03:00
|
|
|
gui_window_set_url(bw->window, c->url);
|
|
|
|
browser_window_update(bw, true);
|
2004-08-12 02:08:26 +04:00
|
|
|
content_open(c, bw, 0, 0, 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_set_status(bw, c->status_message);
|
|
|
|
if (bw->history_add)
|
2004-08-07 02:19:13 +04:00
|
|
|
history_add(bw->history, c, bw->frag_id);
|
2004-02-25 18:12:58 +03:00
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
case CONTENT_MSG_DONE:
|
|
|
|
assert(bw->current_content == c);
|
|
|
|
|
|
|
|
browser_window_update(bw, false);
|
2004-02-27 20:45:19 +03:00
|
|
|
sprintf(status, messages_get("Complete"),
|
2004-02-25 18:12:58 +03:00
|
|
|
((float) (clock() - bw->time0)) /
|
|
|
|
CLOCKS_PER_SEC);
|
|
|
|
browser_window_set_status(bw, status);
|
|
|
|
browser_window_stop_throbber(bw);
|
|
|
|
history_update(bw->history, c);
|
2004-07-03 21:30:28 +04:00
|
|
|
hotlist_visited(c);
|
2004-10-02 03:19:08 +04:00
|
|
|
free (bw->referer);
|
|
|
|
bw->referer = 0;
|
2004-02-25 18:12:58 +03:00
|
|
|
break;
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
case CONTENT_MSG_ERROR:
|
2004-04-25 03:42:32 +04:00
|
|
|
browser_window_set_status(bw, data.error);
|
2004-06-11 00:41:26 +04:00
|
|
|
warn_user(data.error, 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
if (c == bw->loading_content)
|
|
|
|
bw->loading_content = 0;
|
2004-08-26 03:56:49 +04:00
|
|
|
else if (c == bw->current_content) {
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->current_content = 0;
|
2004-08-26 03:56:49 +04:00
|
|
|
bw->caret_callback = NULL;
|
|
|
|
bw->scrolling_box = NULL;
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_stop_throbber(bw);
|
2004-10-02 03:19:08 +04:00
|
|
|
free (bw->referer);
|
|
|
|
bw->referer = 0;
|
2004-02-25 18:12:58 +03:00
|
|
|
break;
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
case CONTENT_MSG_STATUS:
|
|
|
|
browser_window_set_status(bw, c->status_message);
|
|
|
|
break;
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
case CONTENT_MSG_REDIRECT:
|
|
|
|
bw->loading_content = 0;
|
2004-02-27 20:45:19 +03:00
|
|
|
browser_window_set_status(bw,
|
|
|
|
messages_get("Redirecting"));
|
2004-10-02 01:31:55 +04:00
|
|
|
/* the spec says nothing about referrers and
|
|
|
|
* redirects => follow Mozilla and preserve the
|
2004-10-02 03:19:08 +04:00
|
|
|
* referer across the redirect */
|
|
|
|
browser_window_go(bw, data.redirect, bw->referer);
|
2004-02-25 18:12:58 +03:00
|
|
|
break;
|
2003-12-30 02:09:39 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
case CONTENT_MSG_REFORMAT:
|
|
|
|
browser_window_update(bw, false);
|
|
|
|
break;
|
2003-12-30 02:09:39 +03:00
|
|
|
|
2004-03-21 15:50:10 +03:00
|
|
|
case CONTENT_MSG_REDRAW:
|
2004-04-25 03:42:32 +04:00
|
|
|
gui_window_update_box(bw->window, &data);
|
2004-03-21 15:50:10 +03:00
|
|
|
break;
|
|
|
|
|
2004-08-11 23:02:32 +04:00
|
|
|
case CONTENT_MSG_NEWPTR:
|
|
|
|
bw->loading_content = c;
|
|
|
|
break;
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
#ifdef WITH_AUTH
|
|
|
|
case CONTENT_MSG_AUTH:
|
2004-04-25 03:42:32 +04:00
|
|
|
gui_401login_open(bw, c, data.auth_realm);
|
2004-02-25 18:12:58 +03:00
|
|
|
if (c == bw->loading_content)
|
|
|
|
bw->loading_content = 0;
|
2004-08-26 03:56:49 +04:00
|
|
|
else if (c == bw->current_content) {
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->current_content = 0;
|
2004-08-26 03:56:49 +04:00
|
|
|
bw->caret_callback = NULL;
|
|
|
|
bw->scrolling_box = NULL;
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_stop_throbber(bw);
|
2004-10-02 03:19:08 +04:00
|
|
|
free (bw->referer);
|
|
|
|
bw->referer = 0;
|
2004-02-25 18:12:58 +03:00
|
|
|
break;
|
2003-12-30 02:09:39 +03:00
|
|
|
#endif
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Transfer the loading_content to a new download window.
|
|
|
|
*/
|
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
void browser_window_convert_to_download(struct browser_window *bw)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2004-06-28 03:24:11 +04:00
|
|
|
struct gui_download_window *download_window;
|
2004-02-25 18:12:58 +03:00
|
|
|
struct content *c = bw->loading_content;
|
2004-06-28 03:24:11 +04:00
|
|
|
struct fetch *fetch;
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
assert(c);
|
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
fetch = c->fetch;
|
|
|
|
|
|
|
|
if (fetch) {
|
|
|
|
/* create download window */
|
|
|
|
download_window = gui_download_window_create(c->url,
|
|
|
|
c->mime_type, fetch, c->total_size);
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
if (download_window) {
|
|
|
|
/* extract fetch from content */
|
|
|
|
c->fetch = 0;
|
|
|
|
c->fresh = false;
|
|
|
|
fetch_change_callback(fetch, download_window_callback,
|
|
|
|
download_window);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* must already be a download window for this fetch */
|
|
|
|
/** \todo open it at top of stack */
|
|
|
|
}
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/* remove content from browser window */
|
|
|
|
bw->loading_content = 0;
|
|
|
|
content_remove_user(c, browser_window_callback, bw, 0);
|
|
|
|
browser_window_stop_throbber(bw);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the busy indicator.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_start_throbber(struct browser_window *bw)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
bw->throbbing = true;
|
|
|
|
gui_window_start_throbber(bw->window);
|
|
|
|
}
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Stop the busy indicator.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
void browser_window_stop_throbber(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
bw->throbbing = false;
|
|
|
|
gui_window_stop_throbber(bw->window);
|
|
|
|
}
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Redraw browser window, set extent to content, and update title.
|
|
|
|
*
|
|
|
|
* \param bw browser_window
|
|
|
|
* \param scroll_to_top move view to top of page
|
|
|
|
*/
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
void browser_window_update(struct browser_window *bw,
|
|
|
|
bool scroll_to_top)
|
|
|
|
{
|
2004-10-23 00:58:11 +04:00
|
|
|
char *title_local_enc;
|
2004-08-07 02:19:13 +04:00
|
|
|
struct box *pos;
|
|
|
|
int x, y;
|
2004-07-06 00:19:52 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
if (!bw->current_content)
|
|
|
|
return;
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2004-07-06 00:19:52 +04:00
|
|
|
if (bw->current_content->title != NULL
|
|
|
|
&& (title_local_enc = cnv_str_local_enc(bw->current_content->title)) != NULL) {
|
|
|
|
gui_window_set_title(bw->window, title_local_enc);
|
2004-10-23 00:58:11 +04:00
|
|
|
free(title_local_enc);
|
2004-07-06 00:19:52 +04:00
|
|
|
} else
|
2004-02-25 18:12:58 +03:00
|
|
|
gui_window_set_title(bw->window, bw->current_content->url);
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
gui_window_set_extent(bw->window, bw->current_content->width,
|
|
|
|
bw->current_content->height);
|
2004-01-05 05:10:59 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
if (scroll_to_top)
|
|
|
|
gui_window_set_scroll(bw->window, 0, 0);
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
/* if frag_id exists, then try to scroll to it */
|
|
|
|
if (bw->frag_id && bw->current_content->type == CONTENT_HTML) {
|
2004-10-18 01:11:29 +04:00
|
|
|
if ((pos = box_find_by_id(bw->current_content->data.html.layout, bw->frag_id)) != 0) {
|
2004-08-07 02:19:13 +04:00
|
|
|
box_coords(pos, &x, &y);
|
|
|
|
gui_window_set_scroll(bw->window, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
gui_window_redraw_window(bw->window);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2002-12-23 23:06:21 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Stop all fetching activity in a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
void browser_window_stop(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
if (bw->loading_content) {
|
|
|
|
content_remove_user(bw->loading_content,
|
|
|
|
browser_window_callback, bw, 0);
|
|
|
|
bw->loading_content = 0;
|
|
|
|
}
|
2003-12-28 19:17:31 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
if (bw->current_content &&
|
|
|
|
bw->current_content->status != CONTENT_STATUS_DONE) {
|
|
|
|
assert(bw->current_content->status == CONTENT_STATUS_READY);
|
2004-06-21 03:09:52 +04:00
|
|
|
content_stop(bw->current_content,
|
|
|
|
browser_window_callback, bw, 0);
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2003-12-22 01:10:15 +03:00
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
browser_window_stop_throbber(bw);
|
|
|
|
}
|
2003-10-25 23:20:13 +04:00
|
|
|
|
|
|
|
|
2004-06-23 00:39:16 +04:00
|
|
|
/**
|
|
|
|
* Reload the page in a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
2004-06-29 23:08:19 +04:00
|
|
|
* \param all whether to reload all objects associated with the page
|
2004-06-23 00:39:16 +04:00
|
|
|
*/
|
|
|
|
|
2004-06-29 23:08:19 +04:00
|
|
|
void browser_window_reload(struct browser_window *bw, bool all)
|
2004-06-23 00:39:16 +04:00
|
|
|
{
|
2004-06-29 23:08:19 +04:00
|
|
|
struct content *c;
|
|
|
|
unsigned int i;
|
|
|
|
|
2004-06-23 00:39:16 +04:00
|
|
|
if (!bw->current_content || bw->loading_content)
|
|
|
|
return;
|
|
|
|
|
2004-06-29 23:08:19 +04:00
|
|
|
if (all && bw->current_content->type == CONTENT_HTML) {
|
|
|
|
c = bw->current_content;
|
|
|
|
/* invalidate objects */
|
|
|
|
for (i=0; i!=c->data.html.object_count; i++) {
|
|
|
|
if (c->data.html.object[i].content != 0)
|
|
|
|
c->data.html.object[i].content->fresh = false;
|
|
|
|
}
|
|
|
|
/* invalidate stylesheets */
|
2004-07-31 03:40:01 +04:00
|
|
|
for (i=STYLESHEET_START;
|
|
|
|
i!=c->data.html.stylesheet_count; i++) {
|
2004-06-29 23:08:19 +04:00
|
|
|
if (c->data.html.stylesheet_content[i] != 0)
|
|
|
|
c->data.html.stylesheet_content[i]->fresh = false;
|
|
|
|
}
|
|
|
|
}
|
2004-06-23 00:39:16 +04:00
|
|
|
bw->current_content->fresh = false;
|
2004-10-02 01:31:55 +04:00
|
|
|
browser_window_go_post(bw, bw->current_content->url, 0, 0, false, 0);
|
2004-06-23 00:39:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
/**
|
|
|
|
* Change the status bar of a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param text new status text (copied)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_set_status(struct browser_window *bw, const char *text)
|
|
|
|
{
|
|
|
|
gui_window_set_status(bw->window, text);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
|
2004-04-01 04:26:05 +04:00
|
|
|
/**
|
|
|
|
* Change the shape of the mouse pointer
|
|
|
|
*
|
|
|
|
* \param shape shape to use
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_set_pointer(gui_pointer_shape shape)
|
|
|
|
{
|
|
|
|
gui_window_set_pointer(shape);
|
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Close and destroy a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_destroy(struct browser_window *bw)
|
2003-10-25 18:13:49 +04:00
|
|
|
{
|
2004-02-25 18:12:58 +03:00
|
|
|
if (bw->loading_content) {
|
|
|
|
content_remove_user(bw->loading_content,
|
|
|
|
browser_window_callback, bw, 0);
|
|
|
|
bw->loading_content = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bw->current_content) {
|
2004-08-12 02:08:26 +04:00
|
|
|
if (bw->current_content->status == CONTENT_STATUS_READY ||
|
|
|
|
bw->current_content->status ==
|
|
|
|
CONTENT_STATUS_DONE)
|
|
|
|
content_close(bw->current_content);
|
2004-02-25 18:12:58 +03:00
|
|
|
content_remove_user(bw->current_content,
|
|
|
|
browser_window_callback, bw, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
history_destroy(bw->history);
|
|
|
|
gui_window_destroy(bw->window);
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
free(bw->frag_id);
|
2004-02-25 18:12:58 +03:00
|
|
|
free(bw);
|
2003-10-25 18:13:49 +04:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:12:58 +03:00
|
|
|
|
|
|
|
/**
|
2004-06-28 03:24:11 +04:00
|
|
|
* Callback for fetch for download window fetches.
|
2004-02-25 18:12:58 +03:00
|
|
|
*/
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
void download_window_callback(fetch_msg msg, void *p, const char *data,
|
|
|
|
unsigned long size)
|
2003-08-28 23:21:27 +04:00
|
|
|
{
|
2004-06-28 03:24:11 +04:00
|
|
|
struct gui_download_window *download_window = p;
|
2003-08-28 23:21:27 +04:00
|
|
|
|
|
|
|
switch (msg) {
|
2004-07-10 06:35:31 +04:00
|
|
|
case FETCH_PROGRESS:
|
|
|
|
break;
|
2004-06-28 03:24:11 +04:00
|
|
|
case FETCH_DATA:
|
|
|
|
gui_download_window_data(download_window, data, size);
|
2003-08-28 23:21:27 +04:00
|
|
|
break;
|
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
case FETCH_FINISHED:
|
2003-08-28 23:21:27 +04:00
|
|
|
gui_download_window_done(download_window);
|
|
|
|
break;
|
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
case FETCH_ERROR:
|
|
|
|
gui_download_window_error(download_window, data);
|
2003-08-28 23:21:27 +04:00
|
|
|
break;
|
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
case FETCH_TYPE:
|
|
|
|
case FETCH_REDIRECT:
|
|
|
|
case FETCH_AUTH:
|
|
|
|
default:
|
|
|
|
/* not possible */
|
2003-08-28 23:21:27 +04:00
|
|
|
assert(0);
|
|
|
|
break;
|
2004-07-20 00:40:11 +04:00
|
|
|
}
|
2003-08-28 23:21:27 +04:00
|
|
|
}
|
|
|
|
|
2004-06-28 03:24:11 +04:00
|
|
|
|
2004-07-18 03:32:09 +04:00
|
|
|
/**
|
|
|
|
* Handle mouse clicks in a browser window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param click type of mouse click
|
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_mouse_click(struct browser_window *bw,
|
|
|
|
browser_mouse_click click, int x, int y)
|
|
|
|
{
|
|
|
|
if (!bw->current_content)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (bw->current_content->type == CONTENT_HTML)
|
|
|
|
browser_window_mouse_click_html(bw, click, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle mouse clicks in an HTML content window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param click type of mouse click
|
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_mouse_click_html(struct browser_window *bw,
|
|
|
|
browser_mouse_click click, int x, int y)
|
|
|
|
{
|
|
|
|
char *base_url = 0;
|
|
|
|
char *href = 0;
|
|
|
|
char *title = 0;
|
2004-07-18 21:38:01 +04:00
|
|
|
char *url;
|
2004-07-18 03:32:09 +04:00
|
|
|
char status_buffer[200];
|
2004-07-18 21:38:01 +04:00
|
|
|
const char *status = 0;
|
2004-07-18 03:32:09 +04:00
|
|
|
gui_pointer_shape pointer = GUI_POINTER_DEFAULT;
|
2004-07-18 21:38:01 +04:00
|
|
|
int box_x = 0, box_y = 0;
|
2004-07-19 18:31:31 +04:00
|
|
|
int gadget_box_x = 0, gadget_box_y = 0;
|
2004-11-20 03:02:56 +03:00
|
|
|
int scroll_box_x = 0, scroll_box_y = 0;
|
2004-07-18 21:38:01 +04:00
|
|
|
struct box *gadget_box = 0;
|
2004-11-20 03:02:56 +03:00
|
|
|
struct box *scroll_box = 0;
|
2004-07-18 21:38:01 +04:00
|
|
|
struct content *c = bw->current_content;
|
2004-08-26 03:56:49 +04:00
|
|
|
struct box *box;
|
2004-07-18 21:38:01 +04:00
|
|
|
struct content *content = c;
|
|
|
|
struct content *gadget_content = c;
|
|
|
|
struct form_control *gadget = 0;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2004-07-18 03:32:09 +04:00
|
|
|
|
2004-08-26 03:56:49 +04:00
|
|
|
if (click == BROWSER_MOUSE_DRAG) {
|
2004-10-18 01:11:29 +04:00
|
|
|
browser_window_mouse_drag_html(bw, x, y);
|
2004-08-26 03:56:49 +04:00
|
|
|
return;
|
2004-10-18 01:11:29 +04:00
|
|
|
}
|
2004-08-26 03:56:49 +04:00
|
|
|
|
2004-10-18 01:11:29 +04:00
|
|
|
bw->drag_type = DRAGGING_NONE;
|
2004-08-26 03:56:49 +04:00
|
|
|
bw->scrolling_box = NULL;
|
|
|
|
/* search the box tree for a link, imagemap, form control, or
|
2004-10-18 01:11:29 +04:00
|
|
|
* box with scrollbars */
|
2004-08-26 03:56:49 +04:00
|
|
|
box = c->data.html.layout;
|
|
|
|
while ((box = box_at_point(box, x, y, &box_x, &box_y, &content)) !=
|
|
|
|
NULL) {
|
2004-07-18 03:32:09 +04:00
|
|
|
if (box->style &&
|
|
|
|
box->style->visibility == CSS_VISIBILITY_HIDDEN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (box->href) {
|
|
|
|
base_url = content->data.html.base_url;
|
|
|
|
href = box->href;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (box->usemap) {
|
|
|
|
base_url = content->data.html.base_url;
|
|
|
|
href = imagemap_get(content, box->usemap,
|
|
|
|
box_x, box_y, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (box->gadget) {
|
|
|
|
gadget_content = content;
|
|
|
|
base_url = content->data.html.base_url;
|
|
|
|
gadget = box->gadget;
|
2004-07-18 04:12:18 +04:00
|
|
|
gadget_box = box;
|
2004-07-19 18:31:31 +04:00
|
|
|
gadget_box_x = box_x;
|
|
|
|
gadget_box_y = box_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (box->title)
|
|
|
|
title = box->title;
|
|
|
|
|
|
|
|
if (box->style && box->style->cursor != CSS_CURSOR_UNKNOWN)
|
|
|
|
pointer = get_pointer_shape(box->style->cursor);
|
2004-08-26 03:56:49 +04:00
|
|
|
|
2004-11-20 03:02:56 +03:00
|
|
|
if (box->style && box->type != BOX_BR &&
|
|
|
|
box->type != BOX_INLINE &&
|
|
|
|
(box->style->overflow == CSS_OVERFLOW_SCROLL ||
|
|
|
|
box->style->overflow == CSS_OVERFLOW_AUTO) &&
|
|
|
|
((box_vscrollbar_present(box) &&
|
|
|
|
box_x + box->scroll_x + box->padding[LEFT] +
|
|
|
|
box->width < x) ||
|
|
|
|
(box_hscrollbar_present(box) &&
|
|
|
|
box_y + box->scroll_y + box->padding[TOP] +
|
|
|
|
box->height < y))) {
|
|
|
|
scroll_box = box;
|
|
|
|
scroll_box_x = box_x + box->scroll_x;
|
|
|
|
scroll_box_y = box_y + box->scroll_y;
|
2004-08-26 03:56:49 +04:00
|
|
|
}
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
|
2004-11-20 03:02:56 +03:00
|
|
|
if (scroll_box) {
|
|
|
|
status = browser_window_scrollbar_click(bw, click, scroll_box,
|
|
|
|
scroll_box_x, scroll_box_y,
|
|
|
|
x - scroll_box_x, y - scroll_box_y);
|
2004-10-18 01:11:29 +04:00
|
|
|
|
|
|
|
} else if (gadget) {
|
2004-07-18 03:32:09 +04:00
|
|
|
switch (gadget->type) {
|
|
|
|
case GADGET_SELECT:
|
|
|
|
status = messages_get("FormSelect");
|
|
|
|
pointer = GUI_POINTER_MENU;
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
gui_create_form_select_menu(bw, gadget);
|
|
|
|
break;
|
|
|
|
case GADGET_CHECKBOX:
|
|
|
|
status = messages_get("FormCheckbox");
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1) {
|
|
|
|
gadget->selected = !gadget->selected;
|
2004-07-18 21:38:01 +04:00
|
|
|
browser_redraw_box(gadget_content, gadget_box);
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GADGET_RADIO:
|
|
|
|
status = messages_get("FormRadio");
|
2004-07-18 21:38:01 +04:00
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
browser_radio_set(gadget_content, gadget);
|
2004-07-18 03:32:09 +04:00
|
|
|
break;
|
|
|
|
case GADGET_IMAGE:
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1) {
|
2004-07-19 18:31:31 +04:00
|
|
|
gadget->data.image.mx = x - gadget_box_x;
|
|
|
|
gadget->data.image.my = y - gadget_box_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
/* drop through */
|
|
|
|
case GADGET_SUBMIT:
|
|
|
|
if (gadget->form) {
|
2004-11-20 03:02:56 +03:00
|
|
|
res = url_join(gadget->form->action, base_url,
|
|
|
|
&url);
|
2004-07-18 03:32:09 +04:00
|
|
|
snprintf(status_buffer, sizeof status_buffer,
|
|
|
|
messages_get("FormSubmit"),
|
2004-08-09 20:11:58 +04:00
|
|
|
(res == URL_FUNC_OK) ? url :
|
2004-07-18 03:32:09 +04:00
|
|
|
gadget->form->action);
|
|
|
|
status = status_buffer;
|
|
|
|
pointer = GUI_POINTER_POINT;
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
browser_form_submit(bw, gadget->form,
|
|
|
|
gadget);
|
|
|
|
} else {
|
|
|
|
status = messages_get("FormBadSubmit");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GADGET_TEXTAREA:
|
|
|
|
status = messages_get("FormTextarea");
|
|
|
|
pointer = GUI_POINTER_CARET;
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
browser_window_textarea_click(bw,
|
2004-07-19 18:31:31 +04:00
|
|
|
gadget_box,
|
|
|
|
gadget_box_x,
|
|
|
|
gadget_box_y,
|
|
|
|
x - gadget_box_x,
|
|
|
|
y - gadget_box_y);
|
2004-07-18 03:32:09 +04:00
|
|
|
break;
|
|
|
|
case GADGET_TEXTBOX:
|
|
|
|
case GADGET_PASSWORD:
|
|
|
|
status = messages_get("FormTextbox");
|
|
|
|
pointer = GUI_POINTER_CARET;
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
browser_window_input_click(bw,
|
2004-07-19 18:31:31 +04:00
|
|
|
gadget_box,
|
|
|
|
gadget_box_x,
|
|
|
|
gadget_box_y,
|
|
|
|
x - gadget_box_x,
|
|
|
|
y - gadget_box_y);
|
2004-07-18 03:32:09 +04:00
|
|
|
break;
|
|
|
|
case GADGET_HIDDEN:
|
|
|
|
/* not possible: no box generated */
|
|
|
|
break;
|
|
|
|
case GADGET_RESET:
|
|
|
|
status = messages_get("FormReset");
|
|
|
|
break;
|
|
|
|
case GADGET_FILE:
|
|
|
|
status = messages_get("FormFile");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (href) {
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(href, base_url, &url);
|
|
|
|
if (res != URL_FUNC_OK)
|
2004-07-18 03:32:09 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (title) {
|
|
|
|
snprintf(status_buffer, sizeof status_buffer, "%s: %s",
|
|
|
|
title, url);
|
|
|
|
status = status_buffer;
|
|
|
|
} else
|
|
|
|
status = url;
|
|
|
|
|
|
|
|
pointer = GUI_POINTER_POINT;
|
|
|
|
|
2004-11-23 02:29:50 +03:00
|
|
|
if (click == BROWSER_MOUSE_CLICK_1) {
|
|
|
|
browser_window_go(bw, url, c->url);
|
|
|
|
}
|
|
|
|
else if (click == BROWSER_MOUSE_CLICK_2) {
|
|
|
|
browser_window_create(url, bw, c->url);
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (title) {
|
|
|
|
status = title;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (bw->loading_content)
|
|
|
|
status = bw->loading_content->status_message;
|
|
|
|
else
|
|
|
|
status = c->status_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(status);
|
|
|
|
|
|
|
|
browser_window_set_status(bw, status);
|
|
|
|
browser_window_set_pointer(pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-18 01:11:29 +04:00
|
|
|
/**
|
|
|
|
* Handle mouse drags in an HTML content window.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_mouse_drag_html(struct browser_window *bw,
|
|
|
|
int x, int y)
|
|
|
|
{
|
2004-11-20 03:02:56 +03:00
|
|
|
int scroll_x, scroll_y;
|
2004-10-18 01:11:29 +04:00
|
|
|
struct box *box;
|
|
|
|
|
|
|
|
if (bw->drag_type == DRAGGING_VSCROLL) {
|
|
|
|
box = bw->scrolling_box;
|
|
|
|
assert(box);
|
2004-11-20 03:02:56 +03:00
|
|
|
scroll_y = bw->scrolling_start_scroll_y +
|
|
|
|
(float) (y - bw->scrolling_start_y) /
|
|
|
|
(float) bw->scrolling_well_height *
|
|
|
|
(float) (box->descendant_y1 -
|
|
|
|
box->descendant_y0);
|
2004-10-18 01:11:29 +04:00
|
|
|
if (scroll_y < box->descendant_y0)
|
|
|
|
scroll_y = box->descendant_y0;
|
|
|
|
else if (box->descendant_y1 - box->height < scroll_y)
|
|
|
|
scroll_y = box->descendant_y1 - box->height;
|
|
|
|
if (scroll_y == box->scroll_y)
|
|
|
|
return;
|
|
|
|
box->scroll_y = scroll_y;
|
2004-11-20 03:02:56 +03:00
|
|
|
browser_redraw_box(bw->current_content, bw->scrolling_box);
|
2004-10-18 01:11:29 +04:00
|
|
|
|
2004-11-20 03:02:56 +03:00
|
|
|
} else if (bw->drag_type == DRAGGING_HSCROLL) {
|
|
|
|
box = bw->scrolling_box;
|
|
|
|
assert(box);
|
|
|
|
scroll_x = bw->scrolling_start_scroll_x +
|
|
|
|
(float) (x - bw->scrolling_start_x) /
|
|
|
|
(float) bw->scrolling_well_width *
|
|
|
|
(float) (box->descendant_x1 -
|
|
|
|
box->descendant_x0);
|
|
|
|
if (scroll_x < box->descendant_x0)
|
|
|
|
scroll_x = box->descendant_x0;
|
|
|
|
else if (box->descendant_x1 - box->width < scroll_x)
|
|
|
|
scroll_x = box->descendant_x1 - box->width;
|
|
|
|
if (scroll_x == box->scroll_x)
|
|
|
|
return;
|
|
|
|
box->scroll_x = scroll_x;
|
2004-10-18 01:11:29 +04:00
|
|
|
browser_redraw_box(bw->current_content, bw->scrolling_box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-20 03:02:56 +03:00
|
|
|
/**
|
|
|
|
* Handle mouse clicks in a box scrollbar.
|
|
|
|
*
|
|
|
|
* \param bw browser window
|
|
|
|
* \param click type of mouse click
|
|
|
|
* \param box scrolling box
|
|
|
|
* \param box_x position of box in global document coordinates
|
|
|
|
* \param box_y position of box in global document coordinates
|
|
|
|
* \param x coordinate of click relative to box position
|
|
|
|
* \param y coordinate of click relative to box position
|
|
|
|
* \return status bar message
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *browser_window_scrollbar_click(struct browser_window *bw,
|
|
|
|
browser_mouse_click click, struct box *box,
|
|
|
|
int box_x, int box_y, int x, int y)
|
|
|
|
{
|
|
|
|
const int w = SCROLLBAR_WIDTH;
|
|
|
|
bool vscroll, hscroll;
|
|
|
|
int well_height, bar_top, bar_height;
|
|
|
|
int well_width, bar_left, bar_width;
|
|
|
|
const char *status = 0;
|
|
|
|
bool vert;
|
|
|
|
int z, scroll, bar_start, bar_size, well_size, page;
|
|
|
|
|
|
|
|
box_scrollbar_dimensions(box,
|
|
|
|
box->padding[LEFT] + box->width + box->padding[RIGHT],
|
|
|
|
box->padding[TOP] + box->height + box->padding[BOTTOM],
|
|
|
|
w,
|
|
|
|
&vscroll, &hscroll,
|
|
|
|
&well_height, &bar_top, &bar_height,
|
|
|
|
&well_width, &bar_left, &bar_width);
|
|
|
|
|
|
|
|
/* store some data for scroll drags */
|
|
|
|
bw->scrolling_box = box;
|
|
|
|
bw->scrolling_start_x = box_x + x;
|
|
|
|
bw->scrolling_start_y = box_y + y;
|
|
|
|
bw->scrolling_start_scroll_x = box->scroll_x;
|
|
|
|
bw->scrolling_start_scroll_y = box->scroll_y;
|
|
|
|
bw->scrolling_well_width = well_width;
|
|
|
|
bw->scrolling_well_height = well_height;
|
|
|
|
|
|
|
|
/* determine which scrollbar was clicked */
|
|
|
|
if (box_vscrollbar_present(box) &&
|
|
|
|
box->padding[LEFT] + box->width < x) {
|
|
|
|
vert = true;
|
|
|
|
z = y;
|
|
|
|
scroll = box->scroll_y;
|
|
|
|
well_size = well_height;
|
|
|
|
bar_start = bar_top;
|
|
|
|
bar_size = bar_height;
|
|
|
|
page = box->height;
|
|
|
|
} else {
|
|
|
|
vert = false;
|
|
|
|
z = x;
|
|
|
|
scroll = box->scroll_x;
|
|
|
|
well_size = well_width;
|
|
|
|
bar_start = bar_left;
|
|
|
|
bar_size = bar_width;
|
|
|
|
page = box->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find icon in scrollbar and calculate scroll */
|
|
|
|
if (z < w) {
|
|
|
|
status = messages_get(vert ? "ScrollUp" : "ScrollLeft");
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
scroll -= 16;
|
|
|
|
else if (click == BROWSER_MOUSE_CLICK_2)
|
|
|
|
scroll += 16;
|
|
|
|
} else if (z < w + bar_start + w / 4) {
|
|
|
|
status = messages_get(vert ? "ScrollPUp" : "ScrollPLeft");
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
scroll -= page;
|
|
|
|
else if (click == BROWSER_MOUSE_CLICK_2)
|
|
|
|
scroll += page;
|
|
|
|
} else if (z < w + bar_start + bar_size - w / 4) {
|
|
|
|
status = messages_get(vert ? "ScrollV" : "ScrollH");
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
bw->drag_type = vert ? DRAGGING_VSCROLL :
|
|
|
|
DRAGGING_HSCROLL;
|
|
|
|
} else if (z < w + well_size) {
|
|
|
|
status = messages_get(vert ? "ScrollPDown" : "ScrollPRight");
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
scroll += page;
|
|
|
|
else if (click == BROWSER_MOUSE_CLICK_2)
|
|
|
|
scroll -= page;
|
|
|
|
} else {
|
|
|
|
status = messages_get(vert ? "ScrollDown" : "ScrollRight");
|
|
|
|
if (click == BROWSER_MOUSE_CLICK_1)
|
|
|
|
scroll += 16;
|
|
|
|
else if (click == BROWSER_MOUSE_CLICK_2)
|
|
|
|
scroll -= 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update box and redraw */
|
|
|
|
if (vert) {
|
|
|
|
if (scroll < box->descendant_y0)
|
|
|
|
scroll = box->descendant_y0;
|
|
|
|
else if (box->descendant_y1 - box->height < scroll)
|
|
|
|
scroll = box->descendant_y1 - box->height;
|
|
|
|
if (scroll != box->scroll_y) {
|
|
|
|
box->scroll_y = scroll;
|
|
|
|
browser_redraw_box(bw->current_content, box);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (scroll < box->descendant_x0)
|
|
|
|
scroll = box->descendant_x0;
|
|
|
|
else if (box->descendant_x1 - box->width < scroll)
|
|
|
|
scroll = box->descendant_x1 - box->width;
|
|
|
|
if (scroll != box->scroll_x) {
|
|
|
|
box->scroll_x = scroll;
|
|
|
|
browser_redraw_box(bw->current_content, box);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
/**
|
|
|
|
* Set a radio form control and clear the others in the group.
|
|
|
|
*
|
|
|
|
* \param content content containing the form, of type CONTENT_TYPE
|
|
|
|
* \param radio form control of type GADGET_RADIO
|
|
|
|
*/
|
2004-07-18 03:32:09 +04:00
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
void browser_radio_set(struct content *content,
|
|
|
|
struct form_control *radio)
|
2002-12-31 01:56:30 +03:00
|
|
|
{
|
2004-07-18 21:38:01 +04:00
|
|
|
struct form_control *control;
|
|
|
|
|
2004-11-20 03:02:56 +03:00
|
|
|
assert(content);
|
|
|
|
assert(radio);
|
|
|
|
if (!radio->form)
|
2004-09-30 20:48:04 +04:00
|
|
|
return;
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
if (radio->selected)
|
2002-12-31 01:56:30 +03:00
|
|
|
return;
|
2004-07-18 21:38:01 +04:00
|
|
|
|
|
|
|
for (control = radio->form->controls; control;
|
|
|
|
control = control->next) {
|
|
|
|
if (control->type != GADGET_RADIO)
|
|
|
|
continue;
|
|
|
|
if (control == radio)
|
|
|
|
continue;
|
|
|
|
if (strcmp(control->name, radio->name) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (control->selected) {
|
|
|
|
control->selected = false;
|
|
|
|
browser_redraw_box(content, control->box);
|
2002-12-31 01:56:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
radio->selected = true;
|
|
|
|
browser_redraw_box(content, radio->box);
|
2002-12-31 01:56:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
/**
|
|
|
|
* Redraw a box.
|
|
|
|
*
|
|
|
|
* \param c content containing the box, of type CONTENT_HTML
|
|
|
|
* \param box box to redraw
|
|
|
|
*/
|
2003-04-12 16:38:32 +04:00
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
void browser_redraw_box(struct content *c, struct box *box)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
union content_msg_data data;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
box_coords(box, &x, &y);
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
data.redraw.x = x;
|
|
|
|
data.redraw.y = y;
|
2004-10-18 01:11:29 +04:00
|
|
|
data.redraw.width = box->padding[LEFT] + box->width +
|
|
|
|
box->padding[RIGHT];
|
|
|
|
data.redraw.height = box->padding[TOP] + box->height +
|
|
|
|
box->padding[BOTTOM];
|
2004-07-18 21:38:01 +04:00
|
|
|
|
|
|
|
data.redraw.full_redraw = true;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
data.redraw.object = c;
|
|
|
|
data.redraw.object_x = 0;
|
|
|
|
data.redraw.object_y = 0;
|
|
|
|
data.redraw.object_width = c->width;
|
|
|
|
data.redraw.object_height = c->height;
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_REDRAW, data);
|
2003-02-09 22:33:32 +03:00
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
}
|
2002-12-31 01:56:30 +03:00
|
|
|
|
2003-09-23 01:55:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks in a text area by placing the caret.
|
2004-07-19 18:31:31 +04:00
|
|
|
*
|
|
|
|
* \param bw browser window where click occurred
|
|
|
|
* \param textarea textarea box
|
|
|
|
* \param box_x position of textarea in global document coordinates
|
|
|
|
* \param box_y position of textarea in global document coordinates
|
|
|
|
* \param x coordinate of click relative to textarea
|
|
|
|
* \param y coordinate of click relative to textarea
|
2003-09-23 01:55:08 +04:00
|
|
|
*/
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
void browser_window_textarea_click(struct browser_window *bw,
|
|
|
|
struct box *textarea,
|
|
|
|
int box_x, int box_y,
|
|
|
|
int x, int y)
|
2003-09-23 01:55:08 +04:00
|
|
|
{
|
2004-07-19 18:31:31 +04:00
|
|
|
/* A textarea is an INLINE_BLOCK containing a single INLINE_CONTAINER,
|
|
|
|
* which contains the text as runs of INLINE separated by BR. There is
|
|
|
|
* at least one INLINE. The first and last boxes are INLINE.
|
|
|
|
* Consecutive BR may not be present. These constraints are satisfied
|
|
|
|
* by using a 0-length INLINE for blank lines. */
|
2003-09-23 01:55:08 +04:00
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
int char_offset = 0, pixel_offset = 0, new_scroll_y;
|
2004-07-19 18:31:31 +04:00
|
|
|
struct box *inline_container, *text_box;
|
|
|
|
|
|
|
|
inline_container = textarea->children;
|
2003-09-23 01:55:08 +04:00
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
if (inline_container->y + inline_container->height < y) {
|
2003-09-23 01:55:08 +04:00
|
|
|
/* below the bottom of the textarea: place caret at end */
|
|
|
|
text_box = inline_container->last;
|
|
|
|
assert(text_box->type == BOX_INLINE);
|
|
|
|
assert(text_box->text && text_box->font);
|
2004-07-06 00:19:52 +04:00
|
|
|
nsfont_position_in_string(text_box->font, text_box->text,
|
2003-12-27 04:06:46 +03:00
|
|
|
text_box->length,
|
|
|
|
(unsigned int)textarea->width,
|
2003-09-23 01:55:08 +04:00
|
|
|
&char_offset, &pixel_offset);
|
|
|
|
} else {
|
|
|
|
/* find the relevant text box */
|
|
|
|
y -= inline_container->y;
|
|
|
|
for (text_box = inline_container->children;
|
2004-07-19 18:31:31 +04:00
|
|
|
text_box && text_box->y + text_box->height < y;
|
|
|
|
text_box = text_box->next)
|
|
|
|
;
|
|
|
|
for (; text_box && text_box->type != BOX_BR &&
|
|
|
|
text_box->y <= y &&
|
|
|
|
text_box->x + text_box->width < x;
|
2003-09-23 01:55:08 +04:00
|
|
|
text_box = text_box->next)
|
|
|
|
;
|
|
|
|
if (!text_box) {
|
|
|
|
/* past last text box */
|
|
|
|
text_box = inline_container->last;
|
|
|
|
assert(text_box->type == BOX_INLINE);
|
|
|
|
assert(text_box->text && text_box->font);
|
2004-07-06 00:19:52 +04:00
|
|
|
nsfont_position_in_string(text_box->font,
|
|
|
|
text_box->text,
|
2003-12-27 04:06:46 +03:00
|
|
|
text_box->length,
|
|
|
|
(unsigned int)textarea->width,
|
2003-09-23 01:55:08 +04:00
|
|
|
&char_offset, &pixel_offset);
|
|
|
|
} else {
|
|
|
|
/* in a text box */
|
2004-07-19 18:31:31 +04:00
|
|
|
if (text_box->type == BOX_BR)
|
|
|
|
text_box = text_box->prev;
|
|
|
|
else if (y < text_box->y && text_box->prev)
|
|
|
|
text_box = text_box->prev;
|
2003-09-23 01:55:08 +04:00
|
|
|
assert(text_box->type == BOX_INLINE);
|
|
|
|
assert(text_box->text && text_box->font);
|
2004-07-06 00:19:52 +04:00
|
|
|
nsfont_position_in_string(text_box->font,
|
|
|
|
text_box->text,
|
2003-12-27 04:06:46 +03:00
|
|
|
text_box->length,
|
|
|
|
(unsigned int)(x - text_box->x),
|
2003-09-23 01:55:08 +04:00
|
|
|
&char_offset, &pixel_offset);
|
|
|
|
}
|
|
|
|
}
|
2003-09-29 20:32:17 +04:00
|
|
|
|
2004-10-23 00:58:11 +04:00
|
|
|
/* scroll to place the caret in the centre of the visible region */
|
|
|
|
new_scroll_y = inline_container->y + text_box->y +
|
|
|
|
text_box->height / 2 -
|
|
|
|
textarea->height / 2;
|
|
|
|
if (textarea->descendant_y1 - textarea->height < new_scroll_y)
|
|
|
|
new_scroll_y = textarea->descendant_y1 - textarea->height;
|
|
|
|
if (new_scroll_y < 0)
|
|
|
|
new_scroll_y = 0;
|
|
|
|
box_y += textarea->scroll_y - new_scroll_y;
|
2003-09-29 20:32:17 +04:00
|
|
|
|
2003-09-29 03:41:07 +04:00
|
|
|
textarea->gadget->caret_inline_container = inline_container;
|
|
|
|
textarea->gadget->caret_text_box = text_box;
|
2004-10-23 00:58:11 +04:00
|
|
|
textarea->gadget->caret_box_offset = char_offset;
|
2004-07-19 18:31:31 +04:00
|
|
|
textarea->gadget->caret_pixel_offset = pixel_offset;
|
2003-12-27 04:06:46 +03:00
|
|
|
browser_window_place_caret(bw,
|
2004-08-01 17:08:19 +04:00
|
|
|
box_x + inline_container->x + text_box->x +
|
|
|
|
pixel_offset,
|
2004-07-19 18:31:31 +04:00
|
|
|
box_y + inline_container->y + text_box->y,
|
2003-09-23 01:55:08 +04:00
|
|
|
text_box->height,
|
|
|
|
browser_window_textarea_callback, textarea);
|
2003-09-29 20:32:17 +04:00
|
|
|
|
2004-10-23 00:58:11 +04:00
|
|
|
if (new_scroll_y != textarea->scroll_y) {
|
|
|
|
textarea->scroll_y = new_scroll_y;
|
2004-07-19 18:31:31 +04:00
|
|
|
browser_redraw_box(bw->current_content, textarea);
|
2004-10-23 00:58:11 +04:00
|
|
|
}
|
2003-09-23 01:55:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Key press callback for text areas.
|
|
|
|
*/
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
void browser_window_textarea_callback(struct browser_window *bw,
|
2004-10-23 00:58:11 +04:00
|
|
|
wchar_t key, void *p)
|
2003-09-23 01:55:08 +04:00
|
|
|
{
|
|
|
|
struct box *textarea = p;
|
2003-09-29 03:41:07 +04:00
|
|
|
struct box *inline_container = textarea->gadget->caret_inline_container;
|
|
|
|
struct box *text_box = textarea->gadget->caret_text_box;
|
2004-07-19 18:31:31 +04:00
|
|
|
struct box *new_br, *new_text, *t;
|
|
|
|
struct box *prev;
|
2004-10-23 00:58:11 +04:00
|
|
|
size_t char_offset = textarea->gadget->caret_box_offset;
|
2004-07-19 18:31:31 +04:00
|
|
|
int pixel_offset = textarea->gadget->caret_pixel_offset;
|
2004-10-23 00:58:11 +04:00
|
|
|
int new_scroll_y;
|
2004-07-19 18:31:31 +04:00
|
|
|
int box_x, box_y;
|
|
|
|
char utf8[5];
|
|
|
|
unsigned int utf8_len, i;
|
|
|
|
char *text;
|
|
|
|
int width = 0, height = 0;
|
2003-10-09 19:23:10 +04:00
|
|
|
bool reflow = false;
|
2003-09-23 01:55:08 +04:00
|
|
|
|
2003-09-24 01:48:22 +04:00
|
|
|
/* box_dump(textarea, 0); */
|
2004-07-19 18:31:31 +04:00
|
|
|
LOG(("key %i at %i in '%.*s'", key, char_offset,
|
|
|
|
(int) text_box->length, text_box->text));
|
2003-09-24 01:48:22 +04:00
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
box_coords(textarea, &box_x, &box_y);
|
2004-10-23 00:58:11 +04:00
|
|
|
box_x -= textarea->scroll_x;
|
|
|
|
box_y -= textarea->scroll_y;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
|
|
|
if (!(key <= 0x001F || (0x007F <= key && key <= 0x009F))) {
|
2003-09-23 01:55:08 +04:00
|
|
|
/* normal character insertion */
|
2004-07-19 18:31:31 +04:00
|
|
|
/** \todo convert key to UTF-8 properly */
|
|
|
|
utf8[0] = key;
|
|
|
|
utf8_len = 1;
|
|
|
|
|
|
|
|
text = realloc(text_box->text, text_box->length + 8);
|
|
|
|
if (!text) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
text_box->text = text;
|
|
|
|
memmove(text_box->text + char_offset + utf8_len,
|
2003-09-23 01:55:08 +04:00
|
|
|
text_box->text + char_offset,
|
|
|
|
text_box->length - char_offset);
|
2004-07-19 18:31:31 +04:00
|
|
|
for (i = 0; i != utf8_len; i++)
|
|
|
|
text_box->text[char_offset + i] = utf8[i];
|
|
|
|
text_box->length += utf8_len;
|
2003-09-23 01:55:08 +04:00
|
|
|
text_box->text[text_box->length] = 0;
|
|
|
|
text_box->width = UNKNOWN_WIDTH;
|
2004-07-19 18:31:31 +04:00
|
|
|
char_offset += utf8_len;
|
|
|
|
|
2003-10-09 19:23:10 +04:00
|
|
|
reflow = true;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-09-23 22:35:44 +04:00
|
|
|
} else if (key == 10 || key == 13) {
|
|
|
|
/* paragraph break */
|
2004-07-19 18:31:31 +04:00
|
|
|
text = malloc(text_box->length + 1);
|
|
|
|
if (!text) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
new_br = box_create(text_box->style, 0, 0, 0,
|
2004-01-02 15:04:04 +03:00
|
|
|
bw->current_content->data.html.box_pool);
|
2004-07-19 18:31:31 +04:00
|
|
|
new_text = pool_alloc(bw->current_content->data.html.box_pool,
|
|
|
|
sizeof (struct box));
|
|
|
|
if (!new_text) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_br->type = BOX_BR;
|
|
|
|
new_br->style_clone = 1;
|
|
|
|
box_insert_sibling(text_box, new_br);
|
|
|
|
|
|
|
|
memcpy(new_text, text_box, sizeof (struct box));
|
2003-09-30 16:58:33 +04:00
|
|
|
new_text->clone = 1;
|
2004-07-19 18:31:31 +04:00
|
|
|
new_text->text = text;
|
2003-09-30 16:58:33 +04:00
|
|
|
memcpy(new_text->text, text_box->text + char_offset,
|
|
|
|
text_box->length - char_offset);
|
|
|
|
new_text->length = text_box->length - char_offset;
|
|
|
|
text_box->length = char_offset;
|
|
|
|
text_box->width = new_text->width = UNKNOWN_WIDTH;
|
2004-07-19 18:31:31 +04:00
|
|
|
box_insert_sibling(new_br, new_text);
|
|
|
|
|
|
|
|
/* place caret at start of new text box */
|
|
|
|
text_box = new_text;
|
2003-09-30 16:58:33 +04:00
|
|
|
char_offset = 0;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-10-09 19:23:10 +04:00
|
|
|
reflow = true;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-09-23 22:35:44 +04:00
|
|
|
} else if (key == 8 || key == 127) {
|
|
|
|
/* delete to left */
|
|
|
|
if (char_offset == 0) {
|
|
|
|
/* at the start of a text box */
|
2004-07-19 18:31:31 +04:00
|
|
|
if (!text_box->prev)
|
2003-09-23 22:35:44 +04:00
|
|
|
/* at very beginning of text area: ignore */
|
|
|
|
return;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
|
|
|
if (text_box->prev->type == BOX_BR) {
|
|
|
|
/* previous box is BR: remove it */
|
|
|
|
t = text_box->prev;
|
|
|
|
t->prev->next = t->next;
|
|
|
|
t->next->prev = t->prev;
|
|
|
|
box_free(t);
|
2003-09-23 22:35:44 +04:00
|
|
|
}
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-09-23 22:35:44 +04:00
|
|
|
/* delete space by merging with previous text box */
|
|
|
|
prev = text_box->prev;
|
|
|
|
assert(prev->text);
|
2004-07-19 18:31:31 +04:00
|
|
|
text = realloc(prev->text,
|
|
|
|
prev->length + text_box->length + 1);
|
|
|
|
if (!text) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
prev->text = text;
|
|
|
|
memcpy(prev->text + prev->length, text_box->text,
|
|
|
|
text_box->length);
|
|
|
|
char_offset = prev->length; /* caret at join */
|
2003-09-23 22:35:44 +04:00
|
|
|
prev->length += text_box->length;
|
|
|
|
prev->text[prev->length] = 0;
|
|
|
|
prev->width = UNKNOWN_WIDTH;
|
|
|
|
prev->next = text_box->next;
|
|
|
|
if (prev->next)
|
|
|
|
prev->next->prev = prev;
|
|
|
|
else
|
|
|
|
prev->parent->last = prev;
|
|
|
|
box_free(text_box);
|
2004-07-19 18:31:31 +04:00
|
|
|
|
|
|
|
/* place caret at join (see above) */
|
2003-09-23 22:35:44 +04:00
|
|
|
text_box = prev;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-09-23 22:35:44 +04:00
|
|
|
} else {
|
|
|
|
/* delete a character */
|
2004-07-19 18:31:31 +04:00
|
|
|
/** \todo delete entire UTF-8 character */
|
|
|
|
utf8_len = 1;
|
|
|
|
memmove(text_box->text + char_offset - utf8_len,
|
2003-09-23 22:35:44 +04:00
|
|
|
text_box->text + char_offset,
|
|
|
|
text_box->length - char_offset);
|
2004-07-19 18:31:31 +04:00
|
|
|
text_box->length -= utf8_len;
|
2003-09-23 22:35:44 +04:00
|
|
|
text_box->width = UNKNOWN_WIDTH;
|
2004-07-19 18:31:31 +04:00
|
|
|
char_offset -= utf8_len;
|
2003-09-23 22:35:44 +04:00
|
|
|
}
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-10-09 19:23:10 +04:00
|
|
|
reflow = true;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-10-09 00:48:46 +04:00
|
|
|
} else if (key == 28) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Right cursor -> */
|
|
|
|
if ((unsigned int) char_offset != text_box->length) {
|
|
|
|
/** \todo move by a UTF-8 character */
|
|
|
|
utf8_len = 1;
|
|
|
|
char_offset += utf8_len;
|
|
|
|
} else {
|
|
|
|
if (!text_box->next)
|
|
|
|
/* at end of text area: ignore */
|
|
|
|
return;
|
|
|
|
|
|
|
|
text_box = text_box->next;
|
|
|
|
if (text_box->type == BOX_BR)
|
|
|
|
text_box = text_box->next;
|
|
|
|
char_offset = 0;
|
|
|
|
}
|
|
|
|
|
2003-10-09 00:48:46 +04:00
|
|
|
} else if (key == 29) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Left cursor <- */
|
|
|
|
if (char_offset != 0) {
|
|
|
|
/** \todo move by a UTF-8 character */
|
|
|
|
utf8_len = 1;
|
|
|
|
char_offset -= utf8_len;
|
|
|
|
} else {
|
|
|
|
if (!text_box->prev)
|
|
|
|
/* at start of text area: ignore */
|
|
|
|
return;
|
|
|
|
|
|
|
|
text_box = text_box->prev;
|
|
|
|
if (text_box->type == BOX_BR)
|
|
|
|
text_box = text_box->prev;
|
|
|
|
char_offset = text_box->length;
|
|
|
|
}
|
|
|
|
|
2003-09-29 06:47:11 +04:00
|
|
|
} else if (key == 30) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Up Cursor */
|
|
|
|
browser_window_textarea_click(bw, textarea,
|
|
|
|
box_x, box_y,
|
|
|
|
text_box->x + pixel_offset,
|
|
|
|
inline_container->y + text_box->y - 1);
|
|
|
|
return;
|
|
|
|
|
2003-09-29 06:47:11 +04:00
|
|
|
} else if (key == 31) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Down cursor */
|
|
|
|
browser_window_textarea_click(bw, textarea,
|
|
|
|
box_x, box_y,
|
|
|
|
text_box->x + pixel_offset,
|
|
|
|
inline_container->y + text_box->y +
|
|
|
|
text_box->height + 1);
|
|
|
|
return;
|
|
|
|
|
2003-09-23 01:55:08 +04:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
/* box_dump(textarea, 0); */
|
|
|
|
/* for (struct box *t = inline_container->children; t; t = t->next) {
|
|
|
|
assert(t->type == BOX_INLINE);
|
|
|
|
assert(t->text);
|
|
|
|
assert(t->font);
|
|
|
|
assert(t->parent == inline_container);
|
|
|
|
if (t->next) assert(t->next->prev == t);
|
|
|
|
if (t->prev) assert(t->prev->next == t);
|
|
|
|
if (!t->next) {
|
|
|
|
assert(inline_container->last == t);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (t->next->type == BOX_BR) {
|
|
|
|
assert(t->next->next);
|
|
|
|
t = t->next;
|
2003-09-24 01:48:22 +04:00
|
|
|
}
|
|
|
|
} */
|
2003-09-23 22:35:44 +04:00
|
|
|
|
2003-10-09 19:23:10 +04:00
|
|
|
if (reflow) {
|
|
|
|
/* reflow textarea preserving width and height */
|
|
|
|
width = textarea->width;
|
|
|
|
height = textarea->height;
|
2004-07-19 18:31:31 +04:00
|
|
|
if (!layout_inline_container(inline_container, width,
|
|
|
|
textarea, 0, 0,
|
2004-06-03 01:04:35 +04:00
|
|
|
bw->current_content->data.html.box_pool))
|
|
|
|
warn_user("NoMemory", 0);
|
2003-10-09 19:23:10 +04:00
|
|
|
textarea->width = width;
|
|
|
|
textarea->height = height;
|
2004-10-23 00:58:11 +04:00
|
|
|
layout_calculate_descendant_bboxes(textarea);
|
2003-10-09 19:23:10 +04:00
|
|
|
}
|
2003-09-23 01:55:08 +04:00
|
|
|
|
2004-10-23 00:58:11 +04:00
|
|
|
if (text_box->length < char_offset) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* the text box has been split and the caret is in the
|
|
|
|
* second part */
|
2003-09-23 22:35:44 +04:00
|
|
|
char_offset -= (text_box->length + 1); /* +1 for the space */
|
2003-09-23 01:55:08 +04:00
|
|
|
text_box = text_box->next;
|
2003-09-23 22:35:44 +04:00
|
|
|
assert(text_box);
|
2004-10-23 00:58:11 +04:00
|
|
|
assert(char_offset <= text_box->length);
|
2003-09-23 01:55:08 +04:00
|
|
|
}
|
|
|
|
|
2004-10-23 00:58:11 +04:00
|
|
|
/* scroll to place the caret in the centre of the visible region */
|
|
|
|
new_scroll_y = inline_container->y + text_box->y +
|
|
|
|
text_box->height / 2 -
|
|
|
|
textarea->height / 2;
|
|
|
|
if (textarea->descendant_y1 - textarea->height < new_scroll_y)
|
|
|
|
new_scroll_y = textarea->descendant_y1 - textarea->height;
|
|
|
|
if (new_scroll_y < 0)
|
|
|
|
new_scroll_y = 0;
|
|
|
|
box_y += textarea->scroll_y - new_scroll_y;
|
2003-10-06 03:30:21 +04:00
|
|
|
|
2004-07-06 00:19:52 +04:00
|
|
|
pixel_offset = nsfont_width(text_box->font, text_box->text,
|
2004-10-23 00:58:11 +04:00
|
|
|
char_offset);
|
2003-09-23 01:55:08 +04:00
|
|
|
|
2003-09-29 03:41:07 +04:00
|
|
|
textarea->gadget->caret_inline_container = inline_container;
|
|
|
|
textarea->gadget->caret_text_box = text_box;
|
2004-10-23 00:58:11 +04:00
|
|
|
textarea->gadget->caret_box_offset = char_offset;
|
2004-07-19 18:31:31 +04:00
|
|
|
textarea->gadget->caret_pixel_offset = pixel_offset;
|
2003-12-27 04:06:46 +03:00
|
|
|
browser_window_place_caret(bw,
|
2004-08-01 17:08:19 +04:00
|
|
|
box_x + inline_container->x + text_box->x +
|
|
|
|
pixel_offset,
|
2004-07-19 18:31:31 +04:00
|
|
|
box_y + inline_container->y + text_box->y,
|
2003-09-23 01:55:08 +04:00
|
|
|
text_box->height,
|
|
|
|
browser_window_textarea_callback, textarea);
|
|
|
|
|
2004-10-23 00:58:11 +04:00
|
|
|
if (new_scroll_y != textarea->scroll_y || reflow) {
|
|
|
|
textarea->scroll_y = new_scroll_y;
|
2004-07-19 18:31:31 +04:00
|
|
|
browser_redraw_box(bw->current_content, textarea);
|
2004-10-23 00:58:11 +04:00
|
|
|
}
|
2003-09-23 01:55:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-29 03:41:07 +04:00
|
|
|
/**
|
|
|
|
* Handle clicks in a text or password input box by placing the caret.
|
2004-07-19 18:31:31 +04:00
|
|
|
*
|
|
|
|
* \param bw browser window where click occurred
|
|
|
|
* \param input input box
|
|
|
|
* \param box_x position of input in global document coordinates
|
|
|
|
* \param box_y position of input in global document coordinates
|
|
|
|
* \param x coordinate of click relative to input
|
|
|
|
* \param y coordinate of click relative to input
|
2003-09-29 03:41:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_input_click(struct browser_window* bw,
|
2004-07-19 18:31:31 +04:00
|
|
|
struct box *input,
|
|
|
|
int box_x, int box_y,
|
|
|
|
int x, int y)
|
2003-09-29 03:41:07 +04:00
|
|
|
{
|
2005-01-02 06:58:21 +03:00
|
|
|
size_t char_offset = 0;
|
|
|
|
int pixel_offset = 0, dx = 0;
|
2003-09-29 03:41:07 +04:00
|
|
|
struct box *text_box = input->children->children;
|
2004-07-20 00:40:11 +04:00
|
|
|
int uchars;
|
|
|
|
unsigned int offset;
|
2003-09-29 03:41:07 +04:00
|
|
|
|
2004-07-06 00:19:52 +04:00
|
|
|
nsfont_position_in_string(text_box->font, text_box->text,
|
2003-09-29 03:41:07 +04:00
|
|
|
text_box->length, x - text_box->x,
|
|
|
|
&char_offset, &pixel_offset);
|
2004-07-20 00:40:11 +04:00
|
|
|
assert(char_offset <= text_box->length);
|
2003-09-29 03:41:07 +04:00
|
|
|
|
|
|
|
text_box->x = 0;
|
2004-07-19 18:31:31 +04:00
|
|
|
if ((input->width < text_box->width) &&
|
|
|
|
(input->width / 2 < pixel_offset)) {
|
|
|
|
dx = text_box->x;
|
2003-09-29 03:41:07 +04:00
|
|
|
text_box->x = input->width / 2 - pixel_offset;
|
|
|
|
if (text_box->x < input->width - text_box->width)
|
|
|
|
text_box->x = input->width - text_box->width;
|
2004-07-19 18:31:31 +04:00
|
|
|
dx -= text_box->x;
|
2003-09-29 03:41:07 +04:00
|
|
|
}
|
2004-07-20 00:40:11 +04:00
|
|
|
input->gadget->caret_box_offset = char_offset;
|
|
|
|
/* Update caret_form_offset */
|
|
|
|
for (uchars = 0, offset = 0; offset < char_offset; ++uchars) {
|
|
|
|
if ((text_box->text[offset] & 0x80) == 0x00) {
|
|
|
|
++offset;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert((text_box->text[offset] & 0xC0) == 0xC0);
|
|
|
|
for (++offset; offset < char_offset && (text_box->text[offset] & 0xC0) == 0x80; ++offset)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
/* uchars is the number of real Unicode characters at the left
|
|
|
|
* side of the caret.
|
|
|
|
*/
|
|
|
|
for (offset = 0; uchars > 0 && offset < input->gadget->length; --uchars) {
|
|
|
|
if ((input->gadget->value[offset] & 0x80) == 0x00) {
|
|
|
|
++offset;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert((input->gadget->value[offset] & 0xC0) == 0xC0);
|
|
|
|
for (++offset; offset < input->gadget->length && (input->gadget->value[offset] & 0xC0) == 0x80; ++offset)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
assert(uchars == 0);
|
|
|
|
input->gadget->caret_form_offset = offset;
|
2004-07-19 18:31:31 +04:00
|
|
|
input->gadget->caret_pixel_offset = pixel_offset;
|
2003-12-27 04:06:46 +03:00
|
|
|
browser_window_place_caret(bw,
|
2004-08-01 17:08:19 +04:00
|
|
|
box_x + input->children->x + text_box->x + pixel_offset,
|
|
|
|
box_y + input->children->y + text_box->y,
|
2003-09-29 03:41:07 +04:00
|
|
|
text_box->height,
|
|
|
|
browser_window_input_callback, input);
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
if (dx)
|
|
|
|
browser_redraw_box(bw->current_content, input);
|
2003-09-29 03:41:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Key press callback for text or password input boxes.
|
|
|
|
*/
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
void browser_window_input_callback(struct browser_window *bw,
|
2004-08-14 16:16:45 +04:00
|
|
|
wchar_t key, void *p)
|
2003-09-29 03:41:07 +04:00
|
|
|
{
|
2004-07-20 00:40:11 +04:00
|
|
|
struct box *input = (struct box *)p;
|
2003-09-29 03:41:07 +04:00
|
|
|
struct box *text_box = input->children->children;
|
2004-07-20 00:40:11 +04:00
|
|
|
unsigned int box_offset = input->gadget->caret_box_offset;
|
|
|
|
unsigned int form_offset = input->gadget->caret_form_offset;
|
2004-07-19 18:31:31 +04:00
|
|
|
int pixel_offset, dx;
|
|
|
|
int box_x, box_y;
|
2004-07-20 00:40:11 +04:00
|
|
|
struct form* form = input->gadget->form;
|
2004-07-19 18:31:31 +04:00
|
|
|
bool changed = false;
|
2003-09-29 03:41:07 +04:00
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
box_coords(input, &box_x, &box_y);
|
2003-09-29 03:41:07 +04:00
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
if (!(key <= 0x001F || (0x007F <= key && key <= 0x009F))) {
|
2004-07-20 00:40:11 +04:00
|
|
|
char key_to_insert;
|
2004-10-23 00:58:11 +04:00
|
|
|
char *utf8key;
|
2004-07-20 00:40:11 +04:00
|
|
|
size_t utf8keySize;
|
2004-12-08 03:31:11 +03:00
|
|
|
char *value;
|
2004-07-20 00:40:11 +04:00
|
|
|
|
|
|
|
/** \todo: text_box has data in UTF-8 and its length in
|
|
|
|
* bytes is not necessarily equal to number of characters.
|
|
|
|
*/
|
|
|
|
if (input->gadget->length >= input->gadget->maxlength)
|
|
|
|
return;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
/* normal character insertion */
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
/* Insert key in gadget */
|
|
|
|
key_to_insert = (char)key;
|
|
|
|
if ((utf8key = cnv_local_enc_str(&key_to_insert, 1)) == NULL)
|
2004-07-19 18:31:31 +04:00
|
|
|
return;
|
2004-07-20 00:40:11 +04:00
|
|
|
utf8keySize = strlen(utf8key);
|
2004-12-08 03:31:11 +03:00
|
|
|
|
|
|
|
value = realloc(input->gadget->value, input->gadget->length + utf8keySize + 1);
|
|
|
|
if (!value) {
|
|
|
|
free(utf8key);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
input->gadget->value = value;
|
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
memmove(input->gadget->value + form_offset + utf8keySize,
|
|
|
|
input->gadget->value + form_offset,
|
|
|
|
input->gadget->length - form_offset);
|
|
|
|
memcpy(input->gadget->value + form_offset, utf8key, utf8keySize);
|
|
|
|
input->gadget->length += utf8keySize;
|
|
|
|
input->gadget->value[input->gadget->length] = 0;
|
|
|
|
form_offset += utf8keySize;
|
2004-10-23 00:58:11 +04:00
|
|
|
free(utf8key);
|
2004-07-20 00:40:11 +04:00
|
|
|
|
|
|
|
/* Insert key in text box */
|
|
|
|
/* Convert space into NBSP */
|
|
|
|
key_to_insert = (input->gadget->type == GADGET_PASSWORD) ? '*' : (key == ' ') ? 160 : key;
|
|
|
|
if ((utf8key = cnv_local_enc_str(&key_to_insert, 1)) == NULL)
|
2004-07-19 18:31:31 +04:00
|
|
|
return;
|
2004-07-20 00:40:11 +04:00
|
|
|
utf8keySize = strlen(utf8key);
|
2004-12-08 03:31:11 +03:00
|
|
|
|
|
|
|
value = realloc(text_box->text, text_box->length + utf8keySize + 1);
|
|
|
|
if (!value) {
|
|
|
|
free(utf8key);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
text_box->text = value;
|
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
memmove(text_box->text + box_offset + utf8keySize,
|
|
|
|
text_box->text + box_offset,
|
|
|
|
text_box->length - box_offset);
|
|
|
|
memcpy(text_box->text + box_offset, utf8key, utf8keySize);
|
|
|
|
text_box->length += utf8keySize;
|
2003-09-29 03:41:07 +04:00
|
|
|
text_box->text[text_box->length] = 0;
|
2004-07-20 00:40:11 +04:00
|
|
|
box_offset += utf8keySize;
|
2004-10-23 00:58:11 +04:00
|
|
|
free(utf8key);
|
2004-07-20 00:40:11 +04:00
|
|
|
|
2004-08-14 16:57:02 +04:00
|
|
|
text_box->width = nsfont_width(text_box->font,
|
|
|
|
text_box->text, text_box->length);
|
2004-07-19 18:31:31 +04:00
|
|
|
changed = true;
|
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
} else if (key == 8 || key == 127) {
|
2003-09-29 03:41:07 +04:00
|
|
|
/* delete to left */
|
2004-07-20 00:40:11 +04:00
|
|
|
int prev_offset;
|
|
|
|
|
|
|
|
if (box_offset == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Gadget */
|
|
|
|
prev_offset = form_offset;
|
|
|
|
/* Go to the previous valid UTF-8 character */
|
|
|
|
while (form_offset != 0
|
|
|
|
&& !((input->gadget->value[--form_offset] & 0x80) == 0x00 || (input->gadget->value[form_offset] & 0xC0) == 0xC0))
|
|
|
|
;
|
|
|
|
memmove(input->gadget->value + form_offset,
|
|
|
|
input->gadget->value + prev_offset,
|
|
|
|
input->gadget->length - prev_offset);
|
|
|
|
input->gadget->length -= prev_offset - form_offset;
|
|
|
|
input->gadget->value[input->gadget->length] = 0;
|
|
|
|
|
|
|
|
/* Text box */
|
|
|
|
prev_offset = box_offset;
|
|
|
|
/* Go to the previous valid UTF-8 character */
|
|
|
|
while (box_offset != 0
|
|
|
|
&& !((text_box->text[--box_offset] & 0x80) == 0x00 || (text_box->text[box_offset] & 0xC0) == 0xC0))
|
|
|
|
;
|
|
|
|
memmove(text_box->text + box_offset,
|
|
|
|
text_box->text + prev_offset,
|
|
|
|
text_box->length - prev_offset);
|
|
|
|
text_box->length -= prev_offset - box_offset;
|
|
|
|
text_box->text[text_box->length] = 0;
|
|
|
|
|
2004-08-14 16:57:02 +04:00
|
|
|
text_box->width = nsfont_width(text_box->font,
|
|
|
|
text_box->text, text_box->length);
|
2004-07-19 18:31:31 +04:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
|
|
|
|
} else if (key == 21) {
|
|
|
|
/* Ctrl+U */
|
|
|
|
text_box->text[0] = 0;
|
|
|
|
text_box->length = 0;
|
2004-07-20 00:40:11 +04:00
|
|
|
box_offset = 0;
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
input->gadget->value[0] = 0;
|
2004-07-20 00:40:11 +04:00
|
|
|
input->gadget->length = 0;
|
|
|
|
form_offset = 0;
|
|
|
|
|
|
|
|
text_box->width = 0;
|
2004-07-19 18:31:31 +04:00
|
|
|
changed = true;
|
|
|
|
|
2003-09-29 06:47:11 +04:00
|
|
|
} else if (key == 10 || key == 13) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Return/Enter hit */
|
|
|
|
if (form)
|
|
|
|
browser_form_submit(bw, form, 0);
|
2004-07-21 18:20:43 +04:00
|
|
|
return;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-09-29 06:47:11 +04:00
|
|
|
} else if (key == 9) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Tab */
|
|
|
|
struct form_control *next_input;
|
|
|
|
for (next_input = input->gadget->next;
|
|
|
|
next_input &&
|
|
|
|
next_input->type != GADGET_TEXTBOX &&
|
|
|
|
next_input->type != GADGET_TEXTAREA &&
|
|
|
|
next_input->type != GADGET_PASSWORD;
|
|
|
|
next_input = next_input->next)
|
|
|
|
;
|
|
|
|
if (!next_input)
|
|
|
|
return;
|
|
|
|
|
|
|
|
input = next_input->box;
|
|
|
|
text_box = input->children->children;
|
|
|
|
box_coords(input, &box_x, &box_y);
|
2004-07-20 00:40:11 +04:00
|
|
|
form_offset = box_offset = 0;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2004-04-09 03:46:41 +04:00
|
|
|
} else if (key == 11) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Shift+Tab */
|
|
|
|
struct form_control *prev_input;
|
|
|
|
for (prev_input = input->gadget->prev;
|
|
|
|
prev_input &&
|
|
|
|
prev_input->type != GADGET_TEXTBOX &&
|
|
|
|
prev_input->type != GADGET_TEXTAREA &&
|
|
|
|
prev_input->type != GADGET_PASSWORD;
|
|
|
|
prev_input = prev_input->prev)
|
|
|
|
;
|
|
|
|
if (!prev_input)
|
|
|
|
return;
|
|
|
|
|
|
|
|
input = prev_input->box;
|
|
|
|
text_box = input->children->children;
|
|
|
|
box_coords(input, &box_x, &box_y);
|
2004-07-20 00:40:11 +04:00
|
|
|
form_offset = box_offset = 0;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2004-04-09 03:46:41 +04:00
|
|
|
} else if (key == 26) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Ctrl+Left */
|
2004-07-20 00:40:11 +04:00
|
|
|
box_offset = form_offset = 0;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2004-04-09 03:46:41 +04:00
|
|
|
} else if (key == 27) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Ctrl+Right */
|
2004-07-20 00:40:11 +04:00
|
|
|
box_offset = text_box->length;
|
|
|
|
form_offset = input->gadget->length;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
} else if (key == 28) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Right cursor -> */
|
2004-07-20 00:40:11 +04:00
|
|
|
/* Text box */
|
|
|
|
/* Go to the next valid UTF-8 character */
|
|
|
|
while (box_offset != text_box->length
|
|
|
|
&& !((text_box->text[++box_offset] & 0x80) == 0x00 || (text_box->text[box_offset] & 0xC0) == 0xC0))
|
|
|
|
;
|
|
|
|
/* Gadget */
|
|
|
|
/* Go to the next valid UTF-8 character */
|
|
|
|
while (form_offset != input->gadget->length
|
|
|
|
&& !((input->gadget->value[++form_offset] & 0x80) == 0x00 || (input->gadget->value[form_offset] & 0xC0) == 0xC0))
|
|
|
|
;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
} else if (key == 29) {
|
2004-07-19 18:31:31 +04:00
|
|
|
/* Left cursor <- */
|
2004-07-20 00:40:11 +04:00
|
|
|
/* Text box */
|
|
|
|
/* Go to the previous valid UTF-8 character */
|
|
|
|
while (box_offset != 0
|
|
|
|
&& !((text_box->text[--box_offset] & 0x80) == 0x00 || (text_box->text[box_offset] & 0xC0) == 0xC0))
|
|
|
|
;
|
|
|
|
/* Gadget */
|
|
|
|
/* Go to the previous valid UTF-8 character */
|
|
|
|
while (form_offset != 0
|
|
|
|
&& !((input->gadget->value[--form_offset] & 0x80) == 0x00 || (input->gadget->value[form_offset] & 0xC0) == 0xC0))
|
|
|
|
;
|
2004-07-19 18:31:31 +04:00
|
|
|
|
2003-09-29 03:41:07 +04:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-06 00:19:52 +04:00
|
|
|
pixel_offset = nsfont_width(text_box->font, text_box->text,
|
2004-08-14 16:57:02 +04:00
|
|
|
box_offset);
|
2004-07-19 18:31:31 +04:00
|
|
|
dx = text_box->x;
|
2003-09-29 03:41:07 +04:00
|
|
|
text_box->x = 0;
|
2004-07-06 00:19:52 +04:00
|
|
|
if (input->width < text_box->width && input->width / 2 < pixel_offset) {
|
2003-09-29 03:41:07 +04:00
|
|
|
text_box->x = input->width / 2 - pixel_offset;
|
|
|
|
if (text_box->x < input->width - text_box->width)
|
|
|
|
text_box->x = input->width - text_box->width;
|
|
|
|
}
|
2004-07-19 18:31:31 +04:00
|
|
|
dx -= text_box->x;
|
|
|
|
input->gadget->caret_pixel_offset = pixel_offset;
|
2004-07-20 00:40:11 +04:00
|
|
|
|
|
|
|
input->gadget->caret_box_offset = box_offset;
|
|
|
|
input->gadget->caret_form_offset = form_offset;
|
|
|
|
|
2003-12-27 04:06:46 +03:00
|
|
|
browser_window_place_caret(bw,
|
2004-08-01 17:08:19 +04:00
|
|
|
box_x + input->children->x + text_box->x + pixel_offset,
|
|
|
|
box_y + input->children->y + text_box->y,
|
2003-09-29 03:41:07 +04:00
|
|
|
text_box->height,
|
|
|
|
browser_window_input_callback, input);
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
if (dx || changed)
|
|
|
|
browser_redraw_box(bw->current_content, input);
|
2003-09-29 03:41:07 +04:00
|
|
|
}
|
|
|
|
|
2004-08-01 17:08:19 +04:00
|
|
|
|
2003-09-23 01:55:08 +04:00
|
|
|
/**
|
|
|
|
* Position the caret and assign a callback for key presses.
|
|
|
|
*/
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
void browser_window_place_caret(struct browser_window *bw,
|
|
|
|
int x, int y, int height,
|
|
|
|
void (*callback)(struct browser_window *bw,
|
2004-08-14 16:16:45 +04:00
|
|
|
wchar_t key, void *p),
|
2004-07-19 18:31:31 +04:00
|
|
|
void *p)
|
2003-09-23 01:55:08 +04:00
|
|
|
{
|
|
|
|
gui_window_place_caret(bw->window, x, y, height);
|
|
|
|
bw->caret_callback = callback;
|
|
|
|
bw->caret_p = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-21 18:20:43 +04:00
|
|
|
/**
|
|
|
|
* Removes the caret and callback for key process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_remove_caret(struct browser_window *bw)
|
|
|
|
{
|
|
|
|
gui_window_remove_caret(bw->window);
|
|
|
|
bw->caret_callback = NULL;
|
|
|
|
bw->caret_p = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-23 01:55:08 +04:00
|
|
|
/**
|
|
|
|
* Handle key presses in a browser window.
|
|
|
|
*/
|
|
|
|
|
2004-08-14 16:16:45 +04:00
|
|
|
bool browser_window_key_press(struct browser_window *bw, wchar_t key)
|
2003-09-23 01:55:08 +04:00
|
|
|
{
|
|
|
|
if (!bw->caret_callback)
|
2003-12-11 04:23:57 +03:00
|
|
|
return false;
|
2003-09-23 01:55:08 +04:00
|
|
|
bw->caret_callback(bw, key, bw->caret_p);
|
2003-12-11 04:23:57 +03:00
|
|
|
return true;
|
2003-09-23 01:55:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-18 03:32:09 +04:00
|
|
|
/**
|
|
|
|
* Process a selection from a form select menu.
|
|
|
|
*
|
|
|
|
* \param bw browser window with menu
|
|
|
|
* \param control form control with menu
|
|
|
|
* \param item index of item selected from the menu
|
|
|
|
*/
|
|
|
|
|
|
|
|
void browser_window_form_select(struct browser_window *bw,
|
|
|
|
struct form_control *control, int item)
|
2002-09-11 18:24:02 +04:00
|
|
|
{
|
2004-07-18 03:32:09 +04:00
|
|
|
struct form_option *o;
|
|
|
|
int count;
|
|
|
|
struct box *inline_box = control->box->children->children;
|
|
|
|
|
|
|
|
for (count = 0, o = control->data.select.items;
|
|
|
|
o != NULL;
|
|
|
|
count++, o = o->next) {
|
|
|
|
if (!control->data.select.multiple)
|
|
|
|
o->selected = false;
|
|
|
|
if (count == item) {
|
|
|
|
if (control->data.select.multiple) {
|
|
|
|
if (o->selected) {
|
|
|
|
o->selected = false;
|
|
|
|
control->data.select.num_selected--;
|
|
|
|
} else {
|
|
|
|
o->selected = true;
|
|
|
|
control->data.select.num_selected++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
o->selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (o->selected)
|
|
|
|
control->data.select.current = o;
|
2004-02-25 18:12:58 +03:00
|
|
|
}
|
2004-07-18 03:32:09 +04:00
|
|
|
|
|
|
|
free(inline_box->text);
|
|
|
|
inline_box->text = 0;
|
|
|
|
if (control->data.select.num_selected == 0)
|
|
|
|
inline_box->text = strdup(messages_get("Form_None"));
|
|
|
|
else if (control->data.select.num_selected == 1)
|
|
|
|
inline_box->text = strdup(control->data.select.current->text);
|
|
|
|
else
|
|
|
|
inline_box->text = strdup(messages_get("Form_Many"));
|
|
|
|
if (!inline_box->text) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
inline_box->length = 0;
|
|
|
|
} else
|
|
|
|
inline_box->length = strlen(inline_box->text);
|
|
|
|
inline_box->width = control->box->width;
|
|
|
|
|
2004-07-19 19:02:22 +04:00
|
|
|
browser_redraw_box(bw->current_content, control->box);
|
2002-09-11 18:24:02 +04:00
|
|
|
}
|
|
|
|
|
2004-07-18 03:32:09 +04:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
gui_pointer_shape get_pointer_shape(css_cursor cursor)
|
|
|
|
{
|
|
|
|
gui_pointer_shape pointer;
|
|
|
|
|
|
|
|
switch (cursor) {
|
|
|
|
case CSS_CURSOR_CROSSHAIR:
|
|
|
|
pointer = GUI_POINTER_CROSS;
|
|
|
|
break;
|
|
|
|
case CSS_CURSOR_POINTER:
|
|
|
|
pointer = GUI_POINTER_POINT;
|
|
|
|
break;
|
|
|
|
case CSS_CURSOR_MOVE:
|
|
|
|
pointer = GUI_POINTER_MOVE;
|
|
|
|
break;
|
|
|
|
case CSS_CURSOR_E_RESIZE:
|
|
|
|
case CSS_CURSOR_W_RESIZE:
|
|
|
|
pointer = GUI_POINTER_LR;
|
|
|
|
break;
|
|
|
|
case CSS_CURSOR_N_RESIZE:
|
|
|
|
case CSS_CURSOR_S_RESIZE:
|
|
|
|
pointer = GUI_POINTER_UD;
|
|
|
|
break;
|
|
|
|
case CSS_CURSOR_NE_RESIZE:
|
|
|
|
case CSS_CURSOR_SW_RESIZE:
|
|
|
|
pointer = GUI_POINTER_LD;
|
|
|
|
break;
|
|
|
|
case CSS_CURSOR_SE_RESIZE:
|
|
|
|
case CSS_CURSOR_NW_RESIZE:
|
|
|
|
pointer = GUI_POINTER_RD;
|
|
|
|
break;
|
|
|
|
case CSS_CURSOR_TEXT:
|
|
|
|
pointer = GUI_POINTER_CARET;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pointer = GUI_POINTER_DEFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointer;
|
2004-04-03 03:12:26 +04:00
|
|
|
}
|
|
|
|
|
2002-09-11 18:24:02 +04:00
|
|
|
|
2003-10-25 18:13:49 +04:00
|
|
|
/**
|
|
|
|
* Collect controls and submit a form.
|
|
|
|
*/
|
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
void browser_form_submit(struct browser_window *bw, struct form *form,
|
|
|
|
struct form_control *submit_button)
|
2003-05-22 17:21:45 +04:00
|
|
|
{
|
2003-12-26 03:17:55 +03:00
|
|
|
char *data = 0, *url = 0, *url1 = 0, *base;
|
2003-10-25 04:35:49 +04:00
|
|
|
struct form_successful_control *success;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2003-05-22 17:21:45 +04:00
|
|
|
|
2003-12-11 22:06:39 +03:00
|
|
|
assert(form);
|
2003-12-26 03:17:55 +03:00
|
|
|
assert(bw->current_content->type == CONTENT_HTML);
|
2003-12-11 22:06:39 +03:00
|
|
|
|
2004-08-08 23:13:40 +04:00
|
|
|
if (!form_successful_controls(form, submit_button, &success)) {
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
2003-12-26 03:17:55 +03:00
|
|
|
base = bw->current_content->data.html.base_url;
|
2003-10-25 04:35:49 +04:00
|
|
|
|
2003-10-25 18:13:49 +04:00
|
|
|
switch (form->method) {
|
|
|
|
case method_GET:
|
|
|
|
data = form_url_encode(success);
|
2004-08-08 23:13:40 +04:00
|
|
|
if (!data) {
|
|
|
|
form_free_successful(success);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
2004-12-08 03:31:11 +03:00
|
|
|
url = calloc(1, strlen(form->action) + strlen(data) + 2);
|
|
|
|
if (!url) {
|
|
|
|
form_free_successful(success);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-03 02:38:02 +03:00
|
|
|
if(form->action[strlen(form->action)-1] == '?') {
|
2004-07-20 00:40:11 +04:00
|
|
|
sprintf(url, "%s%s", form->action, data);
|
2004-02-03 02:38:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-07-20 00:40:11 +04:00
|
|
|
sprintf(url, "%s?%s", form->action, data);
|
2004-02-03 02:38:02 +03:00
|
|
|
}
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(url, base, &url1);
|
|
|
|
if (res != URL_FUNC_OK)
|
2003-12-26 03:17:55 +03:00
|
|
|
break;
|
2004-10-02 01:31:55 +04:00
|
|
|
browser_window_go(bw, url1, bw->current_content->url);
|
2004-07-20 00:40:11 +04:00
|
|
|
break;
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
case method_POST_URLENC:
|
2003-10-25 18:13:49 +04:00
|
|
|
data = form_url_encode(success);
|
2004-08-08 23:13:40 +04:00
|
|
|
if (!data) {
|
|
|
|
form_free_successful(success);
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(form->action, base, &url);
|
|
|
|
if (res != URL_FUNC_OK)
|
2003-12-26 03:17:55 +03:00
|
|
|
break;
|
2004-10-02 01:31:55 +04:00
|
|
|
browser_window_go_post(bw, url, data, 0, true,
|
|
|
|
bw->current_content->url);
|
2004-07-20 00:40:11 +04:00
|
|
|
break;
|
2003-10-25 18:13:49 +04:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
case method_POST_MULTIPART:
|
2004-08-09 20:11:58 +04:00
|
|
|
res = url_join(form->action, base, &url);
|
|
|
|
if (res != URL_FUNC_OK)
|
2004-03-02 21:02:41 +03:00
|
|
|
break;
|
2004-10-02 01:31:55 +04:00
|
|
|
browser_window_go_post(bw, url, 0, success, true,
|
|
|
|
bw->current_content->url);
|
2004-07-20 00:40:11 +04:00
|
|
|
break;
|
2004-02-25 18:12:58 +03:00
|
|
|
|
2004-07-20 00:40:11 +04:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2003-05-22 17:21:45 +04:00
|
|
|
|
2003-10-25 04:35:49 +04:00
|
|
|
form_free_successful(success);
|
2003-12-26 03:17:55 +03:00
|
|
|
free(data);
|
|
|
|
free(url);
|
|
|
|
free(url1);
|
2003-05-22 17:21:45 +04:00
|
|
|
}
|