A bit more RAII for DilloHtml...

This commit is contained in:
2025-08-01 01:47:08 -04:00
parent b82eab34cf
commit eeb3db8bfd
6 changed files with 11 additions and 21 deletions

View File

@ -475,8 +475,6 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw, const DilloUrl *url,
styleEngine = std::make_unique< StyleEngine >(HT2LT (this), page_url, base_url, bw->zoom);
cssUrls = new misc::SimpleVector <DilloUrl*> (1);
stack = new misc::SimpleVector <DilloHtmlState> (16);
stack->increase();
stack->getRef(0)->parse_mode = DILLO_HTML_PARSE_MODE_INIT;
@ -554,10 +552,6 @@ DilloHtml::~DilloHtml()
delete page_url;
delete base_url;
for (int i = 0; i < cssUrls->size(); i++)
delete cssUrls->get(i);
delete (cssUrls);
for (std::size_t i = 0; i < forms.size(); i++)
a_Html_form_delete (forms.at(i));
forms.clear();
@ -729,9 +723,7 @@ void DilloHtml::loadImages (const DilloUrl *pattern)
*/
void DilloHtml::addCssUrl(const DilloUrl *url)
{
int nu = cssUrls->size();
cssUrls->increase();
cssUrls->set(nu, a_Url_dup(url).release());
cssUrls.push_back( a_Url_dup(url) );
}
bool DilloHtml::HtmlLinkReceiver::enter (Widget *widget, int link, int img,
@ -774,7 +766,7 @@ bool DilloHtml::HtmlLinkReceiver::press (Widget *widget, int link, int img,
ret = true;
} else {
if (link == -1) {
a_UIcmd_page_popup(bw, bw->num_page_bugs != 0, html->cssUrls);
a_UIcmd_page_popup(bw, bw->num_page_bugs != 0, &html->cssUrls);
ret = true;
} else {
a_UIcmd_link_popup(bw, html->links.at(link).get(), html->page_url);
@ -1666,8 +1658,8 @@ static void Html_tag_close_head(DilloHtml *html)
html->InFlags &= ~IN_HEAD;
/* charset is already set, load remote stylesheets now */
for (int i = 0; i < html->cssUrls->size(); i++) {
a_Html_load_stylesheet(html, html->cssUrls->get(i));
for (int i = 0; i < html->cssUrls.size(); i++) {
a_Html_load_stylesheet(html, html->cssUrls.at(i).get());
}
} else if (html->Num_HEAD > 1) {
--html->Num_HEAD;

View File

@ -185,7 +185,7 @@ public: //BUG: for now everything is public
float DocTypeVersion; /* HTML or XHTML version number */
/* vector of remote CSS resources, as given by the LINK element */
lout::misc::SimpleVector<DilloUrl*> *cssUrls;
std::vector< std::unique_ptr< DilloUrl > > cssUrls;
lout::misc::SimpleVector<DilloHtmlState> *stack;
std::unique_ptr< StyleEngine > styleEngine;

View File

@ -353,10 +353,8 @@ static void Menu_popup_cb(void *data)
* Page popup menu (construction & popup)
*/
void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url,
bool_t has_bugs, void *v_cssUrls)
bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls)
{
lout::misc::SimpleVector <DilloUrl*> *cssUrls =
(lout::misc::SimpleVector <DilloUrl*> *) v_cssUrls;
int j = 0;
static Fl_Menu_Item *stylesheets = NULL;
@ -402,7 +400,7 @@ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url,
memset(stylesheets, '\0', (cssUrls->size() + 1) * sizeof(Fl_Menu_Item));
for (j = 0; j < cssUrls->size(); j++) {
DilloUrl *url = cssUrls->get(j);
DilloUrl *url = cssUrls->at(j).get();
const char *url_str = URL_STR(url);
const uint_t head_length = 30, tail_length = 40,
url_len = strlen(url_str);

View File

@ -8,7 +8,7 @@ extern "C" {
#endif /* __cplusplus */
void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url,
bool_t has_bugs, void *v_cssUrls);
bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls);
void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url,
const DilloUrl *page_url);
void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url,

View File

@ -1253,11 +1253,11 @@ void a_UIcmd_add_bookmark(BrowserWindow *bw, const DilloUrl *url)
/*
* Popup the page menu
*/
void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, void *v_cssUrls)
void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls)
{
BrowserWindow *bw = (BrowserWindow*)vbw;
const DilloUrl *url = a_History_get_url(NAV_TOP_UIDX(bw));
a_Menu_page_popup(bw, url, has_bugs, v_cssUrls);
a_Menu_page_popup(bw, url, has_bugs, cssUrls);
}
/*

View File

@ -58,7 +58,7 @@ void a_UIcmd_findtext_reset(BrowserWindow *bw);
void a_UIcmd_findbar_toggle(BrowserWindow *bw, int on);
void a_UIcmd_focus_main_area(BrowserWindow *bw);
void a_UIcmd_focus_location(void *vbw);
void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, void *v_cssUrls);
void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls);
void a_UIcmd_link_popup(void *vbw, const DilloUrl *url, const DilloUrl *page_url);
void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img,
DilloUrl *page_url, DilloUrl *link_url);