Bug 763283 part 2 - Use nsINode::AsContent() in editor/; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-06-10 15:39:21 +03:00
parent bd2dec6adf
commit 24223d582e
5 changed files with 94 additions and 82 deletions

View File

@ -327,7 +327,7 @@ nsEditor::InstallEventListeners()
NS_ERROR_NOT_INITIALIZED);
// Initialize the event target.
nsCOMPtr<nsIContent> rootContent = do_QueryInterface(GetRoot());
nsCOMPtr<nsIContent> rootContent = GetRoot();
NS_ENSURE_TRUE(rootContent, NS_ERROR_NOT_AVAILABLE);
mEventTarget = do_QueryInterface(rootContent->GetParent());
NS_ENSURE_TRUE(mEventTarget, NS_ERROR_NOT_AVAILABLE);
@ -1938,8 +1938,9 @@ NS_IMETHODIMP
nsEditor::DumpContentTree()
{
#ifdef DEBUG
nsCOMPtr<nsIContent> root = do_QueryInterface(mRootElement);
if (root) root->List(stdout);
if (mRootElement) {
mRootElement->List(stdout);
}
#endif
return NS_OK;
}
@ -2139,7 +2140,7 @@ nsEditor::GetPreferredIMEState(IMEState *aState)
return NS_OK;
}
nsCOMPtr<nsIContent> content = do_QueryInterface(GetRoot());
nsCOMPtr<nsIContent> content = GetRoot();
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
nsIFrame* frame = content->GetPrimaryFrame();

View File

