mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-25 05:27:00 +03:00
alter mouse click handling so browser window is uses the same interface
as other root window widgets svn path=/trunk/netsurf/; revision=6464
This commit is contained in:
parent
e5c225f7d9
commit
f32c4ff799
@ -258,25 +258,17 @@ fb_cursor_init(framebuffer_t *fb)
|
||||
return cursor;
|
||||
}
|
||||
|
||||
void
|
||||
fb_cursor_click(framebuffer_t *fb,
|
||||
struct gui_window *g,
|
||||
browser_mouse_state st)
|
||||
int fb_cursor_x(framebuffer_t *fb)
|
||||
{
|
||||
/* check click lies within window */
|
||||
if ((fb->cursor->x > g->x) &&
|
||||
(fb->cursor->y > g->y) &&
|
||||
(fb->cursor->x < g->x + g->width) &&
|
||||
(fb->cursor->y < g->y + g->height)) {
|
||||
browser_window_mouse_click(g->bw,
|
||||
st,
|
||||
fb->cursor->x - g->x + g->scrollx,
|
||||
fb->cursor->y - g->y + g->scrolly);
|
||||
} else {
|
||||
fb_rootwindow_click(fb, g, st, fb->cursor->x, fb->cursor->y);
|
||||
}
|
||||
return fb->cursor->x;
|
||||
}
|
||||
|
||||
int fb_cursor_y(framebuffer_t *fb)
|
||||
{
|
||||
return fb->cursor->y;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* c-basic-offset:8
|
||||
|
@ -19,6 +19,10 @@
|
||||
#ifndef FRAMEBUFFER_FB_CURSOR
|
||||
#define FRAMEBUFFER_FB_CURSOR
|
||||
|
||||
int fb_cursor_x(framebuffer_t *fb);
|
||||
|
||||
int fb_cursor_y(framebuffer_t *fb);
|
||||
|
||||
void fb_cursor_move(struct framebuffer_s *fb, int x, int y);
|
||||
|
||||
void fb_cursor_move_abs(struct framebuffer_s *fb, int x, int y);
|
||||
|
@ -638,9 +638,10 @@ void fb_os_input(struct gui_window *g, bool active)
|
||||
fb_cursor_move(framebuffer, 1, 0);
|
||||
break;
|
||||
case BTN_LEFT:
|
||||
fb_cursor_click(framebuffer,
|
||||
g,
|
||||
BROWSER_MOUSE_CLICK_1);
|
||||
fb_rootwindow_click(g,
|
||||
BROWSER_MOUSE_CLICK_1,
|
||||
fb_cursor_x(framebuffer),
|
||||
fb_cursor_y(framebuffer));
|
||||
break;
|
||||
}
|
||||
} else if (event.type == EV_REL) {
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "framebuffer/fb_plotters.h"
|
||||
#include "framebuffer/fb_frontend.h"
|
||||
#include "framebuffer/fb_cursor.h"
|
||||
#include "framebuffer/fb_rootwindow.h"
|
||||
|
||||
#include "utils/log.h"
|
||||
|
||||
@ -146,11 +147,17 @@ void fb_os_input(struct gui_window *g, bool active)
|
||||
switch (event.button.button) {
|
||||
|
||||
case SDL_BUTTON_LEFT:
|
||||
fb_cursor_click(framebuffer, g, BROWSER_MOUSE_CLICK_1);
|
||||
fb_rootwindow_click(g,
|
||||
BROWSER_MOUSE_CLICK_1,
|
||||
fb_cursor_x(framebuffer),
|
||||
fb_cursor_y(framebuffer));
|
||||
break;
|
||||
|
||||
case SDL_BUTTON_RIGHT:
|
||||
fb_cursor_click(framebuffer, g, BROWSER_MOUSE_CLICK_2);
|
||||
fb_rootwindow_click(g,
|
||||
BROWSER_MOUSE_CLICK_2,
|
||||
fb_cursor_x(framebuffer),
|
||||
fb_cursor_y(framebuffer));
|
||||
break;
|
||||
|
||||
case SDL_BUTTON_WHEELUP:
|
||||
|
@ -279,6 +279,15 @@ void gui_quit(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
fb_browser_window_click(struct gui_window *g, browser_mouse_state st, int x, int y)
|
||||
{
|
||||
browser_window_mouse_click(g->bw,
|
||||
st,
|
||||
x - g->x + g->scrollx,
|
||||
y - g->y + g->scrolly);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct gui_window *gui_create_browser_window(struct browser_window *bw,
|
||||
struct browser_window *clone,
|
||||
@ -299,6 +308,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
|
||||
|
||||
if (window_list == NULL) {
|
||||
window_list = input_window = g;
|
||||
fb_add_window_widget(g, fb_browser_window_click);
|
||||
} else {
|
||||
for(p = window_list; p->next != NULL; p = p->next);
|
||||
p->next = g;
|
||||
|
@ -355,7 +355,6 @@ static const fb_widget_image_t reload = {
|
||||
};
|
||||
|
||||
|
||||
typedef int (*fb_widget_mouseclick_t)(framebuffer_t *fb, struct gui_window *g);
|
||||
|
||||
struct fb_widget {
|
||||
struct fb_widget *next;
|
||||
@ -365,11 +364,11 @@ struct fb_widget {
|
||||
int height;
|
||||
fb_widget_mouseclick_t click;
|
||||
struct bitmap *bitmap;
|
||||
struct gui_window *g;
|
||||
};
|
||||
|
||||
static struct fb_widget *widget_list;
|
||||
|
||||
|
||||
static struct fb_widget *
|
||||
fb_add_button_widget(int x,
|
||||
int y,
|
||||
@ -411,9 +410,33 @@ fb_add_button_widget(int x,
|
||||
return new_widget;
|
||||
}
|
||||
|
||||
struct fb_widget *
|
||||
fb_add_window_widget(struct gui_window *g,
|
||||
fb_widget_mouseclick_t click_rtn)
|
||||
{
|
||||
struct fb_widget *new_widget;
|
||||
new_widget = malloc(sizeof(struct fb_widget));
|
||||
if (new_widget == NULL)
|
||||
return NULL;
|
||||
|
||||
new_widget->x = g->x;
|
||||
new_widget->y = g->y;
|
||||
new_widget->width = g->width;
|
||||
new_widget->height = g->height;
|
||||
new_widget->click = click_rtn;
|
||||
|
||||
new_widget->bitmap = NULL;
|
||||
new_widget->g = g;
|
||||
|
||||
new_widget->next = widget_list;
|
||||
widget_list = new_widget;
|
||||
|
||||
return new_widget;
|
||||
}
|
||||
|
||||
/* left icon click routine */
|
||||
static int
|
||||
fb_widget_leftarrow_click(framebuffer_t *fb, struct gui_window *g)
|
||||
fb_widget_leftarrow_click(struct gui_window *g, browser_mouse_state st, int x, int y)
|
||||
{
|
||||
if (history_back_available(g->bw->history))
|
||||
history_back(g->bw, g->bw->history);
|
||||
@ -423,7 +446,7 @@ fb_widget_leftarrow_click(framebuffer_t *fb, struct gui_window *g)
|
||||
|
||||
/* right arrow icon click routine */
|
||||
static int
|
||||
fb_widget_rightarrow_click(framebuffer_t *fb, struct gui_window *g)
|
||||
fb_widget_rightarrow_click(struct gui_window *g, browser_mouse_state st, int x, int y)
|
||||
{
|
||||
if (history_forward_available(g->bw->history))
|
||||
history_forward(g->bw, g->bw->history);
|
||||
@ -466,21 +489,20 @@ void fb_rootwindow_create(framebuffer_t *fb)
|
||||
fb_plot_ctx = saved_plot_ctx;
|
||||
}
|
||||
|
||||
void fb_rootwindow_click(framebuffer_t *fb,
|
||||
struct gui_window *g,
|
||||
browser_mouse_state st ,
|
||||
int x, int y)
|
||||
void
|
||||
fb_rootwindow_click(struct gui_window *g, browser_mouse_state st, int x, int y)
|
||||
{
|
||||
struct fb_widget *widget;
|
||||
LOG(("Click in root window"));
|
||||
|
||||
widget = widget_list;
|
||||
while (widget != NULL) {
|
||||
if ((x > widget->x) &&
|
||||
if ((widget->click != NULL) &&
|
||||
(x > widget->x) &&
|
||||
(y > widget->y) &&
|
||||
(x < widget->x + widget->width) &&
|
||||
(y < widget->y + widget->height)) {
|
||||
widget->click(fb, g);
|
||||
widget->click(g, st, x, y);
|
||||
break;
|
||||
}
|
||||
widget = widget->next;
|
||||
|
@ -16,5 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void fb_rootwindow_click(framebuffer_t *fb, struct gui_window *g,browser_mouse_state st , int x, int y);
|
||||
typedef int (*fb_widget_mouseclick_t)(struct gui_window *g, browser_mouse_state st, int x, int y);
|
||||
|
||||
void fb_rootwindow_click(struct gui_window *g, browser_mouse_state st , int x, int y);
|
||||
void fb_rootwindow_create(framebuffer_t *fb);
|
||||
|
||||
struct fb_widget *fb_add_window_widget(struct gui_window *g, fb_widget_mouseclick_t click_rtn);
|
||||
|
Loading…
Reference in New Issue
Block a user