Title: [113369] trunk/Source/WebCore
Revision
113369
Author
[email protected]
Date
2012-04-05 13:31:52 -0700 (Thu, 05 Apr 2012)

Log Message

Provide a separate editing command to cleanup of redundant markup.
https://bugs.webkit.org/show_bug.cgi?id=83240

Reviewed by Ryosuke Niwa.

This patch moves the logic originally performed by the private
method removeRedundantMarkup inside ReplaceSelectionCommand into
a separate command. This way the markup cleanup can be exposed as
a separate command, independent from ReplaceSelectionCommand.
        
No new tests. No change in functionality.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
Added new file to project files.
* editing/EditorAllInOne.cpp: Added SimplifyMarkupCommand.
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::doApply): Now uses SimplifyMarkupCommand.
* editing/ReplaceSelectionCommand.h:
(ReplaceSelectionCommand): Removed removeRedundantMarkup.
* editing/SimplifyMarkupCommand.cpp: Added.
(WebCore::SimplifyMarkupCommand::SimplifyMarkupCommand):
(WebCore::SimplifyMarkupCommand::doApply):
* editing/SimplifyMarkupCommand.h: Added.
(WebCore::SimplifyMarkupCommand::create):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (113368 => 113369)


--- trunk/Source/WebCore/CMakeLists.txt	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/CMakeLists.txt	2012-04-05 20:31:52 UTC (rev 113369)
@@ -690,6 +690,7 @@
     editing/ReplaceSelectionCommand.cpp
     editing/SetNodeAttributeCommand.cpp
     editing/SetSelectionCommand.cpp
+    editing/SimplifyMarkupCommand.cpp
     editing/SmartReplace.cpp
     editing/SpellChecker.cpp
     editing/SpellingCorrectionCommand.cpp

Modified: trunk/Source/WebCore/ChangeLog (113368 => 113369)


--- trunk/Source/WebCore/ChangeLog	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/ChangeLog	2012-04-05 20:31:52 UTC (rev 113369)
@@ -1,3 +1,35 @@
+2012-04-05  Enrica Casucci  <[email protected]>
+
+        Provide a separate editing command to cleanup of redundant markup.
+        https://bugs.webkit.org/show_bug.cgi?id=83240
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch moves the logic originally performed by the private
+        method removeRedundantMarkup inside ReplaceSelectionCommand into
+        a separate command. This way the markup cleanup can be exposed as
+        a separate command, independent from ReplaceSelectionCommand.
+        
+        No new tests. No change in functionality.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        Added new file to project files.
+        * editing/EditorAllInOne.cpp: Added SimplifyMarkupCommand.
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::doApply): Now uses SimplifyMarkupCommand.
+        * editing/ReplaceSelectionCommand.h:
+        (ReplaceSelectionCommand): Removed removeRedundantMarkup.
+        * editing/SimplifyMarkupCommand.cpp: Added.
+        (WebCore::SimplifyMarkupCommand::SimplifyMarkupCommand):
+        (WebCore::SimplifyMarkupCommand::doApply):
+        * editing/SimplifyMarkupCommand.h: Added.
+        (WebCore::SimplifyMarkupCommand::create):
+
 2012-04-05  Shawn Singh  <[email protected]>
 
         [chromium] Need to clip to homogeneous w=0 plane when applying transforms.

Modified: trunk/Source/WebCore/GNUmakefile.list.am (113368 => 113369)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-04-05 20:31:52 UTC (rev 113369)
@@ -2086,6 +2086,8 @@
 	Source/WebCore/editing/SetNodeAttributeCommand.h \
 	Source/WebCore/editing/SetSelectionCommand.cpp \
 	Source/WebCore/editing/SetSelectionCommand.h \
+	Source/WebCore/editing/SimplifyMarkupCommand.cpp \
+	Source/WebCore/editing/SimplifyMarkupCommand.h \
 	Source/WebCore/editing/SmartReplace.cpp \
 	Source/WebCore/editing/SmartReplace.h \
 	Source/WebCore/editing/SmartReplaceICU.cpp \

