Chromium Code Reviews| Index: Source/core/html/HTMLImageElement.cpp |
| diff --git a/Source/core/html/HTMLImageElement.cpp b/Source/core/html/HTMLImageElement.cpp |
| index d46f9de78aee086b9d05ce96120bbe88d13633ad..9c311dd6a524415b5fa7b598a960d8cf0e625206 100644 |
| --- a/Source/core/html/HTMLImageElement.cpp |
| +++ b/Source/core/html/HTMLImageElement.cpp |
| @@ -402,6 +402,7 @@ int HTMLImageElement::width(bool ignorePendingStylesheets) |
| if (!layoutObject()) { |
| // check the attribute first for an explicit pixel value |
| bool ok; |
| + // TODO(yoav): That seems buggy when width is provided with a '%'. |
|
igrigorik
2015/06/17 17:26:28
Per spec, it's CSS px only: http://www.w3.org/html
Mike West
2015/06/18 06:20:04
Is there a bug we could point to here?
Yoav Weiss
2015/06/18 06:30:22
I'll open one, once I make sure this is an actual
Yoav Weiss
2015/06/18 09:19:27
Seems to be returning the calculated width after l
|
| int width = getAttribute(widthAttr).toInt(&ok); |
| if (ok) |
| return width; |
| @@ -630,12 +631,41 @@ 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) |
| +{ |
| + if (!value.isEmpty() && !value.contains('%') && !value.contains('*')) |
|
Mike West
2015/06/18 06:20:04
Nit: Could you add a comment here explaining why y
Yoav Weiss
2015/06/18 06:30:22
Will do
|
| + 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 |