Bug 454211 - ISimpleDOMNode functions get_computedStyleForProperties and get_computedStyle functions appear to always return the COM error code 0x80004005 (E_FAIL), r=aaronlev, marcoz

This commit is contained in:
Alexander Surkov 2008-09-17 21:09:34 +08:00
parent b1553e0a7b
commit c0b37d2110
7 changed files with 94 additions and 37 deletions

View File

@ -608,16 +608,17 @@ nsAccessNode::GetChildNodeAt(PRInt32 aChildNum, nsIAccessNode **aAccessNode)
}
NS_IMETHODIMP
nsAccessNode::GetComputedStyleValue(const nsAString& aPseudoElt, const nsAString& aPropertyName, nsAString& aValue)
nsAccessNode::GetComputedStyleValue(const nsAString& aPseudoElt,
const nsAString& aPropertyName,
nsAString& aValue)
{
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(mDOMNode));
if (!domElement) {
if (IsDefunct())
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
GetComputedStyleDeclaration(aPseudoElt, domElement, getter_AddRefs(styleDecl));
GetComputedStyleDeclaration(aPseudoElt, mDOMNode, getter_AddRefs(styleDecl));
NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE);
return styleDecl->GetPropertyValue(aPropertyName, aValue);
}
@ -627,15 +628,13 @@ nsAccessNode::GetComputedStyleCSSValue(const nsAString& aPseudoElt,
nsIDOMCSSPrimitiveValue **aCSSValue)
{
NS_ENSURE_ARG_POINTER(aCSSValue);
*aCSSValue = nsnull;
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(mDOMNode));
if (!domElement)
if (IsDefunct())
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
GetComputedStyleDeclaration(aPseudoElt, domElement,
GetComputedStyleDeclaration(aPseudoElt, mDOMNode,
getter_AddRefs(styleDecl));
NS_ENSURE_STATE(styleDecl);
@ -646,28 +645,29 @@ nsAccessNode::GetComputedStyleCSSValue(const nsAString& aPseudoElt,
return CallQueryInterface(cssValue, aCSSValue);
}
void nsAccessNode::GetComputedStyleDeclaration(const nsAString& aPseudoElt,
nsIDOMElement *aElement,
nsIDOMCSSStyleDeclaration **aCssDecl)
void
nsAccessNode::GetComputedStyleDeclaration(const nsAString& aPseudoElt,
nsIDOMNode *aNode,
nsIDOMCSSStyleDeclaration **aCssDecl)
{
*aCssDecl = nsnull;
nsCOMPtr<nsIDOMElement> domElement = nsAccUtils::GetDOMElementFor(aNode);
if (!domElement)
return;
// Returns number of items in style declaration
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
if (!content) {
return;
}
nsCOMPtr<nsIContent> content = do_QueryInterface(domElement);
nsCOMPtr<nsIDocument> doc = content->GetDocument();
if (!doc) {
if (!doc)
return;
}
nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(doc->GetWindow()));
if (!viewCSS) {
if (!viewCSS)
return;
}
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
viewCSS->GetComputedStyle(aElement, aPseudoElt, getter_AddRefs(cssDecl));
viewCSS->GetComputedStyle(domElement, aPseudoElt, getter_AddRefs(cssDecl));
NS_IF_ADDREF(*aCssDecl = cssDecl);
}

View File

@ -114,7 +114,7 @@ class nsAccessNode: public nsIAccessNode,
static already_AddRefed<nsIPresShell> GetPresShellFor(nsIDOMNode *aStartNode);
static void GetComputedStyleDeclaration(const nsAString& aPseudoElt,
nsIDOMElement *aElement,
nsIDOMNode *aNode,
nsIDOMCSSStyleDeclaration **aCssDecl);
already_AddRefed<nsRootAccessible> GetRootAccessible();

View File

