Clean up some ENABLE(PICTURE_SIZES) stuff, don't change function signatures inside...
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Sep 2014 15:54:40 +0000 (15:54 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Sep 2014 15:54:40 +0000 (15:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136654

Reviewed by Darin Adler.

Adding parameters inside an #ifdef makes for unreadable code, so remove some
#if ENABLE(PICTURE_SIZES) related to the preload scanner and always pass the arguments.
Reduced the argument count on some functions by just passing a Document&.

Also fix a couple of uses of #if ENABLE_PICTURE_SIZES.

* html/HTMLImageElement.h:
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::pumpTokenizer):
(WebCore::HTMLDocumentParser::insert):
(WebCore::HTMLDocumentParser::append):
(WebCore::HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan):
* html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::scan):
(WebCore::HTMLPreloadScanner::scan):
* html/parser/HTMLPreloadScanner.h:
* html/parser/HTMLSrcsetParser.cpp:
(WebCore::pickBestImageCandidate):
(WebCore::bestFitSourceForImageAttributes):
* html/parser/HTMLSrcsetParser.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173464 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/parser/HTMLDocumentParser.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.h
Source/WebCore/html/parser/HTMLSrcsetParser.cpp
Source/WebCore/html/parser/HTMLSrcsetParser.h

index aac9632..0e6a00c 100644 (file)
@@ -1,3 +1,31 @@
+2014-09-10  Simon Fraser  <simon.fraser@apple.com>
+
+        Clean up some ENABLE(PICTURE_SIZES) stuff, don't change function signatures inside #ifdefs
+        https://bugs.webkit.org/show_bug.cgi?id=136654
+
+        Reviewed by Darin Adler.
+
+        Adding parameters inside an #ifdef makes for unreadable code, so remove some
+        #if ENABLE(PICTURE_SIZES) related to the preload scanner and always pass the arguments.
+        Reduced the argument count on some functions by just passing a Document&. 
+        
+        Also fix a couple of uses of #if ENABLE_PICTURE_SIZES.
+
+        * html/HTMLImageElement.h:
+        * html/parser/HTMLDocumentParser.cpp:
+        (WebCore::HTMLDocumentParser::pumpTokenizer):
+        (WebCore::HTMLDocumentParser::insert):
+        (WebCore::HTMLDocumentParser::append):
+        (WebCore::HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan):
+        * html/parser/HTMLPreloadScanner.cpp:
+        (WebCore::TokenPreloadScanner::scan):
+        (WebCore::HTMLPreloadScanner::scan):
+        * html/parser/HTMLPreloadScanner.h:
+        * html/parser/HTMLSrcsetParser.cpp:
+        (WebCore::pickBestImageCandidate):
+        (WebCore::bestFitSourceForImageAttributes):
+        * html/parser/HTMLSrcsetParser.h:
+
 2014-09-10  Chris Fleizach  <cfleizach@apple.com>
 
         AX: aria-labelledby is not honoring sub-node text
index 7cfbf70..324948b 100644 (file)
@@ -48,7 +48,7 @@ public:
 
     int naturalWidth() const;
     int naturalHeight() const;
-#if ENABLE_PICTURE_SIZES
+#if ENABLE(PICTURE_SIZES)
     const AtomicString& currentSrc() const { return m_currentSrc; }
 #endif
 
@@ -127,7 +127,7 @@ private:
     HTMLFormElement* m_form;
     CompositeOperator m_compositeOperator;
     AtomicString m_bestFitImageURL;
-#if ENABLE_PICTURE_SIZES
+#if ENABLE(PICTURE_SIZES)
     AtomicString m_currentSrc;
 #endif
     AtomicString m_lowercasedUsemap;
index 7483f13..e0fb5fc 100644 (file)
@@ -326,11 +326,7 @@ void HTMLDocumentParser::pumpTokenizer(SynchronousMode mode)
             m_preloadScanner = std::make_unique<HTMLPreloadScanner>(m_options, document()->url(), document()->deviceScaleFactor());
             m_preloadScanner->appendToEnd(m_input.current());
         }
-        m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()
-#if ENABLE(PICTURE_SIZES)
-            , document()->renderView(), document()->frame()
-#endif
-        );
+        m_preloadScanner->scan(m_preloader.get(), *document());
     }
 
     InspectorInstrumentation::didWriteHTML(cookie, m_input.current().currentLine().zeroBasedInt());
