RFR: 8326734: text-decoration applied to <span> lost when mixed with <u> or <s>

Alexey Ivanov aivanov at openjdk.org
Fri Mar 29 17:35:42 UTC 2024


The value of the [`text-decoration`](https://www.w3.org/TR/REC-CSS1/#text-decoration) CSS property is not inherited correctly in Swing. If the `<span>` element is mixed with `<u>` or `<s>`, only the value from the `style` attribute of `<span>` is applied.

The fix to this issue is not as simple as that for the previous one in PR #17659, [JDK-8323801](https://bugs.openjdk.org/browse/JDK-8323801). Even in the seemingly simple case where `<u>` is followed by `<span style='text-decoration: line-through'>`, the situation is more complex because the styles are stored in `MuxingAttributeSet` in different elements of the array.

To resolve this problem, `CSS.Attribute.TEXT_DECORATION` is treated as a special case. Indeed, it is a special case: the values set to a single `text-decoration` property should be combined across the entire tree of nested HTML elements and their styles.

So, `MuxingAttributeSet` looks for `text-decoration` in the entire array and combines all the values.

The same way, `StyleSheet` also goes up the inheritance chain by combining the current value of `text-decoration` with that from `getResolveParent`.

The `ConvertSpanAction` combines the value of `text-decoration` of adjacent `<span>` elements.

Finally, `ConvertAction` and `CharacterAction` are refactored. The `ConvertAction` class duplicated the code from `CharacterAction`. Now `ConvertAction` extends `CharacterAction` and overrides a method to provide additional handling.

Thus, [JDK-8325620](https://bugs.openjdk.org/browse/JDK-8325620) is also resolved by this PR, the action used for `<b>`, `<i>`, `<u>` is `CharacterAction` as specified.

-------------

Commit messages:
 - Remove trailing whitespace in text block
 - Add test cases where <span> followed by <u> or <s>
 - Add missing 'return null' for !TEXT_DECORATION
 - Remove trailing whitespace in text block
 - Rename ConvertSpan to ConvertSpanAction
 - Convert only if both new and previous decorations aren't 'none'
 - Refactor ConvertAction: extend CharacterAction to avoid code duplication
 - Simplify ConvertSpan
 - Optimize imports in StyleSheet
 - Update copyright year
 - ... and 7 more: https://git.openjdk.org/jdk/compare/89e0889a...e9cf30b3

Changes: https://git.openjdk.org/jdk/pull/18550/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18550&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8326734
  Stats: 330 lines in 5 files changed: 275 ins; 32 del; 23 mod
  Patch: https://git.openjdk.org/jdk/pull/18550.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18550/head:pull/18550

PR: https://git.openjdk.org/jdk/pull/18550


More information about the client-libs-dev mailing list