* `textbox` gets the `textbox` binding
* `textbox[type="number"]` gets the `numberbox` binding
* `textbox[type="search"]` gets the `search-textbox` binding
* etc
With Custom Elements, there are two approaches I've thought of:
1) Make either 3 different tags (`textbox`, `textbox-number`, `textbox-search`)
2) Fatten up the base binding to also keep track of if we are a number box, searchbox, etc.
Both could work, but neither seems great - the former means we need to duplicate CSS selectors and modify any JS / C++ that’s looking for the tag name, and the latter could get hard to maintain with the number of widgets we have (including page-specific ones that override the main toolkit ones). Any other ideas on how to deal with this?
One thing I noticed is that the spec is that there's a concept of 'customized builtin elements’ [1] where you can have things like:
```
class PlasticButton extends HTMLButtonElement { }
customElements.define("plastic-button", PlasticButton, { extends: "button" });
<button is="plastic-button">Click Me!</button>
```
Which seems like it could map well onto our XBL inheritance if we could do:
```
class Textbox extends XULElement { }
customElements.define(“textbox", Textbox);
class SearchTextbox extends Textbox { }
customElements.define("search-textbox", SearchTextbox, { extends: "textbox" });
<textbox />
<textbox is="search-textbox" />
```
However, that is not allowed as per 'If extends is a valid custom element name, then throw a "NotSupportedError" DOMException’ [2]. Is there a technical reason why we couldn't expose the `is` semantics used by customized builtins for extending other Custom Elements?
Thanks,
Brian
[0]: https://bgrins.github.io/xbl-analysis/tree/#textbox
[1]: https://www.w3.org/TR/custom-elements/#custom-elements-customized-builtin-example
[2]: https://searchfox.org/mozilla-central/rev/4114ad2cfcbc511705c7865a4a34741812f9a2a9/dom/base/CustomElementRegistry.cpp#731
_______________________________________________
firefox-dev mailing list
firef...@mozilla.org
https://mail.mozilla.org/listinfo/firefox-dev
Only some ideas (I don't think they're perfect).
For the purpose of not duplicating selectors, couldn't you add a common
class or something on the connected callback, maybe? It would need to be
a class or what not for now, though :host could make it a bit nicer with
Shadow DOM I guess, at least in terms of styling the component itself.
We support that now, fwiw, but not sure if Shadow DOM is enabled in
chrome yet, I guess not.
For code looking for the tagname and such, I guess you could also modify
them to use instanceof TextBox or something like that, which should be
less repetitive than enumerating tags... But I don't have the context
for how this kind of element is used on the frontend.
-- Emilio
> On Apr 12, 2018, at 4:09 PM, Dave Townsend <dtow...@mozilla.com> wrote:
>
> I don't think the customized built-in element is the right option. If I understand the spec correctly you'd just be replacing all the lifecycle events of the underlying element anyway.
In this case I don’t want ‘customized built-in’ exactly, but I want ‘customized autonomous custom element’ or something like that. So: register an autonomous Custom Element (say, “moz-toolbarbutton"), then be able to support <moz-button is=“ toolbarbutton-badged”>, where toolbarbutton-badged is registered to a class that extends the moz-button class. This is not allowed by the spec, but I’m curious if it’s something that’s worth considering (or if it’s already been discussed).
> Do you know how often do we switch between bindings like this? I'd lean towards just using different tag names, seems likely we could script a rewrite in most cases. Switching at runtime is a problem (in any case I'd imagine).
It's hard to say exactly given the nature of binding via CSS selectors, but from looking at the tree from https://bgrins.github.io/xbl-analysis/tree/ I see the following tags that appear to support more than one binding and approximately how many different bindings get attached to them:
- label (~3)
- menuitem (~3)
- menu (~5)
- toolbarbutton (~5)
- button (~4)
- listitem (~3)
- richlisitem (~15)
- arrowscrollbox (~3)
- menulist (~4)
- richlistbox (~3)
- tree (~2)
- treecol (~2)
- tabs (~2)
- listcell (~3)
- menupopup (~4)
- panel (~6)
- popupnotification (~2)
- textbox (~8)
- browser (~4)
- tabpanels (~2)
- notification (~2)
- progressmeter (~2)
- marquee (~5)
- datetimebox (~2)
- toolbar (~5)
- videocontrols (~2)
Brian
> On Apr 13, 2018, at 9:17 AM, Brian Grinstead <bgrin...@mozilla.com> wrote:
>
> So: register an autonomous Custom Element (say, “moz-toolbarbutton"), then be able to support <moz-button is=“ toolbarbutton-badged”>, where toolbarbutton-badged is registered to a class that extends the moz-button class
Correcting a typo - "moz-button" should have been "moz-toolbarbutton".
where toolbarbutton-badged is registered to a class that extends the moz-button class. This is not allowed by the spec, but I’m curious if it’s something that’s worth considering (or if it’s already been discussed).
In fact my impression is that for XUL we'd need a combination of the two
concepts, in order to make a more incremental transition from the
current state to an implementation that is closer to HTML.
As Brian mentioned, the localName is currently used by platform code to
attach special behavior, for example accessibility, to elements like
"listitem" and "richlisitem". We are also looking into subclassing
XULElement in the platform to add C++-implemented methods to elements
like "panel" and "menupopup". This would in fact make them analogous
to "built-in elements" in HTML. My guess is that preserving this
platform behavior, hard-coded on the localName, is why "customized
built-in elements" exist for HTML in the first place.
The only difference from HTML here is that the base element itself,
the one without the "is" attribute, would also be implemented with a
corresponding JavaScript class extending XULElement, or a more specific
subclass for cases like "panel". This is basically the "non-dashed
custom elements" idea that we applied to facilitate the transition.
This also aligns with the concept that in the future some HTML elements
may be implemented in the user agent as JavaScript classes similar to
custom elements, either partially or entirely. So we would have:
class Panel extends XULPanelElement
class ArrowPanel extends Panel
customElements.define("panel", Panel);
customElements.define("arrow-panel", ArrowPanel, { extends: "panel" });
<panel/>
<panel is="arrow-panel"/>
document.createElement("panel");
document.createElement("panel", { is: "arrow-panel" });
How much effort would it be to support this scenario in XUL?
Cheers,
Paolo
And of course we'd have to audit all the usages of in-tree selectors,
like .closest("richlistitem") should become .closest(".richlistitem"),
as Brian mentioned in the original post.
Couldn’t find any previous discussion about this (it’s been this way since v0) so I filed https://github.com/w3c/webcomponents/issues/750.
Brian