[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

rniwa at webkit.org rniwa at webkit.org
Wed Dec 22 12:48:55 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 22d2b4b678b3ac0c77b37837332608a10bdad71f
Author: rniwa at webkit.org <rniwa at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Aug 31 00:26:14 2010 +0000

    2010-08-30  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Darin Adler.
    
            queryCommandValue("BackColor") returns rgb(0,0,0) for elements with transparent background
            https://bugs.webkit.org/show_bug.cgi?id=21680
    
            The bug was caused by WebKit's using the computed style to obtain the background color,
            which is rgba(0,0,0,0) for nodes with transparent background color. While this is correct
            in the accordance to CSS2 because background-color is not inherited by default,
            it is not desirable for editing purposes where the background color in effect is expected.
    
            Modified valueStyle in EditorCommand.cpp to call Editor::selectionStartCSSPropertyValue,
            instead of Frame::selectionStartStylePropertyValue, which traverses common ancestors of
            the selected range or caret to retrieve the effective background color of the selected region
            instead of the background color at the start of the selection.
            This takes effect when the original background color is transparent or the selection is range
            (to avoid picking up the background color only present at the start of paragraph).
    
            Removed selectionStartStylePropertyValue and migrated it to Editor::selectionStartCSSPropertyValue.
    
            Test: editing/execCommand/query-command-value-background-color.html
    
            * editing/Editor.cpp:
            (WebCore::hasTransparentBackgroundColor): Checks whether the specified style's background color is transparent or not.
            (WebCore::Editor::selectionStartCSSPropertyValue): Migrated the contents of selectionStartStylePropertyValue and
              added the special case for background color.
            * editing/Editor.h: Added the prototype for selectionStartCSSPropertyValue.
            * editing/EditorCommand.cpp:
            (WebCore::valueStyle): Calls Editor::selectionStartCSSPropertyValue.
            * page/Frame.cpp: Removed selectionStartStylePropertyValue.
            * page/Frame.h: Ditto.
    2010-08-30  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Darin Adler.
    
            queryCommandValue("BackColor") returns rgb(0,0,0) for elements with transparent background
            https://bugs.webkit.org/show_bug.cgi?id=21680
    
            Tests queryCommandValue("BackColor") on various cases, especially the cases where
            the background color of the selected node is transparent but that of its ancestor has a color.
    
            * editing/execCommand/query-command-value-background-color-expected.txt: Added.
            * editing/execCommand/query-command-value-background-color.html: Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66431 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 41fc770..b75e864 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
+2010-08-30  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Darin Adler.
+
+        queryCommandValue("BackColor") returns rgb(0,0,0) for elements with transparent background
+        https://bugs.webkit.org/show_bug.cgi?id=21680
+
+        Tests queryCommandValue("BackColor") on various cases, especially the cases where
+        the background color of the selected node is transparent but that of its ancestor has a color.
+
+        * editing/execCommand/query-command-value-background-color-expected.txt: Added.
+        * editing/execCommand/query-command-value-background-color.html: Added.
+
 2010-08-30  Kent Tamura  <tkent at chromium.org>
 
         Reviewed by Adam Barth.
diff --git a/LayoutTests/editing/execCommand/query-command-value-background-color-expected.txt b/LayoutTests/editing/execCommand/query-command-value-background-color-expected.txt
new file mode 100644
index 0000000..3301598
--- /dev/null
+++ b/LayoutTests/editing/execCommand/query-command-value-background-color-expected.txt
@@ -0,0 +1,13 @@
+PASS rgb(0, 128, 0) for <div style='background: green;'><span id=selected>hello world</span></div>
+PASS rgb(0, 128, 0) for <div style='background: green;'><p>hello</p><span id=selected>world</span><p>webkit</p></div>
+PASS rgb(0, 0, 255) for <div style='background: green;'>hello <span style='background-color: blue;' id=selected>world</span></div>
+FAILED expected rgb(204, 204, 204) but got rgb(0, 128, 0) for <div style='background: green;'>hello<span style='position: absolute; top: 200px;' id=selected>world</span></div>
+FAILED expected rgb(0, 0, 0) but got rgb(0, 128, 0) for <div style='background: green;'>hello<span style='position: absolute; top: 500px;' id=selected>world</span></div>
+PASS rgb(0, 128, 0) for <div style='background: green;' id=selected><span style='background-color: yellow'>hello</span> world</div>
+PASS rgb(0, 128, 0) for <div style='background: green;' id=selected><span style='background-color: yellow'>hello</span><span style='background-color: yellow'> world</span></div>
+PASS rgb(0, 128, 0) for <div style='background: green;' id=selected><span style='background-color: yellow'>hello</span><span style='background-color: blue'> world</span></div>
+PASS rgb(255, 255, 0) for <div style='background: green;'><span style='background-color: yellow' id=selected>hello world</span></div>
+PASS rgb(0, 128, 0) for <div style='background: green;'><span style='background-color: rgba(255, 255, 0, 0);' id=selected>hello world</span></div>
+PASS rgba(255, 255, 0, 0.496094) for <div style='background: green;'><span style='background-color: rgba(255, 255, 0, 0.5);' id=selected>hello world</span></div>
+
+
diff --git a/LayoutTests/editing/execCommand/query-command-value-background-color.html b/LayoutTests/editing/execCommand/query-command-value-background-color.html
new file mode 100644
index 0000000..743076b
--- /dev/null
+++ b/LayoutTests/editing/execCommand/query-command-value-background-color.html
@@ -0,0 +1,60 @@
+<html>
+<body style="background: #cccccc;">
+<p id="console"></p>
+<div id="background" style="position: absolute; top: 490px; width: 500px; height:3em;background: black;"></div>
+<div id="container" contenteditable="true"></div>
+<script type="text/javascript"> 
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function getColor(e) {
+    if (document.selection) {
+        var r = document.selection.createRange();
+        r.moveToElementText(e);
+        r.select();
+        backColor = document.queryCommandValue('backColor');
+        r = (backColor & 0xFF)
+        g = ((backColor >> 8) & 0xFF)
+        b = ((backColor >> 16) & 0xFF)
+        return 'rgb('+r+', '+g+', '+b+')';
+    } else {
+        var r = document.createRange();
+        var s = window.getSelection();
+        r.setStart(e, 0);
+        r.setEnd(e, e.childNodes.length);
+        s.removeAllRanges();
+        s.addRange(r);
+        return document.queryCommandValue('backColor');
+    }
+}
+
+function test(html, expected) {
+    var c = document.getElementById('container');
+    c.innerHTML = html;
+    var actual = getColor(document.getElementById('selected'));
+    var console = document.getElementById('console');
+    if (actual == expected) {
+        console.innerHTML += "<span style='color: green; font-weight: bold;'>PASS</span> "+expected+" for ";
+    } else {
+        console.innerHTML += "<span style='color: red; font-weight: bold;'>FAILED</span> expected "+expected+
+            " but got "+actual+" for ";
+    }
+    console.appendChild(document.createTextNode(html));
+    console.innerHTML += "<br>";
+    c.innerHTML = "";
+}
+
+test("<div style='background: green;'><span id=selected>hello world</span></div>", 'rgb(0, 128, 0)');
+test("<div style='background: green;'><p>hello</p><span id=selected>world</span><p>webkit</p></div>", 'rgb(0, 128, 0)');
+test("<div style='background: green;'>hello <span style='background-color: blue;' id=selected>world</span></div>", 'rgb(0, 0, 255)');
+test("<div style='background: green;'>hello<span style='position: absolute; top: 200px;' id=selected>world</span></div>", 'rgb(204, 204, 204)');
+test("<div style='background: green;'>hello<span style='position: absolute; top: 500px;' id=selected>world</span></div>", 'rgb(0, 0, 0)');
+test("<div style='background: green;' id=selected><span style='background-color: yellow'>hello</span> world</div>", 'rgb(0, 128, 0)');
+test("<div style='background: green;' id=selected><span style='background-color: yellow'>hello</span><span style='background-color: yellow'> world</span></div>", 'rgb(0, 128, 0)');
+test("<div style='background: green;' id=selected><span style='background-color: yellow'>hello</span><span style='background-color: blue'> world</span></div>", 'rgb(0, 128, 0)');
+test("<div style='background: green;'><span style='background-color: yellow' id=selected>hello world</span></div>", 'rgb(255, 255, 0)');
+test("<div style='background: green;'><span style='background-color: rgba(255, 255, 0, 0);' id=selected>hello world</span></div>", 'rgb(0, 128, 0)');
+test("<div style='background: green;'><span style='background-color: rgba(255, 255, 0, 0.5);' id=selected>hello world</span></div>", 'rgba(255, 255, 0, 0.496094)');
+
+</script>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 998ad11..86678ad 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,36 @@
+2010-08-30  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Darin Adler.
+
+        queryCommandValue("BackColor") returns rgb(0,0,0) for elements with transparent background
+        https://bugs.webkit.org/show_bug.cgi?id=21680
+
+        The bug was caused by WebKit's using the computed style to obtain the background color,
+        which is rgba(0,0,0,0) for nodes with transparent background color. While this is correct
+        in the accordance to CSS2 because background-color is not inherited by default,
+        it is not desirable for editing purposes where the background color in effect is expected.
+
+        Modified valueStyle in EditorCommand.cpp to call Editor::selectionStartCSSPropertyValue,
+        instead of Frame::selectionStartStylePropertyValue, which traverses common ancestors of
+        the selected range or caret to retrieve the effective background color of the selected region
+        instead of the background color at the start of the selection.
+        This takes effect when the original background color is transparent or the selection is range
+        (to avoid picking up the background color only present at the start of paragraph).
+
+        Removed selectionStartStylePropertyValue and migrated it to Editor::selectionStartCSSPropertyValue.
+
+        Test: editing/execCommand/query-command-value-background-color.html
+
+        * editing/Editor.cpp:
+        (WebCore::hasTransparentBackgroundColor): Checks whether the specified style's background color is transparent or not.
+        (WebCore::Editor::selectionStartCSSPropertyValue): Migrated the contents of selectionStartStylePropertyValue and
+          added the special case for background color.
+        * editing/Editor.h: Added the prototype for selectionStartCSSPropertyValue.
+        * editing/EditorCommand.cpp:
+        (WebCore::valueStyle): Calls Editor::selectionStartCSSPropertyValue.
+        * page/Frame.cpp: Removed selectionStartStylePropertyValue.
+        * page/Frame.h: Ditto.
+
 2010-08-30  Lei Zhang  <thestig at chromium.org>
 
         Reviewed by Shinichiro Hamaji.
diff --git a/WebCore/editing/Editor.cpp b/WebCore/editing/Editor.cpp
index 3dd6e27..1d93308 100644
--- a/WebCore/editing/Editor.cpp
+++ b/WebCore/editing/Editor.cpp
@@ -918,6 +918,56 @@ TriState Editor::selectionHasStyle(CSSStyleDeclaration* style) const
 
     return state;
 }
