| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. | |
| 3 * Copyright (C) 2012 Apple Inc. All rights reserved. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions | |
| 7 * are met: | |
| 8 * | |
| 9 * 1. Redistributions of source code must retain the above | |
| 10 * copyright notice, this list of conditions and the following | |
| 11 * disclaimer. | |
| 12 * 2. Redistributions in binary form must reproduce the above | |
| 13 * copyright notice, this list of conditions and the following | |
| 14 * disclaimer in the documentation and/or other materials | |
| 15 * provided with the distribution. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY | |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE | |
| 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
| 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
| 26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | |
| 27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 28 * SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "sky/engine/config.h" | |
| 32 #include "sky/engine/core/css/CSSGroupingRule.h" | |
| 33 | |
| 34 #include "sky/engine/bindings/core/v8/ExceptionState.h" | |
| 35 #include "sky/engine/core/css/CSSRuleList.h" | |
| 36 #include "sky/engine/core/css/CSSStyleSheet.h" | |
| 37 #include "sky/engine/core/css/parser/BisonCSSParser.h" | |
| 38 #include "sky/engine/core/dom/ExceptionCode.h" | |
| 39 #include "sky/engine/core/frame/UseCounter.h" | |
| 40 #include "sky/engine/wtf/text/StringBuilder.h" | |
| 41 | |
| 42 namespace blink { | |
| 43 | |
| 44 CSSGroupingRule::CSSGroupingRule(StyleRuleGroup* groupRule, CSSStyleSheet* paren
t) | |
| 45 : CSSRule(parent) | |
| 46 , m_groupRule(groupRule) | |
| 47 , m_childRuleCSSOMWrappers(groupRule->childRules().size()) | |
| 48 { | |
| 49 } | |
| 50 | |
| 51 CSSGroupingRule::~CSSGroupingRule() | |
| 52 { | |
| 53 #if !ENABLE(OILPAN) | |
| 54 ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size()); | |
| 55 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { | |
| 56 if (m_childRuleCSSOMWrappers[i]) | |
| 57 m_childRuleCSSOMWrappers[i]->setParentRule(0); | |
| 58 } | |
| 59 #endif | |
| 60 } | |
| 61 | |
| 62 unsigned CSSGroupingRule::insertRule(const String& ruleString, unsigned index, E
xceptionState& exceptionState) | |
| 63 { | |
| 64 ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size()); | |
| 65 | |
| 66 if (index > m_groupRule->childRules().size()) { | |
| 67 exceptionState.throwDOMException(IndexSizeError, "the index " + String::
number(index) + " must be less than or equal to the length of the rule list."); | |
| 68 return 0; | |
| 69 } | |
| 70 | |
| 71 CSSStyleSheet* styleSheet = parentStyleSheet(); | |
| 72 CSSParserContext context(parserContext(), UseCounter::getFrom(styleSheet)); | |
| 73 BisonCSSParser parser(context); | |
| 74 RefPtr<StyleRuleBase> newRule = parser.parseRule(styleSheet ? styleSheet->co
ntents() : 0, ruleString); | |
| 75 if (!newRule) { | |
| 76 exceptionState.throwDOMException(SyntaxError, "the rule '" + ruleString
+ "' is invalid and cannot be parsed."); | |
| 77 return 0; | |
| 78 } | |
| 79 | |
| 80 CSSStyleSheet::RuleMutationScope mutationScope(this); | |
| 81 | |
| 82 m_groupRule->wrapperInsertRule(index, newRule); | |
| 83 | |
| 84 m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>(nullptr)); | |
| 85 return index; | |
| 86 } | |
| 87 | |
| 88 void CSSGroupingRule::deleteRule(unsigned index, ExceptionState& exceptionState) | |
| 89 { | |
| 90 ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size()); | |
| 91 | |
| 92 if (index >= m_groupRule->childRules().size()) { | |
| 93 exceptionState.throwDOMException(IndexSizeError, "the index " + String::
number(index) + " is greated than the length of the rule list."); | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 CSSStyleSheet::RuleMutationScope mutationScope(this); | |
| 98 | |
| 99 m_groupRule->wrapperRemoveRule(index); | |
| 100 | |
| 101 if (m_childRuleCSSOMWrappers[index]) | |
| 102 m_childRuleCSSOMWrappers[index]->setParentRule(0); | |
| 103 m_childRuleCSSOMWrappers.remove(index); | |
| 104 } | |
| 105 | |
| 106 void CSSGroupingRule::appendCSSTextForItems(StringBuilder& result) const | |
| 107 { | |
| 108 unsigned size = length(); | |
| 109 for (unsigned i = 0; i < size; ++i) { | |
| 110 result.appendLiteral(" "); | |
| 111 result.append(item(i)->cssText()); | |
| 112 result.append('\n'); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 unsigned CSSGroupingRule::length() const | |
| 117 { | |
| 118 return m_groupRule->childRules().size(); | |
| 119 } | |
| 120 | |
| 121 CSSRule* CSSGroupingRule::item(unsigned index) const | |
| 122 { | |
| 123 if (index >= length()) | |
| 124 return 0; | |
| 125 ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size()); | |
| 126 RefPtr<CSSRule>& rule = m_childRuleCSSOMWrappers[index]; | |
| 127 if (!rule) | |
| 128 rule = m_groupRule->childRules()[index]->createCSSOMWrapper(const_cast<C
SSGroupingRule*>(this)); | |
| 129 return rule.get(); | |
| 130 } | |
| 131 | |
| 132 CSSRuleList* CSSGroupingRule::cssRules() const | |
| 133 { | |
| 134 if (!m_ruleListCSSOMWrapper) | |
| 135 m_ruleListCSSOMWrapper = LiveCSSRuleList<CSSGroupingRule>::create(const_
cast<CSSGroupingRule*>(this)); | |
| 136 return m_ruleListCSSOMWrapper.get(); | |
| 137 } | |
| 138 | |
| 139 void CSSGroupingRule::reattach(StyleRuleBase* rule) | |
| 140 { | |
| 141 ASSERT(rule); | |
| 142 m_groupRule = static_cast<StyleRuleGroup*>(rule); | |
| 143 for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { | |
| 144 if (m_childRuleCSSOMWrappers[i]) | |
| 145 m_childRuleCSSOMWrappers[i]->reattach(m_groupRule->childRules()[i].g
et()); | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 } // namespace blink | |
| OLD | NEW |