Title: [155176] trunk/Source/WebCore
Revision
155176
Author
[email protected]
Date
2013-09-05 22:48:40 -0700 (Thu, 05 Sep 2013)

Log Message

DRY out srcset related deviceScaleFactor calculations
https://bugs.webkit.org/show_bug.cgi?id=120791

Identical deviceScaleFactor calculations were performed in 3 different locations.
I've added that calculation as a method of Document.
Previous calculations are replaced by calls to this method.

Patch by Yoav Weiss <[email protected]> on 2013-09-05
Reviewed by Andreas Kling.

No new tests since this is a refactoring change. No functionality have changed.

* dom/Document.cpp:
(WebCore::Document::deviceScaleFactor):
* dom/Document.h:
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseAttribute):
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::pumpTokenizer):
(WebCore::HTMLDocumentParser::insert):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (155175 => 155176)


--- trunk/Source/WebCore/ChangeLog	2013-09-06 05:47:21 UTC (rev 155175)
+++ trunk/Source/WebCore/ChangeLog	2013-09-06 05:48:40 UTC (rev 155176)
@@ -1,3 +1,25 @@
+2013-09-05  Yoav Weiss  <[email protected]>
+
+        DRY out srcset related deviceScaleFactor calculations
+        https://bugs.webkit.org/show_bug.cgi?id=120791
+
+        Identical deviceScaleFactor calculations were performed in 3 different locations.
+        I've added that calculation as a method of Document.
+        Previous calculations are replaced by calls to this method.
+
+        Reviewed by Andreas Kling.
+
+        No new tests since this is a refactoring change. No functionality have changed.
+
+        * dom/Document.cpp:
+        (WebCore::Document::deviceScaleFactor):
+        * dom/Document.h:
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::parseAttribute):
+        * html/parser/HTMLDocumentParser.cpp:
+        (WebCore::HTMLDocumentParser::pumpTokenizer):
+        (WebCore::HTMLDocumentParser::insert):
+
 2013-09-05  Brendan Long  <[email protected]>
 
         [Qt] DefaultFullScreenVideoHandler and PlatformVideoWindow are included in the build when they are disabled

Modified: trunk/Source/WebCore/dom/Document.cpp (155175 => 155176)


--- trunk/Source/WebCore/dom/Document.cpp	2013-09-06 05:47:21 UTC (rev 155175)
+++ trunk/Source/WebCore/dom/Document.cpp	2013-09-06 05:48:40 UTC (rev 155176)
@@ -5958,6 +5958,13 @@
 }
 #endif
 
+float Document::deviceScaleFactor() const
+{
+    float deviceScaleFactor = 1.0;
+    if (Page* documentPage = page())
+        deviceScaleFactor = documentPage->deviceScaleFactor();
+    return deviceScaleFactor;
+}
 void Document::didAssociateFormControl(Element* element)
 {
     if (!frame() || !frame()->page() || !frame()->page()->chrome().client().shouldNotifyOnFormChanges())

Modified: trunk/Source/WebCore/dom/Document.h (155175 => 155176)


--- trunk/Source/WebCore/dom/Document.h	2013-09-06 05:47:21 UTC (rev 155175)
+++ trunk/Source/WebCore/dom/Document.h	2013-09-06 05:48:40 UTC (rev 155176)
@@ -496,6 +496,8 @@
     Page* page() const; // can be NULL
     Settings* settings() const; // can be NULL
 
+    float deviceScaleFactor() const;
+
     PassRefPtr<Range> createRange();
 
     PassRefPtr<NodeIterator> createNodeIterator(Node* root, unsigned whatToShow,

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (155175 => 155176)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2013-09-06 05:47:21 UTC (rev 155175)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2013-09-06 05:48:40 UTC (rev 155176)
@@ -123,10 +123,7 @@
         if (renderer() && renderer()->isImage())
             toRenderImage(renderer())->updateAltText();
     } else if (name == srcAttr || name == srcsetAttr) {
-        float deviceScaleFactor = 1.0;
-        if (Page* page = document().page())
-            deviceScaleFactor = page->deviceScaleFactor();
-        m_bestFitImageURL = bestFitSourceForImageAttributes(deviceScaleFactor, fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr));
+        m_bestFitImageURL = bestFitSourceForImageAttributes(document().deviceScaleFactor(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr));
         m_imageLoader.updateFromElementIgnoringPreviousError();
     } else if (name == usemapAttr)
         setIsLink(!value.isNull() && !shouldProhibitLinks(this));

Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp (155175 => 155176)


--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-09-06 05:47:21 UTC (rev 155175)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-09-06 05:48:40 UTC (rev 155176)
@@ -566,10 +566,7 @@
     if (isWaitingForScripts()) {
         ASSERT(m_tokenizer->state() == HTMLTokenizer::DataState);
         if (!m_preloadScanner) {
-            float deviceScaleFactor = 1.0;
-            if (Page* page = document()->page())
-                deviceScaleFactor = page->deviceScaleFactor();
-            m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, document()->url(), deviceScaleFactor));
+            m_preloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, document()->url(), document()->deviceScaleFactor()));
             m_preloadScanner->appendToEnd(m_input.current());
         }
         m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL());
@@ -650,10 +647,7 @@
         // Check the document.write() output with a separate preload scanner as
         // the main scanner can't deal with insertions.
         if (!m_insertionPreloadScanner) {
-            float deviceScaleFactor = 1.0;
-            if (Page* page = document()->page())
-                deviceScaleFactor = page->deviceScaleFactor();
-            m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, document()->url(), deviceScaleFactor));
+            m_insertionPreloadScanner = adoptPtr(new HTMLPreloadScanner(m_options, document()->url(), document()->deviceScaleFactor()));
         }
         m_insertionPreloadScanner->appendToEnd(source);
         m_insertionPreloadScanner->scan(m_preloader.get(), document()->baseElementURL());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to