Changeset 70283 in webkit
- Timestamp:
- Oct 21, 2010 6:30:04 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r70282 r70283 1 2010-10-21 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Tony Chang. 4 5 removeFormat needs to be reimplemented 6 https://bugs.webkit.org/show_bug.cgi?id=43017 7 8 * editing/execCommand/19403-expected.txt: hr element is no longer removed erroneously. 9 * editing/execCommand/19403.html: Updated the test description. 10 * editing/execCommand/4786404-1-expected.txt: Change in text nodes but identical rendering. 11 * editing/execCommand/4786404-2-expected.txt: Ditto. 12 * editing/execCommand/4920488-expected.txt: Preserves anchor element on RemoveFormat. 13 * editing/execCommand/4920488.html: Updated the test description. 14 * editing/execCommand/4920742-1-expected.txt: Preserves div elements. 15 * editing/execCommand/5049671.html: Updated the test to dump twice before and after RemoveFormat. 16 This was a test to ensure WebKit removes anchor elements but we no longer removes anchor elements. 17 * editing/execCommand/5049671-expected.txt: 18 * editing/execCommand/5573879.html: Updated the test description because WebKit no longer removes 19 lists on RemoveFormat. 20 * editing/execCommand/5573879-expected.txt: 21 * editing/execCommand/5770834-1-expected.txt: Removed redundant text-align property value. 22 * editing/execCommand/remove-format-elements-expected.txt: Added. 23 * editing/execCommand/remove-format-elements.html: Added. 24 * editing/execCommand/remove-format-multiple-elements-expected.txt: Added. 25 * editing/execCommand/remove-format-multiple-elements.html: Added. 26 * editing/execCommand/remove-formatting-2-expected.txt: Change in text nodes but identical rendering. 27 * editing/execCommand/remove-formatting-expected.txt: WebKit no longer removes anchor, table, 28 tbody, tr, and td elements. 29 * editing/execCommand/script-tests/remove-format-multiple-elements.js: Added. 30 (testRemoveFormat): 31 (selectAll): 32 (selectSecondWord): 33 (selectFirstTwoWords): 34 (selectLastTwoWords): 35 (selectLastWord): 36 * editing/execCommand/script-tests/toggle-link.js: Anchor wraps div instead of div wrapping anchor. 37 * editing/execCommand/script-tests/toggle-unlink.js: Ditto. 38 * editing/execCommand/toggle-link-expected.txt: Ditto. 39 * editing/execCommand/toggle-unlink-expected.txt: Ditto. 40 * editing/execCommand/unlink-expected.txt: i wraps div instead of i wrapping anchor. 41 * editing/inserting/space-after-removeformat-expected.txt: Editing delegate change. 42 1 43 2010-10-21 Tony Gentilcore <tonyg@chromium.org> 2 44 -
trunk/LayoutTests/editing/execCommand/19403-expected.txt
r34399 r70283 1 This tests for an ASSERT during a RemoveFormat call when it's called on a selection containing only a horizontal rule. It should not ASSERT. Bug: It should also not remove the horizontal rule.2 < br>1 This tests for an ASSERT during a RemoveFormat call when it's called on a selection containing only a horizontal rule. It should not ASSERT. 2 <hr> -
trunk/LayoutTests/editing/execCommand/19403.html
r34399 r70283 1 <div id="description">This tests for an ASSERT during a RemoveFormat call when it's called on a selection containing only a horizontal rule. It should not ASSERT. Bug: It should also not remove the horizontal rule.</div>1 <div id="description">This tests for an ASSERT during a RemoveFormat call when it's called on a selection containing only a horizontal rule. It should not ASSERT.</div> 2 2 <div id="edit" contentEditable="true"><hr></div> 3 3 -
trunk/LayoutTests/editing/execCommand/4786404-1-expected.txt
r69980 r70283 4 4 | id="div" 5 5 | style="font-weight: normal; color: black;" 6 | "<#selection-anchor>foo bar baz<#selection-focus>" 6 | "<#selection-anchor>foo " 7 | "bar" 8 | " baz<#selection-focus>" -
trunk/LayoutTests/editing/execCommand/4786404-2-expected.txt
r69980 r70283 3 3 | contenteditable="true" 4 4 | id="div" 5 | "<#selection-anchor>foo bar baz<#selection-focus>" 5 | "<#selection-anchor>foo" 6 | " bar baz<#selection-focus>" -
trunk/LayoutTests/editing/execCommand/4920488-expected.txt
r69980 r70283 1 This tests for a bug in GMail's Editor, they try to extract the contents of a range that has had it's contents removed from the document by an editing command. You should see 'dogfood' unstyled below.1 This tests for a bug in GMail's Editor, they try to extract the contents of a range that has had it's contents removed from the document by an editing command. Since the bug 43017 requires WebKit does not remove anchor elements, div should be empty after the extraction. We currently leave anchor element in the div due to the Bug 47916. 2 2 3 3 After removeFormat: 4 | "<#selection-anchor>dogfood<#selection-focus>" 4 | "<#selection-anchor>dog" 5 | <a> 6 | href="http://www.google.com/" 7 | "food<#selection-focus>" 5 8 6 9 After extractContents(): 7 | "<#selection-anchor>dogfood<#selection-focus>" 10 | "" 11 | <a> 12 | href="http://www.google.com/" -
trunk/LayoutTests/editing/execCommand/4920488.html
r69980 r70283 6 6 <script> 7 7 8 Markup.description("This tests for a bug in GMail's Editor, they try to extract the contents of a range that has had it's contents removed from the document by an editing command. You should see 'dogfood' unstyled below.");8 Markup.description("This tests for a bug in GMail's Editor, they try to extract the contents of a range that has had it's contents removed from the document by an editing command. Since the bug 43017 requires WebKit does not remove anchor elements, div should be empty after the extraction. We currently leave anchor element in the div due to the Bug 47916."); 9 9 10 10 var div = document.getElementById("div"); -
trunk/LayoutTests/editing/execCommand/4920742-1-expected.txt
r69982 r70283 1 1 This tests for a bug where RemoveFormat would reverse the order of paragraphs. Bug: the caret is not on the last line but it should be. 2 | "<#selection-anchor>foo" 2 3 | <div> 3 | "<#selection-anchor>foo"4 4 | <br> 5 | <br>5 | <div> 6 6 | <#selection-focus> 7 7 | <br> -
trunk/LayoutTests/editing/execCommand/5049671-expected.txt
r69982 r70283 1 This tests for a bug where Remove Format would fail to remove links that were fully selected. You should see plain text only in the editable region below. 2 | "<#selection-anchor>This shouldn't be a link or underlined.<#selection-focus>" 1 This tests was added for a bug where Remove Format would fail to remove links that were fully selected. However, because the bug 43017 requires WebKit does not remove anchor elements, RemoveFormat should NOT remove anchor elements. 2 3 Before RemoveFormat: 4 | <a> 5 | href="http://www.google.com/" 6 | "<#selection-anchor>This shouldn't be a link or underlined.<#selection-focus>" 7 8 After RemoveFormat: 9 | <a> 10 | href="http://www.google.com/" 11 | "<#selection-anchor>This shouldn't be a link or underlined.<#selection-focus>" -
trunk/LayoutTests/editing/execCommand/5049671.html
r69982 r70283 6 6 <script> 7 7 8 Markup.description('This tests was added for a bug where Remove Format would fail to remove links that were fully selected.' 9 + ' However, because the bug 43017 requires WebKit does not remove anchor elements, RemoveFormat should NOT remove anchor elements.'); 10 8 11 var div = document.getElementById("div"); 9 12 div.focus(); 10 13 document.execCommand("SelectAll"); 14 15 Markup.dump(div, 'Before RemoveFormat'); 16 11 17 document.execCommand("RemoveFormat"); 12 18 13 Markup.description('This tests for a bug where Remove Format would fail to remove links that were fully selected. You should see plain text only in the editable region below.'); 14 Markup.dump(div); 19 Markup.dump(div, 'After RemoveFormat'); 15 20 16 21 </script> -
trunk/LayoutTests/editing/execCommand/5573879-expected.txt
r69982 r70283 1 This tests to make sure that RemoveFormat destroys lists if they are fully selected. You should see foo<br>bar below. 2 | <div> 3 | "<#selection-anchor>foo" 4 | <br> 5 | "bar<#selection-focus>" 1 This tests to make sure that RemoveFormat destroys lists if they are fully selected. However, because the bug 43017 requires WebKit does not destroy lists, "foo" and "bar" should be in a separate list item. 2 | <ul> 3 | <li> 4 | "<#selection-anchor>foo" 5 | <li> 6 | "bar<#selection-focus>" -
trunk/LayoutTests/editing/execCommand/5573879.html
r69982 r70283 12 12 document.execCommand("RemoveFormat"); 13 13 14 Markup.description('This tests to make sure that RemoveFormat destroys lists if they are fully selected. You should see foo<br>bar below.'); 14 Markup.description('This tests to make sure that RemoveFormat destroys lists if they are fully selected.' 15 + ' However, because the bug 43017 requires WebKit does not destroy lists, "foo" and "bar" should be in a separate list item.'); 15 16 Markup.dump(div); 16 17 -
trunk/LayoutTests/editing/execCommand/5770834-1-expected.txt
r66585 r70283 3 3 4 4 <div style="text-align: right;"> 5 <div style="text-align: -webkit-auto;">foo<br>bar</div>5 <div>foo<br>bar</div> 6 6 </div> 7 7 -
trunk/LayoutTests/editing/execCommand/remove-formatting-2-expected.txt
r70031 r70283 10 10 EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification 11 11 This tests that RemoveFormat not only removes style from the selected part of the DOM, but that it also applies the document default style to the selection if that's necessary in order to leave the selected text unstyled. 12 | "<#selection-anchor>This<#selection-focus> text should look the same as the text above." 12 | "<#selection-anchor>This<#selection-focus>" 13 | " text should look the same as the text above." -
trunk/LayoutTests/editing/execCommand/remove-formatting-expected.txt
r70031 r70283 5 5 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 6 6 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 7 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 9of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE7 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 3 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 8 8 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 9 9 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification … … 13 13 14 14 markup: 15 | "<#selection-anchor>foobarbaz" 15 | " 16 " 17 | "<#selection-anchor>foo" 18 | <a> 19 | href="http://www.google.com/" 20 | "bar" 21 | "baz" 16 22 | <br> 17 | "foo bar baz" 23 | " 24 " 25 | <table> 26 | border="1" 27 | <tbody> 28 | <tr> 29 | <td> 30 | "foo" 31 | <td> 32 | "bar" 33 | <td> 34 | "baz" 35 | " 36 " 37 | "foo" 38 | "bar" 39 | "baz<#selection-focus>" 18 40 | <br> 19 | "foobarbaz<#selection-focus>"20 41 | " 21 42 " -
trunk/LayoutTests/editing/execCommand/script-tests/toggle-link.js
r66040 r70283 43 43 testSingleToggle("createLink", '<a href="http://trac.webkit.org/" style="font-style: italic;">hello world</a> WebKit', selectFirstTwoWords, '<i><a href="http://webkit.org/">hello world</a></i> WebKit'); 44 44 testSingleToggle("createLink", 'hello <a href="http://trac.webkit.org/"><b>world</b> WebKit</a>', selectFirstTwoWords, '<a href="http://webkit.org/">hello <b>world</b></a><a href="http://trac.webkit.org/"> WebKit</a>'); 45 testSingleToggle("createLink", 'hello <a href="http://trac.webkit.org/" style="font-style: italic;"><b>world</b> WebKit</a>', selectFirstTwoWords, '<a href="http://webkit.org/">hello <b style="font-style: italic; ">world</b></a><a href="http://trac.webkit.org/"><i> WebKit</i></a>'); 45 testSingleToggle("createLink", 'hello <a href="http://trac.webkit.org/" style="font-style: italic;"><b>world</b> WebKit</a>', selectFirstTwoWords, 46 '<a href="http://webkit.org/">hello <b style="font-style: italic; ">world</b></a><a href="http://trac.webkit.org/"><i> WebKit</i></a>'); 46 47 testSingleToggle("createLink", 'hello <b>world</b> WebKit', selectLastWord, 'hello <b>world</b> <a href="http://webkit.org/">WebKit</a>'); 47 48 testSingleToggle("createLink", '<u>hello <b>world</b> WebKit</u>', selectLastWord, '<u>hello <b>world</b> <a href="http://webkit.org/">WebKit</a></u>'); 48 testSingleToggle("createLink", '<a href="http://trac.webkit.org/"><div>hello</div><div>world</div></a>', selectLastWord, '<div><a href="http://trac.webkit.org/">hello</a></div><div><a href="http://webkit.org/">world</a></div>'); 49 testSingleToggle("createLink", '<a href="http://trac.webkit.org/" style="font-weight: bold;"><div>hello</div><div>world</div></a>', selectLastWord, '<div style="font-weight: bold; "><a href="http://trac.webkit.org/">hello</a></div><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>'); 50 testSingleToggle("createLink", '<a href="http://trac.webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>', selectLastWord, '<div style="font-weight: normal; "><a href="http://trac.webkit.org/">hello</a></div><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>'); 49 testSingleToggle("createLink", '<a href="http://trac.webkit.org/"><div>hello</div><div>world</div></a>', selectLastWord, 50 '<a href="http://trac.webkit.org/"><div>hello</div></a><div><a href="http://webkit.org/">world</a></div>'); 51 testSingleToggle("createLink", '<a href="http://trac.webkit.org/" style="font-weight: bold;"><div>hello</div><div>world</div></a>', selectLastWord, 52 '<a href="http://trac.webkit.org/"><div style="font-weight: bold; ">hello</div></a><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>'); 53 testSingleToggle("createLink", '<a href="http://trac.webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>', selectLastWord, 54 '<a href="http://trac.webkit.org/"><div style="font-weight: normal; ">hello</div></a><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>'); 51 55 52 56 document.body.removeChild(testContainer); -
trunk/LayoutTests/editing/execCommand/script-tests/toggle-unlink.js
r69910 r70283 60 60 selectAll, 'hello<div style="background-color: yellow; ">world</div><span class="Apple-style-span" style="background-color: yellow;">WebKit</span>'); 61 61 testSingleToggle("unlink", '<a href="http://webkit.org/" style="font-weight: bold;"><div>hello</div><div>world WebKit</div></a>', 62 selectLastTwoWords, '< div style="font-weight: bold; "><a href="http://webkit.org/">hello</a></div><div style="font-weight: bold; ">world WebKit</div>');62 selectLastTwoWords, '<a href="http://webkit.org/"><div style="font-weight: bold; ">hello</div></a><div style="font-weight: bold; ">world WebKit</div>'); 63 63 testSingleToggle("unlink", '<a href="http://webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>', 64 selectLastWord, '< div style="font-weight: normal; "><a href="http://webkit.org/">hello</a></div><div style="font-weight: bold; ">world</div>');64 selectLastWord, '<a href="http://webkit.org/"><div style="font-weight: normal; ">hello</div></a><div style="font-weight: bold; ">world</div>'); 65 65 66 66 document.body.removeChild(testContainer); -
trunk/LayoutTests/editing/execCommand/toggle-link-expected.txt
r66040 r70283 15 15 PASS select last word of "hello <b>world</b> WebKit" and createLink (http://webkit.org/) yields "hello <b>world</b> <a href="http://webkit.org/">WebKit</a>" 16 16 PASS select last word of "<u>hello <b>world</b> WebKit</u>" and createLink (http://webkit.org/) yields "<u>hello <b>world</b> <a href="http://webkit.org/">WebKit</a></u>" 17 PASS select last word of "<a href="http://trac.webkit.org/"><div>hello</div><div>world</div></a>" and createLink (http://webkit.org/) yields "< div><a href="http://trac.webkit.org/">hello</a></div><div><a href="http://webkit.org/">world</a></div>"18 PASS select last word of "<a href="http://trac.webkit.org/" style="font-weight: bold;"><div>hello</div><div>world</div></a>" and createLink (http://webkit.org/) yields "< div style="font-weight: bold; "><a href="http://trac.webkit.org/">hello</a></div><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>"19 PASS select last word of "<a href="http://trac.webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>" and createLink (http://webkit.org/) yields "< div style="font-weight: normal; "><a href="http://trac.webkit.org/">hello</a></div><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>"17 PASS select last word of "<a href="http://trac.webkit.org/"><div>hello</div><div>world</div></a>" and createLink (http://webkit.org/) yields "<a href="http://trac.webkit.org/"><div>hello</div></a><div><a href="http://webkit.org/">world</a></div>" 18 PASS select last word of "<a href="http://trac.webkit.org/" style="font-weight: bold;"><div>hello</div><div>world</div></a>" and createLink (http://webkit.org/) yields "<a href="http://trac.webkit.org/"><div style="font-weight: bold; ">hello</div></a><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>" 19 PASS select last word of "<a href="http://trac.webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>" and createLink (http://webkit.org/) yields "<a href="http://trac.webkit.org/"><div style="font-weight: normal; ">hello</div></a><div style="font-weight: bold; "><a href="http://webkit.org/">world</a></div>" 20 20 PASS successfullyParsed is true 21 21 -
trunk/LayoutTests/editing/execCommand/toggle-unlink-expected.txt
r69910 r70283 15 15 PASS unlink on all of "<a href="http://webkit.org/" style="background-color: yellow;"><div>hello</div><div>world</div></a>" yields "<div style="background-color: yellow; ">hello</div><div style="background-color: yellow; ">world</div>" 16 16 PASS unlink on all of "hello<a href="http://webkit.org/" style="background-color: yellow;"><div>world</div></a>WebKit" yields "hello<div style="background-color: yellow; ">world</div><span class="Apple-style-span" style="background-color: yellow;">WebKit</span>" 17 PASS unlink on last two words of "<a href="http://webkit.org/" style="font-weight: bold;"><div>hello</div><div>world WebKit</div></a>" yields "< div style="font-weight: bold; "><a href="http://webkit.org/">hello</a></div><div style="font-weight: bold; ">world WebKit</div>"18 PASS unlink on last word of "<a href="http://webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>" yields "< div style="font-weight: normal; "><a href="http://webkit.org/">hello</a></div><div style="font-weight: bold; ">world</div>"17 PASS unlink on last two words of "<a href="http://webkit.org/" style="font-weight: bold;"><div>hello</div><div>world WebKit</div></a>" yields "<a href="http://webkit.org/"><div style="font-weight: bold; ">hello</div></a><div style="font-weight: bold; ">world WebKit</div>" 18 PASS unlink on last word of "<a href="http://webkit.org/" style="font-weight: bold;"><div style="font-weight: normal;">hello</div><div>world</div></a>" yields "<a href="http://webkit.org/"><div style="font-weight: normal; ">hello</div></a><div style="font-weight: bold; ">world</div>" 19 19 PASS successfullyParsed is true 20 20 -
trunk/LayoutTests/editing/execCommand/unlink-expected.txt
r68830 r70283 65 65 This paragraph should should end up unlinked. 66 66 <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> 67 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.67 This paragraph starts with <a href="http://www.google.com"><i>a</i></a><span id="test3start"> link</span> in the middle. Only the 'a' in the previous sentence should be linked after the test. 68 68 <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 <b>line</b> contains <img src="../resources/abe.png"> an image. </a> -
trunk/LayoutTests/editing/inserting/space-after-removeformat-expected.txt
r69509 r70283 1 1 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 2 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification3 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV > BODY > HTML > #document to 10 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE4 EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of BODY > HTML > #document to 9 of BODY > HTML > #document5 EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification6 2 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 7 3 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification -
trunk/WebCore/ChangeLog
r70282 r70283 1 2010-10-21 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Tony Chang. 4 5 removeFormat needs to be reimplemented 6 https://bugs.webkit.org/show_bug.cgi?id=43017 7 8 Reimplemented execCommand('RemoveFormat', false, null). New implementation removes 9 the same elements removed by Internet Explorer. Because WebKit supports StyleWithCSS 10 we also reset any editing styles to match that of the root editable element 11 while Internet Explorer does not remove any CSS styles. 12 13 New implementation uses ApplyStyleCommand to remove appropriate elements and reset the style. 14 Added new constructor and member variable to ApplyStyleCommand to support mass-removal of elements 15 since it's inefficient to call ApplyStyleCommand on each element we're removing. 16 17 To avoid an infinite loop in pushDownInlineStyleAroundNode when mass-removing, WebKit no longer 18 push down element one level at a time. Instead, we keep a stack of styled elements to be applied, 19 and apply wrap siblings of targetNode's ancestors by all of them at once. 20 21 Tests: editing/execCommand/remove-format-elements.html 22 editing/execCommand/remove-format-multiple-elements.html 23 24 * editing/ApplyStyleCommand.cpp: 25 (WebCore::ApplyStyleCommand::ApplyStyleCommand): Added; this version takes style and a function pointer 26 to a boolean function that determines which element needs to removed, and set m_removeOnly to true. 27 (WebCore::ApplyStyleCommand::doApply): Added support for m_isInlineElementToRemoveFunction. 28 (WebCore::ApplyStyleCommand::applyBlockStyle): Ditto. 29 (WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange): Exits early if m_removeOnly is true. 30 (WebCore::ApplyStyleCommand::isStyledInlineElementToRemove): Added. 31 (WebCore::ApplyStyleCommand::removeStyleFromRunBeforeApplyingStyle): Calls isStyledInlineElementToRemove. 32 (WebCore::ApplyStyleCommand::removeInlineStyleFromElement): Ditto. 33 (WebCore::ApplyStyleCommand::removeInlineStyle): Ditto. 34 (WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode): See above. 35 * editing/ApplyStyleCommand.h: 36 (WebCore::ApplyStyleCommand::create): Added. 37 * editing/RemoveFormatCommand.cpp: 38 (WebCore::isElementForRemoveFormatCommand): Added. 39 (WebCore::RemoveFormatCommand::doApply): Rewritten. 40 1 41 2010-10-21 Tony Gentilcore <tonyg@chromium.org> 2 42 -
trunk/WebCore/editing/ApplyStyleCommand.cpp
r69910 r70283 539 539 , m_styledInlineElement(0) 540 540 , m_removeOnly(false) 541 , m_isInlineElementToRemoveFunction(0) 541 542 { 542 543 } … … 552 553 , m_styledInlineElement(0) 553 554 , m_removeOnly(false) 555 , m_isInlineElementToRemoveFunction(0) 554 556 { 555 557 } … … 565 567 , m_styledInlineElement(element) 566 568 , m_removeOnly(removeOnly) 569 , m_isInlineElementToRemoveFunction(0) 570 { 571 } 572 573 ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction editingAction) 574 : CompositeEditCommand(document) 575 , m_style(style->makeMutable()) 576 , m_editingAction(editingAction) 577 , m_propertyLevel(PropertyDefault) 578 , m_start(endingSelection().start().downstream()) 579 , m_end(endingSelection().end().upstream()) 580 , m_useEndingSelection(true) 581 , m_styledInlineElement(0) 582 , m_removeOnly(true) 583 , m_isInlineElementToRemoveFunction(isInlineElementToRemoveFunction) 567 584 { 568 585 } … … 606 623 // apply any remaining styles to the inline elements 607 624 // NOTE: hopefully, this string comparison is the same as checking for a non-null diff 608 if (blockStyle->length() < m_style->length() || m_styledInlineElement ) {625 if (blockStyle->length() < m_style->length() || m_styledInlineElement || m_isInlineElementToRemoveFunction) { 609 626 RefPtr<CSSMutableStyleDeclaration> inlineStyle = m_style->copy(); 610 627 applyRelativeFontStyleChange(inlineStyle.get()); … … 665 682 if (styleChange.cssStyle().length() || m_removeOnly) { 666 683 RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent().node()); 667 RefPtr<Node> newBlock = moveParagraphContentsToNewBlockIfNecessary(paragraphStart.deepEquivalent()); 668 if (newBlock) 669 block = newBlock; 684 if (!m_removeOnly) { 685 RefPtr<Node> newBlock = moveParagraphContentsToNewBlockIfNecessary(paragraphStart.deepEquivalent()); 686 if (newBlock) 687 block = newBlock; 688 } 670 689 ASSERT(block->isHTMLElement()); 671 690 if (block->isHTMLElement()) { … … 1127 1146 void ApplyStyleCommand::applyInlineStyleToNodeRange(CSSMutableStyleDeclaration* style, Node* node, Node* pastEndNode) 1128 1147 { 1148 if (m_removeOnly) 1149 return; 1150 1129 1151 for (Node* next; node && node != pastEndNode; node = next) { 1130 1152 next = node->traverseNextNode(); … … 1172 1194 if (!removeStyleFromRunBeforeApplyingStyle(style, node, runEnd)) 1173 1195 continue; 1174 addInlineStyleIfNeeded(style, node, runEnd, m_removeOnly ? DoNotAddStyledElement : AddStyledElement); 1175 } 1196 addInlineStyleIfNeeded(style, node, runEnd, AddStyledElement); 1197 } 1198 } 1199 1200 bool ApplyStyleCommand::isStyledInlineElementToRemove(Element* element) const 1201 { 1202 return (m_styledInlineElement && element->hasTagName(m_styledInlineElement->tagQName())) 1203 || (m_isInlineElementToRemoveFunction && m_isInlineElementToRemoveFunction(element)); 1176 1204 } 1177 1205 … … 1184 1212 if (node->childNodeCount()) 1185 1213 continue; 1214 // We don't consider m_isInlineElementToRemoveFunction here because we never apply style when m_isInlineElementToRemoveFunction is specified 1186 1215 if (getPropertiesNotIn(style, computedStyle(node).get())->length() 1187 1216 || (m_styledInlineElement && !enclosingNodeWithTag(positionBeforeNode(node), m_styledInlineElement->tagQName()))) { … … 1223 1252 return false; 1224 1253 1225 if ( m_styledInlineElement && element->hasTagName(m_styledInlineElement->tagQName())) {1254 if (isStyledInlineElementToRemove(element)) { 1226 1255 if (mode == RemoveNone) 1227 1256 return true; … … 1505 1534 // The outer loop is traversing the tree vertically from highestAncestor to targetNode 1506 1535 Node* current = highestAncestor; 1536 // Along the way, styled elements that contain targetNode are removed and accumulated into elementsToPushDown. 1537 // Each child of the removed element, exclusing ancestors of targetNode, is then wrapped by clones of elements in elementsToPushDown. 1538 Vector<RefPtr<Element> > elementsToPushDown; 1507 1539 while (current != targetNode) { 1508 1540 ASSERT(current); … … 1512 1544 Node* lastChild = current->lastChild(); 1513 1545 RefPtr<StyledElement> styledElement; 1514 if (current->isStyledElement() && m_styledInlineElement && current->hasTagName(m_styledInlineElement->tagQName()))1546 if (current->isStyledElement() && isStyledInlineElementToRemove(static_cast<Element*>(current))) { 1515 1547 styledElement = static_cast<StyledElement*>(current); 1548 elementsToPushDown.append(styledElement); 1549 } 1516 1550 RefPtr<CSSMutableStyleDeclaration> styleToPushDown = CSSMutableStyleDeclaration::create(); 1517 1551 removeInlineStyleFromElement(style, static_cast<HTMLElement*>(current), RemoveIfNeeded, styleToPushDown.get()); … … 1522 1556 Node* nextChild = child->nextSibling(); 1523 1557 1524 if (child != targetNode && styledElement) { 1525 // If child has children, wrap children of child by a clone of the styled element to avoid infinite loop. 1526 // Otherwise, wrap the child by the styled element, and we won't fall into an infinite loop. 1527 RefPtr<Element> wrapper = styledElement->cloneElementWithoutChildren(); 1528 ExceptionCode ec = 0; 1529 wrapper->removeAttribute(styleAttr, ec); 1530 ASSERT(!ec); 1531 if (child->firstChild()) 1532 surroundNodeRangeWithElement(child->firstChild(), child->lastChild(), wrapper); 1533 else 1558 if (!child->contains(targetNode) && elementsToPushDown.size()) { 1559 for (size_t i = 0; i < elementsToPushDown.size(); i++) { 1560 RefPtr<Element> wrapper = elementsToPushDown[i]->cloneElementWithoutChildren(); 1561 ExceptionCode ec = 0; 1562 wrapper->removeAttribute(styleAttr, ec); 1563 ASSERT(!ec); 1534 1564 surroundNodeRangeWithElement(child, child, wrapper); 1565 } 1535 1566 } 1536 1567 … … 1595 1626 RefPtr<CSSMutableStyleDeclaration> styleToPushDown; 1596 1627 PassRefPtr<Node> childNode = 0; 1597 if ( m_styledInlineElement && elem->hasTagName(m_styledInlineElement->tagQName())) {1628 if (isStyledInlineElementToRemove(elem.get())) { 1598 1629 styleToPushDown = CSSMutableStyleDeclaration::create(); 1599 1630 childNode = elem->firstChild(); -
trunk/WebCore/editing/ApplyStyleCommand.h
r68059 r70283 45 45 enum InlineStyleRemovalMode { RemoveIfNeeded, RemoveAlways, RemoveNone }; 46 46 enum EAddStyledElement { AddStyledElement, DoNotAddStyledElement }; 47 typedef bool (*IsInlineElementToRemoveFunction)(const Element*); 47 48 48 49 static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault) … … 58 59 return adoptRef(new ApplyStyleCommand(element, removeOnly, action)); 59 60 } 61 static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction action = EditActionChangeAttributes) 62 { 63 return adoptRef(new ApplyStyleCommand(document, style, isInlineElementToRemoveFunction, action)); 64 } 60 65 61 66 static RefPtr<CSSMutableStyleDeclaration> removeNonEditingProperties(CSSStyleDeclaration* style); … … 66 71 ApplyStyleCommand(Document*, CSSStyleDeclaration*, const Position& start, const Position& end, EditAction, EPropertyLevel); 67 72 ApplyStyleCommand(PassRefPtr<Element>, bool removeOnly, EditAction); 73 ApplyStyleCommand(Document*, CSSStyleDeclaration*, bool (*isInlineElementToRemove)(const Element*), EditAction); 68 74 69 75 virtual void doApply(); … … 73 79 74 80 // style-removal helpers 81 bool isStyledInlineElementToRemove(Element*) const; 75 82 bool removeStyleFromRunBeforeApplyingStyle(CSSMutableStyleDeclaration* style, Node*& runStart, Node*& runEnd); 76 83 bool removeInlineStyleFromElement(CSSMutableStyleDeclaration*, HTMLElement*, InlineStyleRemovalMode = RemoveIfNeeded, CSSMutableStyleDeclaration* extractedStyle = 0); … … 123 130 RefPtr<Element> m_styledInlineElement; 124 131 bool m_removeOnly; 132 IsInlineElementToRemoveFunction m_isInlineElementToRemoveFunction; 125 133 }; 126 134 -
trunk/WebCore/editing/RemoveFormatCommand.cpp
r67238 r70283 1 1 /* 2 2 * Copyright (C) 2007 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 11 12 * documentation and/or other materials provided with the distribution. 12 13 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 25 */ 25 26 … … 27 28 #include "RemoveFormatCommand.h" 28 29 30 #include "ApplyStyleCommand.h" 29 31 #include "CSSComputedStyleDeclaration.h" 30 32 #include "CSSMutableStyleDeclaration.h" 33 #include "CSSValueKeywords.h" 31 34 #include "Editor.h" 32 35 #include "Frame.h" 36 #include "HTMLElement.h" 33 37 #include "HTMLNames.h" 34 38 #include "VisibleSelection.h" … … 36 40 #include "TextIterator.h" 37 41 #include "TypingCommand.h" 38 #include " ApplyStyleCommand.h"42 #include "htmlediting.h" 39 43 40 44 namespace WebCore { … … 47 51 } 48 52 53 static bool isElementForRemoveFormatCommand(const Element* element) 54 { 55 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, elements, ()); 56 if (elements.isEmpty()) { 57 elements.add(acronymTag); 58 elements.add(bTag); 59 elements.add(bdoTag); 60 elements.add(bigTag); 61 elements.add(citeTag); 62 elements.add(codeTag); 63 elements.add(dfnTag); 64 elements.add(emTag); 65 elements.add(fontTag); 66 elements.add(iTag); 67 elements.add(insTag); 68 elements.add(kbdTag); 69 elements.add(nobrTag); 70 elements.add(qTag); 71 elements.add(sTag); 72 elements.add(sampTag); 73 elements.add(smallTag); 74 elements.add(strikeTag); 75 elements.add(strongTag); 76 elements.add(subTag); 77 elements.add(supTag); 78 elements.add(ttTag); 79 elements.add(uTag); 80 elements.add(varTag); 81 } 82 return elements.contains(element->tagQName()); 83 } 84 49 85 void RemoveFormatCommand::doApply() 50 86 { … … 54 90 return; 55 91 56 // Make a plain text string from the selection to remove formatting like tables and lists.57 String string = plainText(frame->selection()->selection().toNormalizedRange().get());58 59 92 // Get the default style for this editable root, it's the style that we'll give the 60 93 // content that we're operating on. … … 62 95 RefPtr<CSSMutableStyleDeclaration> defaultStyle = ApplyStyleCommand::editingStyleAtPosition(Position(root, 0)); 63 96 64 // Delete the selected content. 65 // FIXME: We should be able to leave this to insertText, but its delete operation 66 // doesn't preserve the style we're about to set. 67 deleteSelection(); 68 69 // Delete doesn't remove fully selected lists. 70 while (breakOutOfEmptyListItem()) 71 ; 72 73 // If the selection was all formatting (like an empty list) the format-less text will 74 // be empty. Early return since we don't need to do any of the work that follows and 75 // to avoid the ASSERT that fires if input(...) is called with an empty String. 76 if (string.isEmpty()) 77 return; 78 79 // Insert the content with the default style. 80 // See <rdar://problem/5794382> RemoveFormat doesn't always reset text alignment 81 frame->selection()->setTypingStyle(defaultStyle.release()); 82 83 inputText(string, true); 97 applyCommandToComposite(ApplyStyleCommand::create(document(), defaultStyle.get(), isElementForRemoveFormatCommand, editingAction())); 84 98 } 85 99
Note: See TracChangeset
for help on using the changeset viewer.