Chromium Code Reviews| 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 reserv ed. |
| 5 * Copyright (C) 2010 Google Inc. All rights reserved. | 5 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 #include "platform/ContentType.h" | 50 #include "platform/ContentType.h" |
| 51 #include "platform/EventDispatchForbiddenScope.h" | 51 #include "platform/EventDispatchForbiddenScope.h" |
| 52 #include "platform/MIMETypeRegistry.h" | 52 #include "platform/MIMETypeRegistry.h" |
| 53 #include "platform/RuntimeEnabledFeatures.h" | 53 #include "platform/RuntimeEnabledFeatures.h" |
| 54 #include "platform/weborigin/SecurityPolicy.h" | 54 #include "platform/weborigin/SecurityPolicy.h" |
| 55 | 55 |
| 56 namespace blink { | 56 namespace blink { |
| 57 | 57 |
| 58 using namespace HTMLNames; | 58 using namespace HTMLNames; |
| 59 | 59 |
| 60 namespace { | |
| 61 | |
| 62 RespectImageOrientationEnum shouldRespectImageOrientation(LayoutObject* layoutOb ject) | |
| 63 { | |
| 64 if (layoutObject) | |
| 65 return layoutObject->shouldRespectImageOrientation(); | |
| 66 | |
| 67 return DoNotRespectImageOrientation; | |
| 68 } | |
| 69 | |
| 70 } // anonymous namespace | |
| 71 | |
| 60 class HTMLImageElement::ViewportChangeListener final : public MediaQueryListList ener { | 72 class HTMLImageElement::ViewportChangeListener final : public MediaQueryListList ener { |
| 61 public: | 73 public: |
| 62 static RefPtrWillBeRawPtr<ViewportChangeListener> create(HTMLImageElement* e lement) | 74 static RefPtrWillBeRawPtr<ViewportChangeListener> create(HTMLImageElement* e lement) |
| 63 { | 75 { |
| 64 return adoptRefWillBeNoop(new ViewportChangeListener(element)); | 76 return adoptRefWillBeNoop(new ViewportChangeListener(element)); |
| 65 } | 77 } |
| 66 | 78 |
| 67 void notifyMediaQueryChanged() override | 79 void notifyMediaQueryChanged() override |
| 68 { | 80 { |
| 69 if (m_element) | 81 if (m_element) |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 | 432 |
| 421 if (!layoutObject()) { | 433 if (!layoutObject()) { |
| 422 // check the attribute first for an explicit pixel value | 434 // check the attribute first for an explicit pixel value |
| 423 bool ok; | 435 bool ok; |
| 424 int width = getAttribute(widthAttr).toInt(&ok); | 436 int width = getAttribute(widthAttr).toInt(&ok); |
| 425 if (ok) | 437 if (ok) |
| 426 return width; | 438 return width; |
| 427 | 439 |
| 428 // if the image is available, use its width | 440 // if the image is available, use its width |
| 429 if (imageLoader().image()) | 441 if (imageLoader().image()) |
| 430 return imageLoader().image()->imageSizeForLayoutObject(layoutObject( ), 1.0f).width(); | 442 return imageLoader().image()->imageSize(DoNotRespectImageOrientation , 1.0f).width(); |
|
Yoav Weiss
2015/11/24 10:29:07
Are you sure this does not change behavior?
I'd
davve
2015/11/24 12:49:13
This is the layoutObject() == null code path.
The
Yoav Weiss
2015/11/24 13:06:56
Fair enough. I would prefer shouldRespectImageOrie
| |
| 431 } | 443 } |
| 432 | 444 |
| 433 LayoutBox* box = layoutBox(); | 445 LayoutBox* box = layoutBox(); |
| 434 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth() , box) : 0; | 446 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedWidth() , box) : 0; |
| 435 } | 447 } |
| 436 | 448 |
| 437 int HTMLImageElement::height() | 449 int HTMLImageElement::height() |
| 438 { | 450 { |
| 439 if (inActiveDocument()) | 451 if (inActiveDocument()) |
| 440 document().updateLayoutIgnorePendingStylesheets(); | 452 document().updateLayoutIgnorePendingStylesheets(); |
| 441 | 453 |
| 442 if (!layoutObject()) { | 454 if (!layoutObject()) { |
| 443 // check the attribute first for an explicit pixel value | 455 // check the attribute first for an explicit pixel value |
| 444 bool ok; | 456 bool ok; |
| 445 int height = getAttribute(heightAttr).toInt(&ok); | 457 int height = getAttribute(heightAttr).toInt(&ok); |
| 446 if (ok) | 458 if (ok) |
| 447 return height; | 459 return height; |
| 448 | 460 |
| 449 // if the image is available, use its height | 461 // if the image is available, use its height |
| 450 if (imageLoader().image()) | 462 if (imageLoader().image()) |
| 451 return imageLoader().image()->imageSizeForLayoutObject(layoutObject( ), 1.0f).height(); | 463 return imageLoader().image()->imageSize(DoNotRespectImageOrientation , 1.0f).height(); |
|
Yoav Weiss
2015/11/24 10:29:07
ditto
davve
2015/11/24 12:49:13
See other reply.
| |
| 452 } | 464 } |
| 453 | 465 |
| 454 LayoutBox* box = layoutBox(); | 466 LayoutBox* box = layoutBox(); |
| 455 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight( ), box) : 0; | 467 return box ? adjustForAbsoluteZoom(box->contentBoxRect().pixelSnappedHeight( ), box) : 0; |
| 456 } | 468 } |
| 457 | 469 |
| 458 int HTMLImageElement::naturalWidth() const | 470 int HTMLImageElement::naturalWidth() const |
| 459 { | 471 { |
| 460 if (!imageLoader().image()) | 472 if (!imageLoader().image()) |
| 461 return 0; | 473 return 0; |
| 462 | 474 |
| 463 return imageLoader().image()->imageSizeForLayoutObject(layoutObject(), m_ima geDevicePixelRatio, ImageResource::IntrinsicCorrectedToDPR).width(); | 475 return imageLoader().image()->imageSize(shouldRespectImageOrientation(layout Object()), m_imageDevicePixelRatio, ImageResource::IntrinsicCorrectedToDPR).widt h(); |
| 464 } | 476 } |
| 465 | 477 |
| 466 int HTMLImageElement::naturalHeight() const | 478 int HTMLImageElement::naturalHeight() const |
| 467 { | 479 { |
| 468 if (!imageLoader().image()) | 480 if (!imageLoader().image()) |
| 469 return 0; | 481 return 0; |
| 470 | 482 |
| 471 return imageLoader().image()->imageSizeForLayoutObject(layoutObject(), m_ima geDevicePixelRatio, ImageResource::IntrinsicCorrectedToDPR).height(); | 483 return imageLoader().image()->imageSize(shouldRespectImageOrientation(layout Object()), m_imageDevicePixelRatio, ImageResource::IntrinsicCorrectedToDPR).heig ht(); |
| 472 } | 484 } |
| 473 | 485 |
| 474 const String& HTMLImageElement::currentSrc() const | 486 const String& HTMLImageElement::currentSrc() const |
| 475 { | 487 { |
| 476 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#do m-img-currentsrc | 488 // http://www.whatwg.org/specs/web-apps/current-work/multipage/edits.html#do m-img-currentsrc |
| 477 // The currentSrc IDL attribute must return the img element's current reques t's current URL. | 489 // The currentSrc IDL attribute must return the img element's current reques t's current URL. |
| 478 // Initially, the pending request turns into current request when it is eith er available or broken. | 490 // Initially, the pending request turns into current request when it is eith er available or broken. |
| 479 // We use the image's dimensions as a proxy to it being in any of these stat es. | 491 // We use the image's dimensions as a proxy to it being in any of these stat es. |
| 480 if (!imageLoader().image() || !imageLoader().image()->image() || !imageLoade r().image()->image()->width()) | 492 if (!imageLoader().image() || !imageLoader().image()->image() || !imageLoade r().image()->image()->width()) |
| 481 return emptyAtom; | 493 return emptyAtom; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 return false; | 632 return false; |
| 621 return !image->isAccessAllowed(destinationSecurityOrigin); | 633 return !image->isAccessAllowed(destinationSecurityOrigin); |
| 622 } | 634 } |
| 623 | 635 |
| 624 FloatSize HTMLImageElement::elementSize() const | 636 FloatSize HTMLImageElement::elementSize() const |
| 625 { | 637 { |
| 626 ImageResource* image = cachedImage(); | 638 ImageResource* image = cachedImage(); |
| 627 if (!image) | 639 if (!image) |
| 628 return FloatSize(); | 640 return FloatSize(); |
| 629 | 641 |
| 630 return FloatSize(image->imageSizeForLayoutObject(layoutObject(), 1.0f)); | 642 return FloatSize(image->imageSize(shouldRespectImageOrientation(layoutObject ()), 1.0f)); |
| 631 } | 643 } |
| 632 | 644 |
| 633 FloatSize HTMLImageElement::defaultDestinationSize() const | 645 FloatSize HTMLImageElement::defaultDestinationSize() const |
| 634 { | 646 { |
| 635 ImageResource* image = cachedImage(); | 647 ImageResource* image = cachedImage(); |
| 636 if (!image) | 648 if (!image) |
| 637 return FloatSize(); | 649 return FloatSize(); |
| 638 LayoutSize size; | 650 LayoutSize size; |
| 639 size = image->imageSizeForLayoutObject(layoutObject(), 1.0f); | 651 size = image->imageSize(shouldRespectImageOrientation(layoutObject()), 1.0f) ; |
| 640 if (layoutObject() && layoutObject()->isLayoutImage() && image->image() && ! image->image()->hasRelativeWidth()) | 652 if (layoutObject() && layoutObject()->isLayoutImage() && image->image() && ! image->image()->hasRelativeWidth()) |
| 641 size.scale(toLayoutImage(layoutObject())->imageDevicePixelRatio()); | 653 size.scale(toLayoutImage(layoutObject())->imageDevicePixelRatio()); |
| 642 return FloatSize(size); | 654 return FloatSize(size); |
| 643 } | 655 } |
| 644 | 656 |
| 645 static bool sourceSizeValue(Element& element, Document& currentDocument, float& sourceSize) | 657 static bool sourceSizeValue(Element& element, Document& currentDocument, float& sourceSize) |
| 646 { | 658 { |
| 647 String sizes = element.fastGetAttribute(sizesAttr); | 659 String sizes = element.fastGetAttribute(sizesAttr); |
| 648 bool exists = !sizes.isNull(); | 660 bool exists = !sizes.isNull(); |
| 649 if (exists) | 661 if (exists) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 ensureUserAgentShadowRoot(); | 781 ensureUserAgentShadowRoot(); |
| 770 } | 782 } |
| 771 | 783 |
| 772 bool HTMLImageElement::isOpaque() const | 784 bool HTMLImageElement::isOpaque() const |
| 773 { | 785 { |
| 774 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); | 786 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); |
| 775 return image && image->currentFrameKnownToBeOpaque(); | 787 return image && image->currentFrameKnownToBeOpaque(); |
| 776 } | 788 } |
| 777 | 789 |
| 778 } | 790 } |
| OLD | NEW |