Some further expansion of ownership for Widget.

This commit is contained in:
2025-04-18 13:29:29 -04:00
parent f63c1209a9
commit 317d1bfa56

View File

@ -50,8 +50,6 @@ void a_Web_init(void)
int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web,
CA_Callback_t *Call, void **Data)
{
Widget *dw = NULL;
_MSG("a_Web_dispatch_by_type\n");
BrowserWindow *bw = Web->bw;
@ -78,16 +76,14 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web,
StyleEngine styleEngine (layout, Web->url, Web->url, bw->zoom);
styleEngine.startElement ("body", Web->bw);
dw = (Widget*) viewer(Type, Web, Call, Data);
if (dw == NULL)
std::unique_ptr< Widget > dw( reinterpret_cast< Widget* >( viewer(Type, Web, Call, Data) ) );
if (not dw)
return -1;
dw->setStyle (styleEngine.style (Web->bw));
/* This method frees the old dw if any */
std::unique_ptr< Widget > dw_unique;
dw_unique.reset( dw );
layout->setWidget(std::move( dw_unique ));
layout->setWidget(std::move( dw ));
/* Set the page title with the bare filename (e.g. for images),
* HTML pages with a <TITLE> tag will overwrite it later */
@ -104,16 +100,19 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web,
/* Let the Nav module know... */
a_Nav_expect_done(Web->bw);
} else {
return 1;
}
/* A non-RootUrl. At this moment we only handle image-children */
if (!dStrnAsciiCasecmp(Type, "image/", 6)) {
dw = (Widget*) viewer(Type, Web, Call, Data);
} else {
auto dw = (Widget*) viewer(Type, Web, Call, Data);
return (dw ? 1 : -1);
}
MSG_HTTP("'%s' cannot be displayed as image; has media type '%s'\n",
URL_STR(Web->url), Type);
}
}
return (dw ? 1 : -1);
return -1;
}