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

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

Issue 2034013002: Make CSSComputedStyledeclaration::getPropertyCSSValue return const (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_make_cssproperty_store_const
Patch Set: Rebase Created 4 years, 6 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 static CSSComputedStyleDeclaration* ensureComputedStyle(const Position& position ) 153 static CSSComputedStyleDeclaration* ensureComputedStyle(const Position& position )
154 { 154 {
155 Element* elem = associatedElementOf(position); 155 Element* elem = associatedElementOf(position);
156 if (!elem) 156 if (!elem)
157 return nullptr; 157 return nullptr;
158 return CSSComputedStyleDeclaration::create(elem); 158 return CSSComputedStyleDeclaration::create(elem);
159 } 159 }
160 160
161 static MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRe dundantProperties, CSSStyleDeclaration* baseStyle); 161 static MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRe dundantProperties, CSSStyleDeclaration* baseStyle);
162 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch }; 162 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV aluesMatch };
163 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool, Legac yFontSizeMode); 163 static int legacyFontSizeFromCSSValue(Document*, const CSSPrimitiveValue*, bool, LegacyFontSizeMode);
164 static bool isTransparentColorValue(CSSValue*); 164 static bool isTransparentColorValue(const CSSValue*);
165 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*); 165 static bool hasTransparentBackgroundColor(CSSStyleDeclaration*);
166 static bool hasTransparentBackgroundColor(StylePropertySet*); 166 static bool hasTransparentBackgroundColor(StylePropertySet*);
167 static CSSValue* backgroundColorValueInEffect(Node*); 167 static const CSSValue* backgroundColorValueInEffect(Node*);
168 static bool hasAncestorVerticalAlignStyle(Node&, CSSValueID); 168 static bool hasAncestorVerticalAlignStyle(Node&, CSSValueID);
169 169
170 class HTMLElementEquivalent : public GarbageCollected<HTMLElementEquivalent> { 170 class HTMLElementEquivalent : public GarbageCollected<HTMLElementEquivalent> {
171 public: 171 public:
172 static HTMLElementEquivalent* create(CSSPropertyID propertyID, CSSValueID pr imitiveValue, const HTMLQualifiedName& tagName) 172 static HTMLElementEquivalent* create(CSSPropertyID propertyID, CSSValueID pr imitiveValue, const HTMLQualifiedName& tagName)
173 { 173 {
174 return new HTMLElementEquivalent(propertyID, primitiveValue, tagName); 174 return new HTMLElementEquivalent(propertyID, primitiveValue, tagName);
175 } 175 }
176 176
177 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); }
(...skipping 28 matching lines...) Expand all
206 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit iveValue, const HTMLQualifiedName& tagName) 206 HTMLElementEquivalent::HTMLElementEquivalent(CSSPropertyID id, CSSValueID primit iveValue, const HTMLQualifiedName& tagName)
207 : m_propertyID(id) 207 : m_propertyID(id)
208 , m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue)) 208 , m_primitiveValue(CSSPrimitiveValue::createIdentifier(primitiveValue))
209 , m_tagName(&tagName) 209 , m_tagName(&tagName)
210 { 210 {
211 DCHECK_NE(primitiveValue, CSSValueInvalid); 211 DCHECK_NE(primitiveValue, CSSValueInvalid);
212 } 212 }
213 213
214 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const 214 bool HTMLElementEquivalent::valueIsPresentInStyle(HTMLElement* element, StylePro pertySet* style) const
215 { 215 {
216 CSSValue* value = style->getPropertyCSSValue(m_propertyID); 216 const CSSValue* value = style->getPropertyCSSValue(m_propertyID);
217 return matches(element) && value && value->isPrimitiveValue() && toCSSPrimit iveValue(value)->getValueID() == m_primitiveValue->getValueID(); 217 return matches(element) && value && value->isPrimitiveValue() && toCSSPrimit iveValue(value)->getValueID() == m_primitiveValue->getValueID();
218 } 218 }
219 219
220 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const 220 void HTMLElementEquivalent::addToStyle(Element*, EditingStyle* style) const
221 { 221 {
222 style->setProperty(m_propertyID, m_primitiveValue->cssText()); 222 style->setProperty(m_propertyID, m_primitiveValue->cssText());
223 } 223 }
224 224
225 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent { 225 class HTMLTextDecorationEquivalent final : public HTMLElementEquivalent {
226 public: 226 public:
(...skipping 17 matching lines...) Expand all
244 } 244 }
245 245
246 bool HTMLTextDecorationEquivalent::propertyExistsInStyle(const StylePropertySet* style) const 246 bool HTMLTextDecorationEquivalent::propertyExistsInStyle(const StylePropertySet* style) const
247 { 247 {
248 return style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect) 248 return style->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect)
249 || style->getPropertyCSSValue(textDecorationPropertyForEditing()); 249 || style->getPropertyCSSValue(textDecorationPropertyForEditing());
250 } 250 }
251 251
252 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(HTMLElement* element, S tylePropertySet* style) const 252 bool HTMLTextDecorationEquivalent::valueIsPresentInStyle(HTMLElement* element, S tylePropertySet* style) const
253 { 253 {
254 CSSValue* styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTextDecor ationsInEffect); 254 const CSSValue* styleValue = style->getPropertyCSSValue(CSSPropertyWebkitTex tDecorationsInEffect);
255 if (!styleValue) 255 if (!styleValue)
256 styleValue = style->getPropertyCSSValue(textDecorationPropertyForEditing ()); 256 styleValue = style->getPropertyCSSValue(textDecorationPropertyForEditing ());
257 return matches(element) && styleValue && styleValue->isValueList() && toCSSV alueList(styleValue)->hasValue(*m_primitiveValue); 257 return matches(element) && styleValue && styleValue->isValueList() && toCSSV alueList(styleValue)->hasValue(*m_primitiveValue);
258 } 258 }
259 259
260 class HTMLAttributeEquivalent : public HTMLElementEquivalent { 260 class HTMLAttributeEquivalent : public HTMLElementEquivalent {
261 public: 261 public:
262 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)
263 { 263 {
264 return new HTMLAttributeEquivalent(propertyID, tagName, attrName); 264 return new HTMLAttributeEquivalent(propertyID, tagName, attrName);
(...skipping 26 matching lines...) Expand all
291 291
292 HTMLAttributeEquivalent::HTMLAttributeEquivalent(CSSPropertyID id, const Qualifi edName& attrName) 292 HTMLAttributeEquivalent::HTMLAttributeEquivalent(CSSPropertyID id, const Qualifi edName& attrName)
293 : HTMLElementEquivalent(id) 293 : HTMLElementEquivalent(id)
294 , m_attrName(attrName) 294 , m_attrName(attrName)
295 { 295 {
296 } 296 }
297 297
298 bool HTMLAttributeEquivalent::valueIsPresentInStyle(HTMLElement* element, StyleP ropertySet* style) const 298 bool HTMLAttributeEquivalent::valueIsPresentInStyle(HTMLElement* element, StyleP ropertySet* style) const
299 { 299 {
300 CSSValue* value = attributeValueAsCSSValue(element); 300 CSSValue* value = attributeValueAsCSSValue(element);
301 CSSValue* styleValue = style->getPropertyCSSValue(m_propertyID); 301 const CSSValue* styleValue = style->getPropertyCSSValue(m_propertyID);
302 302
303 return compareCSSValuePtr(value, styleValue); 303 return compareCSSValuePtr(value, styleValue);
304 } 304 }
305 305
306 void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) const 306 void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) const
307 { 307 {
308 if (CSSValue* value = attributeValueAsCSSValue(element)) 308 if (CSSValue* value = attributeValueAsCSSValue(element))
309 style->setProperty(m_propertyID, value->cssText()); 309 style->setProperty(m_propertyID, value->cssText());
310 } 310 }
311 311
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 385
386 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value) 386 EditingStyle::EditingStyle(CSSPropertyID propertyID, const String& value)
387 : m_mutableStyle(nullptr) 387 : m_mutableStyle(nullptr)
388 , m_isMonospaceFont(false) 388 , m_isMonospaceFont(false)
389 , m_fontSizeDelta(NoFontDelta) 389 , m_fontSizeDelta(NoFontDelta)
390 { 390 {
391 setProperty(propertyID, value); 391 setProperty(propertyID, value);
392 m_isVerticalAlign = propertyID == CSSPropertyVerticalAlign && (value == "sub " || value == "super"); 392 m_isVerticalAlign = propertyID == CSSPropertyVerticalAlign && (value == "sub " || value == "super");
393 } 393 }
394 394
395 static Color cssValueToColor(CSSValue* colorValue) 395 static Color cssValueToColor(const CSSValue* colorValue)
396 { 396 {
397 if (!colorValue || (!colorValue->isColorValue() && !colorValue->isPrimitiveV alue())) 397 if (!colorValue || (!colorValue->isColorValue() && !colorValue->isPrimitiveV alue()))
398 return Color::transparent; 398 return Color::transparent;
399 399
400 if (colorValue->isColorValue()) 400 if (colorValue->isColorValue())
401 return toCSSColorValue(colorValue)->value(); 401 return toCSSColorValue(colorValue)->value();
402 402
403 Color color = 0; 403 Color color = 0;
404 // FIXME: Why ignore the return value? 404 // FIXME: Why ignore the return value?
405 CSSParser::parseColor(color, colorValue->cssText()); 405 CSSParser::parseColor(color, colorValue->cssText());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 { 463 {
464 if (isTabHTMLSpanElementTextNode(node)) 464 if (isTabHTMLSpanElementTextNode(node))
465 node = tabSpanElement(node)->parentNode(); 465 node = tabSpanElement(node)->parentNode();
466 else if (isTabHTMLSpanElement(node)) 466 else if (isTabHTMLSpanElement(node))
467 node = node->parentNode(); 467 node = node->parentNode();
468 468
469 CSSComputedStyleDeclaration* computedStyleAtPosition = CSSComputedStyleDecla ration::create(node); 469 CSSComputedStyleDeclaration* computedStyleAtPosition = CSSComputedStyleDecla ration::create(node);
470 m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosi tion ? computedStyleAtPosition->copyProperties() : editingStyleFromComputedStyle (computedStyleAtPosition); 470 m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosi tion ? computedStyleAtPosition->copyProperties() : editingStyleFromComputedStyle (computedStyleAtPosition);
471 471
472 if (propertiesToInclude == EditingPropertiesInEffect) { 472 if (propertiesToInclude == EditingPropertiesInEffect) {
473 if (CSSValue* value = backgroundColorValueInEffect(node)) 473 if (const CSSValue* value = backgroundColorValueInEffect(node))
474 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssTe xt()); 474 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssTe xt());
475 if (CSSValue* value = computedStyleAtPosition->getPropertyCSSValue(CSSPr opertyWebkitTextDecorationsInEffect)) 475 if (const CSSValue* value = computedStyleAtPosition->getPropertyCSSValue (CSSPropertyWebkitTextDecorationsInEffect))
476 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssTex t()); 476 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssTex t());
477 } 477 }
478 478
479 if (node && node->ensureComputedStyle()) { 479 if (node && node->ensureComputedStyle()) {
480 const ComputedStyle* computedStyle = node->ensureComputedStyle(); 480 const ComputedStyle* computedStyle = node->ensureComputedStyle();
481 removeTextFillAndStrokeColorsIfNeeded(computedStyle); 481 removeTextFillAndStrokeColorsIfNeeded(computedStyle);
482 replaceFontSizeByKeywordIfPossible(computedStyle, computedStyleAtPositio n); 482 replaceFontSizeByKeywordIfPossible(computedStyle, computedStyleAtPositio n);
483 } 483 }
484 484
485 m_isMonospaceFont = computedStyleAtPosition->isMonospaceFont(); 485 m_isMonospaceFont = computedStyleAtPosition->isMonospaceFont();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 if (!m_mutableStyle) 517 if (!m_mutableStyle)
518 return; 518 return;
519 519
520 if (m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize)) { 520 if (m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize)) {
521 // Explicit font size overrides any delta. 521 // Explicit font size overrides any delta.
522 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 522 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
523 return; 523 return;
524 } 524 }
525 525
526 // Get the adjustment amount out of the style. 526 // Get the adjustment amount out of the style.
527 CSSValue* value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebkitFontS izeDelta); 527 const CSSValue* value = m_mutableStyle->getPropertyCSSValue(CSSPropertyWebki tFontSizeDelta);
528 if (!value || !value->isPrimitiveValue()) 528 if (!value || !value->isPrimitiveValue())
529 return; 529 return;
530 530
531 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 531 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
532 532
533 // Only PX handled now. If we handle more types in the future, perhaps 533 // Only PX handled now. If we handle more types in the future, perhaps
534 // a switch statement here would be more appropriate. 534 // a switch statement here would be more appropriate.
535 if (!primitiveValue->isPx()) 535 if (!primitiveValue->isPx())
536 return; 536 return;
537 537
538 m_fontSizeDelta = primitiveValue->getFloatValue(); 538 m_fontSizeDelta = primitiveValue->getFloatValue();
539 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta); 539 m_mutableStyle->removeProperty(CSSPropertyWebkitFontSizeDelta);
540 } 540 }
541 541
542 bool EditingStyle::isEmpty() const 542 bool EditingStyle::isEmpty() const
543 { 543 {
544 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && m_fontSizeDelta == NoFontDelta; 544 return (!m_mutableStyle || m_mutableStyle->isEmpty()) && m_fontSizeDelta == NoFontDelta;
545 } 545 }
546 546
547 bool EditingStyle::textDirection(WritingDirection& writingDirection) const 547 bool EditingStyle::textDirection(WritingDirection& writingDirection) const
548 { 548 {
549 if (!m_mutableStyle) 549 if (!m_mutableStyle)
550 return false; 550 return false;
551 551
552 CSSValue* unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnico deBidi); 552 const CSSValue* unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropert yUnicodeBidi);
553 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 553 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
554 return false; 554 return false;
555 555
556 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID() ; 556 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValueID() ;
557 if (isEmbedOrIsolate(unicodeBidiValue)) { 557 if (isEmbedOrIsolate(unicodeBidiValue)) {
558 CSSValue* direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDir ection); 558 const CSSValue* direction = m_mutableStyle->getPropertyCSSValue(CSSPrope rtyDirection);
559 if (!direction || !direction->isPrimitiveValue()) 559 if (!direction || !direction->isPrimitiveValue())
560 return false; 560 return false;
561 561
562 writingDirection = toCSSPrimitiveValue(direction)->getValueID() == CSSVa lueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection; 562 writingDirection = toCSSPrimitiveValue(direction)->getValueID() == CSSVa lueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
563 563
564 return true; 564 return true;
565 } 565 }
566 566
567 if (unicodeBidiValue == CSSValueNormal) { 567 if (unicodeBidiValue == CSSValueNormal) {
568 writingDirection = NaturalWritingDirection; 568 writingDirection = NaturalWritingDirection;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 unsigned propertyCount = nodeStyle->propertyCount(); 689 unsigned propertyCount = nodeStyle->propertyCount();
690 for (unsigned i = 0; i < propertyCount; ++i) 690 for (unsigned i = 0; i < propertyCount; ++i)
691 m_mutableStyle->removeProperty(nodeStyle->propertyAt(i).id()); 691 m_mutableStyle->removeProperty(nodeStyle->propertyAt(i).id());
692 } 692 }
693 693
694 void EditingStyle::collapseTextDecorationProperties() 694 void EditingStyle::collapseTextDecorationProperties()
695 { 695 {
696 if (!m_mutableStyle) 696 if (!m_mutableStyle)
697 return; 697 return;
698 698
699 CSSValue* textDecorationsInEffect = m_mutableStyle->getPropertyCSSValue(CSSP ropertyWebkitTextDecorationsInEffect); 699 const CSSValue* textDecorationsInEffect = m_mutableStyle->getPropertyCSSValu e(CSSPropertyWebkitTextDecorationsInEffect);
700 if (!textDecorationsInEffect) 700 if (!textDecorationsInEffect)
701 return; 701 return;
702 702
703 if (textDecorationsInEffect->isValueList()) 703 if (textDecorationsInEffect->isValueList())
704 m_mutableStyle->setProperty(textDecorationPropertyForEditing(), textDeco rationsInEffect->cssText(), m_mutableStyle->propertyIsImportant(textDecorationPr opertyForEditing())); 704 m_mutableStyle->setProperty(textDecorationPropertyForEditing(), textDeco rationsInEffect->cssText(), m_mutableStyle->propertyIsImportant(textDecorationPr opertyForEditing()));
705 else 705 else
706 m_mutableStyle->removeProperty(textDecorationPropertyForEditing()); 706 m_mutableStyle->removeProperty(textDecorationPropertyForEditing());
707 m_mutableStyle->removeProperty(CSSPropertyWebkitTextDecorationsInEffect); 707 m_mutableStyle->removeProperty(CSSPropertyWebkitTextDecorationsInEffect);
708 } 708 }
709 709
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 TriState state = FalseTriState; 762 TriState state = FalseTriState;
763 bool nodeIsStart = true; 763 bool nodeIsStart = true;
764 for (Node& node : NodeTraversal::startsAt(*selection.start().anchorNode())) { 764 for (Node& node : NodeTraversal::startsAt(*selection.start().anchorNode())) {
765 if (node.layoutObject() && node.hasEditableStyle()) { 765 if (node.layoutObject() && node.hasEditableStyle()) {
766 CSSComputedStyleDeclaration* nodeStyle = CSSComputedStyleDeclaration ::create(&node); 766 CSSComputedStyleDeclaration* nodeStyle = CSSComputedStyleDeclaration ::create(&node);
767 if (nodeStyle) { 767 if (nodeStyle) {
768 // If the selected element has <sub> or <sup> ancestor element, apply the corresponding 768 // If the selected element has <sub> or <sup> ancestor element, apply the corresponding
769 // style(vertical-align) to it so that document.queryCommandStat e() works with the style. 769 // style(vertical-align) to it so that document.queryCommandStat e() works with the style.
770 // See bug http://crbug.com/582225. 770 // See bug http://crbug.com/582225.
771 if (m_isVerticalAlign && getIdentifierValue(nodeStyle, CSSProper tyVerticalAlign) == CSSValueBaseline) { 771 if (m_isVerticalAlign && getIdentifierValue(nodeStyle, CSSProper tyVerticalAlign) == CSSValueBaseline) {
772 CSSPrimitiveValue* verticalAlign = toCSSPrimitiveValue(m_mut ableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign)); 772 const CSSPrimitiveValue* verticalAlign = toCSSPrimitiveValue (m_mutableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign));
773 if (hasAncestorVerticalAlignStyle(node, verticalAlign->getVa lueID())) 773 if (hasAncestorVerticalAlignStyle(node, verticalAlign->getVa lueID()))
774 node.mutableComputedStyle()->setVerticalAlign(verticalAl ign->convertTo<EVerticalAlign>()); 774 node.mutableComputedStyle()->setVerticalAlign(verticalAl ign->convertTo<EVerticalAlign>());
775 } 775 }
776 776
777 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without chec king if node.isTextNode() 777 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without chec king if node.isTextNode()
778 // because the node can be an element node. See bug http://crbug .com/584939. 778 // because the node can be an element node. See bug http://crbug .com/584939.
779 TriState nodeState = triStateOfStyle(nodeStyle, EditingStyle::Do NotIgnoreTextOnlyProperties); 779 TriState nodeState = triStateOfStyle(nodeStyle, EditingStyle::Do NotIgnoreTextOnlyProperties);
780 if (nodeIsStart) { 780 if (nodeIsStart) {
781 state = nodeState; 781 state = nodeState;
782 nodeIsStart = false; 782 nodeIsStart = false;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 { 1008 {
1009 if (!m_mutableStyle) 1009 if (!m_mutableStyle)
1010 return; 1010 return;
1011 1011
1012 // ReplaceSelectionCommand::handleStyleSpans() requires that this function o nly removes the editing style. 1012 // ReplaceSelectionCommand::handleStyleSpans() requires that this function o nly removes the editing style.
1013 // If this function was modified in the future to delete all redundant prope rties, then add a boolean value to indicate 1013 // If this function was modified in the future to delete all redundant prope rties, then add a boolean value to indicate
1014 // which one of editingStyleAtPosition or computedStyle is called. 1014 // which one of editingStyleAtPosition or computedStyle is called.
1015 EditingStyle* editingStyleAtPosition = EditingStyle::create(position, Editin gPropertiesInEffect); 1015 EditingStyle* editingStyleAtPosition = EditingStyle::create(position, Editin gPropertiesInEffect);
1016 StylePropertySet* styleAtPosition = editingStyleAtPosition->m_mutableStyle.g et(); 1016 StylePropertySet* styleAtPosition = editingStyleAtPosition->m_mutableStyle.g et();
1017 1017
1018 CSSValue* unicodeBidi = nullptr; 1018 const CSSValue* unicodeBidi = nullptr;
1019 CSSValue* direction = nullptr; 1019 const CSSValue* direction = nullptr;
1020 if (shouldPreserveWritingDirection == PreserveWritingDirection) { 1020 if (shouldPreserveWritingDirection == PreserveWritingDirection) {
1021 unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi ); 1021 unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi );
1022 direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection); 1022 direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
1023 } 1023 }
1024 1024
1025 m_mutableStyle->removeEquivalentProperties(styleAtPosition); 1025 m_mutableStyle->removeEquivalentProperties(styleAtPosition);
1026 1026
1027 if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) == textAlignResolvin gStartAndEnd(styleAtPosition)) 1027 if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) == textAlignResolvin gStartAndEnd(styleAtPosition))
1028 m_mutableStyle->removeProperty(CSSPropertyTextAlign); 1028 m_mutableStyle->removeProperty(CSSPropertyTextAlign);
1029 1029
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 break; 1148 break;
1149 if (node.isStyledElement() && !isMailHTMLBlockquoteElement(&node)) { 1149 if (node.isStyledElement() && !isMailHTMLBlockquoteElement(&node)) {
1150 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(&node) , EditingStyle::DoNotOverrideValues, 1150 wrappingStyle->mergeInlineAndImplicitStyleOfElement(toElement(&node) , EditingStyle::DoNotOverrideValues,
1151 EditingStyle::EditingPropertiesInEffect); 1151 EditingStyle::EditingPropertiesInEffect);
1152 } 1152 }
1153 } 1153 }
1154 1154
1155 return wrappingStyle; 1155 return wrappingStyle;
1156 } 1156 }
1157 1157
1158 static void mergeTextDecorationValues(CSSValueList* mergedValue, const CSSValueL ist* valueToMerge) 1158 static CSSValueList* mergeTextDecorationValues(const CSSValueList* mergedValue, const CSSValueList* valueToMerge)
1159 { 1159 {
1160 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::create Identifier(CSSValueUnderline))); 1160 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::create Identifier(CSSValueUnderline)));
1161 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue::crea teIdentifier(CSSValueLineThrough))); 1161 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue::crea teIdentifier(CSSValueLineThrough)));
1162 CSSValueList* result = mergedValue->copy();
1162 if (valueToMerge->hasValue(underline) && !mergedValue->hasValue(underline)) 1163 if (valueToMerge->hasValue(underline) && !mergedValue->hasValue(underline))
1163 mergedValue->append(&underline); 1164 result->append(&underline);
1164 1165
1165 if (valueToMerge->hasValue(lineThrough) && !mergedValue->hasValue(lineThroug h)) 1166 if (valueToMerge->hasValue(lineThrough) && !mergedValue->hasValue(lineThroug h))
1166 mergedValue->append(&lineThrough); 1167 result->append(&lineThrough);
1168
1169 return result;
1167 } 1170 }
1168 1171
1169 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride Mode mode) 1172 void EditingStyle::mergeStyle(const StylePropertySet* style, CSSPropertyOverride Mode mode)
1170 { 1173 {
1171 if (!style) 1174 if (!style)
1172 return; 1175 return;
1173 1176
1174 if (!m_mutableStyle) { 1177 if (!m_mutableStyle) {
1175 m_mutableStyle = style->mutableCopy(); 1178 m_mutableStyle = style->mutableCopy();
1176 return; 1179 return;
1177 } 1180 }
1178 1181
1179 unsigned propertyCount = style->propertyCount(); 1182 unsigned propertyCount = style->propertyCount();
1180 for (unsigned i = 0; i < propertyCount; ++i) { 1183 for (unsigned i = 0; i < propertyCount; ++i) {
1181 StylePropertySet::PropertyReference property = style->propertyAt(i); 1184 StylePropertySet::PropertyReference property = style->propertyAt(i);
1182 CSSValue* value = m_mutableStyle->getPropertyCSSValue(property.id()); 1185 const CSSValue* value = m_mutableStyle->getPropertyCSSValue(property.id( ));
1183 1186
1184 // text decorations never override values 1187 // text decorations never override values
1185 if ((property.id() == textDecorationPropertyForEditing() || property.id( ) == CSSPropertyWebkitTextDecorationsInEffect) && property.value()->isValueList( ) && value) { 1188 if ((property.id() == textDecorationPropertyForEditing() || property.id( ) == CSSPropertyWebkitTextDecorationsInEffect) && property.value()->isValueList( ) && value) {
1186 if (value->isValueList()) { 1189 if (value->isValueList()) {
1187 mergeTextDecorationValues(toCSSValueList(value), toCSSValueList( property.value())); 1190 CSSValueList* result = mergeTextDecorationValues(toCSSValueList( value), toCSSValueList(property.value()));
1191 m_mutableStyle->setProperty(property.id(), result, property.isIm portant());
sashab 2016/06/06 05:50:32 This is the only behavior change that needs real r
1188 continue; 1192 continue;
1189 } 1193 }
1190 value = nullptr; // text-decoration: none is equivalent to not havin g the property 1194 value = nullptr; // text-decoration: none is equivalent to not havin g the property
1191 } 1195 }
1192 1196
1193 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value)) 1197 if (mode == OverrideValues || (mode == DoNotOverrideValues && !value))
1194 m_mutableStyle->setProperty(property.id(), property.value()->cssText (), property.isImportant()); 1198 m_mutableStyle->setProperty(property.id(), property.value()->cssText (), property.isImportant());
1195 } 1199 }
1196 } 1200 }
1197 1201
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 CSSComputedStyleDeclaration* computedStyleForElement = CSSComputedStyleDecla ration::create(element); 1233 CSSComputedStyleDeclaration* computedStyleForElement = CSSComputedStyleDecla ration::create(element);
1230 MutableStylePropertySet* fromComputedStyle = MutableStylePropertySet::create (HTMLQuirksMode); 1234 MutableStylePropertySet* fromComputedStyle = MutableStylePropertySet::create (HTMLQuirksMode);
1231 { 1235 {
1232 unsigned propertyCount = m_mutableStyle->propertyCount(); 1236 unsigned propertyCount = m_mutableStyle->propertyCount();
1233 for (unsigned i = 0; i < propertyCount; ++i) { 1237 for (unsigned i = 0; i < propertyCount; ++i) {
1234 StylePropertySet::PropertyReference property = m_mutableStyle->prope rtyAt(i); 1238 StylePropertySet::PropertyReference property = m_mutableStyle->prope rtyAt(i);
1235 CSSValue* value = property.value(); 1239 CSSValue* value = property.value();
1236 if (!value->isPrimitiveValue()) 1240 if (!value->isPrimitiveValue())
1237 continue; 1241 continue;
1238 if (toCSSPrimitiveValue(value)->isPercentage()) { 1242 if (toCSSPrimitiveValue(value)->isPercentage()) {
1239 if (CSSValue* computedPropertyValue = computedStyleForElement->g etPropertyCSSValue(property.id())) 1243 if (const CSSValue* computedPropertyValue = computedStyleForElem ent->getPropertyCSSValue(property.id()))
1240 fromComputedStyle->addRespectingCascade(CSSProperty(property .id(), computedPropertyValue)); 1244 fromComputedStyle->addRespectingCascade(CSSProperty(property .id(), computedPropertyValue));
1241 } 1245 }
1242 } 1246 }
1243 } 1247 }
1244 m_mutableStyle->mergeAndOverrideOnConflict(fromComputedStyle); 1248 m_mutableStyle->mergeAndOverrideOnConflict(fromComputedStyle);
1245 } 1249 }
1246 1250
1247 static void removePropertiesInStyle(MutableStylePropertySet* styleToRemoveProper tiesFrom, StylePropertySet* style) 1251 static void removePropertiesInStyle(MutableStylePropertySet* styleToRemoveProper tiesFrom, StylePropertySet* style)
1248 { 1252 {
1249 unsigned propertyCount = style->propertyCount(); 1253 unsigned propertyCount = style->propertyCount();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 void EditingStyle::forceInline() 1327 void EditingStyle::forceInline()
1324 { 1328 {
1325 if (!m_mutableStyle) 1329 if (!m_mutableStyle)
1326 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode); 1330 m_mutableStyle = MutableStylePropertySet::create(HTMLQuirksMode);
1327 const bool propertyIsImportant = true; 1331 const bool propertyIsImportant = true;
1328 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant); 1332 m_mutableStyle->setProperty(CSSPropertyDisplay, CSSValueInline, propertyIsIm portant);
1329 } 1333 }
1330 1334
1331 int EditingStyle::legacyFontSize(Document* document) const 1335 int EditingStyle::legacyFontSize(Document* document) const
1332 { 1336 {
1333 CSSValue* cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyFontSize ); 1337 const CSSValue* cssValue = m_mutableStyle->getPropertyCSSValue(CSSPropertyFo ntSize);
1334 if (!cssValue || !cssValue->isPrimitiveValue()) 1338 if (!cssValue || !cssValue->isPrimitiveValue())
1335 return 0; 1339 return 0;
1336 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue), 1340 return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue),
1337 m_isMonospaceFont, AlwaysUseLegacyFontSize); 1341 m_isMonospaceFont, AlwaysUseLegacyFontSize);
1338 } 1342 }
1339 1343
1340 EditingStyle* EditingStyle::styleAtSelectionStart(const VisibleSelection& select ion, bool shouldUseBackgroundColorInEffect, MutableStylePropertySet* styleToChec k) 1344 EditingStyle* EditingStyle::styleAtSelectionStart(const VisibleSelection& select ion, bool shouldUseBackgroundColorInEffect, MutableStylePropertySet* styleToChec k)
1341 { 1345 {
1342 if (selection.isNone()) 1346 if (selection.isNone())
1343 return nullptr; 1347 return nullptr;
(...skipping 24 matching lines...) Expand all
1368 // Find the ancestor that has CSSValueSub or CSSValueSuper as the value of CSS vertical-align property. 1372 // Find the ancestor that has CSSValueSub or CSSValueSuper as the value of CSS vertical-align property.
1369 if (getIdentifierValue(elementStyle, CSSPropertyVerticalAlign) == CSSVal ueBaseline && hasAncestorVerticalAlignStyle(*element, valueID)) 1373 if (getIdentifierValue(elementStyle, CSSPropertyVerticalAlign) == CSSVal ueBaseline && hasAncestorVerticalAlignStyle(*element, valueID))
1370 style->m_mutableStyle->setProperty(CSSPropertyVerticalAlign, valueID ); 1374 style->m_mutableStyle->setProperty(CSSPropertyVerticalAlign, valueID );
1371 } 1375 }
1372 1376
1373 // If background color is transparent, traverse parent nodes until we hit a different value or document root 1377 // If background color is transparent, traverse parent nodes until we hit a different value or document root
1374 // Also, if the selection is a range, ignore the background color at the sta rt of selection, 1378 // Also, if the selection is a range, ignore the background color at the sta rt of selection,
1375 // and find the background color of the common ancestor. 1379 // and find the background color of the common ancestor.
1376 if (shouldUseBackgroundColorInEffect && (selection.isRange() || hasTranspare ntBackgroundColor(style->m_mutableStyle.get()))) { 1380 if (shouldUseBackgroundColorInEffect && (selection.isRange() || hasTranspare ntBackgroundColor(style->m_mutableStyle.get()))) {
1377 const EphemeralRange range(selection.toNormalizedEphemeralRange()); 1381 const EphemeralRange range(selection.toNormalizedEphemeralRange());
1378 if (CSSValue* value = backgroundColorValueInEffect(Range::commonAncestor Container(range.startPosition().computeContainerNode(), range.endPosition().comp uteContainerNode()))) 1382 if (const CSSValue* value = backgroundColorValueInEffect(Range::commonAn cestorContainer(range.startPosition().computeContainerNode(), range.endPosition( ).computeContainerNode())))
1379 style->setProperty(CSSPropertyBackgroundColor, value->cssText()); 1383 style->setProperty(CSSPropertyBackgroundColor, value->cssText());
1380 } 1384 }
1381 1385
1382 return style; 1386 return style;
1383 } 1387 }
1384 1388
1385 static bool isUnicodeBidiNestedOrMultipleEmbeddings(CSSValueID valueID) 1389 static bool isUnicodeBidiNestedOrMultipleEmbeddings(CSSValueID valueID)
1386 { 1390 {
1387 return valueID == CSSValueEmbed || valueID == CSSValueBidiOverride 1391 return valueID == CSSValueEmbed || valueID == CSSValueBidiOverride
1388 || valueID == CSSValueWebkitIsolate || valueID == CSSValueWebkitIsolateO verride || valueID == CSSValueWebkitPlaintext 1392 || valueID == CSSValueWebkitIsolate || valueID == CSSValueWebkitIsolateO verride || valueID == CSSValueWebkitPlaintext
(...skipping 17 matching lines...) Expand all
1406 if (selection.isRange()) { 1410 if (selection.isRange()) {
1407 end = mostBackwardCaretPosition(selection.end()); 1411 end = mostBackwardCaretPosition(selection.end());
1408 1412
1409 DCHECK(end.document()); 1413 DCHECK(end.document());
1410 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); 1414 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE quivalent(), end.parentAnchoredEquivalent())->pastLastNode();
1411 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { 1415 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) {
1412 if (!n->isStyledElement()) 1416 if (!n->isStyledElement())
1413 continue; 1417 continue;
1414 1418
1415 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(n); 1419 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::cr eate(n);
1416 CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicod eBidi); 1420 const CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSProperty UnicodeBidi);
1417 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1421 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
1418 continue; 1422 continue;
1419 1423
1420 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getV alueID(); 1424 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getV alueID();
1421 if (isUnicodeBidiNestedOrMultipleEmbeddings(unicodeBidiValue)) 1425 if (isUnicodeBidiNestedOrMultipleEmbeddings(unicodeBidiValue))
1422 return NaturalWritingDirection; 1426 return NaturalWritingDirection;
1423 } 1427 }
1424 } 1428 }
1425 1429
1426 if (selection.isCaret()) { 1430 if (selection.isCaret()) {
(...skipping 12 matching lines...) Expand all
1439 WritingDirection foundDirection = NaturalWritingDirection; 1443 WritingDirection foundDirection = NaturalWritingDirection;
1440 1444
1441 for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*node)) { 1445 for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*node)) {
1442 if (runner == block) 1446 if (runner == block)
1443 break; 1447 break;
1444 if (!runner.isStyledElement()) 1448 if (!runner.isStyledElement())
1445 continue; 1449 continue;
1446 1450
1447 Element* element = &toElement(runner); 1451 Element* element = &toElement(runner);
1448 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::create (element); 1452 CSSComputedStyleDeclaration* style = CSSComputedStyleDeclaration::create (element);
1449 CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBid i); 1453 const CSSValue* unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnic odeBidi);
1450 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) 1454 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue())
1451 continue; 1455 continue;
1452 1456
1453 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID(); 1457 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi)->getValue ID();
1454 if (unicodeBidiValue == CSSValueNormal) 1458 if (unicodeBidiValue == CSSValueNormal)
1455 continue; 1459 continue;
1456 1460
1457 if (unicodeBidiValue == CSSValueBidiOverride) 1461 if (unicodeBidiValue == CSSValueBidiOverride)
1458 return NaturalWritingDirection; 1462 return NaturalWritingDirection;
1459 1463
1460 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue; 1464 DCHECK(isEmbedOrIsolate(unicodeBidiValue)) << unicodeBidiValue;
1461 CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirection); 1465 const CSSValue* direction = style->getPropertyCSSValue(CSSPropertyDirect ion);
1462 if (!direction || !direction->isPrimitiveValue()) 1466 if (!direction || !direction->isPrimitiveValue())
1463 continue; 1467 continue;
1464 1468
1465 int directionValue = toCSSPrimitiveValue(direction)->getValueID(); 1469 int directionValue = toCSSPrimitiveValue(direction)->getValueID();
1466 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl) 1470 if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
1467 continue; 1471 continue;
1468 1472
1469 if (foundDirection != NaturalWritingDirection) 1473 if (foundDirection != NaturalWritingDirection)
1470 return NaturalWritingDirection; 1474 return NaturalWritingDirection;
1471 1475
1472 // In the range case, make sure that the embedding element persists unti l the end of the range. 1476 // In the range case, make sure that the embedding element persists unti l the end of the range.
1473 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element)) 1477 if (selection.isRange() && !end.anchorNode()->isDescendantOf(element))
1474 return NaturalWritingDirection; 1478 return NaturalWritingDirection;
1475 1479
1476 foundDirection = directionValue == CSSValueLtr ? LeftToRightWritingDirec tion : RightToLeftWritingDirection; 1480 foundDirection = directionValue == CSSValueLtr ? LeftToRightWritingDirec tion : RightToLeftWritingDirection;
1477 } 1481 }
1478 hasNestedOrMultipleEmbeddings = false; 1482 hasNestedOrMultipleEmbeddings = false;
1479 return foundDirection; 1483 return foundDirection;
1480 } 1484 }
1481 1485
1482 DEFINE_TRACE(EditingStyle) 1486 DEFINE_TRACE(EditingStyle)
1483 { 1487 {
1484 visitor->trace(m_mutableStyle); 1488 visitor->trace(m_mutableStyle);
1485 } 1489 }
1486 1490
1487 static void reconcileTextDecorationProperties(MutableStylePropertySet* style) 1491 static void reconcileTextDecorationProperties(MutableStylePropertySet* style)
1488 { 1492 {
1489 CSSValue* textDecorationsInEffect = style->getPropertyCSSValue(CSSPropertyWe bkitTextDecorationsInEffect); 1493 const CSSValue* textDecorationsInEffect = style->getPropertyCSSValue(CSSProp ertyWebkitTextDecorationsInEffect);
1490 CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationProperty ForEditing()); 1494 const CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationPr opertyForEditing());
1491 // We shouldn't have both text-decoration and -webkit-text-decorations-in-ef fect because that wouldn't make sense. 1495 // We shouldn't have both text-decoration and -webkit-text-decorations-in-ef fect because that wouldn't make sense.
1492 DCHECK(!textDecorationsInEffect || !textDecoration); 1496 DCHECK(!textDecorationsInEffect || !textDecoration);
1493 if (textDecorationsInEffect) { 1497 if (textDecorationsInEffect) {
1494 style->setProperty(textDecorationPropertyForEditing(), textDecorationsIn Effect->cssText()); 1498 style->setProperty(textDecorationPropertyForEditing(), textDecorationsIn Effect->cssText());
1495 style->removeProperty(CSSPropertyWebkitTextDecorationsInEffect); 1499 style->removeProperty(CSSPropertyWebkitTextDecorationsInEffect);
1496 textDecoration = textDecorationsInEffect; 1500 textDecoration = textDecorationsInEffect;
1497 } 1501 }
1498 1502
1499 // If text-decoration is set to "none", remove the property because we don't want to add redundant "text-decoration: none". 1503 // If text-decoration is set to "none", remove the property because we don't want to add redundant "text-decoration: none".
1500 if (textDecoration && !textDecoration->isValueList()) 1504 if (textDecoration && !textDecoration->isValueList())
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 } 1560 }
1557 1561
1558 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle); 1562 int fontStyle = getIdentifierValue(style, CSSPropertyFontStyle);
1559 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) { 1563 if (fontStyle == CSSValueItalic || fontStyle == CSSValueOblique) {
1560 style->removeProperty(CSSPropertyFontStyle); 1564 style->removeProperty(CSSPropertyFontStyle);
1561 m_applyItalic = true; 1565 m_applyItalic = true;
1562 } 1566 }
1563 1567
1564 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect 1568 // Assuming reconcileTextDecorationProperties has been called, there should not be -webkit-text-decorations-in-effect
1565 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList. 1569 // Furthermore, text-decoration: none has been trimmed so that text-decorati on property is always a CSSValueList.
1566 CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationProperty ForEditing()); 1570 const CSSValue* textDecoration = style->getPropertyCSSValue(textDecorationPr opertyForEditing());
1567 if (textDecoration && textDecoration->isValueList()) { 1571 if (textDecoration && textDecoration->isValueList()) {
1568 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::cr eateIdentifier(CSSValueUnderline))); 1572 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, underline, (CSSPrimitiveValue::cr eateIdentifier(CSSValueUnderline)));
1569 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue:: createIdentifier(CSSValueLineThrough))); 1573 DEFINE_STATIC_LOCAL(CSSPrimitiveValue, lineThrough, (CSSPrimitiveValue:: createIdentifier(CSSValueLineThrough)));
1570 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy() ; 1574 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy() ;
1571 if (newTextDecoration->removeAll(underline)) 1575 if (newTextDecoration->removeAll(underline))
1572 m_applyUnderline = true; 1576 m_applyUnderline = true;
1573 if (newTextDecoration->removeAll(lineThrough)) 1577 if (newTextDecoration->removeAll(lineThrough))
1574 m_applyLineThrough = true; 1578 m_applyLineThrough = true;
1575 1579
1576 // If trimTextDecorations, delete underline and line-through 1580 // If trimTextDecorations, delete underline and line-through
(...skipping 15 matching lines...) Expand all
1592 if (style->getPropertyCSSValue(CSSPropertyColor)) { 1596 if (style->getPropertyCSSValue(CSSPropertyColor)) {
1593 m_applyFontColor = getFontColor(style).serialized(); 1597 m_applyFontColor = getFontColor(style).serialized();
1594 style->removeProperty(CSSPropertyColor); 1598 style->removeProperty(CSSPropertyColor);
1595 } 1599 }
1596 1600
1597 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily); 1601 m_applyFontFace = style->getPropertyValue(CSSPropertyFontFamily);
1598 // Remove double quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448 1602 // Remove double quotes for Outlook 2007 compatibility. See https://bugs.web kit.org/show_bug.cgi?id=79448
1599 m_applyFontFace.replace('"', ""); 1603 m_applyFontFace.replace('"', "");
1600 style->removeProperty(CSSPropertyFontFamily); 1604 style->removeProperty(CSSPropertyFontFamily);
1601 1605
1602 if (CSSValue* fontSize = style->getPropertyCSSValue(CSSPropertyFontSize)) { 1606 if (const CSSValue* fontSize = style->getPropertyCSSValue(CSSPropertyFontSiz e)) {
1603 if (!fontSize->isPrimitiveValue()) { 1607 if (!fontSize->isPrimitiveValue()) {
1604 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size. 1608 style->removeProperty(CSSPropertyFontSize); // Can't make sense of t he number. Put no font size.
1605 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValuesM atch)) { 1609 } else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toC SSPrimitiveValue(fontSize), isMonospaceFont, UseLegacyFontSizeOnlyIfPixelValuesM atch)) {
1606 m_applyFontSize = String::number(legacyFontSize); 1610 m_applyFontSize = String::number(legacyFontSize);
1607 style->removeProperty(CSSPropertyFontSize); 1611 style->removeProperty(CSSPropertyFontSize);
1608 } 1612 }
1609 } 1613 }
1610 } 1614 }
1611 1615
1612 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertID, CSSValue* refTextDecoration) 1616 static void diffTextDecorations(MutableStylePropertySet* style, CSSPropertyID pr opertyID, const CSSValue* refTextDecoration)
1613 { 1617 {
1614 CSSValue* textDecoration = style->getPropertyCSSValue(propertID); 1618 const CSSValue* textDecoration = style->getPropertyCSSValue(propertyID);
sashab 2016/06/06 05:50:32 Typo fix hehe
1615 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList()) 1619 if (!textDecoration || !textDecoration->isValueList() || !refTextDecoration || !refTextDecoration->isValueList())
1616 return; 1620 return;
1617 1621
1618 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy(); 1622 CSSValueList* newTextDecoration = toCSSValueList(textDecoration)->copy();
1619 CSSValueList* valuesInRefTextDecoration = toCSSValueList(refTextDecoration); 1623 const CSSValueList* valuesInRefTextDecoration = toCSSValueList(refTextDecora tion);
1620 1624
1621 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++) 1625 for (size_t i = 0; i < valuesInRefTextDecoration->length(); i++)
1622 newTextDecoration->removeAll(*valuesInRefTextDecoration->item(i)); 1626 newTextDecoration->removeAll(*valuesInRefTextDecoration->item(i));
1623 1627
1624 setTextDecorationProperty(style, newTextDecoration, propertID); 1628 setTextDecorationProperty(style, newTextDecoration, propertyID);
1625 } 1629 }
1626 1630
1627 static bool fontWeightIsBold(CSSValue* fontWeight) 1631 static bool fontWeightIsBold(const CSSValue* fontWeight)
1628 { 1632 {
1629 if (!fontWeight->isPrimitiveValue()) 1633 if (!fontWeight->isPrimitiveValue())
1630 return false; 1634 return false;
1631 1635
1632 // Because b tag can only bold text, there are only two states in plain html : bold and not bold. 1636 // Because b tag can only bold text, there are only two states in plain html : bold and not bold.
1633 // Collapse all other values to either one of these two states for editing p urposes. 1637 // Collapse all other values to either one of these two states for editing p urposes.
1634 switch (toCSSPrimitiveValue(fontWeight)->getValueID()) { 1638 switch (toCSSPrimitiveValue(fontWeight)->getValueID()) {
1635 case CSSValue100: 1639 case CSSValue100:
1636 case CSSValue200: 1640 case CSSValue200:
1637 case CSSValue300: 1641 case CSSValue300:
1638 case CSSValue400: 1642 case CSSValue400:
1639 case CSSValue500: 1643 case CSSValue500:
1640 case CSSValueNormal: 1644 case CSSValueNormal:
1641 return false; 1645 return false;
1642 case CSSValueBold: 1646 case CSSValueBold:
1643 case CSSValue600: 1647 case CSSValue600:
1644 case CSSValue700: 1648 case CSSValue700:
1645 case CSSValue800: 1649 case CSSValue800:
1646 case CSSValue900: 1650 case CSSValue900:
1647 return true; 1651 return true;
1648 default: 1652 default:
1649 break; 1653 break;
1650 } 1654 }
1651 1655
1652 ASSERT_NOT_REACHED(); // For CSSValueBolder and CSSValueLighter 1656 ASSERT_NOT_REACHED(); // For CSSValueBolder and CSSValueLighter
1653 return false; 1657 return false;
1654 } 1658 }
1655 1659
1656 static bool fontWeightNeedsResolving(CSSValue* fontWeight) 1660 static bool fontWeightNeedsResolving(const CSSValue* fontWeight)
1657 { 1661 {
1658 if (!fontWeight->isPrimitiveValue()) 1662 if (!fontWeight->isPrimitiveValue())
1659 return true; 1663 return true;
1660 1664
1661 CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID(); 1665 const CSSValueID value = toCSSPrimitiveValue(fontWeight)->getValueID();
1662 return value == CSSValueLighter || value == CSSValueBolder; 1666 return value == CSSValueLighter || value == CSSValueBolder;
1663 } 1667 }
1664 1668
1665 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle) 1669 MutableStylePropertySet* getPropertiesNotIn(StylePropertySet* styleWithRedundant Properties, CSSStyleDeclaration* baseStyle)
1666 { 1670 {
1667 DCHECK(styleWithRedundantProperties); 1671 DCHECK(styleWithRedundantProperties);
1668 DCHECK(baseStyle); 1672 DCHECK(baseStyle);
1669 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( ); 1673 MutableStylePropertySet* result = styleWithRedundantProperties->mutableCopy( );
1670 1674
1671 result->removeEquivalentProperties(baseStyle); 1675 result->removeEquivalentProperties(baseStyle);
1672 1676
1673 CSSValue* baseTextDecorationsInEffect = baseStyle->getPropertyCSSValueIntern al(CSSPropertyWebkitTextDecorationsInEffect); 1677 const CSSValue* baseTextDecorationsInEffect = baseStyle->getPropertyCSSValue Internal(CSSPropertyWebkitTextDecorationsInEffect);
1674 diffTextDecorations(result, textDecorationPropertyForEditing(), baseTextDeco rationsInEffect); 1678 diffTextDecorations(result, textDecorationPropertyForEditing(), baseTextDeco rationsInEffect);
1675 diffTextDecorations(result, CSSPropertyWebkitTextDecorationsInEffect, baseTe xtDecorationsInEffect); 1679 diffTextDecorations(result, CSSPropertyWebkitTextDecorationsInEffect, baseTe xtDecorationsInEffect);
1676 1680
1677 if (CSSValue* baseFontWeight = baseStyle->getPropertyCSSValueInternal(CSSPro pertyFontWeight)) { 1681 if (const CSSValue* baseFontWeight = baseStyle->getPropertyCSSValueInternal( CSSPropertyFontWeight)) {
1678 if (CSSValue* fontWeight = result->getPropertyCSSValue(CSSPropertyFontWe ight)) { 1682 if (CSSValue* fontWeight = result->getPropertyCSSValue(CSSPropertyFontWe ight)) {
1679 if (!fontWeightNeedsResolving(fontWeight) && !fontWeightNeedsResolvi ng(baseFontWeight) 1683 if (!fontWeightNeedsResolving(fontWeight) && !fontWeightNeedsResolvi ng(baseFontWeight)
1680 && (fontWeightIsBold(fontWeight) == fontWeightIsBold(baseFontWei ght))) 1684 && (fontWeightIsBold(fontWeight) == fontWeightIsBold(baseFontWei ght)))
1681 result->removeProperty(CSSPropertyFontWeight); 1685 result->removeProperty(CSSPropertyFontWeight);
1682 } 1686 }
1683 } 1687 }
1684 1688
1685 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyColor) && getFontColor (result) == getFontColor(baseStyle)) 1689 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyColor) && getFontColor (result) == getFontColor(baseStyle))
1686 result->removeProperty(CSSPropertyColor); 1690 result->removeProperty(CSSPropertyColor);
1687 1691
1688 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyTextAlign) 1692 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyTextAlign)
1689 && textAlignResolvingStartAndEnd(result) == textAlignResolvingStartAndEn d(baseStyle)) 1693 && textAlignResolvingStartAndEnd(result) == textAlignResolvingStartAndEn d(baseStyle))
1690 result->removeProperty(CSSPropertyTextAlign); 1694 result->removeProperty(CSSPropertyTextAlign);
1691 1695
1692 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyBackgroundColor) && ge tBackgroundColor(result) == getBackgroundColor(baseStyle)) 1696 if (baseStyle->getPropertyCSSValueInternal(CSSPropertyBackgroundColor) && ge tBackgroundColor(result) == getBackgroundColor(baseStyle))
1693 result->removeProperty(CSSPropertyBackgroundColor); 1697 result->removeProperty(CSSPropertyBackgroundColor);
1694 1698
1695 return result; 1699 return result;
1696 } 1700 }
1697 1701
1698 CSSValueID getIdentifierValue(StylePropertySet* style, CSSPropertyID propertyID) 1702 CSSValueID getIdentifierValue(StylePropertySet* style, CSSPropertyID propertyID)
1699 { 1703 {
1700 if (!style) 1704 if (!style)
1701 return CSSValueInvalid; 1705 return CSSValueInvalid;
1702 CSSValue* value = style->getPropertyCSSValue(propertyID); 1706 const CSSValue* value = style->getPropertyCSSValue(propertyID);
1703 if (!value || !value->isPrimitiveValue()) 1707 if (!value || !value->isPrimitiveValue())
1704 return CSSValueInvalid; 1708 return CSSValueInvalid;
1705 return toCSSPrimitiveValue(value)->getValueID(); 1709 return toCSSPrimitiveValue(value)->getValueID();
1706 } 1710 }
1707 1711
1708 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID) 1712 CSSValueID getIdentifierValue(CSSStyleDeclaration* style, CSSPropertyID property ID)
1709 { 1713 {
1710 if (!style) 1714 if (!style)
1711 return CSSValueInvalid; 1715 return CSSValueInvalid;
1712 CSSValue* value = style->getPropertyCSSValueInternal(propertyID); 1716 const CSSValue* value = style->getPropertyCSSValueInternal(propertyID);
1713 if (!value || !value->isPrimitiveValue()) 1717 if (!value || !value->isPrimitiveValue())
1714 return CSSValueInvalid; 1718 return CSSValueInvalid;
1715 return toCSSPrimitiveValue(value)->getValueID(); 1719 return toCSSPrimitiveValue(value)->getValueID();
1716 } 1720 }
1717 1721
1718 int legacyFontSizeFromCSSValue(Document* document, CSSPrimitiveValue* value, boo l isMonospaceFont, LegacyFontSizeMode mode) 1722 int legacyFontSizeFromCSSValue(Document* document, const CSSPrimitiveValue* valu e, bool isMonospaceFont, LegacyFontSizeMode mode)
1719 { 1723 {
1720 CSSPrimitiveValue::LengthUnitType lengthType; 1724 CSSPrimitiveValue::LengthUnitType lengthType;
1721 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value->typeWithCalcResolved( ), lengthType) 1725 if (CSSPrimitiveValue::unitTypeToLengthUnitType(value->typeWithCalcResolved( ), lengthType)
1722 && lengthType == CSSPrimitiveValue::UnitTypePixels) { 1726 && lengthType == CSSPrimitiveValue::UnitTypePixels) {
1723 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFa ctor(value->typeWithCalcResolved()); 1727 double conversion = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFa ctor(value->typeWithCalcResolved());
1724 int pixelFontSize = clampTo<int>(value->getDoubleValue() * conversion); 1728 int pixelFontSize = clampTo<int>(value->getDoubleValue() * conversion);
1725 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, i sMonospaceFont); 1729 int legacyFontSize = FontSize::legacyFontSize(document, pixelFontSize, i sMonospaceFont);
1726 // Use legacy font size only if pixel value matches exactly to that of l egacy font size. 1730 // Use legacy font size only if pixel value matches exactly to that of l egacy font size.
1727 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, legacyFontSize, isMonospaceFont) == pixelFontSize) 1731 if (mode == AlwaysUseLegacyFontSize || FontSize::fontSizeForKeyword(docu ment, legacyFontSize, isMonospaceFont) == pixelFontSize)
1728 return legacyFontSize; 1732 return legacyFontSize;
1729 1733
1730 return 0; 1734 return 0;
1731 } 1735 }
1732 1736
1733 if (CSSValueXSmall <= value->getValueID() && value->getValueID() <= CSSValue WebkitXxxLarge) 1737 if (CSSValueXSmall <= value->getValueID() && value->getValueID() <= CSSValue WebkitXxxLarge)
1734 return value->getValueID() - CSSValueXSmall + 1; 1738 return value->getValueID() - CSSValueXSmall + 1;
1735 1739
1736 return 0; 1740 return 0;
1737 } 1741 }
1738 1742
1739 bool isTransparentColorValue(CSSValue* cssValue) 1743 bool isTransparentColorValue(const CSSValue* cssValue)
1740 { 1744 {
1741 if (!cssValue) 1745 if (!cssValue)
1742 return true; 1746 return true;
1743 if (cssValue->isColorValue()) 1747 if (cssValue->isColorValue())
1744 return !toCSSColorValue(cssValue)->value().alpha(); 1748 return !toCSSColorValue(cssValue)->value().alpha();
1745 if (!cssValue->isPrimitiveValue()) 1749 if (!cssValue->isPrimitiveValue())
1746 return false; 1750 return false;
1747 CSSPrimitiveValue* value = toCSSPrimitiveValue(cssValue); 1751 const CSSPrimitiveValue* value = toCSSPrimitiveValue(cssValue);
1748 return value->getValueID() == CSSValueTransparent; 1752 return value->getValueID() == CSSValueTransparent;
1749 } 1753 }
1750 1754
1751 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style) 1755 bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
1752 { 1756 {
1753 CSSValue* cssValue = style->getPropertyCSSValueInternal(CSSPropertyBackgroun dColor); 1757 const CSSValue* cssValue = style->getPropertyCSSValueInternal(CSSPropertyBac kgroundColor);
1754 return isTransparentColorValue(cssValue); 1758 return isTransparentColorValue(cssValue);
1755 } 1759 }
1756 1760
1757 bool hasTransparentBackgroundColor(StylePropertySet* style) 1761 bool hasTransparentBackgroundColor(StylePropertySet* style)
1758 { 1762 {
1759 CSSValue* cssValue = style->getPropertyCSSValue(CSSPropertyBackgroundColor); 1763 const CSSValue* cssValue = style->getPropertyCSSValue(CSSPropertyBackgroundC olor);
1760 return isTransparentColorValue(cssValue); 1764 return isTransparentColorValue(cssValue);
1761 } 1765 }
1762 1766
1763 CSSValue* backgroundColorValueInEffect(Node* node) 1767 const CSSValue* backgroundColorValueInEffect(Node* node)
1764 { 1768 {
1765 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1769 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1766 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor); 1770 CSSComputedStyleDeclaration* ancestorStyle = CSSComputedStyleDeclaration ::create(ancestor);
1767 if (!hasTransparentBackgroundColor(ancestorStyle)) 1771 if (!hasTransparentBackgroundColor(ancestorStyle))
1768 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1772 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1769 } 1773 }
1770 return nullptr; 1774 return nullptr;
1771 } 1775 }
1772 1776
1773 } // namespace blink 1777 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698