From e3cedc586990f246ad8679a8a91bbfe88a8ac902 Mon Sep 17 00:00:00 2001 From: Cameron Paul Date: Tue, 17 Jun 2025 13:29:34 -0500 Subject: [PATCH 1/2] Expand text-align-center test with more test cases --- test/html/render/text-align-center.html | 62 +++++++++++++++++++-- test/html/render/text-align-center.ref.html | 58 +++++++++++++++++-- 2 files changed, 112 insertions(+), 8 deletions(-) diff --git a/test/html/render/text-align-center.html b/test/html/render/text-align-center.html index 2924df51..99440dbf 100644 --- a/test/html/render/text-align-center.html +++ b/test/html/render/text-align-center.html @@ -3,19 +3,73 @@ Test text-align: center -
-
center
+
simple centered text
+ +
+
nested div with inner center
+
+ +
+
nested div with outer center
+
+ +
+ nested span with inner center +
+ +
+ nested span with outer center
diff --git a/test/html/render/text-align-center.ref.html b/test/html/render/text-align-center.ref.html index f0048d42..b13e004e 100644 --- a/test/html/render/text-align-center.ref.html +++ b/test/html/render/text-align-center.ref.html @@ -8,20 +8,70 @@ margin: 0; padding: 0; } - .outer { + table { + margin-bottom: 10px; + } + + .center { + background-color: aquamarine; + width: 400px; + } + .center td { + text-align: center; + } + + .outer1 { + background-color:coral; + width: 400px; + } + .inner1 { + background-color:aquamarine; + text-align: center; + width: 100px; + } + + .outer3 { background-color:coral; width: 400px; } - .inner { + .inner3 { background-color:aquamarine; text-align: center; width: 100px; + white-space: nowrap; + } + + .outer4 { + background-color:coral; + width: 400px; + } + .inner4 { + background-color:aquamarine; + text-align: center; + width: 100px; + white-space: nowrap; } - - +
center
+ +
simple centered text
+ + + +
nested div with inner center
+ + + +
nested div with outer center
+ + + +
nested span with inner center
+ + +
nested span with outer center
From 50121125a0a79658c456ba88816a63e5b836a6ab Mon Sep 17 00:00:00 2001 From: Cameron Paul Date: Tue, 17 Jun 2025 13:36:32 -0500 Subject: [PATCH 2/2] Fix text-align Inline elements are now aligned based on the text-align value of their containing element instead of their own text-align value. Block level elements are no longer affected by the text-align property. Fixes: https://github.com/dillo-browser/dillo/issues/410 --- dw/textblock_linebreaking.cc | 18 +++++++++++++++++- test/html/Makefile.am | 3 +-- test/html/render/text-align-center.html | 8 ++++---- test/html/render/text-align-center.ref.html | 8 ++++---- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 1a95cb70..06486c12 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -1804,7 +1804,23 @@ void Textblock::alignLine (int lineIndex) int lineBreakWidth = this->lineBreakWidth - (line->leftOffset + line->rightOffset); - switch (firstWord->style->textAlign) { + core::style::TextAlignType alignStyle = core::style::TEXT_ALIGN_LEFT; + + /** + * Only inline elements should be affected by the text-align property. + * While alignStyle will still apply to other elements, the default + * value of TEXT_ALIGN_LEFT will have no effect on the alignment. + */ + if (firstWord->style->display == core::style::DISPLAY_INLINE || + firstWord->style->display == core::style::DISPLAY_INLINE_BLOCK) { + /** + * Elements that *are* affected by text-align are aligned based on + * the text-align value of their containing element. + */ + alignStyle = getStyle()->textAlign; + } + + switch (alignStyle) { case core::style::TEXT_ALIGN_LEFT: DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: left'"); diff --git a/test/html/Makefile.am b/test/html/Makefile.am index e9f9ef4c..29fb39f3 100644 --- a/test/html/Makefile.am +++ b/test/html/Makefile.am @@ -59,5 +59,4 @@ XFAIL_TESTS = \ render/min-width-html.html \ render/multiple-floats.html \ render/span-padding.html \ - render/table-td-width-percent.html \ - render/text-align-center.html + render/table-td-width-percent.html diff --git a/test/html/render/text-align-center.html b/test/html/render/text-align-center.html index 99440dbf..0254a730 100644 --- a/test/html/render/text-align-center.html +++ b/test/html/render/text-align-center.html @@ -58,18 +58,18 @@
simple centered text
-
nested div with inner center
+
nested div with internal center
-
nested div with outer center
+
nested div with external center
- nested span with inner center + nested span with internal center
- nested span with outer center + nested span with external center
diff --git a/test/html/render/text-align-center.ref.html b/test/html/render/text-align-center.ref.html index b13e004e..863b967f 100644 --- a/test/html/render/text-align-center.ref.html +++ b/test/html/render/text-align-center.ref.html @@ -59,19 +59,19 @@ - +
nested div with inner center
nested div with internal center
- +
nested div with outer center
nested div with external center
- +
nested span with inner center
nested span with internal center
- +
nested span with outer center
nested span with external center