mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
editor embedding work; fixing bug with making lists
This commit is contained in:
parent
19e6ec7073
commit
658fa56fa3
@ -3454,6 +3454,8 @@ nsEditor::GetNextNode(nsIDOMNode *aParentNode,
|
||||
nsresult result = NS_OK;
|
||||
if (!aParentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
*aResultNode = nsnull;
|
||||
|
||||
// if aParentNode is a text node, use it's location instead
|
||||
if (IsTextNode(aParentNode))
|
||||
{
|
||||
@ -3468,8 +3470,13 @@ nsEditor::GetNextNode(nsIDOMNode *aParentNode,
|
||||
{
|
||||
result = GetLeftmostChild(child, aResultNode);
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (!aEditableNode) return result;
|
||||
if (IsEditable(*aResultNode)) return result;
|
||||
if (IsEditable(*aResultNode)) return result;
|
||||
else
|
||||
{
|
||||
// restart the search from the non-editable node we just found
|
||||
@ -3506,6 +3513,11 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetRightmostChild(prevSibling, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3533,6 +3545,11 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetRightmostChild(node, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3566,6 +3583,11 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetLeftmostChild(nextSibling, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3594,6 +3616,11 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetLeftmostChild(node, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3721,6 +3748,29 @@ nsEditor::TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag
|
||||
return mDTD->CanContain(parentTagEnum, childTagEnum);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsEditor::IsDescendantOfBody(nsIDOMNode *inNode)
|
||||
{
|
||||
if (!inNode) return PR_FALSE;
|
||||
nsCOMPtr<nsIDOMElement> junk;
|
||||
if (!mBodyElement) GetRootElement(getter_AddRefs(junk));
|
||||
if (!mBodyElement) return PR_FALSE;
|
||||
nsCOMPtr<nsIDOMNode> root = do_QueryInterface(mBodyElement);
|
||||
|
||||
if (inNode == root.get()) return PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(inNode);
|
||||
|
||||
do
|
||||
{
|
||||
node->GetParentNode(getter_AddRefs(parent));
|
||||
if (parent == root) return PR_TRUE;
|
||||
node = parent;
|
||||
} while (parent);
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsEditor::IsContainer(nsIDOMNode *aNode)
|
||||
{
|
||||
@ -5425,7 +5475,7 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
||||
nsCOMPtr<nsIDOMNode> nextNode;
|
||||
result = GetNextNode(node, PR_TRUE, getter_AddRefs(nextNode));
|
||||
if ((NS_SUCCEEDED(result)) && nextNode)
|
||||
{ // there is a priorNode, so delete it's last child (if text content, delete the last char.)
|
||||
{ // there is a nextNode, so delete it's first child (if text content, delete the first char.)
|
||||
// if it has no children, delete it
|
||||
nsCOMPtr<nsIDOMCharacterData> nextNodeAsText;
|
||||
nextNodeAsText = do_QueryInterface(nextNode);
|
||||
|
@ -604,6 +604,9 @@ public:
|
||||
PRBool TagCanContain(const nsString &aParentTag, nsIDOMNode* aChild);
|
||||
PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag);
|
||||
|
||||
/** returns PR_TRUE if aNode is a descendant of our root node */
|
||||
PRBool IsDescendantOfBody(nsIDOMNode *inNode);
|
||||
|
||||
/** returns PR_TRUE if aNode is a container */
|
||||
PRBool IsContainer(nsIDOMNode *aNode);
|
||||
|
||||
|
@ -4629,28 +4629,6 @@ nsHTMLEditRules::UpdateDocChangeRange(nsIDOMRange *aRange)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
nsHTMLEditRules::IsDescendantOfBody(nsIDOMNode *inNode)
|
||||
{
|
||||
if (!inNode) return PR_FALSE;
|
||||
if (inNode == mBody.get()) return PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(inNode);
|
||||
nsresult res;
|
||||
|
||||
do
|
||||
{
|
||||
res = node->GetParentNode(getter_AddRefs(parent));
|
||||
if (NS_FAILED(res)) return PR_FALSE;
|
||||
if (parent == mBody) return PR_TRUE;
|
||||
node = parent;
|
||||
} while (parent);
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLEditRules::InsertMozBRIfNeeded(nsIDOMNode *aNode)
|
||||
{
|
||||
|
@ -178,7 +178,6 @@ protected:
|
||||
nsresult ConvertWhitespace(const nsString & inString, nsString & outString);
|
||||
nsresult ConfirmSelectionInBody();
|
||||
|
||||
PRBool IsDescendantOfBody(nsIDOMNode *inNode);
|
||||
nsresult InsertMozBRIfNeeded(nsIDOMNode *aNode);
|
||||
|
||||
// data members
|
||||
|
@ -3454,6 +3454,8 @@ nsEditor::GetNextNode(nsIDOMNode *aParentNode,
|
||||
nsresult result = NS_OK;
|
||||
if (!aParentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
*aResultNode = nsnull;
|
||||
|
||||
// if aParentNode is a text node, use it's location instead
|
||||
if (IsTextNode(aParentNode))
|
||||
{
|
||||
@ -3468,8 +3470,13 @@ nsEditor::GetNextNode(nsIDOMNode *aParentNode,
|
||||
{
|
||||
result = GetLeftmostChild(child, aResultNode);
|
||||
if (NS_FAILED(result)) return result;
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (!aEditableNode) return result;
|
||||
if (IsEditable(*aResultNode)) return result;
|
||||
if (IsEditable(*aResultNode)) return result;
|
||||
else
|
||||
{
|
||||
// restart the search from the non-editable node we just found
|
||||
@ -3506,6 +3513,11 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetRightmostChild(prevSibling, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3533,6 +3545,11 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetRightmostChild(node, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3566,6 +3583,11 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetLeftmostChild(nextSibling, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3594,6 +3616,11 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode,
|
||||
{
|
||||
result = GetLeftmostChild(node, aResultNode);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
if (!IsDescendantOfBody(*aResultNode))
|
||||
{
|
||||
*aResultNode = nsnull;
|
||||
return result;
|
||||
}
|
||||
if (PR_FALSE==aEditableNode) {
|
||||
return result;
|
||||
}
|
||||
@ -3721,6 +3748,29 @@ nsEditor::TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag
|
||||
return mDTD->CanContain(parentTagEnum, childTagEnum);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsEditor::IsDescendantOfBody(nsIDOMNode *inNode)
|
||||
{
|
||||
if (!inNode) return PR_FALSE;
|
||||
nsCOMPtr<nsIDOMElement> junk;
|
||||
if (!mBodyElement) GetRootElement(getter_AddRefs(junk));
|
||||
if (!mBodyElement) return PR_FALSE;
|
||||
nsCOMPtr<nsIDOMNode> root = do_QueryInterface(mBodyElement);
|
||||
|
||||
if (inNode == root.get()) return PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(inNode);
|
||||
|
||||
do
|
||||
{
|
||||
node->GetParentNode(getter_AddRefs(parent));
|
||||
if (parent == root) return PR_TRUE;
|
||||
node = parent;
|
||||
} while (parent);
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsEditor::IsContainer(nsIDOMNode *aNode)
|
||||
{
|
||||
@ -5425,7 +5475,7 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
||||
nsCOMPtr<nsIDOMNode> nextNode;
|
||||
result = GetNextNode(node, PR_TRUE, getter_AddRefs(nextNode));
|
||||
if ((NS_SUCCEEDED(result)) && nextNode)
|
||||
{ // there is a priorNode, so delete it's last child (if text content, delete the last char.)
|
||||
{ // there is a nextNode, so delete it's first child (if text content, delete the first char.)
|
||||
// if it has no children, delete it
|
||||
nsCOMPtr<nsIDOMCharacterData> nextNodeAsText;
|
||||
nextNodeAsText = do_QueryInterface(nextNode);
|
||||
|
@ -604,6 +604,9 @@ public:
|
||||
PRBool TagCanContain(const nsString &aParentTag, nsIDOMNode* aChild);
|
||||
PRBool TagCanContainTag(const nsString &aParentTag, const nsString &aChildTag);
|
||||
|
||||
/** returns PR_TRUE if aNode is a descendant of our root node */
|
||||
PRBool IsDescendantOfBody(nsIDOMNode *inNode);
|
||||
|
||||
/** returns PR_TRUE if aNode is a container */
|
||||
PRBool IsContainer(nsIDOMNode *aNode);
|
||||
|
||||
|
@ -4629,28 +4629,6 @@ nsHTMLEditRules::UpdateDocChangeRange(nsIDOMRange *aRange)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
nsHTMLEditRules::IsDescendantOfBody(nsIDOMNode *inNode)
|
||||
{
|
||||
if (!inNode) return PR_FALSE;
|
||||
if (inNode == mBody.get()) return PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(inNode);
|
||||
nsresult res;
|
||||
|
||||
do
|
||||
{
|
||||
res = node->GetParentNode(getter_AddRefs(parent));
|
||||
if (NS_FAILED(res)) return PR_FALSE;
|
||||
if (parent == mBody) return PR_TRUE;
|
||||
node = parent;
|
||||
} while (parent);
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLEditRules::InsertMozBRIfNeeded(nsIDOMNode *aNode)
|
||||
{
|
||||
|
@ -178,7 +178,6 @@ protected:
|
||||
nsresult ConvertWhitespace(const nsString & inString, nsString & outString);
|
||||
nsresult ConfirmSelectionInBody();
|
||||
|
||||
PRBool IsDescendantOfBody(nsIDOMNode *inNode);
|
||||
nsresult InsertMozBRIfNeeded(nsIDOMNode *aNode);
|
||||
|
||||
// data members
|
||||
|
Loading…
Reference in New Issue
Block a user