Simplify local history interface.

This commit is contained in:
Michael Drake 2014-02-08 22:43:54 +00:00
parent 2cd2e5b054
commit 3d7cd77982
17 changed files with 67 additions and 123 deletions

View File

@ -916,7 +916,7 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved
}
else
{
history_go(gwin->bw, gwin->bw->history,
history_go(gwin->bw->history,
(struct history_entry *)userdata, false);
}
break;

View File

@ -1064,12 +1064,12 @@ void ami_gui_history(struct gui_window_2 *gwin, bool back)
if(back == true)
{
if(browser_window_back_available(gwin->bw))
history_back(gwin->bw, gwin->bw->history);
history_back(gwin->bw->history, false);
}
else
{
if(browser_window_forward_available(gwin->bw))
history_forward(gwin->bw, gwin->bw->history);
history_forward(gwin->bw->history, false);
}
ami_update_buttons(gwin);

View File

@ -210,13 +210,13 @@ bool ami_history_click(struct history_window *hw,uint16 code)
switch(code)
{
case SELECTUP:
history_click(hw->bw,history_current,x,y,false);
history_click(history_current,x,y,false);
ami_history_redraw(hw);
ami_schedule_redraw(hw->bw->window->shared, true);
break;
case MIDDLEUP:
history_click(hw->bw,history_current,x,y,true);
history_click(history_current,x,y,true);
ami_history_redraw(hw);
break;

View File

@ -948,7 +948,7 @@ void toolbar_back_click(struct s_toolbar *tb)
assert(bw != NULL);
if( history_back_available(bw->history) )
history_back(bw, bw->history);
history_back(bw->history, false);
}
void toolbar_reload_click(struct s_toolbar *tb)
@ -975,7 +975,7 @@ void toolbar_forward_click(struct s_toolbar *tb)
assert(bw != NULL);
if (history_forward_available(bw->history))
history_forward(bw, bw->history);
history_forward(bw->history, false);
}
void toolbar_home_click(struct s_toolbar *tb)

View File

@ -976,7 +976,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m
case 'back':
if (!history_back_available(bw->history))
break;
history_back(bw, bw->history);
history_back(bw->history, false);
nsbeos_window_update_back_forward(scaffold);
break;
case B_NETPOSITIVE_FORWARD:
@ -984,7 +984,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m
case 'forw':
if (!history_forward_available(bw->history))
break;
history_forward(bw, bw->history);
history_forward(bw->history, false);
nsbeos_window_update_back_forward(scaffold);
break;
case B_NETPOSITIVE_STOP:

View File

