Bug 839371 - Implement HTML5 <data> element. r=smaug

This commit is contained in:
David Humphrey (:humph) 2013-02-26 15:19:05 -05:00
parent 247b3cc18a
commit 1029c5c255
14 changed files with 201 additions and 0 deletions

View File

@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "HTMLDataElement.h"
#include "mozilla/dom/HTMLDataElementBinding.h"
#include "nsGenericHTMLElement.h"
NS_IMPL_NS_NEW_HTML_ELEMENT(Data)
namespace mozilla {
namespace dom {
HTMLDataElement::HTMLDataElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsGenericHTMLElement(aNodeInfo)
{
SetIsDOMBinding();
}
HTMLDataElement::~HTMLDataElement()
{
}
NS_IMPL_ADDREF_INHERITED(HTMLDataElement, Element)
NS_IMPL_RELEASE_INHERITED(HTMLDataElement, Element)
NS_INTERFACE_TABLE_HEAD(HTMLDataElement)
NS_HTML_CONTENT_INTERFACE_TABLE0(HTMLDataElement)
NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(HTMLDataElement,
nsGenericHTMLElement)
NS_HTML_CONTENT_INTERFACE_MAP_END
NS_IMPL_ELEMENT_CLONE(HTMLDataElement)
JSObject*
HTMLDataElement::WrapNode(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
return HTMLDataElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
void
HTMLDataElement::GetItemValueText(nsAString& text)
{
GetValue(text);
}
void
HTMLDataElement::SetItemValueText(const nsAString& text)
{
ErrorResult rv;
SetValue(text, rv);
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef mozilla_dom_HTMLDataElement_h
#define mozilla_dom_HTMLDataElement_h
#include "nsIDOMHTMLElement.h"
#include "nsGenericHTMLElement.h"
#include "nsGkAtoms.h"
namespace mozilla {
namespace dom {
class HTMLDataElement MOZ_FINAL : public nsGenericHTMLElement,
public nsIDOMHTMLElement
{
public:
HTMLDataElement(already_AddRefed<nsINodeInfo> aNodeInfo);
virtual ~HTMLDataElement();
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIDOMNode
NS_FORWARD_NSIDOMNODE_TO_NSINODE
// nsIDOMElement
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
// nsIDOMHTMLElement
NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC
// HTMLDataElement WebIDL
void GetValue(nsAString& aValue)
{
GetHTMLAttr(nsGkAtoms::value, aValue);
}
void SetValue(const nsAString& aValue, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::value, aValue, aError);
}
virtual void GetItemValueText(nsAString& text);
virtual void SetItemValueText(const nsAString& text);
virtual nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const;
virtual nsIDOMNode* AsDOMNode() { return this; }
protected:
virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap) MOZ_OVERRIDE;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_HTMLDataElement_h

View File

@ -34,6 +34,7 @@ EXPORTS_mozilla/dom = \
HTMLBodyElement.h \
HTMLBRElement.h \
HTMLButtonElement.h \
HTMLDataElement.h \
HTMLDataListElement.h \
HTMLDivElement.h \
HTMLFieldSetElement.h \
@ -94,6 +95,7 @@ CPPSRCS = \
HTMLBodyElement.cpp \
HTMLButtonElement.cpp \
HTMLCanvasElement.cpp \
HTMLDataElement.cpp \
HTMLDataListElement.cpp \
HTMLDivElement.cpp \
HTMLFieldSetElement.cpp \

View File

@ -1915,6 +1915,7 @@ NS_DECLARE_NS_NEW_HTML_ELEMENT(Body)
NS_DECLARE_NS_NEW_HTML_ELEMENT(Button)
NS_DECLARE_NS_NEW_HTML_ELEMENT(Canvas)
NS_DECLARE_NS_NEW_HTML_ELEMENT(Mod)
NS_DECLARE_NS_NEW_HTML_ELEMENT(Data)
NS_DECLARE_NS_NEW_HTML_ELEMENT(DataList)
NS_DECLARE_NS_NEW_HTML_ELEMENT(Div)
NS_DECLARE_NS_NEW_HTML_ELEMENT(FieldSet)

View File

@ -353,6 +353,7 @@ MOCHITEST_FILES = \
test_mozaudiochannel.html \
test_style_attributes_reflection.html \
test_bug629801.html \
test_bug839371.html \
$(NULL)

View File

@ -126,6 +126,7 @@ HTML_TAG("cite", "");
HTML_TAG("code", "");
HTML_TAG("col", "TableCol");
HTML_TAG("colgroup", "TableCol");
HTML_TAG("data", "Data");
HTML_TAG("datalist", "DataList");
HTML_TAG("dd", "");
HTML_TAG("del", "Mod");

View File

@ -0,0 +1,53 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=839371
-->
<head>
<title>Test for Bug 839371</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="reflect.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=839371">Mozilla Bug 839371</a>
<p id="display"></p>
<div id="content" style="display: none">
<div itemscope>
<data id="d1" itemprop="product-id" value="9678AOU879">The Instigator 2000</data>
</div>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 839371 **/
var d1 = document.getElementById("d1"),
d2 = document.createElement("data");
// .value IDL
is(d1.value, "9678AOU879", "value property reflects content attribute");
d1.value = "123";
is(d1.value, "123", "value property can be set via setter");
// .itemValue getter for <data>'s microdata
var data = document.getItems()[0];
is(data.properties["product-id"][0].itemValue, "123", "itemValue getter reflects value attribute");
// .itemValue setter uses value
data.properties["product-id"][0].itemValue = "456";
is(data.properties["product-id"][0].value, "456", "setting itemValue updates value");
is(data.properties["product-id"][0].itemValue, "456", "setting itemValue updates itemValue");
// .value reflects value attribute
reflectString({
element: d2,
attribute: "value"
});
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,13 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-data-element
*/
interface HTMLDataElement : HTMLElement {
[SetterThrows]
attribute DOMString value;
};

View File

@ -63,6 +63,7 @@ webidl_files = \
HTMLBRElement.webidl \
HTMLButtonElement.webidl \
HTMLCollection.webidl \
HTMLDataElement.webidl \
HTMLDataListElement.webidl \
HTMLDirectoryElement.webidl \
HTMLDivElement.webidl \

View File

@ -80,6 +80,7 @@ EDITOR_ATOM(cssVerticalAlign, "vertical-align")
EDITOR_ATOM(cssWhitespace, "white-space")
EDITOR_ATOM(cssWidth, "width")
EDITOR_ATOM(cssZIndex, "z-index")
EDITOR_ATOM(data, "data")
EDITOR_ATOM(datalist, "datalist")
EDITOR_ATOM(dd, "dd")
EDITOR_ATOM(dfn, "dfn")

View File

@ -646,6 +646,7 @@ static const nsElementInfo kElements[eHTMLTag_userdefined] = {
ELEM(col, false, false, GROUP_TABLE_CONTENT | GROUP_COLGROUP_CONTENT,
GROUP_NONE),
ELEM(colgroup, true, false, GROUP_NONE, GROUP_COLGROUP_CONTENT),
ELEM(data, true, false, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
ELEM(datalist, true, false, GROUP_PHRASE,
GROUP_OPTIONS | GROUP_INLINE_ELEMENT),
ELEM(dd, true, false, GROUP_DL_CONTENT, GROUP_FLOW_ELEMENT),

View File

@ -64,6 +64,7 @@ HTML_HTMLELEMENT_TAG(cite)
HTML_HTMLELEMENT_TAG(code)
HTML_TAG(col, TableCol)
HTML_TAG(colgroup, TableCol)
HTML_TAG(data, Data)
HTML_TAG(datalist, DataList)
HTML_HTMLELEMENT_TAG(dd)
HTML_TAG(del, Mod)

View File

@ -407,6 +407,15 @@ const nsHTMLElement gHTMLElements[] = {
/*special props, prop-range*/ kNoPropagate,kDefaultPropRange,
/*special parents,kids*/ &gInTable,&gColgroupKids,
},
{
/*tag*/ eHTMLTag_data,
/*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown,
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,0,
/*parent,incl,exclgroups*/ kPhrase, (kSelf|kInlineEntity), kNone,
/*special props, prop-range*/ 0, kDefaultPropRange,
/*special parents,kids*/ 0,0,
},
{
/*tag*/ eHTMLTag_datalist,
/*requiredAncestor*/ eHTMLTag_unknown, eHTMLTag_unknown,

View File

@ -77,6 +77,8 @@ static const PRUnichar sHTMLTagUnicodeName_colgroup[] =
{'c', 'o', 'l', 'g', 'r', 'o', 'u', 'p', '\0'};
static const PRUnichar sHTMLTagUnicodeName_counter[] =
{'c', 'o', 'u', 'n', 't', 'e', 'r', '\0'};
static const PRUnichar sHTMLTagUnicodeName_data[] =
{'d', 'a', 't', 'a', '\0'};
static const PRUnichar sHTMLTagUnicodeName_datalist[] =
{'d', 'a', 't', 'a', 'l', 'i', 's', 't', '\0'};
static const PRUnichar sHTMLTagUnicodeName_dd[] =