| 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 reserv
ed. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights |
| 5 * reserved. |
| 5 * Copyright (C) 2010 Google Inc. All rights reserved. | 6 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 6 * | 7 * |
| 7 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
| 11 * | 12 * |
| 12 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 .image() | 501 .image() |
| 501 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), | 502 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), |
| 502 m_imageDevicePixelRatio, | 503 m_imageDevicePixelRatio, |
| 503 ImageResource::IntrinsicCorrectedToDPR) | 504 ImageResource::IntrinsicCorrectedToDPR) |
| 504 .height() | 505 .height() |
| 505 .toInt(); | 506 .toInt(); |
| 506 } | 507 } |
| 507 | 508 |
| 508 const String& HTMLImageElement::currentSrc() const { | 509 const String& HTMLImageElement::currentSrc() const { |
| 509 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#dom-
img-currentsrc | 510 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#dom-
img-currentsrc |
| 510 // The currentSrc IDL attribute must return the img element's current request'
s current URL. | 511 // The currentSrc IDL attribute must return the img element's current |
| 512 // request's current URL. |
| 511 | 513 |
| 512 // Return the picked URL string in case of load error. | 514 // Return the picked URL string in case of load error. |
| 513 if (imageLoader().hadError()) | 515 if (imageLoader().hadError()) |
| 514 return m_bestFitImageURL; | 516 return m_bestFitImageURL; |
| 515 // Initially, the pending request turns into current request when it is either
available or broken. | 517 // Initially, the pending request turns into current request when it is either |
| 516 // We use the image's dimensions as a proxy to it being in any of these states
. | 518 // available or broken. We use the image's dimensions as a proxy to it being |
| 519 // in any of these states. |
| 517 if (!imageLoader().image() || !imageLoader().image()->getImage() || | 520 if (!imageLoader().image() || !imageLoader().image()->getImage() || |
| 518 !imageLoader().image()->getImage()->width()) | 521 !imageLoader().image()->getImage()->width()) |
| 519 return emptyAtom; | 522 return emptyAtom; |
| 520 | 523 |
| 521 return imageLoader().image()->url().getString(); | 524 return imageLoader().image()->url().getString(); |
| 522 } | 525 } |
| 523 | 526 |
| 524 bool HTMLImageElement::isURLAttribute(const Attribute& attribute) const { | 527 bool HTMLImageElement::isURLAttribute(const Attribute& attribute) const { |
| 525 return attribute.name() == srcAttr || attribute.name() == lowsrcAttr || | 528 return attribute.name() == srcAttr || attribute.name() == lowsrcAttr || |
| 526 attribute.name() == longdescAttr || | 529 attribute.name() == longdescAttr || |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 imageLoader().elementDidMoveToNewDocument(); | 591 imageLoader().elementDidMoveToNewDocument(); |
| 589 HTMLElement::didMoveToNewDocument(oldDocument); | 592 HTMLElement::didMoveToNewDocument(oldDocument); |
| 590 } | 593 } |
| 591 | 594 |
| 592 bool HTMLImageElement::isServerMap() const { | 595 bool HTMLImageElement::isServerMap() const { |
| 593 if (!fastHasAttribute(ismapAttr)) | 596 if (!fastHasAttribute(ismapAttr)) |
| 594 return false; | 597 return false; |
| 595 | 598 |
| 596 const AtomicString& usemap = fastGetAttribute(usemapAttr); | 599 const AtomicString& usemap = fastGetAttribute(usemapAttr); |
| 597 | 600 |
| 598 // If the usemap attribute starts with '#', it refers to a map element in the
document. | 601 // If the usemap attribute starts with '#', it refers to a map element in the |
| 602 // document. |
| 599 if (usemap[0] == '#') | 603 if (usemap[0] == '#') |
| 600 return false; | 604 return false; |
| 601 | 605 |
| 602 return document() | 606 return document() |
| 603 .completeURL(stripLeadingAndTrailingHTMLSpaces(usemap)) | 607 .completeURL(stripLeadingAndTrailingHTMLSpaces(usemap)) |
| 604 .isEmpty(); | 608 .isEmpty(); |
| 605 } | 609 } |
| 606 | 610 |
| 607 Image* HTMLImageElement::imageContents() { | 611 Image* HTMLImageElement::imageContents() { |
| 608 if (!imageLoader().imageComplete()) | 612 if (!imageLoader().imageComplete()) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 Element* element = m_source.get(); | 712 Element* element = m_source.get(); |
| 709 if (!element) | 713 if (!element) |
| 710 element = this; | 714 element = this; |
| 711 resourceWidth.isSet = | 715 resourceWidth.isSet = |
| 712 sourceSizeValue(*element, document(), resourceWidth.width); | 716 sourceSizeValue(*element, document(), resourceWidth.width); |
| 713 return resourceWidth; | 717 return resourceWidth; |
| 714 } | 718 } |
| 715 | 719 |
| 716 float HTMLImageElement::sourceSize(Element& element) { | 720 float HTMLImageElement::sourceSize(Element& element) { |
| 717 float value; | 721 float value; |
| 718 // We don't care here if the sizes attribute exists, so we ignore the return v
alue. | 722 // We don't care here if the sizes attribute exists, so we ignore the return |
| 719 // If it doesn't exist, we just return the default. | 723 // value. If it doesn't exist, we just return the default. |
| 720 sourceSizeValue(element, document(), value); | 724 sourceSizeValue(element, document(), value); |
| 721 return value; | 725 return value; |
| 722 } | 726 } |
| 723 | 727 |
| 724 void HTMLImageElement::forceReload() const { | 728 void HTMLImageElement::forceReload() const { |
| 725 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload, | 729 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload, |
| 726 m_referrerPolicy); | 730 m_referrerPolicy); |
| 727 } | 731 } |
| 728 | 732 |
| 729 ScriptPromise HTMLImageElement::createImageBitmap( | 733 ScriptPromise HTMLImageElement::createImageBitmap( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 } | 765 } |
| 762 | 766 |
| 763 if (!foundURL) { | 767 if (!foundURL) { |
| 764 candidate = bestFitSourceForImageAttributes( | 768 candidate = bestFitSourceForImageAttributes( |
| 765 document().devicePixelRatio(), sourceSize(*this), | 769 document().devicePixelRatio(), sourceSize(*this), |
| 766 fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), &document()); | 770 fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), &document()); |
| 767 setBestFitURLAndDPRFromImageCandidate(candidate); | 771 setBestFitURLAndDPRFromImageCandidate(candidate); |
| 768 } | 772 } |
| 769 imageLoader().updateFromElement(behavior, m_referrerPolicy); | 773 imageLoader().updateFromElement(behavior, m_referrerPolicy); |
| 770 | 774 |
| 771 // Images such as data: uri's can return immediately and may already have erro
red out. | 775 // Images such as data: uri's can return immediately and may already have |
| 776 // errored out. |
| 772 bool imageHasLoaded = imageLoader().image() && | 777 bool imageHasLoaded = imageLoader().image() && |
| 773 !imageLoader().image()->isLoading() && | 778 !imageLoader().image()->isLoading() && |
| 774 !imageLoader().image()->errorOccurred(); | 779 !imageLoader().image()->errorOccurred(); |
| 775 bool imageStillLoading = | 780 bool imageStillLoading = |
| 776 !imageHasLoaded && imageLoader().hasPendingActivity() && | 781 !imageHasLoaded && imageLoader().hasPendingActivity() && |
| 777 !imageLoader().hasPendingError() && !imageSourceURL().isEmpty(); | 782 !imageLoader().hasPendingError() && !imageSourceURL().isEmpty(); |
| 778 bool imageHasImage = | 783 bool imageHasImage = |
| 779 imageLoader().image() && imageLoader().image()->hasImage(); | 784 imageLoader().image() && imageLoader().image()->hasImage(); |
| 780 bool imageIsDocument = imageLoader().isLoadingImageDocument() && | 785 bool imageIsDocument = imageLoader().isLoadingImageDocument() && |
| 781 imageLoader().image() && | 786 imageLoader().image() && |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 } | 825 } |
| 821 | 826 |
| 822 void HTMLImageElement::ensurePrimaryContent() { | 827 void HTMLImageElement::ensurePrimaryContent() { |
| 823 if (!m_useFallbackContent) | 828 if (!m_useFallbackContent) |
| 824 return; | 829 return; |
| 825 m_useFallbackContent = false; | 830 m_useFallbackContent = false; |
| 826 reattachFallbackContent(); | 831 reattachFallbackContent(); |
| 827 } | 832 } |
| 828 | 833 |
| 829 void HTMLImageElement::reattachFallbackContent() { | 834 void HTMLImageElement::reattachFallbackContent() { |
| 830 // This can happen inside of attachLayoutTree() in the middle of a recalcStyle
so we need to | 835 // This can happen inside of attachLayoutTree() in the middle of a recalcStyle |
| 831 // reattach synchronously here. | 836 // so we need to reattach synchronously here. |
| 832 if (document().inStyleRecalc()) | 837 if (document().inStyleRecalc()) |
| 833 reattachLayoutTree(); | 838 reattachLayoutTree(); |
| 834 else | 839 else |
| 835 lazyReattachIfAttached(); | 840 lazyReattachIfAttached(); |
| 836 } | 841 } |
| 837 | 842 |
| 838 PassRefPtr<ComputedStyle> HTMLImageElement::customStyleForLayoutObject() { | 843 PassRefPtr<ComputedStyle> HTMLImageElement::customStyleForLayoutObject() { |
| 839 RefPtr<ComputedStyle> newStyle = originalStyleForLayoutObject(); | 844 RefPtr<ComputedStyle> newStyle = originalStyleForLayoutObject(); |
| 840 | 845 |
| 841 if (!m_useFallbackContent) | 846 if (!m_useFallbackContent) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 ImageResource* image = cachedImage(); | 885 ImageResource* image = cachedImage(); |
| 881 if (!image) | 886 if (!image) |
| 882 return IntSize(); | 887 return IntSize(); |
| 883 LayoutSize lSize = image->imageSize( | 888 LayoutSize lSize = image->imageSize( |
| 884 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); | 889 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); |
| 885 DCHECK(lSize.fraction().isZero()); | 890 DCHECK(lSize.fraction().isZero()); |
| 886 return IntSize(lSize.width().toInt(), lSize.height().toInt()); | 891 return IntSize(lSize.width().toInt(), lSize.height().toInt()); |
| 887 } | 892 } |
| 888 | 893 |
| 889 } // namespace blink | 894 } // namespace blink |
| OLD | NEW |