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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 135 } |
136 | 136 |
137 static inline bool isEditingProperty(int id) | 137 static inline bool isEditingProperty(int id) |
138 { | 138 { |
139 return allEditingProperties().contains(static_cast<CSSPropertyID>(id)); | 139 return allEditingProperties().contains(static_cast<CSSPropertyID>(id)); |
140 } | 140 } |
141 | 141 |
142 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS
tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie
sType type = OnlyInheritableEditingProperties) | 142 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS
tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie
sType type = OnlyInheritableEditingProperties) |
143 { | 143 { |
144 if (!style) | 144 if (!style) |
145 return MutableStylePropertySet::create(); | 145 return MutableStylePropertySet::create(HTMLQuirksMode); |
146 return copyEditingProperties(style.get(), type); | 146 return copyEditingProperties(style.get(), type); |
147 } | 147 } |
148 | 148 |
149 static PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ensureComputedStyle(c
onst Position& position) | 149 static PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ensureComputedStyle(c
onst Position& position) |
150 { | 150 { |
151 Element* elem = associatedElementOf(position); | 151 Element* elem = associatedElementOf(position); |
152 if (!elem) | 152 if (!elem) |
153 return nullptr; | 153 return nullptr; |
154 return CSSComputedStyleDeclaration::create(elem); | 154 return CSSComputedStyleDeclaration::create(elem); |
155 } | 155 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 | 310 |
311 PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSVal
ue(Element* element) const | 311 PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSVal
ue(Element* element) const |
312 { | 312 { |
313 ASSERT(element); | 313 ASSERT(element); |
314 const AtomicString& value = element->getAttribute(m_attrName); | 314 const AtomicString& value = element->getAttribute(m_attrName); |
315 if (value.isNull()) | 315 if (value.isNull()) |
316 return nullptr; | 316 return nullptr; |
317 | 317 |
318 RefPtrWillBeRawPtr<MutableStylePropertySet> dummyStyle = nullptr; | 318 RefPtrWillBeRawPtr<MutableStylePropertySet> dummyStyle = nullptr; |
319 dummyStyle = MutableStylePropertySet::create(); | 319 dummyStyle = MutableStylePropertySet::create(HTMLQuirksMode); |
320 dummyStyle->setProperty(m_propertyID, value); | 320 dummyStyle->setProperty(m_propertyID, value); |
321 return dummyStyle->getPropertyCSSValue(m_propertyID); | 321 return dummyStyle->getPropertyCSSValue(m_propertyID); |
322 } | 322 } |
323 | 323 |
324 class HTMLFontSizeEquivalent final : public HTMLAttributeEquivalent { | 324 class HTMLFontSizeEquivalent final : public HTMLAttributeEquivalent { |
325 public: | 325 public: |
326 static PassOwnPtrWillBeRawPtr<HTMLFontSizeEquivalent> create() | 326 static PassOwnPtrWillBeRawPtr<HTMLFontSizeEquivalent> create() |
327 { | 327 { |
328 return adoptPtrWillBeNoop(new HTMLFontSizeEquivalent()); | 328 return adoptPtrWillBeNoop(new HTMLFontSizeEquivalent()); |
329 } | 329 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 // inherit it). Likewise for stroke color. | 496 // inherit it). Likewise for stroke color. |
497 if (computedStyle->textFillColor().isCurrentColor()) | 497 if (computedStyle->textFillColor().isCurrentColor()) |
498 m_mutableStyle->removeProperty(CSSPropertyWebkitTextFillColor); | 498 m_mutableStyle->removeProperty(CSSPropertyWebkitTextFillColor); |
499 if (computedStyle->textStrokeColor().isCurrentColor()) | 499 if (computedStyle->textStrokeColor().isCurrentColor()) |
500 m_mutableStyle->removeProperty(CSSPropertyWebkitTextStrokeColor); | 500 m_mutableStyle->removeProperty(CSSPropertyWebkitTextStrokeColor); |
501 } | 501 } |
502 | 502 |
503 void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, bo
ol important) | 503 void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, bo
ol important) |
504 { | 504 { |
505 if (!m_mutableStyle) | 505 if (!m_mutableStyle) |
506 m_mutableStyle = MutableStylePropertySet::create(); | 506 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); |
507 | 507 |
508 m_mutableStyle->setProperty(propertyID, value, important); | 508 m_mutableStyle->setProperty(propertyID, value, important); |
509 } | 509 } |
510 | 510 |
511 void EditingStyle::replaceFontSizeByKeywordIfPossible(const ComputedStyle* compu
tedStyle, CSSComputedStyleDeclaration* cssComputedStyle) | 511 void EditingStyle::replaceFontSizeByKeywordIfPossible(const ComputedStyle* compu
tedStyle, CSSComputedStyleDeclaration* cssComputedStyle) |
512 { | 512 { |
513 ASSERT(computedStyle); | 513 ASSERT(computedStyle); |
514 if (computedStyle->fontDescription().keywordSize()) | 514 if (computedStyle->fontDescription().keywordSize()) |
515 m_mutableStyle->setProperty(CSSPropertyFontSize, cssComputedStyle->getFo
ntSizeCSSValuePreferringKeyword()->cssText()); | 515 m_mutableStyle->setProperty(CSSPropertyFontSize, cssComputedStyle->getFo
ntSizeCSSValuePreferringKeyword()->cssText()); |
516 } | 516 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 } | 573 } |
574 | 574 |
575 return false; | 575 return false; |
576 } | 576 } |
577 | 577 |
578 void EditingStyle::overrideWithStyle(const StylePropertySet* style) | 578 void EditingStyle::overrideWithStyle(const StylePropertySet* style) |
579 { | 579 { |
580 if (!style || style->isEmpty()) | 580 if (!style || style->isEmpty()) |
581 return; | 581 return; |
582 if (!m_mutableStyle) | 582 if (!m_mutableStyle) |
583 m_mutableStyle = MutableStylePropertySet::create(); | 583 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); |
584 m_mutableStyle->mergeAndOverrideOnConflict(style); | 584 m_mutableStyle->mergeAndOverrideOnConflict(style); |
585 extractFontSizeDelta(); | 585 extractFontSizeDelta(); |
586 } | 586 } |
587 | 587 |
588 void EditingStyle::clear() | 588 void EditingStyle::clear() |
589 { | 589 { |
590 m_mutableStyle.clear(); | 590 m_mutableStyle.clear(); |
591 m_isMonospaceFont = false; | 591 m_isMonospaceFont = false; |
592 m_fontSizeDelta = NoFontDelta; | 592 m_fontSizeDelta = NoFontDelta; |
593 } | 593 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 641 |
642 blockProperties->m_mutableStyle = m_mutableStyle->copyPropertiesInSet(blockP
ropertiesVector()); | 642 blockProperties->m_mutableStyle = m_mutableStyle->copyPropertiesInSet(blockP
ropertiesVector()); |
643 removeBlockProperties(); | 643 removeBlockProperties(); |
644 | 644 |
645 return blockProperties; | 645 return blockProperties; |
646 } | 646 } |
647 | 647 |
648 PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::extractAndRemoveTextDirection
() | 648 PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::extractAndRemoveTextDirection
() |
649 { | 649 { |
650 RefPtrWillBeRawPtr<EditingStyle> textDirection = EditingStyle::create(); | 650 RefPtrWillBeRawPtr<EditingStyle> textDirection = EditingStyle::create(); |
651 textDirection->m_mutableStyle = MutableStylePropertySet::create(); | 651 textDirection->m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMo
de); |
652 textDirection->m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueE
mbed, m_mutableStyle->propertyIsImportant(CSSPropertyUnicodeBidi)); | 652 textDirection->m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueE
mbed, m_mutableStyle->propertyIsImportant(CSSPropertyUnicodeBidi)); |
653 textDirection->m_mutableStyle->setProperty(CSSPropertyDirection, m_mutableSt
yle->getPropertyValue(CSSPropertyDirection), | 653 textDirection->m_mutableStyle->setProperty(CSSPropertyDirection, m_mutableSt
yle->getPropertyValue(CSSPropertyDirection), |
654 m_mutableStyle->propertyIsImportant(CSSPropertyDirection)); | 654 m_mutableStyle->propertyIsImportant(CSSPropertyDirection)); |
655 | 655 |
656 m_mutableStyle->removeProperty(CSSPropertyUnicodeBidi); | 656 m_mutableStyle->removeProperty(CSSPropertyUnicodeBidi); |
657 m_mutableStyle->removeProperty(CSSPropertyDirection); | 657 m_mutableStyle->removeProperty(CSSPropertyDirection); |
658 | 658 |
659 return textDirection; | 659 return textDirection; |
660 } | 660 } |
661 | 661 |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 value = nullptr; // text-decoration: none is equivalent to not havin
g the property | 1165 value = nullptr; // text-decoration: none is equivalent to not havin
g the property |
1166 } | 1166 } |
1167 | 1167 |
1168 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value)) | 1168 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value)) |
1169 m_mutableStyle->setProperty(property.id(), property.value()->cssText
(), property.isImportant()); | 1169 m_mutableStyle->setProperty(property.id(), property.value()->cssText
(), property.isImportant()); |
1170 } | 1170 } |
1171 } | 1171 } |
1172 | 1172 |
1173 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> styleFromMatchedRulesForE
lement(Element* element, unsigned rulesToInclude) | 1173 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> styleFromMatchedRulesForE
lement(Element* element, unsigned rulesToInclude) |
1174 { | 1174 { |
1175 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 1175 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(HTMLQuirksMode); |
1176 RefPtrWillBeRawPtr<StyleRuleList> matchedRules = element->document().ensureS
tyleResolver().styleRulesForElement(element, rulesToInclude); | 1176 RefPtrWillBeRawPtr<StyleRuleList> matchedRules = element->document().ensureS
tyleResolver().styleRulesForElement(element, rulesToInclude); |
1177 if (matchedRules) { | 1177 if (matchedRules) { |
1178 for (unsigned i = 0; i < matchedRules->size(); ++i) | 1178 for (unsigned i = 0; i < matchedRules->size(); ++i) |
1179 style->mergeAndOverrideOnConflict(&matchedRules->at(i)->properties()
); | 1179 style->mergeAndOverrideOnConflict(&matchedRules->at(i)->properties()
); |
1180 } | 1180 } |
1181 return style.release(); | 1181 return style.release(); |
1182 } | 1182 } |
1183 | 1183 |
1184 void EditingStyle::mergeStyleFromRules(Element* element) | 1184 void EditingStyle::mergeStyleFromRules(Element* element) |
1185 { | 1185 { |
1186 RefPtrWillBeRawPtr<MutableStylePropertySet> styleFromMatchedRules = styleFro
mMatchedRulesForElement(element, | 1186 RefPtrWillBeRawPtr<MutableStylePropertySet> styleFromMatchedRules = styleFro
mMatchedRulesForElement(element, |
1187 StyleResolver::AuthorCSSRules | StyleResolver::CrossOriginCSSRules); | 1187 StyleResolver::AuthorCSSRules | StyleResolver::CrossOriginCSSRules); |
1188 // Styles from the inline style declaration, held in the variable "style", t
ake precedence | 1188 // Styles from the inline style declaration, held in the variable "style", t
ake precedence |
1189 // over those from matched rules. | 1189 // over those from matched rules. |
1190 if (m_mutableStyle) | 1190 if (m_mutableStyle) |
1191 styleFromMatchedRules->mergeAndOverrideOnConflict(m_mutableStyle.get()); | 1191 styleFromMatchedRules->mergeAndOverrideOnConflict(m_mutableStyle.get()); |
1192 | 1192 |
1193 clear(); | 1193 clear(); |
1194 m_mutableStyle = styleFromMatchedRules; | 1194 m_mutableStyle = styleFromMatchedRules; |
1195 } | 1195 } |
1196 | 1196 |
1197 void EditingStyle::mergeStyleFromRulesForSerialization(Element* element) | 1197 void EditingStyle::mergeStyleFromRulesForSerialization(Element* element) |
1198 { | 1198 { |
1199 mergeStyleFromRules(element); | 1199 mergeStyleFromRules(element); |
1200 | 1200 |
1201 // The property value, if it's a percentage, may not reflect the actual comp
uted value. | 1201 // The property value, if it's a percentage, may not reflect the actual comp
uted value. |
1202 // For example: style="height: 1%; overflow: visible;" in quirksmode | 1202 // For example: style="height: 1%; overflow: visible;" in quirksmode |
1203 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot
copy/paste fidelity problem | 1203 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot
copy/paste fidelity problem |
1204 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleForElement = CS
SComputedStyleDeclaration::create(element); | 1204 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleForElement = CS
SComputedStyleDeclaration::create(element); |
1205 RefPtrWillBeRawPtr<MutableStylePropertySet> fromComputedStyle = MutableStyle
PropertySet::create(); | 1205 RefPtrWillBeRawPtr<MutableStylePropertySet> fromComputedStyle = MutableStyle
PropertySet::create(HTMLQuirksMode); |
1206 { | 1206 { |
1207 unsigned propertyCount = m_mutableStyle->propertyCount(); | 1207 unsigned propertyCount = m_mutableStyle->propertyCount(); |
1208 for (unsigned i = 0; i < propertyCount; ++i) { | 1208 for (unsigned i = 0; i < propertyCount; ++i) { |
1209 StylePropertySet::PropertyReference property = m_mutableStyle->prope
rtyAt(i); | 1209 StylePropertySet::PropertyReference property = m_mutableStyle->prope
rtyAt(i); |
1210 CSSValue* value = property.value(); | 1210 CSSValue* value = property.value(); |
1211 if (!value->isPrimitiveValue()) | 1211 if (!value->isPrimitiveValue()) |
1212 continue; | 1212 continue; |
1213 if (toCSSPrimitiveValue(value)->isPercentage()) { | 1213 if (toCSSPrimitiveValue(value)->isPercentage()) { |
1214 if (RefPtrWillBeRawPtr<CSSValue> computedPropertyValue = compute
dStyleForElement->getPropertyCSSValue(property.id())) | 1214 if (RefPtrWillBeRawPtr<CSSValue> computedPropertyValue = compute
dStyleForElement->getPropertyCSSValue(property.id())) |
1215 fromComputedStyle->addRespectingCascade(CSSProperty(property
.id(), computedPropertyValue)); | 1215 fromComputedStyle->addRespectingCascade(CSSProperty(property
.id(), computedPropertyValue)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 m_mutableStyle->setProperty(CSSPropertyPosition, CSSValueAbsolute); | 1291 m_mutableStyle->setProperty(CSSPropertyPosition, CSSValueAbsolute); |
1292 m_mutableStyle->setProperty(CSSPropertyLeft, cssValuePool().createValue(x, C
SSPrimitiveValue::UnitType::Pixels)); | 1292 m_mutableStyle->setProperty(CSSPropertyLeft, cssValuePool().createValue(x, C
SSPrimitiveValue::UnitType::Pixels)); |
1293 m_mutableStyle->setProperty(CSSPropertyTop, cssValuePool().createValue(y, CS
SPrimitiveValue::UnitType::Pixels)); | 1293 m_mutableStyle->setProperty(CSSPropertyTop, cssValuePool().createValue(y, CS
SPrimitiveValue::UnitType::Pixels)); |
1294 m_mutableStyle->setProperty(CSSPropertyWidth, cssValuePool().createValue(wid
th, CSSPrimitiveValue::UnitType::Pixels)); | 1294 m_mutableStyle->setProperty(CSSPropertyWidth, cssValuePool().createValue(wid
th, CSSPrimitiveValue::UnitType::Pixels)); |
1295 m_mutableStyle->setProperty(CSSPropertyHeight, cssValuePool().createValue(he
ight, CSSPrimitiveValue::UnitType::Pixels)); | 1295 m_mutableStyle->setProperty(CSSPropertyHeight, cssValuePool().createValue(he
ight, CSSPrimitiveValue::UnitType::Pixels)); |
1296 } | 1296 } |
1297 | 1297 |
1298 void EditingStyle::forceInline() | 1298 void EditingStyle::forceInline() |
1299 { | 1299 { |
1300 if (!m_mutableStyle) | 1300 if (!m_mutableStyle) |
1301 m_mutableStyle = MutableStylePropertySet::create(); | 1301 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); |
1302 const bool propertyIsImportant = true; | 1302 const bool propertyIsImportant = true; |
1303 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm
portant); | 1303 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm
portant); |
1304 } | 1304 } |
1305 | 1305 |
1306 int EditingStyle::legacyFontSize(Document* document) const | 1306 int EditingStyle::legacyFontSize(Document* document) const |
1307 { | 1307 { |
1308 RefPtrWillBeRawPtr<CSSValue> cssValue = m_mutableStyle->getPropertyCSSValue(
CSSPropertyFontSize); | 1308 RefPtrWillBeRawPtr<CSSValue> cssValue = m_mutableStyle->getPropertyCSSValue(
CSSPropertyFontSize); |
1309 if (!cssValue || !cssValue->isPrimitiveValue()) | 1309 if (!cssValue || !cssValue->isPrimitiveValue()) |
1310 return 0; | 1310 return 0; |
1311 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue.get
()), | 1311 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue.get
()), |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 { | 1718 { |
1719 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { | 1719 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { |
1720 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu
tedStyleDeclaration::create(ancestor); | 1720 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu
tedStyleDeclaration::create(ancestor); |
1721 if (!hasTransparentBackgroundColor(ancestorStyle.get())) | 1721 if (!hasTransparentBackgroundColor(ancestorStyle.get())) |
1722 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor
); | 1722 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor
); |
1723 } | 1723 } |
1724 return nullptr; | 1724 return nullptr; |
1725 } | 1725 } |
1726 | 1726 |
1727 } | 1727 } |
OLD | NEW |