Modified: trunk/Source/WebCore/Target.pri (113368 => 113369)


--- trunk/Source/WebCore/Target.pri	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/Target.pri	2012-04-05 20:31:52 UTC (rev 113369)
@@ -666,6 +666,7 @@
     editing/ReplaceSelectionCommand.cpp \
     editing/SetNodeAttributeCommand.cpp \
     editing/SetSelectionCommand.cpp \
+    editing/SimplifyMarkupCommand.cpp \
     editing/SpellChecker.cpp \
     editing/SpellingCorrectionCommand.cpp \
     editing/SplitElementCommand.cpp \
@@ -1797,6 +1798,7 @@
     editing/ReplaceNodeWithSpanCommand.h \
     editing/ReplaceSelectionCommand.h \
     editing/SetNodeAttributeCommand.h \
+    editing/SimplifyMarkupCommand.h \
     editing/SmartReplace.h \
     editing/SpellingCorrectionCommand.h \
     editing/SplitElementCommand.h \

Modified: trunk/Source/WebCore/WebCore.gypi (113368 => 113369)


--- trunk/Source/WebCore/WebCore.gypi	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/WebCore.gypi	2012-04-05 20:31:52 UTC (rev 113369)
@@ -111,6 +111,7 @@
             'editing/HTMLInterchange.h',
             'editing/MoveSelectionCommand.h',
             'editing/ReplaceSelectionCommand.h',
+            'editing/SimplifyMarkupCommand.h',
             'editing/SmartReplace.h',
             'editing/SpellChecker.h',
             'editing/SurroundingText.cpp',
@@ -2576,6 +2577,7 @@
             'editing/SetNodeAttributeCommand.h',
             'editing/SetSelectionCommand.cpp',
             'editing/SetSelectionCommand.h',
+            'editing/SimplifyMarkupCommand.cpp',
             'editing/SmartReplace.cpp',
             'editing/SmartReplaceCF.cpp',
             'editing/SmartReplaceICU.cpp',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (113368 => 113369)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-04-05 20:31:52 UTC (rev 113369)
@@ -56242,6 +56242,62 @@
 				>
 			</File>
 			<File
+				RelativePath="..\editing\SimplifyMarkupCommand.cpp"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					ExcludedFromBuild="false"
+					>
+					<Tool
+                    Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					ExcludedFromBuild="false"
+					>
+					<Tool
+                    Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug_Cairo_CFLite|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+                    Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release_Cairo_CFLite|Win32"
+					ExcludedFromBuild="true"
+					>
+					<Tool
+                    Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug_All|Win32"
+					ExcludedFromBuild="false"
+					>
+					<Tool
+                    Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Production|Win32"
+					ExcludedFromBuild="false"
+					>
+					<Tool
+                    Name="VCCLCompilerTool"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath="..\editing\SimplifyMarkupCommand.h"
+				>
+			</File>
+			<File
 				RelativePath="..\editing\SmartReplace.cpp"
 				>
 				<FileConfiguration

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (113368 => 113369)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-04-05 20:31:52 UTC (rev 113369)
@@ -5681,6 +5681,8 @@
 		C598902E14E9B0F800E8D18B /* PlatformPasteboardMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C5F765BA14E1ECF4006C899B /* PlatformPasteboardMac.mm */; };
 		C598905714E9C28000E8D18B /* PasteboardStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = C5F765B414E1D414006C899B /* PasteboardStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C598905814E9C29900E8D18B /* PlatformPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = C5BAC16F14E30E4700008837 /* PlatformPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		C5A1EA7C152BCF04004D00B6 /* SimplifyMarkupCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C5A1EA79152BC486004D00B6 /* SimplifyMarkupCommand.cpp */; };
