[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

rniwa at webkit.org rniwa at webkit.org
Wed Dec 22 11:37:52 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit ac0112ac9f034c8db36edcf8aa6d056ddeb1ba1a
Author: rniwa at webkit.org <rniwa at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Aug 1 01:10:27 2010 +0000

    2010-07-31  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Ojan Vafai.
    
            SplitElementCommand shouldn't be duplicating id attribute
            https://bugs.webkit.org/show_bug.cgi?id=27156
    
            Modified SplitElementCommand to delete the id attribute from the second element when splitting an element.
            Since this causes WebKit not to merge split elements, added shouldSplitElement to ApplyStyleCommand which
            determines the necessity of splitting the element.
    
            To share code between shouldSplitElement and removeInlineStyleFromElement (extracted from applyInlineStyle)
            dontRemove was added as the 3rd argument to removeHTMLFontStyle, removeHTMLBidiEmbeddingStyle, and removeCSSStyle.
    
            Test: editing/style/split-element-id-duplication.html
    
            * editing/ApplyStyleCommand.cpp:
            (WebCore::ApplyStyleCommand::applyBlockStyle): Added 3rd argument for removeCSSStyle.
            (WebCore::ApplyStyleCommand::applyInlineStyle): Calls shouldSplitElement.
            (WebCore::ApplyStyleCommand::removeInlineStyleFromElement): Extracted from removeInlineStyle.
            (WebCore::ApplyStyleCommand::shouldRemoveInlineStyleFromElement): Inline helper for removeInlineStyleFromElement.
            (WebCore::ApplyStyleCommand::removeHTMLFontStyle): Added dontRemove.
            (WebCore::ApplyStyleCommand::removeHTMLBidiEmbeddingStyle): Added dontRemove.
            (WebCore::ApplyStyleCommand::removeCSSStyle): Added dontRemove.
            (WebCore::ApplyStyleCommand::removeInlineStyle): Calls removeInlineStyleFromElement.
            (WebCore::ApplyStyleCommand::splitTextElementAtStart): Removed the call to splitTextAtStart.
            Branching is now done in applyInlineStyle.
            (WebCore::ApplyStyleCommand::splitTextElementAtEnd): Ditto for splitTextAtEnd.
            (WebCore::ApplyStyleCommand::shouldSplitElement): Added.
            * editing/ApplyStyleCommand.h:
            * editing/SplitElementCommand.cpp:
            (WebCore::SplitElementCommand::executeApply): Deletes the id attribute from the second element.
            (WebCore::SplitElementCommand::doUnapply): Recovers the id attribute of the second element.
    2010-07-31  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Ojan Vafai.
    
            SplitElementCommand shouldn't be duplicating id attribute
            https://bugs.webkit.org/show_bug.cgi?id=27156
    
            Added a test to ensure splitting element doesn't produce multiple nodes with the same id.
    
            * editing/execCommand/indent-nested-blockquotes-expected.txt: Removed the duplication of nodes with the same id.
            * editing/execCommand/indent-pre-expected.txt: Ditto.
            * editing/execCommand/indent-second-paragraph-in-blockquote-expected.txt: Ditto.
            * editing/execCommand/outdent-regular-blockquote-expected.txt:
            * editing/style/split-element-id-duplication-expected.txt: Added.
            * editing/style/split-element-id-duplication.html: Added.
            * editing/undo/redo-style-expected.txt: Editing delegates changed.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64432 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 0cedc90..5a031bf 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,20 @@
+2010-07-31  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Ojan Vafai.
+
+        SplitElementCommand shouldn't be duplicating id attribute
+        https://bugs.webkit.org/show_bug.cgi?id=27156
+
+        Added a test to ensure splitting element doesn't produce multiple nodes with the same id.
+
+        * editing/execCommand/indent-nested-blockquotes-expected.txt: Removed the duplication of nodes with the same id.
+        * editing/execCommand/indent-pre-expected.txt: Ditto.
+        * editing/execCommand/indent-second-paragraph-in-blockquote-expected.txt: Ditto.
+        * editing/execCommand/outdent-regular-blockquote-expected.txt:
+        * editing/style/split-element-id-duplication-expected.txt: Added.
+        * editing/style/split-element-id-duplication.html: Added.
+        * editing/undo/redo-style-expected.txt: Editing delegates changed.
+
 2010-07-31  Satish Sampath  <satish at chromium.org>
 
         Unreviewed text expectations change for Chromium.
diff --git a/LayoutTests/editing/execCommand/indent-nested-blockquotes-expected.txt b/LayoutTests/editing/execCommand/indent-nested-blockquotes-expected.txt
index 71b2bd4..8ea5c0a 100644
--- a/LayoutTests/editing/execCommand/indent-nested-blockquotes-expected.txt
+++ b/LayoutTests/editing/execCommand/indent-nested-blockquotes-expected.txt
@@ -4,4 +4,4 @@ hello
 world
 webkit
 is great
-<blockquote id="outer"> hello <blockquote id="inner"> world<br></blockquote></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><blockquote id="outer"><blockquote id="inner"> webkit </blockquote></blockquote></blockquote><blockquote id="outer"> is great </blockquote>
+<blockquote id="outer"> hello <blockquote id="inner"> world<br></blockquote></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><blockquote><blockquote> webkit </blockquote></blockquote></blockquote><blockquote> is great </blockquote>
diff --git a/LayoutTests/editing/execCommand/indent-pre-expected.txt b/LayoutTests/editing/execCommand/indent-pre-expected.txt
index a0df82b..cd64c84 100644
--- a/LayoutTests/editing/execCommand/indent-pre-expected.txt
+++ b/LayoutTests/editing/execCommand/indent-pre-expected.txt
@@ -27,11 +27,9 @@ does not crash."
 |         class="webkit-indent-blockquote"
 |         style="margin: 0 0 0 40px; border: none; padding: 0px;"
 |         <pre>
-|           id="pre-basic"
 |           "line three
 "
 |         <pre>
-|           id="pre-basic"
 |           "line four"
 |       "
 
@@ -68,11 +66,9 @@ does not crash."
 |                 class="webkit-indent-blockquote"
 |                 style="margin: 0 0 0 40px; border: none; padding: 0px;"
 |                 <pre>
-|                   id="pre-table"
 |                   "table two
 "
 |                 <pre>
-|                   id="pre-table"
 |                   "table three<#selection-focus>"
 |             <td>
 |               "right cell"
diff --git a/LayoutTests/editing/execCommand/indent-second-paragraph-in-blockquote-expected.txt b/LayoutTests/editing/execCommand/indent-second-paragraph-in-blockquote-expected.txt
index e5b3d53..a6bdda4 100644
--- a/LayoutTests/editing/execCommand/indent-second-paragraph-in-blockquote-expected.txt
+++ b/LayoutTests/editing/execCommand/indent-second-paragraph-in-blockquote-expected.txt
@@ -2,4 +2,4 @@ This tests indenting the second paragraph in a blockquote. By indenting "world",
 
 hello
 world
-<blockquote id="test"> hello<br></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><blockquote id="test"> world </blockquote></blockquote>
+<blockquote id="test"> hello<br></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><blockquote> world </blockquote></blockquote>
diff --git a/LayoutTests/editing/execCommand/outdent-regular-blockquote-expected.txt b/LayoutTests/editing/execCommand/outdent-regular-blockquote-expected.txt
index cef0cd2..7548da0 100644
--- a/LayoutTests/editing/execCommand/outdent-regular-blockquote-expected.txt
+++ b/LayoutTests/editing/execCommand/outdent-regular-blockquote-expected.txt
@@ -4,4 +4,4 @@ one
 two
 three
 Before: <blockquote id="test">one<br>two<br>three</blockquote>
-After: <blockquote id="test">one<br></blockquote>two<br><blockquote id="test">three</blockquote>
+After: <blockquote id="test">one<br></blockquote>two<br><blockquote>three</blockquote>
diff --git a/LayoutTests/editing/undo/redo-style-expected.txt b/LayoutTests/editing/undo/redo-style-expected.txt
index b09c578..97e0767 100644
--- a/LayoutTests/editing/undo/redo-style-expected.txt
+++ b/LayoutTests/editing/undo/redo-style-expected.txt
@@ -1,29 +1,25 @@
 EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 7 of DIV > BODY > HTML > #document
 EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of #text > DIV > DIV > BODY > HTML > #document to 2 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV > DIV > BODY > HTML > #document to 2 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of #text > DIV > DIV > BODY > HTML > #document to 2 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text > DIV > DIV > BODY > HTML > #document to 2 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 2 of #text > DIV > DIV > BODY > HTML > #document to 4 of #text > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 2 of #text > DIV > DIV > BODY > HTML > #document to 2 of #text > DIV > DIV > BODY > HTML > #document toDOMRange:range from 0 of #text > SPAN > DIV > DIV > BODY > HTML > #document to 2 of #text > SPAN > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index a473321..4135443 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,37 @@
+2010-07-31  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Ojan Vafai.
+
+        SplitElementCommand shouldn't be duplicating id attribute
+        https://bugs.webkit.org/show_bug.cgi?id=27156
+
+        Modified SplitElementCommand to delete the id attribute from the second element when splitting an element.
+        Since this causes WebKit not to merge split elements, added shouldSplitElement to ApplyStyleCommand which
+        determines the necessity of splitting the element.
+
+        To share code between shouldSplitElement and removeInlineStyleFromElement (extracted from applyInlineStyle)
+        dontRemove was added as the 3rd argument to removeHTMLFontStyle, removeHTMLBidiEmbeddingStyle, and removeCSSStyle.
+
+        Test: editing/style/split-element-id-duplication.html
+
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::applyBlockStyle): Added 3rd argument for removeCSSStyle.
+        (WebCore::ApplyStyleCommand::applyInlineStyle): Calls shouldSplitElement.
+        (WebCore::ApplyStyleCommand::removeInlineStyleFromElement): Extracted from removeInlineStyle.
+        (WebCore::ApplyStyleCommand::shouldRemoveInlineStyleFromElement): Inline helper for removeInlineStyleFromElement.
+        (WebCore::ApplyStyleCommand::removeHTMLFontStyle): Added dontRemove.
+        (WebCore::ApplyStyleCommand::removeHTMLBidiEmbeddingStyle): Added dontRemove.
+        (WebCore::ApplyStyleCommand::removeCSSStyle): Added dontRemove.
+        (WebCore::ApplyStyleCommand::removeInlineStyle): Calls removeInlineStyleFromElement.
+        (WebCore::ApplyStyleCommand::splitTextElementAtStart): Removed the call to splitTextAtStart.
+        Branching is now done in applyInlineStyle.
+        (WebCore::ApplyStyleCommand::splitTextElementAtEnd): Ditto for splitTextAtEnd.
+        (WebCore::ApplyStyleCommand::shouldSplitElement): Added.
+        * editing/ApplyStyleCommand.h:
+        * editing/SplitElementCommand.cpp:
+        (WebCore::SplitElementCommand::executeApply): Deletes the id attribute from the second element.
+        (WebCore::SplitElementCommand::doUnapply): Recovers the id attribute of the second element.
+
 2010-07-31  Luiz Agostini  <luiz.agostini at openbossa.org>
 
         Build fix: Windows.
