Repro Steps: 1) Place the cursor in a contentEditable element. 2) Execute document.execCommand('backColor', false, '#f00') in JavaScript. 3) Type some text. Expected Result: The new text should have a red background. Actual Result: The new text keeps the same background. Notes: 'backColor' works ok when text is actually selected. If we replace 'backColor' with 'foreColor' in step #2, the new text is red as expected. Verified on Safari3/Win and Webkit-Nightly/OSX.
JSEditor.cpp shows that BackColor and ForeColor have different values for the enabledFn member of their CommandImp: WebCore/editing/JSEditor.cpp: { "BackColor", { execBackColor, enabledAnyRichlyEditableRangeSelection, stateNone, valueBackColor } }, WebCore/editing/JSEditor.cpp: { "ForeColor", { execForeColor, enabledAnySelection, stateNone, valueForeColor } }, BackColor requires a range selection which would cause the command to be disabled for collapsed selections. The fix here may be as simple as changing the enabledFn to enabledAnyRichlyEditableSelection. A quick test suggests that this gives the same behaviour as IE on the test case.
So it sounds like all this bug needs is some understanding of what a change to enabledAnyRichlyEditableSelection would mean for the rest of the web. :) I guess we solve that with a test case.
+1 on fixing this. We have horrible, horrible hacks in place to get this working in the Google editor. I'd love to get rid of them!
(In reply to comment #1) > JSEditor.cpp shows that BackColor and ForeColor have different values for the > enabledFn member of their CommandImp: > > WebCore/editing/JSEditor.cpp: { "BackColor", { execBackColor, > enabledAnyRichlyEditableRangeSelection, stateNone, valueBackColor } }, > WebCore/editing/JSEditor.cpp: { "ForeColor", { execForeColor, > enabledAnySelection, stateNone, valueForeColor } }, Yikes that's completely wrong, BackColor should have enabledAnyRichlyEditableRangeSelection, and I don't know why ForeColor has enabledAnySelection, it should be disabled in a plain text region too.
> BackColor should have enabledAnyRichlyEditableRangeSelection that should read "enabledAnyRichlyEditableSelection".
http://trac.webkit.org/changeset/34682