| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 504 } |
| 505 | 505 |
| 506 if (!inlineStyle || newInlineStyle->isEmpty()) { | 506 if (!inlineStyle || newInlineStyle->isEmpty()) { |
| 507 if (isStyleSpanOrSpanWithOnlyStyleAttribute(element)) | 507 if (isStyleSpanOrSpanWithOnlyStyleAttribute(element)) |
| 508 removeNodePreservingChildren(element); | 508 removeNodePreservingChildren(element); |
| 509 else | 509 else |
| 510 removeNodeAttribute(element, styleAttr); | 510 removeNodeAttribute(element, styleAttr); |
| 511 } else if (newInlineStyle->style()->length() != inlineStyle->length()) | 511 } else if (newInlineStyle->style()->length() != inlineStyle->length()) |
| 512 setNodeAttribute(element, styleAttr, newInlineStyle->style()->cssTex
t()); | 512 setNodeAttribute(element, styleAttr, newInlineStyle->style()->cssTex
t()); |
| 513 | 513 |
| 514 // WebKit used to not add display: inline and float: none on copy. | 514 if (isStyleSpan(element)) { |
| 515 // Keep this code around for backward compatibility | |
| 516 if (isLegacyAppleStyleSpan(element)) { | |
| 517 if (!element->firstChild()) { | 515 if (!element->firstChild()) { |
| 518 removeNodePreservingChildren(element); | 516 removeNodePreservingChildren(element); |
| 519 continue; | 517 continue; |
| 520 } | 518 } |
| 521 // There are other styles that style rules can give to style spans, | 519 // There are other styles that style rules can give to style spans, |
| 522 // but these are the two important ones because they'll prevent | 520 // but these are the two important ones because they'll prevent |
| 523 // inserted content from appearing in the right paragraph. | 521 // inserted content from appearing in the right paragraph. |
| 524 // FIXME: Hyatt is concerned that selectively using display:inline w
ill give inconsistent | 522 // FIXME: Hyatt is concerned that selectively using display:inline w
ill give inconsistent |
| 525 // results. We already know one issue because td elements ignore the
ir display property | 523 // results. We already know one issue because td elements ignore the
ir display property |
| 526 // in quirks mode (which Mail.app is always in). We should look for
an alternative. | 524 // in quirks mode (which Mail.app is always in). We should look for
an alternative. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 { | 609 { |
| 612 Node* topNode = fragment.firstChild(); | 610 Node* topNode = fragment.firstChild(); |
| 613 | 611 |
| 614 // Handling the case where we are doing Paste as Quotation or pasting into q
uoted content is more complicated (see handleStyleSpans) | 612 // Handling the case where we are doing Paste as Quotation or pasting into q
uoted content is more complicated (see handleStyleSpans) |
| 615 // and doesn't receive the optimization. | 613 // and doesn't receive the optimization. |
| 616 if (isMailPasteAsQuotationNode(topNode) || enclosingNodeOfType(firstPosition
InOrBeforeNode(topNode), isMailBlockquote, CanCrossEditingBoundary)) | 614 if (isMailPasteAsQuotationNode(topNode) || enclosingNodeOfType(firstPosition
InOrBeforeNode(topNode), isMailBlockquote, CanCrossEditingBoundary)) |
| 617 return false; | 615 return false; |
| 618 | 616 |
| 619 // Either there are no style spans in the fragment or a WebKit client has ad
ded content to the fragment | 617 // Either there are no style spans in the fragment or a WebKit client has ad
ded content to the fragment |
| 620 // before inserting it. Look for and handle style spans after insertion. | 618 // before inserting it. Look for and handle style spans after insertion. |
| 621 if (!isLegacyAppleStyleSpan(topNode)) | 619 if (!isStyleSpan(topNode)) |
| 622 return false; | 620 return false; |
| 623 | 621 |
| 624 Node* wrappingStyleSpan = topNode; | 622 Node* wrappingStyleSpan = topNode; |
| 625 RefPtr<EditingStyle> styleAtInsertionPos = EditingStyle::create(insertionPos
.parentAnchoredEquivalent()); | 623 RefPtr<EditingStyle> styleAtInsertionPos = EditingStyle::create(insertionPos
.parentAnchoredEquivalent()); |
| 626 String styleText = styleAtInsertionPos->style()->cssText(); | 624 String styleText = styleAtInsertionPos->style()->cssText(); |
| 627 | 625 |
| 628 // FIXME: This string comparison is a naive way of comparing two styles. | 626 // FIXME: This string comparison is a naive way of comparing two styles. |
| 629 // We should be taking the diff and check that the diff is empty. | 627 // We should be taking the diff and check that the diff is empty. |
| 630 if (styleText != static_cast<Element*>(wrappingStyleSpan)->getAttribute(styl
eAttr)) | 628 if (styleText != static_cast<Element*>(wrappingStyleSpan)->getAttribute(styl
eAttr)) |
| 631 return false; | 629 return false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 642 // We should remove the Apple-style-span class when we're done, see <rdar://prob
lem/5685600>. | 640 // We should remove the Apple-style-span class when we're done, see <rdar://prob
lem/5685600>. |
| 643 // We should remove styles from spans that are overridden by all of their childr
en, either here | 641 // We should remove styles from spans that are overridden by all of their childr
en, either here |
| 644 // or at copy time. | 642 // or at copy time. |
| 645 void ReplaceSelectionCommand::handleStyleSpans() | 643 void ReplaceSelectionCommand::handleStyleSpans() |
| 646 { | 644 { |
| 647 HTMLElement* wrappingStyleSpan = 0; | 645 HTMLElement* wrappingStyleSpan = 0; |
| 648 // The style span that contains the source document's default style should b
e at | 646 // The style span that contains the source document's default style should b
e at |
| 649 // the top of the fragment, but Mail sometimes adds a wrapper (for Paste As
Quotation), | 647 // the top of the fragment, but Mail sometimes adds a wrapper (for Paste As
Quotation), |
| 650 // so search for the top level style span instead of assuming it's at the to
p. | 648 // so search for the top level style span instead of assuming it's at the to
p. |
| 651 for (Node* node = m_firstNodeInserted.get(); node; node = node->traverseNext
Node()) { | 649 for (Node* node = m_firstNodeInserted.get(); node; node = node->traverseNext
Node()) { |
| 652 if (isLegacyAppleStyleSpan(node)) { | 650 if (isStyleSpan(node)) { |
| 653 wrappingStyleSpan = toHTMLElement(node); | 651 wrappingStyleSpan = toHTMLElement(node); |
| 654 break; | 652 break; |
| 655 } | 653 } |
| 656 } | 654 } |
| 657 | 655 |
| 658 // There might not be any style spans if we're pasting from another applicat
ion or if | 656 // There might not be any style spans if we're pasting from another applicat
ion or if |
| 659 // we are here because of a document.execCommand("InsertHTML", ...) call. | 657 // we are here because of a document.execCommand("InsertHTML", ...) call. |
| 660 if (!wrappingStyleSpan) | 658 if (!wrappingStyleSpan) |
| 661 return; | 659 return; |
| 662 | 660 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 // 6) Select the replacement if requested, and match style if requested. | 984 // 6) Select the replacement if requested, and match style if requested. |
| 987 | 985 |
| 988 VisiblePosition startOfInsertedContent, endOfInsertedContent; | 986 VisiblePosition startOfInsertedContent, endOfInsertedContent; |
| 989 | 987 |
| 990 RefPtr<Node> refNode = fragment.firstChild(); | 988 RefPtr<Node> refNode = fragment.firstChild(); |
| 991 RefPtr<Node> node = refNode->nextSibling(); | 989 RefPtr<Node> node = refNode->nextSibling(); |
| 992 | 990 |
| 993 fragment.removeNode(refNode); | 991 fragment.removeNode(refNode); |
| 994 | 992 |
| 995 Node* blockStart = enclosingBlock(insertionPos.deprecatedNode()); | 993 Node* blockStart = enclosingBlock(insertionPos.deprecatedNode()); |
| 996 if ((isListElement(refNode.get()) || (isLegacyAppleStyleSpan(refNode.get())
&& isListElement(refNode->firstChild()))) | 994 if ((isListElement(refNode.get()) || (isStyleSpan(refNode.get()) && isListEl
ement(refNode->firstChild()))) |
| 997 && blockStart && blockStart->renderer()->isListItem()) | 995 && blockStart && blockStart->renderer()->isListItem()) |
| 998 refNode = insertAsListItems(refNode, blockStart, insertionPos); | 996 refNode = insertAsListItems(refNode, blockStart, insertionPos); |
| 999 else | 997 else |
| 1000 insertNodeAtAndUpdateNodesInserted(refNode, insertionPos); | 998 insertNodeAtAndUpdateNodesInserted(refNode, insertionPos); |
| 1001 | 999 |
| 1002 // Mutation events (bug 22634) may have already removed the inserted content | 1000 // Mutation events (bug 22634) may have already removed the inserted content |
| 1003 if (!refNode->inDocument()) | 1001 if (!refNode->inDocument()) |
| 1004 return; | 1002 return; |
| 1005 | 1003 |
| 1006 bool plainTextFragment = isPlainTextMarkup(refNode.get()); | 1004 bool plainTextFragment = isPlainTextMarkup(refNode.get()); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 return false; | 1325 return false; |
| 1328 | 1326 |
| 1329 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); | 1327 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); |
| 1330 | 1328 |
| 1331 setEndingSelection(selectionAfterReplace); | 1329 setEndingSelection(selectionAfterReplace); |
| 1332 | 1330 |
| 1333 return true; | 1331 return true; |
| 1334 } | 1332 } |
| 1335 | 1333 |
| 1336 } // namespace WebCore | 1334 } // namespace WebCore |
| OLD | NEW |