@@ -392,11 +388,7 @@ void HTMLDocumentParser::insert(const SegmentedString& source)
             m_insertionPreloadScanner = std::make_unique<HTMLPreloadScanner>(m_options, document()->url(), document()->deviceScaleFactor());
         }
         m_insertionPreloadScanner->appendToEnd(source);
-        m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseElementURL()
-#if ENABLE(PICTURE_SIZES)
-            , document()->renderView(), document()->frame()
-#endif
-        );
+        m_insertionPreloadScanner->scan(m_preloader.get(), *document());
     }
 
     endIfDelayed();
@@ -420,11 +412,7 @@ void HTMLDocumentParser::append(PassRefPtr<StringImpl> inputSource)
         } else {
             m_preloadScanner->appendToEnd(source);
             if (isWaitingForScripts())
-                m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()
-#if ENABLE(PICTURE_SIZES)
-                    , document()->renderView(), document()->frame()
-#endif
-                );
+                m_preloadScanner->scan(m_preloader.get(), *document());
         }
     }
 
@@ -562,11 +550,7 @@ void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan()
 {
     ASSERT(m_preloadScanner);
     m_preloadScanner->appendToEnd(m_input.current());
-    m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()
-#if ENABLE(PICTURE_SIZES)
-        , document()->renderView(), document()->frame()
-#endif
-    );
+    m_preloadScanner->scan(m_preloader.get(), *document());
 }
 
 void HTMLDocumentParser::notifyFinished(CachedResource* cachedResource)
index 566ea62..5695cd6 100644 (file)
@@ -93,15 +93,12 @@ public:
     {
     }
 
-    void processAttributes(const HTMLToken::AttributeList& attributes
-#if ENABLE(PICTURE_SIZES)
-        , RenderView* view, Frame* frame
-#endif
-        )
+    void processAttributes(const HTMLToken::AttributeList& attributes, Document& document)
     {
         ASSERT(isMainThread());
         if (m_tagId >= TagId::Unknown)
             return;
+
         for (HTMLToken::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) {
             AtomicString attributeName(iter->name);
             String attributeValue = StringImpl::create8BitIfPossible(iter->value);
@@ -110,11 +107,11 @@ public:
 
         // Resolve between src and srcSet if we have them.
         if (!m_srcSetAttribute.isEmpty()) {
-            ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute
+            unsigned sourceSize = 0;
 #if ENABLE(PICTURE_SIZES)
-                , SourceSizeList::parseSizesAttribute(m_sizesAttribute, view, frame)
+            sourceSize = SourceSizeList::parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
 #endif
-                );
+            ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize);
             setUrlToLoad(imageCandidate.string.toString(), true);
         }
     }
@@ -279,11 +276,7 @@ void TokenPreloadScanner::rewindTo(TokenPreloadScannerCheckpoint checkpointIndex
     m_checkpoints.clear();
 }
 
