Changeset 153624 in webkit
- Timestamp:
- Aug 1, 2013 5:00:29 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 27 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r153623 r153624 1 2013-08-01 Romain Perier <romain.perier@gmail.com> 2 3 Implement img element's srcset attribute 4 https://bugs.webkit.org/show_bug.cgi?id=110252 5 6 Reviewed by Dean Jackson. 7 8 * fast/hidpi/image-srcset-simple.html: Ensures that the good image 9 is selected from srcset by the user agent according to the choosen scale factor. 10 * fast/hidpi/image-srcset-src-selection.html: Ensures that the image 11 from the src attribute is collected by the parsing algorithm and selected by the user agent 12 when no other candidate matches the scale factor. 13 * fast/hidpi/image-srcset-only-src-attribute.html: Ensures that the algorithms used for srcset 14 does not change the behaviour of the src attribute when the srcset attribute is not defined, 15 even using scale factor greater than 1. 16 * fast/hidpi/image-srcset-same-alternative-for-both-attributes.html: Ensures that the good image 17 is selected by the user agent when src and srcset contain an image with a scale factor of 1. 18 * fast/hidpi/image-srcset-invalid-inputs.html: Ensures that the parsing and the selection 19 algorithms support invalid inputs. Theses ones are simply ignored. 20 * fast/hidpi/image-srcset-invalid-inputs-except-one.html: Ensures that a valid image 21 is selected even if this one is part of a set containing invalid inputs. 22 * fast/hidpi/image-srcset-invalid-inputs-correct-src.html: Ensures that the image from 23 the src attribute is choosen when srcset contains only invalid inputs, this selection 24 should not depend on the scale factor. 25 * fast/hidpi/image-srcset-change-dynamically-from-js.html: Ensures that src and srcset attributes 26 can be changed dynamically from javascript. 27 * fast/hidpi/image-srcset-remove-dynamically-from-js.html: Ensures that src attribute 28 can be removed dynamically from javascript. 29 * platform/mac/fast/hidpi/image-srcset-simple-expected.png: 30 * platform/mac/fast/hidpi/image-srcset-simple-expected.txt: 31 * platform/mac/fast/hidpi/image-srcset-src-selection-expected.png: 32 * platform/mac/fast/hidpi/image-srcset-src-selection-expected.txt: 33 * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.png: 34 * platform/mac/fast/hidpi/image-srcset-only-src-attribute-expected.txt: 35 * platform/mac/fast/hidpi/image-srcset-same-alternative-for-both-attributes-expected.png: 36 * platform/mac/fast/hidpi/image-srcset-same-alternative-for-both-attributes-expected.txt: 37 * platform/mac/fast/hidpi/image-srcset-invalid-inputs-expected.png: 38 * platform/mac/fast/hidpi/image-srcset-invalid-inputs-expected.txt: 39 * platform/mac/fast/hidpi/image-srcset-invalid-inputs-except-one-expected.png: 40 * platform/mac/fast/hidpi/image-srcset-invalid-inputs-except-one-expected.txt: 41 * platform/mac/fast/hidpi/image-srcset-invalid-inputs-correct-src-expected.png: 42 * platform/mac/fast/hidpi/image-srcset-invalid-inputs-correct-src-expected.txt: 43 * platform/mac/fast/hidpi/image-srcset-change-dynamically-from-js-expected.png: 44 * platform/mac/fast/hidpi/image-srcset-change-dynamically-from-js-expected.txt: 45 * platform/mac/fast/hidpi/image-srcset-remove-dynamically-from-js-expected.png: 46 * platform/mac/fast/hidpi/image-srcset-remove-dynamically-from-js-expected.txt: 47 1 48 2013-08-01 Bem Jones-Bey <bjonesbe@adobe.com> 2 49 -
trunk/Source/WebCore/ChangeLog
r153613 r153624 1 2013-08-01 Romain Perier <romain.perier@gmail.com> 2 3 Implement img element's srcset attribute 4 https://bugs.webkit.org/show_bug.cgi?id=110252 5 6 Reviewed by Dean Jackson. 7 8 Tests: fast/hidpi/image-srcset-simple.html 9 fast/hidpi/image-srcset-src-selection.html 10 fast/hidpi/image-srcset-simple.html 11 fast/hidpi/image-srcset-src-selection.html 12 fast/hidpi/image-srcset-only-src-attribute.html 13 fast/hidpi/image-srcset-same-alternative-for-both-attributes.html 14 fast/hidpi/image-srcset-invalid-inputs.html 15 fast/hidpi/image-srcset-invalid-inputs-except-one.html 16 fast/hidpi/image-srcset-invalid-inputs-correct-src.html 17 fast/hidpi/image-srcset-change-dynamically-from-js.html 18 fast/hidpi/image-srcset-remove-dynamically-from-js.html 19 20 * html/HTMLAttributeNames.in: Add srcset attribute. 21 * html/HTMLImageElement.cpp: 22 (WebCore::HTMLImageElement::HTMLImageElement): 23 Adding initialization for new variables member. 24 (WebCore::HTMLImageElement::imageSourceURL): 25 Override this method to return the choosen image transparently to the ImageLoader. 26 (WebCore::HTMLImageElement::updateBestImageForScaleFactor): 27 New method to select the good image candidate dependending on the scale factor. This method is separated from 28 parsing because it will be useful for selecting a new image candidate on the fly if the device scale factor changes. 29 (WebCore::HTMLImageElement::updateImagesFromSrcSet): 30 New method for parsing the srcset attribute and build a list of images with the corresponding scale factor. 31 (WebCore::HTMLImageElement::parseAttribute): 32 Adding support for processing the image candidates, select the good one and call ImageLoader for rendering. 33 * html/HTMLImageElement.h: 34 - Adding new methods declarations. 35 - Adding new type definition. 36 - Adding new variable member to store the URL of the choosen image. 37 - Adding new variable member to store the index of the src image. 38 - Adding new Vector to store the list of images after parsing. 39 * html/HTMLImageElement.idl: Adding srcset attribute for the differents existing bidings. 40 1 41 2013-08-01 Filip Pizlo <fpizlo@apple.com> 2 42 -
trunk/Source/WebCore/html/HTMLAttributeNames.in
r151827 r153624 312 312 spellcheck 313 313 src 314 srcset 314 315 srcdoc 315 316 srclang -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r151949 r153624 34 34 #include "HTMLNames.h" 35 35 #include "HTMLParserIdioms.h" 36 #include "Page.h" 36 37 #include "RenderImage.h" 37 38 #include "ScriptEventListener.h" 39 #include <wtf/NotFound.h> 38 40 39 41 using namespace std; … … 48 50 , m_form(form) 49 51 , m_compositeOperator(CompositeSourceOver) 52 , m_bestFitImageURL(nullAtom) 53 , m_srcImageIndex(notFound) 50 54 { 51 55 ASSERT(hasTagName(imgTag)); … … 109 113 } 110 114 115 const AtomicString& HTMLImageElement::imageSourceURL() const 116 { 117 return m_bestFitImageURL == nullAtom ? getAttribute(srcAttr) : m_bestFitImageURL; 118 } 119 120 void HTMLImageElement::updateBestImageForScaleFactor() 121 { 122 float pageScaleFactor = 1.0; 123 124 m_bestFitImageURL = nullAtom; 125 if (Page* page = document()->page()) 126 pageScaleFactor = page->deviceScaleFactor(); 127 for (size_t i = 0; i < m_imagesWithScale.size(); ++i) { 128 if (m_imagesWithScale[i].scaleFactor >= pageScaleFactor) { 129 m_bestFitImageURL = m_imagesWithScale[i].imageURL; 130 return; 131 } 132 } 133 } 134 135 void HTMLImageElement::updateImagesFromSrcSet(const AtomicString& srcset) 136 { 137 const String& string = static_cast<const String&>(srcset); 138 Vector<String> srcSet; 139 140 string.split(',', srcSet); 141 for (size_t i = 0; i < srcSet.size(); ++i) { 142 Vector<String> data; 143 float imgScaleFactor = 1.0; 144 bool validScaleFactor = false; 145 146 srcSet[i].stripWhiteSpace().split(' ', data); 147 if (data.size() > 0 && data.last().endsWith('x')) { 148 imgScaleFactor = data.last().substring(0, data.last().length() - 1).toFloat(&validScaleFactor); 149 if (!validScaleFactor) 150 imgScaleFactor = 1.0; 151 } 152 if (!data.size() || (data.size() == 1 && validScaleFactor)) 153 continue; 154 ImageWithScale image; 155 image.imageURL = data[0]; 156 image.scaleFactor = imgScaleFactor; 157 m_imagesWithScale.append(image); 158 } 159 const AtomicString& src = getAttribute(srcAttr); 160 ImageWithScale image; 161 if (!src.isEmpty()) { 162 image.imageURL = getAttribute(srcAttr); 163 image.scaleFactor = 1.0; 164 m_imagesWithScale.append(image); 165 } 166 stable_sort(m_imagesWithScale.begin(), m_imagesWithScale.end(), compareByScaleFactor); 167 168 for (size_t i = 1; i < m_imagesWithScale.size(); ++i) { 169 if (m_imagesWithScale[i-1].scaleFactor == m_imagesWithScale[i].scaleFactor) { 170 m_imagesWithScale.remove(i); 171 i--; 172 } 173 } 174 if (!src.isEmpty()) 175 m_srcImageIndex = m_imagesWithScale.find(image); 176 } 177 111 178 void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 112 179 { … … 114 181 if (renderer() && renderer()->isImage()) 115 182 toRenderImage(renderer())->updateAltText(); 116 } else if (name == srcAttr) 183 } else if (name == srcAttr) { 184 if (m_srcImageIndex != notFound) 185 m_imagesWithScale.remove(m_srcImageIndex); 186 updateImagesFromSrcSet(value); 187 updateBestImageForScaleFactor(); 117 188 m_imageLoader.updateFromElementIgnoringPreviousError(); 189 } else if (name == srcsetAttr) { 190 m_imagesWithScale.clear(); 191 updateImagesFromSrcSet(value); 192 updateBestImageForScaleFactor(); 193 m_imageLoader.updateFromElementIgnoringPreviousError(); 194 } 118 195 else if (name == usemapAttr) 119 196 setIsLink(!value.isNull()); -
trunk/Source/WebCore/html/HTMLImageElement.h
r152353 r153624 77 77 virtual bool canContainRangeEndPoint() const { return false; } 78 78 79 virtual const AtomicString& imageSourceURL() const OVERRIDE; 80 79 81 protected: 80 82 HTMLImageElement(const QualifiedName&, Document*, HTMLFormElement* = 0); … … 108 110 #endif 109 111 112 void updateImagesFromSrcSet(const AtomicString& srcset); 113 114 void updateBestImageForScaleFactor(); 115 116 struct ImageWithScale { 117 String imageURL; 118 float scaleFactor; 119 bool operator==(const ImageWithScale& image) const 120 { 121 return scaleFactor == image.scaleFactor && imageURL == image.imageURL; 122 } 123 }; 124 125 static inline bool compareByScaleFactor(const ImageWithScale& first, const ImageWithScale& second) 126 { 127 return first.scaleFactor < second.scaleFactor; 128 } 129 110 130 HTMLImageLoader m_imageLoader; 111 131 HTMLFormElement* m_form; 112 132 CompositeOperator m_compositeOperator; 133 AtomicString m_bestFitImageURL; 134 size_t m_srcImageIndex; 135 Vector<ImageWithScale> m_imagesWithScale; 113 136 }; 114 137 -
trunk/Source/WebCore/html/HTMLImageElement.idl
r147857 r153624 32 32 [Reflect, URL] attribute DOMString longDesc; 33 33 [Reflect, URL] attribute DOMString src; 34 [Reflect] attribute DOMString srcset; 34 35 [Reflect] attribute DOMString useMap; 35 36 [Reflect] attribute long vspace;
Note: See TracChangeset
for help on using the changeset viewer.