@ -2382,10 +2382,12 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
// If something visible is deleted, no need to join.
// Visible means all nodes except non-visible textnodes and breaks.
if (join && origCollapsed) {
nsCOMPtr<nsIContent> content = do_QueryInterface(somenode);
if (!content) {
if (!somenode->IsContent()) {
join = false;
} else if (content->NodeType() == nsIDOMNode::TEXT_NODE) {
continue;
}
nsCOMPtr<nsIContent> content = somenode->AsContent();
if (content->NodeType() == nsIDOMNode::TEXT_NODE) {
mHTMLEditor->IsVisTextNode(content, &join, true);
} else {
join = content->IsHTML(nsGkAtoms::br) &&

View File

@ -361,16 +361,17 @@ nsHTMLEditor::FindSelectionRoot(nsINode *aNode)
aNode->IsNodeOfType(nsINode::eCONTENT),
"aNode must be content or document node");
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
nsCOMPtr<nsIDocument> doc = aNode->GetCurrentDoc();
if (!doc) {
return nsnull;
}
if (doc->HasFlag(NODE_IS_EDITABLE) || !content) {
nsCOMPtr<nsIContent> content;
if (doc->HasFlag(NODE_IS_EDITABLE) || !aNode->IsContent()) {
content = doc->GetRootElement();
return content.forget();
}
content = aNode->AsContent();
// XXX If we have readonly flag, shouldn't return the element which has
// contenteditable="true"? However, such case isn't there without chrome
@ -3396,8 +3397,8 @@ nsHTMLEditor::DeleteSelectionImpl(EDirection aAction,
NS_ENSURE_STATE(selection->GetAnchorFocusRange());
NS_ENSURE_STATE(selection->GetAnchorFocusRange()->Collapsed());
nsCOMPtr<nsIContent> content = do_QueryInterface(selection->GetAnchorNode());
NS_ENSURE_STATE(content);
NS_ENSURE_STATE(selection->GetAnchorNode()->IsContent());
nsCOMPtr<nsIContent> content = selection->GetAnchorNode()->AsContent();
// Don't strip wrappers if this is the only wrapper in the block. Then we'll
// add a <br> later, so it won't be an empty wrapper in the end.

View File

@ -1177,10 +1177,13 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
NS_ENSURE_SUCCESS(result, result);
for (iter->Init(range); !iter->IsDone(); iter->Next()) {
nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(content);
if (!iter->GetCurrentNode()->IsContent()) {
continue;
}
nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->AsContent();
nsCOMPtr<nsIDOMNode> node = content->AsDOMNode();
if (node && nsTextEditUtils::IsBody(node)) {
if (nsTextEditUtils::IsBody(node)) {
break;
}
@ -1208,61 +1211,60 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
// handle non-text leaf nodes here
continue;
}
if (node) {
bool isSet = false;
if (first) {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
aAttribute) &&
// Bug 747889: we don't support CSS for fontSize values
(aProperty != nsEditProperty::font ||
!aAttribute->EqualsLiteral("size"))) {
// the HTML styles defined by aProperty/aAttribute has a CSS
// equivalence in this implementation for node; let's check if it
// carries those css styles
if (aValue) {
firstValue.Assign(*aValue);
}
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute,
isSet, firstValue,
COMPUTED_STYLE_TYPE);
} else {
IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet,
&firstValue);
}
*aFirst = isSet;
first = false;
if (outValue) {
*outValue = firstValue;
bool isSet = false;
if (first) {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
aAttribute) &&
// Bug 747889: we don't support CSS for fontSize values
(aProperty != nsEditProperty::font ||
!aAttribute->EqualsLiteral("size"))) {
// the HTML styles defined by aProperty/aAttribute has a CSS
// equivalence in this implementation for node; let's check if it
// carries those css styles
if (aValue) {
firstValue.Assign(*aValue);
}
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute,
isSet, firstValue,
COMPUTED_STYLE_TYPE);
} else {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
aAttribute) &&
// Bug 747889: we don't support CSS for fontSize values
(aProperty != nsEditProperty::font ||
!aAttribute->EqualsLiteral("size"))) {
// the HTML styles defined by aProperty/aAttribute has a CSS equivalence
// in this implementation for node; let's check if it carries those css styles
if (aValue) {
theValue.Assign(*aValue);
}
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute,
isSet, theValue,
COMPUTED_STYLE_TYPE);
} else {
IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet,
&theValue);
}
if (firstValue != theValue) {
*aAll = false;
}
IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet,
&firstValue);
}
if (isSet) {
*aAny = true;
*aFirst = isSet;
first = false;
if (outValue) {
*outValue = firstValue;
}
} else {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
aAttribute) &&
// Bug 747889: we don't support CSS for fontSize values
(aProperty != nsEditProperty::font ||
!aAttribute->EqualsLiteral("size"))) {
// the HTML styles defined by aProperty/aAttribute has a CSS equivalence
// in this implementation for node; let's check if it carries those css styles
if (aValue) {
theValue.Assign(*aValue);
}
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute,
isSet, theValue,
COMPUTED_STYLE_TYPE);
} else {
IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet,
&theValue);
}
if (firstValue != theValue) {
*aAll = false;
}
}
if (isSet) {
*aAny = true;
} else {
*aAll = false;
}
}
}
if (!*aAny) {
@ -1621,8 +1623,8 @@ nsHTMLEditor::RelativeFontChange( PRInt32 aSizeChange)
if (NS_SUCCEEDED(res)) {
nsCOMArray<nsIContent> arrayOfNodes;
while (!iter->IsDone()) {
nsCOMPtr<nsIContent> node = do_QueryInterface(iter->GetCurrentNode());
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(iter->GetCurrentNode()->IsContent(), NS_ERROR_FAILURE);
nsCOMPtr<nsIContent> node = iter->GetCurrentNode()->AsContent();
if (IsEditable(node)) {
arrayOfNodes.AppendObject(node);

View File

@ -785,13 +785,11 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus,
while (!iter->IsDone())
{
nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
if (IsTextNode(content))
{
if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) {
// We found a text node, so position the document's
// iterator at the beginning of the block, then get
// the selection in terms of the string offset.
nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->AsContent();
result = mIterator->PositionAt(content);
@ -910,12 +908,10 @@ nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus,
while (!iter->IsDone())
{
nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
if (IsTextNode(content))
{
if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) {
// We found a text node! Adjust the document's iterator to point
// to the beginning of its text block, then get the current selection.
nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->AsContent();
result = mIterator->PositionAt(content);
@ -1377,13 +1373,13 @@ nsTextServicesDocument::DeleteSelection()
nsCOMPtr<nsIContent> curContent;
if (mIteratorStatus != nsTextServicesDocument::eIsDone)
{
if (mIteratorStatus != nsTextServicesDocument::eIsDone &&
mIterator->GetCurrentNode()->IsContent()) {
// The old iterator is still pointing to something valid,
// so get its current node so we can restore it after we
// create the new iterator!
curContent = do_QueryInterface(mIterator->GetCurrentNode());
curContent = mIterator->GetCurrentNode()->AsContent();
}
// Create the new iterator.
@ -2674,8 +2670,8 @@ nsTextServicesDocument::GetCollapsedSelection(nsITextServicesDocument::TSDBlockS
} else {
// The parent has no children, so position the iterator
// on the parent.
nsCOMPtr<nsIContent> content = do_QueryInterface(parent);
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(parent->IsContent(), NS_ERROR_FAILURE);
nsCOMPtr<nsIContent> content = parent->AsContent();
result = iter->PositionAt(content);
NS_ENSURE_SUCCESS(result, result);
@ -3160,7 +3156,9 @@ nsTextServicesDocument::FirstTextNodeInCurrentBlock(nsIContentIterator *iter)
while (!iter->IsDone())
{
nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->IsContent()
? iter->GetCurrentNode()->AsContent()
: nsnull;
if (IsTextNode(content))
{
@ -3231,7 +3229,9 @@ nsTextServicesDocument::FirstTextNodeInNextBlock(nsIContentIterator *aIterator)
while (!aIterator->IsDone())
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aIterator->GetCurrentNode());
nsCOMPtr<nsIContent> content = aIterator->GetCurrentNode()->IsContent()
? aIterator->GetCurrentNode()->AsContent()
: nsnull;
if (IsTextNode(content))
{
@ -3277,7 +3277,9 @@ nsTextServicesDocument::GetFirstTextNodeInPrevBlock(nsIContent **aContent)
if (!mIterator->IsDone())
{
nsCOMPtr<nsIContent> current = do_QueryInterface(mIterator->GetCurrentNode());
nsCOMPtr<nsIContent> current = mIterator->GetCurrentNode()->IsContent()
? mIterator->GetCurrentNode()->AsContent()
: nsnull;
current.forget(aContent);
}
@ -3311,7 +3313,9 @@ nsTextServicesDocument::GetFirstTextNodeInNextBlock(nsIContent **aContent)
if (!mIterator->IsDone())
{
nsCOMPtr<nsIContent> current = do_QueryInterface(mIterator->GetCurrentNode());
nsCOMPtr<nsIContent> current = mIterator->GetCurrentNode()->IsContent()
? mIterator->GetCurrentNode()->AsContent()
: nsnull;
current.forget(aContent);
}
@ -3371,7 +3375,9 @@ nsTextServicesDocument::CreateOffsetTable(nsTArray<OffsetEntry*> *aOffsetTable,
while (!aIterator->IsDone())
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aIterator->GetCurrentNode());
nsCOMPtr<nsIContent> content = aIterator->GetCurrentNode()->IsContent()
? aIterator->GetCurrentNode()->AsContent()
: nsnull;
if (IsTextNode(content))
{