Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: third_party/WebKit/Source/core/editing/EditingStyle.cpp

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Output info for some DCHECKs, add TODOs. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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
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
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 if (extractedStyle)
904 DCHECK_EQ(shouldPreserveWritingDirection, PreserveWritingDirection);
904 if (!m_mutableStyle) 905 if (!m_mutableStyle)
905 return false; 906 return false;
906 907
907 const HeapVector<Member<HTMLAttributeEquivalent>>& HTMLAttributeEquivalents = htmlAttributeEquivalents(); 908 const HeapVector<Member<HTMLAttributeEquivalent>>& HTMLAttributeEquivalents = htmlAttributeEquivalents();
908 bool removed = false; 909 bool removed = false;
909 for (const auto& attribute : HTMLAttributeEquivalents) { 910 for (const auto& attribute : HTMLAttributeEquivalents) {
910 const HTMLAttributeEquivalent* equivalent = attribute.get(); 911 const HTMLAttributeEquivalent* equivalent = attribute.get();
911 912
912 // unicode-bidi and direction are pushed down separately so don't push d own with other styles. 913 // 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) 914 if (shouldPreserveWritingDirection == PreserveWritingDirection && equiva lent->attributeName() == HTMLNames::dirAttr)
(...skipping 12 matching lines...) Expand all
926 return removed; 927 return removed;
927 } 928 }
928 929
929 bool EditingStyle::styleIsPresentInComputedStyleOfNode(Node* node) const 930 bool EditingStyle::styleIsPresentInComputedStyleOfNode(Node* node) const
930 { 931 {
931 return !m_mutableStyle || getPropertiesNotIn(m_mutableStyle.get(), CSSComput edStyleDeclaration::create(node))->isEmpty(); 932 return !m_mutableStyle || getPropertiesNotIn(m_mutableStyle.get(), CSSComput edStyleDeclaration::create(node))->isEmpty();
932 } 933 }
933 934
934 bool EditingStyle::elementIsStyledSpanOrHTMLEquivalent(const HTMLElement* elemen t) 935 bool EditingStyle::elementIsStyledSpanOrHTMLEquivalent(const HTMLElement* elemen t)
935 { 936 {
936 ASSERT(element); 937 DCHECK(element);
937 bool elementIsSpanOrElementEquivalent = false; 938 bool elementIsSpanOrElementEquivalent = false;
938 if (isHTMLSpanElement(*element)) { 939 if (isHTMLSpanElement(*element)) {
939 elementIsSpanOrElementEquivalent = true; 940 elementIsSpanOrElementEquivalent = true;
940 } else { 941 } else {
941 const HeapVector<Member<HTMLElementEquivalent>>& HTMLElementEquivalents = htmlElementEquivalents(); 942 const HeapVector<Member<HTMLElementEquivalent>>& HTMLElementEquivalents = htmlElementEquivalents();
942 size_t i; 943 size_t i;
943 for (i = 0; i < HTMLElementEquivalents.size(); ++i) { 944 for (i = 0; i < HTMLElementEquivalents.size(); ++i) {
944 if (HTMLElementEquivalents[i]->matches(element)) { 945 if (HTMLElementEquivalents[i]->matches(element)) {
945 elementIsSpanOrElementEquivalent = true; 946 elementIsSpanOrElementEquivalent = true;
946 break; 947 break;
(...skipping 23 matching lines...) Expand all
970 unsigned propertyCount = style->propertyCount(); 971 unsigned propertyCount = style->propertyCount();
971 for (unsigned i = 0; i < propertyCount; ++i) { 972 for (unsigned i = 0; i < propertyCount; ++i) {
972 if (!isEditingProperty(style->propertyAt(i).id())) 973 if (!isEditingProperty(style->propertyAt(i).id()))
973 return false; 974 return false;
974 } 975 }
975 } 976 }
976 matchedAttributes++; 977 matchedAttributes++;
977 } 978 }
978 979
979 // font with color attribute, span with style attribute, etc... 980 // font with color attribute, span with style attribute, etc...
980 ASSERT(matchedAttributes <= attributes.size()); 981 DCHECK_LE(matchedAttributes, attributes.size());
981 return matchedAttributes >= attributes.size(); 982 return matchedAttributes >= attributes.size();
982 } 983 }
983 984
984 void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit ingDirection shouldPreserveWritingDirection) 985 void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWrit ingDirection shouldPreserveWritingDirection)
985 { 986 {
986 if (!m_mutableStyle) 987 if (!m_mutableStyle)
987 return; 988 return;
988 989
989 // ReplaceSelectionCommand::handleStyleSpans() requires that this function o nly removes the editing style. 990 // 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 991 // 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
1013 1014
1014 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) { 1015 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) {
1015 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue( unicodeBidi)->getValueID()); 1016 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue( unicodeBidi)->getValueID());
1016 if (direction && direction->isPrimitiveValue()) 1017 if (direction && direction->isPrimitiveValue())
1017 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValu e(direction)->getValueID()); 1018 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValu e(direction)->getValueID());
1018 } 1019 }
1019 } 1020 }
1020 1021
1021 void EditingStyle::mergeTypingStyle(Document* document) 1022 void EditingStyle::mergeTypingStyle(Document* document)
1022 { 1023 {
1023 ASSERT(document); 1024 DCHECK(document);
1024 1025
1025 EditingStyle* typingStyle = document->frame()->selection().typingStyle(); 1026 EditingStyle* typingStyle = document->frame()->selection().typingStyle();
1026 if (!typingStyle || typingStyle == this) 1027 if (!typingStyle || typingStyle == this)
1027 return; 1028 return;
1028 1029
1029 mergeStyle(typingStyle->style(), OverrideValues); 1030 mergeStyle(typingStyle->style(), OverrideValues);
1030 } 1031 }
1031 1032
1032 void EditingStyle::mergeInlineStyleOfElement(HTMLElement* element, CSSPropertyOv errideMode mode, PropertiesToInclude propertiesToInclude) 1033 void EditingStyle::mergeInlineStyleOfElement(HTMLElement* element, CSSPropertyOv errideMode mode, PropertiesToInclude propertiesToInclude)
1033 { 1034 {
1034 ASSERT(element); 1035 DCHECK(element);
1035 if (!element->inlineStyle()) 1036 if (!element->inlineStyle())
1036 return; 1037 return;
1037 1038
1038 switch (propertiesToInclude) { 1039 switch (propertiesToInclude) {
1039 case AllProperties: 1040 case AllProperties:
1040 mergeStyle(element->inlineStyle(), mode); 1041 mergeStyle(element->inlineStyle(), mode);
1041 return; 1042 return;
1042 case OnlyEditingInheritableProperties: 1043 case OnlyEditingInheritableProperties:
1043 mergeStyle(copyEditingProperties(element->inlineStyle(), OnlyInheritable EditingProperties), mode); 1044 mergeStyle(copyEditingProperties(element->inlineStyle(), OnlyInheritable EditingProperties), mode);
1044 return; 1045 return;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 unsigned propertyCount = style->propertyCount(); 1224 unsigned propertyCount = style->propertyCount();
1224 Vector<CSSPropertyID> propertiesToRemove(propertyCount); 1225 Vector<CSSPropertyID> propertiesToRemove(propertyCount);
1225 for (unsigned i = 0; i < propertyCount; ++i) 1226 for (unsigned i = 0; i < propertyCount; ++i)
1226 propertiesToRemove[i] = style->propertyAt(i).id(); 1227 propertiesToRemove[i] = style->propertyAt(i).id();
1227 1228
1228 styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data() , propertiesToRemove.size()); 1229 styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data() , propertiesToRemove.size());
1229 } 1230 }
1230 1231
1231 void EditingStyle::removeStyleFromRulesAndContext(Element* element, ContainerNod e* context) 1232 void EditingStyle::removeStyleFromRulesAndContext(Element* element, ContainerNod e* context)
1232 { 1233 {
1233 ASSERT(element); 1234 DCHECK(element);
1234 if (!m_mutableStyle) 1235 if (!m_mutableStyle)
1235 return; 1236 return;
1236 1237
1237 // 1. Remove style from matched rules because style remain without repeating it in inline style declaration 1238 // 1. Remove style from matched rules because style remain without repeating it in inline style declaration
1238 MutableStylePropertySet* styleFromMatchedRules = styleFromMatchedRulesForEle ment(element, StyleResolver::AllButEmptyCSSRules); 1239 MutableStylePropertySet* styleFromMatchedRules = styleFromMatchedRulesForEle ment(element, StyleResolver::AllButEmptyCSSRules);
1239 if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) 1240 if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty())
1240 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatch edRules->ensureCSSStyleDeclaration()); 1241 m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatch edRules->ensureCSSStyleDeclaration());
1241 1242
1242 // 2. Remove style present in context and not overriden by matched rules. 1243 // 2. Remove style present in context and not overriden by matched rules.
1243 EditingStyle* computedStyle = EditingStyle::create(context, EditingPropertie sInEffect); 1244 EditingStyle* computedStyle = EditingStyle::create(context, EditingPropertie sInEffect);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 Position position = mostForwardCaretPosition(selection.start()); 1363 Position position = mostForwardCaretPosition(selection.start());
1363 1364
1364 Node* node = position.anchorNode(); 1365 Node* node = position.anchorNode();
1365 if (!node) 1366 if (!node)
1366 return NaturalWritingDirection; 1367 return NaturalWritingDirection;
1367 1368
1368 Position end; 1369 Position end;
1369 if (selection.isRange()) { 1370 if (selection.isRange()) {
1370 end = mostBackwardCaretPosition(selection.end()); 1371 end = mostBackwardCaretPosition(selection.end());
1371 1372
1372 ASSERT(end.document()); 1373 DCHECK(end.document());
1373 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); 1374 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode();
1374 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { 1375 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) {
1375 if (!n->isStyledElement()) 1376 if (!n->isStyledElement())
1376 continue; 1377 continue;
1377 1378
1378 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(n); 1379 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(n);
1379 CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicod eBidi); 1380 CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicod eBidi);
1380 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1381 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
1381 continue; 1382 continue;
1382 1383
(...skipping 27 matching lines...) Expand all
1410 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1411 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
1411 continue; 1412 continue;
1412 1413
1413 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID(); 1414 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID();
1414 if (unicodeBidiValue == CSSValueNormal) 1415 if (unicodeBidiValue == CSSValueNormal)
1415 continue; 1416 continue;
1416 1417
1417 if (unicodeBidiValue == CSSValueBidiOverride) 1418 if (unicodeBidiValue == CSSValueBidiOverride)
1418 return NaturalWritingDirection; 1419 return NaturalWritingDirection;
1419 1420
1420 ASSERT(isEmbedOrIsolate(unicodeBidiValue)); 1421 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue;
1421 CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirection); 1422 CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirection);
1422 if (!direction || !direction->isPrimitiveValue()) 1423 if (!direction || !direction->isPrimitiveValue())
1423 continue; 1424 continue;
1424 1425
1425 int directionValue = toCSSPrimitiveValue(direction)->getValueID(); 1426 int directionValue = toCSSPrimitiveValue(direction)->getValueID();
1426 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) 1427 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
1427 continue; 1428 continue;
1428 1429
1429 if (foundDirection != NaturalWritingDirection) 1430 if (foundDirection != NaturalWritingDirection)
1430 return NaturalWritingDirection; 1431 return NaturalWritingDirection;
(...skipping 11 matching lines...) Expand all
1442 DEFINE_TRACE(EditingStyle) 1443 DEFINE_TRACE(EditingStyle)
1443 { 1444 {
1444 visitor->trace(m_mutableStyle); 1445 visitor->trace(m_mutableStyle);
1445 } 1446 }
1446 1447
1447 static void reconcileTextDecorationProperties(MutableStylePropertySet* style) 1448 static void reconcileTextDecorationProperties(MutableStylePropertySet* style)
1448 { 1449 {
1449 CSSValue* textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWe bkitTextDecorationsInEffect); 1450 CSSValue* textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWe bkitTextDecorationsInEffect);
1450 CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationProperty ForEditing()); 1451 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. 1452 // We shouldn't have both text-decoration and -webkit-text-decorations-in-ef fect because that wouldn't make sense.
1452 ASSERT(!textDecorationsInEffect || !textDecoration); 1453 DCHECK(!textDecorationsInEffect || !textDecoration);
1453 if (textDecorationsInEffect) { 1454 if (textDecorationsInEffect) {
1454 style->setProperty(textDecorationPropertyForEditing(), textDecorationsIn Effect->cssText()); 1455 style->setProperty(textDecorationPropertyForEditing(), textDecorationsIn Effect->cssText());
1455 style->removeProperty(CSSPropertyWebkitTextDecorationsInEffect); 1456 style->removeProperty(CSSPropertyWebkitTextDecorationsInEffect);
1456 textDecoration = textDecorationsInEffect; 1457 textDecoration = textDecorationsInEffect;
1457 } 1458 }
1458 1459
1459 // If text-decoration is set to "none", remove the property because we don't want to add redundant "text-decoration: none". 1460 // 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()) 1461 if (textDecoration && !textDecoration->isValueList())
1461 style->removeProperty(textDecorationPropertyForEditing()); 1462 style->removeProperty(textDecorationPropertyForEditing());
1462 } 1463 }
1463 1464
1464 StyleChange::StyleChange(EditingStyle* style, const Position& position) 1465 StyleChange::StyleChange(EditingStyle* style, const Position& position)
1465 : m_applyBold(false) 1466 : m_applyBold(false)
1466 , m_applyItalic(false) 1467 , m_applyItalic(false)
1467 , m_applyUnderline(false) 1468 , m_applyUnderline(false)
1468 , m_applyLineThrough(false) 1469 , m_applyLineThrough(false)
1469 , m_applySubscript(false) 1470 , m_applySubscript(false)
1470 , m_applySuperscript(false) 1471 , m_applySuperscript(false)
1471 { 1472 {
1472 Document* document = position.document(); 1473 Document* document = position.document();
1473 if (!style || !style->style() || !document || !document->frame() || !associa tedElementOf(position)) 1474 if (!style || !style->style() || !document || !document->frame() || !associa tedElementOf(position))
1474 return; 1475 return;
1475 1476
1476 CSSComputedStyleDeclaration* computedStyle = ensureComputedStyle(position); 1477 CSSComputedStyleDeclaration* computedStyle = ensureComputedStyle(position);
1477 // FIXME: take care of background-color in effect 1478 // FIXME: take care of background-color in effect
1478 MutableStylePropertySet* mutableStyle = getPropertiesNotIn(style->style(), c omputedStyle); 1479 MutableStylePropertySet* mutableStyle = getPropertiesNotIn(style->style(), c omputedStyle);
1479 ASSERT(mutableStyle); 1480 DCHECK(mutableStyle);
1480 1481
1481 reconcileTextDecorationProperties(mutableStyle); 1482 reconcileTextDecorationProperties(mutableStyle);
1482 if (!document->frame()->editor().shouldStyleWithCSS()) 1483 if (!document->frame()->editor().shouldStyleWithCSS())
1483 extractTextStyles(document, mutableStyle, computedStyle->isMonospaceFont ()); 1484 extractTextStyles(document, mutableStyle, computedStyle->isMonospaceFont ());
1484 1485
1485 // Changing the whitespace style in a tab span would collapse the tab into a space. 1486 // Changing the whitespace style in a tab span would collapse the tab into a space.
1486 if (isTabHTMLSpanElementTextNode(position.anchorNode()) || isTabHTMLSpanElem ent((position.anchorNode()))) 1487 if (isTabHTMLSpanElementTextNode(position.anchorNode()) || isTabHTMLSpanElem ent((position.anchorNode())))
1487 mutableStyle->removeProperty(CSSPropertyWhiteSpace); 1488 mutableStyle->removeProperty(CSSPropertyWhiteSpace);
1488 1489
1489 // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle. 1490 // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle.
(...skipping 11 matching lines...) Expand all
1501 style->setProperty(propertyID, newTextDecoration->cssText(), style->prop ertyIsImportant(propertyID)); 1502 style->setProperty(propertyID, newTextDecoration->cssText(), style->prop ertyIsImportant(propertyID));
1502 } else { 1503 } else {
1503 // text-decoration: none is redundant since it does not remove any text 1504 // text-decoration: none is redundant since it does not remove any text
1504 // decorations. 1505 // decorations.
1505 style->removeProperty(propertyID); 1506 style->removeProperty(propertyID);
1506 } 1507 }
1507 } 1508 }
1508 1509
1509 void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet* style, bool isMonospaceFont) 1510 void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet* style, bool isMonospaceFont)
1510 { 1511 {
1511 ASSERT(style); 1512 DCHECK(style);
1512 1513
1513 if (getIdentifierValue(style, CSSPropertyFontWeight) == CSSValueBold) { 1514 if (getIdentifierValue(style, CSSPropertyFontWeight) == CSSValueBold) {
1514 style->removeProperty(CSSPropertyFontWeight); 1515 style->removeProperty(CSSPropertyFontWeight);
1515 m_applyBold = true; 1516 m_applyBold = true;
1516 } 1517 }
1517 1518
1518 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); 1519 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle);
1519 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { 1520 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) {
1520 style->removeProperty(CSSPropertyFontStyle); 1521 style->removeProperty(CSSPropertyFontStyle);
1521 m_applyItalic = true; 1522 m_applyItalic = true;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 { 1618 {
1618 if (!fontWeight->isPrimitiveValue()) 1619 if (!fontWeight->isPrimitiveValue())
1619 return true; 1620 return true;
1620 1621
1621 CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID(); 1622 CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID();
1622 return value == CSSValueLighter || value == CSSValueBolder; 1623 return value == CSSValueLighter || value == CSSValueBolder;
1623 } 1624 }
1624 1625
1625 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle) 1626 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle)
1626 { 1627 {
1627 ASSERT(styleWithRedundantProperties); 1628 DCHECK(styleWithRedundantProperties);
1628 ASSERT(baseStyle); 1629 DCHECK(baseStyle);
1629 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( ); 1630 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( );
1630 1631
1631 result->removeEquivalentProperties(baseStyle); 1632 result->removeEquivalentProperties(baseStyle);
1632 1633
1633 CSSValue* baseTextDecorationsInEffect = baseStyle->getPropertyCSSValueIntern al(CSSPropertyWebkitTextDecorationsInEffect); 1634 CSSValue* baseTextDecorationsInEffect = baseStyle->getPropertyCSSValueIntern al(CSSPropertyWebkitTextDecorationsInEffect);
1634 diffTextDecorations(result, textDecorationPropertyForEditing(), baseTextDeco rationsInEffect); 1635 diffTextDecorations(result, textDecorationPropertyForEditing(), baseTextDeco rationsInEffect);
1635 diffTextDecorations(result, CSSPropertyWebkitTextDecorationsInEffect, baseTe xtDecorationsInEffect); 1636 diffTextDecorations(result, CSSPropertyWebkitTextDecorationsInEffect, baseTe xtDecorationsInEffect);
1636 1637
1637 if (CSSValue* baseFontWeight = baseStyle->getPropertyCSSValueInternal(CSSPro pertyFontWeight)) { 1638 if (CSSValue* baseFontWeight = baseStyle->getPropertyCSSValueInternal(CSSPro pertyFontWeight)) {
1638 if (CSSValue* fontWeight = result->getPropertyCSSValue(CSSPropertyFontWe ight)) { 1639 if (CSSValue* fontWeight = result->getPropertyCSSValue(CSSPropertyFontWe ight)) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 { 1725 {
1725 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1726 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1726 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor); 1727 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor);
1727 if (!hasTransparentBackgroundColor(ancestorStyle)) 1728 if (!hasTransparentBackgroundColor(ancestorStyle))
1728 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1729 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1729 } 1730 }
1730 return nullptr; 1731 return nullptr;
1731 } 1732 }
1732 1733
1733 } // namespace blink 1734 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698