Title: [149167] trunk
- Revision
- 149167
- Author
- [email protected]
- Date
- 2013-04-25 21:51:28 -0700 (Thu, 25 Apr 2013)
Log Message
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.
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.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (149166 => 149167)
--- trunk/LayoutTests/ChangeLog 2013-04-26 04:50:30 UTC (rev 149166)
+++ trunk/LayoutTests/ChangeLog 2013-04-26 04:51:28 UTC (rev 149167)
@@ -1,3 +1,15 @@
+2013-04-25 Ryosuke Niwa <[email protected]>
+
+ 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 <[email protected]>
Add support for Math.imul
Added: trunk/LayoutTests/editing/pasteboard/copy-paste-with-important-rules-expected.txt (0 => 149167)
--- trunk/LayoutTests/editing/pasteboard/copy-paste-with-important-rules-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-paste-with-important-rules-expected.txt 2013-04-26 04:51:28 UTC (rev 149167)
@@ -0,0 +1,38 @@
+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"
+| "
+"
Added: trunk/LayoutTests/editing/pasteboard/copy-paste-with-important-rules.html (0 => 149167)
--- trunk/LayoutTests/editing/pasteboard/copy-paste-with-important-rules.html (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-paste-with-important-rules.html 2013-04-26 04:51:28 UTC (rev 149167)
@@ -0,0 +1,41 @@
+<!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=""
+<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>
Modified: trunk/Source/WebCore/ChangeLog (149166 => 149167)
--- trunk/Source/WebCore/ChangeLog 2013-04-26 04:50:30 UTC (rev 149166)
+++ trunk/Source/WebCore/ChangeLog 2013-04-26 04:51:28 UTC (rev 149167)
@@ -1,3 +1,22 @@
+2013-04-25 Ryosuke Niwa <[email protected]>
+
+ 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 <[email protected]>
StylePropertySet::getPropertyShorthand() should return a String.
Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (149166 => 149167)
--- trunk/Source/WebCore/css/StylePropertySet.cpp 2013-04-26 04:50:30 UTC (rev 149166)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp 2013-04-26 04:51:28 UTC (rev 149167)
@@ -1030,14 +1030,8 @@
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
Modified: trunk/Source/WebCore/css/ViewportStyleResolver.cpp (149166 => 149167)
--- trunk/Source/WebCore/css/ViewportStyleResolver.cpp 2013-04-26 04:50:30 UTC (rev 149166)
+++ trunk/Source/WebCore/css/ViewportStyleResolver.cpp 2013-04-26 04:51:28 UTC (rev 149167)
@@ -65,10 +65,7 @@
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()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes