| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. | 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. |
| 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "core/editing/EditingStyle.h" | 27 #include "core/editing/EditingStyle.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 30 #include "core/HTMLNames.h" | 30 #include "core/HTMLNames.h" |
| 31 #include "core/css/CSSColorValue.h" | 31 #include "core/css/CSSColorValue.h" |
| 32 #include "core/css/CSSComputedStyleDeclaration.h" | 32 #include "core/css/CSSComputedStyleDeclaration.h" |
| 33 #include "core/css/CSSIdentifierValue.h" |
| 33 #include "core/css/CSSPrimitiveValue.h" | 34 #include "core/css/CSSPrimitiveValue.h" |
| 34 #include "core/css/CSSPrimitiveValueMappings.h" | 35 #include "core/css/CSSPrimitiveValueMappings.h" |
| 35 #include "core/css/CSSPropertyMetadata.h" | 36 #include "core/css/CSSPropertyMetadata.h" |
| 36 #include "core/css/CSSRuleList.h" | 37 #include "core/css/CSSRuleList.h" |
| 37 #include "core/css/CSSStyleRule.h" | 38 #include "core/css/CSSStyleRule.h" |
| 38 #include "core/css/CSSValueList.h" | 39 #include "core/css/CSSValueList.h" |
| 39 #include "core/css/FontSize.h" | 40 #include "core/css/FontSize.h" |
| 40 #include "core/css/StylePropertySet.h" | 41 #include "core/css/StylePropertySet.h" |
| 41 #include "core/css/StyleRule.h" | 42 #include "core/css/StyleRule.h" |
| 42 #include "core/css/parser/CSSParser.h" | 43 #include "core/css/parser/CSSParser.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 154 } |
| 154 | 155 |
| 155 static MutableStylePropertySet* getPropertiesNotIn( | 156 static MutableStylePropertySet* getPropertiesNotIn( |
| 156 StylePropertySet* styleWithRedundantProperties, | 157 StylePropertySet* styleWithRedundantProperties, |
| 157 CSSStyleDeclaration* baseStyle); | 158 CSSStyleDeclaration* baseStyle); |
| 158 enum LegacyFontSizeMode { | 159 enum LegacyFontSizeMode { |
| 159 AlwaysUseLegacyFontSize, | 160 AlwaysUseLegacyFontSize, |
| 160 UseLegacyFontSizeOnlyIfPixelValuesMatch | 161 UseLegacyFontSizeOnlyIfPixelValuesMatch |
| 161 }; | 162 }; |
| 162 static int legacyFontSizeFromCSSValue(Document*, | 163 static int legacyFontSizeFromCSSValue(Document*, |
| 163 const CSSPrimitiveValue*, | 164 const CSSValue*, |
| 164 bool, | 165 bool, |
| 165 LegacyFontSizeMode); | 166 LegacyFontSizeMode); |
| 166 static bool isTransparentColorValue(const CSSValue*); | 167 static bool isTransparentColorValue(const CSSValue*); |
| 167 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); | 168 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); |
| 168 static bool hasTransparentBackgroundColor(StylePropertySet*); | 169 static bool hasTransparentBackgroundColor(StylePropertySet*); |
| 169 static const CSSValue* backgroundColorValueInEffect(Node*); | 170 static const CSSValue* backgroundColorValueInEffect(Node*); |
| 170 static bool hasAncestorVerticalAlignStyle(Node&, CSSValueID); | 171 static bool hasAncestorVerticalAlignStyle(Node&, CSSValueID); |
| 171 | 172 |
| 172 class HTMLElementEquivalent : public GarbageCollected<HTMLElementEquivalent> { | 173 class HTMLElementEquivalent : public GarbageCollected<HTMLElementEquivalent> { |
| 173 public: | 174 public: |
| 174 static HTMLElementEquivalent* create(CSSPropertyID propertyID, | 175 static HTMLElementEquivalent* create(CSSPropertyID propertyID, |
| 175 CSSValueID primitiveValue, | 176 CSSValueID primitiveValue, |
| 176 const HTMLQualifiedName& tagName) { | 177 const HTMLQualifiedName& tagName) { |
| 177 return new HTMLElementEquivalent(propertyID, primitiveValue, tagName); | 178 return new HTMLElementEquivalent(propertyID, primitiveValue, tagName); |
| 178 } | 179 } |
| 179 | 180 |
| 180 virtual bool matches(const Element* element) const { | 181 virtual bool matches(const Element* element) const { |
| 181 return !m_tagName || element->hasTagName(*m_tagName); | 182 return !m_tagName || element->hasTagName(*m_tagName); |
| 182 } | 183 } |
| 183 virtual bool hasAttribute() const { return false; } | 184 virtual bool hasAttribute() const { return false; } |
| 184 virtual bool propertyExistsInStyle(const StylePropertySet* style) const { | 185 virtual bool propertyExistsInStyle(const StylePropertySet* style) const { |
| 185 return style->getPropertyCSSValue(m_propertyID); | 186 return style->getPropertyCSSValue(m_propertyID); |
| 186 } | 187 } |
| 187 virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const; | 188 virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const; |
| 188 virtual void addToStyle(Element*, EditingStyle*) const; | 189 virtual void addToStyle(Element*, EditingStyle*) const; |
| 189 | 190 |
| 190 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_primitiveValue); } | 191 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_identifierValue); } |
| 191 | 192 |
| 192 protected: | 193 protected: |
| 193 HTMLElementEquivalent(CSSPropertyID); | 194 HTMLElementEquivalent(CSSPropertyID); |
| 194 HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName); | 195 HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName); |
| 195 HTMLElementEquivalent(CSSPropertyID, | 196 HTMLElementEquivalent(CSSPropertyID, |
| 196 CSSValueID primitiveValue, | 197 CSSValueID primitiveValue, |
| 197 const HTMLQualifiedName& tagName); | 198 const HTMLQualifiedName& tagName); |
| 198 const CSSPropertyID m_propertyID; | 199 const CSSPropertyID m_propertyID; |
| 199 const Member<CSSPrimitiveValue> m_primitiveValue; | 200 const Member<CSSIdentifierValue> m_identifierValue; |
| 200 const HTMLQualifiedName* | 201 const HTMLQualifiedName* |
| 201 m_tagName; // We can store a pointer because HTML tag names are const glo
bal. | 202 m_tagName; // We can store a pointer because HTML tag names are const glo
bal. |
| 202 }; | 203 }; |
| 203 | 204 |
| 204 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id) | 205 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id) |
| 205 : m_propertyID(id), m_tagName(0) {} | 206 : m_propertyID(id), m_tagName(0) {} |
| 206 | 207 |
| 207 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, | 208 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, |
| 208 const HTMLQualifiedName& tagName) | 209 const HTMLQualifiedName& tagName) |
| 209 : m_propertyID(id), m_tagName(&tagName) {} | 210 : m_propertyID(id), m_tagName(&tagName) {} |
| 210 | 211 |
| 211 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, | 212 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, |
| 212 CSSValueID primitiveValue, | 213 CSSValueID valueID, |
| 213 const HTMLQualifiedName& tagName) | 214 const HTMLQualifiedName& tagName) |
| 214 : m_propertyID(id), | 215 : m_propertyID(id), |
| 215 m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue)), | 216 m_identifierValue(CSSIdentifierValue::create(valueID)), |
| 216 m_tagName(&tagName) { | 217 m_tagName(&tagName) { |
| 217 DCHECK_NE(primitiveValue, CSSValueInvalid); | 218 DCHECK_NE(valueID, CSSValueInvalid); |
| 218 } | 219 } |
| 219 | 220 |
| 220 bool HTMLElementEquivalent::valueIsPresentInStyle( | 221 bool HTMLElementEquivalent::valueIsPresentInStyle( |
| 221 HTMLElement* element, | 222 HTMLElement* element, |
| 222 StylePropertySet* style) const { | 223 StylePropertySet* style) const { |
| 223 const CSSValue* value = style->getPropertyCSSValue(m_propertyID); | 224 const CSSValue* value = style->getPropertyCSSValue(m_propertyID); |
| 224 return matches(element) && value && value->isPrimitiveValue() && | 225 return matches(element) && value && value->isIdentifierValue() && |
| 225 toCSSPrimitiveValue(value)->getValueID() == | 226 toCSSIdentifierValue(value)->getValueID() == |
| 226 m_primitiveValue->getValueID(); | 227 m_identifierValue->getValueID(); |
| 227 } | 228 } |
| 228 | 229 |
| 229 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const { | 230 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const { |
| 230 style->setProperty(m_propertyID, m_primitiveValue->cssText()); | 231 style->setProperty(m_propertyID, m_identifierValue->cssText()); |
| 231 } | 232 } |
| 232 | 233 |
| 233 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent { | 234 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent { |
| 234 public: | 235 public: |
| 235 static HTMLElementEquivalent* create(CSSValueID primitiveValue, | 236 static HTMLElementEquivalent* create(CSSValueID primitiveValue, |
| 236 const HTMLQualifiedName& tagName) { | 237 const HTMLQualifiedName& tagName) { |
| 237 return new HTMLTextDecorationEquivalent(primitiveValue, tagName); | 238 return new HTMLTextDecorationEquivalent(primitiveValue, tagName); |
| 238 } | 239 } |
| 239 bool propertyExistsInStyle(const StylePropertySet*) const override; | 240 bool propertyExistsInStyle(const StylePropertySet*) const override; |
| 240 bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const override; | 241 bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const override; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 262 } | 263 } |
| 263 | 264 |
| 264 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle( | 265 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle( |
| 265 HTMLElement* element, | 266 HTMLElement* element, |
| 266 StylePropertySet* style) const { | 267 StylePropertySet* style) const { |
| 267 const CSSValue* styleValue = | 268 const CSSValue* styleValue = |
| 268 style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect); | 269 style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect); |
| 269 if (!styleValue) | 270 if (!styleValue) |
| 270 styleValue = style->getPropertyCSSValue(textDecorationPropertyForEditing()); | 271 styleValue = style->getPropertyCSSValue(textDecorationPropertyForEditing()); |
| 271 return matches(element) && styleValue && styleValue->isValueList() && | 272 return matches(element) && styleValue && styleValue->isValueList() && |
| 272 toCSSValueList(styleValue)->hasValue(*m_primitiveValue); | 273 toCSSValueList(styleValue)->hasValue(*m_identifierValue); |
| 273 } | 274 } |
| 274 | 275 |
| 275 class HTMLAttributeEquivalent : public HTMLElementEquivalent { | 276 class HTMLAttributeEquivalent : public HTMLElementEquivalent { |
| 276 public: | 277 public: |
| 277 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, | 278 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, |
| 278 const HTMLQualifiedName& tagName, | 279 const HTMLQualifiedName& tagName, |
| 279 const QualifiedName& attrName) { | 280 const QualifiedName& attrName) { |
| 280 return new HTMLAttributeEquivalent(propertyID, tagName, attrName); | 281 return new HTMLAttributeEquivalent(propertyID, tagName, attrName); |
| 281 } | 282 } |
| 282 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, | 283 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 364 |
| 364 const CSSValue* HTMLFontSizeEquivalent::attributeValueAsCSSValue( | 365 const CSSValue* HTMLFontSizeEquivalent::attributeValueAsCSSValue( |
| 365 Element* element) const { | 366 Element* element) const { |
| 366 DCHECK(element); | 367 DCHECK(element); |
| 367 const AtomicString& value = element->getAttribute(m_attrName); | 368 const AtomicString& value = element->getAttribute(m_attrName); |
| 368 if (value.isNull()) | 369 if (value.isNull()) |
| 369 return nullptr; | 370 return nullptr; |
| 370 CSSValueID size; | 371 CSSValueID size; |
| 371 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) | 372 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) |
| 372 return nullptr; | 373 return nullptr; |
| 373 return CSSPrimitiveValue::createIdentifier(size); | 374 return CSSIdentifierValue::create(size); |
| 374 } | 375 } |
| 375 | 376 |
| 376 float EditingStyle::NoFontDelta = 0.0f; | 377 float EditingStyle::NoFontDelta = 0.0f; |
| 377 | 378 |
| 378 EditingStyle::EditingStyle(ContainerNode* node, | 379 EditingStyle::EditingStyle(ContainerNode* node, |
| 379 PropertiesToInclude propertiesToInclude) { | 380 PropertiesToInclude propertiesToInclude) { |
| 380 init(node, propertiesToInclude); | 381 init(node, propertiesToInclude); |
| 381 } | 382 } |
| 382 | 383 |
| 383 EditingStyle::EditingStyle(const Position& position, | 384 EditingStyle::EditingStyle(const Position& position, |
| 384 PropertiesToInclude propertiesToInclude) { | 385 PropertiesToInclude propertiesToInclude) { |
| 385 init(position.anchorNode(), propertiesToInclude); | 386 init(position.anchorNode(), propertiesToInclude); |
| 386 } | 387 } |
| 387 | 388 |
| 388 EditingStyle::EditingStyle(const StylePropertySet* style) | 389 EditingStyle::EditingStyle(const StylePropertySet* style) |
| 389 : m_mutableStyle(style ? style->mutableCopy() : nullptr) { | 390 : m_mutableStyle(style ? style->mutableCopy() : nullptr) { |
| 390 extractFontSizeDelta(); | 391 extractFontSizeDelta(); |
| 391 } | 392 } |
| 392 | 393 |
| 393 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) | 394 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) |
| 394 : m_mutableStyle(nullptr) { | 395 : m_mutableStyle(nullptr) { |
| 395 setProperty(propertyID, value); | 396 setProperty(propertyID, value); |
| 396 m_isVerticalAlign = propertyID == CSSPropertyVerticalAlign && | 397 m_isVerticalAlign = propertyID == CSSPropertyVerticalAlign && |
| 397 (value == "sub" || value == "super"); | 398 (value == "sub" || value == "super"); |
| 398 } | 399 } |
| 399 | 400 |
| 400 static Color cssValueToColor(const CSSValue* colorValue) { | 401 static Color cssValueToColor(const CSSValue* colorValue) { |
| 401 if (!colorValue || | 402 if (!colorValue || |
| 402 (!colorValue->isColorValue() && !colorValue->isPrimitiveValue())) | 403 (!colorValue->isColorValue() && !colorValue->isPrimitiveValue() && |
| 404 !colorValue->isIdentifierValue())) |
| 403 return Color::transparent; | 405 return Color::transparent; |
| 404 | 406 |
| 405 if (colorValue->isColorValue()) | 407 if (colorValue->isColorValue()) |
| 406 return toCSSColorValue(colorValue)->value(); | 408 return toCSSColorValue(colorValue)->value(); |
| 407 | 409 |
| 408 Color color = 0; | 410 Color color = 0; |
| 409 // FIXME: Why ignore the return value? | 411 // FIXME: Why ignore the return value? |
| 410 CSSParser::parseColor(color, colorValue->cssText()); | 412 CSSParser::parseColor(color, colorValue->cssText()); |
| 411 return color; | 413 return color; |
| 412 } | 414 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && | 555 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && |
| 554 m_fontSizeDelta == NoFontDelta; | 556 m_fontSizeDelta == NoFontDelta; |
| 555 } | 557 } |
| 556 | 558 |
| 557 bool EditingStyle::textDirection(WritingDirection& writingDirection) const { | 559 bool EditingStyle::textDirection(WritingDirection& writingDirection) const { |
| 558 if (!m_mutableStyle) | 560 if (!m_mutableStyle) |
| 559 return false; | 561 return false; |
| 560 | 562 |
| 561 const CSSValue* unicodeBidi = | 563 const CSSValue* unicodeBidi = |
| 562 m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi); | 564 m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi); |
| 563 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) | 565 if (!unicodeBidi || !unicodeBidi->isIdentifierValue()) |
| 564 return false; | 566 return false; |
| 565 | 567 |
| 566 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID(); | 568 CSSValueID unicodeBidiValue = toCSSIdentifierValue(unicodeBidi)->getValueID(); |
| 567 if (isEmbedOrIsolate(unicodeBidiValue)) { | 569 if (isEmbedOrIsolate(unicodeBidiValue)) { |
| 568 const CSSValue* direction = | 570 const CSSValue* direction = |
| 569 m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection); | 571 m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection); |
| 570 if (!direction || !direction->isPrimitiveValue()) | 572 if (!direction || !direction->isIdentifierValue()) |
| 571 return false; | 573 return false; |
| 572 | 574 |
| 573 writingDirection = | 575 writingDirection = |
| 574 toCSSPrimitiveValue(direction)->getValueID() == CSSValueLtr | 576 toCSSIdentifierValue(direction)->getValueID() == CSSValueLtr |
| 575 ? LeftToRightWritingDirection | 577 ? LeftToRightWritingDirection |
| 576 : RightToLeftWritingDirection; | 578 : RightToLeftWritingDirection; |
| 577 | 579 |
| 578 return true; | 580 return true; |
| 579 } | 581 } |
| 580 | 582 |
| 581 if (unicodeBidiValue == CSSValueNormal) { | 583 if (unicodeBidiValue == CSSValueNormal) { |
| 582 writingDirection = NaturalWritingDirection; | 584 writingDirection = NaturalWritingDirection; |
| 583 return true; | 585 return true; |
| 584 } | 586 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 if (node.layoutObject() && hasEditableStyle(node)) { | 792 if (node.layoutObject() && hasEditableStyle(node)) { |
| 791 CSSComputedStyleDeclaration* nodeStyle = | 793 CSSComputedStyleDeclaration* nodeStyle = |
| 792 CSSComputedStyleDeclaration::create(&node); | 794 CSSComputedStyleDeclaration::create(&node); |
| 793 if (nodeStyle) { | 795 if (nodeStyle) { |
| 794 // If the selected element has <sub> or <sup> ancestor element, apply th
e corresponding | 796 // If the selected element has <sub> or <sup> ancestor element, apply th
e corresponding |
| 795 // style(vertical-align) to it so that document.queryCommandState() work
s with the style. | 797 // style(vertical-align) to it so that document.queryCommandState() work
s with the style. |
| 796 // See bug http://crbug.com/582225. | 798 // See bug http://crbug.com/582225. |
| 797 if (m_isVerticalAlign && | 799 if (m_isVerticalAlign && |
| 798 getIdentifierValue(nodeStyle, CSSPropertyVerticalAlign) == | 800 getIdentifierValue(nodeStyle, CSSPropertyVerticalAlign) == |
| 799 CSSValueBaseline) { | 801 CSSValueBaseline) { |
| 800 const CSSPrimitiveValue* verticalAlign = toCSSPrimitiveValue( | 802 const CSSIdentifierValue* verticalAlign = toCSSIdentifierValue( |
| 801 m_mutableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign)); | 803 m_mutableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign)); |
| 802 if (hasAncestorVerticalAlignStyle(node, verticalAlign->getValueID())) | 804 if (hasAncestorVerticalAlignStyle(node, verticalAlign->getValueID())) |
| 803 node.mutableComputedStyle()->setVerticalAlign( | 805 node.mutableComputedStyle()->setVerticalAlign( |
| 804 verticalAlign->convertTo<EVerticalAlign>()); | 806 verticalAlign->convertTo<EVerticalAlign>()); |
| 805 } | 807 } |
| 806 | 808 |
| 807 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without checking if
node.isTextNode() | 809 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without checking if
node.isTextNode() |
| 808 // because the node can be an element node. See bug http://crbug.com/584
939. | 810 // because the node can be an element node. See bug http://crbug.com/584
939. |
| 809 TriState nodeState = triStateOfStyle( | 811 TriState nodeState = triStateOfStyle( |
| 810 nodeStyle, EditingStyle::DoNotIgnoreTextOnlyProperties); | 812 nodeStyle, EditingStyle::DoNotIgnoreTextOnlyProperties); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 | 1113 |
| 1112 if (getFontColor(m_mutableStyle.get()) == getFontColor(styleAtPosition)) | 1114 if (getFontColor(m_mutableStyle.get()) == getFontColor(styleAtPosition)) |
| 1113 m_mutableStyle->removeProperty(CSSPropertyColor); | 1115 m_mutableStyle->removeProperty(CSSPropertyColor); |
| 1114 | 1116 |
| 1115 if (hasTransparentBackgroundColor(m_mutableStyle.get()) || | 1117 if (hasTransparentBackgroundColor(m_mutableStyle.get()) || |
| 1116 cssValueToColor( | 1118 cssValueToColor( |
| 1117 m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor)) == | 1119 m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor)) == |
| 1118 backgroundColorInEffect(position.computeContainerNode())) | 1120 backgroundColorInEffect(position.computeContainerNode())) |
| 1119 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor); | 1121 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor); |
| 1120 | 1122 |
| 1121 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) { | 1123 if (unicodeBidi && unicodeBidi->isIdentifierValue()) { |
| 1122 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, | 1124 m_mutableStyle->setProperty( |
| 1123 toCSSPrimitiveValue(unicodeBidi)->getValueID()); | 1125 CSSPropertyUnicodeBidi, |
| 1124 if (direction && direction->isPrimitiveValue()) | 1126 toCSSIdentifierValue(unicodeBidi)->getValueID()); |
| 1125 m_mutableStyle->setProperty(CSSPropertyDirection, | 1127 if (direction && direction->isIdentifierValue()) { |
| 1126 toCSSPrimitiveValue(direction)->getValueID()); | 1128 m_mutableStyle->setProperty( |
| 1129 CSSPropertyDirection, toCSSIdentifierValue(direction)->getValueID()); |
| 1130 } |
| 1127 } | 1131 } |
| 1128 } | 1132 } |
| 1129 | 1133 |
| 1130 void EditingStyle::mergeTypingStyle(Document* document) { | 1134 void EditingStyle::mergeTypingStyle(Document* document) { |
| 1131 DCHECK(document); | 1135 DCHECK(document); |
| 1132 | 1136 |
| 1133 EditingStyle* typingStyle = document->frame()->selection().typingStyle(); | 1137 EditingStyle* typingStyle = document->frame()->selection().typingStyle(); |
| 1134 if (!typingStyle || typingStyle == this) | 1138 if (!typingStyle || typingStyle == this) |
| 1135 return; | 1139 return; |
| 1136 | 1140 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 EditingStyle::EditingPropertiesInEffect); | 1264 EditingStyle::EditingPropertiesInEffect); |
| 1261 } | 1265 } |
| 1262 } | 1266 } |
| 1263 | 1267 |
| 1264 return wrappingStyle; | 1268 return wrappingStyle; |
| 1265 } | 1269 } |
| 1266 | 1270 |
| 1267 static const CSSValueList& mergeTextDecorationValues( | 1271 static const CSSValueList& mergeTextDecorationValues( |
| 1268 const CSSValueList& mergedValue, | 1272 const CSSValueList& mergedValue, |
| 1269 const CSSValueList& valueToMerge) { | 1273 const CSSValueList& valueToMerge) { |
| 1270 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, | 1274 DEFINE_STATIC_LOCAL(CSSIdentifierValue, underline, |
| 1271 (CSSPrimitiveValue::createIdentifier(CSSValueUnderline))); | 1275 (CSSIdentifierValue::create(CSSValueUnderline))); |
| 1272 DEFINE_STATIC_LOCAL( | 1276 DEFINE_STATIC_LOCAL(CSSIdentifierValue, lineThrough, |
| 1273 CSSPrimitiveValue, lineThrough, | 1277 (CSSIdentifierValue::create(CSSValueLineThrough))); |
| 1274 (CSSPrimitiveValue::createIdentifier(CSSValueLineThrough))); | |
| 1275 CSSValueList& result = *mergedValue.copy(); | 1278 CSSValueList& result = *mergedValue.copy(); |
| 1276 if (valueToMerge.hasValue(underline) && !mergedValue.hasValue(underline)) | 1279 if (valueToMerge.hasValue(underline) && !mergedValue.hasValue(underline)) |
| 1277 result.append(underline); | 1280 result.append(underline); |
| 1278 | 1281 |
| 1279 if (valueToMerge.hasValue(lineThrough) && !mergedValue.hasValue(lineThrough)) | 1282 if (valueToMerge.hasValue(lineThrough) && !mergedValue.hasValue(lineThrough)) |
| 1280 result.append(lineThrough); | 1283 result.append(lineThrough); |
| 1281 | 1284 |
| 1282 return result; | 1285 return result; |
| 1283 } | 1286 } |
| 1284 | 1287 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 if (!m_mutableStyle) | 1486 if (!m_mutableStyle) |
| 1484 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); | 1487 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); |
| 1485 const bool propertyIsImportant = true; | 1488 const bool propertyIsImportant = true; |
| 1486 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, | 1489 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, |
| 1487 propertyIsImportant); | 1490 propertyIsImportant); |
| 1488 } | 1491 } |
| 1489 | 1492 |
| 1490 int EditingStyle::legacyFontSize(Document* document) const { | 1493 int EditingStyle::legacyFontSize(Document* document) const { |
| 1491 const CSSValue* cssValue = | 1494 const CSSValue* cssValue = |
| 1492 m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize); | 1495 m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize); |
| 1493 if (!cssValue || !cssValue->isPrimitiveValue()) | 1496 if (!cssValue || |
| 1497 !(cssValue->isPrimitiveValue() || cssValue->isIdentifierValue())) |
| 1494 return 0; | 1498 return 0; |
| 1495 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue), | 1499 return legacyFontSizeFromCSSValue(document, cssValue, m_isMonospaceFont, |
| 1496 m_isMonospaceFont, AlwaysUseLegacyFontSize); | 1500 AlwaysUseLegacyFontSize); |
| 1497 } | 1501 } |
| 1498 | 1502 |
| 1499 EditingStyle* EditingStyle::styleAtSelectionStart( | 1503 EditingStyle* EditingStyle::styleAtSelectionStart( |
| 1500 const VisibleSelection& selection, | 1504 const VisibleSelection& selection, |
| 1501 bool shouldUseBackgroundColorInEffect, | 1505 bool shouldUseBackgroundColorInEffect, |
| 1502 MutableStylePropertySet* styleToCheck) { | 1506 MutableStylePropertySet* styleToCheck) { |
| 1503 if (selection.isNone()) | 1507 if (selection.isNone()) |
| 1504 return nullptr; | 1508 return nullptr; |
| 1505 | 1509 |
| 1506 Document& document = *selection.start().document(); | 1510 Document& document = *selection.start().document(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 const EphemeralRange caretRange(position.parentAnchoredEquivalent(), | 1599 const EphemeralRange caretRange(position.parentAnchoredEquivalent(), |
| 1596 end.parentAnchoredEquivalent()); | 1600 end.parentAnchoredEquivalent()); |
| 1597 for (Node& n : caretRange.nodes()) { | 1601 for (Node& n : caretRange.nodes()) { |
| 1598 if (!n.isStyledElement()) | 1602 if (!n.isStyledElement()) |
| 1599 continue; | 1603 continue; |
| 1600 | 1604 |
| 1601 CSSComputedStyleDeclaration* style = | 1605 CSSComputedStyleDeclaration* style = |
| 1602 CSSComputedStyleDeclaration::create(&n); | 1606 CSSComputedStyleDeclaration::create(&n); |
| 1603 const CSSValue* unicodeBidi = | 1607 const CSSValue* unicodeBidi = |
| 1604 style->getPropertyCSSValue(CSSPropertyUnicodeBidi); | 1608 style->getPropertyCSSValue(CSSPropertyUnicodeBidi); |
| 1605 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) | 1609 if (!unicodeBidi || !unicodeBidi->isIdentifierValue()) |
| 1606 continue; | 1610 continue; |
| 1607 | 1611 |
| 1608 CSSValueID unicodeBidiValue = | 1612 CSSValueID unicodeBidiValue = |
| 1609 toCSSPrimitiveValue(unicodeBidi)->getValueID(); | 1613 toCSSIdentifierValue(unicodeBidi)->getValueID(); |
| 1610 if (isUnicodeBidiNestedOrMultipleEmbeddings(unicodeBidiValue)) | 1614 if (isUnicodeBidiNestedOrMultipleEmbeddings(unicodeBidiValue)) |
| 1611 return NaturalWritingDirection; | 1615 return NaturalWritingDirection; |
| 1612 } | 1616 } |
| 1613 } | 1617 } |
| 1614 | 1618 |
| 1615 if (selection.isCaret()) { | 1619 if (selection.isCaret()) { |
| 1616 WritingDirection direction; | 1620 WritingDirection direction; |
| 1617 if (typingStyle && typingStyle->textDirection(direction)) { | 1621 if (typingStyle && typingStyle->textDirection(direction)) { |
| 1618 hasNestedOrMultipleEmbeddings = false; | 1622 hasNestedOrMultipleEmbeddings = false; |
| 1619 return direction; | 1623 return direction; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1631 if (runner == block) | 1635 if (runner == block) |
| 1632 break; | 1636 break; |
| 1633 if (!runner.isStyledElement()) | 1637 if (!runner.isStyledElement()) |
| 1634 continue; | 1638 continue; |
| 1635 | 1639 |
| 1636 Element* element = &toElement(runner); | 1640 Element* element = &toElement(runner); |
| 1637 CSSComputedStyleDeclaration* style = | 1641 CSSComputedStyleDeclaration* style = |
| 1638 CSSComputedStyleDeclaration::create(element); | 1642 CSSComputedStyleDeclaration::create(element); |
| 1639 const CSSValue* unicodeBidi = | 1643 const CSSValue* unicodeBidi = |
| 1640 style->getPropertyCSSValue(CSSPropertyUnicodeBidi); | 1644 style->getPropertyCSSValue(CSSPropertyUnicodeBidi); |
| 1641 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) | 1645 if (!unicodeBidi || !unicodeBidi->isIdentifierValue()) |
| 1642 continue; | 1646 continue; |
| 1643 | 1647 |
| 1644 CSSValueID unicodeBidiValue = | 1648 CSSValueID unicodeBidiValue = |
| 1645 toCSSPrimitiveValue(unicodeBidi)->getValueID(); | 1649 toCSSIdentifierValue(unicodeBidi)->getValueID(); |
| 1646 if (unicodeBidiValue == CSSValueNormal) | 1650 if (unicodeBidiValue == CSSValueNormal) |
| 1647 continue; | 1651 continue; |
| 1648 | 1652 |
| 1649 if (unicodeBidiValue == CSSValueBidiOverride) | 1653 if (unicodeBidiValue == CSSValueBidiOverride) |
| 1650 return NaturalWritingDirection; | 1654 return NaturalWritingDirection; |
| 1651 | 1655 |
| 1652 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue; | 1656 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue; |
| 1653 const CSSValue* direction = | 1657 const CSSValue* direction = |
| 1654 style->getPropertyCSSValue(CSSPropertyDirection); | 1658 style->getPropertyCSSValue(CSSPropertyDirection); |
| 1655 if (!direction || !direction->isPrimitiveValue()) | 1659 if (!direction || !direction->isIdentifierValue()) |
| 1656 continue; | 1660 continue; |
| 1657 | 1661 |
| 1658 int directionValue = toCSSPrimitiveValue(direction)->getValueID(); | 1662 int directionValue = toCSSIdentifierValue(direction)->getValueID(); |
| 1659 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) | 1663 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) |
| 1660 continue; | 1664 continue; |
| 1661 | 1665 |
| 1662 if (foundDirection != NaturalWritingDirection) | 1666 if (foundDirection != NaturalWritingDirection) |
| 1663 return NaturalWritingDirection; | 1667 return NaturalWritingDirection; |
| 1664 | 1668 |
| 1665 // In the range case, make sure that the embedding element persists until th
e end of the range. | 1669 // In the range case, make sure that the embedding element persists until th
e end of the range. |
| 1666 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element)) | 1670 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element)) |
| 1667 return NaturalWritingDirection; | 1671 return NaturalWritingDirection; |
| 1668 | 1672 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { | 1767 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { |
| 1764 style->removeProperty(CSSPropertyFontStyle); | 1768 style->removeProperty(CSSPropertyFontStyle); |
| 1765 m_applyItalic = true; | 1769 m_applyItalic = true; |
| 1766 } | 1770 } |
| 1767 | 1771 |
| 1768 // Assuming reconcileTextDecorationProperties has been called, there should no
t be -webkit-text-decorations-in-effect | 1772 // Assuming reconcileTextDecorationProperties has been called, there should no
t be -webkit-text-decorations-in-effect |
| 1769 // Furthermore, text-decoration: none has been trimmed so that text-decoration
property is always a CSSValueList. | 1773 // Furthermore, text-decoration: none has been trimmed so that text-decoration
property is always a CSSValueList. |
| 1770 const CSSValue* textDecoration = | 1774 const CSSValue* textDecoration = |
| 1771 style->getPropertyCSSValue(textDecorationPropertyForEditing()); | 1775 style->getPropertyCSSValue(textDecorationPropertyForEditing()); |
| 1772 if (textDecoration && textDecoration->isValueList()) { | 1776 if (textDecoration && textDecoration->isValueList()) { |
| 1773 DEFINE_STATIC_LOCAL( | 1777 DEFINE_STATIC_LOCAL(CSSIdentifierValue, underline, |
| 1774 CSSPrimitiveValue, underline, | 1778 (CSSIdentifierValue::create(CSSValueUnderline))); |
| 1775 (CSSPrimitiveValue::createIdentifier(CSSValueUnderline))); | 1779 DEFINE_STATIC_LOCAL(CSSIdentifierValue, lineThrough, |
| 1776 DEFINE_STATIC_LOCAL( | 1780 (CSSIdentifierValue::create(CSSValueLineThrough))); |
| 1777 CSSPrimitiveValue, lineThrough, | |
| 1778 (CSSPrimitiveValue::createIdentifier(CSSValueLineThrough))); | |
| 1779 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy(); | 1781 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy(); |
| 1780 if (newTextDecoration->removeAll(underline)) | 1782 if (newTextDecoration->removeAll(underline)) |
| 1781 m_applyUnderline = true; | 1783 m_applyUnderline = true; |
| 1782 if (newTextDecoration->removeAll(lineThrough)) | 1784 if (newTextDecoration->removeAll(lineThrough)) |
| 1783 m_applyLineThrough = true; | 1785 m_applyLineThrough = true; |
| 1784 | 1786 |
| 1785 // If trimTextDecorations, delete underline and line-through | 1787 // If trimTextDecorations, delete underline and line-through |
| 1786 setTextDecorationProperty(style, newTextDecoration, | 1788 setTextDecorationProperty(style, newTextDecoration, |
| 1787 textDecorationPropertyForEditing()); | 1789 textDecorationPropertyForEditing()); |
| 1788 } | 1790 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1804 style->removeProperty(CSSPropertyColor); | 1806 style->removeProperty(CSSPropertyColor); |
| 1805 } | 1807 } |
| 1806 | 1808 |
| 1807 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); | 1809 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); |
| 1808 // Remove double quotes for Outlook 2007 compatibility. See https://bugs.webki
t.org/show_bug.cgi?id=79448 | 1810 // Remove double quotes for Outlook 2007 compatibility. See https://bugs.webki
t.org/show_bug.cgi?id=79448 |
| 1809 m_applyFontFace.replace('"', ""); | 1811 m_applyFontFace.replace('"', ""); |
| 1810 style->removeProperty(CSSPropertyFontFamily); | 1812 style->removeProperty(CSSPropertyFontFamily); |
| 1811 | 1813 |
| 1812 if (const CSSValue* fontSize = | 1814 if (const CSSValue* fontSize = |
| 1813 style->getPropertyCSSValue(CSSPropertyFontSize)) { | 1815 style->getPropertyCSSValue(CSSPropertyFontSize)) { |
| 1814 if (!fontSize->isPrimitiveValue()) { | 1816 if (!fontSize->isPrimitiveValue() && !fontSize->isIdentifierValue()) { |
| 1815 style->removeProperty( | 1817 style->removeProperty( |
| 1816 CSSPropertyFontSize); // Can't make sense of the number. Put no font
size. | 1818 CSSPropertyFontSize); // Can't make sense of the number. Put no font
size. |
| 1817 } else if (int legacyFontSize = legacyFontSizeFromCSSValue( | 1819 } else if (int legacyFontSize = legacyFontSizeFromCSSValue( |
| 1818 document, toCSSPrimitiveValue(fontSize), isMonospaceFont, | 1820 document, fontSize, isMonospaceFont, |
| 1819 UseLegacyFontSizeOnlyIfPixelValuesMatch)) { | 1821 UseLegacyFontSizeOnlyIfPixelValuesMatch)) { |
| 1820 m_applyFontSize = String::number(legacyFontSize); | 1822 m_applyFontSize = String::number(legacyFontSize); |
| 1821 style->removeProperty(CSSPropertyFontSize); | 1823 style->removeProperty(CSSPropertyFontSize); |
| 1822 } | 1824 } |
| 1823 } | 1825 } |
| 1824 } | 1826 } |
| 1825 | 1827 |
| 1826 static void diffTextDecorations(MutableStylePropertySet* style, | 1828 static void diffTextDecorations(MutableStylePropertySet* style, |
| 1827 CSSPropertyID propertyID, | 1829 CSSPropertyID propertyID, |
| 1828 const CSSValue* refTextDecoration) { | 1830 const CSSValue* refTextDecoration) { |
| 1829 const CSSValue* textDecoration = style->getPropertyCSSValue(propertyID); | 1831 const CSSValue* textDecoration = style->getPropertyCSSValue(propertyID); |
| 1830 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || | 1832 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || |
| 1831 !refTextDecoration->isValueList()) | 1833 !refTextDecoration->isValueList()) |
| 1832 return; | 1834 return; |
| 1833 | 1835 |
| 1834 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy(); | 1836 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy(); |
| 1835 const CSSValueList* valuesInRefTextDecoration = | 1837 const CSSValueList* valuesInRefTextDecoration = |
| 1836 toCSSValueList(refTextDecoration); | 1838 toCSSValueList(refTextDecoration); |
| 1837 | 1839 |
| 1838 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++) | 1840 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++) |
| 1839 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i)); | 1841 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i)); |
| 1840 | 1842 |
| 1841 setTextDecorationProperty(style, newTextDecoration, propertyID); | 1843 setTextDecorationProperty(style, newTextDecoration, propertyID); |
| 1842 } | 1844 } |
| 1843 | 1845 |
| 1844 static bool fontWeightIsBold(const CSSValue* fontWeight) { | 1846 static bool fontWeightIsBold(const CSSValue* fontWeight) { |
| 1845 if (!fontWeight->isPrimitiveValue()) | 1847 if (!fontWeight->isIdentifierValue()) |
| 1846 return false; | 1848 return false; |
| 1847 | 1849 |
| 1848 // Because b tag can only bold text, there are only two states in plain html:
bold and not bold. | 1850 // Because b tag can only bold text, there are only two states in plain html:
bold and not bold. |
| 1849 // Collapse all other values to either one of these two states for editing pur
poses. | 1851 // Collapse all other values to either one of these two states for editing pur
poses. |
| 1850 switch (toCSSPrimitiveValue(fontWeight)->getValueID()) { | 1852 switch (toCSSIdentifierValue(fontWeight)->getValueID()) { |
| 1851 case CSSValue100: | 1853 case CSSValue100: |
| 1852 case CSSValue200: | 1854 case CSSValue200: |
| 1853 case CSSValue300: | 1855 case CSSValue300: |
| 1854 case CSSValue400: | 1856 case CSSValue400: |
| 1855 case CSSValue500: | 1857 case CSSValue500: |
| 1856 case CSSValueNormal: | 1858 case CSSValueNormal: |
| 1857 return false; | 1859 return false; |
| 1858 case CSSValueBold: | 1860 case CSSValueBold: |
| 1859 case CSSValue600: | 1861 case CSSValue600: |
| 1860 case CSSValue700: | 1862 case CSSValue700: |
| 1861 case CSSValue800: | 1863 case CSSValue800: |
| 1862 case CSSValue900: | 1864 case CSSValue900: |
| 1863 return true; | 1865 return true; |
| 1864 default: | 1866 default: |
| 1865 break; | 1867 break; |
| 1866 } | 1868 } |
| 1867 | 1869 |
| 1868 NOTREACHED(); // For CSSValueBolder and CSSValueLighter | 1870 NOTREACHED(); // For CSSValueBolder and CSSValueLighter |
| 1869 return false; | 1871 return false; |
| 1870 } | 1872 } |
| 1871 | 1873 |
| 1872 static bool fontWeightNeedsResolving(const CSSValue* fontWeight) { | 1874 static bool fontWeightNeedsResolving(const CSSValue* fontWeight) { |
| 1873 if (!fontWeight->isPrimitiveValue()) | 1875 if (!fontWeight->isIdentifierValue()) |
| 1874 return true; | 1876 return true; |
| 1875 | 1877 |
| 1876 const CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID(); | 1878 const CSSValueID value = toCSSIdentifierValue(fontWeight)->getValueID(); |
| 1877 return value == CSSValueLighter || value == CSSValueBolder; | 1879 return value == CSSValueLighter || value == CSSValueBolder; |
| 1878 } | 1880 } |
| 1879 | 1881 |
| 1880 MutableStylePropertySet* getPropertiesNotIn( | 1882 MutableStylePropertySet* getPropertiesNotIn( |
| 1881 StylePropertySet* styleWithRedundantProperties, | 1883 StylePropertySet* styleWithRedundantProperties, |
| 1882 CSSStyleDeclaration* baseStyle) { | 1884 CSSStyleDeclaration* baseStyle) { |
| 1883 DCHECK(styleWithRedundantProperties); | 1885 DCHECK(styleWithRedundantProperties); |
| 1884 DCHECK(baseStyle); | 1886 DCHECK(baseStyle); |
| 1885 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy(); | 1887 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy(); |
| 1886 | 1888 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 result->removeProperty(CSSPropertyBackgroundColor); | 1921 result->removeProperty(CSSPropertyBackgroundColor); |
| 1920 | 1922 |
| 1921 return result; | 1923 return result; |
| 1922 } | 1924 } |
| 1923 | 1925 |
| 1924 CSSValueID getIdentifierValue(StylePropertySet* style, | 1926 CSSValueID getIdentifierValue(StylePropertySet* style, |
| 1925 CSSPropertyID propertyID) { | 1927 CSSPropertyID propertyID) { |
| 1926 if (!style) | 1928 if (!style) |
| 1927 return CSSValueInvalid; | 1929 return CSSValueInvalid; |
| 1928 const CSSValue* value = style->getPropertyCSSValue(propertyID); | 1930 const CSSValue* value = style->getPropertyCSSValue(propertyID); |
| 1929 if (!value || !value->isPrimitiveValue()) | 1931 if (!value || !value->isIdentifierValue()) |
| 1930 return CSSValueInvalid; | 1932 return CSSValueInvalid; |
| 1931 return toCSSPrimitiveValue(value)->getValueID(); | 1933 return toCSSIdentifierValue(value)->getValueID(); |
| 1932 } | 1934 } |
| 1933 | 1935 |
| 1934 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, | 1936 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, |
| 1935 CSSPropertyID propertyID) { | 1937 CSSPropertyID propertyID) { |
| 1936 if (!style) | 1938 if (!style) |
| 1937 return CSSValueInvalid; | 1939 return CSSValueInvalid; |
| 1938 const CSSValue* value = style->getPropertyCSSValueInternal(propertyID); | 1940 const CSSValue* value = style->getPropertyCSSValueInternal(propertyID); |
| 1939 if (!value || !value->isPrimitiveValue()) | 1941 if (!value || !value->isIdentifierValue()) |
| 1940 return CSSValueInvalid; | 1942 return CSSValueInvalid; |
| 1941 return toCSSPrimitiveValue(value)->getValueID(); | 1943 return toCSSIdentifierValue(value)->getValueID(); |
| 1942 } | 1944 } |
| 1943 | 1945 |
| 1944 int legacyFontSizeFromCSSValue(Document* document, | 1946 int legacyFontSizeFromCSSValue(Document* document, |
| 1945 const CSSPrimitiveValue* value, | 1947 const CSSValue* value, |
| 1946 bool isMonospaceFont, | 1948 bool isMonospaceFont, |
| 1947 LegacyFontSizeMode mode) { | 1949 LegacyFontSizeMode mode) { |
| 1948 CSSPrimitiveValue::LengthUnitType lengthType; | 1950 if (value->isPrimitiveValue()) { |
| 1949 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value->typeWithCalcResolved(), | 1951 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(*value); |
| 1950 lengthType) && | 1952 CSSPrimitiveValue::LengthUnitType lengthType; |
| 1951 lengthType == CSSPrimitiveValue::UnitTypePixels) { | 1953 if (CSSPrimitiveValue::unitTypeToLengthUnitType( |
| 1952 double conversion = | 1954 primitiveValue.typeWithCalcResolved(), lengthType) && |
| 1953 CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor( | 1955 lengthType == CSSPrimitiveValue::UnitTypePixels) { |
| 1954 value->typeWithCalcResolved()); | 1956 double conversion = |
| 1955 int pixelFontSize = clampTo<int>(value->getDoubleValue() * conversion); | 1957 CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor( |
| 1956 int legacyFontSize = | 1958 primitiveValue.typeWithCalcResolved()); |
| 1957 FontSize::legacyFontSize(document, pixelFontSize, isMonospaceFont); | 1959 int pixelFontSize = |
| 1958 // Use legacy font size only if pixel value matches exactly to that of legac
y font size. | 1960 clampTo<int>(primitiveValue.getDoubleValue() * conversion); |
| 1959 if (mode == AlwaysUseLegacyFontSize || | 1961 int legacyFontSize = |
| 1960 FontSize::fontSizeForKeyword(document, legacyFontSize, | 1962 FontSize::legacyFontSize(document, pixelFontSize, isMonospaceFont); |
| 1961 isMonospaceFont) == pixelFontSize) | 1963 // Use legacy font size only if pixel value matches exactly to that of leg
acy font size. |
| 1962 return legacyFontSize; | 1964 if (mode == AlwaysUseLegacyFontSize || |
| 1965 FontSize::fontSizeForKeyword(document, legacyFontSize, |
| 1966 isMonospaceFont) == pixelFontSize) |
| 1967 return legacyFontSize; |
| 1963 | 1968 |
| 1964 return 0; | 1969 return 0; |
| 1970 } |
| 1965 } | 1971 } |
| 1966 | 1972 |
| 1967 if (CSSValueXSmall <= value->getValueID() && | 1973 if (value->isIdentifierValue()) { |
| 1968 value->getValueID() <= CSSValueWebkitXxxLarge) | 1974 const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(*value); |
| 1969 return value->getValueID() - CSSValueXSmall + 1; | 1975 if (CSSValueXSmall <= identifierValue.getValueID() && |
| 1976 identifierValue.getValueID() <= CSSValueWebkitXxxLarge) |
| 1977 return identifierValue.getValueID() - CSSValueXSmall + 1; |
| 1978 } |
| 1970 | 1979 |
| 1971 return 0; | 1980 return 0; |
| 1972 } | 1981 } |
| 1973 | 1982 |
| 1974 bool isTransparentColorValue(const CSSValue* cssValue) { | 1983 bool isTransparentColorValue(const CSSValue* cssValue) { |
| 1975 if (!cssValue) | 1984 if (!cssValue) |
| 1976 return true; | 1985 return true; |
| 1977 if (cssValue->isColorValue()) | 1986 if (cssValue->isColorValue()) |
| 1978 return !toCSSColorValue(cssValue)->value().alpha(); | 1987 return !toCSSColorValue(cssValue)->value().alpha(); |
| 1979 if (!cssValue->isPrimitiveValue()) | 1988 if (!cssValue->isIdentifierValue()) |
| 1980 return false; | 1989 return false; |
| 1981 const CSSPrimitiveValue* value = toCSSPrimitiveValue(cssValue); | 1990 return toCSSIdentifierValue(cssValue)->getValueID() == CSSValueTransparent; |
| 1982 return value->getValueID() == CSSValueTransparent; | |
| 1983 } | 1991 } |
| 1984 | 1992 |
| 1985 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style) { | 1993 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style) { |
| 1986 const CSSValue* cssValue = | 1994 const CSSValue* cssValue = |
| 1987 style->getPropertyCSSValueInternal(CSSPropertyBackgroundColor); | 1995 style->getPropertyCSSValueInternal(CSSPropertyBackgroundColor); |
| 1988 return isTransparentColorValue(cssValue); | 1996 return isTransparentColorValue(cssValue); |
| 1989 } | 1997 } |
| 1990 | 1998 |
| 1991 bool hasTransparentBackgroundColor(StylePropertySet* style) { | 1999 bool hasTransparentBackgroundColor(StylePropertySet* style) { |
| 1992 const CSSValue* cssValue = | 2000 const CSSValue* cssValue = |
| 1993 style->getPropertyCSSValue(CSSPropertyBackgroundColor); | 2001 style->getPropertyCSSValue(CSSPropertyBackgroundColor); |
| 1994 return isTransparentColorValue(cssValue); | 2002 return isTransparentColorValue(cssValue); |
| 1995 } | 2003 } |
| 1996 | 2004 |
| 1997 const CSSValue* backgroundColorValueInEffect(Node* node) { | 2005 const CSSValue* backgroundColorValueInEffect(Node* node) { |
| 1998 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { | 2006 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { |
| 1999 CSSComputedStyleDeclaration* ancestorStyle = | 2007 CSSComputedStyleDeclaration* ancestorStyle = |
| 2000 CSSComputedStyleDeclaration::create(ancestor); | 2008 CSSComputedStyleDeclaration::create(ancestor); |
| 2001 if (!hasTransparentBackgroundColor(ancestorStyle)) | 2009 if (!hasTransparentBackgroundColor(ancestorStyle)) |
| 2002 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor); | 2010 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor); |
| 2003 } | 2011 } |
| 2004 return nullptr; | 2012 return nullptr; |
| 2005 } | 2013 } |
| 2006 | 2014 |
| 2007 } // namespace blink | 2015 } // namespace blink |
| OLD | NEW |