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 { |
| 39 float scaleFactor; |
| 40 int resourceWidth; |
| 41 |
| 42 DescriptorParsingResult() |
| 43 { |
| 44 scaleFactor = -1.0; |
| 45 resourceWidth = -1; |
| 46 } |
| 47 |
| 48 bool foundDescriptor() const |
| 49 { |
| 50 return (scaleFactor >= 0 || resourceWidth >= 0); |
| 51 } |
| 52 }; |
| 53 |
38 class ImageCandidate { | 54 class ImageCandidate { |
39 public: | 55 public: |
40 ImageCandidate() | 56 ImageCandidate() |
41 : m_scaleFactor(1.0) | 57 : m_scaleFactor(1.0) |
42 { | 58 { |
43 } | 59 } |
44 | 60 |
45 ImageCandidate(const String& source, unsigned start, unsigned length, float
scaleFactor) | 61 ImageCandidate(const String& source, unsigned start, unsigned length, const
DescriptorParsingResult& result) |
46 : m_string(source.createView(start, length)) | 62 : m_string(source.createView(start, length)) |
47 , m_scaleFactor(scaleFactor) | 63 , m_scaleFactor(result.scaleFactor) |
| 64 , m_resourceWidth(result.resourceWidth) |
48 { | 65 { |
49 } | 66 } |
50 | 67 |
51 String toString() const | 68 String toString() const |
52 { | 69 { |
53 return String(m_string.toString()); | 70 return String(m_string.toString()); |
54 } | 71 } |
55 | 72 |
56 AtomicString toAtomicString() const | 73 AtomicString toAtomicString() const |
57 { | 74 { |
58 return AtomicString(m_string.toString()); | 75 return AtomicString(m_string.toString()); |
59 } | 76 } |
60 | 77 |
61 inline float scaleFactor() const | 78 void setScaleFactor(float factor) |
| 79 { |
| 80 m_scaleFactor = factor; |
| 81 } |
| 82 |
| 83 float scaleFactor() const |
62 { | 84 { |
63 return m_scaleFactor; | 85 return m_scaleFactor; |
64 } | 86 } |
65 | 87 |
| 88 int resourceWidth() const |
| 89 { |
| 90 return m_resourceWidth; |
| 91 } |
| 92 |
66 inline bool isEmpty() const | 93 inline bool isEmpty() const |
67 { | 94 { |
68 return m_string.isEmpty(); | 95 return m_string.isEmpty(); |
69 } | 96 } |
70 | 97 |
71 private: | 98 private: |
72 StringView m_string; | 99 StringView m_string; |
73 float m_scaleFactor; | 100 float m_scaleFactor; |
| 101 int m_resourceWidth; |
74 }; | 102 }; |
75 | 103 |
76 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, const St
ring& srcsetAttribute); | 104 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, int effe
ctiveSize, const String& srcsetAttribute); |
77 | 105 |
78 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const St
ring& srcAttribute, const String& srcsetAttribute); | 106 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, int effe
ctiveSize, const String& srcAttribute, const String& srcsetAttribute); |
79 | 107 |
80 String bestFitSourceForImageAttributes(float deviceScaleFactor, const String& sr
cAttribute, ImageCandidate& srcsetImageCandidate); | 108 String bestFitSourceForImageAttributes(float deviceScaleFactor, int effectiveSiz
e, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); |
81 | 109 |
82 } | 110 } |
83 | 111 |
84 #endif | 112 #endif |
OLD | NEW |