+
+static bool hasTransparentBackgroundColor(CSSStyleDeclaration* style)
+{
+    RefPtr<CSSValue> cssValue = style->getPropertyCSSValue(CSSPropertyBackgroundColor);
+    if (!cssValue)
+        return true;
+
+    if (!cssValue->isPrimitiveValue())
+        return false;
+    CSSPrimitiveValue* value = static_cast<CSSPrimitiveValue*>(cssValue.get());
+
+    if (value->primitiveType() == CSSPrimitiveValue::CSS_RGBCOLOR)
+        return !alphaChannel(value->getRGBA32Value());
+
+    return value->getIdent() == CSSValueTransparent;
+}
+
+String Editor::selectionStartCSSPropertyValue(int propertyID)
+{
+    Node* nodeToRemove;
+    RefPtr<CSSStyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove);
+    if (!selectionStyle)
+        return String();
+
+    String value = selectionStyle->getPropertyValue(propertyID);
+
+    if (nodeToRemove) {
+        ExceptionCode ec = 0;
+        nodeToRemove->remove(ec);
+        ASSERT(!ec);
+    }
+
+    // If background color is transparent, traverse parent nodes until we hit a different value or document root
+    // Also, if the selection is a range, ignore the background color at the start of selection,
+    // and find the background color of the common ancestor.
+    if (propertyID == CSSPropertyBackgroundColor && (m_frame->selection()->isRange() || hasTransparentBackgroundColor(selectionStyle.get()))) {
+        RefPtr<Range> range(m_frame->selection()->toNormalizedRange());
+        ExceptionCode ec = 0;
+        Node* ancestor = range->commonAncestorContainer(ec);
+        ASSERT(ancestor);
+        do {
+            selectionStyle = computedStyle(ancestor);
+            ancestor = ancestor->parentNode();
+        } while (hasTransparentBackgroundColor(selectionStyle.get()));
+        value = selectionStyle->getPropertyValue(CSSPropertyBackgroundColor);
+    }
+
+    return value;
+}
+
 void Editor::indent()
 {
     applyCommand(IndentOutdentCommand::create(m_frame->document(), IndentOutdentCommand::Indent));
diff --git a/WebCore/editing/Editor.h b/WebCore/editing/Editor.h
index 83aef7e..96513e1 100644
--- a/WebCore/editing/Editor.h
+++ b/WebCore/editing/Editor.h
@@ -119,6 +119,7 @@ public:
     void respondToChangedContents(const VisibleSelection& endingSelection);
 
     TriState selectionHasStyle(CSSStyleDeclaration*) const;
+    String selectionStartCSSPropertyValue(int propertyID);
     const SimpleFontData* fontForSelection(bool&) const;
     WritingDirection textDirectionForSelection(bool&) const;
     
diff --git a/WebCore/editing/EditorCommand.cpp b/WebCore/editing/EditorCommand.cpp
index eb89593..38a452a 100644
--- a/WebCore/editing/EditorCommand.cpp
+++ b/WebCore/editing/EditorCommand.cpp
@@ -239,7 +239,9 @@ static TriState stateStyle(Frame* frame, int propertyID, const char* desiredValu
 
 static String valueStyle(Frame* frame, int propertyID)
 {
-    return frame->selectionStartStylePropertyValue(propertyID);
+    // FIXME: Rather than retrieving the style at the start of the current selection,
+    // we should retrieve the style present throughout the selection for non-Mac platforms.
+    return frame->editor()->selectionStartCSSPropertyValue(propertyID);
 }
 
 static TriState stateTextWritingDirection(Frame* frame, WritingDirection direction)
diff --git a/WebCore/page/Frame.cpp b/WebCore/page/Frame.cpp
index 521eac1..614d85a 100644
--- a/WebCore/page/Frame.cpp
+++ b/WebCore/page/Frame.cpp
@@ -770,24 +770,6 @@ void Frame::computeAndSetTypingStyle(CSSStyleDeclaration *style, EditAction edit
     m_typingStyle = mutableStyle.release();
 }
 
-String Frame::selectionStartStylePropertyValue(int stylePropertyID) const
-{
-    Node *nodeToRemove;
-    RefPtr<CSSStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);
-    if (!selectionStyle)
-        return String();
-
-    String value = selectionStyle->getPropertyValue(stylePropertyID);
-
-    if (nodeToRemove) {
-        ExceptionCode ec = 0;
-        nodeToRemove->remove(ec);
-        ASSERT(!ec);
-    }
-
-    return value;
-}
-
 PassRefPtr<CSSComputedStyleDeclaration> Frame::selectionComputedStyle(Node*& nodeToRemove) const
 {
     nodeToRemove = 0;
diff --git a/WebCore/page/Frame.h b/WebCore/page/Frame.h
index 36803f8..58520a6 100644
--- a/WebCore/page/Frame.h
+++ b/WebCore/page/Frame.h
@@ -197,7 +197,6 @@ namespace WebCore {
         void setMark(const VisibleSelection&);
 
         void computeAndSetTypingStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
-        String selectionStartStylePropertyValue(int stylePropertyID) const;
         void applyEditingStyleToBodyElement() const;
         void applyEditingStyleToElement(Element*) const;
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list