Bug 567663. Implement 'hidden' attribute. r=sicking

This commit is contained in:
Ms2ger 2010-08-02 15:07:07 +12:00
parent 91595e761f
commit 7b6cd84171
16 changed files with 178 additions and 11 deletions

View File

@ -0,0 +1,5 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<p>This line should be visible.

View File

@ -0,0 +1,6 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<p>This line should be visible.
<p hidden>This line should not be visible.

View File

@ -0,0 +1,9 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<style>
p { display: none; }
[hidden] { display: block; }
</style>
<p hidden>This line should be visible.

View File

@ -0,0 +1,10 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<p hidden>This line should be visible.
<p>This line should not be visible.
<script>
document.getElementsByTagName("p")[0].hidden = false;
document.getElementsByTagName("p")[1].hidden = true;
</script>

View File

@ -0,0 +1,10 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<p hidden>This line should be visible.
<p>This line should not be visible.
<script>
document.getElementsByTagName("p")[0].removeAttribute("hidden");
document.getElementsByTagName("p")[1].setAttribute("hidden", "");
</script>

View File

@ -0,0 +1,8 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<style>
p { display: block; }
</style>
<p hidden>This line should be visible.

View File

@ -0,0 +1,8 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<style>
p { display: block !important; }
</style>
<p hidden>This line should be visible.

View File

@ -0,0 +1,9 @@
<!doctype html>
<title>The hidden attribute</title>
<link rel=author title=Ms2ger href=ms2ger@gmail.com>
<link rel=help href=http://www.whatwg.org/html5/#the-hidden-attribute>
<p>This line should be visible.
<p hidden=hidden>This line should not be visible.
<p hidden=blue>This line should not be visible.
<p hidden=true>This line should not be visible.
<p hidden=false>This line should not be visible.

View File

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20">
<metadata>
<link xmlns="http://www.w3.org/1999/xhtml" rel="author" title="Ms2ger"
href="ms2ger@gmail.com"/>
<link xmlns="http://www.w3.org/1999/xhtml" rel="help"
href="http://www.whatwg.org/html5/#the-hidden-attribute"/>
</metadata>
<rect height="20" width="20"/>
</svg>

After

Width:  |  Height:  |  Size: 355 B

View File

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20">
<metadata>
<link xmlns="http://www.w3.org/1999/xhtml" rel="author" title="Ms2ger"
href="ms2ger@gmail.com"/>
<link xmlns="http://www.w3.org/1999/xhtml" rel="help"
href="http://www.whatwg.org/html5/#the-hidden-attribute"/>
</metadata>
<rect hidden="" height="20" width="20"/>
</svg>

After

Width:  |  Height:  |  Size: 365 B

View File

@ -13,5 +13,13 @@
== 560059-video-dimensions.html 560059-video-dimensions-ref.html
== 573322-quirks.html 573322-quirks-ref.html
== 573322-no-quirks.html 573322-no-quirks-ref.html
== hidden-1a.html hidden-1-ref.html
== hidden-1b.html hidden-1-ref.html
== hidden-1c.html hidden-1-ref.html
== hidden-1d.html hidden-1-ref.html
== hidden-1e.html hidden-1-ref.html
== hidden-1f.html hidden-1-ref.html
== hidden-1g.html hidden-1-ref.html
== hidden-2.svg hidden-2-ref.svg
== href-attr-change-restyles.html href-attr-change-restyles-ref.html
== figure.html figure-ref.html

View File

@ -257,6 +257,7 @@ NS_INTERFACE_MAP_END_AGGREGATED(mElement)
NS_IMPL_INT_ATTR(nsGenericHTMLElement, TabIndex, tabindex)
NS_IMPL_BOOL_ATTR(nsGenericHTMLElement, Hidden, hidden)
nsresult
nsGenericHTMLElement::DOMQueryInterface(nsIDOMHTMLElement *aElement,
@ -279,7 +280,7 @@ nsGenericHTMLElement::DOMQueryInterface(nsIDOMHTMLElement *aElement,
new nsGenericHTMLElementTearoff(this))
NS_INTERFACE_MAP_END
// No closing bracket, becuase NS_INTERFACE_MAP_END does that for us.
// No closing bracket, because NS_INTERFACE_MAP_END does that for us.
nsresult
nsGenericHTMLElement::CopyInnerTo(nsGenericElement* aDst) const
@ -1632,6 +1633,7 @@ nsGenericHTMLElement::MapCommonAttributesInto(const nsMappedAttributes* aAttribu
}
}
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Visibility)) {
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::lang);
if (value && value->Type() == nsAttrValue::eString) {
@ -1639,6 +1641,15 @@ nsGenericHTMLElement::MapCommonAttributesInto(const nsMappedAttributes* aAttribu
eCSSUnit_Ident);
}
}
if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Display)) {
nsRuleDataDisplay* disp = aData->mDisplayData;
if (disp->mDisplay.GetUnit() == eCSSUnit_Null) {
if (aAttributes->IndexOfAttr(nsGkAtoms::hidden, kNameSpaceID_None) >= 0) {
disp->mDisplay.SetIntValue(NS_STYLE_DISPLAY_NONE, eCSSUnit_Enumerated);
}
}
}
}
void
@ -1678,6 +1689,7 @@ nsGenericHTMLFormElement::UpdateEditableFormControlState()
nsGenericHTMLElement::sCommonAttributeMap[] = {
{ &nsGkAtoms::contenteditable },
{ &nsGkAtoms::lang },
{ &nsGkAtoms::hidden },
{ nsnull }
};

