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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLImageElement.h ('k') | Source/core/html/HTMLImageElementTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLImageElement.cpp
diff --git a/Source/core/html/HTMLImageElement.cpp b/Source/core/html/HTMLImageElement.cpp
index d46f9de78aee086b9d05ce96120bbe88d13633ad..00e97af3ce0d93800b6a1eab4769cccf3947b2b5 100644
--- a/Source/core/html/HTMLImageElement.cpp
+++ b/Source/core/html/HTMLImageElement.cpp
@@ -630,12 +630,45 @@ FloatSize HTMLImageElement::defaultDestinationSize() const
return FloatSize(size);
}
-float HTMLImageElement::sourceSize(Element& element)
+static bool sourceSizeValue(Element& element, Document& currentDocument, float& sourceSize)
{
String sizes = element.fastGetAttribute(sizesAttr);
- if (!sizes.isNull())
- UseCounter::count(document(), UseCounter::Sizes);
- return SizesAttributeParser(MediaValuesDynamic::create(document()), sizes).length();
+ bool exists = !sizes.isNull();
+ if (exists)
+ UseCounter::count(currentDocument, UseCounter::Sizes);
+ sourceSize = SizesAttributeParser(MediaValuesDynamic::create(currentDocument), sizes).length();
+ return exists;
+}
+
+int HTMLImageElement::widthAttributeToInt(const String& value, bool& isValid)
+{
+ // '%' is excluded here since having a width percentage based value means
+ // that the actual width depends on layout, so we cannot use it for resourceWidth.
+ // '*' is exclueded since in Blink and WebKit it means that the entire attribtue is ignored.
+ // TODO(yoav): Count these occurences and try to deprecate/remove if feasible: crbug.com/501870
+ if (!value.isEmpty() && !value.contains('%') && !value.contains('*'))
+ return value.toInt(&isValid);
+
+ isValid = false;
+ return 0;
+}
+
+FetchRequest::ResourceWidth HTMLImageElement::resourceWidth()
+{
+ FetchRequest::ResourceWidth resourceWidth;
+ resourceWidth.isSet = sourceSizeValue(*this, document(), resourceWidth.width);
+ if (!resourceWidth.isSet)
+ resourceWidth.width = widthAttributeToInt(fastGetAttribute(widthAttr), resourceWidth.isSet);
+ return resourceWidth;
+}
+
+float HTMLImageElement::sourceSize(Element& element)
+{
+ float value;
+ // We don't care here if the sizes attribute exists, so we ignore the return value.
+ // If it doesn't exist, we just return the default.
+ sourceSizeValue(element, document(), value);
+ return value;
}
void HTMLImageElement::forceReload() const
« 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