| 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 12 matching lines...) Expand all Loading... |
| 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 24 * Boston, MA 02110-1301, USA. | 24 * Boston, MA 02110-1301, USA. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/rendering/RenderImage.h" | 29 #include "core/rendering/RenderImage.h" |
| 30 | 30 |
| 31 #include "core/editing/FrameSelection.h" | 31 #include "core/editing/FrameSelection.h" |
| 32 #include "core/fetch/ImageResource.h" | 32 #include "core/fetch/ImageResource.h" |
| 33 #include "core/fetch/ResourceLoadPriorityOptimizer.h" | |
| 34 #include "core/fetch/ResourceLoader.h" | 33 #include "core/fetch/ResourceLoader.h" |
| 35 #include "core/frame/LocalFrame.h" | 34 #include "core/frame/LocalFrame.h" |
| 36 #include "core/html/HTMLImageElement.h" | 35 #include "core/html/HTMLImageElement.h" |
| 37 #include "core/inspector/InspectorTraceEvents.h" | 36 #include "core/inspector/InspectorTraceEvents.h" |
| 38 #include "core/rendering/HitTestResult.h" | 37 #include "core/rendering/HitTestResult.h" |
| 39 #include "core/rendering/PaintInfo.h" | 38 #include "core/rendering/PaintInfo.h" |
| 40 #include "core/rendering/RenderLayer.h" | 39 #include "core/rendering/RenderLayer.h" |
| 41 #include "core/rendering/RenderView.h" | 40 #include "core/rendering/RenderView.h" |
| 42 #include "core/rendering/TextRunConstructor.h" | 41 #include "core/rendering/TextRunConstructor.h" |
| 43 #include "platform/fonts/Font.h" | 42 #include "platform/fonts/Font.h" |
| 44 #include "platform/fonts/FontCache.h" | 43 #include "platform/fonts/FontCache.h" |
| 45 #include "platform/graphics/GraphicsContext.h" | 44 #include "platform/graphics/GraphicsContext.h" |
| 46 #include "platform/graphics/GraphicsContextStateSaver.h" | 45 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 47 | 46 |
| 48 namespace blink { | 47 namespace blink { |
| 49 | 48 |
| 50 float deviceScaleFactor(LocalFrame*); | 49 float deviceScaleFactor(LocalFrame*); |
| 51 | 50 |
| 52 RenderImage::RenderImage(Element* element) | 51 RenderImage::RenderImage(Element* element) |
| 53 : RenderReplaced(element, IntSize()) | 52 : RenderReplaced(element, IntSize()) |
| 54 , m_imageDevicePixelRatio(1.0f) | 53 , m_imageDevicePixelRatio(1.0f) |
| 55 { | 54 { |
| 56 updateAltText(); | 55 updateAltText(); |
| 57 ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->addRenderObj
ect(this); | |
| 58 } | 56 } |
| 59 | 57 |
| 60 RenderImage* RenderImage::createAnonymous(Document* document) | 58 RenderImage* RenderImage::createAnonymous(Document* document) |
| 61 { | 59 { |
| 62 RenderImage* image = new RenderImage(0); | 60 RenderImage* image = new RenderImage(0); |
| 63 image->setDocumentForAnonymous(document); | 61 image->setDocumentForAnonymous(document); |
| 64 return image; | 62 return image; |
| 65 } | 63 } |
| 66 | 64 |
| 67 RenderImage::~RenderImage() | 65 RenderImage::~RenderImage() |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 void RenderImage::layout() | 462 void RenderImage::layout() |
| 465 { | 463 { |
| 466 LayoutRect oldContentRect = replacedContentRect(); | 464 LayoutRect oldContentRect = replacedContentRect(); |
| 467 RenderReplaced::layout(); | 465 RenderReplaced::layout(); |
| 468 if (replacedContentRect() != oldContentRect) { | 466 if (replacedContentRect() != oldContentRect) { |
| 469 setShouldDoFullPaintInvalidation(true); | 467 setShouldDoFullPaintInvalidation(true); |
| 470 updateInnerContentRect(); | 468 updateInnerContentRect(); |
| 471 } | 469 } |
| 472 } | 470 } |
| 473 | 471 |
| 474 bool RenderImage::updateImageLoadingPriorities() | |
| 475 { | |
| 476 if (!m_imageResource || !m_imageResource->cachedImage() || m_imageResource->
cachedImage()->isLoaded()) | |
| 477 return false; | |
| 478 | |
| 479 LayoutRect viewBounds = viewRect(); | |
| 480 LayoutRect objectBounds = absoluteContentBox(); | |
| 481 | |
| 482 // The object bounds might be empty right now, so intersects will fail since
it doesn't deal | |
| 483 // with empty rects. Use LayoutRect::contains in that case. | |
| 484 bool isVisible; | |
| 485 if (!objectBounds.isEmpty()) | |
| 486 isVisible = viewBounds.intersects(objectBounds); | |
| 487 else | |
| 488 isVisible = viewBounds.contains(objectBounds); | |
| 489 | |
| 490 ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ? | |
| 491 ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer::
NotVisible; | |
| 492 | |
| 493 LayoutRect screenArea; | |
| 494 if (!objectBounds.isEmpty()) { | |
| 495 screenArea = viewBounds; | |
| 496 screenArea.intersect(objectBounds); | |
| 497 } | |
| 498 | |
| 499 ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->notifyImageR
esourceVisibility(m_imageResource->cachedImage(), status, screenArea); | |
| 500 | |
| 501 return true; | |
| 502 } | |
| 503 | |
| 504 void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, dou
ble& intrinsicRatio) const | 472 void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, dou
ble& intrinsicRatio) const |
| 505 { | 473 { |
| 506 RenderReplaced::computeIntrinsicRatioInformation(intrinsicSize, intrinsicRat
io); | 474 RenderReplaced::computeIntrinsicRatioInformation(intrinsicSize, intrinsicRat
io); |
| 507 | 475 |
| 508 // Our intrinsicSize is empty if we're rendering generated images with relat
ive width/height. Figure out the right intrinsic size to use. | 476 // Our intrinsicSize is empty if we're rendering generated images with relat
ive width/height. Figure out the right intrinsic size to use. |
| 509 if (intrinsicSize.isEmpty() && (m_imageResource->imageHasRelativeWidth() ||
m_imageResource->imageHasRelativeHeight())) { | 477 if (intrinsicSize.isEmpty() && (m_imageResource->imageHasRelativeWidth() ||
m_imageResource->imageHasRelativeHeight())) { |
| 510 RenderObject* containingBlock = isOutOfFlowPositioned() ? container() :
this->containingBlock(); | 478 RenderObject* containingBlock = isOutOfFlowPositioned() ? container() :
this->containingBlock(); |
| 511 if (containingBlock->isBox()) { | 479 if (containingBlock->isBox()) { |
| 512 RenderBox* box = toRenderBox(containingBlock); | 480 RenderBox* box = toRenderBox(containingBlock); |
| 513 intrinsicSize.setWidth(box->availableLogicalWidth().toFloat()); | 481 intrinsicSize.setWidth(box->availableLogicalWidth().toFloat()); |
| 514 intrinsicSize.setHeight(box->availableLogicalHeight(IncludeMarginBor
derPadding).toFloat()); | 482 intrinsicSize.setHeight(box->availableLogicalHeight(IncludeMarginBor
derPadding).toFloat()); |
| 515 } | 483 } |
| 516 } | 484 } |
| 517 // Don't compute an intrinsic ratio to preserve historical WebKit behavior i
f we're painting alt text and/or a broken image. | 485 // Don't compute an intrinsic ratio to preserve historical WebKit behavior i
f we're painting alt text and/or a broken image. |
| 518 // Video is excluded from this behavior because video elements have a defaul
t aspect ratio that a failed poster image load should not override. | 486 // Video is excluded from this behavior because video elements have a defaul
t aspect ratio that a failed poster image load should not override. |
| 519 if (m_imageResource && m_imageResource->errorOccurred()) { | 487 if (m_imageResource && m_imageResource->errorOccurred()) { |
| 520 intrinsicRatio = 1; | 488 intrinsicRatio = 1; |
| 521 return; | 489 return; |
| 522 } | 490 } |
| 523 } | 491 } |
| 524 | 492 |
| 525 bool RenderImage::needsPreferredWidthsRecalculation() const | 493 bool RenderImage::needsPreferredWidthsRecalculation() const |
| 526 { | 494 { |
| 527 return RenderReplaced::needsPreferredWidthsRecalculation(); | 495 return RenderReplaced::needsPreferredWidthsRecalculation(); |
| 528 } | 496 } |
| 529 | 497 |
| 530 } // namespace blink | 498 } // namespace blink |
| OLD | NEW |