WebKit doesn't preserve style when copying text from another element
authorGrzegorz Czajkowski <g.czajkowski@samsung.com>
Thu, 25 Apr 2013 12:45:32 +0000 (14:45 +0200)
committerMateusz Leszko <m.leszko@samsung.com>
Tue, 7 May 2013 09:02:32 +0000 (11:02 +0200)
This is cherry-pick from https://bugs.webkit.org/show_bug.cgi?id=112329 (attachment #4)

Change-Id: I05699f90203cd7f58d359c05d97d5ecc0a444e8d

Source/WTF/wtf/Platform.h
Source/WebCore/editing/EditingStyle.cpp
Source/WebCore/editing/EditingStyle.h
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/markup.cpp

index 2925e2f..1223d1f 100644 (file)
 #define ENABLE_TIZEN_LOAD_HTML_STRING_AS_UTF8 1 /* KwangYong Choi (ky0.choi@samsung.com) : Use UTF-8 instead of UTF-16 when the page is loaded by WebPage::loadHTMLString() */
 #define ENABLE_TIZEN_DRAW_SCALED_PATTERN 1 /* Kyungjin Kim(gen.kim@samsung.com) : Scale image prior to draw it's pattern to enhance performance */
 #define ENABLE_TIZEN_PAINT_SELECTION_ANTIALIAS_NONE 1 /* Hyeonji Kim(hyeonji.kim@samsung.com) : Remove the line between the preceding text block and the next text block which are selected */
+#define ENABLE_TIZEN_PRESERVE_STYLE_WHILE_COPYING 1 /* Grzegorz Czajkowski (g.czajkowski@samsung.com): while copying elements, their style are not being copied. It happens for span tag if it occurs alone. This is cherry-pick from https://bugs.webkit.org/show_bug.cgi?id=112329 which is under review. */
 #define ENABLE_TIZEN_USE_SETTINGS_FONT 1 /* Hyeonji Kim(hyeonji.kim@samsung.com) : When font-family is "Tizen", use system's setting font as default font-family */
 #define ENABLE_TIZEN_PARAGRAPH_SEPARATOR_FIX 1 /* Michal Pakula (m.pakula@samsung.com) : This is a quick fix for a bug where new paragraph was not created on contenteditable area with image and text nodes inside span tag */
 #define ENABLE_TIZEN_CONTENT_EDITABLE_BACKSPACE 1 /* Wojciech Bielawski(w.bielawski.com) : This is a quick fix for a bug where after pressing backspace image was moved not correctly */
index a486e17..870cc13 100644 (file)
@@ -1131,16 +1131,36 @@ static void removePropertiesInStyle(StylePropertySet* styleToRemovePropertiesFro
     styleToRemovePropertiesFrom->removePropertiesInSet(propertiesToRemove.data(), propertiesToRemove.size());
 }
 
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+bool EditingStyle::removeStyleFromRulesAndContext(StyledElement* element, Node* context)
+#else
 void EditingStyle::removeStyleFromRulesAndContext(StyledElement* element, Node* context)
+#endif
 {
     ASSERT(element);
     if (!m_mutableStyle)
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+        return false;
+#else
         return;
+#endif
 
     // 1. Remove style from matched rules because style remain without repeating it in inline style declaration
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+    bool removedStyleFromRules = false;
+#endif
     RefPtr<StylePropertySet> styleFromMatchedRules = styleFromMatchedRulesForElement(element, StyleResolver::AllButEmptyCSSRules);
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+    if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) {
+        RefPtr<StylePropertySet> newStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatchedRules->ensureCSSStyleDeclaration());
+        removedStyleFromRules = newStyle->propertyCount() != m_mutableStyle->propertyCount();
+        if (removedStyleFromRules)
+            m_mutableStyle = newStyle;
+    }
+#else
     if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty())
         m_mutableStyle = getPropertiesNotIn(m_mutableStyle.get(), styleFromMatchedRules->ensureCSSStyleDeclaration());
+#endif
 
     // 2. Remove style present in context and not overriden by matched rules.
     RefPtr<EditingStyle> computedStyle = EditingStyle::create(context, EditingPropertiesInEffect);
@@ -1160,6 +1180,10 @@ void EditingStyle::removeStyleFromRulesAndContext(StyledElement* element, Node*
         if (!styleFromMatchedRules->getPropertyCSSValue(CSSPropertyFloat) && getIdentifierValue(m_mutableStyle.get(), CSSPropertyFloat) == CSSValueNone)
             m_mutableStyle->removeProperty(CSSPropertyFloat);
     }
+
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+    return removedStyleFromRules;
+#endif
 }
 
 void EditingStyle::removePropertiesInElementDefaultStyle(Element* element)
index 00e9d57..2e2ff4d 100644 (file)
@@ -135,7 +135,11 @@ public:
     static PassRefPtr<EditingStyle> wrappingStyleForSerialization(Node* context, bool shouldAnnotate);
     void mergeStyleFromRules(StyledElement*);
     void mergeStyleFromRulesForSerialization(StyledElement*);
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+    bool removeStyleFromRulesAndContext(StyledElement*, Node* context);
+#else
     void removeStyleFromRulesAndContext(StyledElement*, Node* context);
+#endif
     void removePropertiesInElementDefaultStyle(Element*);
     void forceInline();
     int legacyFontSize(Document*) const;
index 39627a8..4799314 100644 (file)
@@ -488,6 +488,9 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline(Insert
 
         const StylePropertySet* inlineStyle = element->inlineStyle();
         RefPtr<EditingStyle> newInlineStyle = EditingStyle::create(inlineStyle);
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+        bool removedStyleFromRules = false;
+#endif
         if (inlineStyle) {
             ContainerNode* context = element->parentNode();
 
@@ -495,13 +498,23 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline(Insert
             // styles from blockquoteNode are allowed to override those from the source document, see <rdar://problem/4930986> and <rdar://problem/5089327>.
             Node* blockquoteNode = isMailPasteAsQuotationNode(context) ? context : enclosingNodeOfType(firstPositionInNode(context), isMailBlockquote, CanCrossEditingBoundary);
             if (blockquoteNode)
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+                removedStyleFromRules = newInlineStyle->removeStyleFromRulesAndContext(element, document()->documentElement());
+
+            removedStyleFromRules |= newInlineStyle->removeStyleFromRulesAndContext(element, context);
+#else
                 newInlineStyle->removeStyleFromRulesAndContext(element, document()->documentElement());
 
             newInlineStyle->removeStyleFromRulesAndContext(element, context);
+#endif
         }
 
         if (!inlineStyle || newInlineStyle->isEmpty()) {
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+            if (!removedStyleFromRules && (isStyleSpanOrSpanWithOnlyStyleAttribute(element))) {
+#else
             if (isStyleSpanOrSpanWithOnlyStyleAttribute(element)) {
+#endif
                 insertedNodes.willRemoveNodePreservingChildren(element);
                 removeNodePreservingChildren(element);
                 continue;
index 5d9ba2d..ac67c80 100644 (file)
@@ -587,7 +587,11 @@ String createMarkup(const Range* range, Vector<Node*>* nodes, EAnnotateForInterc
     if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(body).toNormalizedRange().get(), range))
         fullySelectedRoot = body;
     Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange.get(), shouldAnnotate);
+#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING)
+    StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, AnnotateForInterchange, updatedRange.get(), specialCommonAncestor);
+#else
     StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, updatedRange.get(), specialCommonAncestor);
+#endif
     Node* pastEnd = updatedRange->pastLastNode();
 
     Node* startNode = updatedRange->firstNode();