From dc206bff4cc4112399c58aadcd92f595aaa65ec2 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 30 Jul 2010 16:48:57 -0700 Subject: [PATCH] Bug 573258 - Support a.text as defined in HTML5; r=Olli.Pettay approval2.0=benjamin --- .../html/content/src/nsHTMLAnchorElement.cpp | 45 +++++-------------- content/html/content/test/Makefile.in | 1 + content/html/content/test/test_a_text.html | 45 +++++++++++++++++++ .../html/nsIDOMNSHTMLAnchorElement.idl | 9 +++- 4 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 content/html/content/test/test_a_text.html diff --git a/content/html/content/src/nsHTMLAnchorElement.cpp b/content/html/content/src/nsHTMLAnchorElement.cpp index 2a95c6f6f49..737882ab4cd 100644 --- a/content/html/content/src/nsHTMLAnchorElement.cpp +++ b/content/html/content/src/nsHTMLAnchorElement.cpp @@ -50,17 +50,11 @@ #include "nsPresContext.h" #include "nsIEventStateManager.h" -// For GetText(). -#include "nsIContentIterator.h" -#include "nsIDOMText.h" - #include "nsHTMLDNSPrefetch.h" #include "Link.h" using namespace mozilla::dom; -nsresult NS_NewPreContentIterator(nsIContentIterator** aInstancePtrResult); - class nsHTMLAnchorElement : public nsGenericHTMLElement, public nsIDOMHTMLAnchorElement, public nsIDOMNSHTMLAnchorElement2, @@ -68,6 +62,9 @@ class nsHTMLAnchorElement : public nsGenericHTMLElement, public Link { public: + using nsGenericElement::GetText; + using nsGenericElement::SetText; + nsHTMLAnchorElement(already_AddRefed aNodeInfo); virtual ~nsHTMLAnchorElement(); @@ -369,38 +366,16 @@ IMPL_URI_PART(Hash) NS_IMETHODIMP nsHTMLAnchorElement::GetText(nsAString& aText) { - aText.Truncate(); - - // Since this is a Netscape 4 proprietary attribute, we have to implement - // the same behavior. Basically it is returning the last text node of - // of the anchor. Returns an empty string if there is no text node. - // The nsIContentIterator does exactly what we want, if we start the - // iteration from the end. - nsCOMPtr iter; - nsresult rv = NS_NewPreContentIterator(getter_AddRefs(iter)); - NS_ENSURE_SUCCESS(rv, rv); - - // Initialize the content iterator with the children of the anchor - iter->Init(this); - - // Last() positions the iterator to the last child of the anchor, - // starting at the deepest level of children, just like NS4 does. - iter->Last(); - - while (!iter->IsDone()) { - nsCOMPtr textNode(do_QueryInterface(iter->GetCurrentNode())); - if(textNode) { - // The current node is a text node. Get its value and break the loop. - textNode->GetData(aText); - break; - } - - iter->Prev(); - } - + nsContentUtils::GetNodeTextContent(this, PR_TRUE, aText); return NS_OK; } +NS_IMETHODIMP +nsHTMLAnchorElement::SetText(const nsAString& aText) +{ + return nsContentUtils::SetNodeTextContent(this, aText, PR_FALSE); +} + NS_IMETHODIMP nsHTMLAnchorElement::ToString(nsAString& aSource) { diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 3e24d6e6b97..4a253b5c37e 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -144,6 +144,7 @@ _TEST_FILES = test_bug589.html \ test_bug347174_xslp.html \ 347174transformable.xml \ 347174transform.xsl \ + test_a_text.html \ test_anchor_href_cache_invalidation.html \ test_bug481335.xhtml \ test_bug500885.html \ diff --git a/content/html/content/test/test_a_text.html b/content/html/content/test/test_a_text.html new file mode 100644 index 00000000000..a964f11f7cc --- /dev/null +++ b/content/html/content/test/test_a_text.html @@ -0,0 +1,45 @@ + + + + Test for a.text + + + + + + + +
+
+
+ + diff --git a/dom/interfaces/html/nsIDOMNSHTMLAnchorElement.idl b/dom/interfaces/html/nsIDOMNSHTMLAnchorElement.idl index 21c44776df3..e2de674d62c 100644 --- a/dom/interfaces/html/nsIDOMNSHTMLAnchorElement.idl +++ b/dom/interfaces/html/nsIDOMNSHTMLAnchorElement.idl @@ -39,7 +39,7 @@ #include "domstubs.idl" -[scriptable, uuid(a6cf911c-15b3-11d2-932e-00805f8add32)] +[scriptable, uuid(24c39afa-44f7-4cd4-9e63-0504a581a081)] interface nsIDOMNSHTMLAnchorElement : nsISupports { attribute DOMString protocol; @@ -49,7 +49,12 @@ interface nsIDOMNSHTMLAnchorElement : nsISupports attribute DOMString search; attribute DOMString port; attribute DOMString hash; - readonly attribute DOMString text; + + /** + * An alias for the textContent attribute. + */ + [Null(Stringify)] + attribute DOMString text; DOMString toString(); };