| 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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights |
| 5 * reserved. | 5 * reserved. |
| 6 * Copyright (C) 2010 Google Inc. All rights reserved. | 6 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 if (!imageLoader().imageComplete()) | 622 if (!imageLoader().imageComplete()) |
| 623 return nullptr; | 623 return nullptr; |
| 624 | 624 |
| 625 return imageLoader().image()->getImage(); | 625 return imageLoader().image()->getImage(); |
| 626 } | 626 } |
| 627 | 627 |
| 628 bool HTMLImageElement::isInteractiveContent() const { | 628 bool HTMLImageElement::isInteractiveContent() const { |
| 629 return fastHasAttribute(usemapAttr); | 629 return fastHasAttribute(usemapAttr); |
| 630 } | 630 } |
| 631 | 631 |
| 632 PassRefPtr<Image> HTMLImageElement::getSourceImageForCanvas( | |
| 633 SourceImageStatus* status, | |
| 634 AccelerationHint, | |
| 635 SnapshotReason, | |
| 636 const FloatSize& defaultObjectSize) const { | |
| 637 if (!complete() || !cachedImage()) { | |
| 638 *status = IncompleteSourceImageStatus; | |
| 639 return nullptr; | |
| 640 } | |
| 641 | |
| 642 if (cachedImage()->errorOccurred()) { | |
| 643 *status = UndecodableSourceImageStatus; | |
| 644 return nullptr; | |
| 645 } | |
| 646 | |
| 647 RefPtr<Image> sourceImage; | |
| 648 if (cachedImage()->getImage()->isSVGImage()) { | |
| 649 UseCounter::count(document(), UseCounter::SVGInCanvas2D); | |
| 650 SVGImage* svgImage = toSVGImage(cachedImage()->getImage()); | |
| 651 IntSize imageSize = | |
| 652 roundedIntSize(svgImage->concreteObjectSize(defaultObjectSize)); | |
| 653 sourceImage = SVGImageForContainer::create( | |
| 654 svgImage, imageSize, 1, document().completeURL(imageSourceURL())); | |
| 655 } else { | |
| 656 sourceImage = cachedImage()->getImage(); | |
| 657 } | |
| 658 | |
| 659 *status = NormalSourceImageStatus; | |
| 660 return sourceImage->imageForDefaultFrame(); | |
| 661 } | |
| 662 | |
| 663 bool HTMLImageElement::isSVGSource() const { | |
| 664 return cachedImage() && cachedImage()->getImage()->isSVGImage(); | |
| 665 } | |
| 666 | |
| 667 bool HTMLImageElement::wouldTaintOrigin( | |
| 668 SecurityOrigin* destinationSecurityOrigin) const { | |
| 669 ImageResourceContent* image = cachedImage(); | |
| 670 if (!image) | |
| 671 return false; | |
| 672 return !image->isAccessAllowed(destinationSecurityOrigin); | |
| 673 } | |
| 674 | |
| 675 FloatSize HTMLImageElement::elementSize( | |
| 676 const FloatSize& defaultObjectSize) const { | |
| 677 ImageResourceContent* image = cachedImage(); | |
| 678 if (!image) | |
| 679 return FloatSize(); | |
| 680 | |
| 681 if (image->getImage() && image->getImage()->isSVGImage()) | |
| 682 return toSVGImage(cachedImage()->getImage()) | |
| 683 ->concreteObjectSize(defaultObjectSize); | |
| 684 | |
| 685 return FloatSize(image->imageSize( | |
| 686 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f)); | |
| 687 } | |
| 688 | |
| 689 FloatSize HTMLImageElement::defaultDestinationSize( | 632 FloatSize HTMLImageElement::defaultDestinationSize( |
| 690 const FloatSize& defaultObjectSize) const { | 633 const FloatSize& defaultObjectSize) const { |
| 691 ImageResourceContent* image = cachedImage(); | 634 ImageResourceContent* image = cachedImage(); |
| 692 if (!image) | 635 if (!image) |
| 693 return FloatSize(); | 636 return FloatSize(); |
| 694 | 637 |
| 695 if (image->getImage() && image->getImage()->isSVGImage()) | 638 if (image->getImage() && image->getImage()->isSVGImage()) |
| 696 return toSVGImage(cachedImage()->getImage()) | 639 return toSVGImage(cachedImage()->getImage()) |
| 697 ->concreteObjectSize(defaultObjectSize); | 640 ->concreteObjectSize(defaultObjectSize); |
| 698 | 641 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 // | 752 // |
| 810 // Instead of dealing with that, there's a separate check that the | 753 // Instead of dealing with that, there's a separate check that the |
| 811 // ImageResourceContent has non-null image data associated with it, which | 754 // ImageResourceContent has non-null image data associated with it, which |
| 812 // isn't folded into imageHasLoaded above. | 755 // isn't folded into imageHasLoaded above. |
| 813 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument) | 756 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument) |
| 814 ensurePrimaryContent(); | 757 ensurePrimaryContent(); |
| 815 else | 758 else |
| 816 ensureCollapsedOrFallbackContent(); | 759 ensureCollapsedOrFallbackContent(); |
| 817 } | 760 } |
| 818 | 761 |
| 819 const KURL& HTMLImageElement::sourceURL() const { | |
| 820 return cachedImage()->response().url(); | |
| 821 } | |
| 822 | |
| 823 void HTMLImageElement::didAddUserAgentShadowRoot(ShadowRoot&) { | 762 void HTMLImageElement::didAddUserAgentShadowRoot(ShadowRoot&) { |
| 824 HTMLImageFallbackHelper::createAltTextShadowTree(*this); | 763 HTMLImageFallbackHelper::createAltTextShadowTree(*this); |
| 825 } | 764 } |
| 826 | 765 |
| 827 void HTMLImageElement::ensureFallbackForGeneratedContent() { | 766 void HTMLImageElement::ensureFallbackForGeneratedContent() { |
| 828 // The special casing for generated content in createLayoutObject breaks the | 767 // The special casing for generated content in createLayoutObject breaks the |
| 829 // invariant that the layout object attached to this element will always be | 768 // invariant that the layout object attached to this element will always be |
| 830 // appropriate for |m_layoutDisposition|. Force recreate it. | 769 // appropriate for |m_layoutDisposition|. Force recreate it. |
| 831 // TODO(engedy): Remove this hack. See: https://crbug.com/671953. | 770 // TODO(engedy): Remove this hack. See: https://crbug.com/671953. |
| 832 setLayoutDisposition(LayoutDisposition::FallbackContent, | 771 setLayoutDisposition(LayoutDisposition::FallbackContent, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 return originalStyleForLayoutObject(); | 819 return originalStyleForLayoutObject(); |
| 881 case LayoutDisposition::FallbackContent: | 820 case LayoutDisposition::FallbackContent: |
| 882 return HTMLImageFallbackHelper::customStyleForAltText( | 821 return HTMLImageFallbackHelper::customStyleForAltText( |
| 883 *this, ComputedStyle::clone(*originalStyleForLayoutObject())); | 822 *this, ComputedStyle::clone(*originalStyleForLayoutObject())); |
| 884 default: | 823 default: |
| 885 NOTREACHED(); | 824 NOTREACHED(); |
| 886 return nullptr; | 825 return nullptr; |
| 887 } | 826 } |
| 888 } | 827 } |
| 889 | 828 |
| 890 bool HTMLImageElement::isOpaque() const { | |
| 891 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); | |
| 892 return image && image->currentFrameKnownToBeOpaque(); | |
| 893 } | |
| 894 | |
| 895 int HTMLImageElement::sourceWidth() { | |
| 896 SourceImageStatus status; | |
| 897 FloatSize defaultObjectSize(width(), height()); | |
| 898 RefPtr<Image> image = getSourceImageForCanvas( | |
| 899 &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); | |
| 900 return image->width(); | |
| 901 } | |
| 902 | |
| 903 int HTMLImageElement::sourceHeight() { | |
| 904 SourceImageStatus status; | |
| 905 FloatSize defaultObjectSize(width(), height()); | |
| 906 RefPtr<Image> image = getSourceImageForCanvas( | |
| 907 &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); | |
| 908 return image->height(); | |
| 909 } | |
| 910 | |
| 911 IntSize HTMLImageElement::bitmapSourceSize() const { | 829 IntSize HTMLImageElement::bitmapSourceSize() const { |
| 912 ImageResourceContent* image = cachedImage(); | 830 ImageResourceContent* image = cachedImage(); |
| 913 if (!image) | 831 if (!image) |
| 914 return IntSize(); | 832 return IntSize(); |
| 915 LayoutSize lSize = image->imageSize( | 833 LayoutSize lSize = image->imageSize( |
| 916 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); | 834 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); |
| 917 DCHECK(lSize.fraction().isZero()); | 835 DCHECK(lSize.fraction().isZero()); |
| 918 return IntSize(lSize.width().toInt(), lSize.height().toInt()); | 836 return IntSize(lSize.width().toInt(), lSize.height().toInt()); |
| 919 } | 837 } |
| 920 | 838 |
| 921 void HTMLImageElement::associateWith(HTMLFormElement* form) { | 839 void HTMLImageElement::associateWith(HTMLFormElement* form) { |
| 922 if (form && form->isConnected()) { | 840 if (form && form->isConnected()) { |
| 923 m_form = form; | 841 m_form = form; |
| 924 m_formWasSetByParser = true; | 842 m_formWasSetByParser = true; |
| 925 m_form->associate(*this); | 843 m_form->associate(*this); |
| 926 m_form->didAssociateByParser(); | 844 m_form->didAssociateByParser(); |
| 927 } | 845 } |
| 928 }; | 846 }; |
| 929 | 847 |
| 848 FloatSize HTMLImageElement::sourceDefaultObjectSize() { |
| 849 return FloatSize(width(), height()); |
| 850 } |
| 851 |
| 930 } // namespace blink | 852 } // namespace blink |
| OLD | NEW |