https://bugs.webkit.org/show_bug.cgi?id=115217
Reviewed by Darin Adler.
Source/WebCore:
The bug was caused by mergeStyleFromRules overriding "important" style rules with "unimportant" inline styles.
Fixed the bug by using addParsedProperty, which respects !important, in MutableStylePropertySet's
mergeAndOverrideOnConflict, which was only used in editing code. Now that we've fixed this function, we can use
it in ViewportStyleResolver::addViewportRule as well.
Test: editing/pasteboard/copy-paste-with-important-rules.html
* css/StylePropertySet.cpp:
(WebCore::MutableStylePropertySet::mergeAndOverrideOnConflict): Fixed to respect !important.
* css/ViewportStyleResolver.cpp:
(WebCore::ViewportStyleResolver::addViewportRule): Use mergeAndOverrideOnConflict now that the code is identical.
LayoutTests:
Added a regression test.
* editing/pasteboard/copy-paste-with-important-rules-expected.txt: Added.
* editing/pasteboard/copy-paste-with-important-rules.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@149167
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2013-04-25 Ryosuke Niwa <rniwa@webkit.org>
+
+ Copy and paste can strip !important CSS rules due to a bug in mergeStyleFromRules
+ https://bugs.webkit.org/show_bug.cgi?id=115217
+
+ Reviewed by Darin Adler.
+
+ Added a regression test.
+
+ * editing/pasteboard/copy-paste-with-important-rules-expected.txt: Added.
+ * editing/pasteboard/copy-paste-with-important-rules.html: Added.
+
2013-04-24 Oliver Hunt <oliver@apple.com>
Add support for Math.imul
--- /dev/null
+This test ensures copying and paste respects !important in style rules.
+To test manually, copy and paste the content in the first box to the second box. All text should remain in blue and should remain unboldened.
+
+Original content:
+| "
+"
+| <p>
+| "<#selection-anchor>hello "
+| <span>
+| style="color: red; font-weight: bold;"
+| "world"
+| "
+"
+| <p>
+| <span>
+| class="Apple-style-span"
+| style="color: red; font-weight: bold;"
+| "WebKit<#selection-focus>"
+| "
+"
+
+Pasted content:
+| "
+"
+| <p>
+| "hello "
+| <span>
+| style="color: red; font-weight: bold;"
+| "world"
+| "
+"
+| <p>
+| <span>
+| class="Apple-style-span"
+| style="color: red; font-weight: bold;"
+| "WebKit"
+| "
+"
--- /dev/null
+<!DOCTYPE html>
+<html>
+<body>
+<style>
+#source * {
+ color: blue !important;
+ font-weight: normal !important;
+}
+body > div {
+ border: 2px solid black;
+ margin: 10px;
+}
+</style>
+<p id="description">This test ensures copying and paste respects !important in style rules.
+To test manually, copy and paste the content in the first box to the second box. All text should remain in blue and should remain unboldened.</p>
+<div id="source" contenteditable>
+<p>hello <span style="color: red; font-weight: bold;">world</span></p>
+<p><span class="Apple-style-span" style="color: red; font-weight: bold;">WebKit</span></p>
+</div>
+<div id="destination" contenteditable></div>
+<script src="../../resources/dump-as-markup.js"></script>
+<script>
+
+Markup.description(document.getElementById('description').textContent);
+
+var source = document.getElementById('source');
+source.focus();
+getSelection().selectAllChildren(source);
+
+if (document.queryCommandEnabled('paste', false, null) && document.queryCommandEnabled('paste', false, null)) {
+ Markup.dump('source', 'Original content');
+ document.execCommand('copy');
+ getSelection().collapse(document.getElementById('destination'));
+ document.execCommand('paste');
+ Markup.dump('source', 'Pasted content');
+} else
+ Markup.noAutoDump();
+
+</script>
+</body>
+</html>
+2013-04-25 Ryosuke Niwa <rniwa@webkit.org>
+
+ Copy and paste can strip !important CSS rules due to a bug in mergeStyleFromRules
+ https://bugs.webkit.org/show_bug.cgi?id=115217
+
+ Reviewed by Darin Adler.
+
+ The bug was caused by mergeStyleFromRules overriding "important" style rules with "unimportant" inline styles.
+ Fixed the bug by using addParsedProperty, which respects !important, in MutableStylePropertySet's
+ mergeAndOverrideOnConflict, which was only used in editing code. Now that we've fixed this function, we can use
+ it in ViewportStyleResolver::addViewportRule as well.
+
+ Test: editing/pasteboard/copy-paste-with-important-rules.html
+
+ * css/StylePropertySet.cpp:
+ (WebCore::MutableStylePropertySet::mergeAndOverrideOnConflict): Fixed to respect !important.
+ * css/ViewportStyleResolver.cpp:
+ (WebCore::ViewportStyleResolver::addViewportRule): Use mergeAndOverrideOnConflict now that the code is identical.
+
2013-04-25 Andreas Kling <akling@apple.com>
StylePropertySet::getPropertyShorthand() should return a String.
void MutableStylePropertySet::mergeAndOverrideOnConflict(const StylePropertySet* other)
{
unsigned size = other->propertyCount();
- for (unsigned n = 0; n < size; ++n) {
- PropertyReference toMerge = other->propertyAt(n);
- CSSProperty* old = findCSSPropertyWithID(toMerge.id());
- if (old)
- setProperty(toMerge.toCSSProperty(), old);
- else
- appendPrefixingVariantProperty(toMerge.toCSSProperty());
- }
+ for (unsigned i = 0; i < size; ++i)
+ addParsedProperty(other->propertyAt(i).toCSSProperty());
}
void StylePropertySet::addSubresourceStyleURLs(ListHashSet<KURL>& urls, StyleSheetContents* contextStyleSheet) const
return;
}
- // We cannot use mergeAndOverrideOnConflict() here because it doesn't
- // respect the !important declaration (but addParsedProperty() does).
- for (unsigned i = 0; i < propertyCount; ++i)
- m_propertySet->addParsedProperty(propertySet->propertyAt(i).toCSSProperty());
+ m_propertySet->mergeAndOverrideOnConflict(propertySet);
}
void ViewportStyleResolver::clearDocument()