[Webkit-unassigned] [Bug 26937] Copying and pasting into a contenteditable area can create <div>s surrounded by <span>s

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Feb 3 10:18:01 PST 2010


https://bugs.webkit.org/show_bug.cgi?id=26937





--- Comment #14 from Enrica Casucci <enrica at apple.com>  2010-02-03 10:17:58 PST ---
(From update of attachment 48000)
> diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
> index 67f5b56..c65fe8b 100644
> --- a/WebCore/ChangeLog
> +++ b/WebCore/ChangeLog
> @@ -1,3 +1,19 @@
> +2010-02-03  Tony Chang  <tony at chromium.org>
> +
> +        Reviewed by NOBODY (OOPS!).
> +
> +        Copying and pasting into a contenteditable area can create <div>s surrounded by <span>s
> +
> +        This happens because of a span added when we copy that is used to
> +        preserve styles.  To avoid this, when we paste, make sure to apply
> +        the styles to the span's children and then remove the style span.
> +        https://bugs.webkit.org/show_bug.cgi?id=26937
> +
> +        No new tests. (OOPS!)
> +
> +        * editing/ReplaceSelectionCommand.cpp:
> +        (WebCore::ReplaceSelectionCommand::handleStyleSpans):
> +
>  2010-02-02  Steve Falkenburg  <sfalken at apple.com>
>  
>          Reviewed by Darin Adler.
> diff --git a/WebCore/editing/ReplaceSelectionCommand.cpp b/WebCore/editing/ReplaceSelectionCommand.cpp
> index 85a4471..49189e5 100644
> --- a/WebCore/editing/ReplaceSelectionCommand.cpp
> +++ b/WebCore/editing/ReplaceSelectionCommand.cpp
> @@ -638,10 +638,20 @@ void ReplaceSelectionCommand::handleStyleSpans()
>      }
>      
>      // There are non-redundant styles on sourceDocumentStyleSpan, but there is no
> -    // copiedRangeStyleSpan.  Clear the redundant styles from sourceDocumentStyleSpan
> -    // and return.
> +    // copiedRangeStyleSpan.  Remove the span, because it could be surrounding block elements,
> +    // and apply the styles to its children.
>      if (sourceDocumentStyle->length() > 0 && !copiedRangeStyleSpan) {
> -        setNodeAttribute(static_cast<Element*>(sourceDocumentStyleSpan), styleAttr, sourceDocumentStyle->cssText());
> +        for (Node* childNode = sourceDocumentStyleSpan->firstChild(); childNode; childNode = childNode->nextSibling()) {
> +            if (!childNode->isHTMLElement())
> +                continue;
> +            RefPtr<CSSMutableStyleDeclaration> newStyles = sourceDocumentStyle->copy();
> +            HTMLElement* childElement = static_cast<HTMLElement*>(childNode);
> +            RefPtr<CSSMutableStyleDeclaration> existingStyles = childElement->getInlineStyleDecl()->copy();
> +            existingStyles->merge(newStyles.get(), false);
> +            setNodeAttribute(childElement, styleAttr, existingStyles->cssText());
> +        }
> +
> +        removeNodePreservingChildren(sourceDocumentStyleSpan);
>          return;
>      }
>      

Yes, that's the idea. I like it.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list