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

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

Issue 2346193002: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Replaced ASSERTs with DCHECKS in presubmit warnings Created 4 years, 3 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 12 matching lines...) Expand all
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "core/editing/EditingStyle.h" 27 #include "core/editing/EditingStyle.h"
28 28
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "core/HTMLNames.h" 30 #include "core/HTMLNames.h"
31 #include "core/css/CSSColorValue.h" 31 #include "core/css/CSSColorValue.h"
32 #include "core/css/CSSComputedStyleDeclaration.h" 32 #include "core/css/CSSComputedStyleDeclaration.h"
33 #include "core/css/CSSIdentifierValue.h"
33 #include "core/css/CSSPrimitiveValue.h" 34 #include "core/css/CSSPrimitiveValue.h"
34 #include "core/css/CSSPrimitiveValueMappings.h" 35 #include "core/css/CSSPrimitiveValueMappings.h"
35 #include "core/css/CSSPropertyMetadata.h" 36 #include "core/css/CSSPropertyMetadata.h"
36 #include "core/css/CSSRuleList.h" 37 #include "core/css/CSSRuleList.h"
37 #include "core/css/CSSStyleRule.h" 38 #include "core/css/CSSStyleRule.h"
38 #include "core/css/CSSValueList.h" 39 #include "core/css/CSSValueList.h"
39 #include "core/css/FontSize.h" 40 #include "core/css/FontSize.h"
40 #include "core/css/StylePropertySet.h" 41 #include "core/css/StylePropertySet.h"
41 #include "core/css/StyleRule.h" 42 #include "core/css/StyleRule.h"
42 #include "core/css/parser/CSSParser.h" 43 #include "core/css/parser/CSSParser.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 static CSSComputedStyleDeclaration* ensureComputedStyle(const Position& position ) 153 static CSSComputedStyleDeclaration* ensureComputedStyle(const Position& position )
153 { 154 {
154 Element* elem = associatedElementOf(position); 155 Element* elem = associatedElementOf(position);
155 if (!elem) 156 if (!elem)
156 return nullptr; 157 return nullptr;
157 return CSSComputedStyleDeclaration::create(elem); 158 return CSSComputedStyleDeclaration::create(elem);
158 } 159 }
159 160
160 static MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRe dundantProperties, CSSStyleDeclaration* baseStyle); 161 static MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRe dundantProperties, CSSStyleDeclaration* baseStyle);
161 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch }; 162 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch };
162 static int legacyFontSizeFromCSSValue(Document*, const CSSPrimitiveValue*, bool, LegacyFontSizeMode); 163 static int legacyFontSizeFromCSSValue(Document*, const CSSValue*, bool, LegacyFo ntSizeMode);
163 static bool isTransparentColorValue(const CSSValue*); 164 static bool isTransparentColorValue(const CSSValue*);
164 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); 165 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*);
165 static bool hasTransparentBackgroundColor(StylePropertySet*); 166 static bool hasTransparentBackgroundColor(StylePropertySet*);
166 static const CSSValue* backgroundColorValueInEffect(Node*); 167 static const CSSValue* backgroundColorValueInEffect(Node*);
167 static bool hasAncestorVerticalAlignStyle(Node&, CSSValueID); 168 static bool hasAncestorVerticalAlignStyle(Node&, CSSValueID);
168 169
169 class HTMLElementEquivalent : public GarbageCollected<HTMLElementEquivalent> { 170 class HTMLElementEquivalent : public GarbageCollected<HTMLElementEquivalent> {
170 public: 171 public:
171 static HTMLElementEquivalent* create(CSSPropertyID propertyID, CSSValueID pr imitiveValue, const HTMLQualifiedName& tagName) 172 static HTMLElementEquivalent* create(CSSPropertyID propertyID, CSSValueID pr imitiveValue, const HTMLQualifiedName& tagName)
172 { 173 {
173 return new HTMLElementEquivalent(propertyID, primitiveValue, tagName); 174 return new HTMLElementEquivalent(propertyID, primitiveValue, tagName);
174 } 175 }
175 176
176 virtual bool matches(const Element* element) const { return !m_tagName || el ement->hasTagName(*m_tagName); } 177 virtual bool matches(const Element* element) const { return !m_tagName || el ement->hasTagName(*m_tagName); }
177 virtual bool hasAttribute() const { return false; } 178 virtual bool hasAttribute() const { return false; }
178 virtual bool propertyExistsInStyle(const StylePropertySet* style) const { re turn style->getPropertyCSSValue(m_propertyID); } 179 virtual bool propertyExistsInStyle(const StylePropertySet* style) const { re turn style->getPropertyCSSValue(m_propertyID); }
179 virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const; 180 virtual bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const;
180 virtual void addToStyle(Element*, EditingStyle*) const; 181 virtual void addToStyle(Element*, EditingStyle*) const;
181 182
182 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_primitiveValue); } 183 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_identifierValue); }
183 184
184 protected: 185 protected:
185 HTMLElementEquivalent(CSSPropertyID); 186 HTMLElementEquivalent(CSSPropertyID);
186 HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName); 187 HTMLElementEquivalent(CSSPropertyID, const HTMLQualifiedName& tagName);
187 HTMLElementEquivalent(CSSPropertyID, CSSValueID primitiveValue, const HTMLQu alifiedName& tagName); 188 HTMLElementEquivalent(CSSPropertyID, CSSValueID primitiveValue, const HTMLQu alifiedName& tagName);
188 const CSSPropertyID m_propertyID; 189 const CSSPropertyID m_propertyID;
189 const Member<CSSPrimitiveValue> m_primitiveValue; 190 const Member<CSSIdentifierValue> m_identifierValue;
190 const HTMLQualifiedName* m_tagName; // We can store a pointer because HTML t ag names are const global. 191 const HTMLQualifiedName* m_tagName; // We can store a pointer because HTML t ag names are const global.
191 }; 192 };
192 193
193 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id) 194 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id)
194 : m_propertyID(id) 195 : m_propertyID(id)
195 , m_tagName(0) 196 , m_tagName(0)
196 { 197 {
197 } 198 }
198 199
199 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, const HTMLQualifi edName& tagName) 200 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, const HTMLQualifi edName& tagName)
200 : m_propertyID(id) 201 : m_propertyID(id)
201 , m_tagName(&tagName) 202 , m_tagName(&tagName)
202 { 203 {
203 } 204 }
204 205
205 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit iveValue, const HTMLQualifiedName& tagName) 206 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID valueI D, const HTMLQualifiedName& tagName)
206 : m_propertyID(id) 207 : m_propertyID(id)
207 , m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue)) 208 , m_identifierValue(CSSIdentifierValue::createIdentifier(valueID))
208 , m_tagName(&tagName) 209 , m_tagName(&tagName)
209 { 210 {
210 DCHECK_NE(primitiveValue, CSSValueInvalid); 211 DCHECK_NE(valueID, CSSValueInvalid);
211 } 212 }
212 213
213 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const 214 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const
214 { 215 {
215 const CSSValue* value = style->getPropertyCSSValue(m_propertyID); 216 const CSSValue* value = style->getPropertyCSSValue(m_propertyID);
216 return matches(element) && value && value->isPrimitiveValue() && toCSSPrimit iveValue(value)->getValueID() == m_primitiveValue->getValueID(); 217 return matches(element) && value && value->isIdentifierValue() && toCSSIdent ifierValue(value)->getValueID() == m_identifierValue->getValueID();
217 } 218 }
218 219
219 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const 220 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const
220 { 221 {
221 style->setProperty(m_propertyID, m_primitiveValue->cssText()); 222 style->setProperty(m_propertyID, m_identifierValue->cssText());
222 } 223 }
223 224
224 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent { 225 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent {
225 public: 226 public:
226 static HTMLElementEquivalent* create(CSSValueID primitiveValue, const HTMLQu alifiedName& tagName) 227 static HTMLElementEquivalent* create(CSSValueID primitiveValue, const HTMLQu alifiedName& tagName)
227 { 228 {
228 return new HTMLTextDecorationEquivalent(primitiveValue, tagName); 229 return new HTMLTextDecorationEquivalent(primitiveValue, tagName);
229 } 230 }
230 bool propertyExistsInStyle(const StylePropertySet*) const override; 231 bool propertyExistsInStyle(const StylePropertySet*) const override;
231 bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const override; 232 bool valueIsPresentInStyle(HTMLElement*, StylePropertySet*) const override;
(...skipping 14 matching lines...) Expand all
246 { 247 {
247 return style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect) 248 return style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect)
248 || style->getPropertyCSSValue(textDecorationPropertyForEditing()); 249 || style->getPropertyCSSValue(textDecorationPropertyForEditing());
249 } 250 }
250 251
251 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(HTMLElement* element, S tylePropertySet* style) const 252 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(HTMLElement* element, S tylePropertySet* style) const
252 { 253 {
253 const CSSValue* styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTex tDecorationsInEffect); 254 const CSSValue* styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTex tDecorationsInEffect);
254 if (!styleValue) 255 if (!styleValue)
255 styleValue = style->getPropertyCSSValue(textDecorationPropertyForEditing ()); 256 styleValue = style->getPropertyCSSValue(textDecorationPropertyForEditing ());
256 return matches(element) && styleValue && styleValue->isValueList() && toCSSV alueList(styleValue)->hasValue(*m_primitiveValue); 257 return matches(element) && styleValue && styleValue->isValueList() && toCSSV alueList(styleValue)->hasValue(*m_identifierValue);
257 } 258 }
258 259
259 class HTMLAttributeEquivalent : public HTMLElementEquivalent { 260 class HTMLAttributeEquivalent : public HTMLElementEquivalent {
260 public: 261 public:
261 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, const HTMLQ ualifiedName& tagName, const QualifiedName& attrName) 262 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, const HTMLQ ualifiedName& tagName, const QualifiedName& attrName)
262 { 263 {
263 return new HTMLAttributeEquivalent(propertyID, tagName, attrName); 264 return new HTMLAttributeEquivalent(propertyID, tagName, attrName);
264 } 265 }
265 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, const Quali fiedName& attrName) 266 static HTMLAttributeEquivalent* create(CSSPropertyID propertyID, const Quali fiedName& attrName)
266 { 267 {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 343
343 const CSSValue* HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* elemen t) const 344 const CSSValue* HTMLFontSizeEquivalent::attributeValueAsCSSValue(Element* elemen t) const
344 { 345 {
345 DCHECK(element); 346 DCHECK(element);
346 const AtomicString& value = element->getAttribute(m_attrName); 347 const AtomicString& value = element->getAttribute(m_attrName);
347 if (value.isNull()) 348 if (value.isNull())
348 return nullptr; 349 return nullptr;
349 CSSValueID size; 350 CSSValueID size;
350 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size)) 351 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
351 return nullptr; 352 return nullptr;
352 return CSSPrimitiveValue::createIdentifier(size); 353 return CSSIdentifierValue::createIdentifier(size);
353 } 354 }
354 355
355 float EditingStyle::NoFontDelta = 0.0f; 356 float EditingStyle::NoFontDelta = 0.0f;
356 357
357 EditingStyle::EditingStyle(ContainerNode* node, PropertiesToInclude propertiesTo Include) 358 EditingStyle::EditingStyle(ContainerNode* node, PropertiesToInclude propertiesTo Include)
358 { 359 {
359 init(node, propertiesToInclude); 360 init(node, propertiesToInclude);
360 } 361 }
361 362
362 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude) 363 EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert iesToInclude)
363 { 364 {
364 init(position.anchorNode(), propertiesToInclude); 365 init(position.anchorNode(), propertiesToInclude);
365 } 366 }
366 367
367 EditingStyle::EditingStyle(const StylePropertySet* style) 368 EditingStyle::EditingStyle(const StylePropertySet* style)
368 : m_mutableStyle(style ? style->mutableCopy() : nullptr) 369 : m_mutableStyle(style ? style->mutableCopy() : nullptr)
369 { 370 {
370 extractFontSizeDelta(); 371 extractFontSizeDelta();
371 } 372 }
372 373
373 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) 374 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value)
374 : m_mutableStyle(nullptr) 375 : m_mutableStyle(nullptr)
375 { 376 {
376 setProperty(propertyID, value); 377 setProperty(propertyID, value);
377 m_isVerticalAlign = propertyID == CSSPropertyVerticalAlign && (value == "sub " || value == "super"); 378 m_isVerticalAlign = propertyID == CSSPropertyVerticalAlign && (value == "sub " || value == "super");
378 } 379 }
379 380
380 static Color cssValueToColor(const CSSValue* colorValue) 381 static Color cssValueToColor(const CSSValue* colorValue)
381 { 382 {
382 if (!colorValue || (!colorValue->isColorValue() && !colorValue->isPrimitiveV alue())) 383 if (!colorValue || (!colorValue->isColorValue() && !colorValue->isPrimitiveV alue() && !colorValue->isIdentifierValue()))
383 return Color::transparent; 384 return Color::transparent;
384 385
385 if (colorValue->isColorValue()) 386 if (colorValue->isColorValue())
386 return toCSSColorValue(colorValue)->value(); 387 return toCSSColorValue(colorValue)->value();
387 388
388 Color color = 0; 389 Color color = 0;
389 // FIXME: Why ignore the return value? 390 // FIXME: Why ignore the return value?
390 CSSParser::parseColor(color, colorValue->cssText()); 391 CSSParser::parseColor(color, colorValue->cssText());
391 return color; 392 return color;
392 } 393 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 { 529 {
529 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && m_fontSizeDelta == NoFontDelta; 530 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && m_fontSizeDelta == NoFontDelta;
530 } 531 }
531 532
532 bool EditingStyle::textDirection(WritingDirection& writingDirection) const 533 bool EditingStyle::textDirection(WritingDirection& writingDirection) const
533 { 534 {
534 if (!m_mutableStyle) 535 if (!m_mutableStyle)
535 return false; 536 return false;
536 537
537 const CSSValue* unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropert yUnicodeBidi); 538 const CSSValue* unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropert yUnicodeBidi);
538 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 539 if (!unicodeBidi || !unicodeBidi->isIdentifierValue())
539 return false; 540 return false;
540 541
541 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID() ; 542 CSSValueID unicodeBidiValue = toCSSIdentifierValue(unicodeBidi)->getValueID( );
542 if (isEmbedOrIsolate(unicodeBidiValue)) { 543 if (isEmbedOrIsolate(unicodeBidiValue)) {
543 const CSSValue* direction = m_mutableStyle->getPropertyCSSValue(CSSPrope rtyDirection); 544 const CSSValue* direction = m_mutableStyle->getPropertyCSSValue(CSSPrope rtyDirection);
544 if (!direction || !direction->isPrimitiveValue()) 545 if (!direction || !direction->isIdentifierValue())
545 return false; 546 return false;
546 547
547 writingDirection = toCSSPrimitiveValue(direction)->getValueID() == CSSVa lueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection; 548 writingDirection = toCSSIdentifierValue(direction)->getValueID() == CSSV alueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
548 549
549 return true; 550 return true;
550 } 551 }
551 552
552 if (unicodeBidiValue == CSSValueNormal) { 553 if (unicodeBidiValue == CSSValueNormal) {
553 writingDirection = NaturalWritingDirection; 554 writingDirection = NaturalWritingDirection;
554 return true; 555 return true;
555 } 556 }
556 557
557 return false; 558 return false;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 TriState state = FalseTriState; 748 TriState state = FalseTriState;
748 bool nodeIsStart = true; 749 bool nodeIsStart = true;
749 for (Node& node : NodeTraversal::startsAt(*selection.start().anchorNode())) { 750 for (Node& node : NodeTraversal::startsAt(*selection.start().anchorNode())) {
750 if (node.layoutObject() && hasEditableStyle(node)) { 751 if (node.layoutObject() && hasEditableStyle(node)) {
751 CSSComputedStyleDeclaration* nodeStyle = CSSComputedStyleDeclaration ::create(&node); 752 CSSComputedStyleDeclaration* nodeStyle = CSSComputedStyleDeclaration ::create(&node);
752 if (nodeStyle) { 753 if (nodeStyle) {
753 // If the selected element has <sub> or <sup> ancestor element, apply the corresponding 754 // If the selected element has <sub> or <sup> ancestor element, apply the corresponding
754 // style(vertical-align) to it so that document.queryCommandStat e() works with the style. 755 // style(vertical-align) to it so that document.queryCommandStat e() works with the style.
755 // See bug http://crbug.com/582225. 756 // See bug http://crbug.com/582225.
756 if (m_isVerticalAlign && getIdentifierValue(nodeStyle, CSSProper tyVerticalAlign) == CSSValueBaseline) { 757 if (m_isVerticalAlign && getIdentifierValue(nodeStyle, CSSProper tyVerticalAlign) == CSSValueBaseline) {
757 const CSSPrimitiveValue* verticalAlign = toCSSPrimitiveValue (m_mutableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign)); 758 const CSSIdentifierValue* verticalAlign = toCSSIdentifierVal ue(m_mutableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign));
758 if (hasAncestorVerticalAlignStyle(node, verticalAlign->getVa lueID())) 759 if (hasAncestorVerticalAlignStyle(node, verticalAlign->getVa lueID()))
759 node.mutableComputedStyle()->setVerticalAlign(verticalAl ign->convertTo<EVerticalAlign>()); 760 node.mutableComputedStyle()->setVerticalAlign(verticalAl ign->convertTo<EVerticalAlign>());
760 } 761 }
761 762
762 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without chec king if node.isTextNode() 763 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without chec king if node.isTextNode()
763 // because the node can be an element node. See bug http://crbug .com/584939. 764 // because the node can be an element node. See bug http://crbug .com/584939.
764 TriState nodeState = triStateOfStyle(nodeStyle, EditingStyle::Do NotIgnoreTextOnlyProperties); 765 TriState nodeState = triStateOfStyle(nodeStyle, EditingStyle::Do NotIgnoreTextOnlyProperties);
765 if (nodeIsStart) { 766 if (nodeIsStart) {
766 state = nodeState; 767 state = nodeState;
767 nodeIsStart = false; 768 nodeIsStart = false;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) == textAlignResolvin gStartAndEnd(styleAtPosition)) 1013 if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) == textAlignResolvin gStartAndEnd(styleAtPosition))
1013 m_mutableStyle->removeProperty(CSSPropertyTextAlign); 1014 m_mutableStyle->removeProperty(CSSPropertyTextAlign);
1014 1015
1015 if (getFontColor(m_mutableStyle.get()) == getFontColor(styleAtPosition)) 1016 if (getFontColor(m_mutableStyle.get()) == getFontColor(styleAtPosition))
1016 m_mutableStyle->removeProperty(CSSPropertyColor); 1017 m_mutableStyle->removeProperty(CSSPropertyColor);
1017 1018
1018 if (hasTransparentBackgroundColor(m_mutableStyle.get()) 1019 if (hasTransparentBackgroundColor(m_mutableStyle.get())
1019 || cssValueToColor(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgr oundColor)) == backgroundColorInEffect(position.computeContainerNode())) 1020 || cssValueToColor(m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgr oundColor)) == backgroundColorInEffect(position.computeContainerNode()))
1020 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor); 1021 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
1021 1022
1022 if (unicodeBidi && unicodeBidi->isPrimitiveValue()) { 1023 if (unicodeBidi && unicodeBidi->isIdentifierValue()) {
1023 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSPrimitiveValue( unicodeBidi)->getValueID()); 1024 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, toCSSIdentifierValue (unicodeBidi)->getValueID());
1024 if (direction && direction->isPrimitiveValue()) 1025 if (direction && direction->isIdentifierValue())
1025 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSPrimitiveValu e(direction)->getValueID()); 1026 m_mutableStyle->setProperty(CSSPropertyDirection, toCSSIdentifierVal ue(direction)->getValueID());
1026 } 1027 }
1027 } 1028 }
1028 1029
1029 void EditingStyle::mergeTypingStyle(Document* document) 1030 void EditingStyle::mergeTypingStyle(Document* document)
1030 { 1031 {
1031 DCHECK(document); 1032 DCHECK(document);
1032 1033
1033 EditingStyle* typingStyle = document->frame()->selection().typingStyle(); 1034 EditingStyle* typingStyle = document->frame()->selection().typingStyle();
1034 if (!typingStyle || typingStyle == this) 1035 if (!typingStyle || typingStyle == this)
1035 return; 1036 return;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(&node) , EditingStyle::DoNotOverrideValues, 1136 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(&node) , EditingStyle::DoNotOverrideValues,
1136 EditingStyle::EditingPropertiesInEffect); 1137 EditingStyle::EditingPropertiesInEffect);
1137 } 1138 }
1138 } 1139 }
1139 1140
1140 return wrappingStyle; 1141 return wrappingStyle;
1141 } 1142 }
1142 1143
1143 static const CSSValueList& mergeTextDecorationValues(const CSSValueList& mergedV alue, const CSSValueList& valueToMerge) 1144 static const CSSValueList& mergeTextDecorationValues(const CSSValueList& mergedV alue, const CSSValueList& valueToMerge)
1144 { 1145 {
1145 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::create Identifier(CSSValueUnderline))); 1146 DEFINE_STATIC_LOCAL(CSSIdentifierValue, underline, (CSSIdentifierValue::crea teIdentifier(CSSValueUnderline)));
1146 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue::crea teIdentifier(CSSValueLineThrough))); 1147 DEFINE_STATIC_LOCAL(CSSIdentifierValue, lineThrough, (CSSIdentifierValue::cr eateIdentifier(CSSValueLineThrough)));
1147 CSSValueList& result = *mergedValue.copy(); 1148 CSSValueList& result = *mergedValue.copy();
1148 if (valueToMerge.hasValue(underline) && !mergedValue.hasValue(underline)) 1149 if (valueToMerge.hasValue(underline) && !mergedValue.hasValue(underline))
1149 result.append(underline); 1150 result.append(underline);
1150 1151
1151 if (valueToMerge.hasValue(lineThrough) && !mergedValue.hasValue(lineThrough) ) 1152 if (valueToMerge.hasValue(lineThrough) && !mergedValue.hasValue(lineThrough) )
1152 result.append(lineThrough); 1153 result.append(lineThrough);
1153 1154
1154 return result; 1155 return result;
1155 } 1156 }
1156 1157
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 { 1318 {
1318 if (!m_mutableStyle) 1319 if (!m_mutableStyle)
1319 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); 1320 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode);
1320 const bool propertyIsImportant = true; 1321 const bool propertyIsImportant = true;
1321 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant); 1322 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant);
1322 } 1323 }
1323 1324
1324 int EditingStyle::legacyFontSize(Document* document) const 1325 int EditingStyle::legacyFontSize(Document* document) const
1325 { 1326 {
1326 const CSSValue* cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyFo ntSize); 1327 const CSSValue* cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyFo ntSize);
1327 if (!cssValue || !cssValue->isPrimitiveValue()) 1328 if (!cssValue || !(cssValue->isPrimitiveValue() || cssValue->isIdentifierVal ue()))
1328 return 0; 1329 return 0;
1329 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue), 1330 return legacyFontSizeFromCSSValue(document, cssValue, m_isMonospaceFont, Alw aysUseLegacyFontSize);
1330 m_isMonospaceFont, AlwaysUseLegacyFontSize);
1331 } 1331 }
1332 1332
1333 EditingStyle* EditingStyle::styleAtSelectionStart(const VisibleSelection& select ion, bool shouldUseBackgroundColorInEffect, MutableStylePropertySet* styleToChec k) 1333 EditingStyle* EditingStyle::styleAtSelectionStart(const VisibleSelection& select ion, bool shouldUseBackgroundColorInEffect, MutableStylePropertySet* styleToChec k)
1334 { 1334 {
1335 if (selection.isNone()) 1335 if (selection.isNone())
1336 return nullptr; 1336 return nullptr;
1337 1337
1338 Position position = adjustedSelectionStartForStyleComputation(selection); 1338 Position position = adjustedSelectionStartForStyleComputation(selection);
1339 1339
1340 // If the pos is at the end of a text node, then this node is not fully sele cted. 1340 // If the pos is at the end of a text node, then this node is not fully sele cted.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 end = mostBackwardCaretPosition(selection.end()); 1400 end = mostBackwardCaretPosition(selection.end());
1401 1401
1402 DCHECK(end.document()); 1402 DCHECK(end.document());
1403 const EphemeralRange caretRange(position.parentAnchoredEquivalent(), end .parentAnchoredEquivalent()); 1403 const EphemeralRange caretRange(position.parentAnchoredEquivalent(), end .parentAnchoredEquivalent());
1404 for (Node& n : caretRange.nodes()) { 1404 for (Node& n : caretRange.nodes()) {
1405 if (!n.isStyledElement()) 1405 if (!n.isStyledElement())
1406 continue; 1406 continue;
1407 1407
1408 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(&n); 1408 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(&n);
1409 const CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSProperty UnicodeBidi); 1409 const CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSProperty UnicodeBidi);
1410 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1410 if (!unicodeBidi || !unicodeBidi->isIdentifierValue())
1411 continue; 1411 continue;
1412 1412
1413 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getV alueID(); 1413 CSSValueID unicodeBidiValue = toCSSIdentifierValue(unicodeBidi)->get ValueID();
1414 if (isUnicodeBidiNestedOrMultipleEmbeddings(unicodeBidiValue)) 1414 if (isUnicodeBidiNestedOrMultipleEmbeddings(unicodeBidiValue))
1415 return NaturalWritingDirection; 1415 return NaturalWritingDirection;
1416 } 1416 }
1417 } 1417 }
1418 1418
1419 if (selection.isCaret()) { 1419 if (selection.isCaret()) {
1420 WritingDirection direction; 1420 WritingDirection direction;
1421 if (typingStyle && typingStyle->textDirection(direction)) { 1421 if (typingStyle && typingStyle->textDirection(direction)) {
1422 hasNestedOrMultipleEmbeddings = false; 1422 hasNestedOrMultipleEmbeddings = false;
1423 return direction; 1423 return direction;
1424 } 1424 }
1425 node = selection.visibleStart().deepEquivalent().anchorNode(); 1425 node = selection.visibleStart().deepEquivalent().anchorNode();
1426 } 1426 }
1427 DCHECK(node); 1427 DCHECK(node);
1428 1428
1429 // 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 1429 // 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
1430 // to decide. 1430 // to decide.
1431 Node* block = enclosingBlock(node); 1431 Node* block = enclosingBlock(node);
1432 WritingDirection foundDirection = NaturalWritingDirection; 1432 WritingDirection foundDirection = NaturalWritingDirection;
1433 1433
1434 for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*node)) { 1434 for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*node)) {
1435 if (runner == block) 1435 if (runner == block)
1436 break; 1436 break;
1437 if (!runner.isStyledElement()) 1437 if (!runner.isStyledElement())
1438 continue; 1438 continue;
1439 1439
1440 Element* element = &toElement(runner); 1440 Element* element = &toElement(runner);
1441 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::create (element); 1441 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::create (element);
1442 const CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnic odeBidi); 1442 const CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnic odeBidi);
1443 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1443 if (!unicodeBidi || !unicodeBidi->isIdentifierValue())
1444 continue; 1444 continue;
1445 1445
1446 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID(); 1446 CSSValueID unicodeBidiValue = toCSSIdentifierValue(unicodeBidi)->getValu eID();
1447 if (unicodeBidiValue == CSSValueNormal) 1447 if (unicodeBidiValue == CSSValueNormal)
1448 continue; 1448 continue;
1449 1449
1450 if (unicodeBidiValue == CSSValueBidiOverride) 1450 if (unicodeBidiValue == CSSValueBidiOverride)
1451 return NaturalWritingDirection; 1451 return NaturalWritingDirection;
1452 1452
1453 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue; 1453 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue;
1454 const CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirect ion); 1454 const CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirect ion);
1455 if (!direction || !direction->isPrimitiveValue()) 1455 if (!direction || !direction->isIdentifierValue())
1456 continue; 1456 continue;
1457 1457
1458 int directionValue = toCSSPrimitiveValue(direction)->getValueID(); 1458 int directionValue = toCSSIdentifierValue(direction)->getValueID();
1459 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) 1459 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
1460 continue; 1460 continue;
1461 1461
1462 if (foundDirection != NaturalWritingDirection) 1462 if (foundDirection != NaturalWritingDirection)
1463 return NaturalWritingDirection; 1463 return NaturalWritingDirection;
1464 1464
1465 // In the range case, make sure that the embedding element persists unti l the end of the range. 1465 // In the range case, make sure that the embedding element persists unti l the end of the range.
1466 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element)) 1466 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element))
1467 return NaturalWritingDirection; 1467 return NaturalWritingDirection;
1468 1468
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); 1551 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle);
1552 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { 1552 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) {
1553 style->removeProperty(CSSPropertyFontStyle); 1553 style->removeProperty(CSSPropertyFontStyle);
1554 m_applyItalic = true; 1554 m_applyItalic = true;
1555 } 1555 }
1556 1556
1557 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect 1557 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect
1558 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList. 1558 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList.
1559 const CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationPr opertyForEditing()); 1559 const CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationPr opertyForEditing());
1560 if (textDecoration && textDecoration->isValueList()) { 1560 if (textDecoration && textDecoration->isValueList()) {
1561 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::cr eateIdentifier(CSSValueUnderline))); 1561 DEFINE_STATIC_LOCAL(CSSIdentifierValue, underline, (CSSIdentifierValue:: createIdentifier(CSSValueUnderline)));
1562 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue:: createIdentifier(CSSValueLineThrough))); 1562 DEFINE_STATIC_LOCAL(CSSIdentifierValue, lineThrough, (CSSIdentifierValue ::createIdentifier(CSSValueLineThrough)));
1563 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy() ; 1563 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy() ;
1564 if (newTextDecoration->removeAll(underline)) 1564 if (newTextDecoration->removeAll(underline))
1565 m_applyUnderline = true; 1565 m_applyUnderline = true;
1566 if (newTextDecoration->removeAll(lineThrough)) 1566 if (newTextDecoration->removeAll(lineThrough))
1567 m_applyLineThrough = true; 1567 m_applyLineThrough = true;
1568 1568
1569 // If trimTextDecorations, delete underline and line-through 1569 // If trimTextDecorations, delete underline and line-through
1570 setTextDecorationProperty(style, newTextDecoration, textDecorationProper tyForEditing()); 1570 setTextDecorationProperty(style, newTextDecoration, textDecorationProper tyForEditing());
1571 } 1571 }
1572 1572
(...skipping 13 matching lines...) Expand all
1586 m_applyFontColor = getFontColor(style).serialized(); 1586 m_applyFontColor = getFontColor(style).serialized();
1587 style->removeProperty(CSSPropertyColor); 1587 style->removeProperty(CSSPropertyColor);
1588 } 1588 }
1589 1589
1590 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); 1590 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily);
1591 // Remove double quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448 1591 // Remove double quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448
1592 m_applyFontFace.replace('"', ""); 1592 m_applyFontFace.replace('"', "");
1593 style->removeProperty(CSSPropertyFontFamily); 1593 style->removeProperty(CSSPropertyFontFamily);
1594 1594
1595 if (const CSSValue* fontSize = style->getPropertyCSSValue(CSSPropertyFontSiz e)) { 1595 if (const CSSValue* fontSize = style->getPropertyCSSValue(CSSPropertyFontSiz e)) {
1596 if (!fontSize->isPrimitiveValue()) { 1596 if (!fontSize->isPrimitiveValue() && !fontSize->isIdentifierValue()) {
1597 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size. 1597 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size.
1598 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValuesM atch)) { 1598 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, fon tSize, isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValuesMatch)) {
1599 m_applyFontSize = String::number(legacyFontSize); 1599 m_applyFontSize = String::number(legacyFontSize);
1600 style->removeProperty(CSSPropertyFontSize); 1600 style->removeProperty(CSSPropertyFontSize);
1601 } 1601 }
1602 } 1602 }
1603 } 1603 }
1604 1604
1605 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertyID, const CSSValue* refTextDecoration) 1605 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertyID, const CSSValue* refTextDecoration)
1606 { 1606 {
1607 const CSSValue* textDecoration = style->getPropertyCSSValue(propertyID); 1607 const CSSValue* textDecoration = style->getPropertyCSSValue(propertyID);
1608 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList()) 1608 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList())
1609 return; 1609 return;
1610 1610
1611 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy(); 1611 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy();
1612 const CSSValueList* valuesInRefTextDecoration = toCSSValueList(refTextDecora tion); 1612 const CSSValueList* valuesInRefTextDecoration = toCSSValueList(refTextDecora tion);
1613 1613
1614 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++) 1614 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++)
1615 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i)); 1615 newTextDecoration->removeAll(valuesInRefTextDecoration->item(i));
1616 1616
1617 setTextDecorationProperty(style, newTextDecoration, propertyID); 1617 setTextDecorationProperty(style, newTextDecoration, propertyID);
1618 } 1618 }
1619 1619
1620 static bool fontWeightIsBold(const CSSValue* fontWeight) 1620 static bool fontWeightIsBold(const CSSValue* fontWeight)
1621 { 1621 {
1622 if (!fontWeight->isPrimitiveValue()) 1622 if (!fontWeight->isIdentifierValue())
1623 return false; 1623 return false;
1624 1624
1625 // Because b tag can only bold text, there are only two states in plain html : bold and not bold. 1625 // Because b tag can only bold text, there are only two states in plain html : bold and not bold.
1626 // Collapse all other values to either one of these two states for editing p urposes. 1626 // Collapse all other values to either one of these two states for editing p urposes.
1627 switch (toCSSPrimitiveValue(fontWeight)->getValueID()) { 1627 switch (toCSSIdentifierValue(fontWeight)->getValueID()) {
1628 case CSSValue100: 1628 case CSSValue100:
1629 case CSSValue200: 1629 case CSSValue200:
1630 case CSSValue300: 1630 case CSSValue300:
1631 case CSSValue400: 1631 case CSSValue400:
1632 case CSSValue500: 1632 case CSSValue500:
1633 case CSSValueNormal: 1633 case CSSValueNormal:
1634 return false; 1634 return false;
1635 case CSSValueBold: 1635 case CSSValueBold:
1636 case CSSValue600: 1636 case CSSValue600:
1637 case CSSValue700: 1637 case CSSValue700:
1638 case CSSValue800: 1638 case CSSValue800:
1639 case CSSValue900: 1639 case CSSValue900:
1640 return true; 1640 return true;
1641 default: 1641 default:
1642 break; 1642 break;
1643 } 1643 }
1644 1644
1645 NOTREACHED(); // For CSSValueBolder and CSSValueLighter 1645 NOTREACHED(); // For CSSValueBolder and CSSValueLighter
1646 return false; 1646 return false;
1647 } 1647 }
1648 1648
1649 static bool fontWeightNeedsResolving(const CSSValue* fontWeight) 1649 static bool fontWeightNeedsResolving(const CSSValue* fontWeight)
1650 { 1650 {
1651 if (!fontWeight->isPrimitiveValue()) 1651 if (!fontWeight->isIdentifierValue())
1652 return true; 1652 return true;
1653 1653
1654 const CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID(); 1654 const CSSValueID value = toCSSIdentifierValue(fontWeight)->getValueID();
1655 return value == CSSValueLighter || value == CSSValueBolder; 1655 return value == CSSValueLighter || value == CSSValueBolder;
1656 } 1656 }
1657 1657
1658 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle) 1658 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle)
1659 { 1659 {
1660 DCHECK(styleWithRedundantProperties); 1660 DCHECK(styleWithRedundantProperties);
1661 DCHECK(baseStyle); 1661 DCHECK(baseStyle);
1662 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( ); 1662 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( );
1663 1663
1664 result->removeEquivalentProperties(baseStyle); 1664 result->removeEquivalentProperties(baseStyle);
(...skipping 21 matching lines...) Expand all
1686 result->removeProperty(CSSPropertyBackgroundColor); 1686 result->removeProperty(CSSPropertyBackgroundColor);
1687 1687
1688 return result; 1688 return result;
1689 } 1689 }
1690 1690
1691 CSSValueID getIdentifierValue(StylePropertySet* style, CSSPropertyID propertyID) 1691 CSSValueID getIdentifierValue(StylePropertySet* style, CSSPropertyID propertyID)
1692 { 1692 {
1693 if (!style) 1693 if (!style)
1694 return CSSValueInvalid; 1694 return CSSValueInvalid;
1695 const CSSValue* value = style->getPropertyCSSValue(propertyID); 1695 const CSSValue* value = style->getPropertyCSSValue(propertyID);
1696 if (!value || !value->isPrimitiveValue()) 1696 if (!value || !value->isIdentifierValue())
1697 return CSSValueInvalid; 1697 return CSSValueInvalid;
1698 return toCSSPrimitiveValue(value)->getValueID(); 1698 return toCSSIdentifierValue(value)->getValueID();
1699 } 1699 }
1700 1700
1701 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID) 1701 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID)
1702 { 1702 {
1703 if (!style) 1703 if (!style)
1704 return CSSValueInvalid; 1704 return CSSValueInvalid;
1705 const CSSValue* value = style->getPropertyCSSValueInternal(propertyID); 1705 const CSSValue* value = style->getPropertyCSSValueInternal(propertyID);
1706 if (!value || !value->isPrimitiveValue()) 1706 if (!value || !value->isIdentifierValue())
1707 return CSSValueInvalid; 1707 return CSSValueInvalid;
1708 return toCSSPrimitiveValue(value)->getValueID(); 1708 return toCSSIdentifierValue(value)->getValueID();
1709 } 1709 }
1710 1710
1711 int legacyFontSizeFromCSSValue(Document* document, const CSSPrimitiveValue* valu e, bool isMonospaceFont, LegacyFontSizeMode mode) 1711 int legacyFontSizeFromCSSValue(Document* document, const CSSValue* value, bool i sMonospaceFont, LegacyFontSizeMode mode)
1712 { 1712 {
1713 CSSPrimitiveValue::LengthUnitType lengthType; 1713 if (value->isPrimitiveValue()) {
1714 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value->typeWithCalcResolved( ), lengthType) 1714 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(*value);
1715 && lengthType == CSSPrimitiveValue::UnitTypePixels) { 1715 CSSPrimitiveValue::LengthUnitType lengthType;
1716 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFa ctor(value->typeWithCalcResolved()); 1716 if (CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.typeWithC alcResolved(), lengthType)
1717 int pixelFontSize = clampTo<int>(value->getDoubleValue() * conversion); 1717 && lengthType == CSSPrimitiveValue::UnitTypePixels) {
1718 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, i sMonospaceFont); 1718 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsSca leFactor(primitiveValue.typeWithCalcResolved());
1719 // Use legacy font size only if pixel value matches exactly to that of l egacy font size. 1719 int pixelFontSize = clampTo<int>(primitiveValue.getDoubleValue() * c onversion);
1720 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, legacyFontSize, isMonospaceFont) == pixelFontSize) 1720 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSiz e, isMonospaceFont);
1721 return legacyFontSize; 1721 // Use legacy font size only if pixel value matches exactly to that of legacy font size.
1722 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword( document, legacyFontSize, isMonospaceFont) == pixelFontSize)
1723 return legacyFontSize;
1722 1724
1723 return 0; 1725 return 0;
1726 }
1724 } 1727 }
1725 1728
1726 if (CSSValueXSmall <= value->getValueID() && value->getValueID() <= CSSValue WebkitXxxLarge) 1729 if (value->isIdentifierValue()) {
1727 return value->getValueID() - CSSValueXSmall + 1; 1730 const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(*value) ;
1731 if (CSSValueXSmall <= identifierValue.getValueID() && identifierValue.ge tValueID() <= CSSValueWebkitXxxLarge)
1732 return identifierValue.getValueID() - CSSValueXSmall + 1;
1733 }
1728 1734
1729 return 0; 1735 return 0;
1730 } 1736 }
1731 1737
1732 bool isTransparentColorValue(const CSSValue* cssValue) 1738 bool isTransparentColorValue(const CSSValue* cssValue)
1733 { 1739 {
1734 if (!cssValue) 1740 if (!cssValue)
1735 return true; 1741 return true;
1736 if (cssValue->isColorValue()) 1742 if (cssValue->isColorValue())
1737 return !toCSSColorValue(cssValue)->value().alpha(); 1743 return !toCSSColorValue(cssValue)->value().alpha();
1738 if (!cssValue->isPrimitiveValue()) 1744 if (!cssValue->isIdentifierValue())
1739 return false; 1745 return false;
1740 const CSSPrimitiveValue* value = toCSSPrimitiveValue(cssValue); 1746 return toCSSIdentifierValue(cssValue)->getValueID() == CSSValueTransparent;
1741 return value->getValueID() == CSSValueTransparent;
1742 } 1747 }
1743 1748
1744 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style) 1749 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
1745 { 1750 {
1746 const CSSValue* cssValue = style->getPropertyCSSValueInternal(CSSPropertyBac kgroundColor); 1751 const CSSValue* cssValue = style->getPropertyCSSValueInternal(CSSPropertyBac kgroundColor);
1747 return isTransparentColorValue(cssValue); 1752 return isTransparentColorValue(cssValue);
1748 } 1753 }
1749 1754
1750 bool hasTransparentBackgroundColor(StylePropertySet* style) 1755 bool hasTransparentBackgroundColor(StylePropertySet* style)
1751 { 1756 {
1752 const CSSValue* cssValue = style->getPropertyCSSValue(CSSPropertyBackgroundC olor); 1757 const CSSValue* cssValue = style->getPropertyCSSValue(CSSPropertyBackgroundC olor);
1753 return isTransparentColorValue(cssValue); 1758 return isTransparentColorValue(cssValue);
1754 } 1759 }
1755 1760
1756 const CSSValue* backgroundColorValueInEffect(Node* node) 1761 const CSSValue* backgroundColorValueInEffect(Node* node)
1757 { 1762 {
1758 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1763 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1759 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor); 1764 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor);
1760 if (!hasTransparentBackgroundColor(ancestorStyle)) 1765 if (!hasTransparentBackgroundColor(ancestorStyle))
1761 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1766 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1762 } 1767 }
1763 return nullptr; 1768 return nullptr;
1764 } 1769 }
1765 1770
1766 } // namespace blink 1771 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698