Closed
Bug 814090
Opened 12 years ago
Closed 11 years ago
[classList] implements the new toggle spec
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
mozilla24
People
(Reporter: julienw, Assigned: julienw)
References
()
Details
(Keywords: doc-bug-filed)
Attachments
(1 file, 1 obsolete file)
8.61 KB,
patch
|
julienw
:
review+
|
Details | Diff | Splinter Review |
The new specification for classList.toggle added a second argument which can force the toggle. This is useful and can lead to clearer JS code.
Assignee | ||
Updated•12 years ago
|
Assignee | ||
Comment 1•11 years ago
|
||
This doesn't need variadic idl support, so could we add this support ? This is so useful when developing JS using the DOM. Developing on B2G without extra framework there is probably one situation each day when I wish I had this implemented.
Comment 2•11 years ago
|
||
We could. Patches welcome :) Relevant code is <http://mxr.mozilla.org/mozilla-central/source/dom/webidl/DOMTokenList.webidl>, <http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsDOMTokenList.h>, <http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsDOMTokenList.cpp>. Relevant documentation is <https://developer.mozilla.org/en/Mozilla/WebIDL_bindings>. #content will be happy to help if you run into issues.
Updated•11 years ago
|
Keywords: dev-doc-needed
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → felash
Assignee | ||
Comment 3•11 years ago
|
||
I still don't exactly get how to push to try (it finds no change when I push) but I added some tests and they all passes locally.
Attachment #760342 -
Flags: review?(bzbarsky)
Comment 4•11 years ago
|
||
Before I start looking at the code... what is the point of this argument? It looks to me like: .toggle('foo') will add 'foo' to the list if not there, and remove it otherwise. But .toggle('foo', true) will act just like .add('foo') and .toggle('foo', false) will act just like .remove('foo'), except for having a non-void return value. Is my reading of the spec correct? If so, why is this a useful thing for a method called toggle() to do? If I'm misreading it, what am I missing?
Comment 5•11 years ago
|
||
AIUI, you're reading it correctly. It's meant to replace classList[aBooleanArg ? "add" : "remove"](), I think.
Assignee | ||
Comment 6•11 years ago
|
||
This is especially useful when you have a boolean that results from a bool calculation. This is more a sugar syntax, because this allows nothing that can't be done without it. Compare for example (a simplified code taken from the Sms app in Gaia) : if (recipientCount > 0) { this.contactPickButton.classList.add('disabled'); } else { this.contactPickButton.classList.remove('disabled'); } with this code, this can be simplidied like this : this.contactPickButton.classList.toggle('disabled', recipientCount > 0);
Comment 7•11 years ago
|
||
Hmm... ok, I see. Seems like slightly odd API, but I can't come up with a better one right this second. And the spec is ... unreadable. :( And of course toggle('foo', true) is not specced to do the same thing as add('foo'), but we'll worry about that when tests get written for the spec. :(
Flags: needinfo?(annevk)
Comment 8•11 years ago
|
||
Comment on attachment 760342 [details] [diff] [review] patch v1 >+++ b/content/base/src/nsDOMTokenList.cpp >+ const mozilla::dom::Optional<bool>& optionalIsForce, Please drop the "mozilla::dom::" bit. See the "using namespace" near the top of this file. Also, the argument should probably be called "aForce". >+ const bool hasForceArgument = optionalIsForce.WasPassed(); >+ const bool isForce = optionalIsForce.Value(); Doing Value() if !WasPassed() should trigger a fatal assert. Was the relevant codepath just not tested? I think you want something more like: const bool forceOn = aForce.WasPassed() && aForce.Value(); const bool forceOff = aForce.WasPassed() && !aForce.Value(); >+ bool isPresent = (attr && attr->Contains(aToken)); Please remove the extra parens. >+ if ((hasForceArgument && !isForce) || (!hasForceArgument)) { And then this would become: if (!forceOn) { >+ if ((hasForceArgument && isForce) || (!hasForceArgument)) { And this would become: if (!forceOff) { >+++ b/content/base/src/nsDOMTokenList.h >+ const mozilla::dom::Optional<bool>& force, aForce. r=me with the above fixed.
Attachment #760342 -
Flags: review?(bzbarsky) → review+
Assignee | ||
Comment 9•11 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #8) > Comment on attachment 760342 [details] [diff] [review] > patch v1 > > > >+ const bool hasForceArgument = optionalIsForce.WasPassed(); > >+ const bool isForce = optionalIsForce.Value(); > > Doing Value() if !WasPassed() should trigger a fatal assert. Was the > relevant codepath just not tested? strangely, I'm quite sure it is in the mochitests... The tests were existing prior this patch. I also briefly tested using the Web Console. How is it possible then ?
Comment 10•11 years ago
|
||
Did you test an opt build or debug build?
Assignee | ||
Comment 11•11 years ago
|
||
I had no .mozconfig so I think it was an opt build. I'm building again with the debug option. Thanks a lot.
Assignee | ||
Comment 12•11 years ago
|
||
I get the assert failure while running the mochitests with a debug build.
Assignee | ||
Comment 13•11 years ago
|
||
carrying r=bzbarsky try is https://tbpl.mozilla.org/?tree=Try&rev=85804cbf8361
Attachment #760342 -
Attachment is obsolete: true
Attachment #762917 -
Flags: review+
Assignee | ||
Comment 14•11 years ago
|
||
This looks good to me. Ryan, would you double check if try looks good and do the check in ? Thanks !
Keywords: checkin-needed
Comment 15•11 years ago
|
||
(In reply to Julien Wajsberg [:julienw] from comment #3) > I added some tests and they all passes locally. Looks like your added tests didn't actually make it into the patch, though.
Keywords: checkin-needed
Assignee | ||
Comment 16•11 years ago
|
||
Phil, I do see them in the patch, don't you see the changes to `test_classList.html` ?
Flags: needinfo?(philringnalda)
Comment 18•11 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/dccd693173c9
Flags: in-testsuite+
Keywords: checkin-needed
Comment 19•11 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/dccd693173c9
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
Comment 20•11 years ago
|
||
Follow up for documentation: https://bugzilla.mozilla.org/show_bug.cgi?id=885279
Updated•11 years ago
|
Keywords: dev-doc-needed → doc-bug-filed
Comment 21•11 years ago
|
||
The specification has been updated with clearer wording: https://www.w3.org/Bugs/Public/show_bug.cgi?id=22321
Flags: needinfo?(annevk)
You need to log in
before you can comment on or make changes to this bug.
Description
•