void InspectorCSSOMWrappers::collect(ListType* listType)
{
    if (!listType)
        return;
    unsigned size = listType->length();
    for (unsigned i = 0; i < size; ++i) {
        CSSRule* cssRule = listType->item(i);
        switch (cssRule->type()) {
        case CSSRule::IMPORT_RULE:
            collect(downcast<CSSImportRule>(*cssRule).styleSheet());
            break;
        case CSSRule::MEDIA_RULE:
            collect(downcast<CSSMediaRule>(cssRule));
            break;
        case CSSRule::SUPPORTS_RULE:
            collect(downcast<CSSSupportsRule>(cssRule));
            break;
#if ENABLE(CSS_REGIONS)
        case CSSRule::WEBKIT_REGION_RULE:
            collect(downcast<WebKitCSSRegionRule>(cssRule));
            break;
#endif
        case CSSRule::STYLE_RULE:
            m_styleRuleToCSSOMWrapperMap.add(&downcast<CSSStyleRule>(*cssRule).styleRule(), downcast<CSSStyleRule>(cssRule));
            break;
        default:
            break;
        }
    }
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
JSValue jsCSSRuleType(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 = jsNumber(imp->type());
    return result;
}
Exemplo n.º 4
0
void CSSRule::assignOther( const CSSRule &other, RuleType thisType )
{
    if (other.type() != thisType ) {
	if ( impl ) impl->deref();
	impl = 0;
    } else
	CSSRule::operator = ( other );
}
Exemplo n.º 5
0
CSSStyleRule* InspectorCSSStore::asCSSStyleRule(StyleBase* styleBase)
{
    if (!styleBase->isStyleRule())
        return 0;
    CSSRule* rule = static_cast<CSSRule*>(styleBase);
    if (rule->type() != CSSRule::STYLE_RULE)
        return 0;
    return static_cast<CSSStyleRule*>(rule);
}
Exemplo n.º 6
0
RefPtr<CSSRuleList> CSSStyleSheet::rules()
{
    if (!canAccessRules())
        return nullptr;
    // IE behavior.
    RefPtr<StaticCSSRuleList> nonCharsetRules = StaticCSSRuleList::create();
    unsigned ruleCount = length();
    for (unsigned i = 0; i < ruleCount; ++i) {
        CSSRule* rule = item(i);
        if (rule->type() == CSSRule::CHARSET_RULE)
            continue;
        nonCharsetRules->rules().append(rule);
    }
    return nonCharsetRules;
}
Exemplo n.º 7
0
void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const URL& 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);
            URL importURL = document->completeURL(importRule->href());
            if (m_resourceURLs.contains(importURL))
                continue;
            serializeCSSStyleSheet(importRule->styleSheet(), importURL);
        } else if (rule->type() == CSSRule::FONT_FACE_RULE) {
            // 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->type() == CSSRule::STYLE_RULE)
            retrieveResourcesForRule(toCSSStyleRule(rule)->styleRule(), 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->contents().charset());
        ASSERT(textEncoding.isValid());
        String textString = cssText.toString();
        CString text = textEncoding.encode(textString, EntitiesForUnencodables);
        m_resources->append(Resource(url, String("text/css"), SharedBuffer::create(text.data(), text.length())));
        m_resourceURLs.add(url);
    }
}
static CSSStyleSheet* findStyleSheet(StyleEngine* styleEngine, StyleRule* rule)
{
    // FIXME: StyleEngine has a bunch of different accessors for StyleSheet lists, is this the only one we need to care about?
    const Vector<RefPtr<CSSStyleSheet> >& stylesheets = styleEngine->activeAuthorStyleSheets();
    for (size_t i = 0; i < stylesheets.size(); ++i) {
        CSSStyleSheet* sheet = stylesheets[i].get();
        for (unsigned j = 0; j < sheet->length(); ++j) {
            CSSRule* cssRule = sheet->item(j);
            if (cssRule->type() != CSSRule::STYLE_RULE)
                continue;
            CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule);
            if (cssStyleRule->styleRule() == rule)
                return sheet;
        }
    }
    return 0;
}
Exemplo n.º 9
0
CSSRule* ElementRuleCollector::findStyleRule(CSSRuleCollection* cssRules, StyleRule* styleRule)
{
    if (!cssRules)
        return 0;
    CSSRule* result = 0;
    for (unsigned i = 0; i < cssRules->length() && !result; ++i) {
        CSSRule* cssRule = cssRules->item(i);
        CSSRule::Type cssRuleType = cssRule->type();
        if (cssRuleType == CSSRule::STYLE_RULE) {
            CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule);
            if (cssStyleRule->styleRule() == styleRule)
                result = cssRule;
        } else {
            result = findStyleRule(nestedRuleList(cssRule), styleRule);
        }
    }
    return result;
}
Exemplo n.º 10
0
void CSSStyleSheet::addSubresourceURLStrings(HashSet<String>& urls, const String& base) const
{        
    RefPtr<CSSRuleList> ruleList = const_cast<CSSStyleSheet*>(this)->cssRules();
    
    // Add the URLs for each child import rule, and recurse for the stylesheet belonging to each of those rules.
    for (unsigned i = 0; i < ruleList->length(); ++i) {
        CSSRule* rule = ruleList->item(i);
        if (rule->type() != CSSRule::IMPORT_RULE)
            continue;

        CSSImportRule* importRule = static_cast<CSSImportRule*>(rule);
        CSSStyleSheet* ruleSheet = importRule->styleSheet();
        if (!ruleSheet)
            continue;

        KURL fullURL(KURL(base), importRule->href());
        urls.add(fullURL.string());
        ruleSheet->addSubresourceURLStrings(urls, fullURL.string());
    }
}
Exemplo n.º 11
0
CSSRule* ElementRuleCollector::findStyleRule(CSSRuleCollection* cssRules,
                                             StyleRule* styleRule) {
  if (!cssRules)
    return nullptr;
  CSSRule* result = 0;
  for (unsigned i = 0; i < cssRules->length() && !result; ++i) {
    CSSRule* cssRule = cssRules->item(i);
    CSSRule::Type cssRuleType = cssRule->type();
    if (cssRuleType == CSSRule::kStyleRule) {
      CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule);
      if (cssStyleRule->styleRule() == styleRule)
        result = cssRule;
    } else if (cssRuleType == CSSRule::kImportRule) {
      CSSImportRule* cssImportRule = toCSSImportRule(cssRule);
      result = findStyleRule(cssImportRule->styleSheet(), styleRule);
    } else {
      result = findStyleRule(cssRule->cssRules(), styleRule);
    }
  }
  return result;
}
Exemplo n.º 12
0
void CSSStyleSheet::extraCSSOMWrapperIndices(Vector<unsigned>& indices)
{
    indices.grow(m_extraChildRuleCSSOMWrappers.size());

    for (unsigned i = 0; i < m_extraChildRuleCSSOMWrappers.size(); ++i) {
        CSSRule* cssRule = m_extraChildRuleCSSOMWrappers[i].get();
        ASSERT(cssRule->type() == CSSRule::STYLE_RULE);
        StyleRule* styleRule = toCSSStyleRule(cssRule)->styleRule();

        bool didFindIndex = false;
        for (unsigned j = 0; j < m_contents->ruleCount(); ++j) {
            if (m_contents->ruleAt(j) == styleRule) {
                didFindIndex = true;
                indices[i] = j;
                break;
            }
        }
        ASSERT(didFindIndex);
        if (!didFindIndex)
            indices[i] = 0;
    }
}
static v8::Handle<v8::Value> typeAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    CSSRule* imp = V8CSSRule::toNative(info.Holder());
    return v8Integer(imp->type(), info.GetIsolate());
}