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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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<MutableStylePropertySet> editingStyleFromComputedStyle(PassRef
Ptr<CSSComputedStyleDeclaration> style, EditingPropertiesType type = OnlyInherit
ableEditingProperties) | 123 static PassRefPtr<MutableStylePropertySet> editingStyleFromComputedStyle(PassRef
Ptr<CSSComputedStyleDeclaration> style, EditingPropertiesType type = OnlyInherit
ableEditingProperties) |
124 { | 124 { |
125 if (!style) | 125 if (!style) |
126 return static_pointer_cast<MutableStylePropertySet>(StylePropertySet::cr
eate()); | 126 return MutableStylePropertySet::create(); |
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (RefPtr<CSSValue> value = attributeValueAsCSSValue(element)) | 271 if (RefPtr<CSSValue> value = attributeValueAsCSSValue(element)) |
272 style->setProperty(m_propertyID, value->cssText()); | 272 style->setProperty(m_propertyID, value->cssText()); |
273 } | 273 } |
274 | 274 |
275 PassRefPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSValue(Element*
element) const | 275 PassRefPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSValue(Element*
element) const |
276 { | 276 { |
277 ASSERT(element); | 277 ASSERT(element); |
278 if (!element->hasAttribute(m_attrName)) | 278 if (!element->hasAttribute(m_attrName)) |
279 return 0; | 279 return 0; |
280 | 280 |
281 RefPtr<StylePropertySet> dummyStyle; | 281 RefPtr<MutableStylePropertySet> dummyStyle; |
282 dummyStyle = StylePropertySet::create(); | 282 dummyStyle = MutableStylePropertySet::create(); |
283 dummyStyle->setProperty(m_propertyID, element->getAttribute(m_attrName)); | 283 dummyStyle->setProperty(m_propertyID, element->getAttribute(m_attrName)); |
284 return dummyStyle->getPropertyCSSValue(m_propertyID); | 284 return dummyStyle->getPropertyCSSValue(m_propertyID); |
285 } | 285 } |
286 | 286 |
287 class HTMLFontSizeEquivalent : public HTMLAttributeEquivalent { | 287 class HTMLFontSizeEquivalent : public HTMLAttributeEquivalent { |
288 public: | 288 public: |
289 static PassOwnPtr<HTMLFontSizeEquivalent> create() | 289 static PassOwnPtr<HTMLFontSizeEquivalent> create() |
290 { | 290 { |
291 return adoptPtr(new HTMLFontSizeEquivalent()); | 291 return adoptPtr(new HTMLFontSizeEquivalent()); |
292 } | 292 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // inherit it). Likewise for stroke color. | 463 // inherit it). Likewise for stroke color. |
464 if (!renderStyle->textFillColor().isValid()) | 464 if (!renderStyle->textFillColor().isValid()) |
465 m_mutableStyle->removeProperty(CSSPropertyWebkitTextFillColor); | 465 m_mutableStyle->removeProperty(CSSPropertyWebkitTextFillColor); |
466 if (!renderStyle->textStrokeColor().isValid()) | 466 if (!renderStyle->textStrokeColor().isValid()) |
467 m_mutableStyle->removeProperty(CSSPropertyWebkitTextStrokeColor); | 467 m_mutableStyle->removeProperty(CSSPropertyWebkitTextStrokeColor); |
468 } | 468 } |
469 | 469 |
470 void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, bo
ol important) | 470 void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, bo
ol important) |
471 { | 471 { |
472 if (!m_mutableStyle) | 472 if (!m_mutableStyle) |
473 m_mutableStyle = StylePropertySet::create(); | 473 m_mutableStyle = MutableStylePropertySet::create(); |
474 | 474 |
475 m_mutableStyle->setProperty(propertyID, value, important); | 475 m_mutableStyle->setProperty(propertyID, value, important); |
476 } | 476 } |
477 | 477 |
478 void EditingStyle::replaceFontSizeByKeywordIfPossible(RenderStyle* renderStyle,
CSSComputedStyleDeclaration* computedStyle) | 478 void EditingStyle::replaceFontSizeByKeywordIfPossible(RenderStyle* renderStyle,
CSSComputedStyleDeclaration* computedStyle) |
479 { | 479 { |
480 ASSERT(renderStyle); | 480 ASSERT(renderStyle); |
481 if (renderStyle->fontDescription().keywordSize()) | 481 if (renderStyle->fontDescription().keywordSize()) |
482 m_mutableStyle->setProperty(CSSPropertyFontSize, computedStyle->getFontS
izeCSSValuePreferringKeyword()->cssText()); | 482 m_mutableStyle->setProperty(CSSPropertyFontSize, computedStyle->getFontS
izeCSSValuePreferringKeyword()->cssText()); |
483 } | 483 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 // We need to check font-family is monospace as in FontDescription but we do
n't want to duplicate code here. | 549 // We need to check font-family is monospace as in FontDescription but we do
n't want to duplicate code here. |
550 m_shouldUseFixedDefaultFontSize = false; | 550 m_shouldUseFixedDefaultFontSize = false; |
551 extractFontSizeDelta(); | 551 extractFontSizeDelta(); |
552 } | 552 } |
553 | 553 |
554 void EditingStyle::overrideWithStyle(const StylePropertySet* style) | 554 void EditingStyle::overrideWithStyle(const StylePropertySet* style) |
555 { | 555 { |
556 if (!style || style->isEmpty()) | 556 if (!style || style->isEmpty()) |
557 return; | 557 return; |
558 if (!m_mutableStyle) | 558 if (!m_mutableStyle) |
559 m_mutableStyle = StylePropertySet::create(); | 559 m_mutableStyle = MutableStylePropertySet::create(); |
560 m_mutableStyle->mergeAndOverrideOnConflict(style); | 560 m_mutableStyle->mergeAndOverrideOnConflict(style); |
561 extractFontSizeDelta(); | 561 extractFontSizeDelta(); |
562 } | 562 } |
563 | 563 |
564 void EditingStyle::clear() | 564 void EditingStyle::clear() |
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 } |
(...skipping 16 matching lines...) Expand all Loading... |
586 | 586 |
587 blockProperties->m_mutableStyle = m_mutableStyle->copyBlockProperties(); | 587 blockProperties->m_mutableStyle = m_mutableStyle->copyBlockProperties(); |
588 m_mutableStyle->removeBlockProperties(); | 588 m_mutableStyle->removeBlockProperties(); |
589 | 589 |
590 return blockProperties; | 590 return blockProperties; |
591 } | 591 } |
592 | 592 |
593 PassRefPtr<EditingStyle> EditingStyle::extractAndRemoveTextDirection() | 593 PassRefPtr<EditingStyle> EditingStyle::extractAndRemoveTextDirection() |
594 { | 594 { |
595 RefPtr<EditingStyle> textDirection = EditingStyle::create(); | 595 RefPtr<EditingStyle> textDirection = EditingStyle::create(); |
596 textDirection->m_mutableStyle = StylePropertySet::create(); | 596 textDirection->m_mutableStyle = MutableStylePropertySet::create(); |
597 textDirection->m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueE
mbed, m_mutableStyle->propertyIsImportant(CSSPropertyUnicodeBidi)); | 597 textDirection->m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueE
mbed, m_mutableStyle->propertyIsImportant(CSSPropertyUnicodeBidi)); |
598 textDirection->m_mutableStyle->setProperty(CSSPropertyDirection, m_mutableSt
yle->getPropertyValue(CSSPropertyDirection), | 598 textDirection->m_mutableStyle->setProperty(CSSPropertyDirection, m_mutableSt
yle->getPropertyValue(CSSPropertyDirection), |
599 m_mutableStyle->propertyIsImportant(CSSPropertyDirection)); | 599 m_mutableStyle->propertyIsImportant(CSSPropertyDirection)); |
600 | 600 |
601 m_mutableStyle->removeProperty(CSSPropertyUnicodeBidi); | 601 m_mutableStyle->removeProperty(CSSPropertyUnicodeBidi); |
602 m_mutableStyle->removeProperty(CSSPropertyDirection); | 602 m_mutableStyle->removeProperty(CSSPropertyDirection); |
603 | 603 |
604 return textDirection; | 604 return textDirection; |
605 } | 605 } |
606 | 606 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 value = 0; // text-decoration: none is equivalent to not having the
property | 1087 value = 0; // text-decoration: none is equivalent to not having the
property |
1088 } | 1088 } |
1089 | 1089 |
1090 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value)) | 1090 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value)) |
1091 m_mutableStyle->setProperty(property.id(), property.value()->cssText
(), property.isImportant()); | 1091 m_mutableStyle->setProperty(property.id(), property.value()->cssText
(), property.isImportant()); |
1092 } | 1092 } |
1093 } | 1093 } |
1094 | 1094 |
1095 static PassRefPtr<StylePropertySet> styleFromMatchedRulesForElement(Element* ele
ment, unsigned rulesToInclude) | 1095 static PassRefPtr<StylePropertySet> styleFromMatchedRulesForElement(Element* ele
ment, unsigned rulesToInclude) |
1096 { | 1096 { |
1097 RefPtr<StylePropertySet> style = StylePropertySet::create(); | 1097 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create(); |
1098 RefPtr<CSSRuleList> matchedRules = element->document()->styleResolver()->sty
leRulesForElement(element, rulesToInclude); | 1098 RefPtr<CSSRuleList> matchedRules = element->document()->styleResolver()->sty
leRulesForElement(element, rulesToInclude); |
1099 if (matchedRules) { | 1099 if (matchedRules) { |
1100 for (unsigned i = 0; i < matchedRules->length(); i++) { | 1100 for (unsigned i = 0; i < matchedRules->length(); i++) { |
1101 if (matchedRules->item(i)->type() == CSSRule::STYLE_RULE) | 1101 if (matchedRules->item(i)->type() == CSSRule::STYLE_RULE) |
1102 style->mergeAndOverrideOnConflict(static_cast<CSSStyleRule*>(mat
chedRules->item(i))->styleRule()->properties()); | 1102 style->mergeAndOverrideOnConflict(static_cast<CSSStyleRule*>(mat
chedRules->item(i))->styleRule()->properties()); |
1103 } | 1103 } |
1104 } | 1104 } |
1105 | 1105 |
1106 return style.release(); | 1106 return style.release(); |
1107 } | 1107 } |
(...skipping 12 matching lines...) Expand all Loading... |
1120 } | 1120 } |
1121 | 1121 |
1122 void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement* element) | 1122 void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement* element) |
1123 { | 1123 { |
1124 mergeStyleFromRules(element); | 1124 mergeStyleFromRules(element); |
1125 | 1125 |
1126 // The property value, if it's a percentage, may not reflect the actual comp
uted value. | 1126 // The property value, if it's a percentage, may not reflect the actual comp
uted value. |
1127 // For example: style="height: 1%; overflow: visible;" in quirksmode | 1127 // For example: style="height: 1%; overflow: visible;" in quirksmode |
1128 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot
copy/paste fidelity problem | 1128 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot
copy/paste fidelity problem |
1129 RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = CSSComputedSty
leDeclaration::create(element); | 1129 RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = CSSComputedSty
leDeclaration::create(element); |
1130 RefPtr<StylePropertySet> fromComputedStyle = StylePropertySet::create(); | 1130 RefPtr<MutableStylePropertySet> fromComputedStyle = MutableStylePropertySet:
:create(); |
1131 { | 1131 { |
1132 unsigned propertyCount = m_mutableStyle->propertyCount(); | 1132 unsigned propertyCount = m_mutableStyle->propertyCount(); |
1133 for (unsigned i = 0; i < propertyCount; ++i) { | 1133 for (unsigned i = 0; i < propertyCount; ++i) { |
1134 StylePropertySet::PropertyReference property = m_mutableStyle->prope
rtyAt(i); | 1134 StylePropertySet::PropertyReference property = m_mutableStyle->prope
rtyAt(i); |
1135 CSSValue* value = property.value(); | 1135 CSSValue* value = property.value(); |
1136 if (!value->isPrimitiveValue()) | 1136 if (!value->isPrimitiveValue()) |
1137 continue; | 1137 continue; |
1138 if (static_cast<CSSPrimitiveValue*>(value)->isPercentage()) { | 1138 if (static_cast<CSSPrimitiveValue*>(value)->isPercentage()) { |
1139 if (RefPtr<CSSValue> computedPropertyValue = computedStyleForEle
ment->getPropertyCSSValue(property.id())) | 1139 if (RefPtr<CSSValue> computedPropertyValue = computedStyleForEle
ment->getPropertyCSSValue(property.id())) |
1140 fromComputedStyle->addParsedProperty(CSSProperty(property.id
(), computedPropertyValue)); | 1140 fromComputedStyle->addParsedProperty(CSSProperty(property.id
(), computedPropertyValue)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 return; | 1191 return; |
1192 | 1192 |
1193 RefPtr<StylePropertySet> defaultStyle = styleFromMatchedRulesForElement(elem
ent, StyleResolver::UAAndUserCSSRules); | 1193 RefPtr<StylePropertySet> defaultStyle = styleFromMatchedRulesForElement(elem
ent, StyleResolver::UAAndUserCSSRules); |
1194 | 1194 |
1195 removePropertiesInStyle(m_mutableStyle.get(), defaultStyle.get()); | 1195 removePropertiesInStyle(m_mutableStyle.get(), defaultStyle.get()); |
1196 } | 1196 } |
1197 | 1197 |
1198 void EditingStyle::forceInline() | 1198 void EditingStyle::forceInline() |
1199 { | 1199 { |
1200 if (!m_mutableStyle) | 1200 if (!m_mutableStyle) |
1201 m_mutableStyle = StylePropertySet::create(); | 1201 m_mutableStyle = MutableStylePropertySet::create(); |
1202 const bool propertyIsImportant = true; | 1202 const bool propertyIsImportant = true; |
1203 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm
portant); | 1203 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm
portant); |
1204 } | 1204 } |
1205 | 1205 |
1206 int EditingStyle::legacyFontSize(Document* document) const | 1206 int EditingStyle::legacyFontSize(Document* document) const |
1207 { | 1207 { |
1208 RefPtr<CSSValue> cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyF
ontSize); | 1208 RefPtr<CSSValue> cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyF
ontSize); |
1209 if (!cssValue || !cssValue->isPrimitiveValue()) | 1209 if (!cssValue || !cssValue->isPrimitiveValue()) |
1210 return 0; | 1210 return 0; |
1211 return legacyFontSizeFromCSSValue(document, static_cast<CSSPrimitiveValue*>(
cssValue.get()), | 1211 return legacyFontSizeFromCSSValue(document, static_cast<CSSPrimitiveValue*>(
cssValue.get()), |
(...skipping 403 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 |