Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xul boolean attributes

0 views
Skip to first unread message

basic

unread,
Jan 7, 2002, 7:17:12 AM1/7/02
to
I've been playing with the XUL recently and found that XUL boolean attributes
seems to take "false" as the same as "true". This is due to the usage of
hasAttribute() rather than getAttribute() == "true" in XBL. Actually I don't
mind either way, but the XUL1.0 doc states lots of times in the widget and
control section <http://www.mozilla.org/projects/xul/widgets.html> that "true"
and "false" values are allowed. For example:
<quote>
The checked attribute indicates whether or not the checkbox is currently
checked. A value of 'true' indicates that the checkbox should be checked. A
value of 'false' indicates that the checkbox is unchecked.
</quote>

So either the document or the implementation needs to be change. Is
hasAttribute("attr") alot faster than getAttribute("attr") == "true" ?
Is if(val)setAttribute("attr","true");else removeAttribute("attr"); faster than
setAttribute("attr", val ? "true" : "false" ); ?

basic

Fabian Guisset

unread,
Jan 7, 2002, 12:24:44 PM1/7/02
to
basic wrote:

This was changed not long ago after nsIContent::HasAttr() was
implemented by hewitt. Blake and/or bz changed XUL to use
removeAttribute in conjunction with hasAttribute. In my opinion the XUL
spec should be changed.

-Fabian.


> basic
>


David Hyatt

unread,
Jan 7, 2002, 3:02:37 PM1/7/02
to Fabian Guisset
Absolutely not. If false is not accepted for a boolean attribute, then
that is a critical XUL 1.0 bug and should be filed immediately. Please
file as bugs any instances you find where "false" is not being respected.

XML schemas have a notion of an attribute being a boolean type. Being a
boolean type means having two possible values, true and false. If we do
not adhere to this specification, then we end up with our own fruity
definition of a pseudo-boolean that wouldn't mesh with the xsd:boolean type.

Dave
(hy...@netscape.com)

Fabian Guisset wrote:

>
> ------------------------------------------------------------------------
>
> Subject:
>
> Re: xul boolean attributes
> From:
>
> Fabian Guisset <fgui...@softhome.net>
> Date:
>
> Mon, 07 Jan 2002 18:24:44 +0100
>
> Newsgroups:
>
> netscape.public.mozilla.xpfe

basic

unread,
Jan 8, 2002, 11:00:48 AM1/8/02
to

basic

unread,
Jan 8, 2002, 11:29:36 AM1/8/02
to
I've done some very simple tests and found that removeAttribute is always faster
than setAttribute. hasAttribute is faster than getAttribute but not as much as
removeAttribute/setAttribute diff.

I'll start writing patches for bug 118683
<http://bugzilla.mozilla.org/show_bug.cgi?id=118683> to change hasAttribute to
getAttribute. since an empty attribute also works with getAttribute and
removeAttribute is faster than setAttribute, I'll leave removeAttribute alone.

basic

basic

unread,
Jan 8, 2002, 12:48:18 PM1/8/02
to
according to the XML schema 0 and 1 are also accepted, are we going to accept
that as well?

<quote>
http://www.w3.org/TR/xmlschema-2/#boolean

3.2.2.1 Lexical representation

An instance of a datatype that is defined as ·boolean· can have the following
legal literals {true, false, 1, 0}.
3.2.2.2 Canonical representation

The canonical representation for boolean is the set of literals {true, false}.
</quote>

basic

David Hyatt

unread,
Jan 8, 2002, 4:59:31 PM1/8/02
to
Don't worry about 1 and 0 for now.

The basic rules to follow are these:
(1) When writing code that wants to change the value of an attribute to
false, use removeAttribute (since it preserves space and also means
"false" for all XUL boolean attributes).
(2) Code that wishes to check a boolean attribute's value should always
operate under the following assumptions:

(a) If the attribute is present, set to "true", then the value is true
(b) If the attribute is present, set to "false", then the value is false
(c) If the attribute is present and set to anything else, the behavior
is undefined (for consistency you could just assume "false" here)
(d) If the attribute is absent, then the default value as specified by
the schema would be assumed (this is almost always "false" for XUL
boolean attributes, which is why removeAttribute is encouraged over
setattribute to "false").

basic wrote:

>
> ------------------------------------------------------------------------
>
> Subject:
>
> Re: xul boolean attributes
> From:
>

> basic <_ba...@yahoo.com>
> Date:
>
> Wed, 09 Jan 2002 01:48:18 +0800
>
> Newsgroups:
>
> netscape.public.mozilla.xpfe

basic

unread,
Jan 8, 2002, 6:18:40 PM1/8/02
to
There are cases where the default value is for the attribute is "true", I'm
guessing that I should do setAttribute("attr","false"); when false and
removeAttribute("attr"); when true for these cases?

basic

David Hyatt

unread,
Jan 8, 2002, 6:19:11 PM1/8/02
to
Correct. Which attributes are defaulting to true? I've been trying to
make all attributes default to false when omitted. I may want to change
any that are defaulting to true.

dave

basic

unread,
Jan 8, 2002, 6:58:32 PM1/8/02
to
the one I'm refering to is "autoCheck" for checkboxes and checkbox buttons.

basic

David Hyatt

unread,
Jan 8, 2002, 6:59:26 PM1/8/02
to
Ah yes. That one should be true.

dave

basic wrote:

>
> ------------------------------------------------------------------------
>
> Subject:
>
> Re: xul boolean attributes
> From:
>
> basic <_ba...@yahoo.com>
> Date:
>

> Wed, 09 Jan 2002 07:58:32 +0800
>
> Newsgroups:
>
> netscape.public.mozilla.xpfe

Blake Ross

unread,
Jan 9, 2002, 2:53:15 PM1/9/02
to
enableColumnDrag should be defaulting to true (it's not currently).

Blake

0 new messages