OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/html/HTMLImageFallbackHelper.h" | 5 #include "core/html/HTMLImageFallbackHelper.h" |
6 | 6 |
7 #include "core/HTMLNames.h" | 7 #include "core/HTMLNames.h" |
8 #include "core/InputTypeNames.h" | 8 #include "core/InputTypeNames.h" |
9 #include "core/dom/ElementRareData.h" | 9 #include "core/dom/ElementRareData.h" |
10 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 bool noSrcsetSpecified = !element.hasAttribute(srcsetAttr) || element.getAtt
ribute(srcsetAttr).isNull() || element.getAttribute(srcsetAttr).isEmpty(); | 29 bool noSrcsetSpecified = !element.hasAttribute(srcsetAttr) || element.getAtt
ribute(srcsetAttr).isNull() || element.getAttribute(srcsetAttr).isEmpty(); |
30 return noSrcSpecified && noSrcsetSpecified; | 30 return noSrcSpecified && noSrcsetSpecified; |
31 } | 31 } |
32 | 32 |
33 void HTMLImageFallbackHelper::createAltTextShadowTree(Element& element) | 33 void HTMLImageFallbackHelper::createAltTextShadowTree(Element& element) |
34 { | 34 { |
35 ShadowRoot& root = element.ensureUserAgentShadowRoot(); | 35 ShadowRoot& root = element.ensureUserAgentShadowRoot(); |
36 | 36 |
37 RefPtrWillBeRawPtr<HTMLDivElement> container = HTMLDivElement::create(elemen
t.document()); | 37 RefPtrWillBeRawPtr<HTMLDivElement> container = HTMLDivElement::create(elemen
t.document()); |
38 root.appendChild(container); | 38 root.appendChild(container); |
39 container->setAttribute(idAttr, AtomicString("alttext-container", AtomicStri
ng::ConstructFromLiteral)); | 39 container->setAttribute(idAttr, AtomicString("alttext-container")); |
40 container->setInlineStyleProperty(CSSPropertyOverflow, CSSValueHidden); | 40 container->setInlineStyleProperty(CSSPropertyOverflow, CSSValueHidden); |
41 container->setInlineStyleProperty(CSSPropertyBorderWidth, 1, CSSPrimitiveVal
ue::UnitType::Pixels); | 41 container->setInlineStyleProperty(CSSPropertyBorderWidth, 1, CSSPrimitiveVal
ue::UnitType::Pixels); |
42 container->setInlineStyleProperty(CSSPropertyBorderStyle, CSSValueSolid); | 42 container->setInlineStyleProperty(CSSPropertyBorderStyle, CSSValueSolid); |
43 container->setInlineStyleProperty(CSSPropertyBorderColor, CSSValueSilver); | 43 container->setInlineStyleProperty(CSSPropertyBorderColor, CSSValueSilver); |
44 container->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInlineBlock); | 44 container->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInlineBlock); |
45 container->setInlineStyleProperty(CSSPropertyBoxSizing, CSSValueBorderBox); | 45 container->setInlineStyleProperty(CSSPropertyBoxSizing, CSSValueBorderBox); |
46 container->setInlineStyleProperty(CSSPropertyPadding, 1, CSSPrimitiveValue::
UnitType::Pixels); | 46 container->setInlineStyleProperty(CSSPropertyPadding, 1, CSSPrimitiveValue::
UnitType::Pixels); |
47 | 47 |
48 RefPtrWillBeRawPtr<HTMLImageElement> brokenImage = HTMLImageElement::create(
element.document()); | 48 RefPtrWillBeRawPtr<HTMLImageElement> brokenImage = HTMLImageElement::create(
element.document()); |
49 container->appendChild(brokenImage); | 49 container->appendChild(brokenImage); |
50 brokenImage->setIsFallbackImage(); | 50 brokenImage->setIsFallbackImage(); |
51 brokenImage->setAttribute(idAttr, AtomicString("alttext-image", AtomicString
::ConstructFromLiteral)); | 51 brokenImage->setAttribute(idAttr, AtomicString("alttext-image")); |
52 brokenImage->setAttribute(widthAttr, AtomicString("16", AtomicString::Constr
uctFromLiteral)); | 52 brokenImage->setAttribute(widthAttr, AtomicString("16")); |
53 brokenImage->setAttribute(heightAttr, AtomicString("16", AtomicString::Const
ructFromLiteral)); | 53 brokenImage->setAttribute(heightAttr, AtomicString("16")); |
54 brokenImage->setAttribute(alignAttr, AtomicString("left", AtomicString::Cons
tructFromLiteral)); | 54 brokenImage->setAttribute(alignAttr, AtomicString("left")); |
55 brokenImage->setInlineStyleProperty(CSSPropertyMargin, 0, CSSPrimitiveValue:
:UnitType::Pixels); | 55 brokenImage->setInlineStyleProperty(CSSPropertyMargin, 0, CSSPrimitiveValue:
:UnitType::Pixels); |
56 | 56 |
57 RefPtrWillBeRawPtr<HTMLDivElement> altText = HTMLDivElement::create(element.
document()); | 57 RefPtrWillBeRawPtr<HTMLDivElement> altText = HTMLDivElement::create(element.
document()); |
58 container->appendChild(altText); | 58 container->appendChild(altText); |
59 altText->setAttribute(idAttr, AtomicString("alttext", AtomicString::Construc
tFromLiteral)); | 59 altText->setAttribute(idAttr, AtomicString("alttext")); |
60 altText->setInlineStyleProperty(CSSPropertyOverflow, CSSValueHidden); | 60 altText->setInlineStyleProperty(CSSPropertyOverflow, CSSValueHidden); |
61 altText->setInlineStyleProperty(CSSPropertyDisplay, CSSValueBlock); | 61 altText->setInlineStyleProperty(CSSPropertyDisplay, CSSValueBlock); |
62 | 62 |
63 RefPtrWillBeRawPtr<Text> text = Text::create(element.document(), toHTMLEleme
nt(element).altText()); | 63 RefPtrWillBeRawPtr<Text> text = Text::create(element.document(), toHTMLEleme
nt(element).altText()); |
64 altText->appendChild(text); | 64 altText->appendChild(text); |
65 } | 65 } |
66 | 66 |
67 PassRefPtr<ComputedStyle> HTMLImageFallbackHelper::customStyleForAltText(Element
& element, PassRefPtr<ComputedStyle> newStyle) | 67 PassRefPtr<ComputedStyle> HTMLImageFallbackHelper::customStyleForAltText(Element
& element, PassRefPtr<ComputedStyle> newStyle) |
68 { | 68 { |
69 // If we have an author shadow root or have not created the UA shadow root y
et, bail early. We can't | 69 // If we have an author shadow root or have not created the UA shadow root y
et, bail early. We can't |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // This preserves legacy behaviour originally defined when alt-text was mana
ged by LayoutImage. | 105 // This preserves legacy behaviour originally defined when alt-text was mana
ged by LayoutImage. |
106 if (noImageSourceSpecified(element)) | 106 if (noImageSourceSpecified(element)) |
107 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); | 107 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); |
108 else | 108 else |
109 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInline); | 109 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInline); |
110 | 110 |
111 return newStyle; | 111 return newStyle; |
112 } | 112 } |
113 | 113 |
114 } // namespace blink | 114 } // namespace blink |
OLD | NEW |