mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 722416 - Outparamdel nsHTMLCSSUtils::GetElementContainerOrSelf; r=ehsan
This commit is contained in:
parent
fc183b211f
commit
a8ca0f92e2
@ -541,9 +541,8 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty,
|
|||||||
aValue.Truncate();
|
aValue.Truncate();
|
||||||
NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
|
NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMElement> element;
|
nsCOMPtr<nsIDOMElement> element = GetElementContainerOrSelf(aNode);
|
||||||
nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element));
|
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
|
|
||||||
switch (aStyleType) {
|
switch (aStyleType) {
|
||||||
case COMPUTED_STYLE_TYPE:
|
case COMPUTED_STYLE_TYPE:
|
||||||
@ -552,7 +551,7 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty,
|
|||||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
||||||
aProperty->ToString(propString);
|
aProperty->ToString(propString);
|
||||||
// Get the all the computed css styles attached to the element node
|
// Get the all the computed css styles attached to the element node
|
||||||
res = aWindow->GetComputedStyle(element, EmptyString(), getter_AddRefs(cssDecl));
|
nsresult res = aWindow->GetComputedStyle(element, EmptyString(), getter_AddRefs(cssDecl));
|
||||||
if (NS_FAILED(res) || !cssDecl)
|
if (NS_FAILED(res) || !cssDecl)
|
||||||
return res;
|
return res;
|
||||||
// from these declarations, get the one we want and that one only
|
// from these declarations, get the one we want and that one only
|
||||||
@ -565,7 +564,7 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty,
|
|||||||
if (element) {
|
if (element) {
|
||||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
||||||
PRUint32 length;
|
PRUint32 length;
|
||||||
res = GetInlineStyles(element, getter_AddRefs(cssDecl), &length);
|
nsresult res = GetInlineStyles(element, getter_AddRefs(cssDecl), &length);
|
||||||
if (NS_FAILED(res) || !cssDecl) return res;
|
if (NS_FAILED(res) || !cssDecl) return res;
|
||||||
nsAutoString value, propString;
|
nsAutoString value, propString;
|
||||||
aProperty->ToString(propString);
|
aProperty->ToString(propString);
|
||||||
@ -581,9 +580,8 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty,
|
|||||||
nsresult
|
nsresult
|
||||||
nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMWindow **aViewCSS)
|
nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMWindow **aViewCSS)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIDOMElement> element;
|
nsCOMPtr<nsIDOMElement> element = GetElementContainerOrSelf(aNode);
|
||||||
nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element));
|
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
|
|
||||||
// TODO: move this initialization to the top of the function
|
// TODO: move this initialization to the top of the function
|
||||||
*aViewCSS = nsnull;
|
*aViewCSS = nsnull;
|
||||||
@ -593,7 +591,7 @@ nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMWindow **aViewCSS)
|
|||||||
// find the owner document
|
// find the owner document
|
||||||
nsCOMPtr<nsIDOMDocument> doc;
|
nsCOMPtr<nsIDOMDocument> doc;
|
||||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
|
||||||
res = node->GetOwnerDocument(getter_AddRefs(doc));
|
nsresult res = node->GetOwnerDocument(getter_AddRefs(doc));
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@ -1013,16 +1011,15 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
|
|||||||
PRUint8 aStyleType)
|
PRUint8 aStyleType)
|
||||||
{
|
{
|
||||||
aValueString.Truncate();
|
aValueString.Truncate();
|
||||||
nsCOMPtr<nsIDOMElement> theElement;
|
nsCOMPtr<nsIDOMElement> theElement = GetElementContainerOrSelf(aNode);
|
||||||
nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(theElement));
|
NS_ENSURE_TRUE(theElement, NS_ERROR_NULL_POINTER);
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
|
|
||||||
if (theElement && IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
|
if (theElement && IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
|
||||||
// Yes, the requested HTML style has a CSS equivalence in this implementation
|
// Yes, the requested HTML style has a CSS equivalence in this implementation
|
||||||
// Retrieve the default ViewCSS if we are asked for computed styles
|
// Retrieve the default ViewCSS if we are asked for computed styles
|
||||||
nsCOMPtr<nsIDOMWindow> window;
|
nsCOMPtr<nsIDOMWindow> window;
|
||||||
if (COMPUTED_STYLE_TYPE == aStyleType) {
|
if (COMPUTED_STYLE_TYPE == aStyleType) {
|
||||||
res = GetDefaultViewCSS(theElement, getter_AddRefs(window));
|
nsresult res = GetDefaultViewCSS(theElement, getter_AddRefs(window));
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
}
|
}
|
||||||
nsTArray<nsIAtom*> cssPropertyArray;
|
nsTArray<nsIAtom*> cssPropertyArray;
|
||||||
@ -1036,8 +1033,8 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
|
|||||||
for (index = 0; index < count; index++) {
|
for (index = 0; index < count; index++) {
|
||||||
nsAutoString valueString;
|
nsAutoString valueString;
|
||||||
// retrieve the specified/computed value of the property
|
// retrieve the specified/computed value of the property
|
||||||
res = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index],
|
nsresult res = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index],
|
||||||
valueString, window, aStyleType);
|
valueString, window, aStyleType);
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
NS_ENSURE_SUCCESS(res, res);
|
||||||
// append the value to aValueString (possibly with a leading whitespace)
|
// append the value to aValueString (possibly with a leading whitespace)
|
||||||
if (index) aValueString.Append(PRUnichar(' '));
|
if (index) aValueString.Append(PRUnichar(' '));
|
||||||
@ -1324,37 +1321,25 @@ nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement *aElement,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
already_AddRefed<nsIDOMElement>
|
||||||
nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode * aNode, nsIDOMElement ** aElement)
|
nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode* aNode)
|
||||||
{
|
{
|
||||||
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
||||||
|
NS_ENSURE_TRUE(node, nsnull);
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> node=aNode, parentNode;
|
if (nsIDOMNode::DOCUMENT_NODE == node->NodeType()) {
|
||||||
PRUint16 type;
|
return nsnull;
|
||||||
nsresult res;
|
|
||||||
res = node->GetNodeType(&type);
|
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
|
|
||||||
if (nsIDOMNode::DOCUMENT_NODE == type) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop until we find an element
|
// Loop until we find an element.
|
||||||
while (node && nsIDOMNode::ELEMENT_NODE != type) {
|
while (node && !node->IsElement()) {
|
||||||
parentNode = node;
|
node = node->GetNodeParent();
|
||||||
res = parentNode->GetParentNode(getter_AddRefs(node));
|
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
if (node) {
|
|
||||||
res = node->GetNodeType(&type);
|
|
||||||
NS_ENSURE_SUCCESS(res, res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
NS_ASSERTION(node, "we reached a null node ancestor !");
|
|
||||||
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
|
NS_ENSURE_TRUE(node, nsnull);
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
|
||||||
(*aElement) = element;
|
return element.forget();
|
||||||
NS_IF_ADDREF(*aElement);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
@ -299,7 +299,7 @@ public:
|
|||||||
* @param aNode [IN] a node
|
* @param aNode [IN] a node
|
||||||
* @param aElement [OUT] the deepest element node containing aNode (possibly aNode itself)
|
* @param aElement [OUT] the deepest element node containing aNode (possibly aNode itself)
|
||||||
*/
|
*/
|
||||||
nsresult GetElementContainerOrSelf(nsIDOMNode * aNode, nsIDOMElement ** aElement);
|
already_AddRefed<nsIDOMElement> GetElementContainerOrSelf(nsIDOMNode* aNode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the default Window for a given node.
|
* Gets the default Window for a given node.
|
||||||
|
Loading…
Reference in New Issue
Block a user