mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-09 04:22:12 +03:00
[project @ 2003-01-11 17:33:31 by monkeyson]
Mouse gestures. Recognises the same gestures as Opera, although only back, forward and reload actually do anything yet. svn path=/import/netsurf/; revision=91
This commit is contained in:
parent
48e4666fee
commit
6f67739fa7
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* $Id: browser.c,v 1.20 2003/01/06 23:53:39 bursa Exp $
|
||||
* $Id: browser.c,v 1.21 2003/01/11 17:33:31 monkeyson Exp $
|
||||
*/
|
||||
|
||||
#include "netsurf/riscos/font.h"
|
||||
@ -113,29 +113,34 @@ void set_content_html(struct content* c)
|
||||
return;
|
||||
}
|
||||
|
||||
void content_html_reformat(struct content* c, int width)
|
||||
|
||||
char* content_html_reformat(struct content* c, int width)
|
||||
{
|
||||
char* file;
|
||||
char* title = NULL;
|
||||
struct css_selector* selector = xcalloc(1, sizeof(struct css_selector));
|
||||
|
||||
LOG(("Starting stuff"));
|
||||
|
||||
/* need to find title of page */
|
||||
|
||||
if (c->data.html.layout != NULL)
|
||||
{
|
||||
/* TODO: skip if width is unchanged */
|
||||
layout_document(c->data.html.layout->children, (unsigned long)width);
|
||||
return;
|
||||
return title;
|
||||
}
|
||||
|
||||
LOG(("Setting document to myDoc"));
|
||||
c->data.html.document = c->data.html.parser->myDoc;
|
||||
xmlDebugDumpDocument(stderr, c->data.html.parser->myDoc);
|
||||
//xmlDebugDumpDocument(stderr, c->data.html.parser->myDoc);
|
||||
|
||||
/* skip to start of html */
|
||||
LOG(("Skipping to html"));
|
||||
if (c->data.html.document == NULL)
|
||||
{
|
||||
LOG(("There is no document!"));
|
||||
return;
|
||||
return title;
|
||||
}
|
||||
for (c->data.html.markup = c->data.html.document->children;
|
||||
c->data.html.markup != 0 &&
|
||||
@ -146,12 +151,12 @@ void content_html_reformat(struct content* c, int width)
|
||||
if (c->data.html.markup == 0)
|
||||
{
|
||||
LOG(("No markup"));
|
||||
return;
|
||||
return title;
|
||||
}
|
||||
if (strcmp((const char *) c->data.html.markup->name, "html"))
|
||||
{
|
||||
LOG(("Not html"));
|
||||
return;
|
||||
return title;
|
||||
}
|
||||
|
||||
// xfree(c->data.html.stylesheet);
|
||||
@ -183,7 +188,7 @@ void content_html_reformat(struct content* c, int width)
|
||||
|
||||
/* can tidy up memory here? */
|
||||
|
||||
return;
|
||||
return title;
|
||||
}
|
||||
|
||||
void browser_window_reformat(struct browser_window* bw)
|
||||
@ -203,7 +208,7 @@ void browser_window_reformat(struct browser_window* bw)
|
||||
LOG(("HTML content."));
|
||||
browser_window_set_status(bw, "Formatting page...");
|
||||
time0 = clock();
|
||||
content_html_reformat(bw->current_content, gui_window_get_width(bw->window));
|
||||
gui_window_set_title(bw->window, content_html_reformat(bw->current_content, gui_window_get_width(bw->window)));
|
||||
time1 = clock();
|
||||
LOG(("Content reformatted"));
|
||||
if (bw->current_content->data.html.layout != NULL)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* $Id: gui.h,v 1.3 2002/12/30 22:56:30 monkeyson Exp $
|
||||
* $Id: gui.h,v 1.4 2003/01/11 17:33:31 monkeyson Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETSURF_DESKTOP_GUI_H_
|
||||
@ -32,6 +32,7 @@ void gui_window_redraw_window(gui_window* g);
|
||||
void gui_window_set_scroll(gui_window* g, int sx, int sy);
|
||||
void gui_window_set_extent(gui_window* g, int width, int height);
|
||||
void gui_window_set_status(gui_window* g, char* text);
|
||||
void gui_window_set_title(gui_window* g, char* title);
|
||||
|
||||
void gui_window_message(gui_window* g, gui_message* msg);
|
||||
|
||||
|
262
riscos/gui.c
262
riscos/gui.c
@ -1,16 +1,20 @@
|
||||
/**
|
||||
* $Id: gui.c,v 1.14 2003/01/07 23:16:04 bursa Exp $
|
||||
* $Id: gui.c,v 1.15 2003/01/11 17:33:31 monkeyson Exp $
|
||||
*/
|
||||
|
||||
#include "netsurf/riscos/font.h"
|
||||
#include "netsurf/desktop/gui.h"
|
||||
#include "netsurf/render/utils.h"
|
||||
#include "netsurf/desktop/netsurf.h"
|
||||
#include "oslib/osfile.h"
|
||||
#include "oslib/os.h"
|
||||
#include "oslib/wimp.h"
|
||||
#include "oslib/colourtrans.h"
|
||||
#include "netsurf/riscos/theme.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
int gadget_subtract_x;
|
||||
int gadget_subtract_y;
|
||||
@ -393,6 +397,15 @@ gui_window* create_gui_browser_window(struct browser_window* bw)
|
||||
return g;
|
||||
}
|
||||
|
||||
void gui_window_set_title(gui_window* g, char* title)
|
||||
{
|
||||
if (title != NULL)
|
||||
strncpy(g->title, title, 255);
|
||||
else
|
||||
strcpy(g->title, "NetSurf (untitled document)");
|
||||
wimp_force_redraw_title(g->data.browser.window);
|
||||
}
|
||||
|
||||
void gui_window_destroy(gui_window* g)
|
||||
{
|
||||
if (g == NULL)
|
||||
@ -550,7 +563,7 @@ void ro_gui_window_redraw_box(gui_window* g, struct box * box, signed long x, si
|
||||
(wimp_COLOUR_DARK_GREY << wimp_ICON_FG_COLOUR_SHIFT) |
|
||||
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT);
|
||||
icon.data.indirected_text.text = box->gadget->data.textbox.text;
|
||||
icon.data.indirected_text.size = box->gadget->data.textbox.maxlength;
|
||||
icon.data.indirected_text.size = box->gadget->data.textbox.maxlength + 1;
|
||||
icon.data.indirected_text.validation = " ";
|
||||
fprintf(stderr, "writing GADGET TEXTBOX\n");
|
||||
wimp_plot_icon(&icon);
|
||||
@ -1206,6 +1219,211 @@ void ro_gui_w_click(wimp_pointer* pointer)
|
||||
}
|
||||
}
|
||||
|
||||
double calculate_angle(double x, double y)
|
||||
{
|
||||
double a;
|
||||
if (x == 0.0)
|
||||
{
|
||||
if (y < 0.0)
|
||||
a = 0.0;
|
||||
else
|
||||
a = M_PI;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = atan(y / x);
|
||||
if (x > 0.0)
|
||||
a += M_PI_2;
|
||||
else
|
||||
a -= M_PI_2;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
int anglesDifferent(double a, double b)
|
||||
{
|
||||
double c;
|
||||
if (a < 0.0)
|
||||
a += M_2_PI;
|
||||
if (b < 0.0)
|
||||
b += M_2_PI;
|
||||
if (a > M_2_PI)
|
||||
a -= M_2_PI;
|
||||
if (b > M_2_PI)
|
||||
b -= M_2_PI;
|
||||
c = a - b;
|
||||
if (c < 0.0)
|
||||
c += M_2_PI;
|
||||
if (c > M_2_PI)
|
||||
c -= M_2_PI;
|
||||
return (c > M_PI / 6.0);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
mouseaction_NONE,
|
||||
mouseaction_BACK, mouseaction_FORWARD,
|
||||
mouseaction_RELOAD, mouseaction_PARENT,
|
||||
mouseaction_NEWWINDOW_OR_LINKFG, mouseaction_DUPLICATE_OR_LINKBG,
|
||||
mouseaction_TOGGLESIZE, mouseaction_ICONISE, mouseaction_CLOSE
|
||||
} mouseaction;
|
||||
|
||||
#define STOPPED 2
|
||||
#define THRESHOLD 16
|
||||
#define DAMPING 1
|
||||
|
||||
mouseaction ro_gui_try_mouse_action(void)
|
||||
{
|
||||
os_coord start, current, last, offset, moved;
|
||||
double offsetDistance, movedDistance;
|
||||
double angle, oldAngle;
|
||||
bits z;
|
||||
os_coord now;
|
||||
int status;
|
||||
int m;
|
||||
enum {move_NONE, move_LEFT, move_RIGHT, move_UP, move_DOWN} moves[5];
|
||||
|
||||
moves[0] = move_NONE;
|
||||
m = 1;
|
||||
|
||||
os_mouse(&start.x, &start.y, &z, &now);
|
||||
status = 0;
|
||||
|
||||
do
|
||||
{
|
||||
os_mouse(¤t.x, ¤t.y, &z, &now);
|
||||
offset.x = current.x - start.x;
|
||||
offset.y = current.y - start.y;
|
||||
moved.x = current.x - last.x;
|
||||
moved.y = current.y - last.y;
|
||||
offsetDistance = sqrt(offset.x * offset.x + offset.y * offset.y);
|
||||
if (moved.x > 0 || moved.y > 0)
|
||||
movedDistance = sqrt(moved.x * moved.x + moved.y * moved.y);
|
||||
else
|
||||
movedDistance = 0.0;
|
||||
angle = calculate_angle(offset.x, offset.y);
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case 1:
|
||||
if (movedDistance < STOPPED ||
|
||||
(movedDistance > STOPPED*2.0 && anglesDifferent(angle, oldAngle)))
|
||||
{
|
||||
start.x = current.x;
|
||||
start.y = current.y;
|
||||
status = 0;
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
if (offsetDistance > THRESHOLD)
|
||||
{
|
||||
if (fabs(offset.x) > fabs(offset.y))
|
||||
{
|
||||
if (fabs(offset.y) < fabs(offset.x) * DAMPING && fabs(offset.x) > THRESHOLD*0.75)
|
||||
{
|
||||
if (offset.x < 0)
|
||||
moves[m] = move_LEFT;
|
||||
else
|
||||
moves[m] = move_RIGHT;
|
||||
if (moves[m] != moves[m-1])
|
||||
m++;
|
||||
start.x = current.x;
|
||||
start.y = current.y;
|
||||
oldAngle = angle;
|
||||
status = 1;
|
||||
}
|
||||
}
|
||||
else if (fabs(offset.y) > fabs(offset.x))
|
||||
{
|
||||
if (fabs(offset.x) < fabs(offset.y) * DAMPING && fabs(offset.y) > THRESHOLD*0.75)
|
||||
{
|
||||
if (offset.y < 0)
|
||||
moves[m] = move_DOWN;
|
||||
else
|
||||
moves[m] = move_UP;
|
||||
if (moves[m] != moves[m-1])
|
||||
m++;
|
||||
start.x = current.x;
|
||||
start.y = current.y;
|
||||
oldAngle = angle;
|
||||
status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
last.x = current.x;
|
||||
last.y = current.y;
|
||||
LOG(("m = %d", m));
|
||||
|
||||
} while ((z & 2) != 0 && m < 4);
|
||||
|
||||
LOG(("MOUSEACTIONS: %d %d %d %d\n",moves[0], moves[1], moves[2], moves[3]));
|
||||
if (m == 2)
|
||||
{
|
||||
switch (moves[1])
|
||||
{
|
||||
case move_LEFT:
|
||||
LOG(("mouse action: go back"));
|
||||
return mouseaction_BACK;
|
||||
case move_RIGHT:
|
||||
LOG(("MOUSE ACTION: GO FORWARD"));
|
||||
return mouseaction_FORWARD;
|
||||
case move_DOWN:
|
||||
LOG(("mouse action: create new window // open link in new window, foreground"));
|
||||
return mouseaction_NEWWINDOW_OR_LINKFG;
|
||||
}
|
||||
}
|
||||
|
||||
if (m == 3)
|
||||
{
|
||||
switch (moves[1])
|
||||
{
|
||||
case move_UP:
|
||||
switch (moves[2])
|
||||
{
|
||||
case move_DOWN:
|
||||
LOG(("mouse action: reload"));
|
||||
return mouseaction_RELOAD;
|
||||
case move_RIGHT:
|
||||
LOG(("mouse action: toggle size"));
|
||||
return mouseaction_TOGGLESIZE;
|
||||
case move_LEFT:
|
||||
LOG(("mouse action: parent directroy"));
|
||||
return mouseaction_PARENT;
|
||||
}
|
||||
break;
|
||||
|
||||
case move_DOWN:
|
||||
switch (moves[2])
|
||||
{
|
||||
case move_LEFT:
|
||||
LOG(("mouse action: iconise"));
|
||||
return mouseaction_ICONISE;
|
||||
case move_UP:
|
||||
LOG(("mouse action: duplicate // open link in new window, background"));
|
||||
return mouseaction_DUPLICATE_OR_LINKBG;
|
||||
case move_RIGHT:
|
||||
LOG(("mouse action: close"));
|
||||
return mouseaction_CLOSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m == 4)
|
||||
{
|
||||
if (moves[1] == move_RIGHT && moves[2] == move_LEFT &&
|
||||
moves[3] == move_RIGHT)
|
||||
{
|
||||
LOG(("mouse action: close window"));
|
||||
return mouseaction_CLOSE;
|
||||
}
|
||||
}
|
||||
|
||||
return mouseaction_NONE;
|
||||
}
|
||||
|
||||
void ro_gui_window_click(gui_window* g, wimp_pointer* pointer)
|
||||
{
|
||||
struct browser_action msg;
|
||||
@ -1228,7 +1446,34 @@ void ro_gui_window_click(gui_window* g, wimp_pointer* pointer)
|
||||
|
||||
if (pointer->buttons == wimp_CLICK_MENU)
|
||||
{
|
||||
ro_gui_create_menu((wimp_menu*) &browser_menu, pointer->pos.x - 64, pointer->pos.y, g);
|
||||
/* check for mouse gestures */
|
||||
mouseaction ma = ro_gui_try_mouse_action();
|
||||
if (ma == mouseaction_NONE)
|
||||
{
|
||||
os_t now;
|
||||
int z;
|
||||
|
||||
os_mouse(&x, &y, &z, &now);
|
||||
ro_gui_create_menu((wimp_menu*) &browser_menu, x - 64, y, g);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "MOUSE GESTURE %d\n", ma);
|
||||
switch (ma)
|
||||
{
|
||||
case mouseaction_BACK:
|
||||
browser_window_back(g->data.browser.bw);
|
||||
break;
|
||||
|
||||
case mouseaction_FORWARD:
|
||||
browser_window_forward(g->data.browser.bw);
|
||||
break;
|
||||
|
||||
case mouseaction_RELOAD:
|
||||
browser_window_open_location_historical(g->data.browser.bw, g->data.browser.bw->url);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (g->data.browser.bw->current_content != NULL)
|
||||
{
|
||||
@ -1819,14 +2064,15 @@ void gui_edit_textarea(struct browser_window* bw, struct gui_gadget* g)
|
||||
{
|
||||
FILE* file;
|
||||
|
||||
system("cdir <Wimp$ScrapDir>.NetSurf");
|
||||
file = fopen("<Wimp$Scrapdir>.NetSurf.TextArea", "w");
|
||||
xosfile_create_dir("<Wimp$ScrapDir>.NetSurf", 77);
|
||||
file = fopen("<Wimp$ScrapDir>/NetSurf/TextArea", "w");
|
||||
if (g->data.textarea.text != 0)
|
||||
fprintf(file, "%s", g->data.textarea.text);
|
||||
fprintf(stderr, "closing file.\n");
|
||||
fclose(file);
|
||||
|
||||
system("settype <Wimp$ScrapDir>.NetSurf.TextArea FFF");
|
||||
system("filer_run <Wimp$ScrapDir>.NetSurf.TextArea");
|
||||
xosfile_set_type("<Wimp$ScrapDir>.NetSurf.TextArea", osfile_TYPE_TEXT);
|
||||
xos_cli("filer_run <Wimp$ScrapDir>.NetSurf.TextArea");
|
||||
}
|
||||
|
||||
struct msg_datasave {
|
||||
@ -2004,7 +2250,7 @@ void gui_edit_textbox(struct browser_window* bw, struct gui_gadget* g)
|
||||
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT) |
|
||||
(wimp_BUTTON_WRITABLE << wimp_ICON_BUTTON_TYPE_SHIFT);
|
||||
icon.icon.data.indirected_text.text = g->data.textbox.text;
|
||||
icon.icon.data.indirected_text.size = g->data.textbox.maxlength;
|
||||
icon.icon.data.indirected_text.size = g->data.textbox.maxlength + 1;
|
||||
icon.icon.data.indirected_text.validation = " ";
|
||||
current_textbox_i = wimp_create_icon(&icon);
|
||||
current_textbox = g;
|
||||
|
Loading…
Reference in New Issue
Block a user