Bug 757371 part 4 - Do not insert style tags if the style is already applied; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-05-23 10:49:29 +03:00
Родитель 0d9f5e832b
Коммит 18b6bfc148
7 изменённых файлов: 61 добавлений и 40 удалений

Просмотреть файл

@ -45,7 +45,6 @@
"Command fontName, value \"quasit\": beforeinput event, uncanceled":true,
"Command fontName, value \"quasit\": input event, uncanceled":true,
"Command fontName, value \"serif\": beforeinput event, canceled":true,
"Command fontName, value \"serif\": input event, canceled":true,
"Command fontName, value \"serif\": beforeinput event, uncanceled":true,
"Command fontName, value \"serif\": input event, uncanceled":true,
"Command fontName, value \"Helvetica\": beforeinput event, canceled":true,

Просмотреть файл

@ -46,21 +46,13 @@
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"{<p style=\\\"background-color: aqua\\\">foo</p><p>bar</p>}\" queryCommandIndeterm(\"backcolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"{<p style=\\\"background-color: aqua\\\">foo</p><p>bar</p>}\" queryCommandValue(\"backcolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"{<p style=\\\"background-color: aqua\\\">foo</p><p>bar</p>}\" queryCommandValue(\"backcolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"backcolor\") after":true,
"[[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">b[ar]</span>baz</span>\" compare innerHTML":true,
"[[\"backcolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">b[ar]</span>baz</span>\" queryCommandValue(\"backcolor\") before":true,
@ -1702,16 +1694,6 @@
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"{<table><tr><td>foo<td>bar<td>baz</table>}\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"foo<font color=blue>[bar]</font>baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"foo{<font color=blue>bar</font>}baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: blue\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: blue\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: #00f\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: #00f\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: #0000ff\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: #0000ff\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: rgb(0, 0, 255)\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: rgb(0, 0, 255)\\\">foo<span style=\\\"color: brown\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"forecolor\",\"#0000FF\"]] \"<font color=blue>foo<font color=brown>[bar]</font>baz</font>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"<font color=blue>foo<font color=brown>[bar]</font>baz</font>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: rgb(0, 0, 255)\\\">foo<span style=\\\"color: brown\\\">b[ar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"<span style=\\\"color: rgb(0, 0, 255)\\\">foo<span style=\\\"color: brown\\\">b[ar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"forecolor\",\"#0000FF\"]] \"foo<span id=purple>ba[r</span>ba]z\" compare innerHTML":true,
@ -3767,21 +3749,13 @@
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"{<p style=\\\"background-color: aqua\\\">foo</p><p>bar</p>}\" queryCommandIndeterm(\"hilitecolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"{<p style=\\\"background-color: aqua\\\">foo</p><p>bar</p>}\" queryCommandValue(\"hilitecolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"{<p style=\\\"background-color: aqua\\\">foo</p><p>bar</p>}\" queryCommandValue(\"hilitecolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #00ffff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: #0ff\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") after":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") before":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: rgb(0, 255, 255)\\\">foo<span style=\\\"background-color: tan\\\">[bar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") after":true,
"[[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">b[ar]</span>baz</span>\" compare innerHTML":true,
"[[\"hilitecolor\",\"#00FFFF\"]] \"<span style=\\\"background-color: aqua\\\">foo<span style=\\\"background-color: tan\\\">b[ar]</span>baz</span>\" queryCommandValue(\"hilitecolor\") before":true,
@ -6656,22 +6630,10 @@
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"foo<var>b[a]r</var>baz\" queryCommandState(\"italic\") after":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo<var>b[a]r</var>baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo<var>b[a]r</var>baz\" queryCommandState(\"italic\") after":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"fo[o<address>bar</address>b]az\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"fo[o<address>bar</address>b]az\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"fo[o<em>bar</em>b]az\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"fo[o<em>bar</em>b]az\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"foo[<address>bar</address>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo[<address>bar</address>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"foo[<cite>bar</cite>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo[<cite>bar</cite>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"foo[<dfn>bar</dfn>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo[<dfn>bar</dfn>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"foo[<em>bar</em>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo[<em>bar</em>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"foo[<var>bar</var>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo[<var>bar</var>baz]\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"[foo<address>bar</address>]baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"[foo<address>bar</address>]baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"italic\",\"\"]] \"[foo<em>bar</em>]baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"[foo<em>bar</em>]baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"italic\",\"\"]] \"foo<span style=\\\"font-style: oblique\\\">b[a]r</span>baz\" compare innerHTML":true,
@ -10818,7 +10780,6 @@
"[[\"stylewithcss\",\"false\"],[\"strikethrough\",\"\"]] \"foo<span class=\\\"underline\\\">[bar]</span>baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"strikethrough\",\"\"]] \"foo<span class=\\\"underline\\\">b[a]r</span>baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"strikethrough\",\"\"]] \"fo[o<s>bar</s>b]az\" compare innerHTML":true,
"[[\"stylewithcss\",\"false\"],[\"strikethrough\",\"\"]] \"fo[o<s>bar</s>b]az\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"strikethrough\",\"\"]] \"foo[<s>b]ar</s>baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"strikethrough\",\"\"]] \"foo<s>ba[r</s>]baz\" compare innerHTML":true,
"[[\"stylewithcss\",\"true\"],[\"strikethrough\",\"\"]] \"<strike>fo[o</strike><s>b]ar</s>\" compare innerHTML":true,

Просмотреть файл

@ -3878,6 +3878,20 @@ nsHTMLEditor::SelectAll()
// this will NOT find aAttribute unless aAttribute has a non-null value
// so singleton attributes like <Table border> will not be matched!
bool nsHTMLEditor::IsTextPropertySetByContent(nsIContent* aContent,
nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString* aValue,
nsAString* outValue)
{
MOZ_ASSERT(aContent && aProperty);
MOZ_ASSERT_IF(aAttribute, aValue);
bool isSet;
IsTextPropertySetByContent(aContent->AsDOMNode(), aProperty, aAttribute,
aValue, isSet, outValue);
return isSet;
}
void nsHTMLEditor::IsTextPropertySetByContent(nsIDOMNode *aNode,
nsIAtom *aProperty,
const nsAString *aAttribute,

Просмотреть файл

@ -504,7 +504,15 @@ protected:
* May be null. Ignored if aAttribute is null.
* @param aIsSet [OUT] true if <aProperty aAttribute=aValue> effects aNode.
* @param outValue [OUT] the value of the attribute, if aIsSet is true
*
* The nsIContent variant returns aIsSet instead of using an out parameter.
*/
bool IsTextPropertySetByContent(nsIContent* aContent,
nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString* aValue,
nsAString* outValue = nsnull);
void IsTextPropertySetByContent(nsIDOMNode* aNode,
nsIAtom* aProperty,
const nsAString* aAttribute,

Просмотреть файл

@ -435,6 +435,18 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode,
return NS_OK;
}
// don't need to do anything if property already set on node
if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty,
aAttribute, aValue)) {
if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(
aNode, aProperty, aAttribute, *aValue, COMPUTED_STYLE_TYPE)) {
return NS_OK;
}
} else if (IsTextPropertySetByContent(aNode, aProperty,
aAttribute, aValue)) {
return NS_OK;
}
bool useCSS = (IsCSSEnabled() &&
mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty,
aAttribute, aValue)) ||

Просмотреть файл

@ -78,6 +78,7 @@ _TEST_FILES = \
file_select_all_without_body.html \
test_root_element_replacement.html \
test_bug738366.html \
test_bug757371.html \
$(NULL)
ifneq (mobile,$(MOZ_BUILD_APP))

Просмотреть файл

@ -0,0 +1,26 @@
<!DOCTYPE html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=757371
-->
<title>Test for Bug 757371</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=757371">Mozilla Bug 757371</a>
<div contenteditable></div>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
var div = document.querySelector("div");
div.focus();
getSelection().collapse(div, 0);
document.execCommand("bold");
sendString("ab");
sendKey("BACK_SPACE");
sendChar("b");
is(div.innerHTML, "<b>ab</b>");
SimpleTest.finish();
});
</script>