| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) | 5 * (C) 2006 Allan Sandfeld Jensen (kde@carewolf.com) |
| 6 * (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 6 * (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 9 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. | 9 * Copyright (C) Research In Motion Limited 2011-2012. All rights reserved. |
| 10 * | 10 * |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 286 |
| 287 if (cWidth > 2 && cHeight > 2) { | 287 if (cWidth > 2 && cHeight > 2) { |
| 288 const int borderWidth = 1; | 288 const int borderWidth = 1; |
| 289 | 289 |
| 290 // Draw an outline rect where the image should be. | 290 // Draw an outline rect where the image should be. |
| 291 context->setStrokeStyle(SolidStroke); | 291 context->setStrokeStyle(SolidStroke); |
| 292 context->setStrokeColor(Color::lightGray); | 292 context->setStrokeColor(Color::lightGray); |
| 293 context->setFillColor(Color::transparent); | 293 context->setFillColor(Color::transparent); |
| 294 context->drawRect(pixelSnappedIntRect(LayoutRect(paintOffset.x() + l
eftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight))); | 294 context->drawRect(pixelSnappedIntRect(LayoutRect(paintOffset.x() + l
eftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight))); |
| 295 | 295 |
| 296 bool errorPictureDrawn = false; | 296 bool altTextDisplayed = false; |
| 297 LayoutSize imageOffset; | |
| 298 // When calculating the usable dimensions, exclude the pixels of | 297 // When calculating the usable dimensions, exclude the pixels of |
| 299 // the ouline rect so the error image/alt text doesn't draw on it. | 298 // the ouline rect so the error image/alt text doesn't draw on it. |
| 300 LayoutUnit usableWidth = cWidth - 2 * borderWidth; | 299 LayoutUnit usableWidth = cWidth - 2 * borderWidth; |
| 301 LayoutUnit usableHeight = cHeight - 2 * borderWidth; | 300 LayoutUnit usableHeight = cHeight - 2 * borderWidth; |
| 302 | 301 |
| 303 RefPtr<Image> image = m_imageResource->image(); | 302 RefPtr<Image> image = m_imageResource->image(); |
| 304 | 303 |
| 305 if (m_imageResource->errorOccurred() && !image->isNull() && usableWi
dth >= image->width() && usableHeight >= image->height()) { | |
| 306 float deviceScaleFactor = WebCore::deviceScaleFactor(frame()); | |
| 307 // Call brokenImage() explicitly to ensure we get the broken ima
ge icon at the appropriate resolution. | |
| 308 pair<Image*, float> brokenImageAndImageScaleFactor = ImageResour
ce::brokenImage(deviceScaleFactor); | |
| 309 image = brokenImageAndImageScaleFactor.first; | |
| 310 IntSize imageSize = image->size(); | |
| 311 imageSize.scale(1 / brokenImageAndImageScaleFactor.second); | |
| 312 // Center the error image, accounting for border and padding. | |
| 313 LayoutUnit centerX = (usableWidth - imageSize.width()) / 2; | |
| 314 if (centerX < 0) | |
| 315 centerX = 0; | |
| 316 LayoutUnit centerY = (usableHeight - imageSize.height()) / 2; | |
| 317 if (centerY < 0) | |
| 318 centerY = 0; | |
| 319 imageOffset = LayoutSize(leftBorder + leftPad + centerX + border
Width, topBorder + topPad + centerY + borderWidth); | |
| 320 context->drawImage(image.get(), pixelSnappedIntRect(LayoutRect(p
aintOffset + imageOffset, imageSize)), CompositeSourceOver, shouldRespectImageOr
ientation()); | |
| 321 errorPictureDrawn = true; | |
| 322 } | |
| 323 | |
| 324 if (!m_altText.isEmpty()) { | 304 if (!m_altText.isEmpty()) { |
| 325 const Font& font = style()->font(); | 305 const Font& font = style()->font(); |
| 326 const FontMetrics& fontMetrics = font.fontMetrics(); | 306 const FontMetrics& fontMetrics = font.fontMetrics(); |
| 327 LayoutUnit ascent = fontMetrics.ascent(); | 307 LayoutUnit ascent = fontMetrics.ascent(); |
| 328 LayoutPoint textRectOrigin = paintOffset; | 308 LayoutPoint textRectOrigin = paintOffset; |
| 329 textRectOrigin.move(leftBorder + leftPad + (paddingWidth / 2) -
borderWidth, topBorder + topPad + (paddingHeight / 2) - borderWidth); | 309 textRectOrigin.move(leftBorder + leftPad + (paddingWidth / 2) -
borderWidth, topBorder + topPad + (paddingHeight / 2) - borderWidth); |
| 330 LayoutPoint textOrigin(textRectOrigin.x(), textRectOrigin.y() +
ascent); | 310 LayoutPoint textOrigin(textRectOrigin.x(), textRectOrigin.y() +
ascent); |
| 331 | 311 |
| 332 // Only draw the alt text if it'll fit within the content box, | 312 // Only draw the alt text if it'll fit within the content box, |
| 333 // and only if it fits above the error image. | 313 // and only if it fits above the error image. |
| 334 TextRun textRun = RenderBlockFlow::constructTextRun(this, font,
m_altText, style(), TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpa
nsion, DefaultTextRunFlags | RespectDirection); | 314 TextRun textRun = RenderBlockFlow::constructTextRun(this, font,
m_altText, style(), TextRun::AllowTrailingExpansion | TextRun::ForbidLeadingExpa
nsion, DefaultTextRunFlags | RespectDirection); |
| 335 float textWidth = font.width(textRun); | 315 float textWidth = font.width(textRun); |
| 336 TextRunPaintInfo textRunPaintInfo(textRun); | 316 TextRunPaintInfo textRunPaintInfo(textRun); |
| 337 textRunPaintInfo.bounds = FloatRect(textRectOrigin, FloatSize(te
xtWidth, fontMetrics.height())); | 317 textRunPaintInfo.bounds = FloatRect(textRectOrigin, FloatSize(te
xtWidth, fontMetrics.height())); |
| 338 context->setFillColor(resolveColor(CSSPropertyColor)); | 318 context->setFillColor(resolveColor(CSSPropertyColor)); |
| 339 if (textRun.direction() == RTL) { | 319 if (textRun.direction() == RTL) { |
| 340 int availableWidth = cWidth - static_cast<int>(paddingWidth)
; | 320 int availableWidth = cWidth - static_cast<int>(paddingWidth)
; |
| 341 textOrigin.move(availableWidth - ceilf(textWidth), 0); | 321 textOrigin.move(availableWidth - ceilf(textWidth), 0); |
| 342 } | 322 } |
| 343 if (errorPictureDrawn) { | 323 if (usableWidth >= textWidth && usableHeight >= fontMetrics.heig
ht()) { |
| 344 if (usableWidth >= textWidth && fontMetrics.height() <= imag
eOffset.height()) | |
| 345 context->drawBidiText(font, textRunPaintInfo, textOrigin
); | |
| 346 } else if (usableWidth >= textWidth && usableHeight >= fontMetri
cs.height()) { | |
| 347 context->drawBidiText(font, textRunPaintInfo, textOrigin); | 324 context->drawBidiText(font, textRunPaintInfo, textOrigin); |
| 325 altTextDisplayed = true; |
| 348 } | 326 } |
| 349 } | 327 } |
| 328 |
| 329 if (!altTextDisplayed && m_imageResource->errorOccurred() && !image-
>isNull() && usableWidth >= image->width() && usableHeight >= image->height()) { |
| 330 float deviceScaleFactor = WebCore::deviceScaleFactor(frame()); |
| 331 // Call brokenImage() explicitly to ensure we get the broken ima
ge icon at the appropriate resolution. |
| 332 pair<Image*, float> brokenImageAndImageScaleFactor = ImageResour
ce::brokenImage(deviceScaleFactor); |
| 333 image = brokenImageAndImageScaleFactor.first; |
| 334 IntSize imageSize = image->size(); |
| 335 imageSize.scale(1 / brokenImageAndImageScaleFactor.second); |
| 336 // Center the error image, accounting for border and padding. |
| 337 LayoutUnit centerX = (usableWidth - imageSize.width()) / 2; |
| 338 if (centerX < 0) |
| 339 centerX = 0; |
| 340 LayoutUnit centerY = (usableHeight - imageSize.height()) / 2; |
| 341 if (centerY < 0) |
| 342 centerY = 0; |
| 343 LayoutSize imageOffset; |
| 344 imageOffset = LayoutSize(leftBorder + leftPad + centerX + border
Width, topBorder + topPad + centerY + borderWidth); |
| 345 context->drawImage(image.get(), pixelSnappedIntRect(LayoutRect(p
aintOffset + imageOffset, imageSize)), CompositeSourceOver, shouldRespectImageOr
ientation()); |
| 346 } |
| 350 } | 347 } |
| 351 } else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) { | 348 } else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) { |
| 352 RefPtr<Image> img = m_imageResource->image(cWidth, cHeight); | 349 RefPtr<Image> img = m_imageResource->image(cWidth, cHeight); |
| 353 if (!img || img->isNull()) | 350 if (!img || img->isNull()) |
| 354 return; | 351 return; |
| 355 | 352 |
| 356 LayoutRect contentRect = contentBoxRect(); | 353 LayoutRect contentRect = contentBoxRect(); |
| 357 contentRect.moveBy(paintOffset); | 354 contentRect.moveBy(paintOffset); |
| 358 LayoutRect paintRect = replacedContentRect(); | 355 LayoutRect paintRect = replacedContentRect(); |
| 359 paintRect.moveBy(paintOffset); | 356 paintRect.moveBy(paintOffset); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 return 0; | 618 return 0; |
| 622 | 619 |
| 623 ImageResource* cachedImage = m_imageResource->cachedImage(); | 620 ImageResource* cachedImage = m_imageResource->cachedImage(); |
| 624 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage(
)) | 621 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage(
)) |
| 625 return toSVGImage(cachedImage->image())->embeddedContentBox(); | 622 return toSVGImage(cachedImage->image())->embeddedContentBox(); |
| 626 | 623 |
| 627 return 0; | 624 return 0; |
| 628 } | 625 } |
| 629 | 626 |
| 630 } // namespace WebCore | 627 } // namespace WebCore |
| OLD | NEW |