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 16 matching lines...) Expand all Loading... |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
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 "core/CoreExport.h" | 35 #include "core/CoreExport.h" |
36 #include "wtf/Allocator.h" | 36 #include "wtf/Allocator.h" |
37 #include "wtf/text/StringView.h" | |
38 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 class Document; | 41 class Document; |
43 | 42 |
44 enum { UninitializedDescriptor = -1 }; | 43 enum { UninitializedDescriptor = -1 }; |
45 | 44 |
46 class DescriptorParsingResult { | 45 class DescriptorParsingResult { |
47 STACK_ALLOCATED(); | 46 STACK_ALLOCATED(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 }; | 79 }; |
81 | 80 |
82 ImageCandidate() | 81 ImageCandidate() |
83 : m_density(1.0) | 82 : m_density(1.0) |
84 , m_resourceWidth(UninitializedDescriptor) | 83 , m_resourceWidth(UninitializedDescriptor) |
85 , m_originAttribute(SrcsetOrigin) | 84 , m_originAttribute(SrcsetOrigin) |
86 { | 85 { |
87 } | 86 } |
88 | 87 |
89 ImageCandidate(const String& source, unsigned start, unsigned length, const
DescriptorParsingResult& result, OriginAttribute originAttribute) | 88 ImageCandidate(const String& source, unsigned start, unsigned length, const
DescriptorParsingResult& result, OriginAttribute originAttribute) |
90 : m_source(source) | 89 : m_string(source.createView(start, length)) |
91 , m_string(source, start, length) | 90 , m_density(result.hasDensity()?result.density():UninitializedDescriptor
) |
92 , m_density(result.hasDensity() ? result.density() : UninitializedDescri
ptor) | 91 , m_resourceWidth(result.hasWidth()?result.getResourceWidth():Uninitiali
zedDescriptor) |
93 , m_resourceWidth(result.hasWidth() ? result.getResourceWidth() : Uninit
ializedDescriptor) | |
94 , m_originAttribute(originAttribute) | 92 , m_originAttribute(originAttribute) |
95 { | 93 { |
96 } | 94 } |
97 | 95 |
98 String toString() const | 96 String toString() const |
99 { | 97 { |
100 return m_string.toString(); | 98 return String(m_string.toString()); |
101 } | 99 } |
102 | 100 |
103 AtomicString url() const | 101 AtomicString url() const |
104 { | 102 { |
105 return AtomicString(toString()); | 103 return AtomicString(m_string.toString()); |
106 } | 104 } |
107 | 105 |
108 void setDensity(float factor) | 106 void setDensity(float factor) |
109 { | 107 { |
110 m_density = factor; | 108 m_density = factor; |
111 } | 109 } |
112 | 110 |
113 float density() const | 111 float density() const |
114 { | 112 { |
115 return m_density; | 113 return m_density; |
116 } | 114 } |
117 | 115 |
118 int getResourceWidth() const | 116 int getResourceWidth() const |
119 { | 117 { |
120 return m_resourceWidth; | 118 return m_resourceWidth; |
121 } | 119 } |
122 | 120 |
123 bool srcOrigin() const | 121 bool srcOrigin() const |
124 { | 122 { |
125 return (m_originAttribute == SrcOrigin); | 123 return (m_originAttribute == SrcOrigin); |
126 } | 124 } |
127 | 125 |
128 inline bool isEmpty() const | 126 inline bool isEmpty() const |
129 { | 127 { |
130 return m_string.isEmpty(); | 128 return m_string.isEmpty(); |
131 } | 129 } |
132 | 130 |
133 private: | 131 private: |
134 String m_source; // Keep the StringView buffer alive. | |
135 StringView m_string; | 132 StringView m_string; |
136 float m_density; | 133 float m_density; |
137 int m_resourceWidth; | 134 int m_resourceWidth; |
138 OriginAttribute m_originAttribute; | 135 OriginAttribute m_originAttribute; |
139 }; | 136 }; |
140 | 137 |
141 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, float so
urceSize, const String& srcsetAttribute, Document* = nullptr); | 138 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, float so
urceSize, const String& srcsetAttribute, Document* = nullptr); |
142 | 139 |
143 CORE_EXPORT ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFact
or, float sourceSize, const String& srcAttribute, const String& srcsetAttribute,
Document* = nullptr); | 140 CORE_EXPORT ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFact
or, float sourceSize, const String& srcAttribute, const String& srcsetAttribute,
Document* = nullptr); |
144 | 141 |
145 String bestFitSourceForImageAttributes(float deviceScaleFactor, float sourceSize
, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); | 142 String bestFitSourceForImageAttributes(float deviceScaleFactor, float sourceSize
, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); |
146 | 143 |
147 } // namespace blink | 144 } // namespace blink |
148 | 145 |
149 #endif | 146 #endif |
OLD | NEW |