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

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

Issue 22438008: Replace static_cast with safe casting methods (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/custom/V8CSSValueCustom.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 bool HTMLTextDecorationEquivalent::propertyExistsInStyle(const StylePropertySet* style) const 212 bool HTMLTextDecorationEquivalent::propertyExistsInStyle(const StylePropertySet* style) const
213 { 213 {
214 return style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect) || style->getPropertyCSSValue(CSSPropertyTextDecoration); 214 return style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect) || style->getPropertyCSSValue(CSSPropertyTextDecoration);
215 } 215 }
216 216
217 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(Element* element, Style PropertySet* style) const 217 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(Element* element, Style PropertySet* style) const
218 { 218 {
219 RefPtr<CSSValue> styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTe xtDecorationsInEffect); 219 RefPtr<CSSValue> styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTe xtDecorationsInEffect);
220 if (!styleValue) 220 if (!styleValue)
221 styleValue = style->getPropertyCSSValue(CSSPropertyTextDecoration); 221 styleValue = style->getPropertyCSSValue(CSSPropertyTextDecoration);
222 return matches(element) && styleValue && styleValue->isValueList() && static _cast<CSSValueList*>(styleValue.get())->hasValue(m_primitiveValue.get()); 222 return matches(element) && styleValue && styleValue->isValueList() && toCSSV alueList(styleValue.get())->hasValue(m_primitiveValue.get());
223 } 223 }
224 224
225 class HTMLAttributeEquivalent : public HTMLElementEquivalent { 225 class HTMLAttributeEquivalent : public HTMLElementEquivalent {
226 public: 226 public:
227 static PassOwnPtr<HTMLAttributeEquivalent> create(CSSPropertyID propertyID, const QualifiedName& tagName, const QualifiedName& attrName) 227 static PassOwnPtr<HTMLAttributeEquivalent> create(CSSPropertyID propertyID, const QualifiedName& tagName, const QualifiedName& attrName)
228 { 228 {
229 return adoptPtr(new HTMLAttributeEquivalent(propertyID, tagName, attrNam e)); 229 return adoptPtr(new HTMLAttributeEquivalent(propertyID, tagName, attrNam e));
230 } 230 }
231 static PassOwnPtr<HTMLAttributeEquivalent> create(CSSPropertyID propertyID, const QualifiedName& attrName) 231 static PassOwnPtr<HTMLAttributeEquivalent> create(CSSPropertyID propertyID, const QualifiedName& attrName)
232 { 232 {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 360
361 EditingStyle::~EditingStyle() 361 EditingStyle::~EditingStyle()
362 { 362 {
363 } 363 }
364 364
365 static RGBA32 cssValueToRGBA(CSSValue* colorValue) 365 static RGBA32 cssValueToRGBA(CSSValue* colorValue)
366 { 366 {
367 if (!colorValue || !colorValue->isPrimitiveValue()) 367 if (!colorValue || !colorValue->isPrimitiveValue())
368 return Color::transparent; 368 return Color::transparent;
369 369
370 CSSPrimitiveValue* primitiveColor = static_cast<CSSPrimitiveValue*>(colorVal ue); 370 CSSPrimitiveValue* primitiveColor = toCSSPrimitiveValue(colorValue);
371 if (primitiveColor->isRGBColor()) 371 if (primitiveColor->isRGBColor())
372 return primitiveColor->getRGBA32Value(); 372 return primitiveColor->getRGBA32Value();
373 373
374 RGBA32 rgba = 0; 374 RGBA32 rgba = 0;
375 CSSParser::parseColor(rgba, colorValue->cssText()); 375 CSSParser::parseColor(rgba, colorValue->cssText());
376 return rgba; 376 return rgba;
377 } 377 }
378 378
379 static inline RGBA32 getRGBAFontColor(CSSStyleDeclaration* style) 379 static inline RGBA32 getRGBAFontColor(CSSStyleDeclaration* style)
380 { 380 {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 // Explicit font size overrides any delta. 491 // Explicit font size overrides any delta.
492 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 492 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
493 return; 493 return;
494 } 494 }
495 495
496 // Get the adjustment amount out of the style. 496 // Get the adjustment amount out of the style.
497 RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebk itFontSizeDelta); 497 RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebk itFontSizeDelta);
498 if (!value || !value->isPrimitiveValue()) 498 if (!value || !value->isPrimitiveValue())
499 return; 499 return;
500 500
501 CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value.ge t()); 501 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get());
502 502
503 // Only PX handled now. If we handle more types in the future, perhaps 503 // Only PX handled now. If we handle more types in the future, perhaps
504 // a switch statement here would be more appropriate. 504 // a switch statement here would be more appropriate.
505 if (!primitiveValue->isPx()) 505 if (!primitiveValue->isPx())
506 return; 506 return;
507 507
508 m_fontSizeDelta = primitiveValue->getFloatValue(); 508 m_fontSizeDelta = primitiveValue->getFloatValue();
509 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 509 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
510 } 510 }
511 511
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 } 1078 }
1079 1079
1080 unsigned propertyCount = style->propertyCount(); 1080 unsigned propertyCount = style->propertyCount();
1081 for (unsigned i = 0; i < propertyCount; ++i) { 1081 for (unsigned i = 0; i < propertyCount; ++i) {
1082 StylePropertySet::PropertyReference property = style->propertyAt(i); 1082 StylePropertySet::PropertyReference property = style->propertyAt(i);
1083 RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(property.id ()); 1083 RefPtr<CSSValue> value = m_mutableStyle->getPropertyCSSValue(property.id ());
1084 1084
1085 // text decorations never override values 1085 // text decorations never override values
1086 if ((property.id() == CSSPropertyTextDecoration || property.id() == CSSP ropertyWebkitTextDecorationsInEffect) && property.value()->isValueList() && valu e) { 1086 if ((property.id() == CSSPropertyTextDecoration || property.id() == CSSP ropertyWebkitTextDecorationsInEffect) && property.value()->isValueList() && valu e) {
1087 if (value->isValueList()) { 1087 if (value->isValueList()) {
1088 mergeTextDecorationValues(static_cast<CSSValueList*>(value.get() ), static_cast<CSSValueList*>(property.value())); 1088 mergeTextDecorationValues(toCSSValueList(value.get()), toCSSValu eList(property.value()));
1089 continue; 1089 continue;
1090 } 1090 }
1091 value = 0; // text-decoration: none is equivalent to not having the property 1091 value = 0; // text-decoration: none is equivalent to not having the property
1092 } 1092 }
1093 1093
1094 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value)) 1094 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value))
1095 m_mutableStyle->setProperty(property.id(), property.value()->cssText (), property.isImportant()); 1095 m_mutableStyle->setProperty(property.id(), property.value()->cssText (), property.isImportant());
1096 } 1096 }
1097 } 1097 }
1098 1098
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot copy/paste fidelity problem 1132 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot copy/paste fidelity problem
1133 RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = CSSComputedSty leDeclaration::create(element); 1133 RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = CSSComputedSty leDeclaration::create(element);
1134 RefPtr<MutableStylePropertySet> fromComputedStyle = MutableStylePropertySet: :create(); 1134 RefPtr<MutableStylePropertySet> fromComputedStyle = MutableStylePropertySet: :create();
1135 { 1135 {
1136 unsigned propertyCount = m_mutableStyle->propertyCount(); 1136 unsigned propertyCount = m_mutableStyle->propertyCount();
1137 for (unsigned i = 0; i < propertyCount; ++i) { 1137 for (unsigned i = 0; i < propertyCount; ++i) {
1138 StylePropertySet::PropertyReference property = m_mutableStyle->prope rtyAt(i); 1138 StylePropertySet::PropertyReference property = m_mutableStyle->prope rtyAt(i);
1139 CSSValue* value = property.value(); 1139 CSSValue* value = property.value();
1140 if (!value->isPrimitiveValue()) 1140 if (!value->isPrimitiveValue())
1141 continue; 1141 continue;
1142 if (static_cast<CSSPrimitiveValue*>(value)->isPercentage()) { 1142 if (toCSSPrimitiveValue(value)->isPercentage()) {
1143 if (RefPtr<CSSValue> computedPropertyValue = computedStyleForEle ment->getPropertyCSSValue(property.id())) 1143 if (RefPtr<CSSValue> computedPropertyValue = computedStyleForEle ment->getPropertyCSSValue(property.id()))
1144 fromComputedStyle->addParsedProperty(CSSProperty(property.id (), computedPropertyValue)); 1144 fromComputedStyle->addParsedProperty(CSSProperty(property.id (), computedPropertyValue));
1145 } 1145 }
1146 } 1146 }
1147 } 1147 }
1148 m_mutableStyle->mergeAndOverrideOnConflict(fromComputedStyle.get()); 1148 m_mutableStyle->mergeAndOverrideOnConflict(fromComputedStyle.get());
1149 } 1149 }
1150 1150
1151 static void removePropertiesInStyle(MutableStylePropertySet* styleToRemoveProper tiesFrom, StylePropertySet* style) 1151 static void removePropertiesInStyle(MutableStylePropertySet* styleToRemoveProper tiesFrom, StylePropertySet* style)
1152 { 1152 {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 m_mutableStyle = MutableStylePropertySet::create(); 1205 m_mutableStyle = MutableStylePropertySet::create();
1206 const bool propertyIsImportant = true; 1206 const bool propertyIsImportant = true;
1207 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant); 1207 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant);
1208 } 1208 }
1209 1209
1210 int EditingStyle::legacyFontSize(Document* document) const 1210 int EditingStyle::legacyFontSize(Document* document) const
1211 { 1211 {
1212 RefPtr<CSSValue> cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyF ontSize); 1212 RefPtr<CSSValue> cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyF ontSize);
1213 if (!cssValue || !cssValue->isPrimitiveValue()) 1213 if (!cssValue || !cssValue->isPrimitiveValue())
1214 return 0; 1214 return 0;
1215 return legacyFontSizeFromCSSValue(document, static_cast<CSSPrimitiveValue*>( cssValue.get()), 1215 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue.get ()),
1216 m_shouldUseFixedDefaultFontSize, AlwaysUseLegacyFontSize); 1216 m_shouldUseFixedDefaultFontSize, AlwaysUseLegacyFontSize);
1217 } 1217 }
1218 1218
1219 PassRefPtr<EditingStyle> EditingStyle::styleAtSelectionStart(const VisibleSelect ion& selection, bool shouldUseBackgroundColorInEffect) 1219 PassRefPtr<EditingStyle> EditingStyle::styleAtSelectionStart(const VisibleSelect ion& selection, bool shouldUseBackgroundColorInEffect)
1220 { 1220 {
1221 if (selection.isNone()) 1221 if (selection.isNone())
1222 return 0; 1222 return 0;
1223 1223
1224 Position position = adjustedSelectionStartForStyleComputation(selection); 1224 Position position = adjustedSelectionStartForStyleComputation(selection);
1225 1225
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 m_applyItalic = true; 1411 m_applyItalic = true;
1412 } 1412 }
1413 1413
1414 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect 1414 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect
1415 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList. 1415 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList.
1416 RefPtr<CSSValue> textDecoration = style->getPropertyCSSValue(CSSPropertyText Decoration); 1416 RefPtr<CSSValue> textDecoration = style->getPropertyCSSValue(CSSPropertyText Decoration);
1417 if (textDecoration && textDecoration->isValueList()) { 1417 if (textDecoration && textDecoration->isValueList()) {
1418 DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, underline, (CSSPrimitiveV alue::createIdentifier(CSSValueUnderline))); 1418 DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, underline, (CSSPrimitiveV alue::createIdentifier(CSSValueUnderline)));
1419 DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, lineThrough, (CSSPrimitiv eValue::createIdentifier(CSSValueLineThrough))); 1419 DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, lineThrough, (CSSPrimitiv eValue::createIdentifier(CSSValueLineThrough)));
1420 1420
1421 RefPtr<CSSValueList> newTextDecoration = static_cast<CSSValueList*>(text Decoration.get())->copy(); 1421 RefPtr<CSSValueList> newTextDecoration = toCSSValueList(textDecoration.g et())->copy();
1422 if (newTextDecoration->removeAll(underline.get())) 1422 if (newTextDecoration->removeAll(underline.get()))
1423 m_applyUnderline = true; 1423 m_applyUnderline = true;
1424 if (newTextDecoration->removeAll(lineThrough.get())) 1424 if (newTextDecoration->removeAll(lineThrough.get()))
1425 m_applyLineThrough = true; 1425 m_applyLineThrough = true;
1426 1426
1427 // If trimTextDecorations, delete underline and line-through 1427 // If trimTextDecorations, delete underline and line-through
1428 setTextDecorationProperty(style, newTextDecoration.get(), CSSPropertyTex tDecoration); 1428 setTextDecorationProperty(style, newTextDecoration.get(), CSSPropertyTex tDecoration);
1429 } 1429 }
1430 1430
1431 int verticalAlign = getIdentifierValue(style, CSSPropertyVerticalAlign); 1431 int verticalAlign = getIdentifierValue(style, CSSPropertyVerticalAlign);
(...skipping 14 matching lines...) Expand all
1446 } 1446 }
1447 1447
1448 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); 1448 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily);
1449 // Remove single quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448 1449 // Remove single quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448
1450 m_applyFontFace.replaceWithLiteral('\'', ""); 1450 m_applyFontFace.replaceWithLiteral('\'', "");
1451 style->removeProperty(CSSPropertyFontFamily); 1451 style->removeProperty(CSSPropertyFontFamily);
1452 1452
1453 if (RefPtr<CSSValue> fontSize = style->getPropertyCSSValue(CSSPropertyFontSi ze)) { 1453 if (RefPtr<CSSValue> fontSize = style->getPropertyCSSValue(CSSPropertyFontSi ze)) {
1454 if (!fontSize->isPrimitiveValue()) 1454 if (!fontSize->isPrimitiveValue())
1455 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size. 1455 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size.
1456 else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, stati c_cast<CSSPrimitiveValue*>(fontSize.get()), 1456 else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toCSS PrimitiveValue(fontSize.get()),
1457 shouldUseFixedFontDefaultSize, UseLegacyFontSizeOnlyIfPixelValue sMatch)) { 1457 shouldUseFixedFontDefaultSize, UseLegacyFontSizeOnlyIfPixelValue sMatch)) {
1458 m_applyFontSize = String::number(legacyFontSize); 1458 m_applyFontSize = String::number(legacyFontSize);
1459 style->removeProperty(CSSPropertyFontSize); 1459 style->removeProperty(CSSPropertyFontSize);
1460 } 1460 }
1461 } 1461 }
1462 } 1462 }
1463 1463
1464 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertID, CSSValue* refTextDecoration) 1464 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertID, CSSValue* refTextDecoration)
1465 { 1465 {
1466 RefPtr<CSSValue> textDecoration = style->getPropertyCSSValue(propertID); 1466 RefPtr<CSSValue> textDecoration = style->getPropertyCSSValue(propertID);
1467 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList()) 1467 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList())
1468 return; 1468 return;
1469 1469
1470 RefPtr<CSSValueList> newTextDecoration = static_cast<CSSValueList*>(textDeco ration.get())->copy(); 1470 RefPtr<CSSValueList> newTextDecoration = toCSSValueList(textDecoration.get() )->copy();
1471 CSSValueList* valuesInRefTextDecoration = static_cast<CSSValueList*>(refText Decoration); 1471 CSSValueList* valuesInRefTextDecoration = toCSSValueList(refTextDecoration);
1472 1472
1473 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++) 1473 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++)
1474 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i)); 1474 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i));
1475 1475
1476 setTextDecorationProperty(style, newTextDecoration.get(), propertID); 1476 setTextDecorationProperty(style, newTextDecoration.get(), propertID);
1477 } 1477 }
1478 1478
1479 static bool fontWeightIsBold(CSSValue* fontWeight) 1479 static bool fontWeightIsBold(CSSValue* fontWeight)
1480 { 1480 {
1481 if (!fontWeight) 1481 if (!fontWeight)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 { 1621 {
1622 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1622 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1623 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor); 1623 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor);
1624 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1624 if (!hasTransparentBackgroundColor(ancestorStyle.get()))
1625 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1625 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1626 } 1626 }
1627 return 0; 1627 return 0;
1628 } 1628 }
1629 1629
1630 } 1630 }
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8CSSValueCustom.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698