Chromium Code Reviews| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 : m_propertyID(id) | 197 : m_propertyID(id) |
| 198 , m_tagName(&tagName) | 198 , m_tagName(&tagName) |
| 199 { | 199 { |
| 200 } | 200 } |
| 201 | 201 |
| 202 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit iveValue, const HTMLQualifiedName& tagName) | 202 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit iveValue, const HTMLQualifiedName& tagName) |
| 203 : m_propertyID(id) | 203 : m_propertyID(id) |
| 204 , m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue)) | 204 , m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue)) |
| 205 , m_tagName(&tagName) | 205 , m_tagName(&tagName) |
| 206 { | 206 { |
| 207 ASSERT(primitiveValue != CSSValueInvalid); | 207 DCHECK_NE(primitiveValue, CSSValueInvalid); |
| 208 } | 208 } |
| 209 | 209 |
| 210 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const | 210 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const |
| 211 { | 211 { |
| 212 CSSValue* value = style->getPropertyCSSValue(m_propertyID); | 212 CSSValue* value = style->getPropertyCSSValue(m_propertyID); |
| 213 return matches(element) && value && value->isPrimitiveValue() && toCSSPrimit iveValue(value)->getValueID() == m_primitiveValue->getValueID(); | 213 return matches(element) && value && value->isPrimitiveValue() && toCSSPrimit iveValue(value)->getValueID() == m_primitiveValue->getValueID(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const | 216 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const |
| 217 { | 217 { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 } | 300 } |
| 301 | 301 |
| 302 void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) const | 302 void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) const |
| 303 { | 303 { |
| 304 if (CSSValue* value = attributeValueAsCSSValue(element)) | 304 if (CSSValue* value = attributeValueAsCSSValue(element)) |
| 305 style->setProperty(m_propertyID, value->cssText()); | 305 style->setProperty(m_propertyID, value->cssText()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 CSSValue* HTMLAttributeEquivalent::attributeValueAsCSSValue(Element* element) co nst | 308 CSSValue* HTMLAttributeEquivalent::attributeValueAsCSSValue(Element* element) co nst |
| 309 { | 309 { |
| 310 ASSERT(element); | 310 DCHECK(element); |
| 311 const AtomicString& value = element->getAttribute(m_attrName); | 311 const AtomicString& value = element->getAttribute(m_attrName); |
| 312 if (value.isNull()) | 312 if (value.isNull()) |
| 313 return nullptr; | 313 return nullptr; |
| 314 | 314 |
| 315 MutableStylePropertySet* dummyStyle = nullptr; | 315 MutableStylePropertySet* dummyStyle = nullptr; |
| 316 dummyStyle = MutableStylePropertySet::create(HTMLQuirksMode); | 316 dummyStyle = MutableStylePropertySet::create(HTMLQuirksMode); |
| 317 dummyStyle->setProperty(m_propertyID, value); | 317 dummyStyle->setProperty(m_propertyID, value); |
| 318 return dummyStyle->getPropertyCSSValue(m_propertyID); | 318 return dummyStyle->getPropertyCSSValue(m_propertyID); |
| 319 } | 319 } |
| 320 | 320 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 332 HTMLFontSizeEquivalent(); | 332 HTMLFontSizeEquivalent(); |
| 333 }; | 333 }; |
| 334 | 334 |
| 335 HTMLFontSizeEquivalent::HTMLFontSizeEquivalent() | 335 HTMLFontSizeEquivalent::HTMLFontSizeEquivalent() |
| 336 : HTMLAttributeEquivalent(CSSPropertyFontSize, HTMLNames::fontTag, HTMLNames ::sizeAttr) | 336 : HTMLAttributeEquivalent(CSSPropertyFontSize, HTMLNames::fontTag, HTMLNames ::sizeAttr) |
| 337 { | 337 { |
| 338 } | 338 } |
| 339 | 339 |
| 340 CSSValue* HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* element) con st | 340 CSSValue* HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* element) con st |
| 341 { | 341 { |
| 342 ASSERT(element); | 342 DCHECK(element); |
| 343 const AtomicString& value = element->getAttribute(m_attrName); | 343 const AtomicString& value = element->getAttribute(m_attrName); |
| 344 if (value.isNull()) | 344 if (value.isNull()) |
| 345 return nullptr; | 345 return nullptr; |
| 346 CSSValueID size; | 346 CSSValueID size; |
| 347 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) | 347 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) |
| 348 return nullptr; | 348 return nullptr; |
| 349 return CSSPrimitiveValue::createIdentifier(size); | 349 return CSSPrimitiveValue::createIdentifier(size); |
| 350 } | 350 } |
| 351 | 351 |
| 352 float EditingStyle::NoFontDelta = 0.0f; | 352 float EditingStyle::NoFontDelta = 0.0f; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, bo ol important) | 499 void EditingStyle::setProperty(CSSPropertyID propertyID, const String& value, bo ol important) |
| 500 { | 500 { |
| 501 if (!m_mutableStyle) | 501 if (!m_mutableStyle) |
| 502 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); | 502 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); |
| 503 | 503 |
| 504 m_mutableStyle->setProperty(propertyID, value, important); | 504 m_mutableStyle->setProperty(propertyID, value, important); |
| 505 } | 505 } |
| 506 | 506 |
| 507 void EditingStyle::replaceFontSizeByKeywordIfPossible(const ComputedStyle* compu tedStyle, CSSComputedStyleDeclaration* cssComputedStyle) | 507 void EditingStyle::replaceFontSizeByKeywordIfPossible(const ComputedStyle* compu tedStyle, CSSComputedStyleDeclaration* cssComputedStyle) |
| 508 { | 508 { |
| 509 ASSERT(computedStyle); | 509 DCHECK(computedStyle); |
| 510 if (computedStyle->getFontDescription().keywordSize()) | 510 if (computedStyle->getFontDescription().keywordSize()) |
| 511 m_mutableStyle->setProperty(CSSPropertyFontSize, cssComputedStyle->getFo ntSizeCSSValuePreferringKeyword()->cssText()); | 511 m_mutableStyle->setProperty(CSSPropertyFontSize, cssComputedStyle->getFo ntSizeCSSValuePreferringKeyword()->cssText()); |
| 512 } | 512 } |
| 513 | 513 |
| 514 void EditingStyle::extractFontSizeDelta() | 514 void EditingStyle::extractFontSizeDelta() |
| 515 { | 515 { |
| 516 if (!m_mutableStyle) | 516 if (!m_mutableStyle) |
| 517 return; | 517 return; |
| 518 | 518 |
| 519 if (m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize)) { | 519 if (m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize)) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 } | 766 } |
| 767 if (&node == selection.end().anchorNode()) | 767 if (&node == selection.end().anchorNode()) |
| 768 break; | 768 break; |
| 769 } | 769 } |
| 770 | 770 |
| 771 return state; | 771 return state; |
| 772 } | 772 } |
| 773 | 773 |
| 774 bool EditingStyle::conflictsWithInlineStyleOfElement(HTMLElement* element, Editi ngStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const | 774 bool EditingStyle::conflictsWithInlineStyleOfElement(HTMLElement* element, Editi ngStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const |
| 775 { | 775 { |
| 776 ASSERT(element); | 776 DCHECK(element); |
| 777 ASSERT(!conflictingProperties || conflictingProperties->isEmpty()); | 777 DCHECK(!conflictingProperties || conflictingProperties->isEmpty()); |
| 778 | 778 |
| 779 const StylePropertySet* inlineStyle = element->inlineStyle(); | 779 const StylePropertySet* inlineStyle = element->inlineStyle(); |
| 780 if (!m_mutableStyle || !inlineStyle) | 780 if (!m_mutableStyle || !inlineStyle) |
| 781 return false; | 781 return false; |
| 782 | 782 |
| 783 unsigned propertyCount = m_mutableStyle->propertyCount(); | 783 unsigned propertyCount = m_mutableStyle->propertyCount(); |
| 784 for (unsigned i = 0; i < propertyCount; ++i) { | 784 for (unsigned i = 0; i < propertyCount; ++i) { |
| 785 CSSPropertyID propertyID = m_mutableStyle->propertyAt(i).id(); | 785 CSSPropertyID propertyID = m_mutableStyle->propertyAt(i).id(); |
| 786 | 786 |
| 787 // We don't override whitespace property of a tab span because that woul d collapse the tab into a space. | 787 // We don't override whitespace property of a tab span because that woul d collapse the tab into a space. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 | 874 |
| 875 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyDirection, HTMLNames::dirAttr)); | 875 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyDirection, HTMLNames::dirAttr)); |
| 876 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyUnicodeBidi, HTMLNames::dirAttr)); | 876 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyUnicodeBidi, HTMLNames::dirAttr)); |
| 877 } | 877 } |
| 878 | 878 |
| 879 return HTMLAttributeEquivalents; | 879 return HTMLAttributeEquivalents; |
| 880 } | 880 } |
| 881 | 881 |
| 882 bool EditingStyle::conflictsWithImplicitStyleOfAttributes(HTMLElement* element) const | 882 bool EditingStyle::conflictsWithImplicitStyleOfAttributes(HTMLElement* element) const |
| 883 { | 883 { |
| 884 ASSERT(element); | 884 DCHECK(element); |
| 885 if (!m_mutableStyle) | 885 if (!m_mutableStyle) |
| 886 return false; | 886 return false; |
| 887 | 887 |
| 888 const HeapVector<Member<HTMLAttributeEquivalent>>& HTMLAttributeEquivalents = htmlAttributeEquivalents(); | 888 const HeapVector<Member<HTMLAttributeEquivalent>>& HTMLAttributeEquivalents = htmlAttributeEquivalents(); |
| 889 for (const auto& equivalent : HTMLAttributeEquivalents) { | 889 for (const auto& equivalent : HTMLAttributeEquivalents) { |
| 890 if (equivalent->matches(element) && equivalent->propertyExistsInStyle(m_ mutableStyle.get()) | 890 if (equivalent->matches(element) && equivalent->propertyExistsInStyle(m_ mutableStyle.get()) |
| 891 && !equivalent->valueIsPresentInStyle(element, m_mutableStyle.get()) ) | 891 && !equivalent->valueIsPresentInStyle(element, m_mutableStyle.get()) ) |
| 892 return true; | 892 return true; |
| 893 } | 893 } |
| 894 | 894 |
| 895 return false; | 895 return false; |
| 896 } | 896 } |
| 897 | 897 |
| 898 bool EditingStyle::extractConflictingImplicitStyleOfAttributes(HTMLElement* elem ent, ShouldPreserveWritingDirection shouldPreserveWritingDirection, | 898 bool EditingStyle::extractConflictingImplicitStyleOfAttributes(HTMLElement* elem ent, ShouldPreserveWritingDirection shouldPreserveWritingDirection, |
| 899 EditingStyle* extractedStyle, Vector<QualifiedName>& conflictingAttributes, ShouldExtractMatchingStyle shouldExtractMatchingStyle) const | 899 EditingStyle* extractedStyle, Vector<QualifiedName>& conflictingAttributes, ShouldExtractMatchingStyle shouldExtractMatchingStyle) const |
| 900 { | 900 { |
| 901 ASSERT(element); | 901 DCHECK(element); |
| 902 // HTMLAttributeEquivalent::addToStyle doesn't support unicode-bidi and dire ction properties | 902 // HTMLAttributeEquivalent::addToStyle doesn't support unicode-bidi and dire ction properties |
| 903 ASSERT(!extractedStyle || shouldPreserveWritingDirection == PreserveWritingD irection); | 903 DCHECK(!extractedStyle || shouldPreserveWritingDirection == PreserveWritingD irection); |
|
yosin_UTC9
2016/04/14 04:35:00
How about rewriting to:
if (extractStyle)
DCHE
| |
| 904 if (!m_mutableStyle) | 904 if (!m_mutableStyle) |
| 905 return false; | 905 return false; |
| 906 | 906 |
| 907 const HeapVector<Member<HTMLAttributeEquivalent>>& HTMLAttributeEquivalents = htmlAttributeEquivalents(); | 907 const HeapVector<Member<HTMLAttributeEquivalent>>& HTMLAttributeEquivalents = htmlAttributeEquivalents(); |
| 908 bool removed = false; | 908 bool removed = false; |
| 909 for (const auto& attribute : HTMLAttributeEquivalents) { | 909 for (const auto& attribute : HTMLAttributeEquivalents) { |
| 910 const HTMLAttributeEquivalent* equivalent = attribute.get(); | 910 const HTMLAttributeEquivalent* equivalent = attribute.get(); |
| 911 | 911 |
| 912 // unicode-bidi and direction are pushed down separately so don't push d own with other styles. | 912 // unicode-bidi and direction are pushed down separately so don't push d own with other styles. |
| 913 if (shouldPreserveWritingDirection == PreserveWritingDirection && equiva lent->attributeName() == HTMLNames::dirAttr) | 913 if (shouldPreserveWritingDirection == PreserveWritingDirection && equiva lent->attributeName() == HTMLNames::dirAttr) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 926 return removed; | 926 return removed; |
| 927 } | 927 } |
| 928 | 928 |
| 929 bool EditingStyle::styleIsPresentInComputedStyleOfNode(Node* node) const | 929 bool EditingStyle::styleIsPresentInComputedStyleOfNode(Node* node) const |
| 930 { | 930 { |
| 931 return !m_mutableStyle || getPropertiesNotIn(m_mutableStyle.get(), CSSComput edStyleDeclaration::create(node))->isEmpty(); | 931 return !m_mutableStyle || getPropertiesNotIn(m_mutableStyle.get(), CSSComput edStyleDeclaration::create(node))->isEmpty(); |
| 932 } | 932 } |
| 933 | 933 |
| 934 bool EditingStyle::elementIsStyledSpanOrHTMLEquivalent(const HTMLElement* elemen t) | 934 bool EditingStyle::elementIsStyledSpanOrHTMLEquivalent(const HTMLElement* elemen t) |
| 935 { | 935 { |
| 936 ASSERT(element); | 936 DCHECK(element); |
| 937 bool elementIsSpanOrElementEquivalent = false; | 937 bool elementIsSpanOrElementEquivalent = false; |
| 938 if (isHTMLSpanElement(*element)) { | 938 if (isHTMLSpanElement(*element)) { |
| 939 elementIsSpanOrElementEquivalent = true; | 939 elementIsSpanOrElementEquivalent = true; |
| 940 } else { | 940 } else { |
| 941 const HeapVector<Member<HTMLElementEquivalent>>& HTMLElementEquivalents = htmlElementEquivalents(); | 941 const HeapVector<Member<HTMLElementEquivalent>>& HTMLElementEquivalents = htmlElementEquivalents(); |
| 942 size_t i; | 942 size_t i; |
| 943 for (i = 0; i < HTMLElementEquivalents.size(); ++i) { | 943 for (i = 0; i < HTMLElementEquivalents.size(); ++i) { |
| 944 if (HTMLElementEquivalents[i]->matches(element)) { | 944 if (HTMLElementEquivalents[i]->matches(element)) { |
| 945 elementIsSpanOrElementEquivalent = true; | 945 elementIsSpanOrElementEquivalent = true; |
| 946 break; | 946 break; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 970 unsigned propertyCount = style->propertyCount(); | 970 unsigned propertyCount = style->propertyCount(); |
| 971 for (unsigned i = 0; i < propertyCount; ++i) { | 971 for (unsigned i = 0; i < propertyCount; ++i) { |
| 972 if (!isEditingProperty(style->propertyAt(i).id())) | 972 if (!isEditingProperty(style->propertyAt(i).id())) |
| 973 return false; | 973 return false; |
| 974 } | 974 } |
| 975 } | 975 } |
| 976 matchedAttributes++; | 976 matchedAttributes++; |
| 977 } | 977 } |
| 978 | 978 |
| 979 // font with color attribute, span with style attribute, etc... | 979 // font with color attribute, span with style attribute, etc... |
| 980 ASSERT(matchedAttributes <= attributes.size()); | 980 DCHECK_LE(matchedAttributes, attributes.size()); |
| 981 return matchedAttributes >= attributes.size(); | 981 return matchedAttributes >= attributes.size(); |
| 982 } | 982 } |
| 983 | 983 |
| 984 void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit ingDirection shouldPreserveWritingDirection) | 984 void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit ingDirection shouldPreserveWritingDirection) |
| 985 { | 985 { |
| 986 if (!m_mutableStyle) | 986 if (!m_mutableStyle) |
| 987 return; | 987 return; |
| 988 | 988 |
| 989 // ReplaceSelectionCommand::handleStyleSpans() requires that this function o nly removes the editing style. | 989 // ReplaceSelectionCommand::handleStyleSpans() requires that this function o nly removes the editing style. |
| 990 // If this function was modified in the future to delete all redundant prope rties, then add a boolean value to indicate | 990 // If this function was modified in the future to delete all redundant prope rties, then add a boolean value to indicate |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1013 | 1013 |
| 1014 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) { | 1014 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) { |
| 1015 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue( unicodeBidi)->getValueID()); | 1015 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue( unicodeBidi)->getValueID()); |
| 1016 if (direction && direction->isPrimitiveValue()) | 1016 if (direction && direction->isPrimitiveValue()) |
| 1017 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValu e(direction)->getValueID()); | 1017 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValu e(direction)->getValueID()); |
| 1018 } | 1018 } |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 void EditingStyle::mergeTypingStyle(Document* document) | 1021 void EditingStyle::mergeTypingStyle(Document* document) |
| 1022 { | 1022 { |
| 1023 ASSERT(document); | 1023 DCHECK(document); |
| 1024 | 1024 |
| 1025 EditingStyle* typingStyle = document->frame()->selection().typingStyle(); | 1025 EditingStyle* typingStyle = document->frame()->selection().typingStyle(); |
| 1026 if (!typingStyle || typingStyle == this) | 1026 if (!typingStyle || typingStyle == this) |
| 1027 return; | 1027 return; |
| 1028 | 1028 |
| 1029 mergeStyle(typingStyle->style(), OverrideValues); | 1029 mergeStyle(typingStyle->style(), OverrideValues); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 void EditingStyle::mergeInlineStyleOfElement(HTMLElement* element, CSSPropertyOv errideMode mode, PropertiesToInclude propertiesToInclude) | 1032 void EditingStyle::mergeInlineStyleOfElement(HTMLElement* element, CSSPropertyOv errideMode mode, PropertiesToInclude propertiesToInclude) |
| 1033 { | 1033 { |
| 1034 ASSERT(element); | 1034 DCHECK(element); |
| 1035 if (!element->inlineStyle()) | 1035 if (!element->inlineStyle()) |
| 1036 return; | 1036 return; |
| 1037 | 1037 |
| 1038 switch (propertiesToInclude) { | 1038 switch (propertiesToInclude) { |
| 1039 case AllProperties: | 1039 case AllProperties: |
| 1040 mergeStyle(element->inlineStyle(), mode); | 1040 mergeStyle(element->inlineStyle(), mode); |
| 1041 return; | 1041 return; |
| 1042 case OnlyEditingInheritableProperties: | 1042 case OnlyEditingInheritableProperties: |
| 1043 mergeStyle(copyEditingProperties(element->inlineStyle(), OnlyInheritable EditingProperties), mode); | 1043 mergeStyle(copyEditingProperties(element->inlineStyle(), OnlyInheritable EditingProperties), mode); |
| 1044 return; | 1044 return; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1223 unsigned propertyCount = style->propertyCount(); | 1223 unsigned propertyCount = style->propertyCount(); |
| 1224 Vector<CSSPropertyID> propertiesToRemove(propertyCount); | 1224 Vector<CSSPropertyID> propertiesToRemove(propertyCount); |
| 1225 for (unsigned i = 0; i < propertyCount; ++i) | 1225 for (unsigned i = 0; i < propertyCount; ++i) |
| 1226 propertiesToRemove[i] = style->propertyAt(i).id(); | 1226 propertiesToRemove[i] = style->propertyAt(i).id(); |
| 1227 | 1227 |
| 1228 styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data() , propertiesToRemove.size()); | 1228 styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data() , propertiesToRemove.size()); |
| 1229 } | 1229 } |
| 1230 | 1230 |
| 1231 void EditingStyle::removeStyleFromRulesAndContext(Element* element, ContainerNod e* context) | 1231 void EditingStyle::removeStyleFromRulesAndContext(Element* element, ContainerNod e* context) |
| 1232 { | 1232 { |
| 1233 ASSERT(element); | 1233 DCHECK(element); |
| 1234 if (!m_mutableStyle) | 1234 if (!m_mutableStyle) |
| 1235 return; | 1235 return; |
| 1236 | 1236 |
| 1237 // 1. Remove style from matched rules because style remain without repeating it in inline style declaration | 1237 // 1. Remove style from matched rules because style remain without repeating it in inline style declaration |
| 1238 MutableStylePropertySet* styleFromMatchedRules = styleFromMatchedRulesForEle ment(element, StyleResolver::AllButEmptyCSSRules); | 1238 MutableStylePropertySet* styleFromMatchedRules = styleFromMatchedRulesForEle ment(element, StyleResolver::AllButEmptyCSSRules); |
| 1239 if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) | 1239 if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) |
| 1240 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatch edRules->ensureCSSStyleDeclaration()); | 1240 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatch edRules->ensureCSSStyleDeclaration()); |
| 1241 | 1241 |
| 1242 // 2. Remove style present in context and not overriden by matched rules. | 1242 // 2. Remove style present in context and not overriden by matched rules. |
| 1243 EditingStyle* computedStyle = EditingStyle::create(context, EditingPropertie sInEffect); | 1243 EditingStyle* computedStyle = EditingStyle::create(context, EditingPropertie sInEffect); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1362 Position position = mostForwardCaretPosition(selection.start()); | 1362 Position position = mostForwardCaretPosition(selection.start()); |
| 1363 | 1363 |
| 1364 Node* node = position.anchorNode(); | 1364 Node* node = position.anchorNode(); |
| 1365 if (!node) | 1365 if (!node) |
| 1366 return NaturalWritingDirection; | 1366 return NaturalWritingDirection; |
| 1367 | 1367 |
| 1368 Position end; | 1368 Position end; |
| 1369 if (selection.isRange()) { | 1369 if (selection.isRange()) { |
| 1370 end = mostBackwardCaretPosition(selection.end()); | 1370 end = mostBackwardCaretPosition(selection.end()); |
| 1371 | 1371 |
| 1372 ASSERT(end.document()); | 1372 DCHECK(end.document()); |
| 1373 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); | 1373 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); |
| 1374 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { | 1374 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { |
| 1375 if (!n->isStyledElement()) | 1375 if (!n->isStyledElement()) |
| 1376 continue; | 1376 continue; |
| 1377 | 1377 |
| 1378 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(n); | 1378 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(n); |
| 1379 CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicod eBidi); | 1379 CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicod eBidi); |
| 1380 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) | 1380 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) |
| 1381 continue; | 1381 continue; |
| 1382 | 1382 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1410 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) | 1410 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) |
| 1411 continue; | 1411 continue; |
| 1412 | 1412 |
| 1413 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID(); | 1413 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID(); |
| 1414 if (unicodeBidiValue == CSSValueNormal) | 1414 if (unicodeBidiValue == CSSValueNormal) |
| 1415 continue; | 1415 continue; |
| 1416 | 1416 |
| 1417 if (unicodeBidiValue == CSSValueBidiOverride) | 1417 if (unicodeBidiValue == CSSValueBidiOverride) |
| 1418 return NaturalWritingDirection; | 1418 return NaturalWritingDirection; |
| 1419 | 1419 |
| 1420 ASSERT(isEmbedOrIsolate(unicodeBidiValue)); | 1420 DCHECK(isEmbedOrIsolate(unicodeBidiValue)); |
|
yosin_UTC9
2016/04/14 04:34:59
How about adding |<< unicodeBidiValue|?
| |
| 1421 CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirection); | 1421 CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirection); |
| 1422 if (!direction || !direction->isPrimitiveValue()) | 1422 if (!direction || !direction->isPrimitiveValue()) |
| 1423 continue; | 1423 continue; |
| 1424 | 1424 |
| 1425 int directionValue = toCSSPrimitiveValue(direction)->getValueID(); | 1425 int directionValue = toCSSPrimitiveValue(direction)->getValueID(); |
| 1426 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) | 1426 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) |
| 1427 continue; | 1427 continue; |
| 1428 | 1428 |
| 1429 if (foundDirection != NaturalWritingDirection) | 1429 if (foundDirection != NaturalWritingDirection) |
| 1430 return NaturalWritingDirection; | 1430 return NaturalWritingDirection; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1442 DEFINE_TRACE(EditingStyle) | 1442 DEFINE_TRACE(EditingStyle) |
| 1443 { | 1443 { |
| 1444 visitor->trace(m_mutableStyle); | 1444 visitor->trace(m_mutableStyle); |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 static void reconcileTextDecorationProperties(MutableStylePropertySet* style) | 1447 static void reconcileTextDecorationProperties(MutableStylePropertySet* style) |
| 1448 { | 1448 { |
| 1449 CSSValue* textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWe bkitTextDecorationsInEffect); | 1449 CSSValue* textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWe bkitTextDecorationsInEffect); |
| 1450 CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationProperty ForEditing()); | 1450 CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationProperty ForEditing()); |
| 1451 // We shouldn't have both text-decoration and -webkit-text-decorations-in-ef fect because that wouldn't make sense. | 1451 // We shouldn't have both text-decoration and -webkit-text-decorations-in-ef fect because that wouldn't make sense. |
| 1452 ASSERT(!textDecorationsInEffect || !textDecoration); | 1452 DCHECK(!textDecorationsInEffect || !textDecoration); |
| 1453 if (textDecorationsInEffect) { | 1453 if (textDecorationsInEffect) { |
| 1454 style->setProperty(textDecorationPropertyForEditing(), textDecorationsIn Effect->cssText()); | 1454 style->setProperty(textDecorationPropertyForEditing(), textDecorationsIn Effect->cssText()); |
| 1455 style->removeProperty(CSSPropertyWebkitTextDecorationsInEffect); | 1455 style->removeProperty(CSSPropertyWebkitTextDecorationsInEffect); |
| 1456 textDecoration = textDecorationsInEffect; | 1456 textDecoration = textDecorationsInEffect; |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 // If text-decoration is set to "none", remove the property because we don't want to add redundant "text-decoration: none". | 1459 // If text-decoration is set to "none", remove the property because we don't want to add redundant "text-decoration: none". |
| 1460 if (textDecoration && !textDecoration->isValueList()) | 1460 if (textDecoration && !textDecoration->isValueList()) |
| 1461 style->removeProperty(textDecorationPropertyForEditing()); | 1461 style->removeProperty(textDecorationPropertyForEditing()); |
| 1462 } | 1462 } |
| 1463 | 1463 |
| 1464 StyleChange::StyleChange(EditingStyle* style, const Position& position) | 1464 StyleChange::StyleChange(EditingStyle* style, const Position& position) |
| 1465 : m_applyBold(false) | 1465 : m_applyBold(false) |
| 1466 , m_applyItalic(false) | 1466 , m_applyItalic(false) |
| 1467 , m_applyUnderline(false) | 1467 , m_applyUnderline(false) |
| 1468 , m_applyLineThrough(false) | 1468 , m_applyLineThrough(false) |
| 1469 , m_applySubscript(false) | 1469 , m_applySubscript(false) |
| 1470 , m_applySuperscript(false) | 1470 , m_applySuperscript(false) |
| 1471 { | 1471 { |
| 1472 Document* document = position.document(); | 1472 Document* document = position.document(); |
| 1473 if (!style || !style->style() || !document || !document->frame() || !associa tedElementOf(position)) | 1473 if (!style || !style->style() || !document || !document->frame() || !associa tedElementOf(position)) |
| 1474 return; | 1474 return; |
| 1475 | 1475 |
| 1476 CSSComputedStyleDeclaration* computedStyle = ensureComputedStyle(position); | 1476 CSSComputedStyleDeclaration* computedStyle = ensureComputedStyle(position); |
| 1477 // FIXME: take care of background-color in effect | 1477 // FIXME: take care of background-color in effect |
| 1478 MutableStylePropertySet* mutableStyle = getPropertiesNotIn(style->style(), c omputedStyle); | 1478 MutableStylePropertySet* mutableStyle = getPropertiesNotIn(style->style(), c omputedStyle); |
| 1479 ASSERT(mutableStyle); | 1479 DCHECK(mutableStyle); |
| 1480 | 1480 |
| 1481 reconcileTextDecorationProperties(mutableStyle); | 1481 reconcileTextDecorationProperties(mutableStyle); |
| 1482 if (!document->frame()->editor().shouldStyleWithCSS()) | 1482 if (!document->frame()->editor().shouldStyleWithCSS()) |
| 1483 extractTextStyles(document, mutableStyle, computedStyle->isMonospaceFont ()); | 1483 extractTextStyles(document, mutableStyle, computedStyle->isMonospaceFont ()); |
| 1484 | 1484 |
| 1485 // Changing the whitespace style in a tab span would collapse the tab into a space. | 1485 // Changing the whitespace style in a tab span would collapse the tab into a space. |
| 1486 if (isTabHTMLSpanElementTextNode(position.anchorNode()) || isTabHTMLSpanElem ent((position.anchorNode()))) | 1486 if (isTabHTMLSpanElementTextNode(position.anchorNode()) || isTabHTMLSpanElem ent((position.anchorNode()))) |
| 1487 mutableStyle->removeProperty(CSSPropertyWhiteSpace); | 1487 mutableStyle->removeProperty(CSSPropertyWhiteSpace); |
| 1488 | 1488 |
| 1489 // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle. | 1489 // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1501 style->setProperty(propertyID, newTextDecoration->cssText(), style->prop ertyIsImportant(propertyID)); | 1501 style->setProperty(propertyID, newTextDecoration->cssText(), style->prop ertyIsImportant(propertyID)); |
| 1502 } else { | 1502 } else { |
| 1503 // text-decoration: none is redundant since it does not remove any text | 1503 // text-decoration: none is redundant since it does not remove any text |
| 1504 // decorations. | 1504 // decorations. |
| 1505 style->removeProperty(propertyID); | 1505 style->removeProperty(propertyID); |
| 1506 } | 1506 } |
| 1507 } | 1507 } |
| 1508 | 1508 |
| 1509 void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet* style, bool isMonospaceFont) | 1509 void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet* style, bool isMonospaceFont) |
| 1510 { | 1510 { |
| 1511 ASSERT(style); | 1511 DCHECK(style); |
| 1512 | 1512 |
| 1513 if (getIdentifierValue(style, CSSPropertyFontWeight) == CSSValueBold) { | 1513 if (getIdentifierValue(style, CSSPropertyFontWeight) == CSSValueBold) { |
| 1514 style->removeProperty(CSSPropertyFontWeight); | 1514 style->removeProperty(CSSPropertyFontWeight); |
| 1515 m_applyBold = true; | 1515 m_applyBold = true; |
| 1516 } | 1516 } |
| 1517 | 1517 |
| 1518 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); | 1518 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); |
| 1519 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { | 1519 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { |
| 1520 style->removeProperty(CSSPropertyFontStyle); | 1520 style->removeProperty(CSSPropertyFontStyle); |
| 1521 m_applyItalic = true; | 1521 m_applyItalic = true; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1617 { | 1617 { |
| 1618 if (!fontWeight->isPrimitiveValue()) | 1618 if (!fontWeight->isPrimitiveValue()) |
| 1619 return true; | 1619 return true; |
| 1620 | 1620 |
| 1621 CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID(); | 1621 CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID(); |
| 1622 return value == CSSValueLighter || value == CSSValueBolder; | 1622 return value == CSSValueLighter || value == CSSValueBolder; |
| 1623 } | 1623 } |
| 1624 | 1624 |
| 1625 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle) | 1625 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle) |
| 1626 { | 1626 { |
| 1627 ASSERT(styleWithRedundantProperties); | 1627 DCHECK(styleWithRedundantProperties); |
| 1628 ASSERT(baseStyle); | 1628 DCHECK(baseStyle); |
| 1629 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( ); | 1629 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( ); |
| 1630 | 1630 |
| 1631 result->removeEquivalentProperties(baseStyle); | 1631 result->removeEquivalentProperties(baseStyle); |
| 1632 | 1632 |
| 1633 CSSValue* baseTextDecorationsInEffect = baseStyle->getPropertyCSSValueIntern al(CSSPropertyWebkitTextDecorationsInEffect); | 1633 CSSValue* baseTextDecorationsInEffect = baseStyle->getPropertyCSSValueIntern al(CSSPropertyWebkitTextDecorationsInEffect); |
| 1634 diffTextDecorations(result, textDecorationPropertyForEditing(), baseTextDeco rationsInEffect); | 1634 diffTextDecorations(result, textDecorationPropertyForEditing(), baseTextDeco rationsInEffect); |
| 1635 diffTextDecorations(result, CSSPropertyWebkitTextDecorationsInEffect, baseTe xtDecorationsInEffect); | 1635 diffTextDecorations(result, CSSPropertyWebkitTextDecorationsInEffect, baseTe xtDecorationsInEffect); |
| 1636 | 1636 |
| 1637 if (CSSValue* baseFontWeight = baseStyle->getPropertyCSSValueInternal(CSSPro pertyFontWeight)) { | 1637 if (CSSValue* baseFontWeight = baseStyle->getPropertyCSSValueInternal(CSSPro pertyFontWeight)) { |
| 1638 if (CSSValue* fontWeight = result->getPropertyCSSValue(CSSPropertyFontWe ight)) { | 1638 if (CSSValue* fontWeight = result->getPropertyCSSValue(CSSPropertyFontWe ight)) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1724 { | 1724 { |
| 1725 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { | 1725 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { |
| 1726 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor); | 1726 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor); |
| 1727 if (!hasTransparentBackgroundColor(ancestorStyle)) | 1727 if (!hasTransparentBackgroundColor(ancestorStyle)) |
| 1728 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); | 1728 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); |
| 1729 } | 1729 } |
| 1730 return nullptr; | 1730 return nullptr; |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 } // namespace blink | 1733 } // namespace blink |
| OLD | NEW |