@ -118,7 +118,7 @@
- (IBAction) goBack: (id) sender;
{
if (browser && history_back_available( browser->history )) {
history_back(browser, browser->history);
history_back(browser->history, false);
[self updateBackForward];
}
}
@ -126,7 +126,7 @@
- (IBAction) goForward: (id) sender;
{
if (browser && history_forward_available( browser->history )) {
history_forward(browser, browser->history);
history_forward(browser->history, false);
[self updateBackForward];
}
}
@ -316,7 +316,7 @@ static bool history_add_menu_item_cb( const struct history *history, int x0, int
- (IBAction) historyItemSelected: (id) sender;
{
struct history_entry *entry = [[sender representedObject] pointerValue];
history_go( browser, browser->history, entry, false );
history_go( browser->history, entry, false );
[self updateBackForward];
}

View File

@ -72,7 +72,7 @@
{
const NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil];
const bool newWindow = [theEvent modifierFlags] & NSCommandKeyMask;
if (history_click( browser, browser->history,
if (history_click( browser->history,
cocoa_pt_to_px( location.x ), cocoa_pt_to_px( location.y ),
newWindow )) {
[browserView setHistoryVisible: NO];

View File

@ -764,9 +764,9 @@ void browser_window_initialise_common(struct browser_window *bw,
assert(bw);
if (!clone)
bw->history = history_create();
bw->history = history_create(bw);
else
bw->history = history_clone(clone->history);
bw->history = history_clone(clone->history, bw);
/* window characteristics */
bw->refresh_interval = -1;

View File

@ -78,6 +78,8 @@ struct history {
int width;
/** Height of layout. */
int height;
/** Browser window that local history belongs to */
struct browser_window *bw;
};
static struct history_entry *history_clone_entry(struct history *history,
@ -102,7 +104,7 @@ static bool history_enumerate_entry(const struct history *history,
* \return pointer to an opaque history structure, 0 on failure.
*/
struct history *history_create(void)
struct history *history_create(struct browser_window *bw)
{
struct history *history;
@ -113,6 +115,7 @@ struct history *history_create(void)
}
history->width = RIGHT_MARGIN / 2;
history->height = BOTTOM_MARGIN / 2;
history->bw = bw;
return history;
}
@ -125,12 +128,13 @@ struct history *history_create(void)
* \return pointer to an opaque history structure, 0 on failure.
*/
struct history *history_clone(struct history *history)
struct history *history_clone(struct history *history,
struct browser_window *bw)
{
struct history *new_history;
if (!history->start)
return history_create();
return history_create(bw);
new_history = malloc(sizeof *history);
if (!new_history)
@ -370,13 +374,14 @@ void history_free_entry(struct history_entry *entry)
*
* \param bw browser window
* \param history history of the window
* \param new_window whether to open in new window
*/
void history_back(struct browser_window *bw, struct history *history)
void history_back(struct history *history, bool new_window)
{
if (!history || !history->current || !history->current->back)
return;
history_go(bw, history, history->current->back, false);
history_go(history, history->current->back, new_window);
}
@ -385,13 +390,14 @@ void history_back(struct browser_window *bw, struct history *history)
*
* \param bw browser window
* \param history history of the window
* \param new_window whether to open in new window
*/
void history_forward(struct browser_window *bw, struct history *history)
void history_forward(struct history *history, bool new_window)
{
if (!history || !history->current || !history->current->forward_pref)
return;
history_go(bw, history, history->current->forward_pref, false);
history_go(history, history->current->forward_pref, new_window);
}
@ -422,9 +428,7 @@ bool history_forward_available(struct history *history)
/* Documented in local_history.h */
void history_go(struct browser_window *bw,
struct history *history,
struct history_entry *entry,
void history_go(struct history *history, struct history_entry *entry,
bool new_window)
{
nsurl *url;
@ -452,14 +456,11 @@ void history_go(struct browser_window *bw,
history->current = entry;
browser_window_create(BROWSER_WINDOW_VERIFIABLE,
url,
NULL,
bw,
NULL);
url, NULL, history->bw, NULL);
history->current = current;
} else {
history->current = entry;
browser_window_navigate(bw, url, NULL,
browser_window_navigate(history->bw, url, NULL,
BROWSER_WINDOW_VERIFIABLE, NULL, NULL, NULL);
}
@ -702,8 +703,7 @@ bool history_redraw_entry(struct history *history,
* \return true if action was taken, false if click was not on an entry
*/
bool history_click(struct browser_window *bw, struct history *history,
int x, int y, bool new_window)
bool history_click(struct history *history, int x, int y, bool new_window)
{
struct history_entry *entry;
@ -713,7 +713,7 @@ bool history_click(struct browser_window *bw, struct history *history,
if (entry == history->current)
return false;
history_go(bw, history, entry, new_window);
history_go(history, entry, new_window);
return true;
}

View File

@ -32,14 +32,15 @@ struct browser_window;
struct history_entry;
struct redraw_context;
struct history *history_create(void);
struct history *history_clone(struct history *history);
struct history *history_create(struct browser_window *bw);
struct history *history_clone(struct history *history,
struct browser_window *bw);
void history_add(struct history *history, struct hlcache_handle *content,
lwc_string *frag_id);
void history_update(struct history *history, struct hlcache_handle *content);
void history_destroy(struct history *history);
void history_back(struct browser_window *bw, struct history *history);
void history_forward(struct browser_window *bw, struct history *history);
void history_back(struct history *history, bool new_window);
void history_forward(struct history *history, bool new_window);
bool history_back_available(struct history *history);
bool history_forward_available(struct history *history);
void history_size(struct history *history, int *width, int *height);
@ -47,8 +48,7 @@ bool history_redraw(struct history *history, const struct redraw_context *ctx);
bool history_redraw_rectangle(struct history *history,
int x0, int y0, int x1, int y1, int x, int y,
const struct redraw_context *ctx);
bool history_click(struct browser_window *bw, struct history *history,
int x, int y, bool new_window);
bool history_click(struct history *history, int x, int y, bool new_window);
const char *history_position_url(struct history *history, int x, int y);
/**
@ -59,7 +59,8 @@ const char *history_position_url(struct history *history, int x, int y);
* \param entry Current history entry
* \return true to continue enumeration, false to cancel enumeration
*/
typedef bool (*history_enumerate_cb)(const struct history *history, int x0, int y0,
typedef bool (*history_enumerate_cb)(const struct history *history,
int x0, int y0,
int x1, int y1,
const struct history_entry *entry, void *user_data);
@ -71,7 +72,8 @@ typedef bool (*history_enumerate_cb)(const struct history *history, int x0, int
* \param cb callback function
* \param user_data context pointer passed to cb
*/
void history_enumerate(const struct history *history, history_enumerate_cb cb, void *user_data);
void history_enumerate(const struct history *history,
history_enumerate_cb cb, void *user_data);
/**
* Enumerate all entries that will be reached by the 'forward' button
@ -81,7 +83,7 @@ void history_enumerate(const struct history *history, history_enumerate_cb cb, v
* \param user_data Data passed to the callback
*/
void history_enumerate_forward( struct history *history,
history_enumerate_cb cb, void *user_data );
history_enumerate_cb cb, void *user_data);
/**
* Enumerate all entries that will be reached by the 'back' button
@ -91,7 +93,7 @@ void history_enumerate_forward( struct history *history,
* \param user_data Data passed to the callback
*/
void history_enumerate_back( struct history *history,
history_enumerate_cb cb, void *user_data );
history_enumerate_cb cb, void *user_data);
/**
* Returns the URL to a history entry
@ -125,7 +127,7 @@ const char *history_entry_get_title(const struct history_entry *entry);
* \param entry entry to open
* \param new_window open entry in new window
*/
void history_go(struct browser_window *bw, struct history *history,
struct history_entry *entry, bool new_window);
void history_go(struct history *history, struct history_entry *entry,
bool new_window);
#endif

View File

@ -989,7 +989,7 @@ fb_leftarrow_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
if (history_back_available(bw->history))
history_back(bw, bw->history);
history_back(bw->history, false);
fb_update_back_forward(gw);
@ -1007,7 +1007,7 @@ fb_rightarrow_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
if (history_forward_available(bw->history))
history_forward(bw, bw->history);
history_forward(bw->history, false);
fb_update_back_forward(gw);
return 1;

View File

@ -97,7 +97,7 @@ localhistory_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
if (cbi->event->type != NSFB_EVENT_KEY_UP)
return 0;
history_click(glh->bw, glh->bw->history, cbi->x, cbi->y, false);
history_click(glh->bw->history, cbi->x, cbi->y, false);
fbtk_set_mapping(glh->window, false);

View File

@ -1422,7 +1422,7 @@ MULTIHANDLER(back)
nsgtk_search_set_forward_state(true, bw);
nsgtk_search_set_back_state(true, bw);
history_back(bw, bw->history);
history_back(bw->history, false);
nsgtk_window_update_back_forward(g);
return TRUE;
@ -1442,7 +1442,7 @@ MULTIHANDLER(forward)
nsgtk_search_set_forward_state(true, bw);
nsgtk_search_set_back_state(true, bw);
history_forward(bw, bw->history);
history_forward(bw->history, false);
nsgtk_window_update_back_forward(g);
return TRUE;
@ -1741,8 +1741,7 @@ static gboolean nsgtk_history_button_press_event(GtkWidget *widget,
LOG(("X=%g, Y=%g", event->x, event->y));
history_click(bw, bw->history,
event->x, event->y, false);
history_click(bw->history, event->x, event->y, false);
return TRUE;
}

View File

@ -348,7 +348,7 @@ bool ro_gui_history_click(wimp_pointer *pointer)
x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / 2;
y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / 2;
history_click(history_bw, history_current, x, y,
history_click(history_current, x, y,
pointer->buttons == wimp_CLICK_ADJUST);
return true;

View File

@ -135,8 +135,6 @@ static bool ro_gui_window_navigate_up(struct gui_window *g, const char *url);
static void ro_gui_window_action_home(struct gui_window *g);
static void ro_gui_window_action_new_window(struct gui_window *g);
static void ro_gui_window_action_local_history(struct gui_window *g);
static void ro_gui_window_action_navigate_back_new(struct gui_window *g);
static void ro_gui_window_action_navigate_forward_new(struct gui_window *g);
static void ro_gui_window_action_save(struct gui_window *g,
gui_save_type save_type);
static void ro_gui_window_action_search(struct gui_window *g);
@ -2944,11 +2942,11 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
break;
case BROWSER_NAVIGATE_BACK:
if (bw != NULL && bw->history != NULL)
history_back(bw, bw->history);
history_back(bw->history, false);
break;
case BROWSER_NAVIGATE_FORWARD:
if (bw != NULL && bw->history != NULL)
history_forward(bw, bw->history);
history_forward(bw->history, false);
break;
case BROWSER_NAVIGATE_UP:
if (bw != NULL && h != NULL)
@ -3642,20 +3640,22 @@ void ro_gui_window_toolbar_click(void *data,
switch (action.button) {
case TOOLBAR_BUTTON_BACK:
if (g->bw != NULL && g->bw->history != NULL)
history_back(g->bw, g->bw->history);
history_back(g->bw->history, false);
break;
case TOOLBAR_BUTTON_BACK_NEW:
ro_gui_window_action_navigate_back_new(g);
if (g->bw != NULL && g->bw->history != NULL)
history_back(g->bw->history, true);
break;
case TOOLBAR_BUTTON_FORWARD:
if (g->bw != NULL && g->bw->history != NULL)
history_forward(g->bw, g->bw->history);
history_forward(g->bw->history, false);
break;
case TOOLBAR_BUTTON_FORWARD_NEW:
ro_gui_window_action_navigate_forward_new(g);
if (g->bw != NULL && g->bw->history != NULL)
history_forward(g->bw->history, true);
break;
case TOOLBAR_BUTTON_STOP:
@ -4098,62 +4098,6 @@ void ro_gui_window_action_home(struct gui_window *g)
}
/**
* Navigate back from a browser window into a new window.
*
* \param *g The browser window to act on.
*/
void ro_gui_window_action_navigate_back_new(struct gui_window *g)
{
struct browser_window *new_bw;
nserror error;
if (g == NULL || g->bw == NULL)
return;
error = browser_window_create(BROWSER_WINDOW_VERIFIABLE,
NULL,
NULL,
g->bw,
&new_bw);
if (error != NSERROR_OK) {
warn_user(messages_get_errorcode(error), 0);
} else {
history_back(new_bw, new_bw->history);
}
}
/**
* Navigate forward from a browser window into a new window.
*
* \param *g The browser window to act on.
*/
void ro_gui_window_action_navigate_forward_new(struct gui_window *g)
{
struct browser_window *new_bw;
nserror error;
if (g == NULL || g->bw == NULL)
return;
error = browser_window_create(BROWSER_WINDOW_VERIFIABLE,
NULL,
NULL,
g->bw,
&new_bw);
if (error != NSERROR_OK) {
warn_user(messages_get_errorcode(error), 0);
} else {
history_forward(new_bw, new_bw->history);
}
}
/**
* Open a new browser window.
*

View File

@ -853,7 +853,7 @@ nsws_window_command(HWND hwnd,
case IDM_NAV_BACK:
if ((gw->bw != NULL) &&
(history_back_available(gw->bw->history))) {
history_back(gw->bw, gw->bw->history);
history_back(gw->bw->history, false);
}
nsws_window_update_forward_back(gw);
break;
@ -861,7 +861,7 @@ nsws_window_command(HWND hwnd,
case IDM_NAV_FORWARD:
if ((gw->bw != NULL) &&
(history_forward_available(gw->bw->history))) {
history_forward(gw->bw, gw->bw->history);
history_forward(gw->bw->history, false);
}
nsws_window_update_forward_back(gw);
break;

View File

@ -167,8 +167,7 @@ nsws_localhistory_event_callback(HWND hwnd, UINT msg,
x = GET_X_LPARAM(lparam);
y = GET_Y_LPARAM(lparam);
if (history_click(gw->bw,
gw->bw->history,
if (history_click(gw->bw->history,
gw->localhistory->hscroll + x,
gw->localhistory->vscroll + y,
false)) {