mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 20:46:50 +03:00
[project @ 2003-12-11 01:23:57 by bursa]
Clean up key handling and implement scrolling using cursor keys. svn path=/import/netsurf/; revision=425
This commit is contained in:
parent
c5f1560a70
commit
9805610091
@ -205,16 +205,16 @@ void browser_window_open_location(struct browser_window* bw, const char* url0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void browser_window_open_location_post(struct browser_window* bw,
|
void browser_window_open_location_post(struct browser_window* bw,
|
||||||
const char* url0, char *post_urlenc,
|
const char* url, char *post_urlenc,
|
||||||
struct form_successful_control *post_multipart)
|
struct form_successful_control *post_multipart)
|
||||||
{
|
{
|
||||||
char *url;
|
char *url1;
|
||||||
LOG(("bw = %p, url0 = %s", bw, url0));
|
LOG(("bw = %p, url = %s", bw, url));
|
||||||
assert(bw != 0 && url0 != 0);
|
assert(bw != 0 && url != 0);
|
||||||
url = url_join(url0, bw->url);
|
url1 = url_join(url, 0);
|
||||||
browser_window_open_location_historical(bw, url, post_urlenc, post_multipart);
|
browser_window_open_location_historical(bw, url1, post_urlenc, post_multipart);
|
||||||
bw->history_add = true;
|
bw->history_add = true;
|
||||||
xfree(url);
|
free(url1);
|
||||||
LOG(("end"));
|
LOG(("end"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1073,11 +1073,12 @@ void browser_window_place_caret(struct browser_window *bw, int x, int y,
|
|||||||
* Handle key presses in a browser window.
|
* Handle key presses in a browser window.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void browser_window_key_press(struct browser_window *bw, char key)
|
bool browser_window_key_press(struct browser_window *bw, char key)
|
||||||
{
|
{
|
||||||
if (!bw->caret_callback)
|
if (!bw->caret_callback)
|
||||||
return;
|
return false;
|
||||||
bw->caret_callback(bw, key, bw->caret_p);
|
bw->caret_callback(bw, key, bw->caret_p);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1172,17 +1173,20 @@ void browser_window_follow_link(struct browser_window* bw,
|
|||||||
continue;
|
continue;
|
||||||
if (click_boxes[i].box->href != NULL)
|
if (click_boxes[i].box->href != NULL)
|
||||||
{
|
{
|
||||||
if (click_type == 1)
|
if (click_type == 1) {
|
||||||
browser_window_open_location(bw, (char*) click_boxes[i].box->href);
|
char *url = url_join((char*) click_boxes[i].box->href, bw->url);
|
||||||
|
browser_window_open_location(bw, url);
|
||||||
|
free(url);
|
||||||
|
}
|
||||||
else if (click_type == 2)
|
else if (click_type == 2)
|
||||||
{
|
{
|
||||||
|
char *url = url_join((char*) click_boxes[i].box->href, bw->url);
|
||||||
struct browser_window* bw_new;
|
struct browser_window* bw_new;
|
||||||
bw_new = create_browser_window(browser_TITLE | browser_TOOLBAR
|
bw_new = create_browser_window(browser_TITLE | browser_TOOLBAR
|
||||||
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480);
|
| browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480);
|
||||||
gui_window_show(bw_new->window);
|
gui_window_show(bw_new->window);
|
||||||
if (bw->url != NULL)
|
browser_window_open_location(bw_new, url);
|
||||||
bw_new->url = xstrdup(bw->url);
|
free(url);
|
||||||
browser_window_open_location(bw_new, (char*) click_boxes[i].box->href);
|
|
||||||
}
|
}
|
||||||
else if (click_type == 0)
|
else if (click_type == 0)
|
||||||
{
|
{
|
||||||
@ -1526,7 +1530,7 @@ void browser_window_redraw_boxes(struct browser_window* bw, struct box_position*
|
|||||||
void browser_form_submit(struct browser_window *bw, struct form *form,
|
void browser_form_submit(struct browser_window *bw, struct form *form,
|
||||||
struct form_control *submit_button)
|
struct form_control *submit_button)
|
||||||
{
|
{
|
||||||
char *data, *url;
|
char *data, *url, *url1;
|
||||||
struct form_successful_control *success;
|
struct form_successful_control *success;
|
||||||
|
|
||||||
success = form_successful_controls(form, submit_button);
|
success = form_successful_controls(form, submit_button);
|
||||||
@ -1536,19 +1540,25 @@ void browser_form_submit(struct browser_window *bw, struct form *form,
|
|||||||
data = form_url_encode(success);
|
data = form_url_encode(success);
|
||||||
url = xcalloc(1, strlen(form->action) + strlen(data) + 2);
|
url = xcalloc(1, strlen(form->action) + strlen(data) + 2);
|
||||||
sprintf(url, "%s?%s", form->action, data);
|
sprintf(url, "%s?%s", form->action, data);
|
||||||
|
url1 = url_join(url, bw->url);
|
||||||
free(data);
|
free(data);
|
||||||
browser_window_open_location(bw, url);
|
|
||||||
free(url);
|
free(url);
|
||||||
|
browser_window_open_location(bw, url1);
|
||||||
|
free(url1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case method_POST_URLENC:
|
case method_POST_URLENC:
|
||||||
data = form_url_encode(success);
|
data = form_url_encode(success);
|
||||||
browser_window_open_location_post(bw, form->action, data, 0);
|
url = url_join(form->action, bw->url);
|
||||||
|
browser_window_open_location_post(bw, url, data, 0);
|
||||||
|
free(url);
|
||||||
free(data);
|
free(data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case method_POST_MULTIPART:
|
case method_POST_MULTIPART:
|
||||||
browser_window_open_location_post(bw, form->action, 0, success);
|
url = url_join(form->action, bw->url);
|
||||||
|
browser_window_open_location_post(bw, url, 0, success);
|
||||||
|
free(url);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -113,7 +113,7 @@ void gui_redraw_gadget(struct browser_window* bw, struct form_control* g);
|
|||||||
void browser_window_stop_throbber(struct browser_window* bw);
|
void browser_window_stop_throbber(struct browser_window* bw);
|
||||||
void browser_window_reformat(struct browser_window* bw, int scroll_to_top);
|
void browser_window_reformat(struct browser_window* bw, int scroll_to_top);
|
||||||
|
|
||||||
void browser_window_key_press(struct browser_window *bw, char key);
|
bool browser_window_key_press(struct browser_window *bw, char key);
|
||||||
|
|
||||||
struct history_entry * history_add(struct history_entry *current,
|
struct history_entry * history_add(struct history_entry *current,
|
||||||
char *url, char *title);
|
char *url, char *title);
|
||||||
|
110
riscos/gui.c
110
riscos/gui.c
@ -576,79 +576,35 @@ void ro_gui_icon_bar_click(wimp_pointer* pointer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ro_gui_keypress(wimp_key* key)
|
|
||||||
|
/**
|
||||||
|
* Handle Key_Pressed events.
|
||||||
|
*/
|
||||||
|
void ro_gui_keypress(wimp_key *key)
|
||||||
{
|
{
|
||||||
gui_window* g;
|
bool handled = false;
|
||||||
|
gui_window *g = ro_gui_window_lookup(key->w);
|
||||||
|
|
||||||
if (key->i == -1 && (key->c < 256 || (key->c >= 396 && key->c <= 399))) {
|
if (!g) {
|
||||||
g = ro_lookup_gui_from_w(key->w);
|
wimp_process_key(key->c);
|
||||||
if (g) {
|
return;
|
||||||
/* Munge cursor keys into unused control chars */
|
}
|
||||||
if (key->c == 396) key->c = 29; /* Left */
|
|
||||||
else if (key->c == 397) key->c = 28; /* Right */
|
|
||||||
else if (key->c == 398) key->c = 31; /* Down */
|
|
||||||
else if (key->c == 399) key->c = 30; /* Up */
|
|
||||||
browser_window_key_press(g->data.browser.bw, (char) key->c);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g = ro_lookup_gui_toolbar_from_w(key->w);
|
switch (g->type) {
|
||||||
if (g != NULL)
|
case GUI_BROWSER_WINDOW:
|
||||||
{
|
handled = ro_gui_window_keypress(g, key->c,
|
||||||
if (key->c == wimp_KEY_RETURN)
|
(bool) (g->data.browser.toolbar == key->w));
|
||||||
{
|
break;
|
||||||
if (g->data.browser.bw->url != NULL)
|
|
||||||
{
|
case GUI_DOWNLOAD_WINDOW:
|
||||||
xfree(g->data.browser.bw->url);
|
break;
|
||||||
g->data.browser.bw->url = NULL;
|
}
|
||||||
}
|
|
||||||
if (strcasecmp(g->url, "about:") == 0) {
|
if (!handled)
|
||||||
about_create();
|
wimp_process_key(key->c);
|
||||||
browser_window_open_location(g->data.browser.bw,
|
|
||||||
"file:///%3CWimp$ScrapDir%3E/WWW/NetSurf/About");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
browser_window_open_location(g->data.browser.bw, g->url);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (key->c == wimp_KEY_F8)
|
|
||||||
{
|
|
||||||
/* TODO: use some protocol so it's type as HTML not Text. */
|
|
||||||
if(g->data.browser.bw->current_content->type == CONTENT_HTML ||
|
|
||||||
g->data.browser.bw->current_content->type == CONTENT_TEXTPLAIN)
|
|
||||||
xosfile_save_stamped("Pipe:$.Source", osfile_TYPE_TEXT,
|
|
||||||
g->data.browser.bw->current_content->data.html.source,
|
|
||||||
(g->data.browser.bw->current_content->data.html.source +
|
|
||||||
g->data.browser.bw->current_content->data.html.length));
|
|
||||||
xosfile_set_type("Pipe:$.Source", osfile_TYPE_TEXT);
|
|
||||||
xos_cli("Filer_Run Pipe:$.Source");
|
|
||||||
}
|
|
||||||
else if (key->c == wimp_KEY_F9)
|
|
||||||
{
|
|
||||||
switch (g->data.browser.bw->current_content->type) {
|
|
||||||
case CONTENT_HTML:
|
|
||||||
box_dump(g->data.browser.bw->current_content->data.html.layout->children, 0);
|
|
||||||
break;
|
|
||||||
case CONTENT_CSS:
|
|
||||||
css_dump_stylesheet(g->data.browser.bw->current_content->data.css.css);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (key->c == wimp_KEY_F10)
|
|
||||||
{
|
|
||||||
cache_dump();
|
|
||||||
}
|
|
||||||
else if (key->c == (wimp_KEY_CONTROL + wimp_KEY_F2))
|
|
||||||
{
|
|
||||||
browser_window_destroy(g->data.browser.bw);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wimp_process_key(key->c);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void gui_gadget_combo(struct browser_window* bw, struct form_control* g, unsigned long mx, unsigned long my)
|
void gui_gadget_combo(struct browser_window* bw, struct form_control* g, unsigned long mx, unsigned long my)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -930,6 +886,24 @@ void ro_gui_open_help_page (void)
|
|||||||
0,0,-1, (int) strlen(bw->window->url) - 1);
|
0,0,-1, (int) strlen(bw->window->url) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the source of a content to a text editor.
|
||||||
|
*/
|
||||||
|
void ro_gui_view_source(struct content *content)
|
||||||
|
{
|
||||||
|
if (content->type != CONTENT_HTML)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xosfile_save_stamped("<Wimp$Scrap>", 0xfff,
|
||||||
|
content->data.html.source,
|
||||||
|
(content->data.html.source +
|
||||||
|
content->data.html.length));
|
||||||
|
xos_cli("Filer_Run <Wimp$Scrap>");
|
||||||
|
xosfile_set_type("<Wimp$Scrap>", 0xfaf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ro_gui_drag_box_start(wimp_pointer *pointer)
|
void ro_gui_drag_box_start(wimp_pointer *pointer)
|
||||||
{
|
{
|
||||||
wimp_drag *drag_box;
|
wimp_drag *drag_box;
|
||||||
|
@ -96,6 +96,7 @@ int window_y_units(int scr_units, wimp_window_state* win);
|
|||||||
void ro_gui_copy_selection(gui_window* g);
|
void ro_gui_copy_selection(gui_window* g);
|
||||||
void ro_gui_open_help_page(void);
|
void ro_gui_open_help_page(void);
|
||||||
void ro_gui_screen_size(int *width, int *height);
|
void ro_gui_screen_size(int *width, int *height);
|
||||||
|
void ro_gui_view_source(struct content *content);
|
||||||
|
|
||||||
/* in menus.c */
|
/* in menus.c */
|
||||||
void ro_gui_menus_init(void);
|
void ro_gui_menus_init(void);
|
||||||
@ -140,6 +141,8 @@ void ro_gui_toolbar_click(gui_window* g, wimp_pointer* pointer);
|
|||||||
void ro_gui_throb(void);
|
void ro_gui_throb(void);
|
||||||
gui_window* ro_lookup_gui_from_w(wimp_w window);
|
gui_window* ro_lookup_gui_from_w(wimp_w window);
|
||||||
gui_window* ro_lookup_gui_toolbar_from_w(wimp_w window);
|
gui_window* ro_lookup_gui_toolbar_from_w(wimp_w window);
|
||||||
|
gui_window *ro_gui_window_lookup(wimp_w w);
|
||||||
|
bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar);
|
||||||
|
|
||||||
/* in history.c */
|
/* in history.c */
|
||||||
void ro_gui_history_init(void);
|
void ro_gui_history_init(void);
|
||||||
|
@ -413,6 +413,25 @@ gui_window* ro_lookup_gui_toolbar_from_w(wimp_w window)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a wimp window handle to the owning gui_window structure.
|
||||||
|
*/
|
||||||
|
gui_window *ro_gui_window_lookup(wimp_w w)
|
||||||
|
{
|
||||||
|
gui_window *g;
|
||||||
|
|
||||||
|
for (g = window_list; g; g = g->next) {
|
||||||
|
if (g->window == w)
|
||||||
|
return g;
|
||||||
|
else if (g->type == GUI_BROWSER_WINDOW &&
|
||||||
|
g->data.browser.toolbar == w)
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ro_gui_window_mouse_at(wimp_pointer* pointer)
|
void ro_gui_window_mouse_at(wimp_pointer* pointer)
|
||||||
{
|
{
|
||||||
int x,y;
|
int x,y;
|
||||||
@ -573,3 +592,81 @@ void gui_window_place_caret(gui_window *g, int x, int y, int height)
|
|||||||
wimp_set_caret_position(g->window, -1,
|
wimp_set_caret_position(g->window, -1,
|
||||||
x * 2, -(y + height) * 2, height * 2, -1);
|
x * 2, -(y + height) * 2, height * 2, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process Key_Pressed events in a browser window.
|
||||||
|
*/
|
||||||
|
bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar)
|
||||||
|
{
|
||||||
|
struct content *content = g->data.browser.bw->current_content;
|
||||||
|
wimp_window_state state;
|
||||||
|
|
||||||
|
assert(g->type == GUI_BROWSER_WINDOW);
|
||||||
|
|
||||||
|
/* First send the key to the browser window, eg. form fields. */
|
||||||
|
if (!toolbar) {
|
||||||
|
int c = key;
|
||||||
|
/* Munge cursor keys into unused control chars */
|
||||||
|
if (c == 396) c = 29; /* Left */
|
||||||
|
else if (c == 397) c = 28; /* Right */
|
||||||
|
else if (c == 398) c = 31; /* Down */
|
||||||
|
else if (c == 399) c = 30; /* Up */
|
||||||
|
if (c < 256)
|
||||||
|
if (browser_window_key_press(g->data.browser.bw,
|
||||||
|
(char) c))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case wimp_KEY_F8: /* View source. */
|
||||||
|
ro_gui_view_source(content);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case wimp_KEY_F9: /* Dump content for debugging. */
|
||||||
|
switch (content->type) {
|
||||||
|
case CONTENT_HTML:
|
||||||
|
box_dump(content->data.html.layout->children, 0);
|
||||||
|
break;
|
||||||
|
case CONTENT_CSS:
|
||||||
|
css_dump_stylesheet(content->data.css.css);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case wimp_KEY_F10: /* Dump cache for debugging. */
|
||||||
|
cache_dump();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case wimp_KEY_CONTROL + wimp_KEY_F2: /* Close window. */
|
||||||
|
browser_window_destroy(g->data.browser.bw);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case wimp_KEY_RETURN:
|
||||||
|
if (!toolbar)
|
||||||
|
break;
|
||||||
|
if (strcasecmp(g->url, "about:") == 0) {
|
||||||
|
about_create();
|
||||||
|
browser_window_open_location(g->data.browser.bw,
|
||||||
|
"file:///%3CWimp$ScrapDir%3E/WWW/NetSurf/About");
|
||||||
|
} else {
|
||||||
|
browser_window_open_location(g->data.browser.bw, g->url);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case wimp_KEY_UP:
|
||||||
|
case wimp_KEY_DOWN:
|
||||||
|
state.w = g->window;
|
||||||
|
wimp_get_window_state(&state);
|
||||||
|
state.yscroll += key == wimp_KEY_UP ? 32 : -32;
|
||||||
|
wimp_open_window((wimp_open *) &state);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user