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

Unified Diff: sky/engine/core/rendering/RenderImage.cpp

Issue 715963003: Remove alt text from images. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: minor improvement 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/rendering/RenderImage.h ('k') | sky/engine/public/platform/WebLocalizedString.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/rendering/RenderImage.cpp
diff --git a/sky/engine/core/rendering/RenderImage.cpp b/sky/engine/core/rendering/RenderImage.cpp
index 752df66162cece75d152b933d250f72ee0356ec2..a4645cd59761627d087e7d2129344e60014b666e 100644
--- a/sky/engine/core/rendering/RenderImage.cpp
+++ b/sky/engine/core/rendering/RenderImage.cpp
@@ -52,7 +52,6 @@ RenderImage::RenderImage(Element* element)
: RenderReplaced(element, IntSize())
, m_imageDevicePixelRatio(1.0f)
{
- updateAltText();
}
RenderImage* RenderImage::createAnonymous(Document* document)
@@ -80,62 +79,6 @@ void RenderImage::setImageResource(PassOwnPtr<RenderImageResource> imageResource
m_imageResource->initialize(this);
}
-// If we'll be displaying either alt text or an image, add some padding.
-static const unsigned short paddingWidth = 4;
-static const unsigned short paddingHeight = 4;
-
-// Alt text is restricted to this maximum size, in pixels. These are
-// signed integers because they are compared with other signed values.
-static const float maxAltTextWidth = 1024;
-static const int maxAltTextHeight = 256;
-
-IntSize RenderImage::imageSizeForError(ImageResource* newImage) const
-{
- ASSERT_ARG(newImage, newImage);
- ASSERT_ARG(newImage, newImage->imageForRenderer(this));
-
- IntSize imageSize;
- if (newImage->willPaintBrokenImage()) {
- float deviceScaleFactor = blink::deviceScaleFactor(frame());
- pair<Image*, float> brokenImageAndImageScaleFactor = ImageResource::brokenImage(deviceScaleFactor);
- imageSize = brokenImageAndImageScaleFactor.first->size();
- imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
- } else
- imageSize = newImage->imageForRenderer(this)->size();
-
- // imageSize() returns 0 for the error image. We need the true size of the
- // error image, so we have to get it by grabbing image() directly.
- return IntSize(paddingWidth + imageSize.width(), paddingHeight + imageSize.height());
-}
-
-// Sets the image height and width to fit the alt text. Returns true if the
-// image size changed.
-bool RenderImage::setImageSizeForAltText(ImageResource* newImage /* = 0 */)
-{
- IntSize imageSize;
- if (newImage && newImage->imageForRenderer(this))
- imageSize = imageSizeForError(newImage);
- else if (!m_altText.isEmpty() || newImage) {
- // If we'll be displaying either text or an image, add a little padding.
- imageSize = IntSize(paddingWidth, paddingHeight);
- }
-
- // we have an alt and the user meant it (its not a text we invented)
- if (!m_altText.isEmpty()) {
- FontCachePurgePreventer fontCachePurgePreventer;
-
- const Font& font = style()->font();
- IntSize paddedTextSize(paddingWidth + std::min(ceilf(font.width(constructTextRun(this, font, m_altText, style()))), maxAltTextWidth), paddingHeight + std::min(font.fontMetrics().height(), maxAltTextHeight));
- imageSize = imageSize.expandedTo(paddedTextSize);
- }
-
- if (imageSize == intrinsicSize())
- return false;
-
- setIntrinsicSize(imageSize);
- return true;
-}
-
void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
{
if (documentBeingDestroyed())
@@ -155,13 +98,7 @@ void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
if (m_imageResource->cachedImage() && m_imageResource->cachedImage()->hasDevicePixelRatioHeaderValue())
m_imageDevicePixelRatio = 1 / m_imageResource->cachedImage()->devicePixelRatioHeaderValue();
- bool imageSizeChanged = false;
-
- // Set image dimensions, taking into account the size of the alt text.
- if (m_imageResource->errorOccurred() || !newImage)
- imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage());
-
- paintInvalidationOrMarkForLayout(imageSizeChanged, rect);
+ paintInvalidationOrMarkForLayout(rect);
}
void RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize)
@@ -180,7 +117,7 @@ void RenderImage::updateInnerContentRect()
m_imageResource->setContainerSizeForRenderer(containerSize);
}
-void RenderImage::paintInvalidationOrMarkForLayout(bool imageSizeChangedToAccomodateAltText, const IntRect* rect)
+void RenderImage::paintInvalidationOrMarkForLayout(const IntRect* rect)
{
LayoutSize oldIntrinsicSize = intrinsicSize();
LayoutSize newIntrinsicSize = m_imageResource->intrinsicSize();
@@ -193,7 +130,7 @@ void RenderImage::paintInvalidationOrMarkForLayout(bool imageSizeChangedToAccomo
if (!containingBlock())
return;
- bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize || imageSizeChangedToAccomodateAltText;
+ bool imageSourceHasChangedSize = oldIntrinsicSize != newIntrinsicSize;
if (imageSourceHasChangedSize)
setPreferredLogicalWidthsDirty();
@@ -260,85 +197,9 @@ void RenderImage::notifyFinished(Resource* newImage)
void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
- LayoutUnit cWidth = contentWidth();
- LayoutUnit cHeight = contentHeight();
-
GraphicsContext* context = paintInfo.context;
- if (!m_imageResource->hasImage() || m_imageResource->errorOccurred()) {
- if (paintInfo.phase == PaintPhaseSelection)
- return;
-
- if (cWidth > 2 && cHeight > 2) {
- const int borderWidth = 1;
-
- LayoutUnit leftBorder = borderLeft();
- LayoutUnit topBorder = borderTop();
- LayoutUnit leftPad = paddingLeft();
- LayoutUnit topPad = paddingTop();
-
- // Draw an outline rect where the image should be.
- context->setStrokeStyle(SolidStroke);
- context->setStrokeColor(Color::lightGray);
- context->setFillColor(Color::transparent);
- context->drawRect(pixelSnappedIntRect(LayoutRect(paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight)));
-
- bool errorPictureDrawn = false;
- LayoutSize imageOffset;
- // When calculating the usable dimensions, exclude the pixels of
- // the ouline rect so the error image/alt text doesn't draw on it.
- LayoutUnit usableWidth = cWidth - 2 * borderWidth;
- LayoutUnit usableHeight = cHeight - 2 * borderWidth;
-
- RefPtr<Image> image = m_imageResource->image();
-
- if (m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
- float deviceScaleFactor = blink::deviceScaleFactor(frame());
- // Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
- pair<Image*, float> brokenImageAndImageScaleFactor = ImageResource::brokenImage(deviceScaleFactor);
- image = brokenImageAndImageScaleFactor.first;
- IntSize imageSize = image->size();
- imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
- // Center the error image, accounting for border and padding.
- LayoutUnit centerX = (usableWidth - imageSize.width()) / 2;
- if (centerX < 0)
- centerX = 0;
- LayoutUnit centerY = (usableHeight - imageSize.height()) / 2;
- if (centerY < 0)
- centerY = 0;
- imageOffset = LayoutSize(leftBorder + leftPad + centerX + borderWidth, topBorder + topPad + centerY + borderWidth);
- context->drawImage(image.get(), pixelSnappedIntRect(LayoutRect(paintOffset + imageOffset, imageSize)), CompositeSourceOver, shouldRespectImageOrientation());
- errorPictureDrawn = true;
- }
-
- if (!m_altText.isEmpty()) {
- const Font& font = style()->font();
- const FontMetrics& fontMetrics = font.fontMetrics();
- LayoutUnit ascent = fontMetrics.ascent();
- LayoutPoint textRectOrigin = paintOffset;
- textRectOrigin.move(leftBorder + leftPad + (paddingWidth / 2) - borderWidth, topBorder + topPad + (paddingHeight / 2) - borderWidth);
- LayoutPoint textOrigin(textRectOrigin.x(), textRectOrigin.y() + ascent);
-
- // Only draw the alt text if it'll fit within the content box,
- // and only if it fits above the error image.
- TextRun textRun = constructTextRun(this, font, m_altText, style(), TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpansion, DefaultTextRunFlags | RespectDirection);
- float textWidth = font.width(textRun);
- TextRunPaintInfo textRunPaintInfo(textRun);
- textRunPaintInfo.bounds = FloatRect(textRectOrigin, FloatSize(textWidth, fontMetrics.height()));
- context->setFillColor(resolveColor(CSSPropertyColor));
- if (textRun.direction() == RTL) {
- int availableWidth = cWidth - static_cast<int>(paddingWidth);
- textOrigin.move(availableWidth - ceilf(textWidth), 0);
- }
- if (errorPictureDrawn) {
- if (usableWidth >= textWidth && fontMetrics.height() <= imageOffset.height())
- context->drawBidiText(font, textRunPaintInfo, textOrigin);
- } else if (usableWidth >= textWidth && usableHeight >= fontMetrics.height()) {
- context->drawBidiText(font, textRunPaintInfo, textOrigin);
- }
- }
- }
- } else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) {
+ if (m_imageResource->hasImage() && contentWidth() > 0 && contentHeight() > 0) {
LayoutRect contentRect = contentBoxRect();
contentRect.moveBy(paintOffset);
LayoutRect paintRect = replacedContentRect();
@@ -450,15 +311,6 @@ bool RenderImage::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
return inside;
}
-void RenderImage::updateAltText()
-{
- if (!node())
- return;
-
- if (isHTMLImageElement(*node()))
- m_altText = toHTMLImageElement(node())->altText();
-}
-
void RenderImage::layout()
{
LayoutRect oldContentRect = replacedContentRect();
« no previous file with comments | « sky/engine/core/rendering/RenderImage.h ('k') | sky/engine/public/platform/WebLocalizedString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698