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

Unified Diff: Source/core/html/parser/HTMLSrcsetParser.h

Issue 293423002: Refactor srcset parser to align it with spec changes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed ASSERT Created 6 years, 7 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/parser/HTMLParserIdioms.h ('k') | Source/core/html/parser/HTMLSrcsetParser.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLSrcsetParser.h
diff --git a/Source/core/html/parser/HTMLSrcsetParser.h b/Source/core/html/parser/HTMLSrcsetParser.h
index 36287f7487f90ee46251fb393d5281500c322f06..829ff530d7ee66c3f9a4de0f137b67de3720c2bd 100644
--- a/Source/core/html/parser/HTMLSrcsetParser.h
+++ b/Source/core/html/parser/HTMLSrcsetParser.h
@@ -36,20 +36,33 @@
namespace WebCore {
-struct DescriptorParsingResult {
- float scaleFactor;
- int resourceWidth;
+enum { UninitializedDescriptor = -1 };
+class DescriptorParsingResult {
+public:
DescriptorParsingResult()
+ : m_density(UninitializedDescriptor)
+ , m_resourceWidth(UninitializedDescriptor)
+ , m_resourceHeight(UninitializedDescriptor)
{
- scaleFactor = -1.0;
- resourceWidth = -1;
}
- bool foundDescriptor() const
- {
- return (scaleFactor >= 0 || resourceWidth >= 0);
- }
+ bool hasDensity() const { return m_density >= 0; }
+ bool hasWidth() const { return m_resourceWidth >= 0; }
+ bool hasHeight() const { return m_resourceHeight >= 0; }
+
+ float density() const { ASSERT(hasDensity()); return m_density; }
+ unsigned resourceWidth() const { ASSERT(hasWidth()); return m_resourceWidth; }
+ unsigned resourceHeight() const { ASSERT(hasHeight()); return m_resourceHeight; }
+
+ void setResourceWidth(int width) { ASSERT(width >= 0); m_resourceWidth = (unsigned)width; }
+ void setResourceHeight(int height) { ASSERT(height >= 0); m_resourceHeight = (unsigned)height; }
+ void setDensity(float densityToSet) { ASSERT(densityToSet >= 0); m_density = densityToSet; }
+
+private:
+ float m_density;
+ int m_resourceWidth;
+ int m_resourceHeight;
};
class ImageCandidate {
@@ -60,14 +73,14 @@ public:
};
ImageCandidate()
- : m_scaleFactor(1.0)
+ : m_density(1.0)
{
}
ImageCandidate(const String& source, unsigned start, unsigned length, const DescriptorParsingResult& result, OriginAttribute originAttribute)
: m_string(source.createView(start, length))
- , m_scaleFactor(result.scaleFactor)
- , m_resourceWidth(result.resourceWidth)
+ , m_density(result.hasDensity()?result.density():UninitializedDescriptor)
+ , m_resourceWidth(result.hasWidth()?result.resourceWidth():UninitializedDescriptor)
, m_originAttribute(originAttribute)
{
}
@@ -82,14 +95,14 @@ public:
return AtomicString(m_string.toString());
}
- void setScaleFactor(float factor)
+ void setDensity(float factor)
{
- m_scaleFactor = factor;
+ m_density = factor;
}
- float scaleFactor() const
+ float density() const
{
- return m_scaleFactor;
+ return m_density;
}
int resourceWidth() const
@@ -109,7 +122,7 @@ public:
private:
StringView m_string;
- float m_scaleFactor;
+ float m_density;
int m_resourceWidth;
OriginAttribute m_originAttribute;
};
« no previous file with comments | « Source/core/html/parser/HTMLParserIdioms.h ('k') | Source/core/html/parser/HTMLSrcsetParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698