Changeset 49414 in webkit
- Timestamp:
- Oct 9, 2009 8:36:51 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r49406 r49414 1 2009-10-09 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Eric Seidel. 4 5 ApplyStyleCommand removes presentational tags even when not necessary 6 https://bugs.webkit.org/show_bug.cgi?id=28091 7 8 This patch adds test to make sure to preserve presentational tag 9 (u, s, strike, i, em, sup, sub, b, & strong) when the corresponding style is present in 10 the final computed style. i.e. avoid removing tag and re-applying the style later 11 12 * editing/execCommand/19653-2-expected.txt: Two b elements are merged. 13 * editing/execCommand/createLink-expected.txt: Two anchor elements are merged. 14 * editing/execCommand/script-tests/toggle-style-3.js: Added. 15 (testSingleToggle): 16 * editing/execCommand/strikethroughSelection-expected.txt: Redundant style spans are no longer added. 17 * editing/execCommand/toggle-style-3-expected.txt: Added. 18 * editing/execCommand/toggle-style-3.html: Added. 19 * editing/execCommand/unlink-expected.txt: Two anchor elements are merged. 20 * platform/mac/editing/style/5228141-expected.txt: Two b elements are merged. 21 * platform/mac/editing/style/style-boundary-001-expected.txt: Two b elements are merged. 22 1 23 2009-10-09 Alexey Proskuryakov <ap@apple.com> 2 24 -
trunk/LayoutTests/editing/execCommand/19653-2-expected.txt
r34681 r49414 3 3 4 4 This tests splitting two paragraphs with InsertLineBreak while the typing style is bold. New text entered after the split should be bold. The inserted <br> doesn't need to be surrounded by a bold tag here. 5 x<b><br> </b><b>Bold</b>x5 x<b><br>Bold</b>x -
trunk/LayoutTests/editing/execCommand/createLink-expected.txt
r30635 r49414 60 60 <a href="http://www.apple.com/">This</a><a href="http://www.google.com/"> paragraph</a><a href="http://www.apple.com/"> starts out as a link to apple.com. The second word in the paragraph should end up being a link to google.com.</a> 61 61 <a href="http://www.apple.com/">This</a><a href="http://www.google.com/"> paragraph</a><a href="http://www.apple.com/"> starts out as a link to apple.com. The second word in the paragraph should end up being a link to google.com.</a> 62 <p><a href="http://www.google.com/">This </a><i><a href="http://www.google.com/">editable region</a></i><a href="http://www.google.com/"> contains lists, tables, styled text, and images. The entire region should end up being a link to google.com.</a></p> <ul> <li><a href="http://www.google.com/">Item 1</a></li> <li><a href="http://www.google.com/">Item 2</a></li> </ul> <table border="1"><tbody><tr><td><a href="http://www.google.com/">1</a></td><td><a href="http://www.google.com/">2</a></td><td><a href="http://www.google.com/">3</a></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains < /a><a href="http://www.google.com/"><img src="../resources/abe.png"> an image. </a>62 <p><a href="http://www.google.com/">This </a><i><a href="http://www.google.com/">editable region</a></i><a href="http://www.google.com/"> contains lists, tables, styled text, and images. The entire region should end up being a link to google.com.</a></p> <ul> <li><a href="http://www.google.com/">Item 1</a></li> <li><a href="http://www.google.com/">Item 2</a></li> </ul> <table border="1"><tbody><tr><td><a href="http://www.google.com/">1</a></td><td><a href="http://www.google.com/">2</a></td><td><a href="http://www.google.com/">3</a></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains <img src="../resources/abe.png"> an image. </a> -
trunk/LayoutTests/editing/execCommand/strikethroughSelection-expected.txt
r47640 r49414 5 5 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 6 6 execStrikethroughCommand: <span id="test"><s>"Th</s>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 7 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>8 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e </s>quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>9 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>10 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e qu</s>ick brown fox jumps over the lazy dog" uses every letter in the english language. </span>11 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>12 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quic</s>k brown fox jumps over the lazy dog" uses every letter in the english language. </span>13 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>14 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick </s>brown fox jumps over the lazy dog" uses every letter in the english language. </span>15 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>16 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick br</s>own fox jumps over the lazy dog" uses every letter in the english language. </span>17 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>18 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brow</s>n fox jumps over the lazy dog" uses every letter in the english language. </span>19 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>20 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brown </s>fox jumps over the lazy dog" uses every letter in the english language. </span>21 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>22 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brown fo</s>x jumps over the lazy dog" uses every letter in the english language. </span>23 execStrikethroughCommand: <span id="test">" <span class="Apple-style-span">T</span><span class="Apple-style-span">h</span>e quick brown fox jumps over the lazy dog" uses every letter in the english language. </span>24 execStrikethroughCommand: <span id="test"><s>" </s><span class="Apple-style-span"><s>T</s></span><span class="Apple-style-span"><s>h</s></span><s>e quick brown fox </s>jumps over the lazy dog" uses every letter in the english language. </span>7 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 8 execStrikethroughCommand: <span id="test"><s>"The </s>quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 9 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 10 execStrikethroughCommand: <span id="test"><s>"The qu</s>ick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 11 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 12 execStrikethroughCommand: <span id="test"><s>"The quic</s>k brown fox jumps over the lazy dog" uses every letter in the english language. </span> 13 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 14 execStrikethroughCommand: <span id="test"><s>"The quick </s>brown fox jumps over the lazy dog" uses every letter in the english language. </span> 15 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 16 execStrikethroughCommand: <span id="test"><s>"The quick br</s>own fox jumps over the lazy dog" uses every letter in the english language. </span> 17 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 18 execStrikethroughCommand: <span id="test"><s>"The quick brow</s>n fox jumps over the lazy dog" uses every letter in the english language. </span> 19 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 20 execStrikethroughCommand: <span id="test"><s>"The quick brown </s>fox jumps over the lazy dog" uses every letter in the english language. </span> 21 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 22 execStrikethroughCommand: <span id="test"><s>"The quick brown fo</s>x jumps over the lazy dog" uses every letter in the english language. </span> 23 execStrikethroughCommand: <span id="test">"The quick brown fox jumps over the lazy dog" uses every letter in the english language. </span> 24 execStrikethroughCommand: <span id="test"><s>"The quick brown fox </s>jumps over the lazy dog" uses every letter in the english language. </span> -
trunk/LayoutTests/editing/execCommand/unlink-expected.txt
r30635 r49414 67 67 <a href="http://www.apple.com/">The</a> second<a href="http://www.apple.com/"> word in this paragraph should end up being unlinked, everything else should be a link.</a> 68 68 This paragraph starts with <i><a href="http://www.google.com">a</a></i><span id="test3start"> link</span> in the middle. Only the 'a' in the previous sentence should be linked after the test. 69 <p>This <i>editable region</i> contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> <table border="1"><tbody><tr><td>1</td><td>2</td><td><span id="test4end"><a href="http://www.google.com/">3</a></span></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains < /a><a href="http://www.google.com/"><img src="../resources/abe.png"> an image. </a>69 <p>This <i>editable region</i> contains lists, tables, styled text, and images. Everything in this region that is not selected should be a link, nothing that is selected should be a link.</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> <table border="1"><tbody><tr><td>1</td><td>2</td><td><span id="test4end"><a href="http://www.google.com/">3</a></span></td></tr></tbody></table> <a href="http://www.google.com/"><br> This </a><b><a href="http://www.google.com/">line</a></b><a href="http://www.google.com/"> contains <img src="../resources/abe.png"> an image. </a> -
trunk/LayoutTests/platform/mac/editing/style/5228141-expected.txt
r43215 r49414 12 12 RenderBR {BR} at (0,0) size 0x18 13 13 RenderBlock {DIV} at (0,18) size 784x107 14 RenderInline {B} at (0,0) size 166x1814 RenderInline {B} at (0,0) size 242x18 15 15 RenderText {#text} at (0,89) size 166x18 16 16 text run at (0,89) width 166: "This text should be bold." 17 RenderInline {B} at (0,0) size 76x1818 17 RenderImage {IMG} at (166,0) size 76x103 19 18 selection start: position 0 of child 0 {BR} of child 0 {B} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document 20 selection end: position 1 of child 0 {IMG} of child 1{B} of child 1 {DIV} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document19 selection end: position 1 of child 1 {IMG} of child 0 {B} of child 1 {DIV} of child 2 {DIV} of child 1 {BODY} of child 0 {HTML} of document -
trunk/LayoutTests/platform/mac/editing/style/style-boundary-001-expected.txt
r25970 r49414 32 32 RenderBlock {DIV} at (0,180) size 784x32 33 33 RenderBlock {DIV} at (0,0) size 784x32 [border: (2px solid #FF0000)] 34 RenderInline {B} at (0,0) size 12x2834 RenderInline {B} at (0,0) size 25x28 35 35 RenderText {#text} at (2,2) size 12x28 36 36 text run at (2,2) width 12: "a" 37 RenderInline {B} at (0,0) size 13x2838 37 RenderText {#text} at (14,2) size 13x28 39 38 text run at (14,2) width 13: "b" 40 selection start: position 0 of child 0 {#text} of child 1{B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document41 selection end: position 1 of child 0 {#text} of child 1{B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document39 selection start: position 0 of child 1 {#text} of child 0 {B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document 40 selection end: position 1 of child 1 {#text} of child 0 {B} of child 1 {DIV} of child 3 {DIV} of child 1 {BODY} of child 0 {HTML} of document -
trunk/WebCore/ChangeLog
r49413 r49414 1 2009-10-09 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Eric Seidel. 4 5 ApplyStyleCommand removes presentational tags even when not necessary 6 https://bugs.webkit.org/show_bug.cgi?id=28091 7 8 This patch updates implicitlyStyledElementShouldBeRemovedWhenApplyingStyle to return true 9 (triggering removal of tag) only if the style implicitly added by the element is not present in 10 the new style to apply. It also changes surroundNodeRangeWithElement so that it merges the 11 surrounding element when possible. applyTextDecorationStyle is modified so that it does not add 12 style span when the style attribute is empty. 13 14 Test: editing/execCommand/toggle-style-3.html 15 16 * editing/ApplyStyleCommand.cpp: 17 (WebCore::ApplyStyleCommand::shouldRemoveTextDecorationTag): Returns true if specified text 18 decoration is not present in the style to apply 19 (WebCore::ApplyStyleCommand::implicitlyStyledElementShouldBeRemovedWhenApplyingStyle): No longer 20 returns true if the tag is used in new style 21 (WebCore::ApplyStyleCommand::applyTextDecorationStyle): Does not add style-span when redundant 22 (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement): Merges the newly created element 23 with the surrounding identical elements 24 * editing/ApplyStyleCommand.h: 25 1 26 2009-10-09 Adam Barth <abarth@webkit.org> 2 27 -
trunk/WebCore/editing/ApplyStyleCommand.cpp
r49129 r49414 1080 1080 } 1081 1081 1082 bool ApplyStyleCommand::shouldRemoveTextDecorationTag(CSSStyleDeclaration* styleToApply, int textDecorationAddedByTag) const 1083 { 1084 // Honor text-decorations-in-effect 1085 RefPtr<CSSValue> textDecorationsToApply = styleToApply->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect); 1086 if (!textDecorationsToApply || !textDecorationsToApply->isValueList()) 1087 textDecorationsToApply = styleToApply->getPropertyCSSValue(CSSPropertyTextDecoration); 1088 1089 // When there is no text decorations to apply, remove any one of u, s, & strike 1090 if (!textDecorationsToApply || !textDecorationsToApply->isValueList()) 1091 return true; 1092 1093 // Remove node if it implicitly adds style not present in styleToApply 1094 CSSValueList* valueList = static_cast<CSSValueList*>(textDecorationsToApply.get()); 1095 RefPtr<CSSPrimitiveValue> value = CSSPrimitiveValue::createIdentifier(textDecorationAddedByTag); 1096 return !valueList->hasValue(value.get()); 1097 } 1098 1082 1099 // This function maps from styling tags to CSS styles. Used for knowing which 1083 1100 // styling tags should be removed when toggling styles. … … 1093 1110 // IE inserts "strong" tags for execCommand("bold"), so we remove them, even though they're not strictly presentational 1094 1111 if (elem->hasLocalName(bTag) || elem->hasLocalName(strongTag)) 1095 return true;1112 return !equalIgnoringCase(property.value()->cssText(), "bold") || !elem->hasChildNodes(); 1096 1113 break; 1097 1114 case CSSPropertyVerticalAlign: 1098 if (elem->hasLocalName(subTag) || elem->hasLocalName(supTag)) 1099 return true; 1115 if (elem->hasLocalName(subTag)) 1116 return !equalIgnoringCase(property.value()->cssText(), "sub") || !elem->hasChildNodes(); 1117 if (elem->hasLocalName(supTag)) 1118 return !equalIgnoringCase(property.value()->cssText(), "sup") || !elem->hasChildNodes(); 1100 1119 break; 1101 1120 case CSSPropertyFontStyle: 1102 1121 // IE inserts "em" tags for execCommand("italic"), so we remove them, even though they're not strictly presentational 1103 1122 if (elem->hasLocalName(iTag) || elem->hasLocalName(emTag)) 1104 return true;1123 return !equalIgnoringCase(property.value()->cssText(), "italic") || !elem->hasChildNodes(); 1105 1124 break; 1106 1125 case CSSPropertyTextDecoration: 1107 1126 case CSSPropertyWebkitTextDecorationsInEffect: 1108 ASSERT(property.value()); 1109 if (property.value()->isValueList()) { 1110 CSSValueList* valueList = static_cast<CSSValueList*>(property.value()); 1111 DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, underline, (CSSPrimitiveValue::createIdentifier(CSSValueUnderline))); 1112 DEFINE_STATIC_LOCAL(RefPtr<CSSPrimitiveValue>, lineThrough, (CSSPrimitiveValue::createIdentifier(CSSValueLineThrough))); 1113 // Because style is new style to be applied, we delete element only if the element is not used in style. 1114 if (!valueList->hasValue(underline.get()) && elem->hasLocalName(uTag)) 1115 return true; 1116 if (!valueList->hasValue(lineThrough.get()) && (elem->hasLocalName(strikeTag) || elem->hasLocalName(sTag))) 1117 return true; 1118 } else { 1119 // If the value is NOT a list, then it must be "none", in which case we should remove all text decorations. 1120 ASSERT(property.value()->cssText() == "none"); 1121 if (elem->hasLocalName(uTag) || elem->hasLocalName(strikeTag) || elem->hasLocalName(sTag)) 1122 return true; 1123 } 1124 break; 1127 if (elem->hasLocalName(uTag)) 1128 return shouldRemoveTextDecorationTag(style, CSSValueUnderline) || !elem->hasChildNodes(); 1129 else if (elem->hasLocalName(sTag) || elem->hasTagName(strikeTag)) 1130 return shouldRemoveTextDecorationTag(style,CSSValueLineThrough) || !elem->hasChildNodes(); 1125 1131 } 1126 1132 } … … 1308 1314 return; 1309 1315 1310 if (node->isTextNode()) { 1311 RefPtr<HTMLElement> styleSpan = createStyleSpanElement(document()); 1312 surroundNodeRangeWithElement(node, node, styleSpan.get()); 1313 node = styleSpan.get(); 1314 } 1315 1316 if (!node->isElementNode()) 1317 return; 1318 1319 HTMLElement *element = static_cast<HTMLElement *>(node); 1320 1321 StyleChange styleChange(style, Position(element, 0)); 1316 StyleChange styleChange(style, Position(node, 0)); 1322 1317 if (styleChange.cssStyle().length()) { 1318 if (node->isTextNode()) { 1319 RefPtr<HTMLElement> styleSpan = createStyleSpanElement(document()); 1320 surroundNodeRangeWithElement(node, node, styleSpan.get()); 1321 node = styleSpan.get(); 1322 } 1323 1324 if (!node->isElementNode()) 1325 return; 1326 1327 HTMLElement *element = static_cast<HTMLElement *>(node); 1323 1328 String cssText = styleChange.cssStyle(); 1324 1329 CSSMutableStyleDeclaration *decl = element->inlineStyleDecl(); … … 1680 1685 node = next; 1681 1686 } 1687 1688 Node* nextSibling = element->nextSibling(); 1689 Node* previousSibling = element->previousSibling(); 1690 if (nextSibling && nextSibling->isElementNode() && nextSibling->isContentEditable() 1691 && areIdenticalElements(element.get(), static_cast<Element*>(nextSibling))) 1692 mergeIdenticalElements(element, static_cast<Element*>(nextSibling)); 1693 1694 if (previousSibling && previousSibling->isElementNode() && previousSibling->isContentEditable()) { 1695 Node* mergedElement = previousSibling->nextSibling(); 1696 if (mergedElement->isElementNode() && mergedElement->isContentEditable() 1697 && areIdenticalElements(static_cast<Element*>(previousSibling), static_cast<Element*>(mergedElement))) 1698 mergeIdenticalElements(static_cast<Element*>(previousSibling), static_cast<Element*>(mergedElement)); 1699 } 1700 1682 1701 // FIXME: We should probably call updateStartEnd if the start or end was in the node 1683 1702 // range so that the endingSelection() is canonicalized. See the comments at the end of -
trunk/WebCore/editing/ApplyStyleCommand.h
r46914 r49414 63 63 64 64 // style-removal helpers 65 bool shouldRemoveTextDecorationTag(CSSStyleDeclaration* styleToApply, int textDecorationAddedByTag) const; 65 66 bool implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(HTMLElement*, CSSMutableStyleDeclaration*); 66 67 void replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement*&);
Note: See TracChangeset
for help on using the changeset viewer.