Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: Source/core/html/HTMLImageElement.cpp

Issue 1186333004: Add support for `width` based Width Client Hint (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Moar comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageElementTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 ImageResource* image = cachedImage(); 623 ImageResource* image = cachedImage();
624 if (!image) 624 if (!image)
625 return FloatSize(); 625 return FloatSize();
626 LayoutSize size; 626 LayoutSize size;
627 size = image->imageSizeForLayoutObject(layoutObject(), 1.0f); 627 size = image->imageSizeForLayoutObject(layoutObject(), 1.0f);
628 if (layoutObject() && layoutObject()->isLayoutImage() && image->image() && ! image->image()->hasRelativeWidth()) 628 if (layoutObject() && layoutObject()->isLayoutImage() && image->image() && ! image->image()->hasRelativeWidth())
629 size.scale(toLayoutImage(layoutObject())->imageDevicePixelRatio()); 629 size.scale(toLayoutImage(layoutObject())->imageDevicePixelRatio());
630 return FloatSize(size); 630 return FloatSize(size);
631 } 631 }
632 632
633 static bool sourceSizeValue(Element& element, Document& currentDocument, float& sourceSize)
634 {
635 String sizes = element.fastGetAttribute(sizesAttr);
636 bool exists = !sizes.isNull();
637 if (exists)
638 UseCounter::count(currentDocument, UseCounter::Sizes);
639 sourceSize = SizesAttributeParser(MediaValuesDynamic::create(currentDocument ), sizes).length();
640 return exists;
641 }
642
643 int HTMLImageElement::widthAttributeToInt(const String& value, bool& isValid)
644 {
645 // '%' is excluded here since having a width percentage based value means
646 // that the actual width depends on layout, so we cannot use it for resource Width.
647 // '*' is exclueded since in Blink and WebKit it means that the entire attri btue is ignored.
648 // TODO(yoav): Count these occurences and try to deprecate/remove if feasibl e: crbug.com/501870
649 if (!value.isEmpty() && !value.contains('%') && !value.contains('*'))
650 return value.toInt(&isValid);
651
652 isValid = false;
653 return 0;
654 }
655
656 FetchRequest::ResourceWidth HTMLImageElement::resourceWidth()
657 {
658 FetchRequest::ResourceWidth resourceWidth;
659 resourceWidth.isSet = sourceSizeValue(*this, document(), resourceWidth.width );
660 if (!resourceWidth.isSet)
661 resourceWidth.width = widthAttributeToInt(fastGetAttribute(widthAttr), r esourceWidth.isSet);
662 return resourceWidth;
663 }
664
633 float HTMLImageElement::sourceSize(Element& element) 665 float HTMLImageElement::sourceSize(Element& element)
634 { 666 {
635 String sizes = element.fastGetAttribute(sizesAttr); 667 float value;
636 if (!sizes.isNull()) 668 // We don't care here if the sizes attribute exists, so we ignore the return value.
637 UseCounter::count(document(), UseCounter::Sizes); 669 // If it doesn't exist, we just return the default.
638 return SizesAttributeParser(MediaValuesDynamic::create(document()), sizes).l ength(); 670 sourceSizeValue(element, document(), value);
671 return value;
639 } 672 }
640 673
641 void HTMLImageElement::forceReload() const 674 void HTMLImageElement::forceReload() const
642 { 675 {
643 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload); 676 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload);
644 } 677 }
645 678
646 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior) 679 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior)
647 { 680 {
648 if (!document().isActive()) 681 if (!document().isActive())
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 ensureUserAgentShadowRoot(); 760 ensureUserAgentShadowRoot();
728 } 761 }
729 762
730 bool HTMLImageElement::isOpaque() const 763 bool HTMLImageElement::isOpaque() const
731 { 764 {
732 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); 765 Image* image = const_cast<HTMLImageElement*>(this)->imageContents();
733 return image && image->currentFrameKnownToBeOpaque(); 766 return image && image->currentFrameKnownToBeOpaque();
734 } 767 }
735 768
736 } 769 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698