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

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

Issue 1850413002: Improve DEFINE_STATIC_LOCAL()'s handling of Blink GCed objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address compilation failure 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "core/editing/FrameSelection.h" 50 #include "core/editing/FrameSelection.h"
51 #include "core/editing/Position.h" 51 #include "core/editing/Position.h"
52 #include "core/editing/commands/ApplyStyleCommand.h" 52 #include "core/editing/commands/ApplyStyleCommand.h"
53 #include "core/editing/serializers/HTMLInterchange.h" 53 #include "core/editing/serializers/HTMLInterchange.h"
54 #include "core/frame/LocalFrame.h" 54 #include "core/frame/LocalFrame.h"
55 #include "core/html/HTMLFontElement.h" 55 #include "core/html/HTMLFontElement.h"
56 #include "core/html/HTMLSpanElement.h" 56 #include "core/html/HTMLSpanElement.h"
57 #include "core/layout/LayoutBox.h" 57 #include "core/layout/LayoutBox.h"
58 #include "core/layout/LayoutObject.h" 58 #include "core/layout/LayoutObject.h"
59 #include "core/style/ComputedStyle.h" 59 #include "core/style/ComputedStyle.h"
60 #include "wtf/StdLibExtras.h"
60 61
61 namespace blink { 62 namespace blink {
62 63
63 static const CSSPropertyID& textDecorationPropertyForEditing() 64 static const CSSPropertyID& textDecorationPropertyForEditing()
64 { 65 {
65 static const CSSPropertyID property = RuntimeEnabledFeatures::css3TextDecora tionsEnabled() ? CSSPropertyTextDecorationLine : CSSPropertyTextDecoration; 66 static const CSSPropertyID property = RuntimeEnabledFeatures::css3TextDecora tionsEnabled() ? CSSPropertyTextDecorationLine : CSSPropertyTextDecoration;
66 return property; 67 return property;
67 } 68 }
68 69
69 // Editing style properties must be preserved during editing operation. 70 // Editing style properties must be preserved during editing operation.
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 819
819 if (extractedStyle) 820 if (extractedStyle)
820 extractedStyle->setProperty(propertyID, inlineStyle->getPropertyValu e(propertyID), inlineStyle->propertyIsImportant(propertyID)); 821 extractedStyle->setProperty(propertyID, inlineStyle->getPropertyValu e(propertyID), inlineStyle->propertyIsImportant(propertyID));
821 } 822 }
822 823
823 return conflictingProperties && !conflictingProperties->isEmpty(); 824 return conflictingProperties && !conflictingProperties->isEmpty();
824 } 825 }
825 826
826 static const HeapVector<Member<HTMLElementEquivalent>>& htmlElementEquivalents() 827 static const HeapVector<Member<HTMLElementEquivalent>>& htmlElementEquivalents()
827 { 828 {
828 DEFINE_STATIC_LOCAL(PersistentHeapVector<Member<HTMLElementEquivalent>>, HTM LElementEquivalents, ()); 829 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLElementEquivalent>>, HTMLElementEq uivalents, (new HeapVector<Member<HTMLElementEquivalent>>));
829 if (!HTMLElementEquivalents.size()) { 830 if (!HTMLElementEquivalents.size()) {
830 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontWeight, CSSValueBold, HTMLNames::bTag)); 831 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontWeight, CSSValueBold, HTMLNames::bTag));
831 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontWeight, CSSValueBold, HTMLNames::strongTag)); 832 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontWeight, CSSValueBold, HTMLNames::strongTag));
832 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyV erticalAlign, CSSValueSub, HTMLNames::subTag)); 833 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyV erticalAlign, CSSValueSub, HTMLNames::subTag));
833 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyV erticalAlign, CSSValueSuper, HTMLNames::supTag)); 834 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyV erticalAlign, CSSValueSuper, HTMLNames::supTag));
834 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontStyle, CSSValueItalic, HTMLNames::iTag)); 835 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontStyle, CSSValueItalic, HTMLNames::iTag));
835 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontStyle, CSSValueItalic, HTMLNames::emTag)); 836 HTMLElementEquivalents.append(HTMLElementEquivalent::create(CSSPropertyF ontStyle, CSSValueItalic, HTMLNames::emTag));
836 837
837 HTMLElementEquivalents.append(HTMLTextDecorationEquivalent::create(CSSVa lueUnderline, HTMLNames::uTag)); 838 HTMLElementEquivalents.append(HTMLTextDecorationEquivalent::create(CSSVa lueUnderline, HTMLNames::uTag));
838 HTMLElementEquivalents.append(HTMLTextDecorationEquivalent::create(CSSVa lueLineThrough, HTMLNames::sTag)); 839 HTMLElementEquivalents.append(HTMLTextDecorationEquivalent::create(CSSVa lueLineThrough, HTMLNames::sTag));
(...skipping 17 matching lines...) Expand all
856 if (extractedStyle) 857 if (extractedStyle)
857 equivalent->addToStyle(element, extractedStyle); 858 equivalent->addToStyle(element, extractedStyle);
858 return true; 859 return true;
859 } 860 }
860 } 861 }
861 return false; 862 return false;
862 } 863 }
863 864
864 static const HeapVector<Member<HTMLAttributeEquivalent>>& htmlAttributeEquivalen ts() 865 static const HeapVector<Member<HTMLAttributeEquivalent>>& htmlAttributeEquivalen ts()
865 { 866 {
866 DEFINE_STATIC_LOCAL(PersistentHeapVector<Member<HTMLAttributeEquivalent>>, H TMLAttributeEquivalents, ()); 867 DEFINE_STATIC_LOCAL(HeapVector<Member<HTMLAttributeEquivalent>>, HTMLAttribu teEquivalents, (new HeapVector<Member<HTMLAttributeEquivalent>>));
867 if (!HTMLAttributeEquivalents.size()) { 868 if (!HTMLAttributeEquivalents.size()) {
868 // elementIsStyledSpanOrHTMLEquivalent depends on the fact each HTMLAttr iuteEquivalent matches exactly one attribute 869 // elementIsStyledSpanOrHTMLEquivalent depends on the fact each HTMLAttr iuteEquivalent matches exactly one attribute
869 // of exactly one element except dirAttr. 870 // of exactly one element except dirAttr.
870 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyColor, HTMLNames::fontTag, HTMLNames::colorAttr)); 871 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyColor, HTMLNames::fontTag, HTMLNames::colorAttr));
871 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyFontFamily, HTMLNames::fontTag, HTMLNames::faceAttr)); 872 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyFontFamily, HTMLNames::fontTag, HTMLNames::faceAttr));
872 HTMLAttributeEquivalents.append(HTMLFontSizeEquivalent::create()); 873 HTMLAttributeEquivalents.append(HTMLFontSizeEquivalent::create());
873 874
874 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyDirection, HTMLNames::dirAttr)); 875 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyDirection, HTMLNames::dirAttr));
875 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyUnicodeBidi, HTMLNames::dirAttr)); 876 HTMLAttributeEquivalents.append(HTMLAttributeEquivalent::create(CSSPrope rtyUnicodeBidi, HTMLNames::dirAttr));
876 } 877 }
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(node), EditingStyle::DoNotOverrideValues, 1124 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(node), EditingStyle::DoNotOverrideValues,
1124 EditingStyle::EditingPropertiesInEffect); 1125 EditingStyle::EditingPropertiesInEffect);
1125 } 1126 }
1126 } 1127 }
1127 1128
1128 return wrappingStyle.release(); 1129 return wrappingStyle.release();
1129 } 1130 }
1130 1131
1131 static void mergeTextDecorationValues(CSSValueList* mergedValue, const CSSValueL ist* valueToMerge) 1132 static void mergeTextDecorationValues(CSSValueList* mergedValue, const CSSValueL ist* valueToMerge)
1132 { 1133 {
1133 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, underline, (CSSPrimi tiveValue::createIdentifier(CSSValueUnderline))); 1134 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::create Identifier(CSSValueUnderline)));
1134 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, lineThrough, (CSSPri mitiveValue::createIdentifier(CSSValueLineThrough))); 1135 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue::crea teIdentifier(CSSValueLineThrough)));
1135 if (valueToMerge->hasValue(underline) && !mergedValue->hasValue(underline)) 1136 if (valueToMerge->hasValue(&underline) && !mergedValue->hasValue(&underline) )
1136 mergedValue->append(underline); 1137 mergedValue->append(&underline);
1137 1138
1138 if (valueToMerge->hasValue(lineThrough) && !mergedValue->hasValue(lineThroug h)) 1139 if (valueToMerge->hasValue(&lineThrough) && !mergedValue->hasValue(&lineThro ugh))
1139 mergedValue->append(lineThrough); 1140 mergedValue->append(&lineThrough);
1140 } 1141 }
1141 1142
1142 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride Mode mode) 1143 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride Mode mode)
1143 { 1144 {
1144 if (!style) 1145 if (!style)
1145 return; 1146 return;
1146 1147
1147 if (!m_mutableStyle) { 1148 if (!m_mutableStyle) {
1148 m_mutableStyle = style->mutableCopy(); 1149 m_mutableStyle = style->mutableCopy();
1149 return; 1150 return;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); 1518 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle);
1518 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { 1519 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) {
1519 style->removeProperty(CSSPropertyFontStyle); 1520 style->removeProperty(CSSPropertyFontStyle);
1520 m_applyItalic = true; 1521 m_applyItalic = true;
1521 } 1522 }
1522 1523
1523 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect 1524 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect
1524 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList. 1525 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList.
1525 RawPtr<CSSValue> textDecoration = style->getPropertyCSSValue(textDecorationP ropertyForEditing()); 1526 RawPtr<CSSValue> textDecoration = style->getPropertyCSSValue(textDecorationP ropertyForEditing());
1526 if (textDecoration && textDecoration->isValueList()) { 1527 if (textDecoration && textDecoration->isValueList()) {
1527 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, underline, (CSSP rimitiveValue::createIdentifier(CSSValueUnderline))); 1528 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::cr eateIdentifier(CSSValueUnderline)));
1528 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, lineThrough, (CS SPrimitiveValue::createIdentifier(CSSValueLineThrough))); 1529 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue:: createIdentifier(CSSValueLineThrough)));
1529 RawPtr<CSSValueList> newTextDecoration = toCSSValueList(textDecoration.g et())->copy(); 1530 RawPtr<CSSValueList> newTextDecoration = toCSSValueList(textDecoration.g et())->copy();
1530 if (newTextDecoration->removeAll(underline)) 1531 if (newTextDecoration->removeAll(&underline))
1531 m_applyUnderline = true; 1532 m_applyUnderline = true;
1532 if (newTextDecoration->removeAll(lineThrough)) 1533 if (newTextDecoration->removeAll(&lineThrough))
1533 m_applyLineThrough = true; 1534 m_applyLineThrough = true;
1534 1535
1535 // If trimTextDecorations, delete underline and line-through 1536 // If trimTextDecorations, delete underline and line-through
1536 setTextDecorationProperty(style, newTextDecoration.get(), textDecoration PropertyForEditing()); 1537 setTextDecorationProperty(style, newTextDecoration.get(), textDecoration PropertyForEditing());
1537 } 1538 }
1538 1539
1539 int verticalAlign = getIdentifierValue(style, CSSPropertyVerticalAlign); 1540 int verticalAlign = getIdentifierValue(style, CSSPropertyVerticalAlign);
1540 switch (verticalAlign) { 1541 switch (verticalAlign) {
1541 case CSSValueSub: 1542 case CSSValueSub:
1542 style->removeProperty(CSSPropertyVerticalAlign); 1543 style->removeProperty(CSSPropertyVerticalAlign);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 { 1724 {
1724 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1725 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1725 RawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor); 1726 RawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor);
1726 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1727 if (!hasTransparentBackgroundColor(ancestorStyle.get()))
1727 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1728 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1728 } 1729 }
1729 return nullptr; 1730 return nullptr;
1730 } 1731 }
1731 1732
1732 } // namespace blink 1733 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698