| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. | 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc. |
| 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 if (type == AllEditingProperties) | 127 if (type == AllEditingProperties) |
| 128 return style->copyPropertiesInSet(allEditingProperties()); | 128 return style->copyPropertiesInSet(allEditingProperties()); |
| 129 return style->copyPropertiesInSet(inheritableEditingProperties()); | 129 return style->copyPropertiesInSet(inheritableEditingProperties()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 static inline bool isEditingProperty(int id) | 132 static inline bool isEditingProperty(int id) |
| 133 { | 133 { |
| 134 return allEditingProperties().contains(static_cast<CSSPropertyID>(id)); | 134 return allEditingProperties().contains(static_cast<CSSPropertyID>(id)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS
tyle(PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style, EditingPropertie
sType type = OnlyInheritableEditingProperties) | 137 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> editingStyleFromComputedS
tyle(PassRefPtr<CSSComputedStyleDeclaration> style, EditingPropertiesType type =
OnlyInheritableEditingProperties) |
| 138 { | 138 { |
| 139 if (!style) | 139 if (!style) |
| 140 return MutableStylePropertySet::create(); | 140 return MutableStylePropertySet::create(); |
| 141 return copyEditingProperties(style.get(), type); | 141 return copyEditingProperties(style.get(), type); |
| 142 } | 142 } |
| 143 | 143 |
| 144 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP
ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle); | 144 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> getPropertiesNotIn(StyleP
ropertySet* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle); |
| 145 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV
aluesMatch }; | 145 enum LegacyFontSizeMode { AlwaysUseLegacyFontSize, UseLegacyFontSizeOnlyIfPixelV
aluesMatch }; |
| 146 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool should
UseFixedFontDefaultSize, LegacyFontSizeMode); | 146 static int legacyFontSizeFromCSSValue(Document*, CSSPrimitiveValue*, bool should
UseFixedFontDefaultSize, LegacyFontSizeMode); |
| 147 static bool isTransparentColorValue(CSSValue*); | 147 static bool isTransparentColorValue(CSSValue*); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 return textAlignResolvingStartAndEnd(getIdentifierValue(style, CSSPropertyTe
xtAlign), getIdentifierValue(style, CSSPropertyDirection)); | 438 return textAlignResolvingStartAndEnd(getIdentifierValue(style, CSSPropertyTe
xtAlign), getIdentifierValue(style, CSSPropertyDirection)); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude) | 441 void EditingStyle::init(Node* node, PropertiesToInclude propertiesToInclude) |
| 442 { | 442 { |
| 443 if (isTabSpanTextNode(node)) | 443 if (isTabSpanTextNode(node)) |
| 444 node = tabSpanNode(node)->parentNode(); | 444 node = tabSpanNode(node)->parentNode(); |
| 445 else if (isTabSpanNode(node)) | 445 else if (isTabSpanNode(node)) |
| 446 node = node->parentNode(); | 446 node = node->parentNode(); |
| 447 | 447 |
| 448 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = CS
SComputedStyleDeclaration::create(node); | 448 RefPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = CSSComputedSty
leDeclaration::create(node); |
| 449 m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosi
tion ? computedStyleAtPosition->copyProperties() : editingStyleFromComputedStyle
(computedStyleAtPosition); | 449 m_mutableStyle = propertiesToInclude == AllProperties && computedStyleAtPosi
tion ? computedStyleAtPosition->copyProperties() : editingStyleFromComputedStyle
(computedStyleAtPosition); |
| 450 | 450 |
| 451 if (propertiesToInclude == EditingPropertiesInEffect) { | 451 if (propertiesToInclude == EditingPropertiesInEffect) { |
| 452 if (RefPtrWillBeRawPtr<CSSValue> value = backgroundColorInEffect(node)) | 452 if (RefPtrWillBeRawPtr<CSSValue> value = backgroundColorInEffect(node)) |
| 453 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssTe
xt()); | 453 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssTe
xt()); |
| 454 if (RefPtrWillBeRawPtr<CSSValue> value = computedStyleAtPosition->getPro
pertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect)) | 454 if (RefPtrWillBeRawPtr<CSSValue> value = computedStyleAtPosition->getPro
pertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect)) |
| 455 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssTex
t()); | 455 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssTex
t()); |
| 456 } | 456 } |
| 457 | 457 |
| 458 if (node && node->computedStyle()) { | 458 if (node && node->computedStyle()) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 if (!selection.isCaretOrRange()) | 691 if (!selection.isCaretOrRange()) |
| 692 return FalseTriState; | 692 return FalseTriState; |
| 693 | 693 |
| 694 if (selection.isCaret()) | 694 if (selection.isCaret()) |
| 695 return triStateOfStyle(EditingStyle::styleAtSelectionStart(selection).ge
t()); | 695 return triStateOfStyle(EditingStyle::styleAtSelectionStart(selection).ge
t()); |
| 696 | 696 |
| 697 TriState state = FalseTriState; | 697 TriState state = FalseTriState; |
| 698 bool nodeIsStart = true; | 698 bool nodeIsStart = true; |
| 699 for (Node* node = selection.start().deprecatedNode(); node; node = NodeTrave
rsal::next(*node)) { | 699 for (Node* node = selection.start().deprecatedNode(); node; node = NodeTrave
rsal::next(*node)) { |
| 700 if (node->renderer() && node->rendererIsEditable()) { | 700 if (node->renderer() && node->rendererIsEditable()) { |
| 701 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> nodeStyle = CSSCompu
tedStyleDeclaration::create(node); | 701 RefPtr<CSSComputedStyleDeclaration> nodeStyle = CSSComputedStyleDecl
aration::create(node); |
| 702 if (nodeStyle) { | 702 if (nodeStyle) { |
| 703 TriState nodeState = triStateOfStyle(nodeStyle.get(), node->isTe
xtNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreTex
tOnlyProperties); | 703 TriState nodeState = triStateOfStyle(nodeStyle.get(), node->isTe
xtNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreTex
tOnlyProperties); |
| 704 if (nodeIsStart) { | 704 if (nodeIsStart) { |
| 705 state = nodeState; | 705 state = nodeState; |
| 706 nodeIsStart = false; | 706 nodeIsStart = false; |
| 707 } else if (state != nodeState && node->isTextNode()) { | 707 } else if (state != nodeState && node->isTextNode()) { |
| 708 state = MixedTriState; | 708 state = MixedTriState; |
| 709 break; | 709 break; |
| 710 } | 710 } |
| 711 } | 711 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 m_mutableStyle = styleFromMatchedRules; | 1139 m_mutableStyle = styleFromMatchedRules; |
| 1140 } | 1140 } |
| 1141 | 1141 |
| 1142 void EditingStyle::mergeStyleFromRulesForSerialization(Element* element) | 1142 void EditingStyle::mergeStyleFromRulesForSerialization(Element* element) |
| 1143 { | 1143 { |
| 1144 mergeStyleFromRules(element); | 1144 mergeStyleFromRules(element); |
| 1145 | 1145 |
| 1146 // The property value, if it's a percentage, may not reflect the actual comp
uted value. | 1146 // The property value, if it's a percentage, may not reflect the actual comp
uted value. |
| 1147 // For example: style="height: 1%; overflow: visible;" in quirksmode | 1147 // For example: style="height: 1%; overflow: visible;" in quirksmode |
| 1148 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot
copy/paste fidelity problem | 1148 // FIXME: There are others like this, see <rdar://problem/5195123> Slashdot
copy/paste fidelity problem |
| 1149 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyleForElement = CS
SComputedStyleDeclaration::create(element); | 1149 RefPtr<CSSComputedStyleDeclaration> computedStyleForElement = CSSComputedSty
leDeclaration::create(element); |
| 1150 RefPtrWillBeRawPtr<MutableStylePropertySet> fromComputedStyle = MutableStyle
PropertySet::create(); | 1150 RefPtrWillBeRawPtr<MutableStylePropertySet> fromComputedStyle = MutableStyle
PropertySet::create(); |
| 1151 { | 1151 { |
| 1152 unsigned propertyCount = m_mutableStyle->propertyCount(); | 1152 unsigned propertyCount = m_mutableStyle->propertyCount(); |
| 1153 for (unsigned i = 0; i < propertyCount; ++i) { | 1153 for (unsigned i = 0; i < propertyCount; ++i) { |
| 1154 StylePropertySet::PropertyReference property = m_mutableStyle->prope
rtyAt(i); | 1154 StylePropertySet::PropertyReference property = m_mutableStyle->prope
rtyAt(i); |
| 1155 CSSValue* value = property.value(); | 1155 CSSValue* value = property.value(); |
| 1156 if (!value->isPrimitiveValue()) | 1156 if (!value->isPrimitiveValue()) |
| 1157 continue; | 1157 continue; |
| 1158 if (toCSSPrimitiveValue(value)->isPercentage()) { | 1158 if (toCSSPrimitiveValue(value)->isPercentage()) { |
| 1159 if (RefPtrWillBeRawPtr<CSSValue> computedPropertyValue = compute
dStyleForElement->getPropertyCSSValue(property.id())) | 1159 if (RefPtrWillBeRawPtr<CSSValue> computedPropertyValue = compute
dStyleForElement->getPropertyCSSValue(property.id())) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 Position end; | 1282 Position end; |
| 1283 if (selection.isRange()) { | 1283 if (selection.isRange()) { |
| 1284 end = selection.end().upstream(); | 1284 end = selection.end().upstream(); |
| 1285 | 1285 |
| 1286 ASSERT(end.document()); | 1286 ASSERT(end.document()); |
| 1287 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE
quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); | 1287 Node* pastLast = Range::create(*end.document(), position.parentAnchoredE
quivalent(), end.parentAnchoredEquivalent())->pastLastNode(); |
| 1288 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { | 1288 for (Node* n = node; n && n != pastLast; n = NodeTraversal::next(*n)) { |
| 1289 if (!n->isStyledElement()) | 1289 if (!n->isStyledElement()) |
| 1290 continue; | 1290 continue; |
| 1291 | 1291 |
| 1292 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedS
tyleDeclaration::create(n); | 1292 RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclarat
ion::create(n); |
| 1293 RefPtrWillBeRawPtr<CSSValue> unicodeBidi = style->getPropertyCSSValu
e(CSSPropertyUnicodeBidi); | 1293 RefPtrWillBeRawPtr<CSSValue> unicodeBidi = style->getPropertyCSSValu
e(CSSPropertyUnicodeBidi); |
| 1294 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) | 1294 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) |
| 1295 continue; | 1295 continue; |
| 1296 | 1296 |
| 1297 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi.get())
->getValueID(); | 1297 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi.get())
->getValueID(); |
| 1298 if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValu
eBidiOverride) | 1298 if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValu
eBidiOverride) |
| 1299 return NaturalWritingDirection; | 1299 return NaturalWritingDirection; |
| 1300 } | 1300 } |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 if (selection.isCaret()) { | 1303 if (selection.isCaret()) { |
| 1304 WritingDirection direction; | 1304 WritingDirection direction; |
| 1305 if (typingStyle && typingStyle->textDirection(direction)) { | 1305 if (typingStyle && typingStyle->textDirection(direction)) { |
| 1306 hasNestedOrMultipleEmbeddings = false; | 1306 hasNestedOrMultipleEmbeddings = false; |
| 1307 return direction; | 1307 return direction; |
| 1308 } | 1308 } |
| 1309 node = selection.visibleStart().deepEquivalent().deprecatedNode(); | 1309 node = selection.visibleStart().deepEquivalent().deprecatedNode(); |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 // 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 | 1312 // 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 |
| 1313 // to decide. | 1313 // to decide. |
| 1314 Node* block = enclosingBlock(node); | 1314 Node* block = enclosingBlock(node); |
| 1315 WritingDirection foundDirection = NaturalWritingDirection; | 1315 WritingDirection foundDirection = NaturalWritingDirection; |
| 1316 | 1316 |
| 1317 for (; node != block; node = node->parentNode()) { | 1317 for (; node != block; node = node->parentNode()) { |
| 1318 if (!node->isStyledElement()) | 1318 if (!node->isStyledElement()) |
| 1319 continue; | 1319 continue; |
| 1320 | 1320 |
| 1321 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> style = CSSComputedStyle
Declaration::create(node); | 1321 RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration:
:create(node); |
| 1322 RefPtrWillBeRawPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CS
SPropertyUnicodeBidi); | 1322 RefPtrWillBeRawPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CS
SPropertyUnicodeBidi); |
| 1323 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) | 1323 if (!unicodeBidi || !unicodeBidi->isPrimitiveValue()) |
| 1324 continue; | 1324 continue; |
| 1325 | 1325 |
| 1326 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi.get())->ge
tValueID(); | 1326 CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi.get())->ge
tValueID(); |
| 1327 if (unicodeBidiValue == CSSValueNormal) | 1327 if (unicodeBidiValue == CSSValueNormal) |
| 1328 continue; | 1328 continue; |
| 1329 | 1329 |
| 1330 if (unicodeBidiValue == CSSValueBidiOverride) | 1330 if (unicodeBidiValue == CSSValueBidiOverride) |
| 1331 return NaturalWritingDirection; | 1331 return NaturalWritingDirection; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 , m_applyItalic(false) | 1374 , m_applyItalic(false) |
| 1375 , m_applyUnderline(false) | 1375 , m_applyUnderline(false) |
| 1376 , m_applyLineThrough(false) | 1376 , m_applyLineThrough(false) |
| 1377 , m_applySubscript(false) | 1377 , m_applySubscript(false) |
| 1378 , m_applySuperscript(false) | 1378 , m_applySuperscript(false) |
| 1379 { | 1379 { |
| 1380 Document* document = position.document(); | 1380 Document* document = position.document(); |
| 1381 if (!style || !style->style() || !document || !document->frame()) | 1381 if (!style || !style->style() || !document || !document->frame()) |
| 1382 return; | 1382 return; |
| 1383 | 1383 |
| 1384 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> computedStyle = position.com
putedStyle(); | 1384 RefPtr<CSSComputedStyleDeclaration> computedStyle = position.computedStyle()
; |
| 1385 // FIXME: take care of background-color in effect | 1385 // FIXME: take care of background-color in effect |
| 1386 RefPtrWillBeRawPtr<MutableStylePropertySet> mutableStyle = getPropertiesNotI
n(style->style(), computedStyle.get()); | 1386 RefPtrWillBeRawPtr<MutableStylePropertySet> mutableStyle = getPropertiesNotI
n(style->style(), computedStyle.get()); |
| 1387 | 1387 |
| 1388 reconcileTextDecorationProperties(mutableStyle.get()); | 1388 reconcileTextDecorationProperties(mutableStyle.get()); |
| 1389 if (!document->frame()->editor().shouldStyleWithCSS()) | 1389 if (!document->frame()->editor().shouldStyleWithCSS()) |
| 1390 extractTextStyles(document, mutableStyle.get(), computedStyle->useFixedF
ontDefaultSize()); | 1390 extractTextStyles(document, mutableStyle.get(), computedStyle->useFixedF
ontDefaultSize()); |
| 1391 | 1391 |
| 1392 // Changing the whitespace style in a tab span would collapse the tab into a
space. | 1392 // Changing the whitespace style in a tab span would collapse the tab into a
space. |
| 1393 if (isTabSpanTextNode(position.deprecatedNode()) || isTabSpanNode((position.
deprecatedNode()))) | 1393 if (isTabSpanTextNode(position.deprecatedNode()) || isTabSpanNode((position.
deprecatedNode()))) |
| 1394 mutableStyle->removeProperty(CSSPropertyWhiteSpace); | 1394 mutableStyle->removeProperty(CSSPropertyWhiteSpace); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 | 1626 |
| 1627 bool hasTransparentBackgroundColor(StylePropertySet* style) | 1627 bool hasTransparentBackgroundColor(StylePropertySet* style) |
| 1628 { | 1628 { |
| 1629 RefPtrWillBeRawPtr<CSSValue> cssValue = style->getPropertyCSSValue(CSSProper
tyBackgroundColor); | 1629 RefPtrWillBeRawPtr<CSSValue> cssValue = style->getPropertyCSSValue(CSSProper
tyBackgroundColor); |
| 1630 return isTransparentColorValue(cssValue.get()); | 1630 return isTransparentColorValue(cssValue.get()); |
| 1631 } | 1631 } |
| 1632 | 1632 |
| 1633 PassRefPtrWillBeRawPtr<CSSValue> backgroundColorInEffect(Node* node) | 1633 PassRefPtrWillBeRawPtr<CSSValue> backgroundColorInEffect(Node* node) |
| 1634 { | 1634 { |
| 1635 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { | 1635 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { |
| 1636 RefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSCompu
tedStyleDeclaration::create(ancestor); | 1636 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl
aration::create(ancestor); |
| 1637 if (!hasTransparentBackgroundColor(ancestorStyle.get())) | 1637 if (!hasTransparentBackgroundColor(ancestorStyle.get())) |
| 1638 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor
); | 1638 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor
); |
| 1639 } | 1639 } |
| 1640 return nullptr; | 1640 return nullptr; |
| 1641 } | 1641 } |
| 1642 | 1642 |
| 1643 } | 1643 } |
| OLD | NEW |