@ -1138,10 +1138,12 @@ NS_IMETHODIMP nsHTMLTableAccessible::IsProbablyForLayout(PRBool *aIsProbablyForL
for (PRInt32 rowCount = 0; rowCount < rows; rowCount ++) {
nsCOMPtr<nsIDOMNode> rowNode;
nodeList->Item(rowCount, getter_AddRefs(rowNode));
nsCOMPtr<nsIDOMElement> rowElement = do_QueryInterface(rowNode);
nsCOMPtr<nsIDOMCSSStyleDeclaration> styleDecl;
GetComputedStyleDeclaration(EmptyString(), rowElement, getter_AddRefs(styleDecl));
GetComputedStyleDeclaration(EmptyString(), rowNode,
getter_AddRefs(styleDecl));
NS_ENSURE_TRUE(styleDecl, NS_ERROR_FAILURE);
lastRowColor = color;
styleDecl->GetPropertyValue(NS_LITERAL_STRING("background-color"), color);
if (rowCount > 0 && PR_FALSE == lastRowColor.Equals(color)) {

View File

@ -310,13 +310,13 @@ STDMETHODIMP nsAccessNodeWrap::get_computedStyle(
/* [out] */ unsigned short __RPC_FAR *aNumStyleProperties)
{
__try{
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(mDOMNode));
if (!domElement)
return E_FAIL;
*aNumStyleProperties = 0;
if (IsDefunct())
return E_FAIL;
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
GetComputedStyleDeclaration(EmptyString(), domElement, getter_AddRefs(cssDecl));
GetComputedStyleDeclaration(EmptyString(), mDOMNode, getter_AddRefs(cssDecl));
NS_ENSURE_TRUE(cssDecl, E_FAIL);
PRUint32 length;
@ -347,12 +347,11 @@ STDMETHODIMP nsAccessNodeWrap::get_computedStyleForProperties(
/* [length_is][size_is][out] */ BSTR __RPC_FAR *aStyleValues)
{
__try {
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(mDOMNode));
if (!domElement)
if (IsDefunct())
return E_FAIL;
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
GetComputedStyleDeclaration(EmptyString(), domElement, getter_AddRefs(cssDecl));
GetComputedStyleDeclaration(EmptyString(), mDOMNode, getter_AddRefs(cssDecl));
NS_ENSURE_TRUE(cssDecl, E_FAIL);
PRUint32 index;

View File

@ -78,6 +78,7 @@ _TEST_FILES =\
test_nsIAccessibleTable_3.html \
test_nsIAccessibleTable_4.html \
test_nsIAccessibleTable_listboxes.xul \
test_nsIAccessNode_utils.html \
test_nsOuterDocAccessible.html \
test_textattrs.html \
test_textboxes.html \

View File

@ -77,16 +77,16 @@ function getAccessible(aAccOrElmOrID, aInterfaces, aElmObj)
acc = gAccRetrieval.getAccessibleFor(elm);
} catch (e) {
}
if (!acc) {
ok(false, "Can't get accessible for " + aID);
ok(false, "Can't get accessible for " + aAccOrElmOrID);
return null;
}
}
if (!aInterfaces)
return acc;
if (aInterfaces instanceof Array) {
for (var index = 0; index < aInterfaces.length; index++) {
try {

View File

@ -0,0 +1,55 @@
<html>
<head>
<title>nsIAccessNode util methods testing</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/common.js"></script>
<script type="application/javascript">
function doTest()
{
var elmObj = {};
var acc = getAccessible("span", [nsIAccessNode], elmObj);
computedStyle = document.defaultView.getComputedStyle(elmObj.value, "");
// html:span element
is(acc.getComputedStyleValue("", "color"), computedStyle.color,
"Wrong color for element with ID 'span'");
// text child of html:span element
acc = getAccessible(acc.firstChild, [nsIAccessNode]);
is(acc.getComputedStyleValue("", "color"), computedStyle.color,
"Wrong color for text child of element with ID 'span'");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=454211"
title="nsIAccessNode util methods testing">
Mozilla Bug 454211
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<span role="description" style="color: red" id="span">text</span>
</body>
</html>