Clean up gui_window creation API.

This commit is contained in:
Michael Drake 2014-02-09 13:07:39 +00:00
parent 987218e144
commit ea79e85fcd
13 changed files with 117 additions and 82 deletions

View File

@ -3225,8 +3225,8 @@ nserror ami_gui_new_blank_tab(struct gui_window_2 *gwin)
static struct gui_window * static struct gui_window *
gui_window_create(struct browser_window *bw, gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) gui_window_create_flags flags)
{ {
struct gui_window *g = NULL; struct gui_window *g = NULL;
bool closegadg=TRUE; bool closegadg=TRUE;
@ -3250,15 +3250,12 @@ gui_window_create(struct browser_window *bw,
if (nsoption_bool(resize_with_contents)) idcmp_sizeverify = 0; if (nsoption_bool(resize_with_contents)) idcmp_sizeverify = 0;
bw->scale = 1.0; bw->scale = 1.0;
if(clone) if(existing)
{ {
if(clone->window) curx=existing->shared->win->LeftEdge;
{ cury=existing->shared->win->TopEdge;
curx=clone->window->shared->win->LeftEdge; curw=existing->shared->win->Width;
cury=clone->window->shared->win->TopEdge; curh=existing->shared->win->Height;
curw=clone->window->shared->win->Width;
curh=clone->window->shared->win->Height;
}
} }
g = AllocVecTags(sizeof(struct gui_window), AVT_ClearWithValue, 0, TAG_DONE); g = AllocVecTags(sizeof(struct gui_window), AVT_ClearWithValue, 0, TAG_DONE);
@ -3272,9 +3269,9 @@ gui_window_create(struct browser_window *bw,
NewList(&g->dllist); NewList(&g->dllist);
g->deferred_rects = NewObjList(); g->deferred_rects = NewObjList();
if(new_tab && clone) if((flags & GW_CREATE_TAB) && existing)
{ {
g->shared = clone->window->shared; g->shared = existing->shared;
g->tab = g->shared->next_tab; g->tab = g->shared->next_tab;
if((g->shared->tabs == 1) && (nsoption_bool(tab_always_show) == false)) if((g->shared->tabs == 1) && (nsoption_bool(tab_always_show) == false))
@ -3299,10 +3296,10 @@ gui_window_create(struct browser_window *bw,
{ {
struct Node *insert_after = clone->window->tab_node; struct Node *insert_after = clone->window->tab_node;
if(clone->window->last_new_tab) if(existing->last_new_tab)
insert_after = clone->window->last_new_tab; insert_after = existing->last_new_tab;
Insert(&g->shared->tab_list, g->tab_node, insert_after); Insert(&g->shared->tab_list, g->tab_node, insert_after);
clone->window->last_new_tab = g->tab_node; existing->last_new_tab = g->tab_node;
} }
RefreshSetGadgetAttrs((struct Gadget *)g->shared->objects[GID_TABS], RefreshSetGadgetAttrs((struct Gadget *)g->shared->objects[GID_TABS],

View File

@ -211,11 +211,11 @@ static void gui_poll(bool active)
static struct gui_window * static struct gui_window *
gui_window_create(struct browser_window *bw, gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) { gui_window_create_flags flags) {
struct gui_window *gw=NULL; struct gui_window *gw=NULL;
LOG(( "gw: %p, BW: %p, clone %p, tab: %d\n" , gw, bw, clone, LOG(( "gw: %p, BW: %p, existing %p, flags: %d\n" , gw, bw, existing,
(int)new_tab (int)flags
)); ));
gw = calloc(1, sizeof(struct gui_window)); gw = calloc(1, sizeof(struct gui_window));
@ -223,7 +223,7 @@ gui_window_create(struct browser_window *bw,
return NULL; return NULL;
LOG(("new window: %p, bw: %p\n", gw, bw)); LOG(("new window: %p, bw: %p\n", gw, bw));
window_create(gw, bw, clone, WIDGET_STATUSBAR|WIDGET_TOOLBAR|WIDGET_RESIZE\ window_create(gw, bw, existing, WIDGET_STATUSBAR|WIDGET_TOOLBAR|WIDGET_RESIZE\
|WIDGET_SCROLL); |WIDGET_SCROLL);
if (gw->root->win) { if (gw->root->win) {
GRECT pos = { GRECT pos = {

View File

@ -230,7 +230,7 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
int window_create(struct gui_window * gw, int window_create(struct gui_window * gw,
struct browser_window * bw, struct browser_window * bw,
struct browser_window * clone, struct gui_window * existing,
unsigned long inflags) unsigned long inflags)
{ {
int err = 0; int err = 0;
@ -294,8 +294,8 @@ int window_create(struct gui_window * gw,
assert(gw->browser); assert(gw->browser);
gw->browser->bw = bw; gw->browser->bw = bw;
if(clone) if(existing)
gw->browser->bw->scale = clone->scale; gw->browser->bw->scale = existing->browser->bw->scale;
else else
gw->browser->bw->scale = 1; gw->browser->bw->scale = 1;

View File

@ -337,8 +337,8 @@ float nsbeos_get_scale_for_gui(struct gui_window *g)
/* Create a gui_window */ /* Create a gui_window */
static struct gui_window *gui_window_create(struct browser_window *bw, static struct gui_window *gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) gui_window_create_flags flags)
{ {
struct gui_window *g; /**< what we're creating to return */ struct gui_window *g; /**< what we're creating to return */
@ -353,8 +353,8 @@ static struct gui_window *gui_window_create(struct browser_window *bw,
g->bw = bw; g->bw = bw;
g->mouse.state = 0; g->mouse.state = 0;
g->current_pointer = GUI_POINTER_DEFAULT; g->current_pointer = GUI_POINTER_DEFAULT;
if (clone != NULL) if (existing != NULL)
bw->scale = clone->scale; bw->scale = existing->bw->scale;
else else
bw->scale = (float) nsoption_int(scale) / 100; bw->scale = (float) nsoption_int(scale) / 100;

View File

@ -64,21 +64,21 @@ static void gui_poll(bool active)
struct browser_window; struct browser_window;
static struct gui_window *gui_window_create(struct browser_window *bw, static struct gui_window *gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) gui_window_create_flags flags)
{ {
BrowserWindowController *window = nil; BrowserWindowController *window = nil;
if (clone != NULL) { if (existing != NULL) {
bw->scale = clone->scale; bw->scale = clone->scale;
window = [(BrowserViewController *)(clone->window) windowController]; window = [(BrowserViewController *)(existing) windowController];
} else { } else {
bw->scale = (float) nsoption_int(scale) / 100; bw->scale = (float) nsoption_int(scale) / 100;
} }
BrowserViewController *result = [[BrowserViewController alloc] initWithBrowser: bw]; BrowserViewController *result = [[BrowserViewController alloc] initWithBrowser: bw];
if (!new_tab || nil == window) { if (!(flags & GW_CREATE_TAB) || nil == window) {
window = [[[BrowserWindowController alloc] init] autorelease]; window = [[[BrowserWindowController alloc] init] autorelease];
[[window window] makeKeyAndOrderFront: nil]; [[window window] makeKeyAndOrderFront: nil];
} }

View File

@ -699,7 +699,6 @@ browser_window_create(enum browser_window_nav_flags flags,
struct browser_window **ret_bw) struct browser_window **ret_bw)
{ {
struct browser_window *bw; struct browser_window *bw;
struct browser_window *top;
/* caller must provide window to clone or be adding to history */ /* caller must provide window to clone or be adding to history */
assert(clone || assert(clone ||
@ -730,9 +729,14 @@ browser_window_create(enum browser_window_nav_flags flags,
/* gui window */ /* gui window */
/* from the front end's pov, it clones the top level browser window, /* from the front end's pov, it clones the top level browser window,
* so find that. */ * so find that. */
top = browser_window_get_root(clone); clone = browser_window_get_root(clone);
bw->window = guit->window->create(bw, top, ((flags & BROWSER_WINDOW_TAB) != 0)); bw->window = guit->window->create(bw,
(clone != NULL) ? clone->window : NULL,
((flags & BROWSER_WINDOW_TAB) ?
GW_CREATE_TAB : GW_CREATE_NONE) |
((clone != NULL) ?
GW_CREATE_CLONE : GW_CREATE_NONE));
if (bw->window == NULL) { if (bw->window == NULL) {
browser_window_destroy(bw); browser_window_destroy(bw);
@ -1944,6 +1948,15 @@ nsurl * browser_window_get_url(struct browser_window *bw)
} }
/* Exported interface, documented in browser.h */
struct history * browser_window_get_history(struct browser_window *bw)
{
assert(bw != NULL);
return bw->history;
}
/* Exported interface, documented in browser.h */ /* Exported interface, documented in browser.h */
bool browser_window_has_content(struct browser_window *bw) bool browser_window_has_content(struct browser_window *bw)
{ {

View File

@ -129,6 +129,16 @@ nserror browser_window_navigate(struct browser_window *bw,
*/ */
nsurl * browser_window_get_url(struct browser_window *bw); nsurl * browser_window_get_url(struct browser_window *bw);
/**
* Get a browser window's history object.
*
* \param bw browser window
* \return pointer browser window's history object
*
* Clients need history object to make use of the history_* functions.
*/
struct history * browser_window_get_history(struct browser_window *bw);
/** /**
* Get a browser window's content extents. * Get a browser window's content extents.
* *

View File

@ -54,6 +54,12 @@ typedef enum {
GDRAGGING_OTHER GDRAGGING_OTHER
} gui_drag_type; } gui_drag_type;
typedef enum {
GW_CREATE_NONE = 0, /* New window */
GW_CREATE_CLONE = (1 << 0), /* Clone existing window */
GW_CREATE_TAB = (1 << 1) /* In same window as existing */
} gui_window_create_flags;
struct gui_window; struct gui_window;
struct gui_download_window; struct gui_download_window;
struct browser_window; struct browser_window;
@ -77,8 +83,23 @@ struct gui_window_table {
/* Mandantory entries */ /* Mandantory entries */
/** create a gui window for a browsing context */ /**
struct gui_window *(*create)(struct browser_window *bw, struct browser_window *clone, bool new_tab); * Create and open a gui window for a browsing context.
*
* \param bw bw to create gui_window for
* \param existing an existing gui_window, may be NULL
* \param flags flags for gui window creation
* \return gui window, or NULL on error
*
* If GW_CREATE_CLONE or GW_CREATE_TAB flags are set, existing is
* non-NULL.
*
* Front end's gui_window must include a reference to the
* browser window passed in the bw param.
*/
struct gui_window *(*create)(struct browser_window *bw,
struct gui_window *existing,
gui_window_create_flags flags);
/** destroy previously created gui window */ /** destroy previously created gui window */
void (*destroy)(struct gui_window *g); void (*destroy)(struct gui_window *g);

View File

@ -1507,8 +1507,8 @@ create_normal_browser_window(struct gui_window *gw, int furniture_width)
static struct gui_window * static struct gui_window *
gui_window_create(struct browser_window *bw, gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) gui_window_create_flags flags)
{ {
struct gui_window *gw; struct gui_window *gw;
@ -1517,8 +1517,7 @@ gui_window_create(struct browser_window *bw,
if (gw == NULL) if (gw == NULL)
return NULL; return NULL;
/* seems we need to associate the gui window with the underlying /* associate the gui window with the underlying browser window
* browser window
*/ */
gw->bw = bw; gw->bw = bw;

View File

@ -663,8 +663,8 @@ static void window_destroy(GtkWidget *widget, gpointer data)
/* Core interface documented in desktop/gui.h to create a gui_window */ /* Core interface documented in desktop/gui.h to create a gui_window */
static struct gui_window * static struct gui_window *
gui_window_create(struct browser_window *bw, gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) gui_window_create_flags flags)
{ {
struct gui_window *g; /**< what we're creating to return */ struct gui_window *g; /**< what we're creating to return */
GError* error = NULL; GError* error = NULL;
@ -693,16 +693,17 @@ gui_window_create(struct browser_window *bw,
g->bw = bw; g->bw = bw;
g->mouse.state = 0; g->mouse.state = 0;
g->current_pointer = GUI_POINTER_DEFAULT; g->current_pointer = GUI_POINTER_DEFAULT;
if (clone != NULL) { if (flags & GW_CREATE_CLONE) {
bw->scale = clone->scale; assert(existing != NULL);
bw->scale = existing->bw->scale;
} else { } else {
bw->scale = nsoption_int(scale) / 100; bw->scale = nsoption_int(scale) / 100;
} }
/* attach scaffold */ /* attach scaffold */
if (new_tab) { if (flags & GW_CREATE_TAB) {
assert(clone != NULL); assert(existing != NULL);
g->scaffold = clone->window->scaffold; g->scaffold = existing->scaffold;
} else { } else {
/* Now construct and attach a scaffold */ /* Now construct and attach a scaffold */
g->scaffold = nsgtk_new_scaffolding(g); g->scaffold = nsgtk_new_scaffolding(g);

View File

@ -89,8 +89,8 @@ monkey_kill_browser_windows(void)
static struct gui_window * static struct gui_window *
gui_window_create(struct browser_window *bw, gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) gui_window_create_flags flags)
{ {
struct gui_window *ret = calloc(sizeof(*ret), 1); struct gui_window *ret = calloc(sizeof(*ret), 1);
if (ret == NULL) if (ret == NULL)
@ -102,8 +102,9 @@ gui_window_create(struct browser_window *bw,
ret->width = 800; ret->width = 800;
ret->height = 600; ret->height = 600;
fprintf(stdout, "WINDOW NEW WIN %u FOR %p CLONE %p NEWTAB %s\n", fprintf(stdout, "WINDOW NEW WIN %u FOR %p EXISTING %p NEWTAB %s CLONE %s\n",
ret->win_num, bw, clone, new_tab ? "TRUE" : "FALSE"); ret->win_num, bw, existing, flags & GW_CREATE_TAB ? "TRUE" : "FALSE",
flags & GW_CREATE_CLONE ? "TRUE" : "FALSE");
fprintf(stdout, "WINDOW SIZE WIN %u WIDTH %d HEIGHT %d\n", fprintf(stdout, "WINDOW SIZE WIN %u WIDTH %d HEIGHT %d\n",
ret->win_num, ret->width, ret->height); ret->win_num, ret->width, ret->height);

View File

@ -152,8 +152,9 @@ static void ro_gui_window_update_theme(void *data, bool ok);
static bool ro_gui_window_import_text(struct gui_window *g, static bool ro_gui_window_import_text(struct gui_window *g,
const char *filename); const char *filename);
static void ro_gui_window_clone_options(struct browser_window *new_bw, static void ro_gui_window_clone_options(
struct browser_window *old_bw); struct gui_window *new_gui,
struct gui_window *old_gui);
static bool ro_gui_window_prepare_form_select_menu(struct browser_window *bw, static bool ro_gui_window_prepare_form_select_menu(struct browser_window *bw,
struct form_control *control); struct form_control *control);
@ -400,14 +401,15 @@ static void gui_window_place_caret(struct gui_window *g, int x, int y, int heigh
/** /**
* Create and open a new browser window. * Create and open a new browser window.
* *
* \param bw The browser window structure to update * \param bw bw to create gui_window for
* \param clone The browser window to clone options from, or NULL for default * \param existing an existing gui_window, may be NULL
* \param new_tab Determines if new browser context should be a tab or window. * \param flags flags for gui window creation
* \return A gui window, or NULL on error and error reported * \return gui window, or NULL on error
*/ */
static struct gui_window *gui_window_create(struct browser_window *bw, static struct gui_window *gui_window_create(struct browser_window *bw,
struct browser_window *clone, bool new_tab) struct gui_window *existing,
gui_window_create_flags flags)
{ {
int screen_width, screen_height, win_width, win_height, scroll_width; int screen_width, screen_height, win_width, win_height, scroll_width;
static int window_count = 2; static int window_count = 2;
@ -416,7 +418,6 @@ static struct gui_window *gui_window_create(struct browser_window *bw,
os_error *error; os_error *error;
bool open_centred = true; bool open_centred = true;
struct gui_window *g; struct gui_window *g;
struct browser_window *top;
g = malloc(sizeof *g); g = malloc(sizeof *g);
if (!g) { if (!g) {
@ -433,9 +434,10 @@ static struct gui_window *gui_window_create(struct browser_window *bw,
g->iconise_icon = -1; g->iconise_icon = -1;
/* Set the window position */ /* Set the window position */
if (clone && clone->window && nsoption_bool(window_size_clone)) { if (existing != NULL &&
for (top = clone; top->parent; top = top->parent); flags & GW_CREATE_CLONE &&
state.w = top->window->window; nsoption_bool(window_size_clone)) {
state.w = existing->window;
error = xwimp_get_window_state(&state); error = xwimp_get_window_state(&state);
if (error) { if (error) {
LOG(("xwimp_get_window_state: 0x%x: %s", LOG(("xwimp_get_window_state: 0x%x: %s",
@ -594,7 +596,8 @@ static struct gui_window *gui_window_create(struct browser_window *bw,
/* Set the window options */ /* Set the window options */
bw->window = g; bw->window = g;
ro_gui_window_clone_options(bw, clone); bw->scale = ((float)nsoption_int(scale)) / 100;
ro_gui_window_clone_options(g, existing);
ro_gui_window_update_toolbar_buttons(g); ro_gui_window_update_toolbar_buttons(g);
/* Open the window at the top of the stack */ /* Open the window at the top of the stack */
@ -4634,29 +4637,19 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename)
/** /**
* Clones a browser window's options. * Clones a browser window's options.
* *
* \param new_bw the new browser window * \param new_gui the new gui window
* \param old_bw the browser window to clone from, or NULL for default * \param old_gui the gui window to clone from, or NULL for default
*/ */
void ro_gui_window_clone_options(struct browser_window *new_bw, void ro_gui_window_clone_options(
struct browser_window *old_bw) struct gui_window *new_gui,
struct gui_window *old_gui)
{ {
struct gui_window *old_gui = NULL; assert(new_gui);
struct gui_window *new_gui;
assert(new_bw);
/* Get our GUIs
*/
new_gui = new_bw->window;
if (old_bw)
old_gui = old_bw->window;
/* Clone the basic options /* Clone the basic options
*/ */
if (!old_gui) { if (!old_gui) {
new_bw->scale = ((float)nsoption_int(scale)) / 100;
new_gui->option.buffer_animations = nsoption_bool(buffer_animations); new_gui->option.buffer_animations = nsoption_bool(buffer_animations);
new_gui->option.buffer_everything = nsoption_bool(buffer_everything); new_gui->option.buffer_everything = nsoption_bool(buffer_everything);
} else { } else {

View File

@ -1232,8 +1232,8 @@ static HWND nsws_window_create(struct gui_window *gw)
*/ */
static struct gui_window * static struct gui_window *
gui_window_create(struct browser_window *bw, gui_window_create(struct browser_window *bw,
struct browser_window *clone, struct gui_window *existing,
bool new_tab) gui_window_create_flags flags)
{ {
struct gui_window *gw; struct gui_window *gw;