Commit 9bb7e125 authored by Andrea Iacovitti's avatar Andrea Iacovitti

Download a css image only when it is used/resolved by a style.

Previously all images specified in a stylesheet were downloaded at parsing time, regardless.
parent c71ae727
......@@ -37,8 +37,6 @@
#include <xml/dom_stringimpl.h>
#include <xml/dom_docimpl.h>
#include <misc/loader.h>
#include <rendering/font.h>
#include <rendering/render_style.h>
......@@ -1386,21 +1384,9 @@ CSSImageValueImpl::CSSImageValueImpl(const DOMString &url, StyleBaseImpl* style)
{
m_image = 0;
if (!url.isEmpty()) {
khtml::DocLoader *docLoader = 0;
const StyleBaseImpl *root = style;
while (root->parent()) {
root = root->parent();
}
if (root->isCSSStyleSheet()) {
docLoader = static_cast<const CSSStyleSheetImpl*>(root)->docLoader();
}
if (docLoader) {
KUrl fullURL(style->baseURL(), url.string());
m_image = docLoader->requestImage(fullURL.url());
if (m_image) {
m_image->ref(this);
}
}
m_fullImageUrl = KUrl(style->baseURL(), url.string()).url();
} else {
m_fullImageUrl.clear();
}
}
......@@ -1408,6 +1394,7 @@ CSSImageValueImpl::CSSImageValueImpl()
: CSSPrimitiveValueImpl(CSS_VAL_NONE)
{
m_image = 0;
m_fullImageUrl.clear();
}
CSSImageValueImpl::~CSSImageValueImpl()
......@@ -1415,6 +1402,17 @@ CSSImageValueImpl::~CSSImageValueImpl()
if(m_image) m_image->deref(this);
}
khtml::CachedImage *CSSImageValueImpl::requestCssImage(DocumentImpl* doc)
{
if (!m_image && !m_fullImageUrl.isEmpty()) {
m_image = doc->docLoader()->requestImage(m_fullImageUrl);
if (m_image) {
m_image->ref(this);
}
}
return m_image;
}
// ------------------------------------------------------------------------
FontFamilyValueImpl::FontFamilyValueImpl( const QString &string)
......
......@@ -365,9 +365,10 @@ public:
CSSImageValueImpl();
virtual ~CSSImageValueImpl();
khtml::CachedImage *image() { return m_image; }
khtml::CachedImage *requestCssImage(DocumentImpl*);
protected:
khtml::CachedImage *m_image;
QString m_fullImageUrl;
};
class FontFamilyValueImpl : public CSSPrimitiveValueImpl
......
......@@ -3097,8 +3097,7 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
{
HANDLE_INITIAL_AND_INHERIT_ON_INHERITED_PROPERTY(listStyleImage, ListStyleImage)
if (!primitiveValue) return;
style->setListStyleImage(static_cast<CSSImageValueImpl *>(primitiveValue)->image());
//kDebug( 6080 ) << "setting image in list to " << image->image();
style->setListStyleImage(static_cast<CSSImageValueImpl *>(primitiveValue)->requestCssImage(element->document()));
break;
}
......@@ -3692,7 +3691,7 @@ void CSSStyleSelector::applyRule( int id, DOM::CSSValueImpl *value )
else if (val->primitiveType()==CSSPrimitiveValue::CSS_URI)
{
CSSImageValueImpl *image = static_cast<CSSImageValueImpl *>(val);
style->addContent(image->image());
style->addContent(image->requestCssImage(element->document()));
}
else if (val->primitiveType()==CSSPrimitiveValue::CSS_COUNTER)
{
......@@ -4379,7 +4378,7 @@ void CSSStyleSelector::mapBackgroundImage(BackgroundLayer* layer, DOM::CSSValueI
if (!value->isPrimitiveValue()) return;
CSSPrimitiveValueImpl* primitiveValue = static_cast<CSSPrimitiveValueImpl*>(value);
layer->setBackgroundImage(static_cast<CSSImageValueImpl *>(primitiveValue)->image());
layer->setBackgroundImage(static_cast<CSSImageValueImpl *>(primitiveValue)->requestCssImage(element->document()));
}
void CSSStyleSelector::mapBackgroundRepeat(BackgroundLayer* layer, DOM::CSSValueImpl* value)
......
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