Changeset 95335 in webkit


Ignore:
Timestamp:
Sep 16, 2011 5:00:07 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

Deleting line break before h1 converts h1 to span
https://bugs.webkit.org/show_bug.cgi?id=45784

Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Fixed the bug by treating h1 and other elements that retain structure like Mail blockquote.

We already had a logic to overriding styles of merged paragraphs by Mail blockquote so
just extend this logic for h1-h6, pre, etc...

Tests: editing/deleting/merge-paragraph-from-address.html

editing/deleting/merge-paragraph-from-h6-with-style.html
editing/deleting/merge-paragraph-from-h6.html
editing/deleting/merge-paragraph-from-listing.html
editing/deleting/merge-paragraph-into-h1-with-style.html
editing/deleting/merge-paragraph-into-h1.html
editing/deleting/merge-paragraph-into-pre.html

  • editing/ReplaceSelectionCommand.cpp:

(WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):

  • editing/markup.cpp:

(WebCore::isBlockNodeToRetainAppearance): Extracted from ancestorToRetainStructureAndAppearance.
(WebCore::StyledMarkupAccumulator::serializeNodes):
(WebCore::ancestorToRetainStructureAndAppearance):

  • editing/markup.h:

LayoutTests:

Added a bunch of tests to ensure WebKit does not keep block elements' style when merging paragraphs.
When removing line breaks between <h1>hello</h1>world and hello<pre>world</pre> for example,
we should not be overriding and preserving styles from h1 in the merge paragraph respectively.

  • editing/deleting/merge-paragraph-from-address-expected.txt: Added.
  • editing/deleting/merge-paragraph-from-address.html: Added.
  • editing/deleting/merge-paragraph-from-h6-expected.txt: Added.
  • editing/deleting/merge-paragraph-from-h6-with-style-expected.txt: Added.
  • editing/deleting/merge-paragraph-from-h6-with-style.html: Added.
  • editing/deleting/merge-paragraph-from-h6.html: Added.
  • editing/deleting/merge-paragraph-from-listing-expected.txt: Added.
  • editing/deleting/merge-paragraph-from-listing.html: Added.
  • editing/deleting/merge-paragraph-into-h1-expected.txt: Added.
  • editing/deleting/merge-paragraph-into-h1-style-expected.txt: Added.
  • editing/deleting/merge-paragraph-into-h1-with-style-expected.txt: Added.
  • editing/deleting/merge-paragraph-into-h1-with-style.html: Added.
  • editing/deleting/merge-paragraph-into-h1.html: Added.
  • editing/deleting/merge-paragraph-into-pre-expected.txt: Added.
  • editing/deleting/merge-paragraph-into-pre.html: Added.
  • platform/mac/editing/deleting/merge-whitespace-pre-expected.png:
  • platform/mac/editing/deleting/merge-whitespace-pre-expected.txt:
