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 18 matching lines...) Expand all Loading... | |
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 struct DescriptorParsingResult { |
39 float scaleFactor; | 39 float density; |
40 int resourceWidth; | 40 int resourceWidth; |
41 int resourceHeight; | |
41 | 42 |
42 DescriptorParsingResult() | 43 DescriptorParsingResult() |
43 { | 44 { |
44 scaleFactor = -1.0; | 45 density = -1.0; |
eseidel
2014/05/28 22:24:59
Bleh. Sentinel values/in-band data. :(
You migh
Yoav Weiss
2014/05/29 05:17:40
OK, I'll turn that into a class with proper getter
| |
45 resourceWidth = -1; | 46 resourceWidth = -1; |
47 resourceHeight = -1; | |
46 } | 48 } |
47 | 49 |
48 bool foundDescriptor() const | 50 bool foundDensity() { return density >= 0; } |
eseidel
2014/05/28 22:24:59
I think "hasDensitiy" might be more consistent wit
Yoav Weiss
2014/05/29 05:17:40
Sure
| |
49 { | 51 bool foundWidth() { return resourceWidth >= 0; } |
eseidel
2014/05/28 22:24:59
Can these ever be set to negative numbers intentio
Yoav Weiss
2014/05/29 05:17:40
No
| |
50 return (scaleFactor >= 0 || resourceWidth >= 0); | 52 bool foundHeight() { return resourceHeight >= 0; } |
51 } | |
52 }; | 53 }; |
53 | 54 |
54 class ImageCandidate { | 55 class ImageCandidate { |
55 public: | 56 public: |
56 enum OriginAttribute { | 57 enum OriginAttribute { |
57 SrcsetOrigin, | 58 SrcsetOrigin, |
58 SrcOrigin | 59 SrcOrigin |
59 }; | 60 }; |
60 | 61 |
61 ImageCandidate() | 62 ImageCandidate() |
62 : m_scaleFactor(1.0) | 63 : m_density(1.0) |
63 { | 64 { |
64 } | 65 } |
65 | 66 |
66 ImageCandidate(const String& source, unsigned start, unsigned length, const DescriptorParsingResult& result, OriginAttribute originAttribute) | 67 ImageCandidate(const String& source, unsigned start, unsigned length, const DescriptorParsingResult& result, OriginAttribute originAttribute) |
67 : m_string(source.createView(start, length)) | 68 : m_string(source.createView(start, length)) |
68 , m_scaleFactor(result.scaleFactor) | 69 , m_density(result.density) |
69 , m_resourceWidth(result.resourceWidth) | 70 , m_resourceWidth(result.resourceWidth) |
70 , m_originAttribute(originAttribute) | 71 , m_originAttribute(originAttribute) |
71 { | 72 { |
72 } | 73 } |
73 | 74 |
74 String toString() const | 75 String toString() const |
75 { | 76 { |
76 return String(m_string.toString()); | 77 return String(m_string.toString()); |
77 } | 78 } |
78 | 79 |
79 AtomicString url() const | 80 AtomicString url() const |
80 { | 81 { |
81 return AtomicString(m_string.toString()); | 82 return AtomicString(m_string.toString()); |
82 } | 83 } |
83 | 84 |
84 void setScaleFactor(float factor) | 85 void setDensity(float factor) |
85 { | 86 { |
86 m_scaleFactor = factor; | 87 m_density = factor; |
87 } | 88 } |
88 | 89 |
89 float scaleFactor() const | 90 float density() const |
90 { | 91 { |
91 return m_scaleFactor; | 92 return m_density; |
92 } | 93 } |
93 | 94 |
94 int resourceWidth() const | 95 int resourceWidth() const |
95 { | 96 { |
96 return m_resourceWidth; | 97 return m_resourceWidth; |
97 } | 98 } |
98 | 99 |
99 bool srcOrigin() const | 100 bool srcOrigin() const |
100 { | 101 { |
101 return (m_originAttribute == SrcOrigin); | 102 return (m_originAttribute == SrcOrigin); |
102 } | 103 } |
103 | 104 |
104 inline bool isEmpty() const | 105 inline bool isEmpty() const |
105 { | 106 { |
106 return m_string.isEmpty(); | 107 return m_string.isEmpty(); |
107 } | 108 } |
108 | 109 |
109 private: | 110 private: |
110 StringView m_string; | 111 StringView m_string; |
111 float m_scaleFactor; | 112 float m_density; |
112 int m_resourceWidth; | 113 int m_resourceWidth; |
113 OriginAttribute m_originAttribute; | 114 OriginAttribute m_originAttribute; |
114 }; | 115 }; |
115 | 116 |
116 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, unsigned sourceSize, const String& srcsetAttribute); | 117 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, unsigned sourceSize, const String& srcsetAttribute); |
117 | 118 |
118 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceSize, const String& srcAttribute, const String& srcsetAttribute); | 119 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceSize, const String& srcAttribute, const String& srcsetAttribute); |
119 | 120 |
120 String bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceS ize, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); | 121 String bestFitSourceForImageAttributes(float deviceScaleFactor, unsigned sourceS ize, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); |
121 | 122 |
122 } | 123 } |
123 | 124 |
124 #endif | 125 #endif |
OLD | NEW |