View File

@ -141,13 +141,15 @@ public:
virtual nsresult GetInnerHTML(nsAString& aInnerHTML);
virtual nsresult SetInnerHTML(const nsAString& aInnerHTML);
nsresult ScrollIntoView(PRBool aTop, PRUint8 optional_argc);
// Declare Focus(), Blur(), GetTabIndex(), SetTabIndex(), GetSpellcheck(),
// SetSpellcheck(), and GetDraggable() such that classes that inherit interfaces
// with those methods properly override them
// Declare Focus(), Blur(), GetTabIndex(), SetTabIndex(), GetHidden(),
// SetHidden(), GetSpellcheck(), SetSpellcheck(), and GetDraggable() such that
// classes that inherit interfaces with those methods properly override them.
NS_IMETHOD Focus();
NS_IMETHOD Blur();
NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex);
NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
NS_IMETHOD GetHidden(PRBool* aHidden);
NS_IMETHOD SetHidden(PRBool aHidden);
NS_IMETHOD GetSpellcheck(PRBool* aSpellcheck);
NS_IMETHOD SetSpellcheck(PRBool aSpellcheck);
NS_IMETHOD GetDraggable(PRBool* aDraggable);

View File

@ -35,16 +35,18 @@
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = content/html/content/test
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = content/html/content/test
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = test_bug589.html \
_TEST_FILES = \
test_hidden.html \
test_bug589.html \
test_bug691.html \
nnc_lockup.gif \
test_bug694.html \

View File

@ -0,0 +1,53 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=567663
-->
<head>
<title>Test for Bug 567663</title>
<script src="/MochiKit/packed.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=567663">Mozilla Bug 567663</a>
<p id="display"></p>
<div id="content" style="display: none">
<p></p>
<p hidden></p>
</div>
<pre id="test">
<script>
/** Test for Bug 567663 **/
var ps = document.getElementById("content").getElementsByTagName("p");
is(ps[0].hidden, false, "First p's IDL attribute was wrong.");
is(ps[0].hasAttribute("hidden"), false, "First p had a content attribute.");
is(ps[1].hidden, true, "Second p's IDL attribute was wrong.");
is(ps[1].hasAttribute("hidden"), true,
"Second p didn't have a content attribute.");
is(ps[1].getAttribute("hidden"), "",
"Second p's content attribute was wrong.");
ps[0].hidden = true;
is(ps[0].getAttribute("hidden"), "",
"Content attribute was set to an incorrect value.");
ps[1].hidden = false;
is(ps[1].hasAttribute("hidden"), false,
"Second p still had a content attribute.");
ps[0].setAttribute("hidden", "banana");
is(ps[0].hidden, true, "p's IDL attribute was wrong after setting.");
is(ps[0].getAttribute("hidden"), "banana", "Content attribute changed.");
ps[0].setAttribute("hidden", "false");
is(ps[0].hidden, true, "p's IDL attribute was wrong after setting.");
is(ps[0].getAttribute("hidden"), "false", "Content attribute changed.");
ps[0].removeAttribute("hidden");
is(ps[0].hidden, false,
"p's IDL attribute was wrong after removing the content attribute.");
is(ps[0].hasAttribute("hidden"), false);
</script>
</pre>
</body>
</html>

View File

@ -38,7 +38,7 @@
#include "domstubs.idl"
[scriptable, uuid(2eeec2e5-a48f-4251-b2e2-adfb87929d18)]
[scriptable, uuid(f0ffe1d2-9615-492b-aae1-05428ebc2a70)]
interface nsIDOMNSHTMLElement : nsISupports
{
readonly attribute long offsetTop;
@ -48,6 +48,13 @@ interface nsIDOMNSHTMLElement : nsISupports
readonly attribute nsIDOMElement offsetParent;
attribute DOMString innerHTML;
/**
* Indicates that the element is not yet, or is no longer, relevant.
*
* See <http://www.whatwg.org/html5/#the-hidden-attribute>.
*/
attribute boolean hidden;
attribute long tabIndex;
attribute DOMString contentEditable;