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 <yoav@yoav.ws> 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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@155176 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 934297ee
2013-09-05 Yoav Weiss <yoav@yoav.ws>
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 <b.long@cablelabs.com>
[Qt] DefaultFullScreenVideoHandler and PlatformVideoWindow are included in the build when they are disabled
......@@ -5958,6 +5958,13 @@ PassRefPtr<FontLoader> Document::fontloader()
}
#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())
......
......@@ -496,6 +496,8 @@ public:
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,
......
......@@ -123,10 +123,7 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
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));
......
......@@ -566,10 +566,7 @@ void HTMLDocumentParser::pumpTokenizer(SynchronousMode mode)
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 @@ void HTMLDocumentParser::insert(const SegmentedString& source)
// 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());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment