diff options
author | Rodrigo Arias Mallo <rodarima@gmail.com> | 2025-08-24 16:16:40 +0200 |
---|---|---|
committer | Rodrigo Arias Mallo <rodarima@gmail.com> | 2025-08-30 16:08:34 +0200 |
commit | cfa3923a5ffed809b4d4a54f6100f85b9f7a296d (patch) | |
tree | 2f63fe05cae017eeb2a0739237f27c371256a06a | |
parent | 22b4be77888ada3536b57f1da3e265000bc2df82 (diff) |
Don't show form inputs with display:none
When the current element or a parent has display:none, the display_none
flag is set and no new element should be added to the viewport. For form
inputs, instead of always adding the Embed to the viewport, we only do
it if display_none is not set. The Embed is still registered as an input
in the form, so it will continue to send the proper form values to the
server.
For complex buttons that can contain nested elements inside, we switch
to a dummy button that doesn't have a Textbox and rely on the logic at
html.cc to avoid creating more child elements until the display_none is
unset.
Fixes: https://github.com/dillo-browser/dillo/issues/433
-rw-r--r-- | src/form.cc | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/src/form.cc b/src/form.cc index bbf2d30b..d13bff24 100644 --- a/src/form.cc +++ b/src/form.cc @@ -572,7 +572,10 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->setNonCssHint (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, attrbuf); } - HT2TB(html)->addWidget (embed, html->backgroundStyle()); + + /* Don't add to textbox if we are under a display:none element */ + if (!S_TOP(html)->display_none) + HT2TB(html)->addWidget (embed, html->backgroundStyle()); } dFree(type); dFree(name); @@ -684,7 +687,9 @@ void Html_tag_content_textarea(DilloHtml *html, const char *tag, int tagsize) textres->setEditable(false); Html_add_input(html, DILLO_HTML_INPUT_TEXTAREA, embed, name, NULL, false); - HT2TB(html)->addWidget (embed, html->backgroundStyle ()); + if (!S_TOP(html)->display_none) + HT2TB(html)->addWidget (embed, html->backgroundStyle ()); + dFree(name); } @@ -775,7 +780,9 @@ void Html_tag_open_select(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->setNonCssHint (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, attrbuf); } - HT2TB(html)->addWidget (embed, html->backgroundStyle ()); + + if (!S_TOP(html)->display_none) + HT2TB(html)->addWidget (embed, html->backgroundStyle ()); Html_add_input(html, type, embed, name, NULL, false); a_Html_stash_init(html); @@ -932,10 +939,8 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize) if (inp_type != DILLO_HTML_INPUT_UNKNOWN) { /* Render the button */ - Widget *page; Embed *embed; const char *attrbuf; - char *name, *value; if (prefs.show_tooltip && (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { @@ -943,24 +948,30 @@ void Html_tag_open_button(DilloHtml *html, const char *tag, int tagsize) html->styleEngine->setNonCssHint (PROPERTY_X_TOOLTIP, CSS_TYPE_STRING, attrbuf); } - /* We used to have Textblock (prefs.limit_text_width, ...) here, - * but it caused 100% CPU usage. - */ - page = new Textblock (false, true); - page->setStyle (html->backgroundStyle ()); ResourceFactory *factory = HT2LT(html)->getResourceFactory(); - Resource *resource = factory->createComplexButtonResource(page, true); - embed = new Embed(resource); -// a_Dw_button_set_sensitive (DW_BUTTON (button), FALSE); - - HT2TB(html)->addWidget (embed, html->backgroundStyle ()); - - S_TOP(html)->textblock = html->dw = page; - value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL); - name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL); + /* If we are inside a display:none container, instead of creating + * a new hierarchy of elements, add a simple button. */ + if (S_TOP(html)->display_none) { + Resource *resource = factory->createLabelButtonResource("dummy"); + embed = new Embed(resource); + } else { + /* We used to have Textblock (prefs.limit_text_width, ...) here, + * but it caused 100% CPU usage. + */ + Widget *page = new Textblock (false, true); + page->setStyle (html->backgroundStyle ()); + + ComplexButtonResource *resource = factory->createComplexButtonResource(page, true); + embed = new Embed(resource); + HT2TB(html)->addWidget (embed, html->backgroundStyle ()); + S_TOP(html)->textblock = html->dw = page; + } + /* Always add the input element, so is present in the form */ + char *value = a_Html_get_attr_wdef(html, tag, tagsize, "value", NULL); + char *name = a_Html_get_attr_wdef(html, tag, tagsize, "name", NULL); Html_add_input(html, inp_type, embed, name, value, FALSE); dFree(name); dFree(value); |