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

Side by Side Diff: Source/core/paint/ImagePainter.cpp

Issue 696123002: Revert of Use Shadow DOM to display fallback content for images (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/ImageLoader.cpp ('k') | Source/core/rendering/RenderBox.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 5 #include "config.h"
6 #include "core/paint/ImagePainter.h" 6 #include "core/paint/ImagePainter.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/editing/FrameSelection.h" 10 #include "core/editing/FrameSelection.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 m_renderImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor)); 71 m_renderImage.resolveColor(areaElementStyle, CSSPropertyOutlineColor));
72 } 72 }
73 73
74 void ImagePainter::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintO ffset) 74 void ImagePainter::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintO ffset)
75 { 75 {
76 LayoutUnit cWidth = m_renderImage.contentWidth(); 76 LayoutUnit cWidth = m_renderImage.contentWidth();
77 LayoutUnit cHeight = m_renderImage.contentHeight(); 77 LayoutUnit cHeight = m_renderImage.contentHeight();
78 78
79 GraphicsContext* context = paintInfo.context; 79 GraphicsContext* context = paintInfo.context;
80 80
81 if (!m_renderImage.imageResource()->hasImage()) { 81 if (!m_renderImage.imageResource()->hasImage() || m_renderImage.imageResourc e()->errorOccurred()) {
82 if (paintInfo.phase == PaintPhaseSelection) 82 if (paintInfo.phase == PaintPhaseSelection)
83 return; 83 return;
84 84
85 if (cWidth > 2 && cHeight > 2) { 85 if (cWidth > 2 && cHeight > 2) {
86 const int borderWidth = 1;
87
88 LayoutUnit leftBorder = m_renderImage.borderLeft();
89 LayoutUnit topBorder = m_renderImage.borderTop();
90 LayoutUnit leftPad = m_renderImage.paddingLeft();
91 LayoutUnit topPad = m_renderImage.paddingTop();
92
86 // Draw an outline rect where the image should be. 93 // Draw an outline rect where the image should be.
87 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + m_renderImage.borderLeft() + m_renderImage.paddingLeft(), paintOffset.y() + m_r enderImage.borderTop() + m_renderImage.paddingTop(), cWidth, cHeight)); 94 IntRect paintRect = pixelSnappedIntRect(LayoutRect(paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight));
88 DrawingRecorder recorder(context, &m_renderImage, paintInfo.phase, p aintRect); 95 DrawingRecorder recorder(context, &m_renderImage, paintInfo.phase, p aintRect);
89 context->setStrokeStyle(SolidStroke); 96 context->setStrokeStyle(SolidStroke);
90 context->setStrokeColor(Color::lightGray); 97 context->setStrokeColor(Color::lightGray);
91 context->setFillColor(Color::transparent); 98 context->setFillColor(Color::transparent);
92 context->drawRect(paintRect); 99 context->drawRect(paintRect);
100
101 bool errorPictureDrawn = false;
102 LayoutSize imageOffset;
103 // When calculating the usable dimensions, exclude the pixels of
104 // the ouline rect so the error image/alt text doesn't draw on it.
105 LayoutUnit usableWidth = cWidth - 2 * borderWidth;
106 LayoutUnit usableHeight = cHeight - 2 * borderWidth;
107
108 RefPtr<Image> image = m_renderImage.imageResource()->image();
109
110 if (m_renderImage.imageResource()->errorOccurred() && !image->isNull () && usableWidth >= image->width() && usableHeight >= image->height()) {
111 float deviceScaleFactor = blink::deviceScaleFactor(m_renderImage .frame());
112 // Call brokenImage() explicitly to ensure we get the broken ima ge icon at the appropriate resolution.
113 pair<Image*, float> brokenImageAndImageScaleFactor = ImageResour ce::brokenImage(deviceScaleFactor);
114 image = brokenImageAndImageScaleFactor.first;
115 IntSize imageSize = image->size();
116 imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
117 // Center the error image, accounting for border and padding.
118 LayoutUnit centerX = (usableWidth - imageSize.width()) / 2;
119 if (centerX < 0)
120 centerX = 0;
121 LayoutUnit centerY = (usableHeight - imageSize.height()) / 2;
122 if (centerY < 0)
123 centerY = 0;
124 imageOffset = LayoutSize(leftBorder + leftPad + centerX + border Width, topBorder + topPad + centerY + borderWidth);
125 context->drawImage(image.get(), pixelSnappedIntRect(LayoutRect(p aintOffset + imageOffset, imageSize)), CompositeSourceOver, m_renderImage.should RespectImageOrientation());
126 errorPictureDrawn = true;
127 }
128
129 if (!m_renderImage.altText().isEmpty()) {
130 const Font& font = m_renderImage.style()->font();
131 const FontMetrics& fontMetrics = font.fontMetrics();
132 LayoutUnit ascent = fontMetrics.ascent();
133 LayoutPoint textRectOrigin = paintOffset;
134 textRectOrigin.move(leftBorder + leftPad + (RenderImage::padding Width / 2) - borderWidth, topBorder + topPad + (RenderImage::paddingHeight / 2) - borderWidth);
135 LayoutPoint textOrigin(textRectOrigin.x(), textRectOrigin.y() + ascent);
136
137 // Only draw the alt text if it'll fit within the content box,
138 // and only if it fits above the error image.
139 TextRun textRun = constructTextRun(&m_renderImage, font, m_rende rImage.altText(), m_renderImage.style(), TextRun::AllowTrailingExpansion | TextR un::ForbidLeadingExpansion, DefaultTextRunFlags | RespectDirection);
140 float textWidth = font.width(textRun);
141 TextRunPaintInfo textRunPaintInfo(textRun);
142 textRunPaintInfo.bounds = FloatRect(textRectOrigin, FloatSize(te xtWidth, fontMetrics.height()));
143 context->setFillColor(m_renderImage.resolveColor(CSSPropertyColo r));
144 if (textRun.direction() == RTL) {
145 int availableWidth = cWidth - static_cast<int>(RenderImage:: paddingWidth);
146 textOrigin.move(availableWidth - ceilf(textWidth), 0);
147 }
148 if (errorPictureDrawn) {
149 if (usableWidth >= textWidth && fontMetrics.height() <= imag eOffset.height())
150 context->drawBidiText(font, textRunPaintInfo, textOrigin );
151 } else if (usableWidth >= textWidth && usableHeight >= fontMetri cs.height()) {
152 context->drawBidiText(font, textRunPaintInfo, textOrigin);
153 }
154 }
93 } 155 }
94 } else if (cWidth > 0 && cHeight > 0) { 156 } else if (m_renderImage.imageResource()->hasImage() && cWidth > 0 && cHeigh t > 0) {
95 LayoutRect contentRect = m_renderImage.contentBoxRect(); 157 LayoutRect contentRect = m_renderImage.contentBoxRect();
96 contentRect.moveBy(paintOffset); 158 contentRect.moveBy(paintOffset);
97 LayoutRect paintRect = m_renderImage.replacedContentRect(); 159 LayoutRect paintRect = m_renderImage.replacedContentRect();
98 paintRect.moveBy(paintOffset); 160 paintRect.moveBy(paintOffset);
99 DrawingRecorder recorder(context, &m_renderImage, paintInfo.phase, conte ntRect); 161 DrawingRecorder recorder(context, &m_renderImage, paintInfo.phase, conte ntRect);
100 bool clip = !contentRect.contains(paintRect); 162 bool clip = !contentRect.contains(paintRect);
101 if (clip) { 163 if (clip) {
102 context->save(); 164 context->save();
103 context->clip(contentRect); 165 context->clip(contentRect);
104 } 166 }
(...skipping 22 matching lines...) Expand all
127 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing. 189 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing.
128 InspectorInstrumentation::willPaintImage(&m_renderImage); 190 InspectorInstrumentation::willPaintImage(&m_renderImage);
129 InterpolationQuality previousInterpolationQuality = context->imageInterpolat ionQuality(); 191 InterpolationQuality previousInterpolationQuality = context->imageInterpolat ionQuality();
130 context->setImageInterpolationQuality(interpolationQuality); 192 context->setImageInterpolationQuality(interpolationQuality);
131 context->drawImage(image, alignedRect, CompositeSourceOver, m_renderImage.sh ouldRespectImageOrientation()); 193 context->drawImage(image, alignedRect, CompositeSourceOver, m_renderImage.sh ouldRespectImageOrientation());
132 context->setImageInterpolationQuality(previousInterpolationQuality); 194 context->setImageInterpolationQuality(previousInterpolationQuality);
133 InspectorInstrumentation::didPaintImage(&m_renderImage); 195 InspectorInstrumentation::didPaintImage(&m_renderImage);
134 } 196 }
135 197
136 } // namespace blink 198 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/ImageLoader.cpp ('k') | Source/core/rendering/RenderBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698