diff --git a/WebCore/editing/ApplyStyleCommand.cpp b/WebCore/editing/ApplyStyleCommand.cpp
index 8847714..d865468 100644
--- a/WebCore/editing/ApplyStyleCommand.cpp
+++ b/WebCore/editing/ApplyStyleCommand.cpp
@@ -910,7 +910,10 @@ void ApplyStyleCommand::applyInlineStyle(CSSMutableStyleDeclaration *style)
     // split the start node and containing element if the selection starts inside of it
     bool splitStart = isValidCaretPositionInTextNode(start);
     if (splitStart) {
-        splitTextElementAtStart(start, end);
+        if (shouldSplitTextElement(start.node()->parentElement(), style))
+            splitTextElementAtStart(start, end);
+        else
+            splitTextAtStart(start, end);
         start = startPosition();
         end = endPosition();
         startDummySpanAncestor = dummySpanAncestorForNode(start.node());
@@ -919,7 +922,10 @@ void ApplyStyleCommand::applyInlineStyle(CSSMutableStyleDeclaration *style)
     // split the end node and containing element if the selection ends inside of it
     bool splitEnd = isValidCaretPositionInTextNode(end);
     if (splitEnd) {
-        splitTextElementAtEnd(start, end);
+        if (shouldSplitTextElement(end.node()->parentElement(), style))
+            splitTextElementAtEnd(start, end);
+        else
+            splitTextAtEnd(start, end);
         start = startPosition();
         end = endPosition();
         endDummySpanAncestor = dummySpanAncestorForNode(end.node());
@@ -1176,6 +1182,40 @@ bool ApplyStyleCommand::implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(
     return false;
 }
 
+bool ApplyStyleCommand::removeInlineStyleFromElement(CSSMutableStyleDeclaration* style, HTMLElement* element, InlineStyleRemovalMode mode)
+{
+    ASSERT(style);
+    ASSERT(element);
+
+    bool removed = false;
+
+    if (m_styledInlineElement && element->hasTagName(m_styledInlineElement->tagQName())) {
+        removed = true;
+        if (mode == RemoveAttributesAndElements)
+            removeNodePreservingChildren(element);
+    }
+
+    if (implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(element, style)) {
+        removed = true;
+        if (mode == RemoveAttributesAndElements)
+            replaceWithSpanOrRemoveIfWithoutAttributes(element);
+    }
+
+    if (!element->inDocument())
+        return removed;
+
+    // If the node was converted to a span, the span may still contain relevant
+    // styles which must be removed (e.g. <b style='font-weight: bold'>)
+    if (removeHTMLFontStyle(style, element, mode))
+        removed = true;
+    if (removeHTMLBidiEmbeddingStyle(style, element, mode))
+        removed = true;
+    if (removeCSSStyle(style, element, mode))
+        removed = true;
+
+    return removed;
+}
+
 void ApplyStyleCommand::replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement*& elem)
 {
     bool removeNode = false;
@@ -1200,65 +1240,84 @@ void ApplyStyleCommand::replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement*&
     }
 }
 
