Bug 279330 part 2 - execCommand("hilitecolor") should work even in non-CSS mode; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-04-17 13:18:08 +03:00
parent b6e35957b0
commit 1cd223ec12
6 changed files with 386 additions and 405 deletions

View File

@ -914,8 +914,8 @@ nsHighlightColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState)
// rv = RemoveOneProperty(htmlEditor, NS_LITERAL_STRING("font"), NS_LITERAL_STRING("bgcolor"));
rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor"));
} else {
rv = htmlEditor->SetCSSInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor"),
newState);
rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor"),
newState);
}
return rv;

View File

@ -52,7 +52,7 @@ interface nsIContentFilter;
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_EDITOR, 1)
%}
[scriptable, uuid(FF67AD39-ED58-4CD1-A1A3-DCD988390A97)]
[scriptable, uuid(833f30de-94c7-4630-a852-2300ef329d7b)]
interface nsIHTMLEditor : nsISupports
{
@ -118,9 +118,6 @@ interface nsIHTMLEditor : nsISupports
* Example: aProperty="font", aAttribute="color",
* aValue="0x00FFFF"
*/
void setCSSInlineProperty(in nsIAtom aProperty,
in AString aAttribute,
in AString aValue);
void setInlineProperty(in nsIAtom aProperty,
in AString aAttribute,
in AString aValue);

View File

@ -109,18 +109,6 @@ NS_IMETHODIMP nsHTMLEditor::RemoveAllDefaultProperties()
}
// Add the CSS style corresponding to the HTML inline style defined
// by aProperty aAttribute and aValue to the selection
NS_IMETHODIMP nsHTMLEditor::SetCSSInlineProperty(nsIAtom *aProperty,
const nsAString & aAttribute,
const nsAString & aValue)
{
if (IsCSSEnabled()) {
return SetInlineProperty(aProperty, aAttribute, aValue);
}
return NS_OK;
}
NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty,
const nsAString & aAttribute,
const nsAString & aValue)
@ -385,60 +373,58 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode,
nsAutoString tag;
aProperty->ToString(tag);
ToLowerCase(tag);
if (IsCSSEnabled())
{
// we are in CSS mode
if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute))
{
// the HTML style defined by aProperty/aAttribute has a CSS equivalence
// in this implementation for the node aNode
nsCOMPtr<nsIDOMNode> tmp = aNode;
if (IsTextNode(tmp))
{
// we are working on a text node and need to create a span container
// that will carry the styles
InsertContainerAbove( aNode,
address_of(tmp),
NS_LITERAL_STRING("span"),
nsnull,
nsnull);
}
nsCOMPtr<nsIDOMElement>element;
element = do_QueryInterface(tmp);
// first we have to remove occurences of the same style hint in the
// children of the aNode
res = RemoveStyleInside(tmp, aProperty, aAttribute, true);
NS_ENSURE_SUCCESS(res, res);
PRInt32 count;
// then we add the css styles corresponding to the HTML style request
res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, aProperty, aAttribute, aValue, &count, false);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> nextSibling, previousSibling;
GetNextHTMLSibling(tmp, address_of(nextSibling));
GetPriorHTMLSibling(tmp, address_of(previousSibling));
if (nextSibling || previousSibling)
{
nsCOMPtr<nsIDOMNode> mergeParent;
res = tmp->GetParentNode(getter_AddRefs(mergeParent));
NS_ENSURE_SUCCESS(res, res);
if (previousSibling &&
nsEditor::NodeIsType(previousSibling, nsEditProperty::span) &&
NodesSameType(tmp, previousSibling))
{
res = JoinNodes(previousSibling, tmp, mergeParent);
NS_ENSURE_SUCCESS(res, res);
}
if (nextSibling &&
nsEditor::NodeIsType(nextSibling, nsEditProperty::span) &&
NodesSameType(tmp, nextSibling))
{
res = JoinNodes(tmp, nextSibling, mergeParent);
}
}
return res;
bool useCSS = (IsCSSEnabled() &&
mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute)) ||
// bgcolor is always done using CSS
aAttribute->EqualsLiteral("bgcolor");
if (useCSS) {
nsCOMPtr<nsIDOMNode> tmp = aNode;
if (IsTextNode(tmp))
{
// we are working on a text node and need to create a span container
// that will carry the styles
InsertContainerAbove(aNode,
address_of(tmp),
NS_LITERAL_STRING("span"),
nsnull,
nsnull);
}
nsCOMPtr<nsIDOMElement>element;
element = do_QueryInterface(tmp);
// first we have to remove occurences of the same style hint in the
// children of the aNode
res = RemoveStyleInside(tmp, aProperty, aAttribute, true);
NS_ENSURE_SUCCESS(res, res);
PRInt32 count;
// then we add the css styles corresponding to the HTML style request
res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(element, aProperty, aAttribute, aValue, &count, false);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> nextSibling, previousSibling;
GetNextHTMLSibling(tmp, address_of(nextSibling));
GetPriorHTMLSibling(tmp, address_of(previousSibling));
if (nextSibling || previousSibling)
{
nsCOMPtr<nsIDOMNode> mergeParent;
res = tmp->GetParentNode(getter_AddRefs(mergeParent));
NS_ENSURE_SUCCESS(res, res);
if (previousSibling &&
nsEditor::NodeIsType(previousSibling, nsEditProperty::span) &&
NodesSameType(tmp, previousSibling))
{
res = JoinNodes(previousSibling, tmp, mergeParent);
NS_ENSURE_SUCCESS(res, res);
}
if (nextSibling &&
nsEditor::NodeIsType(nextSibling, nsEditProperty::span) &&
NodesSameType(tmp, nextSibling))
{
res = JoinNodes(tmp, nextSibling, mergeParent);
}
}
return res;
}
// don't need to do anything if property already set on node

View File

@ -22,7 +22,6 @@ var knownFailures = {
'backcolor-1' : true,
'createbookmark-0' : true,
'fontsize-1' : true,
'hilitecolor-0' : true,
'subscript-1' : true,
'superscript-1' : true,
},

View File

@ -6,7 +6,7 @@
var text = '<html><head></head><body style="font-size:16px;">'
+ '<p id="redpar">This paragraph should be red</p>'
+ '<p id="bluepar">This paragraph should be blue</p>'
+ '<p id="normalpar">This paragraph should not be colored</p>'
+ '<p>This paragraph should not be colored</p>'
+'</body></html>';
@ -28,11 +28,10 @@ function initIFrame() {
// Test hilighting with styleWithCSS, should hilight the text...
doc.execCommand("styleWithCSS", false, true);
colorPar("redpar", "red");
colorPar("bluepar", "blue");
// Test highlighting without styleWithCSS, should do nothing.
// Test highlighting without styleWithCSS, should also work.
doc.execCommand("styleWithCSS", false, false);
colorPar("normalpar", "red");
colorPar("bluepar", "blue");
}
</script>