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

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

Issue 1225553002: CSSValue Immediates: Make CSSPrimitiveValue a container (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_1
Patch Set: Rebase Created 5 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
« no previous file with comments | « Source/core/editing/ApplyStyleCommand.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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie sType type = OnlyInheritableEditingProperties) 142 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie sType type = OnlyInheritableEditingProperties)
143 { 143 {
144 if (!style) 144 if (!style)
145 return MutableStylePropertySet::create(); 145 return MutableStylePropertySet::create();
146 return copyEditingProperties(style.get(), type); 146 return copyEditingProperties(style.get(), type);
147 } 147 }
148 148
149 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle); 149 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle);
150 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch }; 150 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch };
151 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool, Legac yFontSizeMode); 151 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue, bool, Legacy FontSizeMode);
152 static bool isTransparentColorValue(NullableCSSValue); 152 static bool isTransparentColorValue(NullableCSSValue);
153 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); 153 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*);
154 static bool hasTransparentBackgroundColor(StylePropertySet*); 154 static bool hasTransparentBackgroundColor(StylePropertySet*);
155 static NullableCSSValue backgroundColorInEffect(Node*); 155 static NullableCSSValue backgroundColorInEffect(Node*);
156 156
157 class HTMLElementEquivalent : public NoBaseWillBeGarbageCollected<HTMLElementEqu ivalent> { 157 class HTMLElementEquivalent : public NoBaseWillBeGarbageCollectedFinalized<HTMLE lementEquivalent> {
158 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(HTMLElementEquivalent); 158 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(HTMLElementEquivalent);
159 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent); 159 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent);
160 public: 160 public:
161 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID pr opertyID, CSSValueID primitiveValue, const HTMLQualifiedName& tagName) 161 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSPropertyID pr opertyID, CSSValueID primitiveValue, const HTMLQualifiedName& tagName)
162 { 162 {
163 return adoptPtrWillBeNoop(new HTMLElementEquivalent(propertyID, primitiv eValue, tagName)); 163 return adoptPtrWillBeNoop(new HTMLElementEquivalent(propertyID, primitiv eValue, tagName));
164 } 164 }
165 165
166 virtual bool matches(const Element* element) const { return !m_tagName || el ement->hasTagName(*m_tagName); } 166 virtual bool matches(const Element* element) const { return !m_tagName || el ement->hasTagName(*m_tagName); }
167 virtual bool hasAttribute() const { return false; } 167 virtual bool hasAttribute() const { return false; }
168 virtual bool propertyExistsInStyle(const StylePropertySet* style) const { re turn style->getPropertyCSSValue(m_propertyID); } 168 virtual bool propertyExistsInStyle(const StylePropertySet* style) const { re turn (bool)style->getPropertyCSSValue(m_propertyID); }
169 virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const; 169 virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const;
170 virtual void addToStyle(Element*, EditingStyle*) const; 170 virtual void addToStyle(Element*, EditingStyle*) const;
171 171
172 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_primitiveValue); } 172 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_primitiveValue); }
173 173
174 protected: 174 protected:
175 HTMLElementEquivalent(CSSPropertyID); 175 HTMLElementEquivalent(CSSPropertyID);
176 HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName); 176 HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName);
177 HTMLElementEquivalent(CSSPropertyID, CSSValueID primitiveValue, const HTMLQu alifiedName& tagName); 177 HTMLElementEquivalent(CSSPropertyID, CSSValueID primitiveValue, const HTMLQu alifiedName& tagName);
178 const CSSPropertyID m_propertyID; 178 const CSSPropertyID m_propertyID;
179 const RefPtrWillBeMember<CSSPrimitiveValue> m_primitiveValue; 179 const NullableCSSValue m_primitiveValue;
180 const HTMLQualifiedName* m_tagName; // We can store a pointer because HTML t ag names are const global. 180 const HTMLQualifiedName* m_tagName; // We can store a pointer because HTML t ag names are const global.
181 }; 181 };
182 182
183 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent); 183 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(HTMLElementEquivalent);
184 184
185 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id) 185 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id)
186 : m_propertyID(id) 186 : m_propertyID(id)
187 , m_tagName(0) 187 , m_tagName(0)
188 { 188 {
189 } 189 }
190 190
191 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, const HTMLQualifi edName& tagName) 191 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, const HTMLQualifi edName& tagName)
192 : m_propertyID(id) 192 : m_propertyID(id)
193 , m_tagName(&tagName) 193 , m_tagName(&tagName)
194 { 194 {
195 } 195 }
196 196
197 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit iveValue, const HTMLQualifiedName& tagName) 197 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit iveValue, const HTMLQualifiedName& tagName)
198 : m_propertyID(id) 198 : m_propertyID(id)
199 , m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue)) 199 , m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue))
200 , m_tagName(&tagName) 200 , m_tagName(&tagName)
201 { 201 {
202 ASSERT(primitiveValue != CSSValueInvalid); 202 ASSERT(primitiveValue != CSSValueInvalid);
203 } 203 }
204 204
205 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const 205 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const
206 { 206 {
207 NullableCSSValue value = style->getPropertyCSSValue(m_propertyID); 207 NullableCSSValue value = style->getPropertyCSSValue(m_propertyID);
208 return matches(element) && value && value->isPrimitiveValue() && toCSSPrimit iveValue(value)->getValueID() == m_primitiveValue->getValueID(); 208 return matches(element) && value && value->isPrimitiveValue() && toCSSPrimit iveValue(*value).getValueID() == toCSSPrimitiveValue(*m_primitiveValue).getValue ID();
209 } 209 }
210 210
211 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const 211 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const
212 { 212 {
213 style->setProperty(m_propertyID, m_primitiveValue->cssText()); 213 style->setProperty(m_propertyID, m_primitiveValue->cssText());
214 } 214 }
215 215
216 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent { 216 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent {
217 public: 217 public:
218 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSValueID primi tiveValue, const HTMLQualifiedName& tagName) 218 static PassOwnPtrWillBeRawPtr<HTMLElementEquivalent> create(CSSValueID primi tiveValue, const HTMLQualifiedName& tagName)
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 EditingStyle::~EditingStyle() 385 EditingStyle::~EditingStyle()
386 { 386 {
387 } 387 }
388 388
389 static RGBA32 cssValueToRGBA(NullableCSSValue colorValue) 389 static RGBA32 cssValueToRGBA(NullableCSSValue colorValue)
390 { 390 {
391 if (!colorValue || !colorValue->isPrimitiveValue()) 391 if (!colorValue || !colorValue->isPrimitiveValue())
392 return Color::transparent; 392 return Color::transparent;
393 393
394 CSSPrimitiveValue* primitiveColor = toCSSPrimitiveValue(colorValue); 394 CSSPrimitiveValue primitiveColor = toCSSPrimitiveValue(*colorValue);
395 if (primitiveColor->isRGBColor()) 395 if (primitiveColor.isRGBColor())
396 return primitiveColor->getRGBA32Value(); 396 return primitiveColor.getRGBA32Value();
397 397
398 RGBA32 rgba = 0; 398 RGBA32 rgba = 0;
399 // FIXME: Why ignore the return value? 399 // FIXME: Why ignore the return value?
400 CSSParser::parseColor(rgba, colorValue->cssText()); 400 CSSParser::parseColor(rgba, colorValue->cssText());
401 return rgba; 401 return rgba;
402 } 402 }
403 403
404 static inline RGBA32 getRGBAFontColor(CSSStyleDeclaration* style) 404 static inline RGBA32 getRGBAFontColor(CSSStyleDeclaration* style)
405 { 405 {
406 return cssValueToRGBA(style->getPropertyCSSValueInternal(CSSPropertyColor)); 406 return cssValueToRGBA(style->getPropertyCSSValueInternal(CSSPropertyColor));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // Explicit font size overrides any delta. 516 // Explicit font size overrides any delta.
517 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 517 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
518 return; 518 return;
519 } 519 }
520 520
521 // Get the adjustment amount out of the style. 521 // Get the adjustment amount out of the style.
522 NullableCSSValue value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebk itFontSizeDelta); 522 NullableCSSValue value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebk itFontSizeDelta);
523 if (!value || !value->isPrimitiveValue()) 523 if (!value || !value->isPrimitiveValue())
524 return; 524 return;
525 525
526 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 526 CSSPrimitiveValue primitiveValue = toCSSPrimitiveValue(*value);
527 527
528 // Only PX handled now. If we handle more types in the future, perhaps 528 // Only PX handled now. If we handle more types in the future, perhaps
529 // a switch statement here would be more appropriate. 529 // a switch statement here would be more appropriate.
530 if (!primitiveValue->isPx()) 530 if (!primitiveValue.isPx())
531 return; 531 return;
532 532
533 m_fontSizeDelta = primitiveValue->getFloatValue(); 533 m_fontSizeDelta = primitiveValue.getFloatValue();
534 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 534 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
535 } 535 }
536 536
537 bool EditingStyle::isEmpty() const 537 bool EditingStyle::isEmpty() const
538 { 538 {
539 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && m_fontSizeDelta == NoFontDelta; 539 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && m_fontSizeDelta == NoFontDelta;
540 } 540 }
541 541
542 bool EditingStyle::textDirection(WritingDirection& writingDirection) const 542 bool EditingStyle::textDirection(WritingDirection& writingDirection) const
543 { 543 {
544 if (!m_mutableStyle) 544 if (!m_mutableStyle)
545 return false; 545 return false;
546 546
547 NullableCSSValue unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSProper tyUnicodeBidi); 547 NullableCSSValue unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSProper tyUnicodeBidi);
548 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 548 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
549 return false; 549 return false;
550 550
551 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID() ; 551 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(*unicodeBidi).getValueID() ;
552 if (unicodeBidiValue == CSSValueEmbed) { 552 if (unicodeBidiValue == CSSValueEmbed) {
553 NullableCSSValue direction = m_mutableStyle->getPropertyCSSValue(CSSProp ertyDirection); 553 NullableCSSValue direction = m_mutableStyle->getPropertyCSSValue(CSSProp ertyDirection);
554 if (!direction || !direction->isPrimitiveValue()) 554 if (!direction || !direction->isPrimitiveValue())
555 return false; 555 return false;
556 556
557 writingDirection = toCSSPrimitiveValue(direction)->getValueID() == CSSVa lueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection; 557 writingDirection = toCSSPrimitiveValue(*direction).getValueID() == CSSVa lueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
558 558
559 return true; 559 return true;
560 } 560 }
561 561
562 if (unicodeBidiValue == CSSValueNormal) { 562 if (unicodeBidiValue == CSSValueNormal) {
563 writingDirection = NaturalWritingDirection; 563 writingDirection = NaturalWritingDirection;
564 return true; 564 return true;
565 } 565 }
566 566
567 return false; 567 return false;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 m_mutableStyle->removeProperty(CSSPropertyTextAlign); 998 m_mutableStyle->removeProperty(CSSPropertyTextAlign);
999 999
1000 if (getRGBAFontColor(m_mutableStyle.get()) == getRGBAFontColor(styleAtPositi on)) 1000 if (getRGBAFontColor(m_mutableStyle.get()) == getRGBAFontColor(styleAtPositi on))
1001 m_mutableStyle->removeProperty(CSSPropertyColor); 1001 m_mutableStyle->removeProperty(CSSPropertyColor);
1002 1002
1003 if (hasTransparentBackgroundColor(m_mutableStyle.get()) 1003 if (hasTransparentBackgroundColor(m_mutableStyle.get())
1004 || cssValueToRGBA(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgro undColor)) == rgbaBackgroundColorInEffect(position.containerNode())) 1004 || cssValueToRGBA(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgro undColor)) == rgbaBackgroundColorInEffect(position.containerNode()))
1005 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor); 1005 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
1006 1006
1007 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) { 1007 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) {
1008 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue( unicodeBidi)->getValueID()); 1008 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue( *unicodeBidi).getValueID());
1009 if (direction && direction->isPrimitiveValue()) 1009 if (direction && direction->isPrimitiveValue())
1010 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValu e(direction)->getValueID()); 1010 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValu e(*direction).getValueID());
1011 } 1011 }
1012 } 1012 }
1013 1013
1014 void EditingStyle::mergeTypingStyle(Document* document) 1014 void EditingStyle::mergeTypingStyle(Document* document)
1015 { 1015 {
1016 ASSERT(document); 1016 ASSERT(document);
1017 1017
1018 RefPtrWillBeRawPtr<EditingStyle> typingStyle = document->frame()->selection( ).typingStyle(); 1018 RefPtrWillBeRawPtr<EditingStyle> typingStyle = document->frame()->selection( ).typingStyle();
1019 if (!typingStyle || typingStyle == this) 1019 if (!typingStyle || typingStyle == this)
1020 return; 1020 return;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(node), EditingStyle::DoNotOverrideValues, 1117 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(node), EditingStyle::DoNotOverrideValues,
1118 EditingStyle::EditingPropertiesInEffect); 1118 EditingStyle::EditingPropertiesInEffect);
1119 } 1119 }
1120 } 1120 }
1121 1121
1122 return wrappingStyle.release(); 1122 return wrappingStyle.release();
1123 } 1123 }
1124 1124
1125 static void mergeTextDecorationValues(CSSValueList& mergedValue, const CSSValueL ist& valueToMerge) 1125 static void mergeTextDecorationValues(CSSValueList& mergedValue, const CSSValueL ist& valueToMerge)
1126 { 1126 {
1127 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, underline, (CSSPrimi tiveValue::createIdentifier(CSSValueUnderline))); 1127 CSSPrimitiveValue underline = CSSPrimitiveValue::createIdentifier(CSSValueUn derline);
1128 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, lineThrough, (CSSPri mitiveValue::createIdentifier(CSSValueLineThrough))); 1128 CSSPrimitiveValue lineThrough = CSSPrimitiveValue::createIdentifier(CSSValue LineThrough);
1129 1129
1130 if (valueToMerge.hasValue(CSSValue(*underline)) && !mergedValue.hasValue(CSS Value(*underline))) 1130 if (valueToMerge.hasValue(underline) && !mergedValue.hasValue(underline))
1131 mergedValue.append(CSSValue(*underline)); 1131 mergedValue.append(underline);
1132 1132
1133 if (valueToMerge.hasValue(CSSValue(*lineThrough)) && !mergedValue.hasValue(C SSValue(*lineThrough))) 1133 if (valueToMerge.hasValue(lineThrough) && !mergedValue.hasValue(lineThrough) )
1134 mergedValue.append(CSSValue(*lineThrough)); 1134 mergedValue.append(lineThrough);
1135 } 1135 }
1136 1136
1137 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride Mode mode) 1137 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride Mode mode)
1138 { 1138 {
1139 if (!style) 1139 if (!style)
1140 return; 1140 return;
1141 1141
1142 if (!m_mutableStyle) { 1142 if (!m_mutableStyle) {
1143 m_mutableStyle = style->mutableCopy(); 1143 m_mutableStyle = style->mutableCopy();
1144 return; 1144 return;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 m_mutableStyle = MutableStylePropertySet::create(); 1294 m_mutableStyle = MutableStylePropertySet::create();
1295 const bool propertyIsImportant = true; 1295 const bool propertyIsImportant = true;
1296 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant); 1296 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant);
1297 } 1297 }
1298 1298
1299 int EditingStyle::legacyFontSize(Document* document) const 1299 int EditingStyle::legacyFontSize(Document* document) const
1300 { 1300 {
1301 NullableCSSValue cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyF ontSize); 1301 NullableCSSValue cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyF ontSize);
1302 if (!cssValue || !cssValue->isPrimitiveValue()) 1302 if (!cssValue || !cssValue->isPrimitiveValue())
1303 return 0; 1303 return 0;
1304 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue), 1304 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(*cssValue),
1305 m_isMonospaceFont, AlwaysUseLegacyFontSize); 1305 m_isMonospaceFont, AlwaysUseLegacyFontSize);
1306 } 1306 }
1307 1307
1308 PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::styleAtSelectionStart(const V isibleSelection& selection, bool shouldUseBackgroundColorInEffect) 1308 PassRefPtrWillBeRawPtr<EditingStyle> EditingStyle::styleAtSelectionStart(const V isibleSelection& selection, bool shouldUseBackgroundColorInEffect)
1309 { 1309 {
1310 if (selection.isNone()) 1310 if (selection.isNone())
1311 return nullptr; 1311 return nullptr;
1312 1312
1313 Position position = adjustedSelectionStartForStyleComputation(selection); 1313 Position position = adjustedSelectionStartForStyleComputation(selection);
1314 1314
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); 1360 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode();
1361 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { 1361 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) {
1362 if (!n->isStyledElement()) 1362 if (!n->isStyledElement())
1363 continue; 1363 continue;
1364 1364
1365 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedS tyleDeclaration::create(n); 1365 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedS tyleDeclaration::create(n);
1366 NullableCSSValue unicodeBidi = style->getPropertyCSSValue(CSSPropert yUnicodeBidi); 1366 NullableCSSValue unicodeBidi = style->getPropertyCSSValue(CSSPropert yUnicodeBidi);
1367 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1367 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
1368 continue; 1368 continue;
1369 1369
1370 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getV alueID(); 1370 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(*unicodeBidi).getV alueID();
1371 if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValu eBidiOverride) 1371 if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValu eBidiOverride)
1372 return NaturalWritingDirection; 1372 return NaturalWritingDirection;
1373 } 1373 }
1374 } 1374 }
1375 1375
1376 if (selection.isCaret()) { 1376 if (selection.isCaret()) {
1377 WritingDirection direction; 1377 WritingDirection direction;
1378 if (typingStyle && typingStyle->textDirection(direction)) { 1378 if (typingStyle && typingStyle->textDirection(direction)) {
1379 hasNestedOrMultipleEmbeddings = false; 1379 hasNestedOrMultipleEmbeddings = false;
1380 return direction; 1380 return direction;
1381 } 1381 }
1382 node = selection.visibleStart().deepEquivalent().deprecatedNode(); 1382 node = selection.visibleStart().deepEquivalent().deprecatedNode();
1383 } 1383 }
1384 1384
1385 // The selection is either a caret with no typing attributes or a range in w hich no embedding is added, so just use the start position 1385 // The selection is either a caret with no typing attributes or a range in w hich no embedding is added, so just use the start position
1386 // to decide. 1386 // to decide.
1387 Node* block = enclosingBlock(node); 1387 Node* block = enclosingBlock(node);
1388 WritingDirection foundDirection = NaturalWritingDirection; 1388 WritingDirection foundDirection = NaturalWritingDirection;
1389 1389
1390 for (; node != block; node = node->parentNode()) { 1390 for (; node != block; node = node->parentNode()) {
1391 if (!node->isStyledElement()) 1391 if (!node->isStyledElement())
1392 continue; 1392 continue;
1393 1393
1394 Element* element = toElement(node); 1394 Element* element = toElement(node);
1395 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedStyle Declaration::create(element); 1395 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedStyle Declaration::create(element);
1396 NullableCSSValue unicodeBidi = style->getPropertyCSSValue(CSSPropertyUni codeBidi); 1396 NullableCSSValue unicodeBidi = style->getPropertyCSSValue(CSSPropertyUni codeBidi);
1397 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1397 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
1398 continue; 1398 continue;
1399 1399
1400 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID(); 1400 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(*unicodeBidi).getValue ID();
1401 if (unicodeBidiValue == CSSValueNormal) 1401 if (unicodeBidiValue == CSSValueNormal)
1402 continue; 1402 continue;
1403 1403
1404 if (unicodeBidiValue == CSSValueBidiOverride) 1404 if (unicodeBidiValue == CSSValueBidiOverride)
1405 return NaturalWritingDirection; 1405 return NaturalWritingDirection;
1406 1406
1407 ASSERT(unicodeBidiValue == CSSValueEmbed); 1407 ASSERT(unicodeBidiValue == CSSValueEmbed);
1408 NullableCSSValue direction = style->getPropertyCSSValue(CSSPropertyDirec tion); 1408 NullableCSSValue direction = style->getPropertyCSSValue(CSSPropertyDirec tion);
1409 if (!direction || !direction->isPrimitiveValue()) 1409 if (!direction || !direction->isPrimitiveValue())
1410 continue; 1410 continue;
1411 1411
1412 int directionValue = toCSSPrimitiveValue(direction)->getValueID(); 1412 int directionValue = toCSSPrimitiveValue(*direction).getValueID();
1413 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) 1413 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
1414 continue; 1414 continue;
1415 1415
1416 if (foundDirection != NaturalWritingDirection) 1416 if (foundDirection != NaturalWritingDirection)
1417 return NaturalWritingDirection; 1417 return NaturalWritingDirection;
1418 1418
1419 // In the range case, make sure that the embedding element persists unti l the end of the range. 1419 // In the range case, make sure that the embedding element persists unti l the end of the range.
1420 if (selection.isRange() && !end.deprecatedNode()->isDescendantOf(element )) 1420 if (selection.isRange() && !end.deprecatedNode()->isDescendantOf(element ))
1421 return NaturalWritingDirection; 1421 return NaturalWritingDirection;
1422 1422
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); 1504 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle);
1505 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { 1505 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) {
1506 style->removeProperty(CSSPropertyFontStyle); 1506 style->removeProperty(CSSPropertyFontStyle);
1507 m_applyItalic = true; 1507 m_applyItalic = true;
1508 } 1508 }
1509 1509
1510 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect 1510 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect
1511 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList. 1511 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList.
1512 NullableCSSValue textDecoration = style->getPropertyCSSValue(textDecorationP ropertyForEditing()); 1512 NullableCSSValue textDecoration = style->getPropertyCSSValue(textDecorationP ropertyForEditing());
1513 if (textDecoration && textDecoration->isValueList()) { 1513 if (textDecoration && textDecoration->isValueList()) {
1514 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, underline, (CSSP rimitiveValue::createIdentifier(CSSValueUnderline))); 1514 CSSPrimitiveValue underline = CSSPrimitiveValue::createIdentifier(CSSVal ueUnderline);
1515 DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, lineThrough, (CS SPrimitiveValue::createIdentifier(CSSValueLineThrough))); 1515 CSSPrimitiveValue lineThrough = CSSPrimitiveValue::createIdentifier(CSSV alueLineThrough);
1516 RefPtrWillBeRawPtr<CSSValueList> newTextDecoration = toCSSValueList(text Decoration)->copy(); 1516 RefPtrWillBeRawPtr<CSSValueList> newTextDecoration = toCSSValueList(text Decoration)->copy();
1517 if (newTextDecoration->removeAll(CSSValue(*underline))) 1517 if (newTextDecoration->removeAll(underline))
1518 m_applyUnderline = true; 1518 m_applyUnderline = true;
1519 if (newTextDecoration->removeAll(CSSValue(*lineThrough))) 1519 if (newTextDecoration->removeAll(lineThrough))
1520 m_applyLineThrough = true; 1520 m_applyLineThrough = true;
1521 1521
1522 // If trimTextDecorations, delete underline and line-through 1522 // If trimTextDecorations, delete underline and line-through
1523 setTextDecorationProperty(style, newTextDecoration.get(), textDecoration PropertyForEditing()); 1523 setTextDecorationProperty(style, newTextDecoration.get(), textDecoration PropertyForEditing());
1524 } 1524 }
1525 1525
1526 int verticalAlign = getIdentifierValue(style, CSSPropertyVerticalAlign); 1526 int verticalAlign = getIdentifierValue(style, CSSPropertyVerticalAlign);
1527 switch (verticalAlign) { 1527 switch (verticalAlign) {
1528 case CSSValueSub: 1528 case CSSValueSub:
1529 style->removeProperty(CSSPropertyVerticalAlign); 1529 style->removeProperty(CSSPropertyVerticalAlign);
(...skipping 11 matching lines...) Expand all
1541 } 1541 }
1542 1542
1543 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); 1543 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily);
1544 // Remove single quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448 1544 // Remove single quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448
1545 m_applyFontFace.replaceWithLiteral('\'', ""); 1545 m_applyFontFace.replaceWithLiteral('\'', "");
1546 style->removeProperty(CSSPropertyFontFamily); 1546 style->removeProperty(CSSPropertyFontFamily);
1547 1547
1548 if (NullableCSSValue fontSize = style->getPropertyCSSValue(CSSPropertyFontSi ze)) { 1548 if (NullableCSSValue fontSize = style->getPropertyCSSValue(CSSPropertyFontSi ze)) {
1549 if (!fontSize->isPrimitiveValue()) { 1549 if (!fontSize->isPrimitiveValue()) {
1550 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size. 1550 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size.
1551 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValuesM atch)) { 1551 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(*fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValues Match)) {
1552 m_applyFontSize = String::number(legacyFontSize); 1552 m_applyFontSize = String::number(legacyFontSize);
1553 style->removeProperty(CSSPropertyFontSize); 1553 style->removeProperty(CSSPropertyFontSize);
1554 } 1554 }
1555 } 1555 }
1556 } 1556 }
1557 1557
1558 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertyID, NullableCSSValue refTextDecoration) 1558 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertyID, NullableCSSValue refTextDecoration)
1559 { 1559 {
1560 NullableCSSValue textDecoration = style->getPropertyCSSValue(propertyID); 1560 NullableCSSValue textDecoration = style->getPropertyCSSValue(propertyID);
1561 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList()) 1561 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList())
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 return result.release(); 1640 return result.release();
1641 } 1641 }
1642 1642
1643 CSSValueID getIdentifierValue(StylePropertySet* style, CSSPropertyID propertyID) 1643 CSSValueID getIdentifierValue(StylePropertySet* style, CSSPropertyID propertyID)
1644 { 1644 {
1645 if (!style) 1645 if (!style)
1646 return CSSValueInvalid; 1646 return CSSValueInvalid;
1647 NullableCSSValue value = style->getPropertyCSSValue(propertyID); 1647 NullableCSSValue value = style->getPropertyCSSValue(propertyID);
1648 if (!value || !value->isPrimitiveValue()) 1648 if (!value || !value->isPrimitiveValue())
1649 return CSSValueInvalid; 1649 return CSSValueInvalid;
1650 return toCSSPrimitiveValue(value)->getValueID(); 1650 return toCSSPrimitiveValue(*value).getValueID();
1651 } 1651 }
1652 1652
1653 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID) 1653 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID)
1654 { 1654 {
1655 if (!style) 1655 if (!style)
1656 return CSSValueInvalid; 1656 return CSSValueInvalid;
1657 NullableCSSValue value = style->getPropertyCSSValueInternal(propertyID); 1657 NullableCSSValue value = style->getPropertyCSSValueInternal(propertyID);
1658 if (!value || !value->isPrimitiveValue()) 1658 if (!value || !value->isPrimitiveValue())
1659 return CSSValueInvalid; 1659 return CSSValueInvalid;
1660 return toCSSPrimitiveValue(value)->getValueID(); 1660 return toCSSPrimitiveValue(*value).getValueID();
1661 } 1661 }
1662 1662
1663 int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue* value, boo l isMonospaceFont, LegacyFontSizeMode mode) 1663 int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue value, bool isMonospaceFont, LegacyFontSizeMode mode)
1664 { 1664 {
1665 CSSPrimitiveValue::LengthUnitType lengthType; 1665 CSSPrimitiveValue::LengthUnitType lengthType;
1666 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value->primitiveType(), leng thType) 1666 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value.primitiveType(), lengt hType)
1667 && lengthType == CSSPrimitiveValue::UnitTypePixels) { 1667 && lengthType == CSSPrimitiveValue::UnitTypePixels) {
1668 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFa ctor(value->primitiveType()); 1668 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFa ctor(value.primitiveType());
1669 int pixelFontSize = clampTo<int>(value->getDoubleValue() * conversion); 1669 int pixelFontSize = clampTo<int>(value.getDoubleValue() * conversion);
1670 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, i sMonospaceFont); 1670 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, i sMonospaceFont);
1671 // Use legacy font size only if pixel value matches exactly to that of l egacy font size. 1671 // Use legacy font size only if pixel value matches exactly to that of l egacy font size.
1672 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, legacyFontSize, isMonospaceFont) == pixelFontSize) 1672 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, legacyFontSize, isMonospaceFont) == pixelFontSize)
1673 return legacyFontSize; 1673 return legacyFontSize;
1674 1674
1675 return 0; 1675 return 0;
1676 } 1676 }
1677 1677
1678 if (CSSValueXSmall <= value->getValueID() && value->getValueID() <= CSSValue WebkitXxxLarge) 1678 if (CSSValueXSmall <= value.getValueID() && value.getValueID() <= CSSValueWe bkitXxxLarge)
1679 return value->getValueID() - CSSValueXSmall + 1; 1679 return value.getValueID() - CSSValueXSmall + 1;
1680 1680
1681 return 0; 1681 return 0;
1682 } 1682 }
1683 1683
1684 bool isTransparentColorValue(NullableCSSValue cssValue) 1684 bool isTransparentColorValue(NullableCSSValue cssValue)
1685 { 1685 {
1686 if (!cssValue) 1686 if (!cssValue)
1687 return true; 1687 return true;
1688 if (!cssValue->isPrimitiveValue()) 1688 if (!cssValue->isPrimitiveValue())
1689 return false; 1689 return false;
1690 CSSPrimitiveValue* value = toCSSPrimitiveValue(cssValue); 1690 CSSPrimitiveValue value = toCSSPrimitiveValue(*cssValue);
1691 if (value->isRGBColor()) 1691 if (value.isRGBColor())
1692 return !alphaChannel(value->getRGBA32Value()); 1692 return !alphaChannel(value.getRGBA32Value());
1693 return value->getValueID() == CSSValueTransparent; 1693 return value.getValueID() == CSSValueTransparent;
1694 } 1694 }
1695 1695
1696 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style) 1696 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
1697 { 1697 {
1698 NullableCSSValue cssValue = style->getPropertyCSSValueInternal(CSSPropertyBa ckgroundColor); 1698 NullableCSSValue cssValue = style->getPropertyCSSValueInternal(CSSPropertyBa ckgroundColor);
1699 return isTransparentColorValue(cssValue); 1699 return isTransparentColorValue(cssValue);
1700 } 1700 }
1701 1701
1702 bool hasTransparentBackgroundColor(StylePropertySet* style) 1702 bool hasTransparentBackgroundColor(StylePropertySet* style)
1703 { 1703 {
1704 NullableCSSValue cssValue = style->getPropertyCSSValue(CSSPropertyBackground Color); 1704 NullableCSSValue cssValue = style->getPropertyCSSValue(CSSPropertyBackground Color);
1705 return isTransparentColorValue(cssValue); 1705 return isTransparentColorValue(cssValue);
1706 } 1706 }
1707 1707
1708 NullableCSSValue backgroundColorInEffect(Node* node) 1708 NullableCSSValue backgroundColorInEffect(Node* node)
1709 { 1709 {
1710 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1710 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1711 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor); 1711 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu tedStyleDeclaration::create(ancestor);
1712 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1712 if (!hasTransparentBackgroundColor(ancestorStyle.get()))
1713 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1713 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1714 } 1714 }
1715 return nullptr; 1715 return nullptr;
1716 } 1716 }
1717 1717
1718 } 1718 }
OLDNEW
« no previous file with comments | « Source/core/editing/ApplyStyleCommand.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698