| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #ifndef HTMLSrcsetParser_h | 32 #ifndef HTMLSrcsetParser_h |
| 33 #define HTMLSrcsetParser_h | 33 #define HTMLSrcsetParser_h |
| 34 | 34 |
| 35 #include "wtf/text/WTFString.h" | 35 #include "wtf/text/WTFString.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 struct DescriptorParsingResult { | 39 enum { UninitializedDescriptor = -1 }; |
| 40 float scaleFactor; | |
| 41 int resourceWidth; | |
| 42 | 40 |
| 41 class DescriptorParsingResult { |
| 42 public: |
| 43 DescriptorParsingResult() | 43 DescriptorParsingResult() |
| 44 : m_density(UninitializedDescriptor) |
| 45 , m_resourceWidth(UninitializedDescriptor) |
| 46 , m_resourceHeight(UninitializedDescriptor) |
| 44 { | 47 { |
| 45 scaleFactor = -1.0; | |
| 46 resourceWidth = -1; | |
| 47 } | 48 } |
| 48 | 49 |
| 49 bool foundDescriptor() const | 50 bool hasDensity() const { return m_density >= 0; } |
| 50 { | 51 bool hasWidth() const { return m_resourceWidth >= 0; } |
| 51 return (scaleFactor >= 0 || resourceWidth >= 0); | 52 bool hasHeight() const { return m_resourceHeight >= 0; } |
| 52 } | 53 |
| 54 float density() const { ASSERT(hasDensity()); return m_density; } |
| 55 unsigned resourceWidth() const { ASSERT(hasWidth()); return m_resourceWidth;
} |
| 56 unsigned resourceHeight() const { ASSERT(hasHeight()); return m_resourceHeig
ht; } |
| 57 |
| 58 void setResourceWidth(int width) { ASSERT(width >= 0); m_resourceWidth = (un
signed)width; } |
| 59 void setResourceHeight(int height) { ASSERT(height >= 0); m_resourceHeight =
(unsigned)height; } |
| 60 void setDensity(float densityToSet) { ASSERT(densityToSet >= 0); m_density =
densityToSet; } |
| 61 |
| 62 private: |
| 63 float m_density; |
| 64 int m_resourceWidth; |
| 65 int m_resourceHeight; |
| 53 }; | 66 }; |
| 54 | 67 |
| 55 class ImageCandidate { | 68 class ImageCandidate { |
| 56 public: | 69 public: |
| 57 enum OriginAttribute { | 70 enum OriginAttribute { |
| 58 SrcsetOrigin, | 71 SrcsetOrigin, |
| 59 SrcOrigin | 72 SrcOrigin |
| 60 }; | 73 }; |
| 61 | 74 |
| 62 ImageCandidate() | 75 ImageCandidate() |
| 63 : m_scaleFactor(1.0) | 76 : m_density(1.0) |
| 64 { | 77 { |
| 65 } | 78 } |
| 66 | 79 |
| 67 ImageCandidate(const String& source, unsigned start, unsigned length, const
DescriptorParsingResult& result, OriginAttribute originAttribute) | 80 ImageCandidate(const String& source, unsigned start, unsigned length, const
DescriptorParsingResult& result, OriginAttribute originAttribute) |
| 68 : m_string(source.createView(start, length)) | 81 : m_string(source.createView(start, length)) |
| 69 , m_scaleFactor(result.scaleFactor) | 82 , m_density(result.hasDensity()?result.density():UninitializedDescriptor
) |
| 70 , m_resourceWidth(result.resourceWidth) | 83 , m_resourceWidth(result.hasWidth()?result.resourceWidth():Uninitialized
Descriptor) |
| 71 , m_originAttribute(originAttribute) | 84 , m_originAttribute(originAttribute) |
| 72 { | 85 { |
| 73 } | 86 } |
| 74 | 87 |
| 75 String toString() const | 88 String toString() const |
| 76 { | 89 { |
| 77 return String(m_string.toString()); | 90 return String(m_string.toString()); |
| 78 } | 91 } |
| 79 | 92 |
| 80 AtomicString url() const | 93 AtomicString url() const |
| 81 { | 94 { |
| 82 return AtomicString(m_string.toString()); | 95 return AtomicString(m_string.toString()); |
| 83 } | 96 } |
| 84 | 97 |
| 85 void setScaleFactor(float factor) | 98 void setDensity(float factor) |
| 86 { | 99 { |
| 87 m_scaleFactor = factor; | 100 m_density = factor; |
| 88 } | 101 } |
| 89 | 102 |
| 90 float scaleFactor() const | 103 float density() const |
| 91 { | 104 { |
| 92 return m_scaleFactor; | 105 return m_density; |
| 93 } | 106 } |
| 94 | 107 |
| 95 int resourceWidth() const | 108 int resourceWidth() const |
| 96 { | 109 { |
| 97 return m_resourceWidth; | 110 return m_resourceWidth; |
| 98 } | 111 } |
| 99 | 112 |
| 100 bool srcOrigin() const | 113 bool srcOrigin() const |
| 101 { | 114 { |
| 102 return (m_originAttribute == SrcOrigin); | 115 return (m_originAttribute == SrcOrigin); |
| 103 } | 116 } |
| 104 | 117 |
| 105 inline bool isEmpty() const | 118 inline bool isEmpty() const |
| 106 { | 119 { |
| 107 return m_string.isEmpty(); | 120 return m_string.isEmpty(); |
| 108 } | 121 } |
| 109 | 122 |
| 110 private: | 123 private: |
| 111 StringView m_string; | 124 StringView m_string; |
| 112 float m_scaleFactor; | 125 float m_density; |
| 113 int m_resourceWidth; | 126 int m_resourceWidth; |
| 114 OriginAttribute m_originAttribute; | 127 OriginAttribute m_originAttribute; |
| 115 }; | 128 }; |
| 116 | 129 |
| 117 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, unsigned
sourceSize, const String& srcsetAttribute); | 130 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, unsigned
sourceSize, const String& srcsetAttribute); |
| 118 | 131 |
| 119 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned
sourceSize, const String& srcAttribute, const String& srcsetAttribute); | 132 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned
sourceSize, const String& srcAttribute, const String& srcsetAttribute); |
| 120 | 133 |
| 121 String bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceS
ize, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); | 134 String bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceS
ize, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); |
| 122 | 135 |
| 123 } | 136 } |
| 124 | 137 |
| 125 #endif | 138 #endif |
| OLD | NEW |