示例#1
0
StyleRuleBase* StyleRuleBase::copy() const {
  switch (type()) {
    case Style:
      return toStyleRule(this)->copy();
    case Page:
      return toStyleRulePage(this)->copy();
    case FontFace:
      return toStyleRuleFontFace(this)->copy();
    case Media:
      return toStyleRuleMedia(this)->copy();
    case Supports:
      return toStyleRuleSupports(this)->copy();
    case Import:
      // FIXME: Copy import rules.
      NOTREACHED();
      return nullptr;
    case Keyframes:
      return toStyleRuleKeyframes(this)->copy();
    case Viewport:
      return toStyleRuleViewport(this)->copy();
    case Namespace:
      return toStyleRuleNamespace(this)->copy();
    case Charset:
    case Keyframe:
      ASSERT_NOT_REACHED();
      return nullptr;
  }
  ASSERT_NOT_REACHED();
  return nullptr;
}
示例#2
0
bool StyleSheetContents::wrapperInsertRule(StyleRuleBase* rule,
        unsigned index) {
    ASSERT(m_isMutable);
    SECURITY_DCHECK(index <= ruleCount());

    if (index < m_importRules.size() ||
            (index == m_importRules.size() && rule->isImportRule())) {
        // Inserting non-import rule before @import is not allowed.
        if (!rule->isImportRule())
            return false;

        StyleRuleImport* importRule = toStyleRuleImport(rule);
        if (importRule->mediaQueries())
            setHasMediaQueries();

        m_importRules.insert(index, importRule);
        m_importRules[index]->setParentStyleSheet(this);
        m_importRules[index]->requestStyleSheet();
        // FIXME: Stylesheet doesn't actually change meaningfully before the
        // imported sheets are loaded.
        return true;
    }
    // Inserting @import rule after a non-import rule is not allowed.
    if (rule->isImportRule())
        return false;

    index -= m_importRules.size();

    if (index < m_namespaceRules.size() ||
            (index == m_namespaceRules.size() && rule->isNamespaceRule())) {
        // Inserting non-namespace rules other than import rule before @namespace is
        // not allowed.
        if (!rule->isNamespaceRule())
            return false;
        // Inserting @namespace rule when rules other than import/namespace/charset
        // are present is not allowed.
        if (!m_childRules.isEmpty())
            return false;

        StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule);
        m_namespaceRules.insert(index, namespaceRule);
        // For now to be compatible with IE and Firefox if namespace rule with same
        // prefix is added irrespective of adding the rule at any index, last added
        // rule's value is considered.
        // TODO ([email protected]): As per spec last valid rule should be
        // considered, which means if namespace rule is added in the middle of
        // existing namespace rules, rule which comes later in rule list with same
        // prefix needs to be considered.
        parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri());
        return true;
    }

    if (rule->isNamespaceRule())
        return false;

    index -= m_namespaceRules.size();

    m_childRules.insert(index, rule);
    return true;
}
示例#3
0
void StyleSheetContents::parserAppendRule(StyleRuleBase* rule) {
    if (rule->isImportRule()) {
        // Parser enforces that @import rules come before anything else
        ASSERT(m_childRules.isEmpty());
        StyleRuleImport* importRule = toStyleRuleImport(rule);
        if (importRule->mediaQueries())
            setHasMediaQueries();
        m_importRules.append(importRule);
        m_importRules.last()->setParentStyleSheet(this);
        m_importRules.last()->requestStyleSheet();
        return;
    }

    if (rule->isNamespaceRule()) {
        // Parser enforces that @namespace rules come before all rules other than
        // import/charset rules
        ASSERT(m_childRules.isEmpty());
        StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule);
        parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri());
        m_namespaceRules.append(&namespaceRule);
        return;
    }

    m_childRules.append(rule);
}
示例#4
0
CSSRule* StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet,
                                           CSSRule* parentRule) const {
  CSSRule* rule = nullptr;
  StyleRuleBase* self = const_cast<StyleRuleBase*>(this);
  switch (type()) {
    case Style:
      rule = CSSStyleRule::create(toStyleRule(self), parentSheet);
      break;
    case Page:
      rule = CSSPageRule::create(toStyleRulePage(self), parentSheet);
      break;
    case FontFace:
      rule = CSSFontFaceRule::create(toStyleRuleFontFace(self), parentSheet);
      break;
    case Media:
      rule = CSSMediaRule::create(toStyleRuleMedia(self), parentSheet);
      break;
    case Supports:
      rule = CSSSupportsRule::create(toStyleRuleSupports(self), parentSheet);
      break;
    case Import:
      rule = CSSImportRule::create(toStyleRuleImport(self), parentSheet);
      break;
    case Keyframes:
      rule = CSSKeyframesRule::create(toStyleRuleKeyframes(self), parentSheet);
      break;
    case Namespace:
      rule = CSSNamespaceRule::create(toStyleRuleNamespace(self), parentSheet);
      break;
    case Viewport:
      rule = CSSViewportRule::create(toStyleRuleViewport(self), parentSheet);
      break;
    case Keyframe:
    case Charset:
      ASSERT_NOT_REACHED();
      return nullptr;
  }
  if (parentRule)
    rule->setParentRule(parentRule);
  return rule;
}
示例#5
0
void StyleRuleBase::finalizeGarbageCollectedObject()
{
    switch (type()) {
    case Charset:
        toStyleRuleCharset(this)->~StyleRuleCharset();
        return;
    case Style:
        toStyleRule(this)->~StyleRule();
        return;
    case Page:
        toStyleRulePage(this)->~StyleRulePage();
        return;
    case FontFace:
        toStyleRuleFontFace(this)->~StyleRuleFontFace();
        return;
    case Media:
        toStyleRuleMedia(this)->~StyleRuleMedia();
        return;
    case Supports:
        toStyleRuleSupports(this)->~StyleRuleSupports();
        return;
    case Import:
        toStyleRuleImport(this)->~StyleRuleImport();
        return;
    case Keyframes:
        toStyleRuleKeyframes(this)->~StyleRuleKeyframes();
        return;
    case Keyframe:
        toStyleRuleKeyframe(this)->~StyleRuleKeyframe();
        return;
    case Namespace:
        toStyleRuleNamespace(this)->~StyleRuleNamespace();
        return;
    case Viewport:
        toStyleRuleViewport(this)->~StyleRuleViewport();
        return;
    case Unknown:
        return;
    }
    ASSERT_NOT_REACHED();
}
示例#6
0
void StyleRuleBase::destroy()
{
    switch (type()) {
    case Charset:
        delete toStyleRuleCharset(this);
        return;
    case Style:
        delete toStyleRule(this);
        return;
    case Page:
        delete toStyleRulePage(this);
        return;
    case FontFace:
        delete toStyleRuleFontFace(this);
        return;
    case Media:
        delete toStyleRuleMedia(this);
        return;
    case Supports:
        delete toStyleRuleSupports(this);
        return;
    case Import:
        delete toStyleRuleImport(this);
        return;
    case Keyframes:
        delete toStyleRuleKeyframes(this);
        return;
    case Keyframe:
        delete toStyleRuleKeyframe(this);
        return;
    case Namespace:
        delete toStyleRuleNamespace(this);
        return;
    case Viewport:
        delete toStyleRuleViewport(this);
        return;
    case Unknown:
        return;
    }
    ASSERT_NOT_REACHED();
}