Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLImageFallbackHelper.cpp

Issue 2384273007: reflow comments in core/html/*.{cpp,h},core/html/imports (Closed)
Patch Set: comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 altText->setInlineStyleProperty(CSSPropertyDisplay, CSSValueBlock); 65 altText->setInlineStyleProperty(CSSPropertyDisplay, CSSValueBlock);
66 66
67 Text* text = 67 Text* text =
68 Text::create(element.document(), toHTMLElement(element).altText()); 68 Text::create(element.document(), toHTMLElement(element).altText());
69 altText->appendChild(text); 69 altText->appendChild(text);
70 } 70 }
71 71
72 PassRefPtr<ComputedStyle> HTMLImageFallbackHelper::customStyleForAltText( 72 PassRefPtr<ComputedStyle> HTMLImageFallbackHelper::customStyleForAltText(
73 Element& element, 73 Element& element,
74 PassRefPtr<ComputedStyle> newStyle) { 74 PassRefPtr<ComputedStyle> newStyle) {
75 // If we have an author shadow root or have not created the UA shadow root yet , bail early. We can't 75 // If we have an author shadow root or have not created the UA shadow root
76 // use ensureUserAgentShadowRoot() here because that would alter the DOM tree during style recalc. 76 // yet, bail early. We can't use ensureUserAgentShadowRoot() here because that
77 // would alter the DOM tree during style recalc.
77 if (element.authorShadowRoot() || !element.userAgentShadowRoot()) 78 if (element.authorShadowRoot() || !element.userAgentShadowRoot())
78 return newStyle; 79 return newStyle;
79 80
80 Element* placeHolder = 81 Element* placeHolder =
81 element.userAgentShadowRoot()->getElementById("alttext-container"); 82 element.userAgentShadowRoot()->getElementById("alttext-container");
82 Element* brokenImage = 83 Element* brokenImage =
83 element.userAgentShadowRoot()->getElementById("alttext-image"); 84 element.userAgentShadowRoot()->getElementById("alttext-image");
84 // Input elements have a UA shadow root of their own. We may not have replaced it with fallback content yet. 85 // Input elements have a UA shadow root of their own. We may not have replaced
86 // it with fallback content yet.
85 if (!placeHolder || !brokenImage) 87 if (!placeHolder || !brokenImage)
86 return newStyle; 88 return newStyle;
87 89
88 if (element.document().inQuirksMode()) { 90 if (element.document().inQuirksMode()) {
89 // Mimic the behaviour of the image host by setting symmetric dimensions if only one dimension is specified. 91 // Mimic the behaviour of the image host by setting symmetric dimensions if
92 // only one dimension is specified.
90 if (newStyle->width().isSpecifiedOrIntrinsic() && 93 if (newStyle->width().isSpecifiedOrIntrinsic() &&
91 newStyle->height().isAuto()) 94 newStyle->height().isAuto())
92 newStyle->setHeight(newStyle->width()); 95 newStyle->setHeight(newStyle->width());
93 else if (newStyle->height().isSpecifiedOrIntrinsic() && 96 else if (newStyle->height().isSpecifiedOrIntrinsic() &&
94 newStyle->width().isAuto()) 97 newStyle->width().isAuto())
95 newStyle->setWidth(newStyle->height()); 98 newStyle->setWidth(newStyle->height());
96 if (newStyle->width().isSpecifiedOrIntrinsic() && 99 if (newStyle->width().isSpecifiedOrIntrinsic() &&
97 newStyle->height().isSpecifiedOrIntrinsic()) { 100 newStyle->height().isSpecifiedOrIntrinsic()) {
98 placeHolder->setInlineStyleProperty(CSSPropertyVerticalAlign, 101 placeHolder->setInlineStyleProperty(CSSPropertyVerticalAlign,
99 CSSValueBaseline); 102 CSSValueBaseline);
100 } 103 }
101 } 104 }
102 105
103 // If the image has specified dimensions allow the alt-text container expand t o fill them. 106 // If the image has specified dimensions allow the alt-text container expand
107 // to fill them.
104 if (newStyle->width().isSpecifiedOrIntrinsic() && 108 if (newStyle->width().isSpecifiedOrIntrinsic() &&
105 newStyle->height().isSpecifiedOrIntrinsic()) { 109 newStyle->height().isSpecifiedOrIntrinsic()) {
106 placeHolder->setInlineStyleProperty( 110 placeHolder->setInlineStyleProperty(
107 CSSPropertyWidth, 100, CSSPrimitiveValue::UnitType::Percentage); 111 CSSPropertyWidth, 100, CSSPrimitiveValue::UnitType::Percentage);
108 placeHolder->setInlineStyleProperty( 112 placeHolder->setInlineStyleProperty(
109 CSSPropertyHeight, 100, CSSPrimitiveValue::UnitType::Percentage); 113 CSSPropertyHeight, 100, CSSPrimitiveValue::UnitType::Percentage);
110 } 114 }
111 115
112 // Make sure the broken image icon appears on the appropriate side of the imag e for the element's writing direction. 116 // Make sure the broken image icon appears on the appropriate side of the
117 // image for the element's writing direction.
113 brokenImage->setInlineStyleProperty( 118 brokenImage->setInlineStyleProperty(
114 CSSPropertyFloat, 119 CSSPropertyFloat,
115 AtomicString(newStyle->direction() == LTR ? "left" : "right")); 120 AtomicString(newStyle->direction() == LTR ? "left" : "right"));
116 121
117 // This is an <img> with no attributes, so don't display anything. 122 // This is an <img> with no attributes, so don't display anything.
118 if (noImageSourceSpecified(element) && 123 if (noImageSourceSpecified(element) &&
119 !newStyle->width().isSpecifiedOrIntrinsic() && 124 !newStyle->width().isSpecifiedOrIntrinsic() &&
120 !newStyle->height().isSpecifiedOrIntrinsic() && 125 !newStyle->height().isSpecifiedOrIntrinsic() &&
121 toHTMLElement(element).altText().isEmpty()) 126 toHTMLElement(element).altText().isEmpty())
122 newStyle->setDisplay(EDisplay::None); 127 newStyle->setDisplay(EDisplay::None);
123 128
124 // This preserves legacy behaviour originally defined when alt-text was manage d by LayoutImage. 129 // This preserves legacy behaviour originally defined when alt-text was
130 // managed by LayoutImage.
125 if (noImageSourceSpecified(element)) 131 if (noImageSourceSpecified(element))
126 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone); 132 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone);
127 else 133 else
128 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInline); 134 brokenImage->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInline);
129 135
130 return newStyle; 136 return newStyle;
131 } 137 }
132 138
133 } // namespace blink 139 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLImageElementTest.cpp ('k') | third_party/WebKit/Source/core/html/HTMLImageLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698