| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 static const Vector<CSSPropertyID>& inheritableEditingProperties() | 102 static const Vector<CSSPropertyID>& inheritableEditingProperties() |
| 103 { | 103 { |
| 104 DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ()); | 104 DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ()); |
| 105 if (properties.isEmpty()) | 105 if (properties.isEmpty()) |
| 106 RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(staticEditingPro
perties + nonInheritedStaticPropertiesCount, WTF_ARRAY_LENGTH(staticEditingPrope
rties) - nonInheritedStaticPropertiesCount, properties); | 106 RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(staticEditingPro
perties + nonInheritedStaticPropertiesCount, WTF_ARRAY_LENGTH(staticEditingPrope
rties) - nonInheritedStaticPropertiesCount, properties); |
| 107 return properties; | 107 return properties; |
| 108 } | 108 } |
| 109 | 109 |
| 110 template <class StyleDeclarationType> | 110 template <class StyleDeclarationType> |
| 111 static PassRefPtr<StylePropertySet> copyEditingProperties(StyleDeclarationType*
style, EditingPropertiesType type = OnlyInheritableEditingProperties) | 111 static PassRefPtr<MutableStylePropertySet> copyEditingProperties(StyleDeclaratio
nType* style, EditingPropertiesType type = OnlyInheritableEditingProperties) |
| 112 { | 112 { |
| 113 if (type == AllEditingProperties) | 113 if (type == AllEditingProperties) |
| 114 return style->copyPropertiesInSet(allEditingProperties()); | 114 return style->copyPropertiesInSet(allEditingProperties()); |
| 115 return style->copyPropertiesInSet(inheritableEditingProperties()); | 115 return style->copyPropertiesInSet(inheritableEditingProperties()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 static inline bool isEditingProperty(int id) | 118 static inline bool isEditingProperty(int id) |
| 119 { | 119 { |
| 120 return allEditingProperties().contains(static_cast<CSSPropertyID>(id)); | 120 return allEditingProperties().contains(static_cast<CSSPropertyID>(id)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static PassRefPtr<StylePropertySet> editingStyleFromComputedStyle(PassRefPtr<CSS
ComputedStyleDeclaration> style, EditingPropertiesType type = OnlyInheritableEdi
tingProperties) | 123 static PassRefPtr<MutableStylePropertySet> editingStyleFromComputedStyle(PassRef
Ptr<CSSComputedStyleDeclaration> style, EditingPropertiesType type = OnlyInherit
ableEditingProperties) |
| 124 { | 124 { |
| 125 if (!style) | 125 if (!style) |
| 126 return StylePropertySet::create(); | 126 return static_pointer_cast<MutableStylePropertySet>(StylePropertySet::cr
eate()); |
| 127 return copyEditingProperties(style.get(), type); | 127 return copyEditingProperties(style.get(), type); |
| 128 } | 128 } |
| 129 | 129 |
| 130 static PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWi
thRedundantProperties, CSSStyleDeclaration* baseStyle); | 130 static PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWi
thRedundantProperties, CSSStyleDeclaration* baseStyle); |
| 131 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV
aluesMatch }; | 131 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV
aluesMatch }; |
| 132 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool should
UseFixedFontDefaultSize, LegacyFontSizeMode); | 132 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool should
UseFixedFontDefaultSize, LegacyFontSizeMode); |
| 133 static bool isTransparentColorValue(CSSValue*); | 133 static bool isTransparentColorValue(CSSValue*); |
| 134 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); | 134 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); |
| 135 static bool hasTransparentBackgroundColor(StylePropertySet*); | 135 static bool hasTransparentBackgroundColor(StylePropertySet*); |
| 136 static PassRefPtr<CSSValue> backgroundColorInEffect(Node*); | 136 static PassRefPtr<CSSValue> backgroundColorInEffect(Node*); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 328 } |
| 329 | 329 |
| 330 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert
iesToInclude) | 330 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert
iesToInclude) |
| 331 : m_shouldUseFixedDefaultFontSize(false) | 331 : m_shouldUseFixedDefaultFontSize(false) |
| 332 , m_fontSizeDelta(NoFontDelta) | 332 , m_fontSizeDelta(NoFontDelta) |
| 333 { | 333 { |
| 334 init(position.deprecatedNode(), propertiesToInclude); | 334 init(position.deprecatedNode(), propertiesToInclude); |
| 335 } | 335 } |
| 336 | 336 |
| 337 EditingStyle::EditingStyle(const StylePropertySet* style) | 337 EditingStyle::EditingStyle(const StylePropertySet* style) |
| 338 : m_mutableStyle(style ? style->copy() : 0) | 338 : m_mutableStyle(style ? style->mutableCopy() : 0) |
| 339 , m_shouldUseFixedDefaultFontSize(false) | 339 , m_shouldUseFixedDefaultFontSize(false) |
| 340 , m_fontSizeDelta(NoFontDelta) | 340 , m_fontSizeDelta(NoFontDelta) |
| 341 { | 341 { |
| 342 extractFontSizeDelta(); | 342 extractFontSizeDelta(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 EditingStyle::EditingStyle(const CSSStyleDeclaration* style) | 345 EditingStyle::EditingStyle(const CSSStyleDeclaration* style) |
| 346 : m_mutableStyle(style ? style->copy() : 0) | 346 : m_mutableStyle(style ? style->copyProperties() : 0) |
| 347 , m_shouldUseFixedDefaultFontSize(false) | 347 , m_shouldUseFixedDefaultFontSize(false) |
| 348 , m_fontSizeDelta(NoFontDelta) | 348 , m_fontSizeDelta(NoFontDelta) |
| 349 { | 349 { |
| 350 extractFontSizeDelta(); | 350 extractFontSizeDelta(); |
| 351 } | 351 } |
| 352 | 352 |
| 353 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) | 353 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) |
| 354 : m_mutableStyle(0) | 354 : m_mutableStyle(0) |
| 355 , m_shouldUseFixedDefaultFontSize(false) | 355 , m_shouldUseFixedDefaultFontSize(false) |
| 356 , m_fontSizeDelta(NoFontDelta) | 356 , m_fontSizeDelta(NoFontDelta) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 430 } |
| 431 | 431 |
| 432 void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude) | 432 void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude) |
| 433 { | 433 { |
| 434 if (isTabSpanTextNode(node)) | 434 if (isTabSpanTextNode(node)) |
| 435 node = tabSpanNode(node)->parentNode(); | 435 node = tabSpanNode(node)->parentNode(); |
| 436 else if (isTabSpanNode(node)) | 436 else if (isTabSpanNode(node)) |
| 437 node = node->parentNode(); | 437 node = node->parentNode(); |
| 438 | 438 |
| 439 RefPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = CSSComputedSty
leDeclaration::create(node); | 439 RefPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = CSSComputedSty
leDeclaration::create(node); |
| 440 m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosi
tion ? computedStyleAtPosition->copy() : editingStyleFromComputedStyle(computedS
tyleAtPosition); | 440 m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosi
tion ? computedStyleAtPosition->copyProperties() : editingStyleFromComputedStyle
(computedStyleAtPosition); |
| 441 | 441 |
| 442 if (propertiesToInclude == EditingPropertiesInEffect) { | 442 if (propertiesToInclude == EditingPropertiesInEffect) { |
| 443 if (RefPtr<CSSValue> value = backgroundColorInEffect(node)) | 443 if (RefPtr<CSSValue> value = backgroundColorInEffect(node)) |
| 444 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssTe
xt()); | 444 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssTe
xt()); |
| 445 if (RefPtr<CSSValue> value = computedStyleAtPosition->getPropertyCSSValu
e(CSSPropertyWebkitTextDecorationsInEffect)) | 445 if (RefPtr<CSSValue> value = computedStyleAtPosition->getPropertyCSSValu
e(CSSPropertyWebkitTextDecorationsInEffect)) |
| 446 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssTex
t()); | 446 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssTex
t()); |
| 447 } | 447 } |
| 448 | 448 |
| 449 if (node && node->computedStyle()) { | 449 if (node && node->computedStyle()) { |
| 450 RenderStyle* renderStyle = node->computedStyle(); | 450 RenderStyle* renderStyle = node->computedStyle(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 { | 565 { |
| 566 m_mutableStyle.clear(); | 566 m_mutableStyle.clear(); |
| 567 m_shouldUseFixedDefaultFontSize = false; | 567 m_shouldUseFixedDefaultFontSize = false; |
| 568 m_fontSizeDelta = NoFontDelta; | 568 m_fontSizeDelta = NoFontDelta; |
| 569 } | 569 } |
| 570 | 570 |
| 571 PassRefPtr<EditingStyle> EditingStyle::copy() const | 571 PassRefPtr<EditingStyle> EditingStyle::copy() const |
| 572 { | 572 { |
| 573 RefPtr<EditingStyle> copy = EditingStyle::create(); | 573 RefPtr<EditingStyle> copy = EditingStyle::create(); |
| 574 if (m_mutableStyle) | 574 if (m_mutableStyle) |
| 575 copy->m_mutableStyle = m_mutableStyle->copy(); | 575 copy->m_mutableStyle = m_mutableStyle->mutableCopy(); |
| 576 copy->m_shouldUseFixedDefaultFontSize = m_shouldUseFixedDefaultFontSize; | 576 copy->m_shouldUseFixedDefaultFontSize = m_shouldUseFixedDefaultFontSize; |
| 577 copy->m_fontSizeDelta = m_fontSizeDelta; | 577 copy->m_fontSizeDelta = m_fontSizeDelta; |
| 578 return copy; | 578 return copy; |
| 579 } | 579 } |
| 580 | 580 |
| 581 PassRefPtr<EditingStyle> EditingStyle::extractAndRemoveBlockProperties() | 581 PassRefPtr<EditingStyle> EditingStyle::extractAndRemoveBlockProperties() |
| 582 { | 582 { |
| 583 RefPtr<EditingStyle> blockProperties = EditingStyle::create(); | 583 RefPtr<EditingStyle> blockProperties = EditingStyle::create(); |
| 584 if (!m_mutableStyle) | 584 if (!m_mutableStyle) |
| 585 return blockProperties; | 585 return blockProperties; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 if (valueToMerge->hasValue(lineThrough.get()) && !mergedValue->hasValue(line
Through.get())) | 1062 if (valueToMerge->hasValue(lineThrough.get()) && !mergedValue->hasValue(line
Through.get())) |
| 1063 mergedValue->append(lineThrough.get()); | 1063 mergedValue->append(lineThrough.get()); |
| 1064 } | 1064 } |
| 1065 | 1065 |
| 1066 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride
Mode mode) | 1066 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride
Mode mode) |
| 1067 { | 1067 { |
| 1068 if (!style) | 1068 if (!style) |
| 1069 return; | 1069 return; |
| 1070 | 1070 |
| 1071 if (!m_mutableStyle) { | 1071 if (!m_mutableStyle) { |
| 1072 m_mutableStyle = style->copy(); | 1072 m_mutableStyle = style->mutableCopy(); |
| 1073 return; | 1073 return; |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 unsigned propertyCount = style->propertyCount(); | 1076 unsigned propertyCount = style->propertyCount(); |
| 1077 for (unsigned i = 0; i < propertyCount; ++i) { | 1077 for (unsigned i = 0; i < propertyCount; ++i) { |
| 1078 StylePropertySet::PropertyReference property = style->propertyAt(i); | 1078 StylePropertySet::PropertyReference property = style->propertyAt(i); |
| 1079 RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(property.id
()); | 1079 RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(property.id
()); |
| 1080 | 1080 |
| 1081 // text decorations never override values | 1081 // text decorations never override values |
| 1082 if ((property.id() == CSSPropertyTextDecoration || property.id() == CSSP
ropertyWebkitTextDecorationsInEffect) && property.value()->isValueList() && valu
e) { | 1082 if ((property.id() == CSSPropertyTextDecoration || property.id() == CSSP
ropertyWebkitTextDecorationsInEffect) && property.value()->isValueList() && valu
e) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 { | 1512 { |
| 1513 ASSERT(style); | 1513 ASSERT(style); |
| 1514 RefPtr<CSSValue> fontWeight = style->getPropertyCSSValue(CSSPropertyFontWeig
ht); | 1514 RefPtr<CSSValue> fontWeight = style->getPropertyCSSValue(CSSPropertyFontWeig
ht); |
| 1515 return fontWeightIsBold(fontWeight.get()); | 1515 return fontWeightIsBold(fontWeight.get()); |
| 1516 } | 1516 } |
| 1517 | 1517 |
| 1518 PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWithRedun
dantProperties, CSSStyleDeclaration* baseStyle) | 1518 PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWithRedun
dantProperties, CSSStyleDeclaration* baseStyle) |
| 1519 { | 1519 { |
| 1520 ASSERT(styleWithRedundantProperties); | 1520 ASSERT(styleWithRedundantProperties); |
| 1521 ASSERT(baseStyle); | 1521 ASSERT(baseStyle); |
| 1522 RefPtr<StylePropertySet> result = styleWithRedundantProperties->copy(); | 1522 RefPtr<MutableStylePropertySet> result = styleWithRedundantProperties->mutab
leCopy(); |
| 1523 | 1523 |
| 1524 result->removeEquivalentProperties(baseStyle); | 1524 result->removeEquivalentProperties(baseStyle); |
| 1525 | 1525 |
| 1526 RefPtr<CSSValue> baseTextDecorationsInEffect = baseStyle->getPropertyCSSValu
eInternal(CSSPropertyWebkitTextDecorationsInEffect); | 1526 RefPtr<CSSValue> baseTextDecorationsInEffect = baseStyle->getPropertyCSSValu
eInternal(CSSPropertyWebkitTextDecorationsInEffect); |
| 1527 diffTextDecorations(result.get(), CSSPropertyTextDecoration, baseTextDecorat
ionsInEffect.get()); | 1527 diffTextDecorations(result.get(), CSSPropertyTextDecoration, baseTextDecorat
ionsInEffect.get()); |
| 1528 diffTextDecorations(result.get(), CSSPropertyWebkitTextDecorationsInEffect,
baseTextDecorationsInEffect.get()); | 1528 diffTextDecorations(result.get(), CSSPropertyWebkitTextDecorationsInEffect,
baseTextDecorationsInEffect.get()); |
| 1529 | 1529 |
| 1530 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyFontWeight) && fontWei
ghtIsBold(result.get()) == fontWeightIsBold(baseStyle)) | 1530 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyFontWeight) && fontWei
ghtIsBold(result.get()) == fontWeightIsBold(baseStyle)) |
| 1531 result->removeProperty(CSSPropertyFontWeight); | 1531 result->removeProperty(CSSPropertyFontWeight); |
| 1532 | 1532 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 { | 1615 { |
| 1616 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { | 1616 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { |
| 1617 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl
aration::create(ancestor); | 1617 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl
aration::create(ancestor); |
| 1618 if (!hasTransparentBackgroundColor(ancestorStyle.get())) | 1618 if (!hasTransparentBackgroundColor(ancestorStyle.get())) |
| 1619 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor
); | 1619 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor
); |
| 1620 } | 1620 } |
| 1621 return 0; | 1621 return 0; |
| 1622 } | 1622 } |
| 1623 | 1623 |
| 1624 } | 1624 } |
| OLD | NEW |