From: Grzegorz Czajkowski Date: Thu, 25 Apr 2013 12:45:32 +0000 (+0200) Subject: WebKit doesn't preserve style when copying text from another element X-Git-Tag: submit/tizen_2.1/20130514.045449~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fccadac34c199ba488e2835fde9401fe7faca785;p=framework%2Fweb%2Fwebkit-efl.git WebKit doesn't preserve style when copying text from another element This is cherry-pick from https://bugs.webkit.org/show_bug.cgi?id=112329 (attachment #4) Change-Id: I05699f90203cd7f58d359c05d97d5ecc0a444e8d --- diff --git a/Source/WTF/wtf/Platform.h b/Source/WTF/wtf/Platform.h index 2925e2f..1223d1f 100644 --- a/Source/WTF/wtf/Platform.h +++ b/Source/WTF/wtf/Platform.h @@ -446,6 +446,7 @@ #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 */ diff --git a/Source/WebCore/editing/EditingStyle.cpp b/Source/WebCore/editing/EditingStyle.cpp index a486e17..870cc13 100644 --- a/Source/WebCore/editing/EditingStyle.cpp +++ b/Source/WebCore/editing/EditingStyle.cpp @@ -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 styleFromMatchedRules = styleFromMatchedRulesForElement(element, StyleResolver::AllButEmptyCSSRules); +#if ENABLE(TIZEN_PRESERVE_STYLE_WHILE_COPYING) + if (styleFromMatchedRules && !styleFromMatchedRules->isEmpty()) { + RefPtr 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 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) diff --git a/Source/WebCore/editing/EditingStyle.h b/Source/WebCore/editing/EditingStyle.h index 00e9d57..2e2ff4d 100644 --- a/Source/WebCore/editing/EditingStyle.h +++ b/Source/WebCore/editing/EditingStyle.h @@ -135,7 +135,11 @@ public: static PassRefPtr 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; diff --git a/Source/WebCore/editing/ReplaceSelectionCommand.cpp b/Source/WebCore/editing/ReplaceSelectionCommand.cpp index 39627a8..4799314 100644 --- a/Source/WebCore/editing/ReplaceSelectionCommand.cpp +++ b/Source/WebCore/editing/ReplaceSelectionCommand.cpp @@ -488,6 +488,9 @@ void ReplaceSelectionCommand::removeRedundantStylesAndKeepStyleSpanInline(Insert const StylePropertySet* inlineStyle = element->inlineStyle(); RefPtr 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 and . 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; diff --git a/Source/WebCore/editing/markup.cpp b/Source/WebCore/editing/markup.cpp index 5d9ba2d..ac67c80 100644 --- a/Source/WebCore/editing/markup.cpp +++ b/Source/WebCore/editing/markup.cpp @@ -587,7 +587,11 @@ String createMarkup(const Range* range, Vector* 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();