void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const KURL& url) { StringBuilder cssText; for (unsigned i = 0; i < styleSheet->length(); ++i) { StyleBase* item = styleSheet->item(i); String itemText = item->cssText(); if (!itemText.isEmpty()) { cssText.append(itemText); if (i < styleSheet->length() - 1) cssText.append("\n\n"); } // Some rules have resources associated with them that we need to retrieve. if (item->isImportRule()) { CSSImportRule* importRule = static_cast<CSSImportRule*>(item); KURL importURL = styleSheet->document()->completeURL(importRule->href()); if (m_resourceURLs.contains(importURL)) continue; serializeCSSStyleSheet(importRule->styleSheet(), importURL); } else if (item->isFontFaceRule()) { // FIXME: Add support for font face rule. It is not clear to me at this point if the actual otf/eot file can // be retrieved from the CSSFontFaceRule object. } else if (item->isStyleRule()) retrieveResourcesForCSSRule(static_cast<CSSStyleRule*>(item)); } if (url.isValid() && !m_resourceURLs.contains(url)) { // FIXME: We should check whether a charset has been specified and if none was found add one. TextEncoding textEncoding(styleSheet->charset()); ASSERT(textEncoding.isValid()); String textString = cssText.toString(); CString text = textEncoding.encode(textString.characters(), textString.length(), EntitiesForUnencodables); m_resources->append(Resource(url, String("text/css"), SharedBuffer::create(text.data(), text.length()))); m_resourceURLs.add(url); } }
bool CSSStyleSheet::isLoading() { unsigned len = length(); for (unsigned i = 0; i < len; ++i) { StyleBase* rule = item(i); if (rule->isImportRule() && static_cast<CSSImportRule*>(rule)->isLoading()) return true; } return false; }
bool XSLStyleSheet::isLoading() { unsigned len = length(); for (unsigned i = 0; i < len; ++i) { StyleBase* rule = item(i); if (rule->isImportRule()) { XSLImportRule* import = static_cast<XSLImportRule*>(rule); if (import->isLoading()) return true; } } return false; }
void XSLStyleSheet::clearDocuments() { m_stylesheetDoc = 0; unsigned len = length(); for (unsigned i = 0; i < len; ++i) { StyleBase* rule = item(i); if (rule->isImportRule()) { XSLImportRule* import = static_cast<XSLImportRule*>(rule); if (import->styleSheet()) import->styleSheet()->clearDocuments(); } } }
xmlDocPtr XSLStyleSheet::locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri) { bool matchedParent = (parentDoc == document()); unsigned len = length(); for (unsigned i = 0; i < len; ++i) { StyleBase* rule = item(i); if (rule->isImportRule()) { XSLImportRule* import = static_cast<XSLImportRule*>(rule); XSLStyleSheet* child = import->styleSheet(); if (!child) continue; if (matchedParent) { if (child->processed()) continue; // libxslt has been given this sheet already. // Check the URI of the child stylesheet against the doc URI. // In order to ensure that libxml canonicalized both URLs, we get the original href // string from the import rule and canonicalize it using libxml before comparing it // with the URI argument. CString importHref = import->href().utf8(); xmlChar* base = xmlNodeGetBase(parentDoc, (xmlNodePtr)parentDoc); xmlChar* childURI = xmlBuildURI((const xmlChar*)importHref.data(), base); bool equalURIs = xmlStrEqual(uri, childURI); xmlFree(base); xmlFree(childURI); if (equalURIs) { child->markAsProcessed(); return child->document(); } } else { xmlDocPtr result = import->styleSheet()->locateStylesheetSubResource(parentDoc, uri); if (result) return result; } } } return 0; }