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

Side by Side Diff: Source/core/rendering/RenderImage.cpp

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed build on win and mac Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 LayoutUnit centerY = (usableHeight - imageSize.height()) / 2; 327 LayoutUnit centerY = (usableHeight - imageSize.height()) / 2;
328 if (centerY < 0) 328 if (centerY < 0)
329 centerY = 0; 329 centerY = 0;
330 imageOffset = LayoutSize(leftBorder + leftPad + centerX + border Width, topBorder + topPad + centerY + borderWidth); 330 imageOffset = LayoutSize(leftBorder + leftPad + centerX + border Width, topBorder + topPad + centerY + borderWidth);
331 context->drawImage(image.get(), style()->colorSpace(), pixelSnap pedIntRect(LayoutRect(paintOffset + imageOffset, imageSize)), CompositeSourceOve r, shouldRespectImageOrientation()); 331 context->drawImage(image.get(), style()->colorSpace(), pixelSnap pedIntRect(LayoutRect(paintOffset + imageOffset, imageSize)), CompositeSourceOve r, shouldRespectImageOrientation());
332 errorPictureDrawn = true; 332 errorPictureDrawn = true;
333 } 333 }
334 334
335 if (!m_altText.isEmpty()) { 335 if (!m_altText.isEmpty()) {
336 String text = document()->displayStringModifiedByEncoding(m_altT ext); 336 String text = document()->displayStringModifiedByEncoding(m_altT ext);
337 context->setFillColor(style()->visitedDependentColor(CSSProperty Color), style()->colorSpace());
338 const Font& font = style()->font(); 337 const Font& font = style()->font();
339 const FontMetrics& fontMetrics = font.fontMetrics(); 338 const FontMetrics& fontMetrics = font.fontMetrics();
340 LayoutUnit ascent = fontMetrics.ascent(); 339 LayoutUnit ascent = fontMetrics.ascent();
341 LayoutPoint altTextOffset = paintOffset; 340 LayoutPoint textRectOrigin = paintOffset;
342 altTextOffset.move(leftBorder + leftPad + (paddingWidth / 2) - b orderWidth, topBorder + topPad + ascent + (paddingHeight / 2) - borderWidth); 341 textRectOrigin.move(leftBorder + leftPad + (paddingWidth / 2) - borderWidth, topBorder + topPad + (paddingHeight / 2) - borderWidth);
342 LayoutPoint textOrigin(textRectOrigin.x(), textRectOrigin.y() + ascent);
343 343
344 // Only draw the alt text if it'll fit within the content box, 344 // Only draw the alt text if it'll fit within the content box,
345 // and only if it fits above the error image. 345 // and only if it fits above the error image.
346 TextRun textRun = RenderBlock::constructTextRun(this, font, text , style()); 346 TextRun textRun = RenderBlock::constructTextRun(this, font, text , style());
347 LayoutUnit textWidth = font.width(textRun); 347 LayoutUnit textWidth = font.width(textRun);
348 TextRunPaintInfo textRunPaintInfo(textRun);
349 textRunPaintInfo.bounds = FloatRect(textRectOrigin, FloatSize(te xtWidth, fontMetrics.height()));
350 context->setFillColor(style()->visitedDependentColor(CSSProperty Color), style()->colorSpace());
348 if (errorPictureDrawn) { 351 if (errorPictureDrawn) {
349 if (usableWidth >= textWidth && fontMetrics.height() <= imag eOffset.height()) 352 if (usableWidth >= textWidth && fontMetrics.height() <= imag eOffset.height())
350 context->drawText(font, textRun, altTextOffset); 353 context->drawText(font, textRunPaintInfo, textOrigin);
351 } else if (usableWidth >= textWidth && usableHeight >= fontMetri cs.height()) 354 } else if (usableWidth >= textWidth && usableHeight >= fontMetri cs.height())
352 context->drawText(font, textRun, altTextOffset); 355 context->drawText(font, textRunPaintInfo, textOrigin);
353 } 356 }
354 } 357 }
355 } else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) { 358 } else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) {
356 RefPtr<Image> img = m_imageResource->image(cWidth, cHeight); 359 RefPtr<Image> img = m_imageResource->image(cWidth, cHeight);
357 if (!img || img->isNull()) { 360 if (!img || img->isNull()) {
358 if (page && paintInfo.phase == PaintPhaseForeground) 361 if (page && paintInfo.phase == PaintPhaseForeground)
359 page->addRelevantUnpaintedObject(this, visualOverflowRect()); 362 page->addRelevantUnpaintedObject(this, visualOverflowRect());
360 return; 363 return;
361 } 364 }
362 365
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 #if ENABLE(SVG) 578 #if ENABLE(SVG)
576 CachedImage* cachedImage = m_imageResource->cachedImage(); 579 CachedImage* cachedImage = m_imageResource->cachedImage();
577 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage( )) 580 if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage( ))
578 return static_cast<SVGImage*>(cachedImage->image())->embeddedContentBox( ); 581 return static_cast<SVGImage*>(cachedImage->image())->embeddedContentBox( );
579 #endif 582 #endif
580 583
581 return 0; 584 return 0;
582 } 585 }
583 586
584 } // namespace WebCore 587 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderFileUploadControl.cpp ('k') | Source/core/rendering/RenderListBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698