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

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

Issue 236593003: Align srcset parsing with spec changes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added some more tests Created 6 years, 8 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
« no previous file with comments | « no previous file | Source/core/html/parser/HTMLSrcsetParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 bool foundDescriptor() const 48 bool foundDescriptor() const
49 { 49 {
50 return (scaleFactor >= 0 || resourceWidth >= 0); 50 return (scaleFactor >= 0 || resourceWidth >= 0);
51 } 51 }
52 }; 52 };
53 53
54 class ImageCandidate { 54 class ImageCandidate {
55 public: 55 public:
56 enum OriginAttribute {
57 SrcsetOrigin,
58 SrcOrigin
59 };
60
56 ImageCandidate() 61 ImageCandidate()
57 : m_scaleFactor(1.0) 62 : m_scaleFactor(1.0)
58 { 63 {
59 } 64 }
60 65
61 ImageCandidate(const String& source, unsigned start, unsigned length, const DescriptorParsingResult& result) 66 ImageCandidate(const String& source, unsigned start, unsigned length, const DescriptorParsingResult& result, OriginAttribute originAttribute)
62 : m_string(source.createView(start, length)) 67 : m_string(source.createView(start, length))
63 , m_scaleFactor(result.scaleFactor) 68 , m_scaleFactor(result.scaleFactor)
64 , m_resourceWidth(result.resourceWidth) 69 , m_resourceWidth(result.resourceWidth)
70 , m_originAttribute(originAttribute)
65 { 71 {
66 } 72 }
67 73
68 String toString() const 74 String toString() const
69 { 75 {
70 return String(m_string.toString()); 76 return String(m_string.toString());
71 } 77 }
72 78
73 AtomicString toAtomicString() const 79 AtomicString toAtomicString() const
74 { 80 {
75 return AtomicString(m_string.toString()); 81 return AtomicString(m_string.toString());
76 } 82 }
77 83
78 void setScaleFactor(float factor) 84 void setScaleFactor(float factor)
79 { 85 {
80 m_scaleFactor = factor; 86 m_scaleFactor = factor;
81 } 87 }
82 88
83 float scaleFactor() const 89 float scaleFactor() const
84 { 90 {
85 return m_scaleFactor; 91 return m_scaleFactor;
86 } 92 }
87 93
88 int resourceWidth() const 94 int resourceWidth() const
89 { 95 {
90 return m_resourceWidth; 96 return m_resourceWidth;
91 } 97 }
92 98
99 bool srcOrigin() const
100 {
101 return (m_originAttribute == SrcOrigin);
102 }
103
93 inline bool isEmpty() const 104 inline bool isEmpty() const
94 { 105 {
95 return m_string.isEmpty(); 106 return m_string.isEmpty();
96 } 107 }
97 108
98 private: 109 private:
99 StringView m_string; 110 StringView m_string;
100 float m_scaleFactor; 111 float m_scaleFactor;
101 int m_resourceWidth; 112 int m_resourceWidth;
113 OriginAttribute m_originAttribute;
102 }; 114 };
103 115
104 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, int effe ctiveSize, const String& srcsetAttribute); 116 ImageCandidate bestFitSourceForSrcsetAttribute(float deviceScaleFactor, int effe ctiveSize, const String& srcsetAttribute);
105 117
106 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, int effe ctiveSize, const String& srcAttribute, const String& srcsetAttribute); 118 ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, int effe ctiveSize, const String& srcAttribute, const String& srcsetAttribute);
107 119
108 String bestFitSourceForImageAttributes(float deviceScaleFactor, int effectiveSiz e, const String& srcAttribute, ImageCandidate& srcsetImageCandidate); 120 String bestFitSourceForImageAttributes(float deviceScaleFactor, int effectiveSiz e, const String& srcAttribute, ImageCandidate& srcsetImageCandidate);
109 121
110 } 122 }
111 123
112 #endif 124 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/html/parser/HTMLSrcsetParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698