Chromium Code Reviews| Index: Source/core/inspector/LayoutEditor.cpp |
| diff --git a/Source/core/inspector/LayoutEditor.cpp b/Source/core/inspector/LayoutEditor.cpp |
| index d95854df1cb05a6bec0c7a402549309195fa2b03..6a6c645cc02368691de12a62d600e1c3bd2094ef 100644 |
| --- a/Source/core/inspector/LayoutEditor.cpp |
| +++ b/Source/core/inspector/LayoutEditor.cpp |
| @@ -265,7 +265,8 @@ PassRefPtr<JSONObject> LayoutEditor::buildJSONInfo() const |
| RefPtrWillBeRawPtr<CSSPrimitiveValue> LayoutEditor::getPropertyCSSValue(CSSPropertyID property) const |
| { |
| - RefPtrWillBeRawPtr<CSSStyleDeclaration> style = m_cssAgent->findEffectiveDeclaration(m_element.get(), property); |
| + RefPtrWillBeRawPtr<CSSRuleList> ruleList = m_cssAgent->matchedRulesList(m_element.get()); |
| + RefPtrWillBeRawPtr<CSSStyleDeclaration> style = m_cssAgent->findEffectiveDeclaration(property, ruleList.get(), m_element->style()); |
| if (!style) |
| return nullptr; |
| @@ -332,11 +333,8 @@ void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) |
| void LayoutEditor::overlayPropertyChanged(float cssDelta) |
| { |
| if (m_changingProperty && m_factor) { |
| - String errorString; |
| float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue); |
| - m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changingProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue::unitTypeToString(m_valueUnitType)); |
| - if (!errorString) |
| - m_isDirty = true; |
| + m_isDirty |= setCSSPropertyValueInCurrentRule(truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue::unitTypeToString(m_valueUnitType)); |
| } |
| } |
| @@ -368,16 +366,7 @@ void LayoutEditor::initializeCSSRules() |
| if (!m_element) |
| return; |
| - Document* ownerDocument = m_element->ownerDocument(); |
| - // A non-active document has no styles. |
| - if (!ownerDocument->isActive()) |
| - return; |
| - |
| - // Matched rules. |
| - StyleResolver& styleResolver = ownerDocument->ensureStyleResolver(); |
| - PseudoId elementPseudoId = m_element->pseudoId(); |
| - m_element->updateDistribution(); |
| - RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoCSSRulesForElement(m_element.get(), elementPseudoId, StyleResolver::AllCSSRules); |
| + RefPtrWillBeRawPtr<CSSRuleList> matchedRules = m_cssAgent->matchedRulesList(m_element.get()); |
| if (!matchedRules) |
| return; |
| @@ -398,7 +387,7 @@ void LayoutEditor::initializeCSSRules() |
| Vector<std::pair<unsigned, CSSStyleRule*>> selectors; |
| for (unsigned i = 0; i < uniqRules.size(); ++i) { |
| TrackExceptionState exceptionState; |
| - RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySelectorAll(AtomicString(uniqRules[i]->selectorText()), exceptionState); |
| + RefPtrWillBeRawPtr<StaticElementList> elements = m_element->ownerDocument()->querySelectorAll(AtomicString(uniqRules[i]->selectorText()), exceptionState); |
| unsigned length = exceptionState.hadException() ? 0: elements->length(); |
| selectors.append(std::make_pair(length, uniqRules[i])); |
| } |
| @@ -482,4 +471,37 @@ String LayoutEditor::currentSelectorInfo() |
| return m_cachedSelectorsInfo.get(m_currentRuleIndex); |
| } |
| +bool LayoutEditor::setCSSPropertyValueInCurrentRule(const String& value) |
| +{ |
| + if (!m_element) |
| + return false; |
| + |
| + CSSStyleRule* rule = m_currentRuleIndex == -1 ? nullptr : m_matchedRules[m_currentRuleIndex].get(); |
|
dgozman
2015/09/03 20:42:14
RefPtrWil....<CSSStyleRule>
sergeyv
2015/09/03 22:43:27
Done.
|
| + RefPtrWillBeRawPtr<CSSRuleList> ruleList = m_cssAgent->matchedRulesList(m_element.get()); |
| + RefPtrWillBeRawPtr<CSSStyleDeclaration> effectiveDeclaration = m_cssAgent->findEffectiveDeclaration(m_changingProperty, ruleList.get(), m_element->style()); |
| + |
| + CSSStyleRule* effectiveRule = nullptr; |
| + if (effectiveDeclaration && effectiveDeclaration->parentRule() && effectiveDeclaration->parentRule()->type() == CSSRule::STYLE_RULE) |
| + effectiveRule = toCSSStyleRule(effectiveDeclaration->parentRule()); |
| + |
| + String longhand = getPropertyNameString(m_changingProperty); |
| + bool forceImportant = effectiveDeclaration && effectiveDeclaration->getPropertyPriority(longhand) == "important"; |
| + |
| + if (effectiveDeclaration && rule) { |
| + int effectiveRuleIndex = -1; |
| + int ruleIndex = -1; |
| + for (unsigned i = 0, size = ruleList ? ruleList->length() : 0; i < size; ++i) { |
| + CSSRule* currentRule = ruleList->item(size - i - 1); |
| + if (currentRule == effectiveRule) |
| + effectiveRuleIndex = i; |
| + if (currentRule == rule) |
| + ruleIndex = i; |
| + } |
| + forceImportant |= effectiveRuleIndex < ruleIndex; |
| + } |
| + String errorString; |
| + m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), rule ? rule->style() : m_element->style(), m_changingProperty, value, forceImportant); |
| + return errorString.isEmpty(); |
| +} |
| + |
| } // namespace blink |