| 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 15 matching lines...) Expand all Loading... |
| 26 #include "bindings/core/v8/ScriptEventListener.h" | 26 #include "bindings/core/v8/ScriptEventListener.h" |
| 27 #include "core/CSSPropertyNames.h" | 27 #include "core/CSSPropertyNames.h" |
| 28 #include "core/HTMLNames.h" | 28 #include "core/HTMLNames.h" |
| 29 #include "core/MediaTypeNames.h" | 29 #include "core/MediaTypeNames.h" |
| 30 #include "core/css/MediaQueryMatcher.h" | 30 #include "core/css/MediaQueryMatcher.h" |
| 31 #include "core/css/MediaValuesDynamic.h" | 31 #include "core/css/MediaValuesDynamic.h" |
| 32 #include "core/css/parser/SizesAttributeParser.h" | 32 #include "core/css/parser/SizesAttributeParser.h" |
| 33 #include "core/dom/Attribute.h" | 33 #include "core/dom/Attribute.h" |
| 34 #include "core/dom/NodeTraversal.h" | 34 #include "core/dom/NodeTraversal.h" |
| 35 #include "core/dom/shadow/ShadowRoot.h" | 35 #include "core/dom/shadow/ShadowRoot.h" |
| 36 #include "core/fetch/ImageResource.h" | 36 #include "core/fetch/ImageResourceContent.h" |
| 37 #include "core/frame/Deprecation.h" | 37 #include "core/frame/Deprecation.h" |
| 38 #include "core/frame/ImageBitmap.h" | 38 #include "core/frame/ImageBitmap.h" |
| 39 #include "core/frame/LocalDOMWindow.h" | 39 #include "core/frame/LocalDOMWindow.h" |
| 40 #include "core/html/HTMLAnchorElement.h" | 40 #include "core/html/HTMLAnchorElement.h" |
| 41 #include "core/html/HTMLCanvasElement.h" | 41 #include "core/html/HTMLCanvasElement.h" |
| 42 #include "core/html/HTMLFormElement.h" | 42 #include "core/html/HTMLFormElement.h" |
| 43 #include "core/html/HTMLImageFallbackHelper.h" | 43 #include "core/html/HTMLImageFallbackHelper.h" |
| 44 #include "core/html/HTMLPictureElement.h" | 44 #include "core/html/HTMLPictureElement.h" |
| 45 #include "core/html/HTMLSourceElement.h" | 45 #include "core/html/HTMLSourceElement.h" |
| 46 #include "core/html/parser/HTMLParserIdioms.h" | 46 #include "core/html/parser/HTMLParserIdioms.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 void HTMLImageElement::attachLayoutTree(const AttachContext& context) { | 361 void HTMLImageElement::attachLayoutTree(const AttachContext& context) { |
| 362 HTMLElement::attachLayoutTree(context); | 362 HTMLElement::attachLayoutTree(context); |
| 363 | 363 |
| 364 if (layoutObject() && layoutObject()->isImage()) { | 364 if (layoutObject() && layoutObject()->isImage()) { |
| 365 LayoutImage* layoutImage = toLayoutImage(layoutObject()); | 365 LayoutImage* layoutImage = toLayoutImage(layoutObject()); |
| 366 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); | 366 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); |
| 367 if (m_isFallbackImage) { | 367 if (m_isFallbackImage) { |
| 368 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->frame()); | 368 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->frame()); |
| 369 std::pair<Image*, float> brokenImageAndImageScaleFactor = | 369 std::pair<Image*, float> brokenImageAndImageScaleFactor = |
| 370 ImageResource::brokenImage(deviceScaleFactor); | 370 ImageResourceContent::brokenImage(deviceScaleFactor); |
| 371 ImageResource* newImageResource = | 371 ImageResourceContent* newImageResource = |
| 372 ImageResource::create(brokenImageAndImageScaleFactor.first); | 372 ImageResourceContent::create(brokenImageAndImageScaleFactor.first); |
| 373 layoutImage->imageResource()->setImageResource(newImageResource); | 373 layoutImage->imageResource()->setImageResource(newImageResource); |
| 374 } | 374 } |
| 375 if (layoutImageResource->hasImage()) | 375 if (layoutImageResource->hasImage()) |
| 376 return; | 376 return; |
| 377 | 377 |
| 378 if (!imageLoader().image() && !layoutImageResource->cachedImage()) | 378 if (!imageLoader().image() && !layoutImageResource->cachedImage()) |
| 379 return; | 379 return; |
| 380 layoutImageResource->setImageResource(imageLoader().image()); | 380 layoutImageResource->setImageResource(imageLoader().image()); |
| 381 } | 381 } |
| 382 } | 382 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 } | 481 } |
| 482 | 482 |
| 483 unsigned HTMLImageElement::naturalWidth() const { | 483 unsigned HTMLImageElement::naturalWidth() const { |
| 484 if (!imageLoader().image()) | 484 if (!imageLoader().image()) |
| 485 return 0; | 485 return 0; |
| 486 | 486 |
| 487 return imageLoader() | 487 return imageLoader() |
| 488 .image() | 488 .image() |
| 489 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), | 489 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), |
| 490 m_imageDevicePixelRatio, | 490 m_imageDevicePixelRatio, |
| 491 ImageResource::IntrinsicCorrectedToDPR) | 491 ImageResourceContent::IntrinsicCorrectedToDPR) |
| 492 .width() | 492 .width() |
| 493 .toUnsigned(); | 493 .toUnsigned(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 unsigned HTMLImageElement::naturalHeight() const { | 496 unsigned HTMLImageElement::naturalHeight() const { |
| 497 if (!imageLoader().image()) | 497 if (!imageLoader().image()) |
| 498 return 0; | 498 return 0; |
| 499 | 499 |
| 500 return imageLoader() | 500 return imageLoader() |
| 501 .image() | 501 .image() |
| 502 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), | 502 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), |
| 503 m_imageDevicePixelRatio, | 503 m_imageDevicePixelRatio, |
| 504 ImageResource::IntrinsicCorrectedToDPR) | 504 ImageResourceContent::IntrinsicCorrectedToDPR) |
| 505 .height() | 505 .height() |
| 506 .toUnsigned(); | 506 .toUnsigned(); |
| 507 } | 507 } |
| 508 | 508 |
| 509 const String& HTMLImageElement::currentSrc() const { | 509 const String& HTMLImageElement::currentSrc() const { |
| 510 // 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 |
| 511 // The currentSrc IDL attribute must return the img element's current | 511 // The currentSrc IDL attribute must return the img element's current |
| 512 // request's current URL. | 512 // request's current URL. |
| 513 | 513 |
| 514 // Return the picked URL string in case of load error. | 514 // Return the picked URL string in case of load error. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 *status = NormalSourceImageStatus; | 648 *status = NormalSourceImageStatus; |
| 649 return sourceImage->imageForDefaultFrame(); | 649 return sourceImage->imageForDefaultFrame(); |
| 650 } | 650 } |
| 651 | 651 |
| 652 bool HTMLImageElement::isSVGSource() const { | 652 bool HTMLImageElement::isSVGSource() const { |
| 653 return cachedImage() && cachedImage()->getImage()->isSVGImage(); | 653 return cachedImage() && cachedImage()->getImage()->isSVGImage(); |
| 654 } | 654 } |
| 655 | 655 |
| 656 bool HTMLImageElement::wouldTaintOrigin( | 656 bool HTMLImageElement::wouldTaintOrigin( |
| 657 SecurityOrigin* destinationSecurityOrigin) const { | 657 SecurityOrigin* destinationSecurityOrigin) const { |
| 658 ImageResource* image = cachedImage(); | 658 ImageResourceContent* image = cachedImage(); |
| 659 if (!image) | 659 if (!image) |
| 660 return false; | 660 return false; |
| 661 return !image->isAccessAllowed(destinationSecurityOrigin); | 661 return !image->isAccessAllowed(destinationSecurityOrigin); |
| 662 } | 662 } |
| 663 | 663 |
| 664 FloatSize HTMLImageElement::elementSize( | 664 FloatSize HTMLImageElement::elementSize( |
| 665 const FloatSize& defaultObjectSize) const { | 665 const FloatSize& defaultObjectSize) const { |
| 666 ImageResource* image = cachedImage(); | 666 ImageResourceContent* image = cachedImage(); |
| 667 if (!image) | 667 if (!image) |
| 668 return FloatSize(); | 668 return FloatSize(); |
| 669 | 669 |
| 670 if (image->getImage() && image->getImage()->isSVGImage()) | 670 if (image->getImage() && image->getImage()->isSVGImage()) |
| 671 return toSVGImage(cachedImage()->getImage()) | 671 return toSVGImage(cachedImage()->getImage()) |
| 672 ->concreteObjectSize(defaultObjectSize); | 672 ->concreteObjectSize(defaultObjectSize); |
| 673 | 673 |
| 674 return FloatSize(image->imageSize( | 674 return FloatSize(image->imageSize( |
| 675 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f)); | 675 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f)); |
| 676 } | 676 } |
| 677 | 677 |
| 678 FloatSize HTMLImageElement::defaultDestinationSize( | 678 FloatSize HTMLImageElement::defaultDestinationSize( |
| 679 const FloatSize& defaultObjectSize) const { | 679 const FloatSize& defaultObjectSize) const { |
| 680 ImageResource* image = cachedImage(); | 680 ImageResourceContent* image = cachedImage(); |
| 681 if (!image) | 681 if (!image) |
| 682 return FloatSize(); | 682 return FloatSize(); |
| 683 | 683 |
| 684 if (image->getImage() && image->getImage()->isSVGImage()) | 684 if (image->getImage() && image->getImage()->isSVGImage()) |
| 685 return toSVGImage(cachedImage()->getImage()) | 685 return toSVGImage(cachedImage()->getImage()) |
| 686 ->concreteObjectSize(defaultObjectSize); | 686 ->concreteObjectSize(defaultObjectSize); |
| 687 | 687 |
| 688 LayoutSize size; | 688 LayoutSize size; |
| 689 size = image->imageSize( | 689 size = image->imageSize( |
| 690 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); | 690 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 !imageHasLoaded && imageLoader().hasPendingActivity() && | 781 !imageHasLoaded && imageLoader().hasPendingActivity() && |
| 782 !imageLoader().hasPendingError() && !imageSourceURL().isEmpty(); | 782 !imageLoader().hasPendingError() && !imageSourceURL().isEmpty(); |
| 783 bool imageHasImage = | 783 bool imageHasImage = |
| 784 imageLoader().image() && imageLoader().image()->hasImage(); | 784 imageLoader().image() && imageLoader().image()->hasImage(); |
| 785 bool imageIsDocument = imageLoader().isLoadingImageDocument() && | 785 bool imageIsDocument = imageLoader().isLoadingImageDocument() && |
| 786 imageLoader().image() && | 786 imageLoader().image() && |
| 787 !imageLoader().image()->errorOccurred(); | 787 !imageLoader().image()->errorOccurred(); |
| 788 | 788 |
| 789 // Icky special case for deferred images: | 789 // Icky special case for deferred images: |
| 790 // A deferred image is not loading, does have pending activity, does not | 790 // A deferred image is not loading, does have pending activity, does not |
| 791 // have an error, but it does have an ImageResource associated | 791 // have an error, but it does have an ImageResourceContent associated |
| 792 // with it, so imageHasLoaded will be true even though the image hasn't | 792 // with it, so imageHasLoaded will be true even though the image hasn't |
| 793 // actually loaded. Fixing the definition of imageHasLoaded isn't | 793 // actually loaded. Fixing the definition of imageHasLoaded isn't |
| 794 // sufficient, because a deferred image does have pending activity, does not | 794 // sufficient, because a deferred image does have pending activity, does not |
| 795 // have a pending error, and does have a source URL, so if imageHasLoaded | 795 // have a pending error, and does have a source URL, so if imageHasLoaded |
| 796 // was correct, imageStillLoading would become wrong. | 796 // was correct, imageStillLoading would become wrong. |
| 797 // | 797 // |
| 798 // Instead of dealing with that, there's a separate check that the | 798 // Instead of dealing with that, there's a separate check that the |
| 799 // ImageResource has non-null image data associated with it, which isn't | 799 // ImageResourceContent has non-null image data associated with it, which |
| 800 // folded into imageHasLoaded above. | 800 // isn't folded into imageHasLoaded above. |
| 801 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument) | 801 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument) |
| 802 ensurePrimaryContent(); | 802 ensurePrimaryContent(); |
| 803 else | 803 else |
| 804 ensureFallbackContent(); | 804 ensureFallbackContent(); |
| 805 } | 805 } |
| 806 | 806 |
| 807 const KURL& HTMLImageElement::sourceURL() const { | 807 const KURL& HTMLImageElement::sourceURL() const { |
| 808 return cachedImage()->response().url(); | 808 return cachedImage()->response().url(); |
| 809 } | 809 } |
| 810 | 810 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 int HTMLImageElement::sourceHeight() { | 875 int HTMLImageElement::sourceHeight() { |
| 876 SourceImageStatus status; | 876 SourceImageStatus status; |
| 877 FloatSize defaultObjectSize(width(), height()); | 877 FloatSize defaultObjectSize(width(), height()); |
| 878 RefPtr<Image> image = getSourceImageForCanvas( | 878 RefPtr<Image> image = getSourceImageForCanvas( |
| 879 &status, PreferNoAcceleration, SnapshotReasonCopyToWebGLTexture, | 879 &status, PreferNoAcceleration, SnapshotReasonCopyToWebGLTexture, |
| 880 defaultObjectSize); | 880 defaultObjectSize); |
| 881 return image->height(); | 881 return image->height(); |
| 882 } | 882 } |
| 883 | 883 |
| 884 IntSize HTMLImageElement::bitmapSourceSize() const { | 884 IntSize HTMLImageElement::bitmapSourceSize() const { |
| 885 ImageResource* image = cachedImage(); | 885 ImageResourceContent* image = cachedImage(); |
| 886 if (!image) | 886 if (!image) |
| 887 return IntSize(); | 887 return IntSize(); |
| 888 LayoutSize lSize = image->imageSize( | 888 LayoutSize lSize = image->imageSize( |
| 889 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); | 889 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); |
| 890 DCHECK(lSize.fraction().isZero()); | 890 DCHECK(lSize.fraction().isZero()); |
| 891 return IntSize(lSize.width().toInt(), lSize.height().toInt()); | 891 return IntSize(lSize.width().toInt(), lSize.height().toInt()); |
| 892 } | 892 } |
| 893 | 893 |
| 894 } // namespace blink | 894 } // namespace blink |
| OLD | NEW |