+		C5A1EA7D152BCF08004D00B6 /* SimplifyMarkupCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = C5A1EA7A152BC486004D00B6 /* SimplifyMarkupCommand.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C5B4C24D1509236C00A6EF37 /* WebCoreNSURLExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = C5B4C24B1509236C00A6EF37 /* WebCoreNSURLExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C5B4C24E1509236C00A6EF37 /* WebCoreNSURLExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = C5B4C24C1509236C00A6EF37 /* WebCoreNSURLExtras.mm */; };
 		C5D4AA7A116BAFB60069CA93 /* GlyphMetricsMap.h in Headers */ = {isa = PBXBuildFile; fileRef = C5D4AA78116BAFB60069CA93 /* GlyphMetricsMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -12767,6 +12769,8 @@
 		C585A67911D4FB07004C3E4B /* JSIDBRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBRequest.h; sourceTree = "<group>"; };
 		C585A69411D4FB13004C3E4B /* JSIDBFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSIDBFactory.cpp; sourceTree = "<group>"; };
 		C585A69511D4FB13004C3E4B /* JSIDBFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBFactory.h; sourceTree = "<group>"; };
+		C5A1EA79152BC486004D00B6 /* SimplifyMarkupCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimplifyMarkupCommand.cpp; sourceTree = "<group>"; };
+		C5A1EA7A152BC486004D00B6 /* SimplifyMarkupCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimplifyMarkupCommand.h; sourceTree = "<group>"; };
 		C5B4C24B1509236C00A6EF37 /* WebCoreNSURLExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreNSURLExtras.h; sourceTree = "<group>"; };
 		C5B4C24C1509236C00A6EF37 /* WebCoreNSURLExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSURLExtras.mm; sourceTree = "<group>"; };
 		C5BAC16F14E30E4700008837 /* PlatformPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformPasteboard.h; sourceTree = "<group>"; };
@@ -16695,6 +16699,8 @@
 				93309DC0099E64910056E581 /* SetNodeAttributeCommand.cpp */,
 				93309DC1099E64910056E581 /* SetNodeAttributeCommand.h */,
 				B8DBDB47130B0F8A00F5CDB1 /* SetSelectionCommand.cpp */,
+				C5A1EA79152BC486004D00B6 /* SimplifyMarkupCommand.cpp */,
+				C5A1EA7A152BC486004D00B6 /* SimplifyMarkupCommand.h */,
 				B8DBDB48130B0F8A00F5CDB1 /* SetSelectionCommand.h */,
 				4B6FA6F30C39E48C00087011 /* SmartReplace.cpp */,
 				4B6FA6F20C39E48C00087011 /* SmartReplace.h */,
@@ -24718,6 +24724,7 @@
 				CE08C3D2152B599A0021B8C2 /* AlternativeTextController.h in Headers */,
 				A07D3356152B630E001B6393 /* JSWebGLShaderPrecisionFormat.h in Headers */,
 				A07D3358152B632D001B6393 /* WebGLShaderPrecisionFormat.h in Headers */,
+				C5A1EA7D152BCF08004D00B6 /* SimplifyMarkupCommand.h in Headers */,
 				CEDA12D7152CA1CB00D9E08D /* AlternativeTextClient.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -27717,6 +27724,7 @@
 				CE08C3D1152B599A0021B8C2 /* AlternativeTextController.cpp in Sources */,
 				A07D3355152B630E001B6393 /* JSWebGLShaderPrecisionFormat.cpp in Sources */,
 				A08CF154152B77B3009C5775 /* WebGLShaderPrecisionFormat.cpp in Sources */,
+				C5A1EA7C152BCF04004D00B6 /* SimplifyMarkupCommand.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebCore/editing/EditingAllInOne.cpp (113368 => 113369)


--- trunk/Source/WebCore/editing/EditingAllInOne.cpp	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/editing/EditingAllInOne.cpp	2012-04-05 20:31:52 UTC (rev 113369)
@@ -63,6 +63,7 @@
 #include <ReplaceSelectionCommand.cpp>
 #include <SetNodeAttributeCommand.cpp>
 #include <SetSelectionCommand.cpp>
+#include <SimplifyMarkupCommand.cpp>
 #include <SmartReplace.cpp>
 #include <SmartReplaceCF.cpp>
 #include <SpellingCorrectionCommand.cpp>

Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp (113368 => 113369)


--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp	2012-04-05 20:31:52 UTC (rev 113369)
@@ -49,6 +49,7 @@
 #include "RenderInline.h"
 #include "RenderObject.h"
 #include "RenderText.h"
+#include "SimplifyMarkupCommand.h"
 #include "SmartReplace.h"
 #include "StylePropertySet.h"
 #include "TextIterator.h"
@@ -550,54 +551,6 @@
     }
 }
 
-void ReplaceSelectionCommand::removeRedundantMarkup(InsertedNodes& insertedNodes)
-{
-    Node* pastEndNode = insertedNodes.pastLastLeaf();
-    Node* rootNode = insertedNodes.firstNodeInserted()->parentNode();
-    Vector<Node*> nodesToRemove;
-    
-    // Walk through the inserted nodes, to see if there are elements that could be removed
-    // without affecting the style. The goal is to produce leaner markup even when starting
-    // from a verbose fragment.
-    // We look at inline elements as well as non top level divs that don't have attributes. 
-    for (Node* node = insertedNodes.firstNodeInserted(); node && node != pastEndNode; node = node->traverseNextNode()) {
-        if (node->firstChild() || (node->isTextNode() && node->nextSibling()))
-            continue;
-        
-        Node* startingNode = node->parentNode();
-        RenderStyle* startingStyle = startingNode->renderStyle();
-        if (!startingStyle)
-            continue;
-        Node* currentNode = startingNode;
-        Node* topNodeWithStartingStyle = 0;
-        while (currentNode != rootNode) {
-            if (currentNode->parentNode() != rootNode && isRemovableBlock(currentNode))
-                nodesToRemove.append(currentNode);
-
-            currentNode = currentNode->parentNode();
-            if (!currentNode->renderer() || !currentNode->renderer()->isRenderInline() || toRenderInline(currentNode->renderer())->alwaysCreateLineBoxes())
-                continue;
-
-            if (currentNode && currentNode->firstChild() != currentNode->lastChild()) {
-                topNodeWithStartingStyle = 0;
-                break;
-            }
-            
-            unsigned context;
-            if (currentNode->renderStyle()->diff(startingStyle, context) == StyleDifferenceEqual)
-                topNodeWithStartingStyle = currentNode;
-            
-        }
-        if (topNodeWithStartingStyle) {
-            for (Node* node = startingNode; node != topNodeWithStartingStyle; node = node->parentNode())
-                nodesToRemove.append(node);
-        }
-    }
-    // we perform all the DOM mutations at once.
-    for (size_t i = 0; i < nodesToRemove.size(); ++i)
-        removeNodePreservingChildren(nodesToRemove[i]);
-}
-
 static inline bool nodeHasVisibleRenderText(Text* text)
 {
     return text->renderer() && toRenderText(text->renderer())->renderedTextLength() > 0;
@@ -1067,7 +1020,7 @@
     removeRedundantStylesAndKeepStyleSpanInline(insertedNodes);
 
     if (m_sanitizeFragment)
-        removeRedundantMarkup(insertedNodes);
+        applyCommandToComposite(SimplifyMarkupCommand::create(document(), insertedNodes.firstNodeInserted(), insertedNodes.pastLastLeaf()));
 
     // Setup m_startOfInsertedContent and m_endOfInsertedContent. This should be the last two lines of code that access insertedNodes.
     m_startOfInsertedContent = firstPositionInOrBeforeNode(insertedNodes.firstNodeInserted());

Modified: trunk/Source/WebCore/editing/ReplaceSelectionCommand.h (113368 => 113369)


--- trunk/Source/WebCore/editing/ReplaceSelectionCommand.h	2012-04-05 20:28:12 UTC (rev 113368)
+++ trunk/Source/WebCore/editing/ReplaceSelectionCommand.h	2012-04-05 20:31:52 UTC (rev 113369)
@@ -89,7 +89,6 @@
     void removeUnrenderedTextNodesAtEnds(InsertedNodes&);
     
     void removeRedundantStylesAndKeepStyleSpanInline(InsertedNodes&);
-    void removeRedundantMarkup(InsertedNodes&);
     void handleStyleSpans(InsertedNodes&);
     void handlePasteAsQuotationNode();
     

Added: trunk/Source/WebCore/editing/SimplifyMarkupCommand.cpp (0 => 113369)


--- trunk/Source/WebCore/editing/SimplifyMarkupCommand.cpp	                        (rev 0)
+++ trunk/Source/WebCore/editing/SimplifyMarkupCommand.cpp	2012-04-05 20:31:52 UTC (rev 113369)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2012 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "SimplifyMarkupCommand.h"
+
+#include "NodeRenderStyle.h"
+#include "RenderInline.h"
+#include "RenderObject.h"
+#include "RenderStyle.h"
+
+namespace WebCore {
+
+SimplifyMarkupCommand::SimplifyMarkupCommand(Document* document, Node* firstNode, Node* nodeAfterLast) 
+    : CompositeEditCommand(document), m_firstNode(firstNode), m_nodeAfterLast(nodeAfterLast)
+{
+}
+    
+void SimplifyMarkupCommand::doApply()
+{
+    Node* rootNode = m_firstNode->parentNode();
+    Vector<Node*> nodesToRemove;
+    
+    // Walk through the inserted nodes, to see if there are elements that could be removed
+    // without affecting the style. The goal is to produce leaner markup even when starting
+    // from a verbose fragment.
+    // We look at inline elements as well as non top level divs that don't have attributes. 
+    for (Node* node = m_firstNode.get(); node && node != m_nodeAfterLast; node = node->traverseNextNode()) {
+        if (node->firstChild() || (node->isTextNode() && node->nextSibling()))
+            continue;
+        
+        Node* startingNode = node->parentNode();
+        RenderStyle* startingStyle = startingNode->renderStyle();
+        if (!startingStyle)
+            continue;
+        Node* currentNode = startingNode;
+        Node* topNodeWithStartingStyle = 0;
+        while (currentNode != rootNode) {
+            if (currentNode->parentNode() != rootNode && isRemovableBlock(currentNode))
+                nodesToRemove.append(currentNode);
+            
+            currentNode = currentNode->parentNode();
+            if (!currentNode->renderer() || !currentNode->renderer()->isRenderInline() || toRenderInline(currentNode->renderer())->alwaysCreateLineBoxes())
+                continue;
+            
+            if (currentNode && currentNode->firstChild() != currentNode->lastChild()) {
+                topNodeWithStartingStyle = 0;
+                break;
+            }
+            
+            unsigned context;
+            if (currentNode->renderStyle()->diff(startingStyle, context) == StyleDifferenceEqual)
+                topNodeWithStartingStyle = currentNode;
+            
+        }
+        if (topNodeWithStartingStyle) {
+            for (Node* node = startingNode; node != topNodeWithStartingStyle; node = node->parentNode())
+                nodesToRemove.append(node);
+        }
+    }
+    // we perform all the DOM mutations at once.
+    for (size_t i = 0; i < nodesToRemove.size(); ++i)
+        removeNodePreservingChildren(nodesToRemove[i]);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/editing/SimplifyMarkupCommand.h (0 => 113369)


--- trunk/Source/WebCore/editing/SimplifyMarkupCommand.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/SimplifyMarkupCommand.h	2012-04-05 20:31:52 UTC (rev 113369)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef SimplifyMarkupCommand_h
+#define SimplifyMarkupCommand_h
+
+#include "CompositeEditCommand.h"
+
+namespace WebCore {
+
+class SimplifyMarkupCommand : public CompositeEditCommand {
+public:
+    static PassRefPtr<SimplifyMarkupCommand> create(Document* document, Node* firstNode, Node* nodeAfterLast)
+    {
+        return adoptRef(new SimplifyMarkupCommand(document, firstNode, nodeAfterLast));
+    }
+
+private:
+    SimplifyMarkupCommand(Document*, Node* firstNode, Node* nodeAfterLast);
+
+    virtual void doApply();
+    
+    RefPtr<Node> m_firstNode;
+    RefPtr<Node> m_nodeAfterLast;
+};
+
+} // namespace WebCore
+
+#endif // SimplifyMarkupCommand_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to