From f1793770dcfdd94d556786bc05b9c870ec4732e7 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Tue, 28 Oct 2008 19:54:57 +0800 Subject: [PATCH] Bug 460932 - text-indent and text-align should really be object attributes, r=aaronlev, marcoz --- accessible/src/base/nsAccessibilityAtomList.h | 6 +- accessible/src/base/nsAccessible.cpp | 21 ++- accessible/src/base/nsTextUtils.cpp | 2 - accessible/tests/mochitest/Makefile.in | 1 + accessible/tests/mochitest/attributes.js | 141 ++++++++++++++++ accessible/tests/mochitest/common.js | 1 + accessible/tests/mochitest/test_cssattrs.html | 73 ++++---- .../tests/mochitest/test_groupattrs.xul | 42 ++--- .../tests/mochitest/test_textattrs.html | 156 ++---------------- 9 files changed, 224 insertions(+), 219 deletions(-) create mode 100644 accessible/tests/mochitest/attributes.js diff --git a/accessible/src/base/nsAccessibilityAtomList.h b/accessible/src/base/nsAccessibilityAtomList.h index 9a55dbc45cab..6f991bb96a18 100755 --- a/accessible/src/base/nsAccessibilityAtomList.h +++ b/accessible/src/base/nsAccessibilityAtomList.h @@ -157,7 +157,6 @@ ACCESSIBILITY_ATOM(anonid, "anonid") // Used for ID's in XBL ACCESSIBILITY_ATOM(contenteditable, "contenteditable") ACCESSIBILITY_ATOM(control, "control") ACCESSIBILITY_ATOM(disabled, "disabled") -ACCESSIBILITY_ATOM(display, "display") ACCESSIBILITY_ATOM(_class, "class") ACCESSIBILITY_ATOM(cycles, "cycles") // used for XUL cycler attribute ACCESSIBILITY_ATOM(curpos, "curpos") // XUL @@ -187,6 +186,11 @@ ACCESSIBILITY_ATOM(tooltiptext, "tooltiptext") ACCESSIBILITY_ATOM(type, "type") ACCESSIBILITY_ATOM(value, "value") + // Alphabetical list of object attributes +ACCESSIBILITY_ATOM(display, "display") +ACCESSIBILITY_ATOM(textAlign, "text-align") +ACCESSIBILITY_ATOM(textIndent, "text-indent") + // Alphabetical list of text attributes (AT API) ACCESSIBILITY_ATOM(backgroundColor, "background-color") ACCESSIBILITY_ATOM(invalid, "invalid") diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 70df07764783..305d0019cf05 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -2182,13 +2182,28 @@ nsAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes) } // Expose 'display' attribute. - nsAutoString displayValue; + nsAutoString value; nsresult rv = GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("display"), - displayValue); + value); if (NS_SUCCEEDED(rv)) nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::display, - displayValue); + value); + + // Expose 'text-align' attribute. + rv = GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("text-align"), + value); + if (NS_SUCCEEDED(rv)) + nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::textAlign, + value); + + // Expose 'text-indent' attribute. + rv = GetComputedStyleValue(EmptyString(), NS_LITERAL_STRING("text-indent"), + value); + if (NS_SUCCEEDED(rv)) + nsAccUtils::SetAccAttr(aAttributes, nsAccessibilityAtoms::textIndent, + value); + return NS_OK; } diff --git a/accessible/src/base/nsTextUtils.cpp b/accessible/src/base/nsTextUtils.cpp index 4806b6d13de9..1338b2fe5f8a 100644 --- a/accessible/src/base/nsTextUtils.cpp +++ b/accessible/src/base/nsTextUtils.cpp @@ -87,8 +87,6 @@ static nsCSSTextAttrMapItem gCSSTextAttrsMap[] = { { "font-weight", kAnyValue, kCopyName, kCopyValue }, { "text-decoration", "line-through", "text-line-through-style", "solid" }, { "text-decoration", "underline", "text-underline-style", "solid" }, - { "text-align", kAnyValue, kCopyName, kCopyValue }, - { "text-indent", kAnyValue, kCopyName, kCopyValue }, { "vertical-align", kAnyValue, "text-position", kCopyValue } }; diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index 905a4bcd5281..e1830c0c99ef 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -48,6 +48,7 @@ include $(topsrcdir)/config/rules.mk _TEST_FILES =\ moz.png \ longdesc_src.html \ + attributes.js \ common.js \ nsIAccessible_actions.js \ nsIAccessible_name.css \ diff --git a/accessible/tests/mochitest/attributes.js b/accessible/tests/mochitest/attributes.js new file mode 100644 index 000000000000..4d5dc18dfc20 --- /dev/null +++ b/accessible/tests/mochitest/attributes.js @@ -0,0 +1,141 @@ +//////////////////////////////////////////////////////////////////////////////// +// Object attributes. + +/** + * Test object attributes. + * + * @param aID [in] the ID of DOM element having accessible + * @param aAttrs [in] the map of expected object attributes + * (name/value pairs) + * @param aSkipUnexpectedAttrs [in] points this function doesn't fail if + * unexpected attribute is encountered + */ +function testAttrs(aID, aAttrs, aSkipUnexpectedAttrs) +{ + var accessible = getAccessible(aID); + if (!accessible) + return; + + var attrs = null; + try { + attrs = accessible.attributes; + } catch (e) { } + + if (!attrs) { + ok(false, "Can't get object attributes for " + aID); + return; + } + + var errorMsg = " for " + aID; + compareAttrs(errorMsg, attrs, aAttrs, aSkipUnexpectedAttrs); +} + +//////////////////////////////////////////////////////////////////////////////// +// Text attributes. + +/** + * Test text attributes. + * + * @param aID [in] the ID of DOM element having text + * accessible + * @param aOffset [in] the offset inside text accessible to fetch + * text attributes + * @param aAttrs [in] the map of expected text attributes + * (name/value pairs) + * @param aStartOffset [in] expected start offset where text attributes + * are applied + * @param aEndOffset [in] expected end offset where text attribute + * are applied + * @param aSkipUnexpectedAttrs [in] points the function doesn't fail if + * unexpected attribute is encountered + */ +function testTextAttrs(aID, aOffset, aAttrs, aStartOffset, aEndOffset, + aSkipUnexpectedAttrs) +{ + var accessible = getAccessible(aID, [nsIAccessibleText]); + if (!accessible) + return; + + var startOffset = { value: -1 }; + var endOffset = { value: -1 }; + var attrs = null; + try { + attrs = accessible.getTextAttributes(false, aOffset, + startOffset, endOffset); + } catch (e) { + } + + if (!attrs) { + ok(false, "Can't get text attributes for " + aID); + return; + } + + var errorMsg = " for " + aID + " at offset " + aOffset; + + is(startOffset.value, aStartOffset, "Wrong start offset" + errorMsg); + is(endOffset.value, aEndOffset, "Wrong end offset" + errorMsg); + + compareAttrs(errorMsg, attrs, aAttrs, aSkipUnexpectedAttrs); +} + +/** + * Test default text attributes. + * + * @param aID [in] the ID of DOM element having text + * accessible + * @param aDefAttrs [in] the map of expected text attributes + * (name/value pairs) + * @param aSkipUnexpectedAttrs [in] points the function doesn't fail if + * unexpected attribute is encountered + */ +function testDefaultTextAttrs(aID, aDefAttrs, aSkipUnexpectedAttrs) +{ + var accessible = getAccessible(aID, [nsIAccessibleText]); + if (!accessible) + return; + + var defAttrs = null; + try{ + defAttrs = accessible.defaultTextAttributes; + } catch (e) { + } + + if (!defAttrs) { + ok(false, "Can't get default text attributes for " + aID); + return; + } + + var errorMsg = ". Getting default text attributes for " + aID; + compareAttrs(errorMsg, defAttrs, aDefAttrs, aSkipUnexpectedAttrs); +} + +//////////////////////////////////////////////////////////////////////////////// +// Private. + +function compareAttrs(aErrorMsg, aAttrs, aExpectedAttrs, aSkipUnexpectedAttrs) +{ + var enumerate = aAttrs.enumerate(); + while (enumerate.hasMoreElements()) { + var prop = enumerate.getNext().QueryInterface(nsIPropertyElement); + + if (!(prop.key in aExpectedAttrs)) { + if (!aSkipUnexpectedAttrs) + ok(false, "Unexpected attribute '" + prop.key + "' having '" + + prop.value + "'" + aErrorMsg); + } else { + is(prop.value, aExpectedAttrs[prop.key], + "Attribute '" + prop.key + " 'has wrong value" + aErrorMsg); + } + } + + for (var name in aExpectedAttrs) { + var value = ""; + try { + value = aAttrs.getStringProperty(name); + } catch(e) { } + + if (!value) + ok(false, + "There is no expected attribute '" + name + "' " + aErrorMsg); + } +} diff --git a/accessible/tests/mochitest/common.js b/accessible/tests/mochitest/common.js index c0222d4134e6..3533901b5965 100644 --- a/accessible/tests/mochitest/common.js +++ b/accessible/tests/mochitest/common.js @@ -29,6 +29,7 @@ const nsIAccessibleValue = Components.interfaces.nsIAccessibleValue; const nsIObserverService = Components.interfaces.nsIObserverService; const nsIDOMNode = Components.interfaces.nsIDOMNode; +const nsIPropertyElement = Components.interfaces.nsIPropertyElement; //////////////////////////////////////////////////////////////////////////////// // Roles diff --git a/accessible/tests/mochitest/test_cssattrs.html b/accessible/tests/mochitest/test_cssattrs.html index b9eb6011fb6d..f31aab3d22aa 100644 --- a/accessible/tests/mochitest/test_cssattrs.html +++ b/accessible/tests/mochitest/test_cssattrs.html @@ -1,57 +1,46 @@ CSS-like attributes tests - + - - + + + + + - + + + + +