-void TokenPreloadScanner::scan(const HTMLToken& token, Vector<std::unique_ptr<PreloadRequest>>& requests
-#if ENABLE(PICTURE_SIZES)
-        , RenderView* view, Frame* frame
-#endif
-        )
+void TokenPreloadScanner::scan(const HTMLToken& token, Vector<std::unique_ptr<PreloadRequest>>& requests, Document& document)
 {
     switch (token.type()) {
     case HTMLToken::Character:
@@ -334,11 +327,7 @@ void TokenPreloadScanner::scan(const HTMLToken& token, Vector<std::unique_ptr<Pr
         }
 
         StartTagScanner scanner(tagId, m_deviceScaleFactor);
-        scanner.processAttributes(token.attributes()
-#if ENABLE(PICTURE_SIZES)
-            , view, frame
-#endif
-            );
+        scanner.processAttributes(token.attributes(), document);
         if (auto request = scanner.createPreloadRequest(m_predictedBaseElementURL))
             requests.append(WTF::move(request));
         return;
@@ -372,14 +361,12 @@ void HTMLPreloadScanner::appendToEnd(const SegmentedString& source)
     m_source.append(source);
 }
 
-void HTMLPreloadScanner::scan(HTMLResourcePreloader* preloader, const URL& startingBaseElementURL
-#if ENABLE(PICTURE_SIZES)
-        , RenderView* view, Frame* frame
-#endif
-        )
+void HTMLPreloadScanner::scan(HTMLResourcePreloader* preloader, Document& document)
 {
     ASSERT(isMainThread()); // HTMLTokenizer::updateStateFor only works on the main thread.
 
+    const URL& startingBaseElementURL = document.baseElementURL();
+
     // When we start scanning, our best prediction of the baseElementURL is the real one!
     if (!startingBaseElementURL.isEmpty())
         m_scanner.setPredictedBaseElementURL(startingBaseElementURL);
@@ -389,11 +376,7 @@ void HTMLPreloadScanner::scan(HTMLResourcePreloader* preloader, const URL& start
     while (m_tokenizer->nextToken(m_source, m_token)) {
         if (m_token.type() == HTMLToken::StartTag)
             m_tokenizer->updateStateFor(AtomicString(m_token.name()));
-        m_scanner.scan(m_token, requests
-#if ENABLE(PICTURE_SIZES)
-            , view, frame
-#endif
-            );
+        m_scanner.scan(m_token, requests, document);
         m_token.clear();
     }
 
index b67a51a..d2e3d1c 100644 (file)
@@ -47,11 +47,7 @@ public:
     explicit TokenPreloadScanner(const URL& documentURL, float deviceScaleFactor = 1.0);
     ~TokenPreloadScanner();
 
-    void scan(const HTMLToken&, PreloadRequestStream& requests
-#if ENABLE_PICTURE_SIZES
-        , RenderView*, Frame*
-#endif
-        );
+    void scan(const HTMLToken&, PreloadRequestStream& requests, Document&);
 
     void setPredictedBaseElementURL(const URL& url) { m_predictedBaseElementURL = url; }
 
@@ -131,11 +127,7 @@ public:
     ~HTMLPreloadScanner();
 
     void appendToEnd(const SegmentedString&);
-    void scan(HTMLResourcePreloader*, const URL& documentBaseElementURL
-#if ENABLE_PICTURE_SIZES
-        , RenderView*, Frame*
-#endif
-        );
+    void scan(HTMLResourcePreloader*, Document&);
 
 private:
     TokenPreloadScanner m_scanner;
index f2f1a5f..b5acefa 100644 (file)
@@ -229,12 +229,12 @@ Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(StringView attrib
         return parseImageCandidatesFromSrcsetAttribute<UChar>(attribute.characters16(), attribute.length());
 }
 
-static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<ImageCandidate>& imageCandidates
-#if ENABLE(PICTURE_SIZES)
-    , unsigned sourceSize
-#endif
-    )
+static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<ImageCandidate>& imageCandidates, unsigned sourceSize)
 {
+#if !ENABLE(PICTURE_SIZES)
+    UNUSED_PARAM(sourceSize);
+#endif
+
     bool ignoreSrc = false;
     if (imageCandidates.isEmpty())
         return ImageCandidate();
@@ -274,11 +274,7 @@ static ImageCandidate pickBestImageCandidate(float deviceScaleFactor, Vector<Ima
     return imageCandidates[winner];
 }
 
-ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute
-#if ENABLE(PICTURE_SIZES)
-    , unsigned sourceSize
-#endif
-    )
+ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, unsigned sourceSize)
 {
     if (srcsetAttribute.isNull()) {
         if (srcAttribute.isNull())
@@ -291,11 +287,7 @@ ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const At
     if (!srcAttribute.isEmpty())
         imageCandidates.append(ImageCandidate(StringView(srcAttribute), DescriptorParsingResult(), ImageCandidate::SrcOrigin));
 
-    return pickBestImageCandidate(deviceScaleFactor, imageCandidates
-#if ENABLE(PICTURE_SIZES)
-        , sourceSize
-#endif
-        );
+    return pickBestImageCandidate(deviceScaleFactor, imageCandidates, sourceSize);
 }
 
 } // namespace WebCore
index 7b6edaf..df9486d 100644 (file)
@@ -98,11 +98,7 @@ struct ImageCandidate {
     OriginAttribute originAttribute;
 };
 
-ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute
-#if ENABLE(PICTURE_SIZES)
-    , unsigned sourceSize
-#endif
-    );
+ImageCandidate bestFitSourceForImageAttributes(float deviceScaleFactor, const AtomicString& srcAttribute, const AtomicString& srcsetAttribute, unsigned sourceSize);
 
 Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(StringView attribute);