summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-02-27 23:51:49 +0100
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-03-02 20:47:59 +0100
commitf5a0b6030c2001e5a0fcacf8139afa800643eb47 (patch)
treed3246c688104af7a6cedbe7cbeb98e0b76c57d51
parenteed15beb109cf83af1d1c66cc77c85430b405f78 (diff)
Ignore percent width td attributes in tables
The width attribute in tr and td tags is deprecated in HTML 4.01 and obsolete in HTML 5. However, we should still support it when loading the page in the transitional mode. Currently, the relative values of the width attribute are transformed into CSS values. They cause the available text width to be computed by applying the relative value to the cell width, which causes an unintended effect. The workaround for now is to simply ignore the value when it is specified as a percent.
-rw-r--r--ChangeLog1
-rw-r--r--src/table.cc19
-rw-r--r--test/html/Makefile.am1
3 files changed, 15 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index b1b00247..906e1630 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -58,6 +58,7 @@ dillo-3.1 [not released yet]
scroll_switches_tabs to disable the behavior.
- Fix OpenSSL handling of unexpected EOF without close notify alert.
- Expand home tilde '~' in the file plugin.
+ - Ignore width attribute with relative values for td and th elements.
Patches: Rodrigo Arias Mallo <rodarima@gmail.com>
-----------------------------------------------------------------------------
diff --git a/src/table.cc b/src/table.cc
index 859b1063..1268fbd9 100644
--- a/src/table.cc
+++ b/src/table.cc
@@ -2,6 +2,7 @@
* File: table.cc
*
* Copyright 2008 Jorge Arellano Cid <jcid@dillo.org>
+ * Copyright 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -414,9 +415,17 @@ static void Html_tag_open_table_cell(DilloHtml *html,
a_Html_tag_set_align_attr (html, tag, tagsize);
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "width"))) {
- html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH,
- CSS_TYPE_LENGTH_PERCENTAGE,
- a_Html_parse_length (html, attrbuf));
+ CssLength l = a_Html_parse_length (html, attrbuf);
+ /* Only apply the width if the width is given in pixels,
+ * otherwise the percent value is applied to the size of the
+ * cell instead of to the table available width */
+ if (CSS_LENGTH_TYPE(l) == CSS_LENGTH_TYPE_PX) {
+ html->styleEngine->setNonCssHint (CSS_PROPERTY_WIDTH,
+ CSS_TYPE_LENGTH, l);
+ } else {
+ /* TODO: Support relative sizes for HTML 4.01 pages in
+ * transitional mode */
+ }
if (html->DocType == DT_HTML && html->DocTypeVersion >= 5.0f)
BUG_MSG("<t%c> width attribute is obsolete.",
(tagsize >=3 && (D_ASCII_TOLOWER(tag[2]) == 'd')) ? 'd' : 'h');
@@ -433,7 +442,7 @@ static void Html_tag_open_table_cell(DilloHtml *html,
BUG_MSG("<t%c> bgcolor attribute is obsolete.",
(tagsize >=3 && (D_ASCII_TOLOWER(tag[2]) == 'd')) ? 'd' : 'h');
}
-
+ break;
default:
/* compiler happiness */
break;
@@ -457,7 +466,7 @@ static void Html_tag_content_table_cell(DilloHtml *html,
BUG_MSG("<t%c> outside <tr>.",
(tagsize >=3 && (D_ASCII_TOLOWER(tag[2]) == 'd')) ? 'd' : 'h');
/* a_Dw_table_add_cell takes care that dillo does not crash. */
- /* continues */
+ /* fallthrough */
case DILLO_HTML_TABLE_MODE_TR:
case DILLO_HTML_TABLE_MODE_TD:
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "colspan"))) {
diff --git a/test/html/Makefile.am b/test/html/Makefile.am
index a6d9d4cf..28548f83 100644
--- a/test/html/Makefile.am
+++ b/test/html/Makefile.am
@@ -32,5 +32,4 @@ XFAIL_TESTS = \
render/max-width-html.html \
render/min-width-html.html \
render/span-padding.html \
- render/table-td-width-percent-img.html \
render/table-td-width-percent.html