コード例 #1
0
String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionCode& ec)
{
    StyleAttributeMutationScope mutationScope(this);
    CSSPropertyID propertyID = cssPropertyID(propertyName);
    if (!propertyID)
        return String();

    willMutate();

    ec = 0;
    String result;
    bool changed = m_propertySet->removeProperty(propertyID, &result);

    didMutate(changed ? PropertyChanged : NoChanges);

    if (changed)
        mutationScope.enqueueMutationRecord();
    return result;
}
コード例 #2
0
ファイル: CSSGroupingRule.cpp プロジェクト: CannedFish/webkit
void CSSGroupingRule::deleteRule(unsigned index, ExceptionCode& ec)
{
    ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size());

    if (index >= m_groupRule->childRules().size()) {
        // INDEX_SIZE_ERR: Raised if the specified index does not correspond to a
        // rule in the media rule list.
        ec = INDEX_SIZE_ERR;
        return;
    }

    CSSStyleSheet::RuleMutationScope mutationScope(this);

    m_groupRule->wrapperRemoveRule(index);

    if (m_childRuleCSSOMWrappers[index])
        m_childRuleCSSOMWrappers[index]->setParentRule(0);
    m_childRuleCSSOMWrappers.remove(index);
}
コード例 #3
0
void CSSStyleSheet::deleteRule(unsigned index, ExceptionCode& ec)
{
    ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());

    ec = 0;
    if (index >= length()) {
        ec = INDEX_SIZE_ERR;
        return;
    }
    RuleMutationScope mutationScope(this);

    m_contents->wrapperDeleteRule(index);

    if (!m_childRuleCSSOMWrappers.isEmpty()) {
        if (m_childRuleCSSOMWrappers[index])
            m_childRuleCSSOMWrappers[index]->setParentStyleSheet(0);
        m_childRuleCSSOMWrappers.remove(index);
    }
}
コード例 #4
0
String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionCode& ec)
{
#if ENABLE(MUTATION_OBSERVERS)
    StyleAttributeMutationScope mutationScope(this);
#endif
    CSSPropertyID propertyID = cssPropertyID(propertyName);
    if (!propertyID)
        return String();
    ec = 0;
    String result;
    bool changes = m_propertySet->removeProperty(propertyID, &result);
    if (changes) {
        setNeedsStyleRecalc();
#if ENABLE(MUTATION_OBSERVERS)
        mutationScope.enqueueMutationRecord();
#endif
    }
    return result;
}
コード例 #5
0
void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
{
#if ENABLE(MUTATION_OBSERVERS)
    StyleAttributeMutationScope mutationScope(this);
#endif
    CSSPropertyID propertyID = cssPropertyID(propertyName);
    if (!propertyID)
        return;
    bool important = priority.find("important", 0, false) != notFound;
    ec = 0;
    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
    if (changed) {
        // CSS DOM requires raising SYNTAX_ERR of parsing failed, but this is too dangerous for compatibility,
        // see <http://bugs.webkit.org/show_bug.cgi?id=7296>.
        setNeedsStyleRecalc();
#if ENABLE(MUTATION_OBSERVERS)
        mutationScope.enqueueMutationRecord();
#endif
    }
}
コード例 #6
0
ファイル: CSSStyleSheet.cpp プロジェクト: eocanha/webkit
ExceptionOr<unsigned> CSSStyleSheet::insertRule(const String& ruleString, unsigned index)
{
    ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());

    if (index > length())
        return Exception { INDEX_SIZE_ERR };
    RefPtr<StyleRuleBase> rule = CSSParser::parseRule(m_contents.get().parserContext(), m_contents.ptr(), ruleString);

    if (!rule)
        return Exception { SYNTAX_ERR };

    RuleMutationScope mutationScope(this, RuleInsertion, is<StyleRuleKeyframes>(*rule) ? downcast<StyleRuleKeyframes>(rule.get()) : nullptr);

    bool success = m_contents.get().wrapperInsertRule(rule.releaseNonNull(), index);
    if (!success)
        return Exception { HIERARCHY_REQUEST_ERR };
    if (!m_childRuleCSSOMWrappers.isEmpty())
        m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());

    return index;
}
コード例 #7
0
void CSSStyleRule::setSelectorText(const String& selectorText)
{
    CSSParser p(parserContext());
    CSSSelectorList selectorList;
    p.parseSelector(selectorText, selectorList);
    if (!selectorList.isValid())
        return;

    // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369>
    if (selectorList.componentCount() > RuleData::maximumSelectorComponentCount)
        return;

    CSSStyleSheet::RuleMutationScope mutationScope(this);

    m_styleRule->wrapperAdoptSelectorList(selectorList);

    if (hasCachedSelectorText()) {
        selectorTextCache().remove(this);
        setHasCachedSelectorText(false);
    }
}
コード例 #8
0
void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionState& exceptionState)
{
    StyleAttributeMutationScope mutationScope(this);
    CSSPropertyID propertyID = cssPropertyID(propertyName);
    if (!propertyID)
        return;

    bool important = priority.find("important", 0, false) != kNotFound;

    willMutate();

    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());

    didMutate(changed ? PropertyChanged : NoChanges);

    if (changed) {
        // CSS DOM requires raising SyntaxError of parsing failed, but this is too dangerous for compatibility,
        // see <http://bugs.webkit.org/show_bug.cgi?id=7296>.
        mutationScope.enqueueMutationRecord();
    }
}
コード例 #9
0
ExceptionOr<String> PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName)
{
    StyleAttributeMutationScope mutationScope(this);
    CSSPropertyID propertyID = cssPropertyID(propertyName);
    if (isCustomPropertyName(propertyName))
        propertyID = CSSPropertyCustom;
    if (!propertyID)
        return String();

    if (!willMutate())
        return String();

    String result;
    bool changed = propertyID != CSSPropertyCustom ? m_propertySet->removeProperty(propertyID, &result) : m_propertySet->removeCustomProperty(propertyName, &result);

    didMutate(changed ? PropertyChanged : NoChanges);

    if (changed)
        mutationScope.enqueueMutationRecord();
    return WTFMove(result);
}
コード例 #10
0
ファイル: CSSStyleSheet.cpp プロジェクト: mirror/chromium
unsigned CSSStyleSheet::insertRule(const String& ruleString,
                                   unsigned index,
                                   ExceptionState& exceptionState) {
  DCHECK(m_childRuleCSSOMWrappers.isEmpty() ||
         m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());

  if (index > length()) {
    exceptionState.throwDOMException(
        IndexSizeError, "The index provided (" + String::number(index) +
                            ") is larger than the maximum index (" +
                            String::number(length()) + ").");
    return 0;
  }
  CSSParserContext context(m_contents->parserContext(),
                           UseCounter::getFrom(this));
  StyleRuleBase* rule =
      CSSParser::parseRule(context, m_contents.get(), ruleString);

  if (!rule) {
    exceptionState.throwDOMException(
        SyntaxError, "Failed to parse the rule '" + ruleString + "'.");
    return 0;
  }
  RuleMutationScope mutationScope(this);

  bool success = m_contents->wrapperInsertRule(rule, index);
  if (!success) {
    if (rule->isNamespaceRule())
      exceptionState.throwDOMException(InvalidStateError,
                                       "Failed to insert the rule");
    else
      exceptionState.throwDOMException(HierarchyRequestError,
                                       "Failed to insert the rule.");
    return 0;
  }
  if (!m_childRuleCSSOMWrappers.isEmpty())
    m_childRuleCSSOMWrappers.insert(index, Member<CSSRule>(nullptr));

  return index;
}
コード例 #11
0
void CSSStyleSheet::deleteRule(unsigned index, ExceptionState& exceptionState)
{
    ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());

    if (index >= length()) {
        exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is larger than the maximum index (" + String::number(length() - 1) + ").");
        return;
    }
    RuleMutationScope mutationScope(this);

    bool success = m_contents->wrapperDeleteRule(index);
    if (!success) {
        exceptionState.throwDOMException(InvalidStateError, "Failed to delete rule");
        return;
    }

    if (!m_childRuleCSSOMWrappers.isEmpty()) {
        if (m_childRuleCSSOMWrappers[index])
            m_childRuleCSSOMWrappers[index]->setParentStyleSheet(0);
        m_childRuleCSSOMWrappers.remove(index);
    }
}
コード例 #12
0
String AbstractPropertySetCSSStyleDeclaration::removeProperty(
    const String& propertyName,
    ExceptionState& exceptionState) {
  CSSPropertyID propertyID = cssPropertyID(propertyName);
  if (!propertyID)
    return String();

  StyleAttributeMutationScope mutationScope(this);
  willMutate();

  String result;
  bool changed = false;
  if (propertyID == CSSPropertyVariable)
    changed = propertySet().removeProperty(AtomicString(propertyName), &result);
  else
    changed = propertySet().removeProperty(propertyID, &result);

  didMutate(changed ? PropertyChanged : NoChanges);

  if (changed)
    mutationScope.enqueueMutationRecord();
  return result;
}
コード例 #13
0
ファイル: CSSMediaRule.cpp プロジェクト: dzhshf/WebKit
unsigned CSSMediaRule::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec)
{
    ASSERT(m_childRuleCSSOMWrappers.size() == m_mediaRule->childRules().size());

    if (index > m_mediaRule->childRules().size()) {
        // INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point.
        ec = INDEX_SIZE_ERR;
        return 0;
    }

    CSSParser parser(parserContext());
    CSSStyleSheet* styleSheet = parentStyleSheet();
    RefPtr<StyleRuleBase> newRule = parser.parseRule(styleSheet ? styleSheet->contents() : 0, ruleString);
    if (!newRule) {
        // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable.
        ec = SYNTAX_ERR;
        return 0;
    }

    if (newRule->isImportRule()) {
        // FIXME: an HIERARCHY_REQUEST_ERR should also be thrown for a @charset or a nested
        // @media rule.  They are currently not getting parsed, resulting in a SYNTAX_ERR
        // to get raised above.

        // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified
        // index, e.g., if an @import rule is inserted after a standard rule set or other
        // at-rule.
        ec = HIERARCHY_REQUEST_ERR;
        return 0;
    }
    CSSStyleSheet::RuleMutationScope mutationScope(this);

    m_mediaRule->wrapperInsertRule(index, newRule);

    m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
    return index;
}
コード例 #14
0
DISABLE_CFI_PERF
void AbstractPropertySetCSSStyleDeclaration::setPropertyInternal(
    CSSPropertyID unresolvedProperty,
    const String& customPropertyName,
    const String& value,
    bool important,
    ExceptionState&) {
  StyleAttributeMutationScope mutationScope(this);
  willMutate();

  bool didChange = false;
  if (unresolvedProperty == CSSPropertyVariable) {
    bool isAnimationTainted = isKeyframeStyle();
    didChange =
        propertySet()
            .setProperty(AtomicString(customPropertyName), value, important,
                         contextStyleSheet(), isAnimationTainted)
            .didChange;
  } else {
    didChange = propertySet()
                    .setProperty(unresolvedProperty, value, important,
                                 contextStyleSheet())
                    .didChange;
  }

  didMutate(didChange ? PropertyChanged : NoChanges);

  if (!didChange)
    return;

  Element* parent = parentElement();
  if (parent)
    parent->document().styleEngine().attributeChangedForElement(
        HTMLNames::styleAttr, *parent);
  mutationScope.enqueueMutationRecord();
}
コード例 #15
0
ファイル: CSSKeyframesRule.cpp プロジェクト: domenic/mojo
void CSSKeyframesRule::setName(const String& name)
{
    CSSStyleSheet::RuleMutationScope mutationScope(this);

    m_keyframesRule->setName(name);
}