Bug 317093 part 3 - Clean up nsHTMLEditor::GetInlinePropertyBase; r=ehsan

This commit is contained in:
Aryeh Gregor 2012-04-18 17:26:02 +03:00
Родитель fc783fb0a6
Коммит 2b66dee706
1 изменённых файлов: 93 добавлений и 107 удалений

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

@ -958,25 +958,25 @@ bool nsHTMLEditor::IsAtEndOfNode(nsIDOMNode *aNode, PRInt32 aOffset)
nsresult
nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
const nsAString *aAttribute,
const nsAString *aValue,
bool *aFirst,
bool *aAny,
bool *aAll,
nsAString *outValue,
bool aCheckDefaults)
const nsAString *aAttribute,
const nsAString *aValue,
bool *aFirst,
bool *aAny,
bool *aAll,
nsAString *outValue,
bool aCheckDefaults)
{
NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
nsresult result;
*aAny=false;
*aAll=true;
*aFirst=false;
bool first=true;
*aAny = false;
*aAll = true;
*aFirst = false;
bool first = true;
bool useCSS = IsCSSEnabled();
nsCOMPtr<nsISelection>selection;
nsCOMPtr<nsISelection> selection;
result = GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(result, result);
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
@ -995,28 +995,26 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
result = enumerator->CurrentItem(getter_AddRefs(currentItem));
// XXX: should be a while loop, to get each separate range
// XXX: ERROR_HANDLING can currentItem be null?
if ((NS_SUCCEEDED(result)) && currentItem)
{
if (NS_SUCCEEDED(result) && currentItem) {
bool firstNodeInRange = true; // for each range, set a flag
nsCOMPtr<nsIDOMRange> range(do_QueryInterface(currentItem));
if (isCollapsed)
{
if (isCollapsed) {
range->GetStartContainer(getter_AddRefs(collapsedNode));
NS_ENSURE_TRUE(collapsedNode, NS_ERROR_FAILURE);
bool isSet, theSetting;
if (aAttribute)
{
if (aAttribute) {
nsString tString(*aAttribute); //MJUDGE SCC NEED HELP
nsString tOutString;//MJUDGE SCC NEED HELP
mTypeInState->GetTypingState(isSet, theSetting, aProperty, tString, &tOutString);
if (outValue)
nsString tOutString; //MJUDGE SCC NEED HELP
mTypeInState->GetTypingState(isSet, theSetting, aProperty, tString,
&tOutString);
if (outValue) {
outValue->Assign(tOutString);
}
else
}
} else {
mTypeInState->GetTypingState(isSet, theSetting, aProperty);
if (isSet)
{
}
if (isSet) {
*aFirst = *aAny = *aAll = theSetting;
return NS_OK;
}
@ -1026,17 +1024,18 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
isSet, getter_AddRefs(resultNode), outValue);
*aFirst = *aAny = *aAll = isSet;
if (!isSet && aCheckDefaults)
{
// style not set, but if it is a default then it will appear if
// content is inserted, so we should report it as set (analogous to TypeInState).
if (!isSet && aCheckDefaults) {
// style not set, but if it is a default then it will appear if
// content is inserted, so we should report it as set (analogous to
// TypeInState).
PRInt32 index;
if (aAttribute &&
TypeInState::FindPropInList(aProperty, *aAttribute, outValue, mDefaultStyles, index))
{
if (aAttribute && TypeInState::FindPropInList(aProperty, *aAttribute,
outValue, mDefaultStyles,
index)) {
*aFirst = *aAny = *aAll = true;
if (outValue)
if (outValue) {
outValue->Assign(mDefaultStyles[index]->value);
}
}
}
return NS_OK;
@ -1048,7 +1047,6 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
do_CreateInstance("@mozilla.org/content/post-content-iterator;1");
NS_ENSURE_TRUE(iter, NS_ERROR_NULL_POINTER);
iter->Init(range);
nsAutoString firstValue, theValue;
nsCOMPtr<nsIDOMNode> endNode;
@ -1057,106 +1055,94 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
NS_ENSURE_SUCCESS(result, result);
result = range->GetEndOffset(&endOffset);
NS_ENSURE_SUCCESS(result, result);
while (!iter->IsDone())
{
nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
for (iter->Init(range); !iter->IsDone(); iter->Next()) {
nsCOMPtr<nsIContent> content = do_QueryInterface(iter->GetCurrentNode());
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(content);
if (node && nsTextEditUtils::IsBody(node))
if (node && nsTextEditUtils::IsBody(node)) {
break;
}
nsCOMPtr<nsIDOMCharacterData>text;
nsCOMPtr<nsIDOMCharacterData> text;
text = do_QueryInterface(content);
bool skipNode = false;
// just ignore any non-editable nodes
if (text && !IsEditable(text))
{
skipNode = true;
if (text && !IsEditable(text)) {
continue;
}
else if (text)
{
if (!isCollapsed && first && firstNodeInRange)
{
if (text) {
if (!isCollapsed && first && firstNodeInRange) {
firstNodeInRange = false;
PRInt32 startOffset;
range->GetStartOffset(&startOffset);
PRUint32 count;
text->GetLength(&count);
if (startOffset==(PRInt32)count)
{
skipNode = true;
if (startOffset == (PRInt32)count) {
continue;
}
} else if (node == endNode && !endOffset) {
continue;
}
else if (node == endNode && !endOffset)
{
skipNode = true;
}
} else if (content->IsElement()) {
// handle non-text leaf nodes here
continue;
}
else if (content->IsElement())
{ // handle non-text leaf nodes here
skipNode = true;
}
if (!skipNode)
{
if (node)
{
bool isSet = false;
nsCOMPtr<nsIDOMNode>resultNode;
if (first)
{
if (useCSS &&
mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) {
// 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);
if (node) {
bool isSet = false;
nsCOMPtr<nsIDOMNode> resultNode;
if (first) {
if (useCSS &&
mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) {
// 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);
}
else {
IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet,
getter_AddRefs(resultNode), &firstValue);
}
*aFirst = isSet;
first = false;
if (outValue) *outValue = firstValue;
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute,
isSet, firstValue,
COMPUTED_STYLE_TYPE);
} else {
IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet,
getter_AddRefs(resultNode), &firstValue);
}
else
{
if (useCSS &&
mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) {
// 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,
getter_AddRefs(resultNode), &theValue);
}
if (firstValue != theValue)
*aAll = false;
*aFirst = isSet;
first = false;
if (outValue) {
*outValue = firstValue;
}
if (isSet) {
*aAny = true;
} else {
if (useCSS &&
mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) {
// 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,
getter_AddRefs(resultNode), &theValue);
}
else {
if (firstValue != theValue) {
*aAll = false;
}
}
if (isSet) {
*aAny = true;
} else {
*aAll = false;
}
}
iter->Next();
}
}
if (!*aAny)
{ // make sure that if none of the selection is set, we don't report all is set
if (!*aAny) {
// make sure that if none of the selection is set, we don't report all is
// set
*aAll = false;
}
return result;