Commit be11a3e6 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Reorder/clean up HTMLImageFallbackHelper::CreateAltTextShadowTree

This reorders the construction sequence so that the created subtrees or
nodes are inserted after they've had their attributes (and other things)
set.

In the context of the bug referenced the interesting bit is setting the
is-fallback-image flag on the HTMLImageElement before inserting it.

Bug: 1000273
Change-Id: Ica4d7d50709c9338b4df6e3c4a4ce1f22d5c3924
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789811
Auto-Submit: Fredrik Söderquist <fs@opera.com>
Commit-Queue: Stephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694751}
parent 7323cad3
...@@ -113,16 +113,12 @@ class ImageFallbackContentBuilder { ...@@ -113,16 +113,12 @@ class ImageFallbackContentBuilder {
} // namespace } // namespace
void HTMLImageFallbackHelper::CreateAltTextShadowTree(Element& element) { void HTMLImageFallbackHelper::CreateAltTextShadowTree(Element& element) {
ShadowRoot& root = element.EnsureUserAgentShadowRoot(); Document& document = element.GetDocument();
auto* container = auto* container = MakeGarbageCollected<HTMLSpanElement>(document);
MakeGarbageCollected<HTMLSpanElement>(element.GetDocument());
root.AppendChild(container);
container->setAttribute(kIdAttr, AtomicString("alttext-container")); container->setAttribute(kIdAttr, AtomicString("alttext-container"));
auto* broken_image = auto* broken_image = MakeGarbageCollected<HTMLImageElement>(document);
MakeGarbageCollected<HTMLImageElement>(element.GetDocument());
container->AppendChild(broken_image);
broken_image->SetIsFallbackImage(); broken_image->SetIsFallbackImage();
broken_image->setAttribute(kIdAttr, AtomicString("alttext-image")); broken_image->setAttribute(kIdAttr, AtomicString("alttext-image"));
broken_image->setAttribute(kWidthAttr, AtomicString("16")); broken_image->setAttribute(kWidthAttr, AtomicString("16"));
...@@ -130,14 +126,16 @@ void HTMLImageFallbackHelper::CreateAltTextShadowTree(Element& element) { ...@@ -130,14 +126,16 @@ void HTMLImageFallbackHelper::CreateAltTextShadowTree(Element& element) {
broken_image->setAttribute(kAlignAttr, AtomicString("left")); broken_image->setAttribute(kAlignAttr, AtomicString("left"));
broken_image->SetInlineStyleProperty(CSSPropertyID::kMargin, 0, broken_image->SetInlineStyleProperty(CSSPropertyID::kMargin, 0,
CSSPrimitiveValue::UnitType::kPixels); CSSPrimitiveValue::UnitType::kPixels);
container->AppendChild(broken_image);
auto* alt_text = MakeGarbageCollected<HTMLSpanElement>(element.GetDocument()); auto* alt_text = MakeGarbageCollected<HTMLSpanElement>(document);
container->AppendChild(alt_text);
alt_text->setAttribute(kIdAttr, AtomicString("alttext")); alt_text->setAttribute(kIdAttr, AtomicString("alttext"));
Text* text = auto* text = Text::Create(document, To<HTMLElement>(element).AltText());
Text::Create(element.GetDocument(), To<HTMLElement>(element).AltText());
alt_text->AppendChild(text); alt_text->AppendChild(text);
container->AppendChild(alt_text);
element.EnsureUserAgentShadowRoot().AppendChild(container);
} }
scoped_refptr<ComputedStyle> HTMLImageFallbackHelper::CustomStyleForAltText( scoped_refptr<ComputedStyle> HTMLImageFallbackHelper::CustomStyleForAltText(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment