WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
186883
Implement support for Element.toggleAttribute
https://bugs.webkit.org/show_bug.cgi?id=186883
Summary
Implement support for Element.toggleAttribute
Jonathan Kingston
Reported
2018-06-21 02:07:30 PDT
Element.toggleAttribute provides a simple boolean interface the same as classList.toggle for Element. See
https://github.com/whatwg/dom/issues/461
Firefox implementation bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=1469592
Other browsers are willing to implement:
https://github.com/whatwg/dom/issues/461#issuecomment-398206390
Attachments
Patch
(12.27 KB, patch)
2018-07-03 12:04 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2018-07-03 12:04:51 PDT
Created
attachment 344202
[details]
Patch
WebKit Commit Bot
Comment 2
2018-07-03 13:46:45 PDT
Comment on
attachment 344202
[details]
Patch Clearing flags on attachment: 344202 Committed
r233475
: <
https://trac.webkit.org/changeset/233475
>
WebKit Commit Bot
Comment 3
2018-07-03 13:46:46 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 4
2018-07-03 13:47:21 PDT
<
rdar://problem/41790122
>
Darin Adler
Comment 5
2018-07-04 12:08:48 PDT
Comment on
attachment 344202
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=344202&action=review
> Source/WebCore/dom/Element.h:117 > + ExceptionOr<bool> toggleAttribute(const AtomicString& name, std::optional<bool> force);
Should this be localName instead of name?
> Source/WebCore/dom/Element.idl:47 > + [CEReactions, MayThrowException] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
Should this be localName instead of qualifiedName?
Chris Dumez
Comment 6
2018-07-05 08:55:57 PDT
(In reply to Darin Adler from
comment #5
)
> Comment on
attachment 344202
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=344202&action=review
> > > Source/WebCore/dom/Element.h:117 > > + ExceptionOr<bool> toggleAttribute(const AtomicString& name, std::optional<bool> force); > > Should this be localName instead of name? > > > Source/WebCore/dom/Element.idl:47 > > + [CEReactions, MayThrowException] boolean toggleAttribute(DOMString qualifiedName, optional boolean force); > > Should this be localName instead of qualifiedName?
We try to keep the IDL in sync with the spec and the spec says "qualifiedName". I will check what makes sense for the implementation though.
Chris Dumez
Comment 7
2018-07-05 08:56:46 PDT
(In reply to Chris Dumez from
comment #6
)
> (In reply to Darin Adler from
comment #5
) > > Comment on
attachment 344202
[details]
> > Patch > > > > View in context: > >
https://bugs.webkit.org/attachment.cgi?id=344202&action=review
> > > > > Source/WebCore/dom/Element.h:117 > > > + ExceptionOr<bool> toggleAttribute(const AtomicString& name, std::optional<bool> force); > > > > Should this be localName instead of name? > > > > > Source/WebCore/dom/Element.idl:47 > > > + [CEReactions, MayThrowException] boolean toggleAttribute(DOMString qualifiedName, optional boolean force); > > > > Should this be localName instead of qualifiedName? > > We try to keep the IDL in sync with the spec and the spec says > "qualifiedName". > I will check what makes sense for the implementation though.
At the very least, the new method is consistent with the others: WEBCORE_EXPORT const AtomicString& getAttribute(const AtomicString& name) const; WEBCORE_EXPORT ExceptionOr<void> setAttribute(const AtomicString& name, const AtomicString& value);
Chris Dumez
Comment 8
2018-07-05 09:08:13 PDT
Comment on
attachment 344202
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=344202&action=review
> Source/WebCore/dom/Element.cpp:1284 > + unsigned index = elementData() ? elementData()->findAttributeIndexByName(caseAdjustedLocalName, false) : ElementData::attributeNotFound;
Specification says the input is a qualifiedName so I should probably be using the findAttributeIndexByName(QualifiedName) overload here. I'll look into this further.
> Source/WebCore/dom/Element.cpp:1287 > + setAttributeInternal(index, QualifiedName { nullAtom(), caseAdjustedLocalName, nullAtom() }, emptyString(), NotInSynchronizationOfLazyAttribute);
Here is correct though because the spec says: "If force is not given or is true, create an attribute whose local name is qualifiedName"
Chris Dumez
Comment 9
2018-07-05 09:11:51 PDT
Comment on
attachment 344202
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=344202&action=review
> LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes.html:134 > + el.toggleAttribute("foo:bar");
Actually the behavior for qualified name is tested here and we pass this test. findAttributeIndexByName(const AtomicString&) does the right thing when the attribute has a prefix: attribute.name().toString() == caseAdjustedName Based on this, I believe I should rename localName / name in the implementation to qualifiedName, to match the IDL and the spec.
Chris Dumez
Comment 10
2018-07-05 09:49:34 PDT
(In reply to Chris Dumez from
comment #9
)
> Comment on
attachment 344202
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=344202&action=review
> > > LayoutTests/imported/w3c/web-platform-tests/dom/nodes/attributes.html:134 > > + el.toggleAttribute("foo:bar"); > > Actually the behavior for qualified name is tested here and we pass this > test. findAttributeIndexByName(const AtomicString&) does the right thing > when the attribute has a prefix: > attribute.name().toString() == caseAdjustedName > > Based on this, I believe I should rename localName / name in the > implementation to qualifiedName, to match the IDL and the spec.
https://bugs.webkit.org/show_bug.cgi?id=187347
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug