Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLSrcsetParser.h

Issue 2007103003: Expand WTF::StringView's API to be more like StringPiece. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove bad assert. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
37 #include "wtf/text/WTFString.h" 38 #include "wtf/text/WTFString.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
41 class Document; 42 class Document;
42 43
43 enum { UninitializedDescriptor = -1 }; 44 enum { UninitializedDescriptor = -1 };
44 45
45 class DescriptorParsingResult { 46 class DescriptorParsingResult {
46 STACK_ALLOCATED(); 47 STACK_ALLOCATED();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 }; 80 };
80 81
81 ImageCandidate() 82 ImageCandidate()
82 : m_density(1.0) 83 : m_density(1.0)
83 , m_resourceWidth(UninitializedDescriptor) 84 , m_resourceWidth(UninitializedDescriptor)
84 , m_originAttribute(SrcsetOrigin) 85 , m_originAttribute(SrcsetOrigin)
85 { 86 {
86 } 87 }
87 88
88 ImageCandidate(const String& source, unsigned start, unsigned length, const DescriptorParsingResult& result, OriginAttribute originAttribute) 89 ImageCandidate(const String& source, unsigned start, unsigned length, const DescriptorParsingResult& result, OriginAttribute originAttribute)
89 : m_string(source.createView(start, length)) 90 : m_source(source)
90 , m_density(result.hasDensity()?result.density():UninitializedDescriptor ) 91 , m_string(source, start, length)
91 , m_resourceWidth(result.hasWidth()?result.getResourceWidth():Uninitiali zedDescriptor) 92 , m_density(result.hasDensity() ? result.density() : UninitializedDescri ptor)
93 , m_resourceWidth(result.hasWidth() ? result.getResourceWidth() : Uninit ializedDescriptor)
92 , m_originAttribute(originAttribute) 94 , m_originAttribute(originAttribute)
93 { 95 {
94 } 96 }
95 97
96 String toString() const 98 String toString() const
97 { 99 {
98 return String(m_string.toString()); 100 return m_string.toString();
99 } 101 }
100 102
101 AtomicString url() const 103 AtomicString url() const
102 { 104 {
103 return AtomicString(m_string.toString()); 105 return AtomicString(toString());
104 } 106 }
105 107
106 void setDensity(float factor) 108 void setDensity(float factor)
107 { 109 {
108 m_density = factor; 110 m_density = factor;
109 } 111 }
110 112
111 float density() const 113 float density() const
112 { 114 {
113 return m_density; 115 return m_density;
114 } 116 }
115 117
116 int getResourceWidth() const 118 int getResourceWidth() const
117 { 119 {
118 return m_resourceWidth; 120 return m_resourceWidth;
119 } 121 }
120 122
121 bool srcOrigin() const 123 bool srcOrigin() const
122 { 124 {
123 return (m_originAttribute == SrcOrigin); 125 return (m_originAttribute == SrcOrigin);
124 } 126 }
125 127
126 inline bool isEmpty() const 128 inline bool isEmpty() const
127 { 129 {
128 return m_string.isEmpty(); 130 return m_string.isEmpty();
129 } 131 }
130 132
131 private: 133 private:
134 String m_source; // Keep the StringView buffer alive.
132 StringView m_string; 135 StringView m_string;
133 float m_density; 136 float m_density;
134 int m_resourceWidth; 137 int m_resourceWidth;
135 OriginAttribute m_originAttribute; 138 OriginAttribute m_originAttribute;
136 }; 139 };
137 140
138 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, float so urceSize, const String& srcsetAttribute, Document* = nullptr); 141 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, float so urceSize, const String& srcsetAttribute, Document* = nullptr);
139 142
140 CORE_EXPORT ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFact or, float sourceSize, const String& srcAttribute, const String& srcsetAttribute, Document* = nullptr); 143 CORE_EXPORT ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFact or, float sourceSize, const String& srcAttribute, const String& srcsetAttribute, Document* = nullptr);
141 144
142 String bestFitSourceForImageAttributes(float deviceScaleFactor, float sourceSize , const String& srcAttribute, ImageCandidate& srcsetImageCandidate); 145 String bestFitSourceForImageAttributes(float deviceScaleFactor, float sourceSize , const String& srcAttribute, ImageCandidate& srcsetImageCandidate);
143 146
144 } // namespace blink 147 } // namespace blink
145 148
146 #endif 149 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698