JSValue* JSCSSRule::getValueProperty(ExecState* exec, int token) const { switch (token) { case TypeAttrNum: { CSSRule* imp = static_cast<CSSRule*>(impl()); return jsNumber(imp->type()); } case CssTextAttrNum: { CSSRule* imp = static_cast<CSSRule*>(impl()); return jsStringOrNull(imp->cssText()); } case ParentStyleSheetAttrNum: { CSSRule* imp = static_cast<CSSRule*>(impl()); return toJS(exec, WTF::getPtr(imp->parentStyleSheet())); } case ParentRuleAttrNum: { CSSRule* imp = static_cast<CSSRule*>(impl()); return toJS(exec, WTF::getPtr(imp->parentRule())); } case ConstructorAttrNum: return getConstructor(exec); } return 0; }
JSValue jsCSSRuleCssText(ExecState* exec, JSValue slotBase, const Identifier&) { JSCSSRule* castedThis = static_cast<JSCSSRule*>(asObject(slotBase)); UNUSED_PARAM(exec); CSSRule* imp = static_cast<CSSRule*>(castedThis->impl()); JSValue result = jsStringOrNull(exec, imp->cssText()); return result; }
void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const KURL& url) { StringBuilder cssText; for (unsigned i = 0; i < styleSheet->length(); ++i) { CSSRule* rule = styleSheet->item(i); String itemText = rule->cssText(); if (!itemText.isEmpty()) { cssText.append(itemText); if (i < styleSheet->length() - 1) cssText.append("\n\n"); } Document* document = styleSheet->findDocument(); // Some rules have resources associated with them that we need to retrieve. if (rule->isImportRule()) { CSSImportRule* importRule = static_cast<CSSImportRule*>(rule); KURL importURL = document->completeURL(importRule->href()); if (m_resourceURLs.contains(importURL)) continue; serializeCSSStyleSheet(importRule->styleSheet(), importURL); } else if (rule->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 (rule->isStyleRule()) retrieveResourcesForCSSRule(static_cast<CSSStyleRule*>(rule), document); } 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); } }
void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const KURL& url) { StringBuilder cssText; for (unsigned i = 0; i < styleSheet->length(); ++i) { CSSRule* rule = styleSheet->item(i); String itemText = rule->cssText(); if (!itemText.isEmpty()) { cssText.append(itemText); if (i < styleSheet->length() - 1) cssText.append("\n\n"); } Document* document = styleSheet->ownerDocument(); // Some rules have resources associated with them that we need to retrieve. if (rule->type() == CSSRule::IMPORT_RULE) { CSSImportRule* importRule = toCSSImportRule(rule); KURL importURL = document->completeURL(importRule->href()); if (m_resourceURLs.contains(importURL)) continue; serializeCSSStyleSheet(importRule->styleSheet(), importURL); } else if (rule->type() == CSSRule::FONT_FACE_RULE) { retrieveResourcesForProperties(toCSSFontFaceRule(rule)->styleRule()->properties(), document); } else if (rule->type() == CSSRule::STYLE_RULE) { retrieveResourcesForProperties(toCSSStyleRule(rule)->styleRule()->properties(), document); } } if (url.isValid() && !m_resourceURLs.contains(url)) { // FIXME: We should check whether a charset has been specified and if none was found add one. WTF::TextEncoding textEncoding(styleSheet->contents()->charset()); ASSERT(textEncoding.isValid()); String textString = cssText.toString(); CString text = textEncoding.normalizeAndEncode(textString, WTF::EntitiesForUnencodables); m_resources->append(SerializedResource(url, String("text/css"), SharedBuffer::create(text.data(), text.length()))); m_resourceURLs.add(url); } }
static v8::Handle<v8::Value> cssTextAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { CSSRule* imp = V8CSSRule::toNative(info.Holder()); return v8StringOrNull(imp->cssText(), info.GetIsolate()); }