-void ApplyStyleCommand::removeHTMLFontStyle(CSSMutableStyleDeclaration *style, HTMLElement *elem)
+bool ApplyStyleCommand::removeHTMLFontStyle(CSSMutableStyleDeclaration* style, HTMLElement* elem, InlineStyleRemovalMode mode)
 {
     ASSERT(style);
     ASSERT(elem);
 
     if (!elem->hasLocalName(fontTag))
-        return;
-        
+        return false;
+
+    bool removed = false;
     CSSMutableStyleDeclaration::const_iterator end = style->end();
     for (CSSMutableStyleDeclaration::const_iterator it = style->begin(); it != end; ++it) {
+        const QualifiedName* attrToRemove = 0;
         switch ((*it).id()) {
-            case CSSPropertyColor:
-                removeNodeAttribute(elem, colorAttr);
-                break;
-            case CSSPropertyFontFamily:
-                removeNodeAttribute(elem, faceAttr);
-                break;
-            case CSSPropertyFontSize:
-                removeNodeAttribute(elem, sizeAttr);
-                break;
+        case CSSPropertyColor:
+            attrToRemove = &colorAttr;
+            break;
+        case CSSPropertyFontFamily:
+            attrToRemove = &faceAttr;
+            break;
+        case CSSPropertyFontSize:
+            attrToRemove = &sizeAttr;
+            break;
+        }
+
+        if (attrToRemove) {
+            removed = true;
+            if (mode == RemoveAttributesAndElements)
+                removeNodeAttribute(elem, *attrToRemove);
         }
     }
 
-    if (isEmptyFontTag(elem))
+    if (isEmptyFontTag(elem) && mode == RemoveAttributesAndElements)
         removeNodePreservingChildren(elem);
+
+    return removed;
 }
 
