| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 // Return the inserted content's first VisiblePosition. | 520 // Return the inserted content's first VisiblePosition. |
| 521 return VisiblePosition(nextCandidate(positionBeforeNode(m_firstNodeInserted.
get()))); | 521 return VisiblePosition(nextCandidate(positionBeforeNode(m_firstNodeInserted.
get()))); |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Remove style spans before insertion if they are unnecessary. It's faster bec
ause we'll | 524 // Remove style spans before insertion if they are unnecessary. It's faster bec
ause we'll |
| 525 // avoid doing a layout. | 525 // avoid doing a layout. |
| 526 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const
Position& insertionPos) | 526 static bool handleStyleSpansBeforeInsertion(ReplacementFragment& fragment, const
Position& insertionPos) |
| 527 { | 527 { |
| 528 Node* topNode = fragment.firstChild(); | 528 Node* topNode = fragment.firstChild(); |
| 529 | 529 |
| 530 // Handling this case is more complicated (see handleStyleSpans) and doesn't
receive the optimization. | 530 // Handling the case where we are doing Paste as Quotation or pasting into q
uoted content is more complicated (see handleStyleSpans) |
| 531 if (isMailPasteAsQuotationNode(topNode)) | 531 // and doesn't receive the optimization. |
| 532 if (isMailPasteAsQuotationNode(topNode) || nearestMailBlockquote(topNode)) |
| 532 return false; | 533 return false; |
| 533 | 534 |
| 534 // Either there are no style spans in the fragment or a WebKit client has ad
ded content to the fragment | 535 // Either there are no style spans in the fragment or a WebKit client has ad
ded content to the fragment |
| 535 // before inserting it. Look for and handle style spans after insertion. | 536 // before inserting it. Look for and handle style spans after insertion. |
| 536 if (!isStyleSpan(topNode)) | 537 if (!isStyleSpan(topNode)) |
| 537 return false; | 538 return false; |
| 538 | 539 |
| 539 Node* sourceDocumentStyleSpan = topNode; | 540 Node* sourceDocumentStyleSpan = topNode; |
| 540 RefPtr<Node> copiedRangeStyleSpan = sourceDocumentStyleSpan->firstChild(); | 541 RefPtr<Node> copiedRangeStyleSpan = sourceDocumentStyleSpan->firstChild(); |
| 541 | 542 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 } | 585 } |
| 585 | 586 |
| 586 // There might not be any style spans if we're pasting from another applicat
ion or if | 587 // There might not be any style spans if we're pasting from another applicat
ion or if |
| 587 // we are here because of a document.execCommand("InsertHTML", ...) call. | 588 // we are here because of a document.execCommand("InsertHTML", ...) call. |
| 588 if (!sourceDocumentStyleSpan) | 589 if (!sourceDocumentStyleSpan) |
| 589 return; | 590 return; |
| 590 | 591 |
| 591 RefPtr<CSSMutableStyleDeclaration> sourceDocumentStyle = static_cast<HTMLEle
ment*>(sourceDocumentStyleSpan)->getInlineStyleDecl()->copy(); | 592 RefPtr<CSSMutableStyleDeclaration> sourceDocumentStyle = static_cast<HTMLEle
ment*>(sourceDocumentStyleSpan)->getInlineStyleDecl()->copy(); |
| 592 Node* context = sourceDocumentStyleSpan->parentNode(); | 593 Node* context = sourceDocumentStyleSpan->parentNode(); |
| 593 | 594 |
| 594 // If Mail wraps the fragment with a Paste as Quotation blockquote, styles f
rom that element are | 595 // If Mail wraps the fragment with a Paste as Quotation blockquote, or if yo
u're pasting into a quoted region, |
| 595 // allowed to override those from the source document, see <rdar://problem/4
930986>. | 596 // styles from blockquoteNode are allowed to override those from the source
document, see <rdar://problem/4930986> and <rdar://problem/5089327>. |
| 596 if (isMailPasteAsQuotationNode(context)) { | 597 Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : neare
stMailBlockquote(context); |
| 597 RefPtr<CSSMutableStyleDeclaration> blockquoteStyle = computedStyle(conte
xt)->copyInheritableProperties(); | 598 if (blockquoteNode) { |
| 598 RefPtr<CSSMutableStyleDeclaration> parentStyle = computedStyle(context->
parentNode())->copyInheritableProperties(); | 599 RefPtr<CSSMutableStyleDeclaration> blockquoteStyle = computedStyle(block
quoteNode)->copyInheritableProperties(); |
| 600 RefPtr<CSSMutableStyleDeclaration> parentStyle = computedStyle(blockquot
eNode->parentNode())->copyInheritableProperties(); |
| 599 parentStyle->diff(blockquoteStyle.get()); | 601 parentStyle->diff(blockquoteStyle.get()); |
| 600 | 602 |
| 601 CSSMutableStyleDeclaration::const_iterator end = blockquoteStyle->end(); | 603 CSSMutableStyleDeclaration::const_iterator end = blockquoteStyle->end(); |
| 602 for (CSSMutableStyleDeclaration::const_iterator it = blockquoteStyle->be
gin(); it != end; ++it) { | 604 for (CSSMutableStyleDeclaration::const_iterator it = blockquoteStyle->be
gin(); it != end; ++it) { |
| 603 const CSSProperty& property = *it; | 605 const CSSProperty& property = *it; |
| 604 sourceDocumentStyle->removeProperty(property.id()); | 606 sourceDocumentStyle->removeProperty(property.id()); |
| 605 } | 607 } |
| 606 | 608 |
| 607 context = context->parentNode(); | 609 context = blockquoteNode->parentNode(); |
| 608 } | 610 } |
| 609 | 611 |
| 610 RefPtr<CSSMutableStyleDeclaration> contextStyle = computedStyle(context)->co
pyInheritableProperties(); | 612 RefPtr<CSSMutableStyleDeclaration> contextStyle = computedStyle(context)->co
pyInheritableProperties(); |
| 611 contextStyle->diff(sourceDocumentStyle.get()); | 613 contextStyle->diff(sourceDocumentStyle.get()); |
| 612 | 614 |
| 613 // Remove block properties in the span's style. This prevents properties tha
t probably have no effect | 615 // Remove block properties in the span's style. This prevents properties tha
t probably have no effect |
| 614 // currently from affecting blocks later if the style is cloned for a new bl
ock element during a future | 616 // currently from affecting blocks later if the style is cloned for a new bl
ock element during a future |
| 615 // editing operation. | 617 // editing operation. |
| 616 // FIXME: They *can* have an effect currently if blocks beneath the style sp
an aren't individually marked | 618 // FIXME: They *can* have an effect currently if blocks beneath the style sp
an aren't individually marked |
| 617 // with block styles by the editing engine used to style them. WebKit doesn
't do this, but others might. | 619 // with block styles by the editing engine used to style them. WebKit doesn
't do this, but others might. |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 m_firstNodeInserted = node; | 1086 m_firstNodeInserted = node; |
| 1085 | 1087 |
| 1086 if (node == m_lastLeafInserted) | 1088 if (node == m_lastLeafInserted) |
| 1087 return; | 1089 return; |
| 1088 | 1090 |
| 1089 m_lastLeafInserted = node->lastDescendant(); | 1091 m_lastLeafInserted = node->lastDescendant(); |
| 1090 } | 1092 } |
| 1091 | 1093 |
| 1092 } // namespace WebCore | 1094 } // namespace WebCore |
| 1093 | 1095 |
| OLD | NEW |