Changeset 92330 in webkit
- Timestamp:
- Aug 3, 2011 4:42:25 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r92327 r92330 1 2011-08-03 Ryosuke Niwa <rniwa@webkit.org> 2 3 select-all, copy, paste of specialAncestorElements (e.g. pre, h1, etc) nests the element inside itself 4 https://bugs.webkit.org/show_bug.cgi?id=26483 5 6 Reviewed by Enrica Casucci. 7 8 * editing/pasteboard/5065605-expected.txt: 9 * editing/pasteboard/copy-paste-text-in-h1-expected.txt: Added. 10 * editing/pasteboard/copy-paste-text-in-h1.html: Added. 11 * editing/pasteboard/display-block-on-spans-expected.txt: 12 * editing/pasteboard/paste-pre-001-expected.txt: 13 * editing/pasteboard/paste-pre-002-expected.txt: 14 * editing/pasteboard/paste-text-011-expected.txt: 15 1 16 2011-08-03 Mark Pilgrim <pilgrim@chromium.org> 2 17 -
trunk/LayoutTests/editing/pasteboard/5065605-expected.txt
r86983 r92330 22 22 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted 23 23 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 24 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 24 of #text > FONT > DIV > SPAN > FONT > DIV > DIV > BODY > HTML > #document to 24 of #text > FONT > DIV > SPAN> FONT > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE24 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 24 of #text > FONT > DIV > DIV > BODY > HTML > #document to 24 of #text > FONT > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 25 25 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 26 26 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification … … 37 37 | color="#ff0000" 38 38 | "This text should be red." 39 | <font> 40 | class="Apple-style-span" 41 | color="#ff0000" 42 | "This text should be red." 39 43 | <div> 40 44 | <font> 41 45 | class="Apple-style-span" 42 46 | color="#ff0000" 43 | <span> 44 | class="Apple-style-span" 45 | style="color: rgb(0, 0, 0); " 46 | <font> 47 | class="Apple-style-span" 48 | color="#ff0000" 49 | "This text should be red." 50 | <div> 51 | <font> 52 | class="Apple-style-span" 53 | color="#ff0000" 54 | "This text should be red.<#selection-caret>" 47 | "This text should be red.<#selection-caret>" -
trunk/LayoutTests/editing/pasteboard/display-block-on-spans-expected.txt
r83268 r92330 30 30 | style="display:block" 31 31 | <b> 32 | "This<#selection-caret>" 33 | <b> 32 | <span> 33 | class="Apple-style-span" 34 | style="font-weight: normal; " 35 | <b> 36 | "This<#selection-caret>" 34 37 | " is another paragraph." 35 38 | <br> -
trunk/LayoutTests/editing/pasteboard/paste-pre-001-expected.txt
r87531 r92330 8 8 bar 9 9 execCutCommand: <div id="test" class="editing"> <pre><br></pre> </div> 10 execPasteCommand: <div id="test" class="editing"> <pre> <span class="Apple-style-span" style="font-family: Times; white-space: normal; "><pre>foo bar</pre></span></pre> </div>10 execPasteCommand: <div id="test" class="editing"> <pre>foo bar</pre> </div> -
trunk/LayoutTests/editing/pasteboard/paste-pre-002-expected.txt
r87531 r92330 3 3 bar 4 4 execCopyCommand: <div id="test" class="editing"> <pre>foo bar</pre> </div> 5 execPasteCommand: <div id="test" class="editing"> <pre> <span class="Apple-style-span" style="font-family: Times; white-space: normal; "><pre>foo bar</pre></span></pre> </div>5 execPasteCommand: <div id="test" class="editing"> <pre>foo bar</pre> </div> -
trunk/LayoutTests/editing/pasteboard/paste-text-011-expected.txt
r86983 r92330 7 7 EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of P > BODY > HTML > #document to 0 of P > BODY > HTML > #document givenAction:WebViewInsertActionPasted 8 8 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 9 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 5 of #text > B > FONT > P > SPAN > B > FONT > P > BODY > HTML > #document to 5 of #text > B > FONT > P > SPAN> B > FONT > P > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE9 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 5 of #text > B > FONT > P > BODY > HTML > #document to 5 of #text > B > FONT > P > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 10 10 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 11 11 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification … … 31 31 | face="Monaco" 32 32 | <b> 33 | <span> 34 | class="Apple-style-span" 35 | style="font-family: Times; font-weight: normal; " 36 | <p> 37 | <font> 38 | face="Monaco" 39 | <b> 40 | "hello" 41 | <p> 42 | <font> 43 | face="Monaco" 44 | <b> 45 | "there<#selection-caret>" 33 | "hello" 34 | <p> 35 | <font> 36 | face="Monaco" 37 | <b> 38 | "there<#selection-caret>" 46 39 | " 47 40 -
trunk/Source/WebCore/ChangeLog
r92328 r92330 1 2011-08-03 Ryosuke Niwa <rniwa@webkit.org> 2 3 select-all, copy, paste of specialAncestorElements (e.g. pre, h1, etc) nests the element inside itself 4 https://bugs.webkit.org/show_bug.cgi?id=26483 5 6 Reviewed by Enrica Casucci. 7 8 The bug was caused by WebKit serializing pre, h1, etc... to retain structure and appearance when copying 9 rich content and pasting did not remove such nodes wrapping the copied contents. 10 11 Fixed the bug by extending r81887 and r83322 to remove those elements from where WebKit pastes into. 12 13 Test: editing/pasteboard/copy-paste-text-in-h1.html 14 15 * editing/ReplaceSelectionCommand.cpp: 16 (WebCore::nodeHasAttributesToPreserve): Extracted from isInlineNodeWithStyle. 17 (WebCore::isInlineNodeWithStyle): Calls nodeHasAttributesToPreserve. 18 (WebCore::ReplaceSelectionCommand::doApply): Calls ancestorToRetainStructureAndAppearance. 19 Remove nodes copied by ancestorToRetainStructureAndAppearance at insertionPos before pasting the fragment. 20 * editing/markup.cpp: 21 (WebCore::ancestorToRetainStructureAndAppearance): Takes ShouldIncludeParagraphSeparators. 22 * editing/markup.h: 23 1 24 2011-08-03 Mark Pilgrim <pilgrim@chromium.org> 2 25 -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r91702 r92330 761 761 } 762 762 763 static bool nodeHasAttributesToPreserve(const HTMLElement* element) 764 { 765 const NamedNodeMap* attributeMap = element->attributeMap(); 766 return attributeMap && !attributeMap->isEmpty() && (attributeMap->length() > 1 || !element->hasAttribute(styleAttr)); 767 } 768 763 769 static bool isInlineNodeWithStyle(const Node* node) 764 770 { … … 782 788 // We can skip inline elements that don't have attributes or whose only 783 789 // attribute is the style attribute. 784 const NamedNodeMap* attributeMap = element->attributeMap(); 785 if (!attributeMap || attributeMap->isEmpty() || (attributeMap->length() == 1 && element->hasAttribute(styleAttr))) 786 return true; 787 788 return false; 790 return !nodeHasAttributesToPreserve(static_cast<const HTMLElement*>(node)); 789 791 } 790 792 … … 938 940 // our style spans and for positions inside list items 939 941 // since insertAsListItems already does the right thing. 940 if (!m_matchStyle && !enclosingList(insertionPos.containerNode()) && isStyleSpan(fragment.firstChild())) { 942 if (!m_matchStyle && !enclosingList(insertionPos.containerNode()) && isStyleSpan(fragment.firstChild()) 943 && VisiblePosition(firstPositionInNode(insertionPos.containerNode())) == VisiblePosition(lastPositionInNode(insertionPos.containerNode()))) { 941 944 if (insertionPos.containerNode()->isTextNode() && insertionPos.offsetInContainerNode() && !insertionPos.atLastEditingPositionForNode()) { 942 945 splitTextNodeContainingElement(insertionPos.containerText(), insertionPos.offsetInContainerNode()); … … 944 947 } 945 948 946 // FIXME: isInlineNodeWithStyle does not check editability. 947 if (RefPtr<Node> nodeToSplitTo = highestEnclosingNodeOfType(insertionPos, isInlineNodeWithStyle)) { 948 if (insertionPos.containerNode() != nodeToSplitTo) { 949 nodeToSplitTo = splitTreeToNode(insertionPos.anchorNode(), nodeToSplitTo.get(), true).get(); 949 RefPtr<Node> nodeToSplitTo = highestEnclosingNodeOfType(insertionPos, isInlineNodeWithStyle); 950 if (HTMLElement* ancestor = ancestorToRetainStructureAndAppearance(nodeToSplitTo ? nodeToSplitTo.get() : insertionPos.containerNode(), IncludeParagraphSeparators)) { 951 if (ancestor->parentNode() && unsplittableElementForPosition(insertionPos)->contains(ancestor->parentNode()) && !nodeHasAttributesToPreserve(ancestor)) 952 nodeToSplitTo = ancestor; 953 } 954 if (nodeToSplitTo) { 955 if (insertionPos.containerNode() != nodeToSplitTo->parentNode()) { 956 nodeToSplitTo = splitTreeToNode(insertionPos.anchorNode(), nodeToSplitTo->parentNode()).get(); 950 957 insertionPos = positionInParentBeforeNode(nodeToSplitTo.get()); 951 958 } -
trunk/Source/WebCore/editing/markup.cpp
r89440 r92330 351 351 } 352 352 353 static Node* ancestorToRetainStructureAndAppearance(Node* commonAncestor)353 HTMLElement* ancestorToRetainStructureAndAppearance(Node* commonAncestor, ShouldIncludeParagraphSeparators shouldIncludeParagraphSeparators) 354 354 { 355 355 Node* commonAncestorBlock = enclosingBlock(commonAncestor); … … 363 363 table = table->parentNode(); 364 364 365 return t able;365 return toHTMLElement(table); 366 366 } 367 367 … … 377 377 || commonAncestorBlock->hasTagName(h4Tag) 378 378 || commonAncestorBlock->hasTagName(h5Tag)) 379 return commonAncestorBlock; 379 return toHTMLElement(commonAncestorBlock); 380 381 if (shouldIncludeParagraphSeparators == IncludeParagraphSeparators 382 && (commonAncestorBlock->hasTagName(pTag) || commonAncestorBlock->hasTagName(divTag))) 383 return toHTMLElement(commonAncestorBlock); 380 384 381 385 return 0; -
trunk/Source/WebCore/editing/markup.h
r85064 r92330 34 34 namespace WebCore { 35 35 36 class Document; 37 class DocumentFragment; 38 class Element; 39 class KURL; 40 class Node; 41 class Range; 36 class Document; 37 class DocumentFragment; 38 class Element; 39 class HTMLElement; 40 class KURL; 41 class Node; 42 class Range; 42 43 43 44 44 enum EChildrenOnly { IncludeNode, ChildrenOnly }; 45 enum EAbsoluteURLs { DoNotResolveURLs, AbsoluteURLs }; 45 46 46 47 48 47 PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String& text); 48 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document*, const String& markup, const String& baseURL, FragmentScriptingPermission = FragmentScriptingAllowed); 49 PassRefPtr<DocumentFragment> createFragmentFromNodes(Document*, const Vector<Node*>&); 49 50 50 bool isPlainTextMarkup(Node *node);51 bool isPlainTextMarkup(Node*); 51 52 52 String createMarkup(const Range*, 53 Vector<Node*>* = 0, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs); 54 String createMarkup(const Node*, EChildrenOnly = IncludeNode, Vector<Node*>* = 0, EAbsoluteURLs = DoNotResolveURLs); 55 56 String createFullMarkup(const Node*); 57 String createFullMarkup(const Range*); 53 String createMarkup(const Range*, Vector<Node*>* = 0, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs); 54 String createMarkup(const Node*, EChildrenOnly = IncludeNode, Vector<Node*>* = 0, EAbsoluteURLs = DoNotResolveURLs); 58 55 59 String urlToMarkup(const KURL&, const String& title); 60 String imageToMarkup(const KURL&, Element*); 56 String createFullMarkup(const Node*); 57 String createFullMarkup(const Range*); 58 59 String urlToMarkup(const KURL&, const String& title); 60 String imageToMarkup(const KURL&, Element*); 61 62 enum ShouldIncludeParagraphSeparators { DoNotIncludeParagraphSeparators, IncludeParagraphSeparators }; 63 HTMLElement* ancestorToRetainStructureAndAppearance(Node*, ShouldIncludeParagraphSeparators = DoNotIncludeParagraphSeparators); 64 61 65 } 62 66
Note: See TracChangeset
for help on using the changeset viewer.