From 176065e86aa906731d0832ba9b2141a718c300f1 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Sat, 9 Feb 2013 13:36:34 +0900 Subject: [PATCH] Bug 445510 - Support ARIA-based text attributes, r=tbsaunde --HG-- rename : accessible/tests/mochitest/attributes/test_text.html => accessible/tests/mochitest/textattrs/test_general.html --- accessible/src/base/TextAttrs.cpp | 86 +++++++++++++++++++ accessible/src/base/TextAttrs.h | 32 +++++++ accessible/tests/mochitest/Makefile.in | 1 + .../tests/mochitest/attributes/Makefile.in | 1 - .../tests/mochitest/textattrs/Makefile.in | 19 ++++ .../test_general.html} | 0 .../mochitest/textattrs/test_invalid.html | 62 +++++++++++++ content/base/src/nsGkAtomList.h | 2 + 8 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 accessible/tests/mochitest/textattrs/Makefile.in rename accessible/tests/mochitest/{attributes/test_text.html => textattrs/test_general.html} (100%) create mode 100644 accessible/tests/mochitest/textattrs/test_invalid.html diff --git a/accessible/src/base/TextAttrs.cpp b/accessible/src/base/TextAttrs.cpp index e49103f7bbb..20461c8e7de 100644 --- a/accessible/src/base/TextAttrs.cpp +++ b/accessible/src/base/TextAttrs.cpp @@ -83,6 +83,9 @@ TextAttrsMgr::GetAttributes(nsIPersistentProperties* aAttributes, // "language" text attribute LangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode); + // "aria-invalid" text attribute + InvalidTextAttr invalidTextAttr(hyperTextElm, offsetNode); + // "background-color" text attribute BGColorTextAttr bgColorTextAttr(rootFrame, frame); @@ -113,6 +116,7 @@ TextAttrsMgr::GetAttributes(nsIPersistentProperties* aAttributes, TextAttr* attrArray[] = { &langTextAttr, + &invalidTextAttr, &bgColorTextAttr, &colorTextAttr, &fontFamilyTextAttr, @@ -226,6 +230,88 @@ TextAttrsMgr::LangTextAttr:: nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::language, aValue); } +//////////////////////////////////////////////////////////////////////////////// +// InvalidTextAttr +//////////////////////////////////////////////////////////////////////////////// + +TextAttrsMgr::InvalidTextAttr:: + InvalidTextAttr(nsIContent* aRootElm, nsIContent* aElm) : + TTextAttr(!aElm), mRootElm(aRootElm) +{ + mIsRootDefined = GetValue(mRootElm, &mRootNativeValue); + if (aElm) + mIsDefined = GetValue(aElm, &mNativeValue); +} + +bool +TextAttrsMgr::InvalidTextAttr:: + GetValueFor(Accessible* aAccessible, uint32_t* aValue) +{ + nsIContent* elm = nsCoreUtils::GetDOMElementFor(aAccessible->GetContent()); + return elm ? GetValue(elm, aValue) : false; +} + +void +TextAttrsMgr::InvalidTextAttr:: + ExposeValue(nsIPersistentProperties* aAttributes, const uint32_t& aValue) +{ + switch (aValue) { + case eFalse: + nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid, + NS_LITERAL_STRING("false")); + break; + + case eGrammar: + nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid, + NS_LITERAL_STRING("grammar")); + break; + + case eSpelling: + nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid, + NS_LITERAL_STRING("spelling")); + break; + + case eTrue: + nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::invalid, + NS_LITERAL_STRING("true")); + break; + } +} + +bool +TextAttrsMgr::InvalidTextAttr:: + GetValue(nsIContent* aElm, uint32_t* aValue) +{ + nsIContent* elm = aElm; + do { + if (nsAccUtils::HasDefinedARIAToken(elm, nsGkAtoms::aria_invalid)) { + static nsIContent::AttrValuesArray tokens[] = + { &nsGkAtoms::_false, &nsGkAtoms::grammar, &nsGkAtoms::spelling, + nullptr }; + + int32_t idx = elm->FindAttrValueIn(kNameSpaceID_None, + nsGkAtoms::aria_invalid, tokens, + eCaseMatters); + switch (idx) { + case 0: + *aValue = eFalse; + return true; + case 1: + *aValue = eGrammar; + return true; + case 2: + *aValue = eSpelling; + return true; + default: + *aValue = eTrue; + return true; + } + } + } while ((elm = elm->GetParent()) && elm != mRootElm); + + return false; +} + //////////////////////////////////////////////////////////////////////////////// // BGColorTextAttr diff --git a/accessible/src/base/TextAttrs.h b/accessible/src/base/TextAttrs.h index c511ac87fb8..6c26572084c 100644 --- a/accessible/src/base/TextAttrs.h +++ b/accessible/src/base/TextAttrs.h @@ -212,6 +212,38 @@ protected: }; + /** + * Class is used for the 'invalid' text attribute. Note, it calculated + * the attribute from aria-invalid attribute only; invalid:spelling attribute + * calculated from misspelled text in the editor is managed by + * HyperTextAccessible and applied on top of the value from aria-invalid. + */ + class InvalidTextAttr : public TTextAttr + { + public: + InvalidTextAttr(nsIContent* aRootElm, nsIContent* aElm); + virtual ~InvalidTextAttr() { }; + + protected: + + enum { + eFalse, + eGrammar, + eSpelling, + eTrue + }; + + // TextAttr + virtual bool GetValueFor(Accessible* aAccessible, uint32_t* aValue); + virtual void ExposeValue(nsIPersistentProperties* aAttributes, + const uint32_t& aValue); + + private: + bool GetValue(nsIContent* aElm, uint32_t* aValue); + nsIContent* mRootElm; + }; + + /** * Class is used for the work with 'background-color' text attribute. */ diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index 8777e880d5a..dbb78a81f90 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -29,6 +29,7 @@ DIRS = \ states \ table \ text \ + textattrs \ textcaret \ textselection \ tree \ diff --git a/accessible/tests/mochitest/attributes/Makefile.in b/accessible/tests/mochitest/attributes/Makefile.in index 76f179a7350..51379cab780 100644 --- a/accessible/tests/mochitest/attributes/Makefile.in +++ b/accessible/tests/mochitest/attributes/Makefile.in @@ -19,7 +19,6 @@ MOCHITEST_A11Y_FILES =\ test_obj_group.xul \ test_obj_group_tree.xul \ test_tag.html \ - test_text.html \ test_xml-roles.html \ $(NULL) diff --git a/accessible/tests/mochitest/textattrs/Makefile.in b/accessible/tests/mochitest/textattrs/Makefile.in new file mode 100644 index 00000000000..ea08c752dd7 --- /dev/null +++ b/accessible/tests/mochitest/textattrs/Makefile.in @@ -0,0 +1,19 @@ +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +DEPTH = @DEPTH@ +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = accessible/textattrs + +include $(DEPTH)/config/autoconf.mk + +MOCHITEST_A11Y_FILES =\ + test_general.html \ + test_invalid.html \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/accessible/tests/mochitest/attributes/test_text.html b/accessible/tests/mochitest/textattrs/test_general.html similarity index 100% rename from accessible/tests/mochitest/attributes/test_text.html rename to accessible/tests/mochitest/textattrs/test_general.html diff --git a/accessible/tests/mochitest/textattrs/test_invalid.html b/accessible/tests/mochitest/textattrs/test_invalid.html new file mode 100644 index 00000000000..495db088818 --- /dev/null +++ b/accessible/tests/mochitest/textattrs/test_invalid.html @@ -0,0 +1,62 @@ + + + + Invalid text attribute + + + + + + + + + + + + + + + + + + + Mozilla Bug 445510 + +

+ +
+  
+ +
no invalid
+
invalid:true
+
invalid:false
+
invalid:grammar
+
invalid:spelling
+
invalid:true
+ + diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index e01a839154d..3329842b82e 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -2100,6 +2100,7 @@ GK_ATOM(datatable, "datatable") GK_ATOM(directory, "directory") GK_ATOM(droppable, "droppable") GK_ATOM(eventFromInput, "event-from-input") +GK_ATOM(grammar, "grammar") GK_ATOM(gridcell, "gridcell") GK_ATOM(heading, "heading") GK_ATOM(InlineBlockFrame, "InlineBlockFrame") @@ -2127,6 +2128,7 @@ GK_ATOM(rowgroup, "rowgroup") GK_ATOM(rowheader, "rowheader") GK_ATOM(select1, "select1") GK_ATOM(setsize, "setsize") +GK_ATOM(spelling, "spelling") GK_ATOM(spinbutton, "spinbutton") GK_ATOM(status, "status") GK_ATOM(tableCellIndex, "table-cell-index")