| Index: third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
|
| diff --git a/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp b/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..59e966f7e131d379b6bb7b9525167e732b07e67e
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/css/cssom/InlineStylePropertyMap.cpp
|
| @@ -0,0 +1,190 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE fil
|
| +
|
| +#include "core/css/cssom/InlineStylePropertyMap.h"
|
| +
|
| +#include "core/CSSPropertyNames.h"
|
| +#include "core/css/CSSPrimitiveValue.h"
|
| +#include "core/css/CSSValueList.h"
|
| +#include "core/css/StylePropertySet.h"
|
| +#include "core/css/cssom/CSSOMTypes.h"
|
| +#include "core/css/cssom/SimpleLength.h"
|
| +
|
| +namespace blink {
|
| +
|
| +StyleValue* InlineStylePropertyMap::get(CSSPropertyID propertyID)
|
| +{
|
| + ASSERT(propertyID != CSSPropertyInvalid);
|
| +
|
| + updatePropertyIfNeeded(propertyID);
|
| +
|
| + if (!m_styles.contains(propertyID)) {
|
| + return nullptr;
|
| + }
|
| + StyleValueVector& styleVector = ensurePropertyList(propertyID);
|
| + if (styleVector.isEmpty()) {
|
| + return nullptr;
|
| + }
|
| + return styleVector.at(0);
|
| +}
|
| +
|
| +StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID)
|
| +{
|
| + ASSERT(propertyID != CSSPropertyInvalid);
|
| +
|
| + updatePropertyIfNeeded(propertyID);
|
| +
|
| + if (!m_styles.contains(propertyID))
|
| + return StyleValueVector();
|
| +
|
| + return ensurePropertyList(propertyID);
|
| +}
|
| +
|
| +bool InlineStylePropertyMap::has(CSSPropertyID propertyID)
|
| +{
|
| + ASSERT(propertyID != CSSPropertyInvalid);
|
| + return m_styles.contains(propertyID) && (!ensurePropertyList(propertyID).isEmpty());
|
| +}
|
| +
|
| +Vector<String> InlineStylePropertyMap::getProperties()
|
| +{
|
| + Vector<String> result;
|
| + StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle();
|
| + for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) {
|
| + CSSPropertyID cssPropertyID = inlineStyleSet.propertyAt(i).id();
|
| + // TODO(meade): Consider whether this is necessary here.
|
| + updatePropertyIfNeeded(cssPropertyID);
|
| + result.append(getPropertyNameString(cssPropertyID));
|
| + }
|
| + return result;
|
| +}
|
| +
|
| +void InlineStylePropertyMap::set(CSSPropertyID propertyID, StyleValueOrStyleValueSequenceOrString& item, ExceptionState& exceptionState)
|
| +{
|
| + ASSERT(propertyID != CSSPropertyInvalid);
|
| + if (!item.isNull()) {
|
| + m_styles.remove(propertyID);
|
| + append(propertyID, item, exceptionState);
|
| + } else {
|
| + // Clear it.
|
| + remove(propertyID, exceptionState);
|
| + }
|
| +}
|
| +
|
| +void InlineStylePropertyMap::append(CSSPropertyID propertyID, StyleValueOrStyleValueSequenceOrString& item, ExceptionState& exceptionState)
|
| +{
|
| + ASSERT(propertyID != CSSPropertyInvalid);
|
| +
|
| + StyleValueVector& values = ensurePropertyList(propertyID);
|
| + bool supportsMultiple = CSSOMTypes::propertySupportsMultiple(propertyID);
|
| +
|
| + if (item.isStyleValue()) {
|
| + // Setting a single value.
|
| + StyleValue* value = item.getAsStyleValue();
|
| + if (!CSSOMTypes::propertyCanTake(propertyID, *value)) {
|
| + exceptionState.throwTypeError("Invalid type for property");
|
| + return;
|
| + }
|
| + if (!values.isEmpty() && !supportsMultiple) {
|
| + exceptionState.throwTypeError("Property does not support multiple values");
|
| + return;
|
| + }
|
| + values.append(value);
|
| +
|
| + } else if (item.isStyleValueSequence()) {
|
| + if (!CSSOMTypes::propertySupportsMultiple(propertyID)) {
|
| + exceptionState.throwTypeError("Property does not support multiple values");
|
| + }
|
| + // Check all the values in the sequence to make sure they're valid.
|
| + const StyleValueVector specifiedValues = item.getAsStyleValueSequence();
|
| + for (const Member<StyleValue> value : specifiedValues) {
|
| + if (!CSSOMTypes::propertyCanTake(propertyID, *value)) {
|
| + exceptionState.throwTypeError("Invalid type for property");
|
| + return;
|
| + }
|
| + }
|
| + values.appendVector(specifiedValues);
|
| +
|
| + } else if (item.isNull()) {
|
| + // No-op
|
| + return;
|
| + } else if (item.isString()) {
|
| + // Parse it.
|
| + // TODO(meade): Implement this.
|
| + exceptionState.throwTypeError("Not implemented yet");
|
| + return;
|
| + }
|
| +
|
| + if (supportsMultiple) {
|
| + RefPtrWillBeRawPtr<CSSValueList> valueList = CSSValueList::createSpaceSeparated();
|
| + for (const Member<StyleValue> value : values) {
|
| + valueList->append(value->toCSSValue());
|
| + }
|
| + m_ownerElement->setInlineStyleProperty(propertyID, valueList);
|
| + } else {
|
| + m_ownerElement->setInlineStyleProperty(propertyID, values[0]->toCSSValue());
|
| + }
|
| + m_cleanStyles.set(propertyID, true);
|
| +}
|
| +
|
| +void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& exceptionState)
|
| +{
|
| + ASSERT(propertyID != CSSPropertyInvalid);
|
| +
|
| + const StyleVectorMap::iterator& iterator = m_styles.find(propertyID);
|
| + if (iterator == m_styles.end())
|
| + return;
|
| +
|
| + m_styles.remove(iterator);
|
| + m_ownerElement->removeInlineStyleProperty(propertyID);
|
| + m_cleanStyles.set(propertyID, true);
|
| +}
|
| +
|
| +void InlineStylePropertyMap::updatePropertyIfNeeded(CSSPropertyID propertyID)
|
| +{
|
| + if (m_cleanStyles.contains(propertyID) && m_cleanStyles.get(propertyID)) {
|
| + return;
|
| + }
|
| +
|
| + RefPtrWillBeRawPtr<CSSValue> cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyCSSValue(propertyID);
|
| + if (!cssValue) {
|
| + m_styles.remove(propertyID);
|
| + m_cleanStyles.set(propertyID, true);
|
| + return;
|
| + }
|
| +
|
| + StyleValueVector& values = ensurePropertyList(propertyID);
|
| + values.clear();
|
| +
|
| + if (!cssValue->isValueList()) {
|
| + StyleValue* styleValue = StyleValue::create(*cssValue);
|
| + if (styleValue) {
|
| + values.append(*styleValue);
|
| + }
|
| + }
|
| +
|
| + if (values.isEmpty())
|
| + m_styles.remove(propertyID);
|
| +
|
| + // TODO(meade) implement the other cases.
|
| +
|
| + m_cleanStyles.set(propertyID, true);
|
| +}
|
| +
|
| +void InlineStylePropertyMap::updateCustomProperty(const String& propertyName, PassRefPtrWillBeRawPtr<CSSValue> cssValue)
|
| +{
|
| + // TODO(meade): Implement.
|
| +}
|
| +
|
| +StyleValueVector& InlineStylePropertyMap::ensurePropertyList(CSSPropertyID propertyID)
|
| +{
|
| + if (!m_styles.contains(propertyID)) {
|
| + m_styles.set(propertyID, StyleValueVector());
|
| + }
|
| + // Note: If you write return m_style.get(propertyID) here, you get a copy.
|
| + return m_styles.find(propertyID)->value;
|
| +}
|
| +
|
| +} // namespace blink
|
| +
|
|
|