| 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/FormAssociated.h" | 40 #include "core/html/FormAssociated.h" |
| 41 #include "core/html/HTMLAnchorElement.h" | 41 #include "core/html/HTMLAnchorElement.h" |
| 42 #include "core/html/HTMLCanvasElement.h" | 42 #include "core/html/HTMLCanvasElement.h" |
| 43 #include "core/html/HTMLFormElement.h" | 43 #include "core/html/HTMLFormElement.h" |
| 44 #include "core/html/HTMLImageFallbackHelper.h" | 44 #include "core/html/HTMLImageFallbackHelper.h" |
| 45 #include "core/html/HTMLPictureElement.h" | 45 #include "core/html/HTMLPictureElement.h" |
| 46 #include "core/html/HTMLSourceElement.h" | 46 #include "core/html/HTMLSourceElement.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 | 365 |
| 366 void HTMLImageElement::attachLayoutTree(const AttachContext& context) { | 366 void HTMLImageElement::attachLayoutTree(const AttachContext& context) { |
| 367 HTMLElement::attachLayoutTree(context); | 367 HTMLElement::attachLayoutTree(context); |
| 368 | 368 |
| 369 if (layoutObject() && layoutObject()->isImage()) { | 369 if (layoutObject() && layoutObject()->isImage()) { |
| 370 LayoutImage* layoutImage = toLayoutImage(layoutObject()); | 370 LayoutImage* layoutImage = toLayoutImage(layoutObject()); |
| 371 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); | 371 LayoutImageResource* layoutImageResource = layoutImage->imageResource(); |
| 372 if (m_isFallbackImage) { | 372 if (m_isFallbackImage) { |
| 373 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->frame()); | 373 float deviceScaleFactor = blink::deviceScaleFactor(layoutImage->frame()); |
| 374 std::pair<Image*, float> brokenImageAndImageScaleFactor = | 374 std::pair<Image*, float> brokenImageAndImageScaleFactor = |
| 375 ImageResource::brokenImage(deviceScaleFactor); | 375 ImageResourceContent::brokenImage(deviceScaleFactor); |
| 376 ImageResource* newImageResource = | 376 ImageResourceContent* newImageResource = |
| 377 ImageResource::create(brokenImageAndImageScaleFactor.first); | 377 ImageResourceContent::create(brokenImageAndImageScaleFactor.first); |
| 378 layoutImage->imageResource()->setImageResource(newImageResource); | 378 layoutImage->imageResource()->setImageResource(newImageResource); |
| 379 } | 379 } |
| 380 if (layoutImageResource->hasImage()) | 380 if (layoutImageResource->hasImage()) |
| 381 return; | 381 return; |
| 382 | 382 |
| 383 if (!imageLoader().image() && !layoutImageResource->cachedImage()) | 383 if (!imageLoader().image() && !layoutImageResource->cachedImage()) |
| 384 return; | 384 return; |
| 385 layoutImageResource->setImageResource(imageLoader().image()); | 385 layoutImageResource->setImageResource(imageLoader().image()); |
| 386 } | 386 } |
| 387 } | 387 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 } | 486 } |
| 487 | 487 |
| 488 unsigned HTMLImageElement::naturalWidth() const { | 488 unsigned HTMLImageElement::naturalWidth() const { |
| 489 if (!imageLoader().image()) | 489 if (!imageLoader().image()) |
| 490 return 0; | 490 return 0; |
| 491 | 491 |
| 492 return imageLoader() | 492 return imageLoader() |
| 493 .image() | 493 .image() |
| 494 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), | 494 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), |
| 495 m_imageDevicePixelRatio, | 495 m_imageDevicePixelRatio, |
| 496 ImageResource::IntrinsicCorrectedToDPR) | 496 ImageResourceContent::IntrinsicCorrectedToDPR) |
| 497 .width() | 497 .width() |
| 498 .toUnsigned(); | 498 .toUnsigned(); |
| 499 } | 499 } |
| 500 | 500 |
| 501 unsigned HTMLImageElement::naturalHeight() const { | 501 unsigned HTMLImageElement::naturalHeight() const { |
| 502 if (!imageLoader().image()) | 502 if (!imageLoader().image()) |
| 503 return 0; | 503 return 0; |
| 504 | 504 |
| 505 return imageLoader() | 505 return imageLoader() |
| 506 .image() | 506 .image() |
| 507 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), | 507 ->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), |
| 508 m_imageDevicePixelRatio, | 508 m_imageDevicePixelRatio, |
| 509 ImageResource::IntrinsicCorrectedToDPR) | 509 ImageResourceContent::IntrinsicCorrectedToDPR) |
| 510 .height() | 510 .height() |
| 511 .toUnsigned(); | 511 .toUnsigned(); |
| 512 } | 512 } |
| 513 | 513 |
| 514 const String& HTMLImageElement::currentSrc() const { | 514 const String& HTMLImageElement::currentSrc() const { |
| 515 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#dom-
img-currentsrc | 515 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#dom-
img-currentsrc |
| 516 // The currentSrc IDL attribute must return the img element's current | 516 // The currentSrc IDL attribute must return the img element's current |
| 517 // request's current URL. | 517 // request's current URL. |
| 518 | 518 |
| 519 // Return the picked URL string in case of load error. | 519 // Return the picked URL string in case of load error. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 *status = NormalSourceImageStatus; | 653 *status = NormalSourceImageStatus; |
| 654 return sourceImage->imageForDefaultFrame(); | 654 return sourceImage->imageForDefaultFrame(); |
| 655 } | 655 } |
| 656 | 656 |
| 657 bool HTMLImageElement::isSVGSource() const { | 657 bool HTMLImageElement::isSVGSource() const { |
| 658 return cachedImage() && cachedImage()->getImage()->isSVGImage(); | 658 return cachedImage() && cachedImage()->getImage()->isSVGImage(); |
| 659 } | 659 } |
| 660 | 660 |
| 661 bool HTMLImageElement::wouldTaintOrigin( | 661 bool HTMLImageElement::wouldTaintOrigin( |
| 662 SecurityOrigin* destinationSecurityOrigin) const { | 662 SecurityOrigin* destinationSecurityOrigin) const { |
| 663 ImageResource* image = cachedImage(); | 663 ImageResourceContent* image = cachedImage(); |
| 664 if (!image) | 664 if (!image) |
| 665 return false; | 665 return false; |
| 666 return !image->isAccessAllowed(destinationSecurityOrigin); | 666 return !image->isAccessAllowed(destinationSecurityOrigin); |
| 667 } | 667 } |
| 668 | 668 |
| 669 FloatSize HTMLImageElement::elementSize( | 669 FloatSize HTMLImageElement::elementSize( |
| 670 const FloatSize& defaultObjectSize) const { | 670 const FloatSize& defaultObjectSize) const { |
| 671 ImageResource* image = cachedImage(); | 671 ImageResourceContent* image = cachedImage(); |
| 672 if (!image) | 672 if (!image) |
| 673 return FloatSize(); | 673 return FloatSize(); |
| 674 | 674 |
| 675 if (image->getImage() && image->getImage()->isSVGImage()) | 675 if (image->getImage() && image->getImage()->isSVGImage()) |
| 676 return toSVGImage(cachedImage()->getImage()) | 676 return toSVGImage(cachedImage()->getImage()) |
| 677 ->concreteObjectSize(defaultObjectSize); | 677 ->concreteObjectSize(defaultObjectSize); |
| 678 | 678 |
| 679 return FloatSize(image->imageSize( | 679 return FloatSize(image->imageSize( |
| 680 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f)); | 680 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f)); |
| 681 } | 681 } |
| 682 | 682 |
| 683 FloatSize HTMLImageElement::defaultDestinationSize( | 683 FloatSize HTMLImageElement::defaultDestinationSize( |
| 684 const FloatSize& defaultObjectSize) const { | 684 const FloatSize& defaultObjectSize) const { |
| 685 ImageResource* image = cachedImage(); | 685 ImageResourceContent* image = cachedImage(); |
| 686 if (!image) | 686 if (!image) |
| 687 return FloatSize(); | 687 return FloatSize(); |
| 688 | 688 |
| 689 if (image->getImage() && image->getImage()->isSVGImage()) | 689 if (image->getImage() && image->getImage()->isSVGImage()) |
| 690 return toSVGImage(cachedImage()->getImage()) | 690 return toSVGImage(cachedImage()->getImage()) |
| 691 ->concreteObjectSize(defaultObjectSize); | 691 ->concreteObjectSize(defaultObjectSize); |
| 692 | 692 |
| 693 LayoutSize size; | 693 LayoutSize size; |
| 694 size = image->imageSize( | 694 size = image->imageSize( |
| 695 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); | 695 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 !imageHasLoaded && imageLoader().hasPendingActivity() && | 787 !imageHasLoaded && imageLoader().hasPendingActivity() && |
| 788 !imageLoader().hasPendingError() && !imageSourceURL().isEmpty(); | 788 !imageLoader().hasPendingError() && !imageSourceURL().isEmpty(); |
| 789 bool imageHasImage = | 789 bool imageHasImage = |
| 790 imageLoader().image() && imageLoader().image()->hasImage(); | 790 imageLoader().image() && imageLoader().image()->hasImage(); |
| 791 bool imageIsDocument = imageLoader().isLoadingImageDocument() && | 791 bool imageIsDocument = imageLoader().isLoadingImageDocument() && |
| 792 imageLoader().image() && | 792 imageLoader().image() && |
| 793 !imageLoader().image()->errorOccurred(); | 793 !imageLoader().image()->errorOccurred(); |
| 794 | 794 |
| 795 // Icky special case for deferred images: | 795 // Icky special case for deferred images: |
| 796 // A deferred image is not loading, does have pending activity, does not | 796 // A deferred image is not loading, does have pending activity, does not |
| 797 // have an error, but it does have an ImageResource associated | 797 // have an error, but it does have an ImageResourceContent associated |
| 798 // with it, so imageHasLoaded will be true even though the image hasn't | 798 // with it, so imageHasLoaded will be true even though the image hasn't |
| 799 // actually loaded. Fixing the definition of imageHasLoaded isn't | 799 // actually loaded. Fixing the definition of imageHasLoaded isn't |
| 800 // sufficient, because a deferred image does have pending activity, does not | 800 // sufficient, because a deferred image does have pending activity, does not |
| 801 // have a pending error, and does have a source URL, so if imageHasLoaded | 801 // have a pending error, and does have a source URL, so if imageHasLoaded |
| 802 // was correct, imageStillLoading would become wrong. | 802 // was correct, imageStillLoading would become wrong. |
| 803 // | 803 // |
| 804 // Instead of dealing with that, there's a separate check that the | 804 // Instead of dealing with that, there's a separate check that the |
| 805 // ImageResource has non-null image data associated with it, which isn't | 805 // ImageResourceContent has non-null image data associated with it, which |
| 806 // folded into imageHasLoaded above. | 806 // isn't folded into imageHasLoaded above. |
| 807 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument) | 807 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument) |
| 808 ensurePrimaryContent(); | 808 ensurePrimaryContent(); |
| 809 else | 809 else |
| 810 ensureCollapsedOrFallbackContent(); | 810 ensureCollapsedOrFallbackContent(); |
| 811 } | 811 } |
| 812 | 812 |
| 813 const KURL& HTMLImageElement::sourceURL() const { | 813 const KURL& HTMLImageElement::sourceURL() const { |
| 814 return cachedImage()->response().url(); | 814 return cachedImage()->response().url(); |
| 815 } | 815 } |
| 816 | 816 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 | 892 |
| 893 int HTMLImageElement::sourceHeight() { | 893 int HTMLImageElement::sourceHeight() { |
| 894 SourceImageStatus status; | 894 SourceImageStatus status; |
| 895 FloatSize defaultObjectSize(width(), height()); | 895 FloatSize defaultObjectSize(width(), height()); |
| 896 RefPtr<Image> image = getSourceImageForCanvas( | 896 RefPtr<Image> image = getSourceImageForCanvas( |
| 897 &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); | 897 &status, PreferNoAcceleration, SnapshotReasonUnknown, defaultObjectSize); |
| 898 return image->height(); | 898 return image->height(); |
| 899 } | 899 } |
| 900 | 900 |
| 901 IntSize HTMLImageElement::bitmapSourceSize() const { | 901 IntSize HTMLImageElement::bitmapSourceSize() const { |
| 902 ImageResource* image = cachedImage(); | 902 ImageResourceContent* image = cachedImage(); |
| 903 if (!image) | 903 if (!image) |
| 904 return IntSize(); | 904 return IntSize(); |
| 905 LayoutSize lSize = image->imageSize( | 905 LayoutSize lSize = image->imageSize( |
| 906 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); | 906 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); |
| 907 DCHECK(lSize.fraction().isZero()); | 907 DCHECK(lSize.fraction().isZero()); |
| 908 return IntSize(lSize.width().toInt(), lSize.height().toInt()); | 908 return IntSize(lSize.width().toInt(), lSize.height().toInt()); |
| 909 } | 909 } |
| 910 | 910 |
| 911 void HTMLImageElement::associateWith(HTMLFormElement* form) { | 911 void HTMLImageElement::associateWith(HTMLFormElement* form) { |
| 912 if (form && form->isConnected()) { | 912 if (form && form->isConnected()) { |
| 913 m_form = form; | 913 m_form = form; |
| 914 m_formWasSetByParser = true; | 914 m_formWasSetByParser = true; |
| 915 m_form->associate(*this); | 915 m_form->associate(*this); |
| 916 m_form->didAssociateByParser(); | 916 m_form->didAssociateByParser(); |
| 917 } | 917 } |
| 918 }; | 918 }; |
| 919 | 919 |
| 920 } // namespace blink | 920 } // namespace blink |
| OLD | NEW |