Commit 897d431a authored by meade's avatar meade Committed by Commit bot

Resubmission of sashab's patch: Make CSSComputedStyledeclaration::getPropertyCSSValue return const

Make CSSComputedStyledeclaration::getPropertyCSSValue() return a const
CSSValue* instead of a regular CSSValue*. This required changing
CSSStyleDeclaration::getPropertyCSSValueInternal() return a const
CSSValue* as well, and marking CSSValueList::copy() as a const method
(which it already was, it was just missing the const modifier). This is
pre-work for making CSSValueList store const CSSValues.

This patch is mostly mechanical changes, but does contain one logic
change: the static method mergeTextDecorationValues in EditingStyle
needs to be changed since it modifies a CSSValueList that points inside
the mutable style. Instead, the function is changed to take two
CSSValueLists and return a new one, and the callsite is changed to
replace the old CSSValueList with the new one in the style rather than
modifying the old CSSValueList in-place.

Original patch is here:
https://codereview.chromium.org/2034013002

BUG=526586

Review-Url: https://codereview.chromium.org/2046463003
Cr-Commit-Position: refs/heads/master@{#398235}
parent 3b4f64f3
...@@ -195,7 +195,7 @@ void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::Name> name, ...@@ -195,7 +195,7 @@ void V8CSSStyleDeclaration::namedPropertyGetterCustom(v8::Local<v8::Name> name,
CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder()); CSSStyleDeclaration* impl = V8CSSStyleDeclaration::toImpl(info.Holder());
// TODO(leviw): This API doesn't support custom properties. // TODO(leviw): This API doesn't support custom properties.
CSSValue* cssValue = impl->getPropertyCSSValueInternal(resolvedProperty); const CSSValue* cssValue = impl->getPropertyCSSValueInternal(resolvedProperty);
if (cssValue) { if (cssValue) {
v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate()); v8SetReturnValueStringOrNull(info, cssValue->cssText(), info.GetIsolate());
return; return;
......
...@@ -401,7 +401,7 @@ inline static CSSPrimitiveValue* zoomAdjustedPixelValue(double value, const Comp ...@@ -401,7 +401,7 @@ inline static CSSPrimitiveValue* zoomAdjustedPixelValue(double value, const Comp
return CSSPrimitiveValue::create(adjustFloatForAbsoluteZoom(value, style), CSSPrimitiveValue::UnitType::Pixels); return CSSPrimitiveValue::create(adjustFloatForAbsoluteZoom(value, style), CSSPrimitiveValue::UnitType::Pixels);
} }
CSSValue* CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword() const const CSSValue* CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword() const
{ {
if (!m_node) if (!m_node)
return nullptr; return nullptr;
...@@ -514,7 +514,7 @@ Node* CSSComputedStyleDeclaration::styledNode() const ...@@ -514,7 +514,7 @@ Node* CSSComputedStyleDeclaration::styledNode() const
return m_node.get(); return m_node.get();
} }
CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValue(AtomicString customPropertyName) const const CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValue(AtomicString customPropertyName) const
{ {
Node* styledNode = this->styledNode(); Node* styledNode = this->styledNode();
if (!styledNode) if (!styledNode)
...@@ -536,7 +536,7 @@ std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> CSSComputedStyle ...@@ -536,7 +536,7 @@ std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> CSSComputedStyle
return ComputedStyleCSSValueMapping::getVariables(*style); return ComputedStyleCSSValueMapping::getVariables(*style);
} }
CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID) const const CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID) const
{ {
Node* styledNode = this->styledNode(); Node* styledNode = this->styledNode();
if (!styledNode) if (!styledNode)
...@@ -576,7 +576,7 @@ CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propert ...@@ -576,7 +576,7 @@ CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propert
String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) const String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) const
{ {
CSSValue* value = getPropertyCSSValue(propertyID); const CSSValue* value = getPropertyCSSValue(propertyID);
if (value) if (value)
return value->cssText(); return value->cssText();
return ""; return "";
...@@ -610,7 +610,7 @@ bool CSSComputedStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, c ...@@ -610,7 +610,7 @@ bool CSSComputedStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, c
return true; return true;
} }
} }
CSSValue* value = getPropertyCSSValue(propertyID); const CSSValue* value = getPropertyCSSValue(propertyID);
return value && propertyValue && value->equals(*propertyValue); return value && propertyValue && value->equals(*propertyValue);
} }
...@@ -624,7 +624,7 @@ MutableStylePropertySet* CSSComputedStyleDeclaration::copyPropertiesInSet(const ...@@ -624,7 +624,7 @@ MutableStylePropertySet* CSSComputedStyleDeclaration::copyPropertiesInSet(const
HeapVector<CSSProperty, 256> list; HeapVector<CSSProperty, 256> list;
list.reserveInitialCapacity(properties.size()); list.reserveInitialCapacity(properties.size());
for (unsigned i = 0; i < properties.size(); ++i) { for (unsigned i = 0; i < properties.size(); ++i) {
CSSValue* value = getPropertyCSSValue(properties[i]); const CSSValue* value = getPropertyCSSValue(properties[i]);
if (value) if (value)
list.append(CSSProperty(properties[i], value, false)); list.append(CSSProperty(properties[i], value, false));
} }
...@@ -641,7 +641,7 @@ String CSSComputedStyleDeclaration::getPropertyValue(const String& propertyName) ...@@ -641,7 +641,7 @@ String CSSComputedStyleDeclaration::getPropertyValue(const String& propertyName)
CSSPropertyID propertyID = cssPropertyID(propertyName); CSSPropertyID propertyID = cssPropertyID(propertyName);
if (!propertyID) { if (!propertyID) {
if (RuntimeEnabledFeatures::cssVariablesEnabled() && CSSVariableParser::isValidVariableName(propertyName)) { if (RuntimeEnabledFeatures::cssVariablesEnabled() && CSSVariableParser::isValidVariableName(propertyName)) {
CSSValue* value = getPropertyCSSValue(AtomicString(propertyName)); const CSSValue* value = getPropertyCSSValue(AtomicString(propertyName));
if (value) if (value)
return value->cssText(); return value->cssText();
} }
...@@ -678,7 +678,7 @@ String CSSComputedStyleDeclaration::removeProperty(const String& name, Exception ...@@ -678,7 +678,7 @@ String CSSComputedStyleDeclaration::removeProperty(const String& name, Exception
return String(); return String();
} }
CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID) const CSSValue* CSSComputedStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
{ {
return getPropertyCSSValue(propertyID); return getPropertyCSSValue(propertyID);
} }
......
...@@ -58,11 +58,11 @@ public: ...@@ -58,11 +58,11 @@ public:
MutableStylePropertySet* copyProperties() const; MutableStylePropertySet* copyProperties() const;
CSSValue* getPropertyCSSValue(CSSPropertyID) const; const CSSValue* getPropertyCSSValue(CSSPropertyID) const;
CSSValue* getPropertyCSSValue(AtomicString customPropertyName) const; const CSSValue* getPropertyCSSValue(AtomicString customPropertyName) const;
std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> getVariables() const; std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> getVariables() const;
CSSValue* getFontSizeCSSValuePreferringKeyword() const; const CSSValue* getFontSizeCSSValuePreferringKeyword() const;
bool isMonospaceFont() const; bool isMonospaceFont() const;
MutableStylePropertySet* copyPropertiesInSet(const Vector<CSSPropertyID>&) const; MutableStylePropertySet* copyPropertiesInSet(const Vector<CSSPropertyID>&) const;
...@@ -94,7 +94,7 @@ private: ...@@ -94,7 +94,7 @@ private:
void setCSSFloat(const String&, ExceptionState&); void setCSSFloat(const String&, ExceptionState&);
String cssText() const override; String cssText() const override;
void setCSSText(const String&, ExceptionState&) override; void setCSSText(const String&, ExceptionState&) override;
CSSValue* getPropertyCSSValueInternal(CSSPropertyID) override; const CSSValue* getPropertyCSSValueInternal(CSSPropertyID) override;
String getPropertyValueInternal(CSSPropertyID) override; String getPropertyValueInternal(CSSPropertyID) override;
void setPropertyInternal(CSSPropertyID, const String& customPropertyName, const String& value, bool important, ExceptionState&) override; void setPropertyInternal(CSSPropertyID, const String& customPropertyName, const String& value, bool important, ExceptionState&) override;
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
// CSSPropertyID versions of the CSSOM functions to support bindings and editing. // CSSPropertyID versions of the CSSOM functions to support bindings and editing.
// Use the non-virtual methods in the concrete subclasses when possible. // Use the non-virtual methods in the concrete subclasses when possible.
// The CSSValue returned by this function should not be exposed to the web as it may be used by multiple documents at the same time. // The CSSValue returned by this function should not be exposed to the web as it may be used by multiple documents at the same time.
virtual CSSValue* getPropertyCSSValueInternal(CSSPropertyID) = 0; virtual const CSSValue* getPropertyCSSValueInternal(CSSPropertyID) = 0;
virtual String getPropertyValueInternal(CSSPropertyID) = 0; virtual String getPropertyValueInternal(CSSPropertyID) = 0;
virtual void setPropertyInternal(CSSPropertyID, const String& propertyValue, const String& value, bool important, ExceptionState&) = 0; virtual void setPropertyInternal(CSSPropertyID, const String& propertyValue, const String& value, bool important, ExceptionState&) = 0;
......
...@@ -62,7 +62,7 @@ bool CSSValueList::hasValue(const CSSValue& val) const ...@@ -62,7 +62,7 @@ bool CSSValueList::hasValue(const CSSValue& val) const
return false; return false;
} }
CSSValueList* CSSValueList::copy() CSSValueList* CSSValueList::copy() const
{ {
CSSValueList* newList = nullptr; CSSValueList* newList = nullptr;
switch (m_valueListSeparator) { switch (m_valueListSeparator) {
......
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
void append(CSSValue* value) { m_values.append(value); } void append(CSSValue* value) { m_values.append(value); }
bool removeAll(const CSSValue&); bool removeAll(const CSSValue&);
bool hasValue(const CSSValue&) const; bool hasValue(const CSSValue&) const;
CSSValueList* copy(); CSSValueList* copy() const;
String customCSSText() const; String customCSSText() const;
bool equals(const CSSValueList&) const; bool equals(const CSSValueList&) const;
......
...@@ -258,7 +258,7 @@ String AbstractPropertySetCSSStyleDeclaration::removeProperty(const String& prop ...@@ -258,7 +258,7 @@ String AbstractPropertySetCSSStyleDeclaration::removeProperty(const String& prop
return result; return result;
} }
CSSValue* AbstractPropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID) const CSSValue* AbstractPropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
{ {
return propertySet().getPropertyCSSValue(propertyID); return propertySet().getPropertyCSSValue(propertyID);
} }
......
...@@ -60,7 +60,7 @@ private: ...@@ -60,7 +60,7 @@ private:
void setCSSFloat(const String&, ExceptionState&); void setCSSFloat(const String&, ExceptionState&);
String cssText() const final; String cssText() const final;
void setCSSText(const String&, ExceptionState&) final; void setCSSText(const String&, ExceptionState&) final;
CSSValue* getPropertyCSSValueInternal(CSSPropertyID) final; const CSSValue* getPropertyCSSValueInternal(CSSPropertyID) final;
String getPropertyValueInternal(CSSPropertyID) final; String getPropertyValueInternal(CSSPropertyID) final;
void setPropertyInternal(CSSPropertyID, const String& customPropertyName, const String& value, bool important, ExceptionState&) final; void setPropertyInternal(CSSPropertyID, const String& customPropertyName, const String& value, bool important, ExceptionState&) final;
......
...@@ -11,7 +11,7 @@ namespace blink { ...@@ -11,7 +11,7 @@ namespace blink {
StylePropertyMap::StyleValueVector ComputedStylePropertyMap::getAll(CSSPropertyID propertyID) StylePropertyMap::StyleValueVector ComputedStylePropertyMap::getAll(CSSPropertyID propertyID)
{ {
CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueInternal(propertyID); const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueInternal(propertyID);
if (!cssValue) if (!cssValue)
return StylePropertyMap::StyleValueVector(); return StylePropertyMap::StyleValueVector();
return cssValueToStyleValueVector(propertyID, *cssValue); return cssValueToStyleValueVector(propertyID, *cssValue);
......
...@@ -1682,7 +1682,7 @@ float ApplyStyleCommand::computedFontSize(Node* node) ...@@ -1682,7 +1682,7 @@ float ApplyStyleCommand::computedFontSize(Node* node)
if (!style) if (!style)
return 0; return 0;
CSSPrimitiveValue* value = toCSSPrimitiveValue(style->getPropertyCSSValue(CSSPropertyFontSize)); const CSSPrimitiveValue* value = toCSSPrimitiveValue(style->getPropertyCSSValue(CSSPropertyFontSize));
if (!value) if (!value)
return 0; return 0;
......
...@@ -187,20 +187,20 @@ void LayoutEditor::rebuild() ...@@ -187,20 +187,20 @@ void LayoutEditor::rebuild()
editableSelectorUpdated(false); editableSelectorUpdated(false);
} }
CSSPrimitiveValue* LayoutEditor::getPropertyCSSValue(CSSPropertyID property) const const CSSPrimitiveValue* LayoutEditor::getPropertyCSSValue(CSSPropertyID property) const
{ {
CSSStyleDeclaration* style = m_cssAgent->findEffectiveDeclaration(property, m_matchedStyles); CSSStyleDeclaration* style = m_cssAgent->findEffectiveDeclaration(property, m_matchedStyles);
if (!style) if (!style)
return nullptr; return nullptr;
CSSValue* cssValue = style->getPropertyCSSValueInternal(property); const CSSValue* cssValue = style->getPropertyCSSValueInternal(property);
if (!cssValue || !cssValue->isPrimitiveValue()) if (!cssValue || !cssValue->isPrimitiveValue())
return nullptr; return nullptr;
return toCSSPrimitiveValue(cssValue); return toCSSPrimitiveValue(cssValue);
} }
bool LayoutEditor::growInside(String propertyName, CSSPrimitiveValue* value) bool LayoutEditor::growInside(String propertyName, const CSSPrimitiveValue* value)
{ {
FloatQuad content1, padding1, border1, margin1; FloatQuad content1, padding1, border1, margin1;
InspectorHighlight::buildNodeQuads(m_element.get(), &content1, &padding1, &border1, &margin1); InspectorHighlight::buildNodeQuads(m_element.get(), &content1, &padding1, &border1, &margin1);
...@@ -254,7 +254,7 @@ bool LayoutEditor::growInside(String propertyName, CSSPrimitiveValue* value) ...@@ -254,7 +254,7 @@ bool LayoutEditor::growInside(String propertyName, CSSPrimitiveValue* value)
std::unique_ptr<protocol::DictionaryValue> LayoutEditor::createValueDescription(const String& propertyName) std::unique_ptr<protocol::DictionaryValue> LayoutEditor::createValueDescription(const String& propertyName)
{ {
CSSPrimitiveValue* cssValue = getPropertyCSSValue(cssPropertyID(propertyName)); const CSSPrimitiveValue* cssValue = getPropertyCSSValue(cssPropertyID(propertyName));
if (cssValue && !(cssValue->isLength() || cssValue->isPercentage())) if (cssValue && !(cssValue->isLength() || cssValue->isPercentage()))
return nullptr; return nullptr;
...@@ -284,7 +284,7 @@ void LayoutEditor::overlayStartedPropertyChange(const String& anchorName) ...@@ -284,7 +284,7 @@ void LayoutEditor::overlayStartedPropertyChange(const String& anchorName)
if (!m_changingProperty) if (!m_changingProperty)
return; return;
CSSPrimitiveValue* cssValue = getPropertyCSSValue(m_changingProperty); const CSSPrimitiveValue* cssValue = getPropertyCSSValue(m_changingProperty);
m_valueUnitType = cssValue ? cssValue->typeWithCalcResolved() : CSSPrimitiveValue::UnitType::Pixels; m_valueUnitType = cssValue ? cssValue->typeWithCalcResolved() : CSSPrimitiveValue::UnitType::Pixels;
if (!isMutableUnitType(m_valueUnitType)) if (!isMutableUnitType(m_valueUnitType))
return; return;
......
...@@ -45,14 +45,14 @@ public: ...@@ -45,14 +45,14 @@ public:
private: private:
LayoutEditor(Element*, InspectorCSSAgent*, InspectorDOMAgent*, ScriptController*); LayoutEditor(Element*, InspectorCSSAgent*, InspectorDOMAgent*, ScriptController*);
CSSPrimitiveValue* getPropertyCSSValue(CSSPropertyID) const; const CSSPrimitiveValue* getPropertyCSSValue(CSSPropertyID) const;
std::unique_ptr<protocol::DictionaryValue> createValueDescription(const String&); std::unique_ptr<protocol::DictionaryValue> createValueDescription(const String&);
void appendAnchorFor(protocol::ListValue*, const String&, const String&); void appendAnchorFor(protocol::ListValue*, const String&, const String&);
bool setCSSPropertyValueInCurrentRule(const String&); bool setCSSPropertyValueInCurrentRule(const String&);
void editableSelectorUpdated(bool hasChanged) const; void editableSelectorUpdated(bool hasChanged) const;
void evaluateInOverlay(const String&, std::unique_ptr<protocol::Value>) const; void evaluateInOverlay(const String&, std::unique_ptr<protocol::Value>) const;
std::unique_ptr<protocol::DictionaryValue> currentSelectorInfo(CSSStyleDeclaration*) const; std::unique_ptr<protocol::DictionaryValue> currentSelectorInfo(CSSStyleDeclaration*) const;
bool growInside(String propertyName, CSSPrimitiveValue*); bool growInside(String propertyName, const CSSPrimitiveValue*);
Member<Element> m_element; Member<Element> m_element;
Member<InspectorCSSAgent> m_cssAgent; Member<InspectorCSSAgent> m_cssAgent;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment