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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 | 136 |
| 137 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie sType type = OnlyInheritableEditingProperties) | 137 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie sType type = OnlyInheritableEditingProperties) |
| 138 { | 138 { |
| 139 if (!style) | 139 if (!style) |
| 140 return MutableStylePropertySet::create(); | 140 return MutableStylePropertySet::create(); |
| 141 return copyEditingProperties(style.get(), type); | 141 return copyEditingProperties(style.get(), type); |
| 142 } | 142 } |
| 143 | 143 |
| 144 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle); | 144 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle); |
| 145 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch }; | 145 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch }; |
| 146 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool should UseFixedFontDefaultSize, LegacyFontSizeMode); | 146 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, FixedPitchF ontType, LegacyFontSizeMode); |
| 147 static bool isTransparentColorValue(CSSValue*); | 147 static bool isTransparentColorValue(CSSValue*); |
| 148 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); | 148 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); |
| 149 static bool hasTransparentBackgroundColor(StylePropertySet*); | 149 static bool hasTransparentBackgroundColor(StylePropertySet*); |
| 150 static PassRefPtrWillBeRawPtr<CSSValue> backgroundColorInEffect(Node*); | 150 static PassRefPtrWillBeRawPtr<CSSValue> backgroundColorInEffect(Node*); |
| 151 | 151 |
| 152 class HTMLElementEquivalent : public NoBaseWillBeGarbageCollected<HTMLElementEqu ivalent> { | 152 class HTMLElementEquivalent : public NoBaseWillBeGarbageCollected<HTMLElementEqu ivalent> { |
| 153 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; | 153 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
| 154 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent); | 154 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent); |
| 155 public: | 155 public: |
| 156 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID pr opertyID, CSSValueID primitiveValue, const QualifiedName& tagName) | 156 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID pr opertyID, CSSValueID primitiveValue, const QualifiedName& tagName) |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 return nullptr; | 335 return nullptr; |
| 336 CSSValueID size; | 336 CSSValueID size; |
| 337 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) | 337 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) |
| 338 return nullptr; | 338 return nullptr; |
| 339 return CSSPrimitiveValue::createIdentifier(size); | 339 return CSSPrimitiveValue::createIdentifier(size); |
| 340 } | 340 } |
| 341 | 341 |
| 342 float EditingStyle::NoFontDelta = 0.0f; | 342 float EditingStyle::NoFontDelta = 0.0f; |
| 343 | 343 |
| 344 EditingStyle::EditingStyle() | 344 EditingStyle::EditingStyle() |
| 345 : m_shouldUseFixedDefaultFontSize(false) | 345 : m_shouldUseFixedDefaultFontSize(NonFixedPitchFont) |
| 346 , m_fontSizeDelta(NoFontDelta) | 346 , m_fontSizeDelta(NoFontDelta) |
| 347 { | 347 { |
| 348 } | 348 } |
| 349 | 349 |
| 350 EditingStyle::EditingStyle(Node* node, PropertiesToInclude propertiesToInclude) | 350 EditingStyle::EditingStyle(Node* node, PropertiesToInclude propertiesToInclude) |
| 351 : m_shouldUseFixedDefaultFontSize(false) | 351 : m_shouldUseFixedDefaultFontSize(NonFixedPitchFont) |
| 352 , m_fontSizeDelta(NoFontDelta) | 352 , m_fontSizeDelta(NoFontDelta) |
| 353 { | 353 { |
| 354 init(node, propertiesToInclude); | 354 init(node, propertiesToInclude); |
| 355 } | 355 } |
| 356 | 356 |
| 357 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude) | 357 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude) |
| 358 : m_shouldUseFixedDefaultFontSize(false) | 358 : m_shouldUseFixedDefaultFontSize(NonFixedPitchFont) |
| 359 , m_fontSizeDelta(NoFontDelta) | 359 , m_fontSizeDelta(NoFontDelta) |
| 360 { | 360 { |
| 361 init(position.deprecatedNode(), propertiesToInclude); | 361 init(position.deprecatedNode(), propertiesToInclude); |
| 362 } | 362 } |
| 363 | 363 |
| 364 EditingStyle::EditingStyle(const StylePropertySet* style) | 364 EditingStyle::EditingStyle(const StylePropertySet* style) |
| 365 : m_mutableStyle(style ? style->mutableCopy() : nullptr) | 365 : m_mutableStyle(style ? style->mutableCopy() : nullptr) |
| 366 , m_shouldUseFixedDefaultFontSize(false) | 366 , m_shouldUseFixedDefaultFontSize(NonFixedPitchFont) |
| 367 , m_fontSizeDelta(NoFontDelta) | 367 , m_fontSizeDelta(NoFontDelta) |
| 368 { | 368 { |
| 369 extractFontSizeDelta(); | 369 extractFontSizeDelta(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) | 372 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) |
| 373 : m_mutableStyle(nullptr) | 373 : m_mutableStyle(nullptr) |
| 374 , m_shouldUseFixedDefaultFontSize(false) | 374 , m_shouldUseFixedDefaultFontSize(NonFixedPitchFont) |
| 375 , m_fontSizeDelta(NoFontDelta) | 375 , m_fontSizeDelta(NoFontDelta) |
| 376 { | 376 { |
| 377 setProperty(propertyID, value); | 377 setProperty(propertyID, value); |
| 378 } | 378 } |
| 379 | 379 |
| 380 EditingStyle::~EditingStyle() | 380 EditingStyle::~EditingStyle() |
| 381 { | 381 { |
| 382 } | 382 } |
| 383 | 383 |
| 384 static RGBA32 cssValueToRGBA(CSSValue* colorValue) | 384 static RGBA32 cssValueToRGBA(CSSValue* colorValue) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 return; | 567 return; |
| 568 if (!m_mutableStyle) | 568 if (!m_mutableStyle) |
| 569 m_mutableStyle = MutableStylePropertySet::create(); | 569 m_mutableStyle = MutableStylePropertySet::create(); |
| 570 m_mutableStyle->mergeAndOverrideOnConflict(style); | 570 m_mutableStyle->mergeAndOverrideOnConflict(style); |
| 571 extractFontSizeDelta(); | 571 extractFontSizeDelta(); |
| 572 } | 572 } |
| 573 | 573 |
| 574 void EditingStyle::clear() | 574 void EditingStyle::clear() |
| 575 { | 575 { |
| 576 m_mutableStyle.clear(); | 576 m_mutableStyle.clear(); |
| 577 m_shouldUseFixedDefaultFontSize = false; | 577 m_shouldUseFixedDefaultFontSize = NonFixedPitchFont; |
| 578 m_fontSizeDelta = NoFontDelta; | 578 m_fontSizeDelta = NoFontDelta; |
| 579 } | 579 } |
| 580 | 580 |
| 581 PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::copy() const | 581 PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::copy() const |
| 582 { | 582 { |
| 583 RefPtrWillBeRawPtr<EditingStyle> copy = EditingStyle::create(); | 583 RefPtrWillBeRawPtr<EditingStyle> copy = EditingStyle::create(); |
| 584 if (m_mutableStyle) | 584 if (m_mutableStyle) |
| 585 copy->m_mutableStyle = m_mutableStyle->mutableCopy(); | 585 copy->m_mutableStyle = m_mutableStyle->mutableCopy(); |
| 586 copy->m_shouldUseFixedDefaultFontSize = m_shouldUseFixedDefaultFontSize; | 586 copy->m_shouldUseFixedDefaultFontSize = m_shouldUseFixedDefaultFontSize; |
| 587 copy->m_fontSizeDelta = m_fontSizeDelta; | 587 copy->m_fontSizeDelta = m_fontSizeDelta; |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1427 static void setTextDecorationProperty(MutableStylePropertySet* style, const CSSV alueList* newTextDecoration, CSSPropertyID propertyID) | 1427 static void setTextDecorationProperty(MutableStylePropertySet* style, const CSSV alueList* newTextDecoration, CSSPropertyID propertyID) |
| 1428 { | 1428 { |
| 1429 if (newTextDecoration->length()) | 1429 if (newTextDecoration->length()) |
| 1430 style->setProperty(propertyID, newTextDecoration->cssText(), style->prop ertyIsImportant(propertyID)); | 1430 style->setProperty(propertyID, newTextDecoration->cssText(), style->prop ertyIsImportant(propertyID)); |
| 1431 else { | 1431 else { |
| 1432 // text-decoration: none is redundant since it does not remove any text decorations. | 1432 // text-decoration: none is redundant since it does not remove any text decorations. |
| 1433 style->removeProperty(propertyID); | 1433 style->removeProperty(propertyID); |
| 1434 } | 1434 } |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1437 void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet* style, bool shouldUseFixedFontDefaultSize) | 1437 void StyleChange::extractTextStyles(Document* document, MutableStylePropertySet* style, FixedPitchFontType fixedPitchFontType) |
| 1438 { | 1438 { |
| 1439 ASSERT(style); | 1439 ASSERT(style); |
| 1440 | 1440 |
| 1441 if (getIdentifierValue(style, CSSPropertyFontWeight) == CSSValueBold) { | 1441 if (getIdentifierValue(style, CSSPropertyFontWeight) == CSSValueBold) { |
| 1442 style->removeProperty(CSSPropertyFontWeight); | 1442 style->removeProperty(CSSPropertyFontWeight); |
| 1443 m_applyBold = true; | 1443 m_applyBold = true; |
| 1444 } | 1444 } |
| 1445 | 1445 |
| 1446 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); | 1446 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); |
| 1447 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { | 1447 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1486 m_applyFontColor = Color(getRGBAFontColor(style)).serialized(); | 1486 m_applyFontColor = Color(getRGBAFontColor(style)).serialized(); |
| 1487 style->removeProperty(CSSPropertyColor); | 1487 style->removeProperty(CSSPropertyColor); |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); | 1490 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); |
| 1491 // Remove single quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448 | 1491 // Remove single quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448 |
| 1492 m_applyFontFace.replaceWithLiteral('\'', ""); | 1492 m_applyFontFace.replaceWithLiteral('\'', ""); |
| 1493 style->removeProperty(CSSPropertyFontFamily); | 1493 style->removeProperty(CSSPropertyFontFamily); |
| 1494 | 1494 |
| 1495 if (RefPtrWillBeRawPtr<CSSValue> fontSize = style->getPropertyCSSValue(CSSPr opertyFontSize)) { | 1495 if (RefPtrWillBeRawPtr<CSSValue> fontSize = style->getPropertyCSSValue(CSSPr opertyFontSize)) { |
| 1496 if (!fontSize->isPrimitiveValue()) | 1496 if (!fontSize->isPrimitiveValue()) { |
| 1497 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size. | 1497 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size. |
| 1498 else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toCSS PrimitiveValue(fontSize.get()), | 1498 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(fontSize.get()), fixedPitchFontType, UseLegacyFontSizeOnlyIfPix elValuesMatch)) { |
| 1499 shouldUseFixedFontDefaultSize, UseLegacyFontSizeOnlyIfPixelValue sMatch)) { | |
| 1500 m_applyFontSize = String::number(legacyFontSize); | 1499 m_applyFontSize = String::number(legacyFontSize); |
| 1501 style->removeProperty(CSSPropertyFontSize); | 1500 style->removeProperty(CSSPropertyFontSize); |
| 1502 } | 1501 } |
| 1503 } | 1502 } |
| 1504 } | 1503 } |
| 1505 | 1504 |
| 1506 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertID, CSSValue* refTextDecoration) | 1505 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertID, CSSValue* refTextDecoration) |
| 1507 { | 1506 { |
| 1508 RefPtrWillBeRawPtr<CSSValue> textDecoration = style->getPropertyCSSValue(pro pertID); | 1507 RefPtrWillBeRawPtr<CSSValue> textDecoration = style->getPropertyCSSValue(pro pertID); |
| 1509 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList()) | 1508 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList()) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1606 if (!value || !value->isPrimitiveValue()) | 1605 if (!value || !value->isPrimitiveValue()) |
| 1607 return CSSValueInvalid; | 1606 return CSSValueInvalid; |
| 1608 return toCSSPrimitiveValue(value.get())->getValueID(); | 1607 return toCSSPrimitiveValue(value.get())->getValueID(); |
| 1609 } | 1608 } |
| 1610 | 1609 |
| 1611 static bool isCSSValueLength(CSSPrimitiveValue* value) | 1610 static bool isCSSValueLength(CSSPrimitiveValue* value) |
| 1612 { | 1611 { |
| 1613 return value->isFontIndependentLength(); | 1612 return value->isFontIndependentLength(); |
| 1614 } | 1613 } |
| 1615 | 1614 |
| 1616 int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue* value, boo l shouldUseFixedFontDefaultSize, LegacyFontSizeMode mode) | 1615 int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue* value, Fix edPitchFontType fixedPitchFontType, LegacyFontSizeMode mode) |
| 1617 { | 1616 { |
| 1618 if (isCSSValueLength(value)) { | 1617 if (isCSSValueLength(value)) { |
| 1619 int pixelFontSize = value->getIntValue(CSSPrimitiveValue::CSS_PX); | 1618 int pixelFontSize = value->getIntValue(CSSPrimitiveValue::CSS_PX); |
| 1620 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, s houldUseFixedFontDefaultSize); | 1619 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, f ixedPitchFontType); |
| 1621 // Use legacy font size only if pixel value matches exactly to that of l egacy font size. | 1620 // Use legacy font size only if pixel value matches exactly to that of l egacy font size. |
| 1622 int cssPrimitiveEquivalent = legacyFontSize - 1 + CSSValueXSmall; | 1621 int cssPrimitiveEquivalent = legacyFontSize - 1 + CSSValueXSmall; |
| 1623 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, cssPrimitiveEquivalent, shouldUseFixedFontDefaultSize) == pixelFontSize) | 1622 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, static_cast<CSSValueID>(cssPrimitiveEquivalent), fixedPitchFontType) == pi xelFontSize) |
|
Inactive
2014/06/26 19:43:11
nit: Maybe you can cast that one on the previous l
h.joshi
2014/06/27 06:55:27
Done.
| |
| 1624 return legacyFontSize; | 1623 return legacyFontSize; |
| 1625 | 1624 |
| 1626 return 0; | 1625 return 0; |
| 1627 } | 1626 } |
| 1628 | 1627 |
| 1629 if (CSSValueXSmall <= value->getValueID() && value->getValueID() <= CSSValue WebkitXxxLarge) | 1628 if (CSSValueXSmall <= value->getValueID() && value->getValueID() <= CSSValue WebkitXxxLarge) |
| 1630 return value->getValueID() - CSSValueXSmall + 1; | 1629 return value->getValueID() - CSSValueXSmall + 1; |
| 1631 | 1630 |
| 1632 return 0; | 1631 return 0; |
| 1633 } | 1632 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1660 { | 1659 { |
| 1661 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { | 1660 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { |
| 1662 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor); | 1661 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor); |
| 1663 if (!hasTransparentBackgroundColor(ancestorStyle.get())) | 1662 if (!hasTransparentBackgroundColor(ancestorStyle.get())) |
| 1664 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); | 1663 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); |
| 1665 } | 1664 } |
| 1666 return nullptr; | 1665 return nullptr; |
| 1667 } | 1666 } |
| 1668 | 1667 |
| 1669 } | 1668 } |
| OLD | NEW |