Location:
trunk
Files:
15 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r95332 r95335  
     12011-09-14  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deleting line break before h1 converts h1 to span
     4        https://bugs.webkit.org/show_bug.cgi?id=45784
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Added a bunch of tests to ensure WebKit does not keep block elements' style when merging paragraphs.
     9        When removing line breaks between <h1>hello</h1>world and hello<pre>world</pre> for example,
     10        we should not be overriding and preserving styles from h1 in the merge paragraph respectively.
     11
     12        * editing/deleting/merge-paragraph-from-address-expected.txt: Added.
     13        * editing/deleting/merge-paragraph-from-address.html: Added.
     14        * editing/deleting/merge-paragraph-from-h6-expected.txt: Added.
     15        * editing/deleting/merge-paragraph-from-h6-with-style-expected.txt: Added.
     16        * editing/deleting/merge-paragraph-from-h6-with-style.html: Added.
     17        * editing/deleting/merge-paragraph-from-h6.html: Added.
     18        * editing/deleting/merge-paragraph-from-listing-expected.txt: Added.
     19        * editing/deleting/merge-paragraph-from-listing.html: Added.
     20        * editing/deleting/merge-paragraph-into-h1-expected.txt: Added.
     21        * editing/deleting/merge-paragraph-into-h1-style-expected.txt: Added.
     22        * editing/deleting/merge-paragraph-into-h1-with-style-expected.txt: Added.
     23        * editing/deleting/merge-paragraph-into-h1-with-style.html: Added.
     24        * editing/deleting/merge-paragraph-into-h1.html: Added.
     25        * editing/deleting/merge-paragraph-into-pre-expected.txt: Added.
     26        * editing/deleting/merge-paragraph-into-pre.html: Added.
     27        * platform/mac/editing/deleting/merge-whitespace-pre-expected.png:
     28        * platform/mac/editing/deleting/merge-whitespace-pre-expected.txt:
     29
    1302011-09-16  David Levin  <levin@chromium.org>
    231
  • trunk/LayoutTests/platform/mac/editing/deleting/merge-whitespace-pre-expected.txt

    r63291 r95335  
    1313          RenderText {#text} at (0,0) size 21x18
    1414            text run at (0,0) width 21: "foo"
    15           RenderInline {SPAN} at (0,0) size 24x15
    16             RenderText {#text} at (21,2) size 24x15
    17               text run at (21,2) width 24: "bar"
     15          RenderText {#text} at (21,0) size 20x18
     16            text run at (21,0) width 20: "bar"
    1817        RenderBlock {PRE} at (0,31) size 784x15
    1918          RenderText {#text} at (0,0) size 24x15
  • trunk/Source/WebCore/ChangeLog

    r95333 r95335  
     12011-09-14  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deleting line break before h1 converts h1 to span
     4        https://bugs.webkit.org/show_bug.cgi?id=45784
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Fixed the bug by treating h1 and other elements that retain structure like Mail blockquote.
     9
     10        We already had a logic to overriding styles of merged paragraphs by Mail blockquote so
     11        just extend this logic for h1-h6, pre, etc...
     12
     13        Tests: editing/deleting/merge-paragraph-from-address.html
     14               editing/deleting/merge-paragraph-from-h6-with-style.html
     15               editing/deleting/merge-paragraph-from-h6.html
     16               editing/deleting/merge-paragraph-from-listing.html
     17               editing/deleting/merge-paragraph-into-h1-with-style.html
     18               editing/deleting/merge-paragraph-into-h1.html
     19               editing/deleting/merge-paragraph-into-pre.html
     20
     21        * editing/ReplaceSelectionCommand.cpp:
     22        (WebCore::ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline):
     23        * editing/markup.cpp:
     24        (WebCore::isBlockNodeToRetainAppearance): Extracted from ancestorToRetainStructureAndAppearance.
     25        (WebCore::StyledMarkupAccumulator::serializeNodes):
     26        (WebCore::ancestorToRetainStructureAndAppearance):
     27        * editing/markup.h:
     28
    1292011-09-16  Max Perepelitsyn  <pph34r@gmail.com>
    230
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r94793 r95335  
    497497            // If Mail wraps the fragment with a Paste as Quotation blockquote, or if you're pasting into a quoted region,
    498498            // styles from blockquoteNode are allowed to override those from the source document, see <rdar://problem/4930986> and <rdar://problem/5089327>.
    499             Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary);
     499            Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : enclosingNodeOfType(firstPositionInNode(context), isBlockNodeToRetainAppearance, CanCrossEditingBoundary);
    500500            if (blockquoteNode)
    501501                newInlineStyle->removeStyleFromRulesAndContext(element, document()->documentElement());
  • trunk/Source/WebCore/editing/markup.cpp

    r94640 r95335  
    337337}
    338338
     339bool isBlockNodeToRetainAppearance(const Node* node)
     340{
     341    DEFINE_STATIC_LOCAL(HashSet<QualifiedName::QualifiedNameImpl*>, names, ());
     342    if (!names.size()) {
     343        names.add(addressTag.impl());
     344        names.add(blockquoteTag.impl());
     345        names.add(h1Tag.impl());
     346        names.add(h2Tag.impl());
     347        names.add(h3Tag.impl());
     348        names.add(h4Tag.impl());
     349        names.add(h5Tag.impl());
     350        names.add(h6Tag.impl());
     351        names.add(listingTag.impl());
     352        names.add(preTag.impl());
     353    }
     354    return node->isElementNode() && names.contains(toElement(node)->tagQName().impl());
     355}
     356
    339357Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd)
    340358{
     
    351369        // to help us differentiate those styles from ones that the user has applied.
    352370        // This helps us get the color of content pasted into blockquotes right.
    353         m_wrappingStyle->removeStyleAddedByNode(enclosingNodeOfType(firstPositionInOrBeforeNode(parentOfHighestNode), isMailBlockquote, CanCrossEditingBoundary));
     371        m_wrappingStyle->removeStyleAddedByNode(enclosingNodeOfType(firstPositionInOrBeforeNode(parentOfHighestNode), isBlockNodeToRetainAppearance, CanCrossEditingBoundary));
    354372
    355373        // Call collapseTextDecorationProperties first or otherwise it'll copy the value over from in-effect to text-decorations.
     
    454472    }
    455473
    456     if (commonAncestorBlock->hasTagName(listingTag)
     474    if (isBlockNodeToRetainAppearance(commonAncestorBlock)
    457475        || commonAncestorBlock->hasTagName(olTag)
    458         || commonAncestorBlock->hasTagName(preTag)
    459476        || commonAncestorBlock->hasTagName(tableTag)
    460477        || commonAncestorBlock->hasTagName(ulTag)
    461         || commonAncestorBlock->hasTagName(xmpTag)
    462         || commonAncestorBlock->hasTagName(h1Tag)
    463         || commonAncestorBlock->hasTagName(h2Tag)
    464         || commonAncestorBlock->hasTagName(h3Tag)
    465         || commonAncestorBlock->hasTagName(h4Tag)
    466         || commonAncestorBlock->hasTagName(h5Tag))
     478        || commonAncestorBlock->hasTagName(xmpTag))
    467479        return commonAncestorBlock;
    468480
  • trunk/Source/WebCore/editing/markup.h

    r92769 r95335  
    5050    bool isPlainTextMarkup(Node *node);
    5151
     52    bool isBlockNodeToRetainAppearance(const Node*);
    5253    String createMarkup(const Range*,
    5354        Vector<Node*>* = 0, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs);
    5455    String createMarkup(const Node*, EChildrenOnly = IncludeNode, Vector<Node*>* = 0, EAbsoluteURLs = DoNotResolveURLs);
    55    
     56
    5657    String createFullMarkup(const Node*);
    5758    String createFullMarkup(const Range*);
Note: See TracChangeset for help on using the changeset viewer.