mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Styles were not preserved in Composer when creating a new list item, hitting twice the Return Key
The inline styles (B I U ..) hierarchy of elements had to be recreated in the new list item. b=46474; r=jfrancis; sr=kin; a=asa
This commit is contained in:
parent
0f7cfff93f
commit
ba2410c1c7
@ -5976,7 +5976,7 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection,
|
||||
if (NS_FAILED(res)) return res;
|
||||
// now split list item
|
||||
PRInt32 newOffset;
|
||||
res = mHTMLEditor->SplitNodeDeep( aListItem, selNode, aOffset, &newOffset);
|
||||
res = mHTMLEditor->SplitNodeDeep( aListItem, selNode, aOffset, &newOffset, PR_FALSE);
|
||||
if (NS_FAILED(res)) return res;
|
||||
// hack: until I can change the damaged doc range code back to being
|
||||
// extra inclusive, I have to manually detect certain list items that
|
||||
@ -5994,6 +5994,21 @@ nsHTMLEditRules::ReturnInListItem(nsISelection *aSelection,
|
||||
res = CreateMozBR(prevItem, 0, address_of(brNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
else {
|
||||
res = mHTMLEditor->IsEmptyNode(aListItem, &bIsEmptyNode, PR_TRUE);
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (bIsEmptyNode) {
|
||||
nsCOMPtr<nsIDOMNode> brNode;
|
||||
res = mHTMLEditor->CopyLastEditableChildStyles(prevItem, aListItem, getter_AddRefs(brNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (brNode) {
|
||||
nsCOMPtr<nsIDOMNode> brParent;
|
||||
PRInt32 offset;
|
||||
res = nsEditor::GetNodeLocation(brNode, address_of(brParent), &offset);
|
||||
return aSelection->Collapse(brParent, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res = aSelection->Collapse(aListItem,0);
|
||||
return res;
|
||||
|
@ -5353,3 +5353,70 @@ nsHTMLEditor::ParseStyleAttrIntoCSSRule(const PRUnichar *aString, nsIDOMCSSStyle
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNode * aNewBlock,
|
||||
nsIDOMNode **aOutBrNode)
|
||||
{
|
||||
*aOutBrNode = nsnull;
|
||||
nsCOMPtr<nsIDOMNode> child = aPreviousBlock, tmp = aPreviousBlock;
|
||||
nsresult res;
|
||||
while (tmp) {
|
||||
child = tmp;
|
||||
res = GetLastEditableChild(child, address_of(tmp));
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
while (child && nsTextEditUtils::IsBreak(child)) {
|
||||
nsCOMPtr<nsIDOMNode> priorNode;
|
||||
res = GetPriorHTMLNode(child, address_of(priorNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
child = priorNode;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> newStyles = nsnull, deepestStyle = nsnull;
|
||||
while (child && (child != aPreviousBlock)) {
|
||||
if (nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("a")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("b")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("i")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("u")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("tt")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("s")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("strike")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("big")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("small")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("blink")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("sub")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("sup")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("font")) ||
|
||||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("span"))) {
|
||||
nsAutoString domTagName;
|
||||
child->GetNodeName(domTagName);
|
||||
ToLowerCase(domTagName);
|
||||
if (newStyles) {
|
||||
nsCOMPtr<nsIDOMNode> newContainer;
|
||||
res = InsertContainerAbove(newStyles, address_of(newContainer), domTagName);
|
||||
if (NS_FAILED(res)) return res;
|
||||
newStyles = newContainer;
|
||||
}
|
||||
else {
|
||||
res = CreateNode(domTagName, aNewBlock, 0, getter_AddRefs(newStyles));
|
||||
if (NS_FAILED(res)) return res;
|
||||
deepestStyle = newStyles;
|
||||
}
|
||||
res = CloneAttributes(newStyles, child);
|
||||
if (NS_FAILED(res)) return res;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> tmp;
|
||||
res = child->GetParentNode(getter_AddRefs(tmp));
|
||||
if (NS_FAILED(res)) return res;
|
||||
child = tmp;
|
||||
}
|
||||
if (deepestStyle) {
|
||||
nsCOMPtr<nsIDOMNode> outBRNode;
|
||||
res = CreateBR(deepestStyle, 0, address_of(outBRNode));
|
||||
if (NS_FAILED(res)) return res;
|
||||
// Getters must addref
|
||||
*aOutBrNode = outBRNode;
|
||||
NS_ADDREF(*aOutBrNode);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -119,6 +119,9 @@ public:
|
||||
|
||||
/* ------------ nsIHTMLEditor methods -------------- */
|
||||
|
||||
NS_IMETHOD CopyLastEditableChildStyles(nsIDOMNode *aPreviousBlock, nsIDOMNode *aNewBlock,
|
||||
nsIDOMNode **aOutBrNode);
|
||||
|
||||
NS_IMETHOD ParseStyleAttrIntoCSSRule(const PRUnichar *aString, nsIDOMCSSStyleRule **_retval);
|
||||
|
||||
NS_IMETHOD SetCSSInlineProperty(nsIAtom *aProperty,
|
||||
|
Loading…
Reference in New Issue
Block a user