Title: [123940] trunk
Revision
123940
Author
[email protected]
Date
2012-07-27 17:32:15 -0700 (Fri, 27 Jul 2012)

Log Message

execCommand copies the backgroung-color of the enclosing element to the element being edited.
https://bugs.webkit.org/show_bug.cgi?id=91783

Patch by Sukolsak Sakshuwong <[email protected]> on 2012-07-27
Reviewed by Ryosuke Niwa.

Source/WebCore:

InsertListCommand and some other edit commands remove redundant
style properties after their DOM modification by using
StylePropertySet::removeEquivalentProperties.  However, this method
does not remove redundant background-color properties such as
"background-color: white" and "background-color: #fff" because
it compares them using cssText and thus treats them as different.
Add code to convert background colors to RGBA and then compare them.

Test: editing/style/redundant-background-color.html

* editing/EditingStyle.cpp:
(WebCore::getRGBABackgroundColor):
(WebCore):
(WebCore::getPropertiesNotIn):

LayoutTests:

This tests to make sure that WebKit removes redundant "background-color"
property after execCommand.

* editing/style/redundant-background-color-expected.txt: Added.
* editing/style/redundant-background-color.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (123939 => 123940)


--- trunk/LayoutTests/ChangeLog	2012-07-28 00:30:31 UTC (rev 123939)
+++ trunk/LayoutTests/ChangeLog	2012-07-28 00:32:15 UTC (rev 123940)
@@ -1,3 +1,16 @@
+2012-07-27  Sukolsak Sakshuwong  <[email protected]>
+
+        execCommand copies the backgroung-color of the enclosing element to the element being edited.
+        https://bugs.webkit.org/show_bug.cgi?id=91783
+
+        Reviewed by Ryosuke Niwa.
+
+        This tests to make sure that WebKit removes redundant "background-color"
+        property after execCommand.
+
+        * editing/style/redundant-background-color-expected.txt: Added.
+        * editing/style/redundant-background-color.html: Added.
+
 2012-07-27  Scott Graham  <[email protected]>
 
         Change navigator.webkitGamepads[] to navigator.webkitGetGamepads()

Added: trunk/LayoutTests/editing/style/redundant-background-color-expected.txt (0 => 123940)


--- trunk/LayoutTests/editing/style/redundant-background-color-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/style/redundant-background-color-expected.txt	2012-07-28 00:32:15 UTC (rev 123940)
@@ -0,0 +1,5 @@
+This tests to make sure that WebKit removes redundant background-color property after execCommand. (See the bug 91783). There should be no background-color property below.
+| <ul>
+|   <li>
+|     "<#selection-anchor>Hello<#selection-focus>"
+|     <br>

Added: trunk/LayoutTests/editing/style/redundant-background-color.html (0 => 123940)


--- trunk/LayoutTests/editing/style/redundant-background-color.html	                        (rev 0)
+++ trunk/LayoutTests/editing/style/redundant-background-color.html	2012-07-28 00:32:15 UTC (rev 123940)
@@ -0,0 +1,26 @@
+<!doctype html>
+<html>
+<head>
+<title>Redundant background-color</title>
+<script src=""
+</head>
+<body>
+<div id="div">Hello</div>
+
+<script>
+Markup.description("This tests to make sure that WebKit removes redundant background-color property after execCommand. (See the bug 91783). There should be no background-color property below.");
+
+var div = document.getElementById("div");
+div.contentEditable = true;
+div.style.cssText = "background-color: white;";
+
+var range = document.createRange();
+range.selectNodeContents(div);
+window.getSelection().addRange(range);
+
+document.execCommand("insertUnorderedList");
+
+Markup.dump(div);
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (123939 => 123940)


--- trunk/Source/WebCore/ChangeLog	2012-07-28 00:30:31 UTC (rev 123939)
+++ trunk/Source/WebCore/ChangeLog	2012-07-28 00:32:15 UTC (rev 123940)
@@ -1,3 +1,25 @@
+2012-07-27  Sukolsak Sakshuwong  <[email protected]>
+
+        execCommand copies the backgroung-color of the enclosing element to the element being edited.
+        https://bugs.webkit.org/show_bug.cgi?id=91783
+
+        Reviewed by Ryosuke Niwa.
+
+        InsertListCommand and some other edit commands remove redundant
+        style properties after their DOM modification by using
+        StylePropertySet::removeEquivalentProperties.  However, this method
+        does not remove redundant background-color properties such as
+        "background-color: white" and "background-color: #fff" because
+        it compares them using cssText and thus treats them as different.
+        Add code to convert background colors to RGBA and then compare them.
+
+        Test: editing/style/redundant-background-color.html
+
+        * editing/EditingStyle.cpp:
+        (WebCore::getRGBABackgroundColor):
+        (WebCore):
+        (WebCore::getPropertiesNotIn):
+
 2012-07-27  Gyuyoung Kim  <[email protected]>
 
         [EFL] Return 0 when network is offline

Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (123939 => 123940)


--- trunk/Source/WebCore/editing/EditingStyle.cpp	2012-07-28 00:30:31 UTC (rev 123939)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp	2012-07-28 00:32:15 UTC (rev 123940)
@@ -368,6 +368,16 @@
     return cssValueToRGBA(style->getPropertyCSSValue(CSSPropertyColor).get());
 }
 
+static inline RGBA32 getRGBABackgroundColor(CSSStyleDeclaration* style)
+{
+    return cssValueToRGBA(style->getPropertyCSSValueInternal(CSSPropertyBackgroundColor).get());
+}
+
+static inline RGBA32 getRGBABackgroundColor(StylePropertySet* style)
+{
+    return cssValueToRGBA(style->getPropertyCSSValue(CSSPropertyBackgroundColor).get());
+}
+
 static inline RGBA32 rgbaBackgroundColorInEffect(Node* node)
 {
     return cssValueToRGBA(backgroundColorInEffect(node).get());
@@ -1505,6 +1515,9 @@
         && textAlignResolvingStartAndEnd(result.get()) == textAlignResolvingStartAndEnd(baseStyle))
         result->removeProperty(CSSPropertyTextAlign);
 
+    if (baseStyle->getPropertyCSSValueInternal(CSSPropertyBackgroundColor) && getRGBABackgroundColor(result.get()) == getRGBABackgroundColor(baseStyle))
+        result->removeProperty(CSSPropertyBackgroundColor);
+
     return result;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to