-void ApplyStyleCommand::removeHTMLBidiEmbeddingStyle(CSSMutableStyleDeclaration *style, HTMLElement *elem)
+bool ApplyStyleCommand::removeHTMLBidiEmbeddingStyle(CSSMutableStyleDeclaration* style, HTMLElement* elem, InlineStyleRemovalMode mode)
 {
     ASSERT(style);
     ASSERT(elem);
 
     if (!elem->hasAttribute(dirAttr))
-        return;
+        return false;
 
     if (!style->getPropertyCSSValue(CSSPropertyUnicodeBidi) && !style->getPropertyCSSValue(CSSPropertyDirection))
-        return;
+        return false;
+
+    if (mode == RemoveNone)
+        return true;
 
     removeNodeAttribute(elem, dirAttr);
 
     // FIXME: should this be isSpanWithoutAttributesOrUnstyleStyleSpan?  Need a test.
     if (isUnstyledStyleSpan(elem))
         removeNodePreservingChildren(elem);
+
+    return true;
 }
 
-void ApplyStyleCommand::removeCSSStyle(CSSMutableStyleDeclaration* style, HTMLElement* elem)
+bool ApplyStyleCommand::removeCSSStyle(CSSMutableStyleDeclaration* style, HTMLElement* elem, InlineStyleRemovalMode mode)
 {
     ASSERT(style);
     ASSERT(elem);
 
     CSSMutableStyleDeclaration* decl = elem->inlineStyleDecl();
     if (!decl)
-        return;
+        return false;
 
+    bool removed = false;
     CSSMutableStyleDeclaration::const_iterator end = style->end();
     for (CSSMutableStyleDeclaration::const_iterator it = style->begin(); it != end; ++it) {
         CSSPropertyID propertyID = static_cast<CSSPropertyID>((*it).id());
         RefPtr<CSSValue> value = decl->getPropertyCSSValue(propertyID);
         if (value && (propertyID != CSSPropertyWhiteSpace || !isTabSpanNode(elem))) {
+            removed = true;
+            if (mode == RemoveNone)
+                return true;
             removeCSSProperty(decl, propertyID);
             if (propertyID == CSSPropertyUnicodeBidi && !decl->getPropertyValue(CSSPropertyDirection).isEmpty())
                 removeCSSProperty(decl, CSSPropertyDirection);
@@ -1271,6 +1330,8 @@ void ApplyStyleCommand::removeCSSStyle(CSSMutableStyleDeclaration* style, HTMLEl
 
     if (isSpanWithoutAttributesOrUnstyleStyleSpan(elem))
         removeNodePreservingChildren(elem);
+
+    return removed;
 }
 
 static bool hasTextDecorationProperty(Node *node)
@@ -1472,19 +1533,7 @@ void ApplyStyleCommand::removeInlineStyle(PassRefPtr<CSSMutableStyleDeclaration>
             HTMLElement* elem = static_cast<HTMLElement*>(node);
             Node* prev = elem->traversePreviousNodePostOrder();
             Node* next = elem->traverseNextNode();
-            if (m_styledInlineElement && elem->hasTagName(m_styledInlineElement->tagQName()))
-                removeNodePreservingChildren(elem);
-
-            if (implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(elem, style.get()))
-                replaceWithSpanOrRemoveIfWithoutAttributes(elem);
-
-            // If the node was converted to a span, the span may still contain relevant
-            // styles which must be removed (e.g. <b style='font-weight: bold'>)
-            if (elem->inDocument()) {
-                removeHTMLFontStyle(style.get(), elem);
-                removeHTMLBidiEmbeddingStyle(style.get(), elem);
-                removeCSSStyle(style.get(), elem);
-            }
+            removeInlineStyleFromElement(style.get(), elem);
             if (!elem->inDocument()) {
                 if (s.node() == elem) {
                     // Since elem must have been fully selected, and it is at the start
@@ -1554,10 +1603,6 @@ void ApplyStyleCommand::splitTextAtEnd(const Position& start, const Position& en
 
 void ApplyStyleCommand::splitTextElementAtStart(const Position& start, const Position& end)
 {
-    Node* parent = start.node()->parentNode();
-    if (!parent || !parent->parentElement() || !parent->parentElement()->isContentEditable())
-        return splitTextAtStart(start, end);
-
     int endOffsetAdjustment = start.node() == end.node() ? start.deprecatedEditingOffset() : 0;
     Text* text = static_cast<Text*>(start.node());
     splitTextNodeContainingElement(text, start.deprecatedEditingOffset());
@@ -1566,10 +1611,6 @@ void ApplyStyleCommand::splitTextElementAtStart(const Position& start, const Pos
 
 void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Position& end)
 {
-    Node* parent = end.node()->parentNode();
-    if (!parent || !parent->parentElement() || !parent->parentElement()->isContentEditable())
-        return splitTextAtEnd(start, end);
-
     Text* text = static_cast<Text*>(end.node());
     splitTextNodeContainingElement(text, end.deprecatedEditingOffset());
 
@@ -1580,6 +1621,14 @@ void ApplyStyleCommand::splitTextElementAtEnd(const Position& start, const Posit
     updateStartEnd(Position(startNode, start.deprecatedEditingOffset()), Position(prevNode->parent(), prevNode->nodeIndex() + 1));
 }
 
+bool ApplyStyleCommand::shouldSplitTextElement(Element* element, CSSMutableStyleDeclaration* style)
+{
+    if (!element || !element->isHTMLElement() || !element->parentElement() || !element->parentElement()->isContentEditable())
+        return false;
+
+    return shouldRemoveInlineStyleFromElement(style, static_cast<HTMLElement*>(element));
+}
+
 bool ApplyStyleCommand::isValidCaretPositionInTextNode(const Position& position)
 {
     Node* node = position.node();
diff --git a/WebCore/editing/ApplyStyleCommand.h b/WebCore/editing/ApplyStyleCommand.h
index 199b9db..0aa8110 100644
--- a/WebCore/editing/ApplyStyleCommand.h
+++ b/WebCore/editing/ApplyStyleCommand.h
@@ -42,6 +42,7 @@ enum ShouldIncludeTypingStyle {
 class ApplyStyleCommand : public CompositeEditCommand {
 public:
     enum EPropertyLevel { PropertyDefault, ForceBlockProperties };
+    enum InlineStyleRemovalMode { RemoveAttributesAndElements, RemoveNone };
 
     static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
     {
@@ -71,10 +72,12 @@ private:
     // style-removal helpers
     bool shouldRemoveTextDecorationTag(CSSStyleDeclaration* styleToApply, int textDecorationAddedByTag) const;
     bool implicitlyStyledElementShouldBeRemovedWhenApplyingStyle(HTMLElement*, CSSMutableStyleDeclaration*);
+    bool removeInlineStyleFromElement(CSSMutableStyleDeclaration*, HTMLElement*, InlineStyleRemovalMode = RemoveAttributesAndElements);
+    inline bool shouldRemoveInlineStyleFromElement(CSSMutableStyleDeclaration* style, HTMLElement* element) {return removeInlineStyleFromElement(style, element, RemoveNone);}
     void replaceWithSpanOrRemoveIfWithoutAttributes(HTMLElement*&);
-    void removeHTMLFontStyle(CSSMutableStyleDeclaration*, HTMLElement*);
-    void removeHTMLBidiEmbeddingStyle(CSSMutableStyleDeclaration*, HTMLElement*);
-    void removeCSSStyle(CSSMutableStyleDeclaration*, HTMLElement*);
+    bool removeHTMLFontStyle(CSSMutableStyleDeclaration*, HTMLElement*, InlineStyleRemovalMode = RemoveAttributesAndElements);
+    bool removeHTMLBidiEmbeddingStyle(CSSMutableStyleDeclaration*, HTMLElement*, InlineStyleRemovalMode = RemoveAttributesAndElements);
+    bool removeCSSStyle(CSSMutableStyleDeclaration*, HTMLElement*, InlineStyleRemovalMode = RemoveAttributesAndElements);
     void removeInlineStyle(PassRefPtr<CSSMutableStyleDeclaration>, const Position& start, const Position& end);
     bool nodeFullySelected(Node*, const Position& start, const Position& end) const;
     bool nodeFullyUnselected(Node*, const Position& start, const Position& end) const;
@@ -95,6 +98,7 @@ private:
     void splitTextAtEnd(const Position& start, const Position& end);
     void splitTextElementAtStart(const Position& start, const Position& end);
     void splitTextElementAtEnd(const Position& start, const Position& end);
+    bool shouldSplitTextElement(Element* elem, CSSMutableStyleDeclaration*);
     bool isValidCaretPositionInTextNode(const Position& position);
     bool mergeStartWithPreviousIfIdentical(const Position& start, const Position& end);
     bool mergeEndWithNextIfIdentical(const Position& start, const Position& end);
diff --git a/WebCore/editing/SplitElementCommand.cpp b/WebCore/editing/SplitElementCommand.cpp
index 2998c6a..5047205 100644
--- a/WebCore/editing/SplitElementCommand.cpp
+++ b/WebCore/editing/SplitElementCommand.cpp
@@ -27,6 +27,7 @@
 #include "SplitElementCommand.h"
 
 #include "Element.h"
+#include "HTMLNames.h"
 #include <wtf/Assertions.h>
 
 namespace WebCore {
@@ -58,7 +59,11 @@ void SplitElementCommand::executeApply()
     parent->insertBefore(m_element1.get(), m_element2.get(), ec);
     if (ec)
         return;
-    
+
+    // Delete id attribute from the second element because the same id cannot be used for more than one element
+    m_element2->removeAttribute(HTMLNames::idAttr, ec);
+    ASSERT(!ec);
+
     size_t size = children.size();
     for (size_t i = 0; i < size; ++i)
         m_element1->appendChild(children[i], ec);
@@ -88,6 +93,10 @@ void SplitElementCommand::doUnapply()
     for (size_t i = 0; i < size; ++i)
         m_element2->insertBefore(children[i].get(), refChild.get(), ec);
 
+    // Recover the id attribute of the original element.
+    if (m_element1->hasAttribute(HTMLNames::idAttr))
+        m_element2->setAttribute(HTMLNames::idAttr, m_element1->getAttribute(HTMLNames::idAttr));
+
     m_element1->remove(ec);
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list