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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 if (!m_mutableStyle) | 609 if (!m_mutableStyle) |
610 return; | 610 return; |
611 | 611 |
612 m_mutableStyle->removeBlockProperties(); | 612 m_mutableStyle->removeBlockProperties(); |
613 } | 613 } |
614 | 614 |
615 void EditingStyle::removeStyleAddedByNode(Node* node) | 615 void EditingStyle::removeStyleAddedByNode(Node* node) |
616 { | 616 { |
617 if (!node || !node->parentNode()) | 617 if (!node || !node->parentNode()) |
618 return; | 618 return; |
619 RefPtr<StylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComp
utedStyleDeclaration::create(node->parentNode()), AllEditingProperties); | 619 RefPtr<MutableStylePropertySet> parentStyle = editingStyleFromComputedStyle(
CSSComputedStyleDeclaration::create(node->parentNode()), AllEditingProperties); |
620 RefPtr<StylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComput
edStyleDeclaration::create(node), AllEditingProperties); | 620 RefPtr<MutableStylePropertySet> nodeStyle = editingStyleFromComputedStyle(CS
SComputedStyleDeclaration::create(node), AllEditingProperties); |
621 nodeStyle->removeEquivalentProperties(parentStyle->ensureCSSStyleDeclaration
()); | 621 nodeStyle->removeEquivalentProperties(parentStyle->ensureCSSStyleDeclaration
()); |
622 m_mutableStyle->removeEquivalentProperties(nodeStyle->ensureCSSStyleDeclarat
ion()); | 622 m_mutableStyle->removeEquivalentProperties(nodeStyle->ensureCSSStyleDeclarat
ion()); |
623 } | 623 } |
624 | 624 |
625 void EditingStyle::removeStyleConflictingWithStyleOfNode(Node* node) | 625 void EditingStyle::removeStyleConflictingWithStyleOfNode(Node* node) |
626 { | 626 { |
627 if (!node || !node->parentNode() || !m_mutableStyle) | 627 if (!node || !node->parentNode() || !m_mutableStyle) |
628 return; | 628 return; |
629 | 629 |
630 RefPtr<StylePropertySet> parentStyle = editingStyleFromComputedStyle(CSSComp
utedStyleDeclaration::create(node->parentNode()), AllEditingProperties); | 630 RefPtr<MutableStylePropertySet> parentStyle = editingStyleFromComputedStyle(
CSSComputedStyleDeclaration::create(node->parentNode()), AllEditingProperties); |
631 RefPtr<StylePropertySet> nodeStyle = editingStyleFromComputedStyle(CSSComput
edStyleDeclaration::create(node), AllEditingProperties); | 631 RefPtr<MutableStylePropertySet> nodeStyle = editingStyleFromComputedStyle(CS
SComputedStyleDeclaration::create(node), AllEditingProperties); |
632 nodeStyle->removeEquivalentProperties(parentStyle->ensureCSSStyleDeclaration
()); | 632 nodeStyle->removeEquivalentProperties(parentStyle->ensureCSSStyleDeclaration
()); |
633 | 633 |
634 unsigned propertyCount = nodeStyle->propertyCount(); | 634 unsigned propertyCount = nodeStyle->propertyCount(); |
635 for (unsigned i = 0; i < propertyCount; ++i) | 635 for (unsigned i = 0; i < propertyCount; ++i) |
636 m_mutableStyle->removeProperty(nodeStyle->propertyAt(i).id()); | 636 m_mutableStyle->removeProperty(nodeStyle->propertyAt(i).id()); |
637 } | 637 } |
638 | 638 |
639 void EditingStyle::removeNonEditingProperties() | 639 void EditingStyle::removeNonEditingProperties() |
640 { | 640 { |
641 if (m_mutableStyle) | 641 if (m_mutableStyle) |
(...skipping 22 matching lines...) Expand all Loading... |
664 CSSPropertyWebkitTextDecorationsInEffect, | 664 CSSPropertyWebkitTextDecorationsInEffect, |
665 CSSPropertyFontStyle, | 665 CSSPropertyFontStyle, |
666 CSSPropertyFontWeight, | 666 CSSPropertyFontWeight, |
667 CSSPropertyColor, | 667 CSSPropertyColor, |
668 }; | 668 }; |
669 | 669 |
670 TriState EditingStyle::triStateOfStyle(EditingStyle* style) const | 670 TriState EditingStyle::triStateOfStyle(EditingStyle* style) const |
671 { | 671 { |
672 if (!style || !style->m_mutableStyle) | 672 if (!style || !style->m_mutableStyle) |
673 return FalseTriState; | 673 return FalseTriState; |
674 return triStateOfStyle(style->m_mutableStyle->ensureCSSStyleDeclaration(), D
oNotIgnoreTextOnlyProperties); | 674 return triStateOfStyle(static_pointer_cast<MutableStylePropertySet>(style->m
_mutableStyle)->ensureCSSStyleDeclaration(), DoNotIgnoreTextOnlyProperties); |
675 } | 675 } |
676 | 676 |
677 TriState EditingStyle::triStateOfStyle(CSSStyleDeclaration* styleToCompare, Shou
ldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const | 677 TriState EditingStyle::triStateOfStyle(CSSStyleDeclaration* styleToCompare, Shou
ldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const |
678 { | 678 { |
679 RefPtr<StylePropertySet> difference = getPropertiesNotIn(m_mutableStyle.get(
), styleToCompare); | 679 RefPtr<StylePropertySet> difference = getPropertiesNotIn(m_mutableStyle.get(
), styleToCompare); |
680 | 680 |
681 if (shouldIgnoreTextOnlyProperties == IgnoreTextOnlyProperties) | 681 if (shouldIgnoreTextOnlyProperties == IgnoreTextOnlyProperties) |
682 difference->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(t
extOnlyProperties)); | 682 difference->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(t
extOnlyProperties)); |
683 | 683 |
684 if (difference->isEmpty()) | 684 if (difference->isEmpty()) |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 continue; | 1085 continue; |
1086 } | 1086 } |
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<MutableStylePropertySet> styleFromMatchedRulesForElement(Eleme
nt* element, unsigned rulesToInclude) |
1096 { | 1096 { |
1097 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::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 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data()
, propertiesToRemove.size()); | 1154 styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data()
, propertiesToRemove.size()); |
1155 } | 1155 } |
1156 | 1156 |
1157 void EditingStyle::removeStyleFromRulesAndContext(StyledElement* element, Node*
context) | 1157 void EditingStyle::removeStyleFromRulesAndContext(StyledElement* element, Node*
context) |
1158 { | 1158 { |
1159 ASSERT(element); | 1159 ASSERT(element); |
1160 if (!m_mutableStyle) | 1160 if (!m_mutableStyle) |
1161 return; | 1161 return; |
1162 | 1162 |
1163 // 1. Remove style from matched rules because style remain without repeating
it in inline style declaration | 1163 // 1. Remove style from matched rules because style remain without repeating
it in inline style declaration |
1164 RefPtr<StylePropertySet> styleFromMatchedRules = styleFromMatchedRulesForEle
ment(element, StyleResolver::AllButEmptyCSSRules); | 1164 RefPtr<MutableStylePropertySet> styleFromMatchedRules = styleFromMatchedRule
sForElement(element, StyleResolver::AllButEmptyCSSRules); |
1165 if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) | 1165 if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) |
1166 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatch
edRules->ensureCSSStyleDeclaration()); | 1166 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatch
edRules->ensureCSSStyleDeclaration()); |
1167 | 1167 |
1168 // 2. Remove style present in context and not overriden by matched rules. | 1168 // 2. Remove style present in context and not overriden by matched rules. |
1169 RefPtr<EditingStyle> computedStyle = EditingStyle::create(context, EditingPr
opertiesInEffect); | 1169 RefPtr<EditingStyle> computedStyle = EditingStyle::create(context, EditingPr
opertiesInEffect); |
1170 if (computedStyle->m_mutableStyle) { | 1170 if (computedStyle->m_mutableStyle) { |
1171 if (!computedStyle->m_mutableStyle->getPropertyCSSValue(CSSPropertyBackg
roundColor)) | 1171 if (!computedStyle->m_mutableStyle->getPropertyCSSValue(CSSPropertyBackg
roundColor)) |
1172 computedStyle->m_mutableStyle->setProperty(CSSPropertyBackgroundColo
r, CSSValueTransparent); | 1172 computedStyle->m_mutableStyle->setProperty(CSSPropertyBackgroundColo
r, CSSValueTransparent); |
1173 | 1173 |
1174 removePropertiesInStyle(computedStyle->m_mutableStyle.get(), styleFromMa
tchedRules.get()); | 1174 removePropertiesInStyle(computedStyle->m_mutableStyle.get(), styleFromMa
tchedRules.get()); |
1175 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), computedStyle-
>m_mutableStyle->ensureCSSStyleDeclaration()); | 1175 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), static_pointer
_cast<MutableStylePropertySet>(computedStyle->m_mutableStyle)->ensureCSSStyleDec
laration()); |
1176 } | 1176 } |
1177 | 1177 |
1178 // 3. If this element is a span and has display: inline or float: none, remo
ve them unless they are overriden by rules. | 1178 // 3. If this element is a span and has display: inline or float: none, remo
ve them unless they are overriden by rules. |
1179 // These rules are added by serialization code to wrap text nodes. | 1179 // These rules are added by serialization code to wrap text nodes. |
1180 if (isStyleSpanOrSpanWithOnlyStyleAttribute(element)) { | 1180 if (isStyleSpanOrSpanWithOnlyStyleAttribute(element)) { |
1181 if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyDisplay) && g
etIdentifierValue(m_mutableStyle.get(), CSSPropertyDisplay) == CSSValueInline) | 1181 if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyDisplay) && g
etIdentifierValue(m_mutableStyle.get(), CSSPropertyDisplay) == CSSValueInline) |
1182 m_mutableStyle->removeProperty(CSSPropertyDisplay); | 1182 m_mutableStyle->removeProperty(CSSPropertyDisplay); |
1183 if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyFloat) && get
IdentifierValue(m_mutableStyle.get(), CSSPropertyFloat) == CSSValueNone) | 1183 if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyFloat) && get
IdentifierValue(m_mutableStyle.get(), CSSPropertyFloat) == CSSValueNone) |
1184 m_mutableStyle->removeProperty(CSSPropertyFloat); | 1184 m_mutableStyle->removeProperty(CSSPropertyFloat); |
1185 } | 1185 } |
(...skipping 429 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 |