Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Parsing of <body link vlink alink> is not per spec
https://bugs.webkit.org/show_bug.cgi?id=156849

Reviewed by Darin Adler.

Use the rules for parsing a legacy color value to parse link, vlink, and alink content attributes
on body element: https://html.spec.whatwg.org/#rules-for-parsing-a-legacy-colour-value

Based on https://crrev.com/ac6c480c0c078999a785de7ef1e10c6c0c928c75

* LayoutTests/fast/html/body-color-legacy-parsing-1-expected.html: Added.
* LayoutTests/fast/html/body-color-legacy-parsing-1.html: Added.
* LayoutTests/fast/html/body-color-legacy-parsing-2-expected.html: Added.
* LayoutTests/fast/html/body-color-legacy-parsing-2.html: Added.
* LayoutTests/fast/html/body-color-legacy-parsing-3-expected.html: Added.
* LayoutTests/fast/html/body-color-legacy-parsing-3.html: Added.
* LayoutTests/platform/ios/TestExpectations:

* Source/WebCore/html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::parseAttribute): Fixed the bug.
* Source/WebCore/html/HTMLElement.cpp:
(WebCore::HTMLElement::parseLegacyColorValue): Made this a protected member function.
(WebCore::HTMLElement::addHTMLColorToStyle):
* Source/WebCore/html/HTMLElement.h:

Canonical link: https://commits.webkit.org/252992@main
  • Loading branch information
rniwa committed Aug 1, 2022
1 parent e540252 commit c521422
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 17 deletions.
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body bgcolor="00ff00" link="#008000">
<a href="#unVisitedLink">hello</a>
</body>
</html>
6 changes: 6 additions & 0 deletions LayoutTests/fast/html/body-color-legacy-parsing-1.html
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body bgcolor="00ff0x" link="00800x">
<a href="#unVisitedLink">hello</a>
</body>
</html>
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body link="#008000">
<a href="#">hello</a>
</body>
</html>
16 changes: 16 additions & 0 deletions LayoutTests/fast/html/body-color-legacy-parsing-2.html
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<body alink="0080x">
<a href="#foo">hello</a>
<script src="../../resources/ui-helper.js"></script>
<script>
(function () {
if (!window.eventSender)
return;
const anchor = document.querySelector('a');
eventSender.mouseMoveTo(anchor.offsetLeft + anchor.offsetWidth / 2, anchor.offsetTop + anchor.offsetHeight / 2);
eventSender.mouseDown();
})();
</script>
</body>
</html>
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body link="#008000">
<a href="#">hello</a>
</body>
</html>
12 changes: 12 additions & 0 deletions LayoutTests/fast/html/body-color-legacy-parsing-3.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<body vlink="0080x">
<a href="#bar">hello</a>
<script>
if (window.testRunner)
window.testRunner.keepWebHistory();
if (location.hash != '#bar')
location.href = '#bar';
</script>
</body>
</html>
1 change: 1 addition & 0 deletions LayoutTests/platform/ios/TestExpectations
Expand Up @@ -1093,6 +1093,7 @@ fast/css/pseudo-element-selector-scrollbar-hover.html [ Skip ]
fast/css/user-drag-none.html [ Skip ]
fast/forms/range/disabled-while-dragging.html [ Skip ]
fast/forms/range/range-drag-when-toggled-disabled.html [ Skip ]
fast/html/body-color-legacy-parsing-2.html [ Skip ]
fast/media/video-element-in-details-collapse.html [ Skip ]
fast/frames/user-gesture-timestamp-propagation.html [ Failure ]
fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html [ Skip ]
Expand Down
27 changes: 13 additions & 14 deletions Source/WebCore/html/HTMLBodyElement.cpp
Expand Up @@ -115,25 +115,24 @@ const AtomString& HTMLBodyElement::eventNameForWindowEventHandlerAttribute(const
void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == vlinkAttr || name == alinkAttr || name == linkAttr) {
if (value.isNull()) {
if (name == linkAttr)
auto parsedColor = parseLegacyColorValue(value);
if (name == linkAttr) {
if (parsedColor)
document().setLinkColor(*parsedColor);
else
document().resetLinkColor();
else if (name == vlinkAttr)
} else if (name == vlinkAttr) {
if (parsedColor)
document().setVisitedLinkColor(*parsedColor);
else
document().resetVisitedLinkColor();
} else {
ASSERT(name == alinkAttr);
if (parsedColor)
document().setActiveLinkColor(*parsedColor);
else
document().resetActiveLinkColor();
} else {
Color color = CSSParser::parseColorWithoutContext(value, !document().inQuirksMode());
if (color.isValid()) {
if (name == linkAttr)
document().setLinkColor(color);
else if (name == vlinkAttr)
document().setVisitedLinkColor(color);
else
document().setActiveLinkColor(color);
}
}

invalidateStyleForSubtree();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/HTMLElement.cpp
Expand Up @@ -966,7 +966,7 @@ void HTMLElement::addHTMLNumberToStyle(MutableStyleProperties& style, CSSPropert

// Color parsing that matches HTML's "rules for parsing a legacy color value"
// https://html.spec.whatwg.org/#rules-for-parsing-a-legacy-colour-value
static std::optional<SRGBA<uint8_t>> parseLegacyColorValue(StringView string)
std::optional<SRGBA<uint8_t>> HTMLElement::parseLegacyColorValue(StringView string)
{
// An empty string doesn't apply a color.
if (string.isEmpty())
Expand Down Expand Up @@ -1039,7 +1039,7 @@ static std::optional<SRGBA<uint8_t>> parseLegacyColorValue(StringView string)
return { { redValue, greenValue, blueValue } };
}

void HTMLElement::addHTMLColorToStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const String& attributeValue)
void HTMLElement::addHTMLColorToStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const AtomString& attributeValue)
{
if (auto color = parseLegacyColorValue(attributeValue))
style.setProperty(propertyID, CSSValuePool::singleton().createColorValue(*color));
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/html/HTMLElement.h
Expand Up @@ -148,7 +148,8 @@ class HTMLElement : public StyledElement {
void addHTMLPixelsToStyle(MutableStyleProperties&, CSSPropertyID, StringView value);
void addHTMLNumberToStyle(MutableStyleProperties&, CSSPropertyID, StringView value);

void addHTMLColorToStyle(MutableStyleProperties&, CSSPropertyID, const String& color);
static std::optional<SRGBA<uint8_t>> parseLegacyColorValue(StringView);
void addHTMLColorToStyle(MutableStyleProperties&, CSSPropertyID, const AtomString& color);

void applyAspectRatioFromWidthAndHeightAttributesToStyle(StringView widthAttribute, StringView heightAttribute, MutableStyleProperties&);
void applyAspectRatioWithoutDimensionalRulesFromWidthAndHeightAttributesToStyle(StringView widthAttribute, StringView heightAttribute, MutableStyleProperties&);
Expand Down

0 comments on commit c521422

Please sign in to comment.