Merge branch 'fix-ui-crash-bug' into master

* fix-ui-crash-bug:
  Ownership of page Widget plumbed to top.
  Plumb Widget ownership up higher.
  Push Widget ownership up one more level.
  Do the whitespace format.
  Some further expansion of ownership for `Widget`.
  Widen the unique pointer a bit more.
  I plumbed out ownership a bit and it hasn't crashed yet.
  Started plumbing out the ownership from layout.
  Revert "This adds some resource-ownership tracking."
This commit is contained in:
2025-04-18 14:23:39 -04:00
7 changed files with 33 additions and 37 deletions

View File

@ -390,8 +390,7 @@ FltkPlatform::FltkResourceFactory::createLabelButtonResource (const char
}
core::ui::ComplexButtonResource *
FltkPlatform::FltkResourceFactory::createComplexButtonResource (std::unique_ptr< core::Widget
> widget,
FltkPlatform::FltkResourceFactory::createComplexButtonResource (std::unique_ptr< core::Widget > widget,
bool relief)
{
return new ui::FltkComplexButtonResource (platform, std::move( widget ), relief);

View File

@ -726,8 +726,8 @@ void FltkLabelButtonResource::setLabel (const char *label)
// ----------------------------------------------------------------------
FltkComplexButtonResource::FltkComplexButtonResource (FltkPlatform *platform,
std::unique_ptr< dw::core::Widget
> widget, bool relief):
std::unique_ptr< dw::core::Widget > widget,
bool relief):
FltkSpecificResource <dw::core::ui::ComplexButtonResource> (platform)
{
flatView = topView = NULL;

View File

@ -5,8 +5,6 @@
# error Do not include this file directly, use "fltkcore.hh" instead.
#endif
#include <memory>
#include <FL/Fl_Button.H>
#include <FL/Fl_Menu.H>
#include <FL/Fl_Text_Buffer.H>

View File

@ -377,15 +377,16 @@ void Layout::addWidget (std::unique_ptr< Widget > widget)
widget->stackingContextWidget = widget.get();
}
Widget *widget_p= widget.get();
topLevel = std::move( widget );
topLevel->layout = this;
topLevel->container = NULL;
DBG_OBJ_SET_PTR_O (topLevel.get(), "container", topLevel->container);
widget_p->layout = this;
widget_p->container = NULL;
DBG_OBJ_SET_PTR_O (widget_p, "container", widget_p->container);
queueResizeList->clear ();
topLevel->notifySetAsTopLevel ();
widget_p->notifySetAsTopLevel ();
findtextState.setWidget (topLevel.get());
findtextState.setWidget (widget_p);
canvasHeightGreater = false;
DBG_OBJ_SET_SYM ("canvasHeightGreater",
@ -424,16 +425,16 @@ void Layout::removeWidget ()
updateCursor ();
}
void Layout::setWidget (std::unique_ptr< Widget >widget)
void Layout::setWidget (std::unique_ptr< Widget > widget)
{
DBG_OBJ_ASSOC_CHILD (widget);
DBG_OBJ_ASSOC_CHILD (widget.get());
widgetAtPoint = NULL;
if (topLevel) {
topLevel.reset();
}
textZone->zoneFree ();
addWidget (std::move(widget));
addWidget (std::move( widget ));
updateCursor ();

View File

@ -5,8 +5,6 @@
# error Do not include this file directly, use "core.hh" instead.
#endif
#include <memory>
namespace dw {
namespace core {

View File

@ -945,8 +945,6 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize)
if (inp_type != DILLO_HTML_INPUT_UNKNOWN) {
/* Render the button */
std::unique_ptr< Widget > page;
Widget *page_p;
Embed *embed;
const char *attrbuf;
char *name, *value;
@ -960,9 +958,9 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize)
/* We used to have Textblock (prefs.limit_text_width, ...) here,
* but it caused 100% CPU usage.
*/
page = std::make_unique< Textblock > (false, true);
std::unique_ptr< Widget > page = std::make_unique< Textblock >( false, true );
Widget *page_p= page.get();
page->setStyle (html->backgroundStyle ());
page_p= page.get();
ResourceFactory *factory = HT2LT(html)->getResourceFactory();
Resource *resource = factory->createComplexButtonResource(std::move( page ), true);
@ -2044,12 +2042,13 @@ static Embed *Html_input_image(DilloHtml *html, const char *tag, int tagsize)
// At this point, we know that Image->ir represents an image
// widget. Notice that the order of the casts matters, because
// of multiple inheritance.
std::unique_ptr< dw::Image > dwi;
dwi.reset( reinterpret_cast< dw::Image *>( (dw::core::ImgRenderer*)Image->img_rndr ) );
dw::Image *dwi = (dw::Image*)(dw::core::ImgRenderer*)Image->img_rndr;
std::unique_ptr< dw::core::Widget > dwi_unique;
dwi_unique.reset( dwi );
dwi->setStyle (html->backgroundStyle ());
ResourceFactory *factory = HT2LT(html)->getResourceFactory();
ComplexButtonResource *complex_b_r =
factory->createComplexButtonResource(std::move( dwi ), false);
factory->createComplexButtonResource(std::move( dwi_unique ), false);
button = new Embed(complex_b_r);
HT2TB(html)->addWidget (button, html->style ());
}

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,14 +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 */
layout->setWidget(std::unique_ptr< Widget >{ dw });
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 */
@ -102,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 {
/* A non-RootUrl. At this moment we only handle image-children */
if (!dStrnAsciiCasecmp(Type, "image/", 6)) {
dw = (Widget*) viewer(Type, Web, Call, Data);
} else {
MSG_HTTP("'%s' cannot be displayed as image; has media type '%s'\n",
URL_STR(Web->url), Type);
}
return 1;
}
return (dw ? 1 : -1);
/* A non-RootUrl. At this moment we only handle image-children */
if (!dStrnAsciiCasecmp(Type, "image/", 6)) {
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 -1;
}