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